minecodex 1.2.2 → 2.0.1

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 (87) hide show
  1. package/README.md +9 -3
  2. package/features/images/README.md +16 -98
  3. package/features/images/codex-feature.json +6 -23
  4. package/features/images/src/library-prompt-page.mjs +239 -0
  5. package/features/model-slider/THIRD_PARTY_NOTICES.md +1 -1
  6. package/features/notes/DESIGN.md +66 -0
  7. package/features/notes/README.md +18 -99
  8. package/features/notes/assets/icons/book-open-nav.svg +15 -0
  9. package/features/notes/assets/icons/book-open.svg +16 -0
  10. package/features/notes/assets/native-emojis.json +1 -0
  11. package/features/notes/assets/native-prompt-icons.json +28 -0
  12. package/features/notes/codex-feature.json +12 -70
  13. package/features/notes/src/main.mjs +2 -2
  14. package/features/notes/src/product.mjs +287 -613
  15. package/features/notes/src/prompt-schema.mjs +117 -0
  16. package/features/notes/src/quick-prompts-page.mjs +1559 -0
  17. package/features/notes/src/quick-prompts-server.mjs +167 -0
  18. package/features/session-status/DESIGN.md +11 -3
  19. package/features/session-status/README.md +8 -4
  20. package/features/session-status/src/session-status.mjs +272 -25
  21. package/features/sidebar-focus/DESIGN.md +16 -0
  22. package/features/sidebar-focus/codex-feature.json +20 -0
  23. package/features/sidebar-focus/src/sidebar-focus.mjs +134 -0
  24. package/features/sidebar-focus/vendor/lucide-LICENSE +43 -0
  25. package/features/unread-inbox/DESIGN.md +36 -0
  26. package/features/unread-inbox/codex-feature.json +20 -0
  27. package/features/unread-inbox/src/unread-inbox.mjs +446 -0
  28. package/features/usage-meter/DESIGN.md +49 -0
  29. package/features/usage-meter/README.md +18 -0
  30. package/features/usage-meter/codex-feature.json +13 -0
  31. package/features/usage-meter/src/usage-meter.mjs +200 -0
  32. package/package.json +17 -5
  33. package/packages/cli/src/config.mjs +4 -1
  34. package/packages/cli/src/control-server.mjs +2 -2
  35. package/packages/runtime-host/src/codex-injection.mjs +38 -3
  36. package/packages/runtime-host/src/codex-runtime.mjs +41 -20
  37. package/packages/runtime-host/src/feature-registry.mjs +1 -0
  38. package/packages/runtime-host/src/session-status-reader.mjs +40 -16
  39. package/features/notes/assets/icons/circle.svg +0 -15
  40. package/features/notes/assets/icons/ellipsis.svg +0 -17
  41. package/features/notes/assets/icons/external-link.svg +0 -17
  42. package/features/notes/assets/icons/list-todo.svg +0 -19
  43. package/features/notes/assets/icons/message-square-quote.svg +0 -17
  44. package/features/notes/assets/icons/paperclip.svg +0 -15
  45. package/features/notes/assets/icons/star-off.svg +0 -17
  46. package/features/notes/assets/icons/star.svg +0 -15
  47. package/features/notes/assets/icons/sticky-note.svg +0 -16
  48. package/features/notes/assets/icons/trash-2.svg +0 -19
  49. package/features/notes/src/http-server.mjs +0 -580
  50. package/features/notes/web/app.js +0 -1202
  51. package/features/notes/web/codex-artifact-document.svg +0 -1
  52. package/features/notes/web/codex-attachment.svg +0 -1
  53. package/features/notes/web/codex-build.svg +0 -1
  54. package/features/notes/web/codex-code.svg +0 -1
  55. package/features/notes/web/codex-cplusplus.svg +0 -1
  56. package/features/notes/web/codex-css.svg +0 -1
  57. package/features/notes/web/codex-document.svg +0 -1
  58. package/features/notes/web/codex-file.svg +0 -1
  59. package/features/notes/web/codex-folder.svg +0 -1
  60. package/features/notes/web/codex-hashes.svg +0 -1
  61. package/features/notes/web/codex-html.svg +0 -1
  62. package/features/notes/web/codex-image.svg +0 -1
  63. package/features/notes/web/codex-java.svg +0 -1
  64. package/features/notes/web/codex-javascript.svg +0 -1
  65. package/features/notes/web/codex-json.svg +0 -1
  66. package/features/notes/web/codex-notebook.svg +0 -1
  67. package/features/notes/web/codex-pdf.svg +0 -1
  68. package/features/notes/web/codex-pencil.svg +0 -3
  69. package/features/notes/web/codex-php.svg +0 -1
  70. package/features/notes/web/codex-plus.svg +0 -3
  71. package/features/notes/web/codex-presentation.svg +0 -1
  72. package/features/notes/web/codex-python.svg +0 -1
  73. package/features/notes/web/codex-react.svg +0 -1
  74. package/features/notes/web/codex-rust.svg +0 -1
  75. package/features/notes/web/codex-shell.svg +0 -1
  76. package/features/notes/web/codex-skill.svg +0 -1
  77. package/features/notes/web/codex-spreadsheet.svg +0 -1
  78. package/features/notes/web/codex-task.svg +0 -3
  79. package/features/notes/web/codex-terminal.svg +0 -1
  80. package/features/notes/web/codex-toml.svg +0 -1
  81. package/features/notes/web/codex-typescript.svg +0 -1
  82. package/features/notes/web/codex-view-all.svg +0 -3
  83. package/features/notes/web/file-icons.mjs +0 -68
  84. package/features/notes/web/i18n.mjs +0 -237
  85. package/features/notes/web/index.html +0 -15
  86. package/features/notes/web/styles.css +0 -1155
  87. package/features/notes/web/todo-drag.mjs +0 -18
@@ -0,0 +1,36 @@
1
+ # 任务切换
2
+
3
+ 仅在线程侧栏收起时显示入口;展开时移除入口并关闭浮层。入口随 Codex 标题栏布局切换:
4
+ - 普通/分栏:在主 Chat 标题前显示原生 list-bullet 图标;整段标题可点击。
5
+ - 全宽标签页:在 Chat 标签页前注入独立的任务图标按钮。
6
+ - 移除扩展铃铛,注入入口存在时,用原生完整 SVG 显示无蓝点的 Sidebar 图标;保留 React 原节点,卸载或展开侧栏时移除替代图标并恢复原节点。
7
+ - 悬停入口150ms展开;鼠标离开入口与浮层250ms后关闭,跨越8px间隙进入浮层会取消关闭。点击入口确保打开;点击外部、Escape 关闭。Enter、空格、ArrowDown 可打开。
8
+
9
+ 样式使用原生字体、text-secondary、radius-lg、primary-ghost-hover 与 ring token。入口仅 hover 显示背景,不保持选中底色。标题区域 no-drag,其他标题栏区域保留窗口拖拽。
10
+
11
+ 浮层宽320px(窄窗口缩小),最大高440px(约5条,受视口高度限制);沿用 dropdown 背景与 border,圆角16px、shadow-md,外层上下 padding 6px、左右0;滚动容器左右 padding 6px,使滚动条靠近浮层边缘。位置对齐标题触发区域左侧、底缘下方8px,并受窗口边界约束。
12
+
13
+ 列表集合为等待回复/批准、工作中、最近1小时打开过、未读的会话,按 Thread ID 去重。按需要回复、等待批准、未读、执行中、空闲排序,同级按消息时间倒序;排除当前会话。原生流式摘要变化时更新观测消息时间,不因菜单重绘更新时间。最近访问记录限定当前窗口运行期间。每条显示:
14
+ 1. 单行标题(13px/18px),远程标识紧随标题且不显示主机名;右侧状态优先级为待确认标签、原生 loading、相对时间。背景仅 hover 时显示。
15
+ 2. 单行省略的 AI 回答摘要(12px/16px)。
16
+ 3. 所属 Project 原生图标(12px)与名称(若有),11px/16px 弱化文字,不合并分组。条目 padding 10px 12px,行间 gap 4px,圆角10px。
17
+
18
+ 时间使用原生 hover card 的 recencyAt,缺失时 updatedAt;每30秒刷新。工作状态读取原生 statusState.type=loading。缓存会话数据与原生导航回调,复用导航和已读更新,不缓存 DOM 行,不发送消息。
19
+
20
+ 打开时临时启用 Activity 以取得完整列表,关闭或卸载时恢复原先模式。只读取原生数据,预览不标记已读。界面及无障碍文案适配中英文。
21
+
22
+ 入口只显示任务图标,不显示数量。浮层标题为 Recent activity/最近活动,反映工作中、未读与最近访问的集合;不将最近访问误称为待处理。浮层无页面遮罩,点击外部关闭,Escape 关闭并返回入口焦点。
23
+
24
+ 标题固定、条目容器独立滚动;上下保留6px内边距;条目内容左右保留6px,滚动条不受外层横向内边距挤压。
25
+
26
+ 点击后先同步显示浮层与可用数据,首帧绘制后再切换原生 Activity 补全条目;关闭或卸载会取消尚未开始的切换。
27
+
28
+ 消息刷新时保留列表滚动位置与条目键盘焦点。当前身份消失时清除选中状态,最近访问缓存按一小时过期。
29
+
30
+ 待确认状态读取原生行的 `statusPill.label.props.id=codex.localTaskRow.needsInput` 或 `chips[].id=awaiting-approval`,不根据摘要推断。Needs input/需要回复沿用原生 chart-blue 15% 背景,Awaiting approval/等待批准沿用 chart-green 20% 背景与圆角胶囊;适配紧凑行使用12px/16px文字。点击条目仍仅导航,不执行批准或原生 Snooze 动作。
31
+
32
+ 滚动条与原生 overflow 容器一致:thin,静止使用 `--color-border`,hover/active 使用 `--color-border-strong`,轨道透明;不使用全局较深的 `--scrollbar-color`。
33
+
34
+ 入口提醒点:排除当前会话后,有需要回复或批准时为红色 `#FF3B30`,否则存在未读为原生蓝色 `--blue-400`;只有执行中或空闲则无点。点直径6px。无其他命中会话时不打开浮层,包括仅当前会话命中的情况。原生侧栏图标与 MineCodex 提醒随注入/卸载同步恢复。
35
+
36
+ 浮层标题颜色与原生 Sidebar 类别标题一致,使用 `--color-text-tertiary`。
@@ -0,0 +1,20 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "unread-inbox",
4
+ "version": "0.1.0",
5
+ "label": {
6
+ "en": "Task Switcher",
7
+ "zh-CN": "任务切换"
8
+ },
9
+ "description": {
10
+ "en": "Switch between working and unread chats from the chat title or task button.",
11
+ "zh-CN": "点击聊天标题或任务按钮,切换工作中与未读会话。"
12
+ },
13
+ "entry": {
14
+ "kind": "page-script",
15
+ "script": "src/unread-inbox.mjs"
16
+ },
17
+ "placement": {
18
+ "order": 70
19
+ }
20
+ }
@@ -0,0 +1,446 @@
1
+ // 原生完整侧栏图标,取自当前 Codex 16px/20px 资源。
2
+ const sidebarGlyphs = {"16": "<svg aria-hidden=\"true\" class=\"_Icon_uttcz_1\" focusable=\"false\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path d=\"M4.66699 4.80859C4.95683 4.80873 5.19238 5.04412 5.19238 5.33398V10.667C5.19238 10.9569 4.95683 11.1923 4.66699 11.1924C4.37704 11.1924 4.1416 10.9569 4.1416 10.667V5.33398C4.1416 5.04403 4.37704 4.80859 4.66699 4.80859Z\" fill=\"currentColor\"></path> <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M11.5 2.30762C13.1707 2.30762 14.5254 3.66235 14.5254 5.33301V10.666C14.5254 12.3367 13.1707 13.6914 11.5 13.6914H4.5C2.82934 13.6914 1.47461 12.3367 1.47461 10.666V5.33301C1.47461 3.66235 2.82934 2.30762 4.5 2.30762H11.5ZM4.5 3.3584C3.40924 3.3584 2.52539 4.24225 2.52539 5.33301V10.666C2.52539 11.7568 3.40924 12.6416 4.5 12.6416H11.5C12.5908 12.6416 13.4746 11.7568 13.4746 10.666V5.33301C13.4746 4.24225 12.5908 3.3584 11.5 3.3584H4.5Z\" fill=\"currentColor\"></path></svg>", "20": "<svg aria-hidden=\"true\" class=\"_Icon_uttcz_1\" focusable=\"false\" height=\"20\" viewBox=\"0 0 20 20\" width=\"20\"><path d=\"M5.83301 6.00098C6.20028 6.00098 6.49805 6.29875 6.49805 6.66602V13.333C6.49787 13.7001 6.20017 13.998 5.83301 13.998C5.46596 13.9979 5.16814 13.7 5.16797 13.333V6.66602C5.16797 6.29883 5.46585 6.00111 5.83301 6.00098Z\" fill=\"currentColor\"></path> <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M14.5 2.87695C16.5241 2.87695 18.165 4.51787 18.165 6.54199V13.459C18.1649 15.483 16.524 17.124 14.5 17.124H5.5C3.47598 17.124 1.83514 15.483 1.83496 13.459V6.54199C1.83496 4.51787 3.47588 2.87695 5.5 2.87695H14.5ZM5.5 4.20703C4.21042 4.20703 3.16504 5.25241 3.16504 6.54199V13.459C3.16521 14.7484 4.21052 15.7939 5.5 15.7939H14.5C15.7895 15.7939 16.8348 14.7484 16.835 13.459V6.54199C16.835 5.25241 15.7896 4.20703 14.5 4.20703H5.5Z\" fill=\"currentColor\"></path></svg>"};
3
+ const taskGlyph = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\"><path d=\"M13.3336 11.4749C13.6234 11.475 13.858 11.7104 13.858 12.0002C13.8579 12.2899 13.6233 12.5255 13.3336 12.5256H6.66663C6.37678 12.5256 6.1414 12.2901 6.14124 12.0002C6.14124 11.7103 6.37668 11.4749 6.66663 11.4749H13.3336Z\" fill=\"currentColor\"/> <path d=\"M3.07874 10.9827C3.50002 10.9827 3.84226 11.3241 3.84241 11.7454C3.84241 12.1667 3.50011 12.509 3.07874 12.509C2.65748 12.5089 2.31604 12.1666 2.31604 11.7454C2.31619 11.3242 2.65758 10.9828 3.07874 10.9827Z\" fill=\"currentColor\"/> <path d=\"M13.3336 7.47485C13.6234 7.47503 13.858 7.7104 13.858 8.00024C13.8579 8.28995 13.6233 8.52546 13.3336 8.52563H6.66663C6.37678 8.52563 6.1414 8.29005 6.14124 8.00024C6.14124 7.71029 6.37668 7.47485 6.66663 7.47485H13.3336Z\" fill=\"currentColor\"/> <path d=\"M3.07874 6.98267C3.50002 6.98267 3.84226 7.32411 3.84241 7.74536C3.84241 8.16674 3.50011 8.50903 3.07874 8.50903C2.65748 8.50888 2.31604 8.16665 2.31604 7.74536C2.31619 7.3242 2.65758 6.98281 3.07874 6.98267Z\" fill=\"currentColor\"/> <path d=\"M13.3336 3.47485C13.6234 3.47503 13.858 3.7104 13.858 4.00024C13.8579 4.28995 13.6233 4.52546 13.3336 4.52563H6.66663C6.37678 4.52563 6.1414 4.29005 6.14124 4.00024C6.14124 3.71029 6.37668 3.47485 6.66663 3.47485H13.3336Z\" fill=\"currentColor\"/> <path d=\"M3.07874 2.98267C3.50002 2.98267 3.84226 3.32411 3.84241 3.74536C3.84241 4.16674 3.50011 4.50903 3.07874 4.50903C2.65748 4.50888 2.31604 4.16665 2.31604 3.74536C2.31619 3.3242 2.65758 2.98281 3.07874 2.98267Z\" fill=\"currentColor\"/></svg>";
4
+ const deviceGlyphs = {"local": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M12.6667 2.47461C13.6928 2.47479 14.525 3.30694 14.5251 4.33301V10.1445C15.0248 10.184 15.3787 10.6177 15.3787 11.0928V11.9355C15.3785 12.9036 14.6274 13.7373 13.6433 13.7373H2.34644C1.36254 13.7371 0.611273 12.9035 0.611084 11.9355V11.0928C0.611084 10.6149 0.970003 10.1796 1.47437 10.1445V4.33301C1.47454 3.30702 2.3068 2.47492 3.33276 2.47461H12.6667ZM1.66187 11.9355C1.66205 12.3765 1.99397 12.6863 2.34644 12.6865H13.6433C13.9959 12.6865 14.3287 12.3767 14.3289 11.9355V11.1924H1.66187V11.9355ZM3.33276 3.52539C2.8867 3.5257 2.52532 3.88692 2.52515 4.33301V10.1416H13.4744V4.33301C13.4742 3.88684 13.1129 3.52557 12.6667 3.52539H3.33276Z\" fill=\"currentColor\"/></svg>", "remote": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M11.5005 1.1416C12.4346 1.14184 13.1919 1.89985 13.1919 2.83398V6.55859H13.3335C13.8259 6.55859 14.1917 6.9676 14.1919 7.42969V8.2959C14.1914 9.14015 13.5269 9.85938 12.6665 9.85938H3.3335C2.47306 9.85938 1.80856 9.14015 1.80811 8.2959V7.42969C1.80834 6.9677 2.17428 6.55877 2.6665 6.55859H2.80811V2.83398C2.80811 1.8997 3.56621 1.1416 4.50049 1.1416H11.5005ZM2.85889 8.2959C2.85933 8.59786 3.08989 8.80859 3.3335 8.80859H12.6665C12.9101 8.80859 13.1416 8.59786 13.1421 8.2959V7.60938H2.85889V8.2959ZM4.50049 2.19238C4.14611 2.19238 3.85889 2.4796 3.85889 2.83398V6.55859H12.1421V2.83398C12.1421 2.47975 11.8547 2.19262 11.5005 2.19238H4.50049Z\" fill=\"currentColor\"/> <path d=\"M2.8595 13.4307C3.28863 13.4308 3.63684 13.7788 3.63684 14.208C3.63677 14.6371 3.28859 14.9852 2.8595 14.9854C2.43029 14.9854 2.08222 14.6372 2.08215 14.208C2.08215 13.7788 2.43025 13.4307 2.8595 13.4307Z\" fill=\"currentColor\"/> <path d=\"M5.42981 13.4307C5.859 13.4307 6.20715 13.7788 6.20715 14.208C6.20709 14.6372 5.85896 14.9853 5.42981 14.9854C5.0006 14.9854 4.65253 14.6372 4.65247 14.208C4.65247 13.7788 5.00056 13.4307 5.42981 13.4307Z\" fill=\"currentColor\"/> <path d=\"M8.00012 13.4307C8.42937 13.4307 8.77747 13.7788 8.77747 14.208C8.7774 14.6372 8.42933 14.9854 8.00012 14.9854C7.57092 14.9854 7.22284 14.6372 7.22278 14.208C7.22278 13.7788 7.57087 13.4307 8.00012 13.4307Z\" fill=\"currentColor\"/> <path d=\"M10.5704 13.4307C10.9997 13.4307 11.3478 13.7788 11.3478 14.208C11.3477 14.6372 10.9996 14.9854 10.5704 14.9854C10.1414 14.9852 9.79413 14.6371 9.79407 14.208C9.79407 13.7789 10.1414 13.4309 10.5704 13.4307Z\" fill=\"currentColor\"/> <path d=\"M13.1417 13.4307C13.5707 13.4309 13.9181 13.7789 13.9181 14.208C13.918 14.637 13.5707 14.9851 13.1417 14.9854C12.7125 14.9854 12.3644 14.6372 12.3644 14.208C12.3644 13.7788 12.7125 13.4307 13.1417 13.4307Z\" fill=\"currentColor\"/> <path d=\"M8.00012 10.8809C8.42925 10.8809 8.77727 11.2281 8.77747 11.6572C8.77747 12.0865 8.42937 12.4346 8.00012 12.4346C7.57087 12.4346 7.22278 12.0865 7.22278 11.6572C7.22298 11.2281 7.571 10.8809 8.00012 10.8809Z\" fill=\"currentColor\"/></svg>"};
5
+ const text = (en, cn) => (document.documentElement.lang || navigator.language || "en").startsWith("zh") ? cn : en;
6
+ const projectIcons = new Map();
7
+ const folderGlyph = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"20\" height=\"20\" fill=\"none\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M6.94946 2.66821C7.58311 2.66821 8.20067 2.86877 8.71313 3.24146L9.77759 4.01587C10.0627 4.22319 10.4065 4.33521 10.759 4.33521H14.9583C16.6142 4.33521 17.9563 5.67732 17.9563 7.33325V14.3333C17.9563 15.9892 16.6142 17.3313 14.9583 17.3313H5.04126C3.38547 17.3311 2.04321 15.9891 2.04321 14.3333V5.66626C2.04339 4.01058 3.38558 2.66839 5.04126 2.66821H6.94946ZM3.37329 9.83228V14.3333C3.37329 15.2545 4.12001 16.001 5.04126 16.0012H14.9583C15.8796 16.0012 16.6262 15.2546 16.6262 14.3333V9.83228H3.37329ZM5.04126 3.99829C4.12012 3.99847 3.37347 4.74512 3.37329 5.66626V8.5022H16.6262V7.33325C16.6262 6.41186 15.8796 5.66528 14.9583 5.66528H10.759C10.1254 5.66528 9.50784 5.46377 8.99536 5.09106L7.93091 4.31763C7.64576 4.11024 7.30205 3.99829 6.94946 3.99829H5.04126Z\" fill=\"currentColor\"/></svg>";
8
+ const marker = "data-minecodex-unread";
9
+ const style = document.createElement("style");
10
+ style.textContent = `
11
+ [data-minecodex-task-title] { pointer-events:auto; -webkit-app-region:no-drag; cursor:pointer; border-radius:var(--radius-lg); min-height:32px; padding-inline:6px; }
12
+ [data-minecodex-task-title]:hover { background:var(--color-background-primary-ghost-hover); }
13
+ [data-minecodex-task-title]:focus-visible { outline:2px solid var(--color-ring); outline-offset:-2px; }
14
+ [data-minecodex-task-badge] { display:inline-flex; flex-shrink:0; align-items:center; gap:4px; color:var(--color-text-secondary); font-family:var(--font-sans-default); font-size:var(--text-xs); font-variant-numeric:tabular-nums; position:relative; }
15
+ [data-minecodex-task-badge][data-notification]::after { content:""; position:absolute; width:6px; height:6px; right:-2px; top:-1px; border-radius:50%; background:var(--blue-400,#3A83F7); box-shadow:0 0 0 1.5px var(--color-token-dropdown-background); }
16
+ [data-minecodex-task-badge][data-notification=red]::after { background:#FF3B30; }
17
+ [data-minecodex-sidebar-original] { display:none !important; }
18
+ [data-minecodex-unread=trigger] { -webkit-app-region:no-drag; }
19
+ [${marker}=panel] { position:fixed; z-index:2147483000; box-sizing:border-box; width:min(320px,calc(100vw - 16px)); max-height:min(440px,calc(100vh - 64px)); display:flex; flex-direction:column; overflow:hidden; padding:6px 0; border:1px solid var(--color-border); border-radius:16px; background:var(--color-token-dropdown-background); color:var(--color-text-primary); box-shadow:var(--shadow-md,0 4px 16px rgba(0,0,0,.12)); font-family:var(--font-sans-default); font-size:var(--text-sm); }
20
+ [${marker}=panel][hidden] { display:none; }
21
+ [${marker}=panel] .mcx-thread-list { min-height:0; overflow-y:auto; overscroll-behavior:contain; padding:0 6px; scrollbar-width:thin; scrollbar-color:var(--color-border) transparent; }
22
+ [${marker}=panel] .mcx-thread-list:hover, [${marker}=panel] .mcx-thread-list:active { scrollbar-color:var(--color-border-strong) transparent; }
23
+ [${marker}=panel] h2 { flex-shrink:0; margin:8px 16px; font-size:var(--text-sm); font-weight:500; color:var(--color-text-tertiary); }
24
+ [${marker}=panel] [data-unread-row] { display:flex; flex-direction:column; gap:4px; width:100%; padding:10px 12px; box-sizing:border-box; border:0; border-radius:10px; background:transparent; text-align:start; color:var(--color-text-primary); font:inherit; cursor:pointer; }
25
+ [${marker}=panel] [data-unread-row][aria-current=page] .mcx-thread-title::before { content:""; display:inline-block; width:5px; height:5px; margin-inline-end:6px; border-radius:50%; background:currentColor; vertical-align:middle; }
26
+ [${marker}=panel] [data-unread-row]:hover { background:var(--color-background-primary-ghost-hover); }
27
+ [${marker}=panel] [data-unread-row]:focus-visible { outline:2px solid var(--color-ring); outline-offset:-2px; }
28
+ [${marker}=panel] .mcx-thread-header { display:flex; align-items:center; gap:8px; width:100%; min-width:0; }
29
+ [${marker}=panel] .mcx-thread-title { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; font-size:13px; line-height:18px; font-weight:500; }
30
+ [${marker}=panel] .mcx-device { display:flex; flex-shrink:0; color:var(--color-text-tertiary); }
31
+ [${marker}=panel] .mcx-loading { margin-inline-start:auto; flex-shrink:0; display:flex; align-items:center; color:var(--color-text-tertiary); }
32
+ [${marker}=panel] time { margin-inline-start:auto; flex-shrink:0; font-size:var(--text-xs); color:var(--color-text-tertiary); }
33
+ [${marker}=panel] .mcx-summary { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:12px; line-height:16px; color:var(--color-text-tertiary); }
34
+ [${marker}=panel] .mcx-project { display:flex; align-items:center; gap:6px; padding:0; min-width:0; font-size:11px; line-height:16px; color:var(--color-text-tertiary); font-weight:400; }
35
+ [${marker}=panel] .mcx-project > span:last-child { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
36
+ [${marker}=panel] .mcx-project svg, [${marker}=panel] .mcx-project-icon { width:12px; height:12px; flex:none; }
37
+ [${marker}=panel] .mcx-project-icon > * { width:12px; height:12px; }
38
+ [${marker}=panel] .mcx-attention { margin-inline-start:auto; flex:none; max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; border-radius:999px; padding:2px 10px 2px 8px; font-size:12px; line-height:16px; color:var(--color-chart-blue); background:color-mix(in srgb,var(--color-chart-blue) 15%,transparent); }
39
+ [${marker}=panel] .mcx-attention[data-attention="approval"] { color:var(--color-chart-green); background:color-mix(in srgb,var(--color-chart-green) 20%,transparent); }
40
+ [${marker}=panel] .mcx-empty { margin:20px 12px; color:var(--color-text-tertiary); }
41
+ `;
42
+ document.head.append(style);
43
+ const panel = document.createElement("div");
44
+ panel.setAttribute(marker, "panel");
45
+ panel.id = "minecodex-unread-panel";
46
+ panel.setAttribute("role", "dialog");
47
+ panel.hidden = true;
48
+ document.body.append(panel);
49
+ let trigger = null, badge = null, binding = null, standalone = false;
50
+ let activityFrame = null, activityTimer = null;
51
+ let hoverOpenTimer = null, hoverCloseTimer = null;
52
+ function cancelHoverTimers() {
53
+ clearTimeout(hoverOpenTimer); clearTimeout(hoverCloseTimer);
54
+ }
55
+ function scheduleHoverOpen() {
56
+ cancelHoverTimers();
57
+ if (panel.hidden) hoverOpenTimer = setTimeout(open, 150);
58
+ }
59
+ function scheduleHoverClose() {
60
+ cancelHoverTimers();
61
+ // 留出跨越入口与浮层间隙的时间。
62
+ hoverCloseTimer = setTimeout(() => close(), 250);
63
+ }
64
+ panel.addEventListener("pointerenter", cancelHoverTimers, { signal });
65
+ panel.addEventListener("pointerleave", scheduleHoverClose, { signal });
66
+ const recentRows = new Map();
67
+ const openedAt = new Map();
68
+ const messageUpdates = new Map();
69
+ let selectedKey = null;
70
+ let restoreActivity = false, signature = "", queued = false, disposed = false;
71
+ function activityButton() {
72
+ return [...document.querySelectorAll('#app-shell-sidebar button[aria-pressed]')].find(e => /activity|活动|动态/.test(e.getAttribute("aria-label") || ""));
73
+ }
74
+ function isUnread(row) {
75
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
76
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
77
+ if (typeof fiber.memoizedProps?.isUnread === "boolean") return fiber.memoizedProps.isUnread;
78
+ }
79
+ return false;
80
+ }
81
+ function isWorking(row) {
82
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
83
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
84
+ const status = fiber.memoizedProps?.statusState;
85
+ if (status?.type) return status.type === "loading";
86
+ }
87
+ return false;
88
+ }
89
+ // 缓存数据与原生导航动作,不保留会被 React 卸载的会话 DOM。
90
+ function threadRecord(row) {
91
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
92
+ let activate = null;
93
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
94
+ const props = fiber.memoizedProps;
95
+ if (props?.statusState && typeof props.onClick === "function") { activate = props.onClick; break; }
96
+ }
97
+ return { ...threadDetails(row), key:row.dataset.appActionSidebarThreadId, unread:isUnread(row), activate, spinner:row.querySelector?.('[class~="motion-safe:animate-spin"]')?.outerHTML ?? "" };
98
+ }
99
+ function notificationColor(records) {
100
+ return records.some(item => item.attention) ? "red" : records.some(item => item.unread) ? "blue" : null;
101
+ }
102
+ function selectThreads(records, recent, now = Date.now(), currentKey = null) {
103
+ const rank = item => item.attention === "input" ? 0 : item.attention === "approval" ? 1 : item.unread ? 2 : item.working ? 3 : 4;
104
+ return [...new Map(records.map(item => [item.key, item])).values()]
105
+ .filter(item => item.key !== currentKey && (item.attention || item.working || item.unread || now - (recent.get(item.key) ?? -Infinity) < 3600000))
106
+ .sort((a, b) => rank(a) - rank(b) || (b.timestamp ?? 0) - (a.timestamp ?? 0));
107
+ }
108
+ function captureCurrentRow() {
109
+ const selected = document.querySelector('#app-shell-sidebar [data-app-action-sidebar-thread-selected="true"]');
110
+ const id = document.querySelector('[data-above-composer-conversation-id]')?.getAttribute('data-above-composer-conversation-id');
111
+ selectedKey = selected?.dataset.appActionSidebarThreadId
112
+ ?? [...recentRows.keys()].find(key => id && key.endsWith(":" + id)) ?? null;
113
+ if (selected) recentRows.set(selectedKey, threadRecord(selected));
114
+ if (selectedKey) openedAt.set(selectedKey, Date.now());
115
+ for (const [key, time] of openedAt) if (Date.now() - time >= 3600000) {
116
+ openedAt.delete(key); recentRows.delete(key); messageUpdates.delete(key);
117
+ }
118
+ }
119
+ function projectForRow(row) {
120
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
121
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
122
+ const group = fiber.memoizedProps?.secondaryContent?.props?.projectGroup;
123
+ if (group?.projectId) return { id:group.projectId, name:group.label };
124
+ }
125
+ return null;
126
+ }
127
+ function attentionState(row) {
128
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
129
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
130
+ const props = fiber.memoizedProps;
131
+ // 复用原生状态契约,不从摘要文案推断待确认状态。
132
+ if (props?.chips?.some(chip => chip.id === "awaiting-approval")) return "approval";
133
+ if (props?.statusPill?.label?.props?.id === "codex.localTaskRow.needsInput") return "input";
134
+ }
135
+ return null;
136
+ }
137
+ function threadDetails(row) {
138
+ let fiber = row[Object.keys(row).find(key => key.startsWith("__reactFiber"))];
139
+ let summary, hostConfig;
140
+ for (let depth = 0; fiber && depth < 35; depth++, fiber = fiber.return) {
141
+ summary ||= fiber.memoizedProps?.threadSummary;
142
+ hostConfig ||= fiber.memoizedProps?.hoverCardHostConfig;
143
+ }
144
+ const hostId = summary?.hostId || row.dataset.appActionSidebarThreadHostId || "local";
145
+ const key = row.dataset.appActionSidebarThreadId;
146
+ const working = isWorking(row);
147
+ const message = row.querySelector("[data-thread-secondary-title]")?.textContent || "";
148
+ const nativeTime = summary?.recencyAt ?? summary?.updatedAt ?? null;
149
+ const previous = messageUpdates.get(key);
150
+ // 原生流式摘要发生变化时推进时间,不因重绘或打开菜单重置消息时间。
151
+ if (working && (!previous || previous.message !== message || !previous.working)) {
152
+ messageUpdates.set(key, {message, working, time:Math.max(nativeTime || 0, Date.now())});
153
+ } else if (previous) previous.working = working;
154
+ return {
155
+ title:row.dataset.appActionSidebarThreadTitle || row.querySelector("[data-thread-title]")?.textContent || "",
156
+ summary:row.querySelector("[data-thread-secondary-title]")?.textContent || "",
157
+ // 与原生 Thread hover card 相同,优先使用任务 recency 时间。
158
+ timestamp:Math.max(nativeTime || 0, messageUpdates.get(key)?.time || 0) || null,
159
+ hostId, hostName:hostConfig?.display_name || hostId,
160
+ project:projectForRow(row),
161
+ working:isWorking(row),
162
+ attention:attentionState(row),
163
+ };
164
+ }
165
+ function relativeTime(timestamp, now = Date.now()) {
166
+ if (!Number.isFinite(timestamp)) return "";
167
+ const seconds = Math.max(0, Math.floor((now - timestamp) / 1000));
168
+ if (seconds < 60) return text("Just now", "刚刚");
169
+ const units = seconds < 3600 ? [60, "m", "分钟"] : seconds < 86400 ? [3600, "h", "小时"] : [86400, "d", "天"];
170
+ const value = Math.floor(seconds / units[0]);
171
+ return text(value + units[1], value + units[2] + "前");
172
+ }
173
+ function cacheProjectIcons() {
174
+ for (const row of document.querySelectorAll('#app-shell-sidebar [data-app-action-sidebar-project-row]')) {
175
+ const glyph = row.querySelector("span.relative.inline-flex");
176
+ if (glyph) projectIcons.set(row.dataset.appActionSidebarProjectId, glyph.cloneNode(true));
177
+ }
178
+ }
179
+ function close(restoreFocus = false) {
180
+ cancelHoverTimers();
181
+ cancelAnimationFrame(activityFrame); clearTimeout(activityTimer);
182
+ activityFrame = null; activityTimer = null;
183
+ panel.hidden = true;
184
+ if (trigger?.getAttribute("aria-expanded") !== "false") trigger?.setAttribute("aria-expanded", "false");
185
+ if (restoreActivity) {
186
+ restoreActivity = false;
187
+ const native = activityButton();
188
+ if (native?.getAttribute("aria-pressed") === "true") native.click();
189
+ }
190
+ if (restoreFocus) trigger?.focus();
191
+ }
192
+ function position() {
193
+ if (!trigger) return;
194
+ const rect = trigger.getBoundingClientRect();
195
+ const width = Math.min(320, innerWidth - 16);
196
+ panel.style.left = `${Math.max(8, Math.min(rect.left, innerWidth - width - 8))}px`;
197
+ panel.style.top = `${rect.bottom + 8}px`;
198
+ panel.style.maxWidth = `${width}px`;
199
+ panel.style.maxHeight = `${Math.max(0, Math.min(440, innerHeight - rect.bottom - 24))}px`;
200
+ }
201
+ function activityRecords() {
202
+ captureCurrentRow();
203
+ const records = [...document.querySelectorAll('#app-shell-sidebar [data-app-action-sidebar-thread-row]')].map(threadRecord);
204
+ const mounted = new Set(records.map(item => item.key));
205
+ for (const item of records) if (openedAt.has(item.key)) recentRows.set(item.key, item);
206
+ for (const [key, item] of recentRows) if (!mounted.has(key)) records.push({ ...item, working:false, unread:false, attention:null });
207
+ return selectThreads(records, openedAt, Date.now(), selectedKey);
208
+ }
209
+ function syncNotification(details) {
210
+ const color = notificationColor(details);
211
+ if (color) { if (badge?.dataset.notification !== color) badge?.setAttribute("data-notification", color); }
212
+ else badge?.removeAttribute("data-notification");
213
+ }
214
+ function renderRows(details = activityRecords()) {
215
+ syncNotification(details);
216
+ if (!details.length) { close(); return; }
217
+ const next = JSON.stringify([text("Recent activity", "最近活动"), details, Math.floor(Date.now() / 60000)]);
218
+ if (signature === next) return;
219
+ signature = next;
220
+ const scrollTop = panel.querySelector(".mcx-thread-list")?.scrollTop ?? 0;
221
+ const focusedKey = panel.contains(document.activeElement) ? document.activeElement?.dataset.threadKey : null;
222
+ panel.replaceChildren();
223
+ panel.setAttribute("aria-label", text("Recent activity", "最近活动"));
224
+ const heading = document.createElement("h2");
225
+ heading.textContent = text("Recent activity", "最近活动");
226
+ panel.append(heading);
227
+ const list = document.createElement("div");
228
+ list.className = "mcx-thread-list";
229
+ panel.append(list);
230
+ details.forEach(item => {
231
+ const card = document.createElement("button");
232
+ card.type = "button";
233
+ card.dataset.unreadRow = "";
234
+ card.dataset.threadKey = item.key;
235
+ if (item.current) card.setAttribute("aria-current", "page");
236
+ const header = document.createElement("span");
237
+ header.className = "mcx-thread-header";
238
+ const title = document.createElement("span");
239
+ title.className = "mcx-thread-title";
240
+ title.textContent = item.title;
241
+ const device = document.createElement("span");
242
+ device.className = "mcx-device";
243
+ const remote = item.hostId !== "local";
244
+ device.innerHTML = deviceGlyphs[remote ? "remote" : "local"];
245
+ device.title = text("Remote", "远程");
246
+ device.setAttribute("aria-label", device.title);
247
+ header.append(title);
248
+ if (remote) header.append(device);
249
+ const elapsed = relativeTime(item.timestamp);
250
+ if (item.attention) {
251
+ const label = document.createElement("span");
252
+ label.className = "mcx-attention";
253
+ label.dataset.attention = item.attention;
254
+ label.textContent = item.attention === "approval" ? text("Awaiting approval", "等待批准") : text("Needs input", "需要回复");
255
+ header.append(label);
256
+ } else if (item.working) {
257
+ const loading = document.createElement("span");
258
+ loading.className = "mcx-loading";
259
+ loading.setAttribute("role", "status");
260
+ loading.setAttribute("aria-label", text("Working", "正在工作"));
261
+ // 直接复用当前会话原生 loading,保持动画与 reduced-motion 行为一致。
262
+ loading.innerHTML = item.spinner;
263
+ header.append(loading);
264
+ } else if (elapsed) {
265
+ const time = document.createElement("time");
266
+ time.dateTime = new Date(item.timestamp).toISOString();
267
+ time.textContent = elapsed;
268
+ time.title = new Date(item.timestamp).toLocaleString();
269
+ header.append(time);
270
+ }
271
+ card.append(header);
272
+ if (item.summary) {
273
+ const summary = document.createElement("span");
274
+ summary.className = "mcx-summary";
275
+ summary.textContent = item.summary;
276
+ card.append(summary);
277
+ }
278
+ if (item.project) {
279
+ const project = document.createElement("span");
280
+ project.className = "mcx-project";
281
+ const icon = document.createElement("span");
282
+ icon.className = "mcx-project-icon";
283
+ const glyph = projectIcons.get(item.project.id)?.cloneNode(true);
284
+ if (glyph) icon.append(glyph);
285
+ else icon.innerHTML = folderGlyph;
286
+ project.append(icon);
287
+ const name = document.createElement("span");
288
+ name.textContent = item.project.name;
289
+ project.append(name);
290
+ card.append(project);
291
+ }
292
+ card.addEventListener("click", () => {
293
+ if (!item.current) {
294
+ const native = [...document.querySelectorAll('#app-shell-sidebar [data-app-action-sidebar-thread-row]')]
295
+ .find(row => row.dataset.appActionSidebarThreadId === item.key);
296
+ const activate = native ? threadRecord(native).activate : item.activate;
297
+ if (!activate) return;
298
+ activate();
299
+ }
300
+ close();
301
+ });
302
+ list.append(card);
303
+ });
304
+ if (!details.length) {
305
+ const empty = document.createElement("p");
306
+ empty.className = "mcx-empty";
307
+ empty.textContent = text("You're all caught up", "暂无未读会话");
308
+ list.append(empty);
309
+ }
310
+ if (focusedKey) [...list.children].find(card => card.dataset.threadKey === focusedKey)?.focus({ preventScroll:true });
311
+ list.scrollTop = scrollTop;
312
+ }
313
+ function open() {
314
+ if (!trigger) return;
315
+ cacheProjectIcons();
316
+ captureCurrentRow();
317
+ const native = activityButton();
318
+ if (!native) return;
319
+ const details = activityRecords();
320
+ syncNotification(details);
321
+ if (!details.length) return;
322
+ panel.hidden = false;
323
+ trigger.setAttribute("aria-expanded", "true");
324
+ renderRows(details); position();
325
+ // 先呈现浮层,下一帧之后再更新原生 Activity,避免同步 React 切换阻塞点击反馈。
326
+ if (native.getAttribute("aria-pressed") !== "true") {
327
+ activityFrame = requestAnimationFrame(() => {
328
+ activityFrame = null;
329
+ activityTimer = setTimeout(() => {
330
+ activityTimer = null;
331
+ if (disposed || panel.hidden) return;
332
+ const latest = activityButton();
333
+ if (latest?.getAttribute("aria-pressed") === "false") {
334
+ restoreActivity = true; latest.click();
335
+ }
336
+ }, 0);
337
+ });
338
+ }
339
+ }
340
+ function visible(element) {
341
+ return element && !element.closest('[aria-hidden="true"], [inert]') && element.checkVisibility();
342
+ }
343
+ const nativeSidebarIcons = new Map();
344
+ function restoreSidebarIcons() {
345
+ for (const [original, replacement] of nativeSidebarIcons) {
346
+ original.removeAttribute("data-minecodex-sidebar-original"); replacement.remove();
347
+ }
348
+ nativeSidebarIcons.clear();
349
+ }
350
+ function syncSidebarIcons(toggle) {
351
+ for (const [original, replacement] of nativeSidebarIcons) {
352
+ if (!original.isConnected || !toggle.contains(original)) {
353
+ original.removeAttribute("data-minecodex-sidebar-original"); replacement.remove(); nativeSidebarIcons.delete(original);
354
+ }
355
+ }
356
+ for (const original of toggle.querySelectorAll('svg:not([data-minecodex-sidebar-replacement])')) {
357
+ if (nativeSidebarIcons.has(original)) continue;
358
+ const glyph = sidebarGlyphs[original.getAttribute("width")];
359
+ if (!glyph) continue;
360
+ const container = document.createElement("span");
361
+ container.innerHTML = glyph;
362
+ const replacement = container.firstElementChild;
363
+ replacement.setAttribute("class", original.getAttribute("class") || "");
364
+ replacement.setAttribute("data-minecodex-sidebar-replacement", "");
365
+ replacement.setAttribute("data-no-autosize", "true");
366
+ // 不移除 React 所有的 SVG,只切换显示并插入独立资源。
367
+ original.setAttribute("data-minecodex-sidebar-original", "");
368
+ original.after(replacement); nativeSidebarIcons.set(original, replacement);
369
+ }
370
+ }
371
+ function detachTrigger() {
372
+ restoreSidebarIcons();
373
+ binding?.abort(); binding = null;
374
+ if (standalone) trigger?.remove();
375
+ else if (trigger) {
376
+ for (const name of ["data-minecodex-task-title", "data-minecodex-unread", "role", "tabindex", "aria-haspopup", "aria-controls", "aria-expanded", "aria-label"]) trigger.removeAttribute(name);
377
+ }
378
+ badge?.remove(); badge = null; trigger = null;
379
+ }
380
+ function sync() {
381
+ if (disposed) return;
382
+ cacheProjectIcons();
383
+ captureCurrentRow();
384
+ const sidebarToggle = [...document.querySelectorAll("[data-app-shell-sidebar-trigger]")].find(visible);
385
+ if (!sidebarToggle || sidebarToggle.getAttribute("aria-expanded") !== "false") {
386
+ close(); detachTrigger(); return;
387
+ }
388
+ const title = [...document.querySelectorAll('[data-app-shell-titlebar-slot="main"] [data-app-shell-titlebar-content]')]
389
+ .find(e => visible(e) && !e.querySelector("button, [role=tab], [data-app-shell-tab-row]"));
390
+ const tabs = [...document.querySelectorAll('[data-app-shell-tab-row][role=presentation]')].find(visible);
391
+ const target = title || tabs;
392
+ if (!target) { close(); detachTrigger(); return; }
393
+ const needsStandalone = !title;
394
+ if (!trigger?.isConnected || standalone !== needsStandalone || (title ? trigger !== title : trigger.parentElement !== target)) {
395
+ close(); detachTrigger(); standalone = needsStandalone;
396
+ binding = new AbortController();
397
+ if (title) {
398
+ trigger = title;
399
+ trigger.setAttribute("data-minecodex-task-title", "");
400
+ trigger.setAttribute("role", "button");
401
+ trigger.tabIndex = 0;
402
+ } else {
403
+ trigger = document.createElement("button");
404
+ trigger.type = "button";
405
+ trigger.className = "no-drag pointer-events-auto flex items-center justify-center gap-1 rounded-lg text-tertiary hover:bg-primary-ghost-hover button-toolbar px-2";
406
+ target.prepend(trigger);
407
+ }
408
+ trigger.setAttribute(marker, "trigger");
409
+ trigger.setAttribute("aria-haspopup", "dialog");
410
+ trigger.setAttribute("aria-controls", panel.id);
411
+ trigger.setAttribute("aria-expanded", "false");
412
+ badge = document.createElement("span");
413
+ badge.setAttribute("data-minecodex-task-badge", "");
414
+ badge.innerHTML = taskGlyph;
415
+ trigger.prepend(badge);
416
+ trigger.addEventListener("click", event => { event.stopPropagation(); if (panel.hidden) open(); }, {signal:binding.signal});
417
+ trigger.addEventListener("pointerenter", scheduleHoverOpen, { signal:binding.signal });
418
+ trigger.addEventListener("pointerleave", scheduleHoverClose, { signal:binding.signal });
419
+ trigger.addEventListener("keydown", event => {
420
+ if (["Enter", " ", "ArrowDown"].includes(event.key)) {
421
+ event.preventDefault(); event.stopPropagation();
422
+ if (event.key === "ArrowDown" || panel.hidden) open(); else close();
423
+ }
424
+ }, {signal:binding.signal});
425
+ }
426
+ syncSidebarIcons(sidebarToggle);
427
+ const details = activityRecords();
428
+ syncNotification(details);
429
+ const label = text("Recent activity", "最近活动");
430
+ if (trigger.getAttribute("aria-label") !== label) trigger.setAttribute("aria-label", label);
431
+ if (!panel.hidden) { renderRows(details); position(); }
432
+ }
433
+ const observer = new MutationObserver(() => {
434
+ if (queued) return;
435
+ queued = true;
436
+ queueMicrotask(() => { queued = false; sync(); });
437
+ });
438
+ observer.observe(document.documentElement, { childList:true, subtree:true, attributes:true, attributeFilter:["aria-expanded", "aria-pressed", "aria-hidden", "data-app-shell-header-layout", "data-app-action-sidebar-thread-selected", "lang"] });
439
+ document.addEventListener("pointerdown", event => { if (!trigger?.contains(event.target) && !panel.contains(event.target)) close(); }, { signal });
440
+ document.addEventListener("keydown", event => { if (event.key === "Escape" && !panel.hidden) { event.preventDefault(); close(true); } }, { signal });
441
+ window.addEventListener("resize", position, { signal });
442
+ const refreshTimer = setInterval(sync, 30000);
443
+ sync();
444
+ return () => {
445
+ disposed = true; clearInterval(refreshTimer); observer.disconnect(); close(); detachTrigger(); panel.remove(); style.remove();
446
+ };
@@ -0,0 +1,49 @@
1
+ # Usage Meter
2
+
3
+ ## 用户任务与范围
4
+
5
+ 在原生导航栏 Help 与 Account 之间查看当前账号剩余额度,点击直达 Settings → Usage。
6
+ 仅向 `nav[data-app-navigation-rail="true"]` 注入一个控件,不注册通用侧栏
7
+ 菜单项,不向 Settings 的分类列表插入内容。
8
+
9
+ ## 数据契约
10
+
11
+ 已在 2026-09-29 的运行中 Codex 确认:原生 QueryClient 的成功额度数据缓存键为
12
+ `["rate-limit-status"]`,由 Codex 自行更新。
13
+ 插件只订阅该缓存,校验响应的 user_id/account_id 与当前原生 auth 一致,不自行请求
14
+ 接口,不持久化账号或额度数据。切换账号、退出登录、额度数据缺失时隐藏旧值。
15
+
16
+ 窗口按 `limit_window_seconds` 识别:604800 为周、18000 为五小时;不依赖
17
+ primary/secondary 顺序或套餐字符串。剩余百分比为 clamp(100-used_percent,0,100),
18
+ 四舍五入显示整数。缺失/非法值不当成零。
19
+
20
+ 单周窗口显示一个周环和周剩余数字。周与五小时同时存在时,周在外、五小时在内,
21
+ 中央显示五小时剩余数字,不带百分号。没有周窗口时不显示本控件。
22
+
23
+ ## 视觉 tokens
24
+
25
+ | 角色 | 权威 token / 值 | 用途 |
26
+ | --- | --- | --- |
27
+ | 点击区域 | 克隆 Help 的原生按钮 class 和 data 样式属性;当前 36×36px | 与导航项对齐 |
28
+ | 环图 | 24×24px;viewBox 32;圆心 16;周半径 43/3、五小时半径 10.5;描边 10/3 viewBox units(渲染 2.5px) | 自定义数据图,不是替代导航图标 |
29
+ | 周环 | 继承 Help 按钮的 `currentColor`(原生 tertiary 中性灰) | 单圈或外圈 |
30
+ | 五小时环 | `--color-text-secondary`(中性灰) | 双圈内圈 |
31
+ | 轨道 | 对应环色 18% alpha | 剩余额度的底轨 |
32
+ | 中央数字 | 继承 Help 的颜色;`--font-sans-default`;`--text-xs` × 2/3(8px),单双圈与三位数均一致;500、tabular-nums、line-height:1 | 优先五小时 |
33
+ | Tooltip | `--color-background-tooltip` / `--color-text-tooltip` / `--color-border-tooltip` / `--shadow-tooltip` | 与原生 Help Tooltip 一致 |
34
+ | Tooltip 几何 | `--radius-2xl`;5px 12px padding;`--text-sm` / 18px;两列 gap 16px | label 左、数字右对齐 |
35
+ | Tooltip 字体 | `--tooltip-compact-font-weight` / `--tracking-tooltip` | 与原生紧凑提示一致 |
36
+
37
+ 环从顶部顺时针填充。Tooltip 在按钮右侧 2px,纵向居中并约束在窗口内;
38
+ 鼠标悬停延迟 350ms,键盘聚焦立即显示,Escape 隐藏。单圈一行 Weekly Limit;
39
+ 双圈依次为 5h Limit、Weekly Limit,数值带 %。没有额外标题或说明。
40
+
41
+ 原生 Help 图标为 20px,点击区域 36px。Account 头像可见直径为 24px;额度外环含描边的可见直径同为 24px,
42
+ 数字与环均以按钮几何中心对齐;中性灰取自原生 navbar,不使用彩色强调。
43
+ 单双圈使用同一实现,双圈验收图采用模拟值,不更改账号缓存。减少动画偏好不添加进度过渡。
44
+
45
+ ## 跳转与生命周期
46
+
47
+ 已确认原生入口指向 `/settings/usage?tab=overview`。使用当前 React Router
48
+ 的 navigate,并保留当前路由 state;不模拟设置菜单内部点击。
49
+ 移除功能时清除缓存订阅、DOM observer、事件、Tooltip 与按钮。
@@ -0,0 +1,18 @@
1
+ # Usage Meter · 额度环
2
+
3
+ 在 Codex 原生 navbar 的 Help 与 Account 之间显示当前登录账号的**剩余额度**。
4
+
5
+ - 只有周额度:单圈,中心为周剩余百分比整数。
6
+ - 同时有周与五小时额度:外圈为周、内圈为五小时,中心显示五小时剩余数字。
7
+ - 悬浮或键盘聚焦显示 Tooltip;双圈时先显示 `5h Limit`,再显示 `Weekly Limit`,标签左对齐、百分比右对齐。
8
+ - 点击进入原生 Settings → Usage。
9
+
10
+ 数据直接订阅当前账号的原生额度缓存,与 Usage 页同步。窗口类型按实际时长识别,
11
+ 不通过套餐名称猜测。缺失数据、退出登录或切换账号时不展示旧额度。
12
+ 不新增 API 请求,不持久化账号信息,不修改 Settings 分类导航。
13
+
14
+ MineCodex 管理页面可单独开关此功能。设计与原生接入契约见 [DESIGN.md](DESIGN.md)。
15
+
16
+ ```bash
17
+ node --test features/usage-meter/test/*.test.mjs
18
+ ```
@@ -0,0 +1,13 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "usage-meter",
4
+ "version": "0.1.0",
5
+ "label": { "en": "Usage Meter", "zh-CN": "额度环" },
6
+ "description": {
7
+ "en": "Show remaining weekly and 5-hour limits between Help and Account and open Usage settings.",
8
+ "zh-CN": "在 Help 与 Account 之间显示周与五小时剩余额度,点击进入 Usage 设置。"
9
+ },
10
+ "entry": { "kind": "page-script", "script": "src/usage-meter.mjs" },
11
+ "icon": { "viewBox": "0 0 24 24", "markup": "<circle cx=\"12\" cy=\"12\" r=\"9\"></circle><circle cx=\"12\" cy=\"12\" r=\"5\"></circle>" },
12
+ "placement": { "order": 60 }
13
+ }