ai_co_discuss 0.5.40 → 0.5.42

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 (59) hide show
  1. package/.agents/skills/discuss-goal/SKILL.md +1 -1
  2. package/.agents/skills/discuss-host/references/room.md +4 -4
  3. package/.agents/skills/discuss-participant/SKILL.md +3 -1
  4. package/.agents/skills/discuss-participant/references/interactive-html.md +35 -8
  5. package/.agents/skills/discuss-participant/references/visual-examples.md +41 -18
  6. package/README.md +2 -2
  7. package/README.zh-CN.md +2 -2
  8. package/backend/analytics.py +24 -2
  9. package/backend/analytics_issues.py +210 -0
  10. package/backend/free_room.py +21 -9
  11. package/backend/questions.py +3 -2
  12. package/backend/server.py +11 -3
  13. package/docs/deployment.md +1 -1
  14. package/docs/en/deployment.md +1 -1
  15. package/docs/en/guide/admin.md +9 -9
  16. package/docs/en/guide/analytics.md +13 -18
  17. package/docs/en/guide/faq.md +1 -1
  18. package/docs/en/guide/goal.md +1 -1
  19. package/docs/en/guide/remote.md +2 -2
  20. package/docs/en/guide/rooms.md +4 -4
  21. package/docs/en/guide/scheduling.md +1 -1
  22. package/docs/en/guide/voice.md +5 -4
  23. package/docs/en/guide/working.md +2 -2
  24. package/docs/guide/admin.md +9 -9
  25. package/docs/guide/analytics.md +13 -18
  26. package/docs/guide/faq.md +1 -1
  27. package/docs/guide/goal.md +1 -1
  28. package/docs/guide/remote.md +2 -2
  29. package/docs/guide/rooms.md +4 -4
  30. package/docs/guide/scheduling.md +1 -1
  31. package/docs/guide/voice.md +5 -4
  32. package/docs/guide/working.md +2 -2
  33. package/frontend/locales/en/admin.json +29 -1
  34. package/frontend/locales/en/analytics.json +62 -42
  35. package/frontend/locales/en/app.json +1 -1
  36. package/frontend/locales/en/backend.json +9 -2
  37. package/frontend/locales/en/backend_worker.json +4 -0
  38. package/frontend/locales/en/external.json +3 -0
  39. package/frontend/locales/en/room.json +6 -1
  40. package/frontend/locales/en/settings.json +15 -2
  41. package/package.json +1 -1
  42. package/runner/adapters/api.mjs +1 -1
  43. package/runner/admin_cli.mjs +8 -8
  44. package/runner/admin_panel.mjs +11 -11
  45. package/runner/discuss.py +1 -1
  46. package/runner/discussion_launch.mjs +2 -2
  47. package/runner/external_gateway.mjs +2 -2
  48. package/runner/free_runner.mjs +9 -8
  49. package/runner/i18n_en.mjs +14 -13
  50. package/runner/scheduler.mjs +21 -15
  51. package/runner/session_driver.mjs +3 -1
  52. package/runner/site_deploy.mjs +8 -4
  53. package/runner/weixin.mjs +32 -9
  54. package/web/admin.css +1 -1
  55. package/web/admin.js +3 -3
  56. package/web/app.js +5 -4
  57. package/web/i18n.js +4 -4
  58. package/web/modern.css +1 -1
  59. package/web/modern.js +169 -93
@@ -27,7 +27,7 @@ description: "AI CoDiscuss 的 Goal 模式主持技能,仅主持人调用,
27
27
  |---|---|---|
28
28
  | 推进中 | `goal state ROOM --state doing --revision REV` | 默认:房间空闲满用户设定的时长(默认 2 分钟)就唤醒你 |
29
29
  | 等待后台 | `goal state ROOM --state waiting --revision REV --note-file 草稿 [--minutes N]` | 空闲时不唤醒;到时限(默认 30 分钟)兜底唤醒一次 |
30
- | 待用户确认 | `goal state ROOM --state pending --revision REV --note-file 草稿 [--minutes N]` | 空闲时不唤醒;5 分钟后用户仍未回复且绑定了微信时发微信通知;到时限(默认 60 分钟)兜底唤醒一次 |
30
+ | 待用户确认 | `goal state ROOM --state pending --revision REV --note-file 草稿 [--minutes N]` | 空闲时不唤醒;3 分钟后用户仍未回复且绑定了微信时发微信通知;到时限(默认 60 分钟)兜底唤醒一次 |
31
31
 
32
32
  - 待确认的 note 写清要用户做什么,它会原样出现在微信通知里。要用户在几个选项里拍板时改用阻塞提问,不必声明待确认,见参与技能 [回答房间请求](../discuss-participant/references/room.md)“需要用户决定时”。
33
33
  - 后台工作回来、接着推进前改回 `doing`;忘了改到时限也会兜底唤醒。用户发言后、每次被续跑唤醒时状态都自动回到推进中,需要时重新声明。
@@ -15,10 +15,10 @@
15
15
 
16
16
  任务的 `request_purposes` 说明每条请求为何交给你。先 `room view` 看成员与状态,再决定由谁处理。
17
17
 
18
- - `route`:用户未点名的消息,或全体调度交回的原问题,由你回答或分派;全体调度未代办时仍须读原文再安排。
19
- - `handoff`:你派出的成员都已结束(含失败)。交给其他成员或汇总给用户;成员的回答已完整时只用一两句说明完成,不复述。
20
- - `notice`:程序发现了要你处理的事(成员失败、某一棒失败、重试结果、你要求的续跑、定时检查、你自己失败),消息写明是什么,按 [房间控制与恢复](control.md) 处理。你已有待处理请求时,程序只把通知写进记录、不另建请求:处理任何请求时,新消息里作者为“系统”的通知同样要处理。
21
- - `all`:用户请全体成员各自回应一次,其他成员已同时收到;先独立回答自己的部分,不加 `--to`。用户用 `@全体成员` 点名时,所有人答完后程序会再发一条 `notice` 请你汇总:读各成员回答,写共识、分歧与你的取舍,需要时再派活;回应很简单(如打招呼、报模型)时一两句收尾即可。
18
+ - `route`:用户未点名的消息,或全体调度交回的原问题,由你回答或分派;全体调度未代办时仍须读原文再安排。用户只是表示收到、致谢或留备注时,简短收尾,不派活。
19
+ - `handoff`:你派出的成员都已结束(含失败)。请求的 `outcome` 每项带成员回答的 `message_id`,按编号 `message view` 读,不靠翻页去找。交给其他成员或汇总给用户;成员的回答已完整时只用一两句说明完成,不复述。
20
+ - `notice`:程序发现了要你处理的事(成员失败、某一棒失败、重试结果、你要求的续跑、定时检查、你自己失败),消息写明是什么,按 [房间控制与恢复](control.md) 处理;派出的工作在你继续工作时结束、或重试后结束,交回通知同样列出回答编号。你已有待处理请求时,程序只把通知写进记录、不另建请求:处理任何请求时,新消息里作者为“系统”的通知同样要处理。
21
+ - `all`:用户请全体成员各自回应一次,其他成员已同时收到;先独立回答自己的部分,不加 `--to`。用户用 `@全体成员` 点名时,所有人答完后程序会再发一条 `notice` 请你汇总:通知列出每位成员的回答编号,按编号 `message view` 逐条读,再写共识、分歧与你的取舍,需要时再派活;回应很简单(如打招呼、报模型)时一两句收尾即可。
22
22
  - `goal_start`、`goal_continue`:按技能 [discuss-goal](../../discuss-goal/SKILL.md) 处理。
23
23
  - `discuss_start`:用户发了 `/discuss`。消息带文本时以原文为准,只整理措辞;没带时从最近对话提炼,提炼不出明确的讨论问题就不开启,直接回答并说明缺什么。开启:`run start ROOM --request 请求编号 --goal-file 草稿`,上限用房间默认值,你不设置;然后照常简短回答,之后程序会给你讨论主持任务。
24
24
  - 用户只点名你(旁问,如问近况、是否卡住):读进行中执行的详情(有接力时加 `sequence view`、`room events`)后直接回答,进行中的工作照常。旁问里的新任务涉及正在工作的成员或同一批文件时,等交回后再派,或先撤回原派活;互不相干的可以马上派。
@@ -18,7 +18,7 @@ description: "AI CoDiscuss 的通用参与技能,所有参与者(包括主
18
18
  | 手动成员注册、原会话或手动回答 | [手动接入](references/manual.md) |
19
19
  | 写入结果不明、被拒、超长正文 | [写入与恢复](references/writing.md) |
20
20
  | 接力(`sequence`)、向用户提问(`question`)、生图(`image`)、主动发言 | [按需场景](references/situations.md) |
21
- | 回答需要用户亲手操作的演示(交互式可视化,正文里的 `visual` 代码块) | [交付交互式可视化](references/interactive-html.md) |
21
+ | 用户要求“图文并茂”,或一张图、一个可操作的演示比文字讲得更清楚(交互式可视化,正文里的 `visual` 代码块) | [交付交互式可视化](references/interactive-html.md) |
22
22
  | 为本房间或指定房间制作分享卡封面 | [share-card](../share-card/SKILL.md) |
23
23
 
24
24
  ## 硬约束
@@ -55,6 +55,8 @@ description: "AI CoDiscuss 的通用参与技能,所有参与者(包括主
55
55
 
56
56
  用请求者使用的语言回答,结论先行;篇幅与结构由你按问题决定。正文约 300 字以上或分多段时写摘要:给只听语音播报的人,约 15 秒念完(不超过约 80 字),用能直接念出口的话、不用列表和编号。
57
57
 
58
+ **图文并茂**:讲结构、流程、对比、数据或参数影响时,主动配一张 `visual` 图示(静态图也行),不必等用户要求;用户说“图文并茂”时一定配。一条回答通常一两张,图只放文字讲不清的部分,简单问答不配。写法见 [交付交互式可视化](references/interactive-html.md)。
59
+
58
60
  **给人看的成品默认作为附件交付**:这次新建或改出、请求者要看或要拿走的结果(文档、表格、幻灯片、PDF、图片、音视频、放不进正文的大网页,或它们的打包;要在正文里直接运行的页面写成 `visual` 代码块,不另附),上传为附件,正文用 `[文件 #n]`(图片 `[图片 #n]`)引用(n 是该文件在本条 `--attachment` 中的先后序号,从 1 起,不是附件 ID;提交后程序换成房间内的统一编号);改了已交付的成品就附上新版。(附件随消息保存、卡片内直接预览,分享页、其他设备和外部成员都看得到;项目文件之后会变,也只有能读这台电脑的人看得到。)项目源码与配置的修改、中间产物和日志不附(执行卡片已显示文件差异)。用户说了只放项目里的也不附,正文用反引号写出它的项目路径(如 `合同.docx`),回答下方会出现该文件的卡片。
59
61
 
60
62
  附件先 `attachment upload ROOM --file FILE --submission-id 上传编号`,再 `message post --attachment ID`(最多 10 个,单个 20 MiB,须在执行资格结束前上传)。
@@ -1,10 +1,10 @@
1
1
  # 交付交互式可视化
2
2
 
3
- 只在你判断回答需要用户亲手操作(拖动参数看变化、点开分步讲解、可点的界面原型)时读本页。怎么设计页面由你决定;本页只写房间网页怎样显示它、给了页面什么、有哪些限制。
3
+ 用于图文并茂的回答:静态图示(结构图、流程图、对比图、数据图)和需要用户亲手操作的演示(拖动参数看变化、点开分步讲解、可点的界面原型)。画什么由你决定;本页写房间网页怎样显示它、统一的控件样式和必须遵守的限制。
4
4
 
5
5
  ## 写法:正文里的 `visual` 代码块
6
6
 
7
- 在回答正文里写一个信息串恰好为 `visual` 的围栏代码块,内容是一份自包含的 HTML(完整文档或片段都行)。网页在代码块所在位置直接显示并运行它,外面由房间加一圈淡边框和少量内边距与正文区分,高度随内容;页面自己不要再画外框和底色;下方一行小字可收起、看源码、放大到预览窗口、在新标签页打开、下载。手机上同样就地显示。
7
+ 在回答正文里写一个信息串恰好为 `visual` 的围栏代码块,内容是一份自包含的 HTML(完整文档或片段都行)。网页在代码块所在位置直接显示并运行它,外面由房间加一圈淡边框和少量内边距与正文区分,高度随内容;页面自己不要再画外框和底色。右上角有房间的工具按钮:电脑上悬停时浮在页面右上角约 150×32px 的范围,不放必须随时看得到或点得到的东西;手机上工具是框内单独的第一行(名称在左,“…”和收起在右上角),在页面上方、不遮挡页面。手机上同样就地显示。
8
8
 
9
9
  ````markdown
10
10
  前面写引出它的话。
@@ -38,6 +38,35 @@
38
38
  - 优先用原生控件(滑块、复选框、下拉框);拖拽只作增强,同时提供上移、下移按钮。
39
39
  - 面板里的得分、估算由你给出时,写明依据,凭判断的标“假设”;交回的结论带上前提(如“在这组得分下选 A”),别让精确的数字显得比依据更可靠。
40
40
 
41
+ ## 外观:克制、两端、两种主题
42
+
43
+ - **像正文里的插图,不像另一个网页**:不加标题栏、外框、阴影、渐变、大色块和装饰图标;强调色只给关键数据和主操作,其余用正文色、次要色和边框色。
44
+ - **电脑和手机竖屏都要好用**(用户另有要求除外):正文栏在电脑上约 600–800px,手机约 340px。用 `cd-grid`、`cd-row`、`flex-wrap` 让并排的块在窄屏自动换行;SVG 用 `viewBox` 加 `class="cd-chart"`:图形随栏宽等比缩放,里面的文字和 `cd-*` 线条在屏幕上保持固定大小(约 11–13px),所以手机上图形变小而字不变小。`viewBox` 宽度取 400–480,文字四周留出余量(靠边的刻度离边缘至少 20、文字与相邻图形间隔至少 8,按 `viewBox` 单位算),否则手机上文字会被裁掉或压到图形;可点的控件高度不小于约 32px。
45
+ - **深浅两套主题都要好看**:颜色只用下表变量,并写兜底值;不写死任何颜色(包括白色文字)。
46
+ - **控件用房间的统一样式,不自己画**:下面的默认样式和 `cd-*` 类已注入,直接用;只有它们表达不了时才补自己的 CSS,补的也只引用变量。
47
+
48
+ ## 统一样式
49
+
50
+ 已注入、直接生效的:`button`、`select`、`textarea`、文本类 `input` 有边框、圆角和内边距,字号比正文小一档,高度不低于 32px,悬停与焦点有反馈;按钮是淡底,下拉框自带箭头;滑块是细轨道,已选部分自动填强调色,圆点为强调色;复选框、单选框用强调色;`table` 有细分隔线、表头用提示色小字;所有元素 `box-sizing: border-box`。
51
+
52
+ 按需加的类(都是低优先级,页面自己的规则可覆盖):
53
+
54
+ | 类 | 用途 |
55
+ |---|---|
56
+ | `cd-wrap` | 外层容器,最宽 640px 居中 |
57
+ | `cd-stack` / `cd-row` / `cd-between` / `cd-grid` | 纵向间距 / 横排可换行 / 两端对齐可换行 / 自适应多列(窄屏变一列) |
58
+ | `cd-stats` + `cd-stat` | 关键数字行:`<div class="cd-stat"><b>40.8</b><span>射程 m</span></div>` |
59
+ | `cd-field` | 一行参数:`<label class="cd-field"><span>角度</span><input type="range"><output></output></label>`,手机上滑块自动换到下一行 |
60
+ | `cd-primary` | 主操作按钮(强调色淡底),一个页面最多一个 |
61
+ | `cd-tabs` | 分段切换:内放 `button`,选中项写 `aria-pressed="true"` |
62
+ | `cd-card` | 需要与背景区分的色块(正文色的淡底,深浅色下都看得出) |
63
+ | `cd-muted` / `cd-hint` / `cd-accent` | 次要文字 / 提示小字 / 强调色文字 |
64
+ | `cd-chart` | 自适应宽度的 `svg`;其中的 `text` 默认正文色、屏幕上约 12px |
65
+ | `cd-axis` / `cd-gridline` / `cd-tick` / `cd-label` | SVG 坐标轴 / 虚线网格 / 刻度文字(提示色,约 11px)/ 标注文字(约 13px) |
66
+ | `cd-line` / `cd-line-muted` | SVG 主曲线(强调色)/ 参照线(虚线) |
67
+ | `cd-box` / `cd-box-accent` | SVG 节点框:中性淡底加细边 / 淡强调色底加强调色边(只给关键节点) |
68
+ | `cd-fill` / `cd-fill-soft` / `cd-fill-muted` | SVG 实心强调色 / 淡强调色 / 中性灰(柱、面积、箭头) |
69
+
41
70
  ## 房间给页面的东西
42
71
 
43
72
  房间往页面里注入一份基础样式和下面的变量。变量在页面载入后送到,用户切换深浅色时再送一次。
@@ -49,22 +78,20 @@
49
78
  | `--codiscuss-text-hint` | 提示文字、刻度 |
50
79
  | `--codiscuss-border` | 边框、分隔线、坐标轴 |
51
80
  | `--codiscuss-accent` | 强调色 |
52
- | `--codiscuss-card` | 卡片底色(控件底、需要与背景区分的色块) |
81
+ | `--codiscuss-card` | 卡片底色,与消息的底色相同:用来盖住下层内容,做不出看得见的色块(色块用 `cd-card`) |
53
82
  | `--codiscuss-font-family`、`--codiscuss-font-size` | 房间正文的字体与字号 |
54
83
  | `--codiscuss-radius` | 圆角 |
55
84
  | `--codiscuss-color-scheme` | `light` 或 `dark` |
56
85
 
57
86
  已由房间设好、页面改不了的:`html` 和 `body` 透明底、外边距为 0;`body` 的文字颜色、字体、字号;深浅色。
58
87
 
59
- 已有默认外观、可以覆盖的:`button`、`select`、文本类 `input` 有边框、圆角、底色和内边距;滑块、复选框、单选框用强调色;键盘焦点有描边。
60
-
61
88
  ## 约束
62
89
 
63
- - **不设页面底色,不设 `body` 字体和颜色**:设了也不生效。需要色块时用 `--codiscuss-card`。
90
+ - **不设页面底色,不设 `body` 字体和颜色**:设了也不生效。需要色块时用 `cd-card`。
64
91
  - **颜色只用变量,并写兜底值**:如 `var(--codiscuss-accent, #2563eb)`。放大的预览窗口、手机全屏和新标签页也注入房间主题,兜底值用于变量到达前或下载后直接打开时。不写 `prefers-color-scheme`,深浅色由房间决定。
65
92
  - **颜色写在 CSS 里**(SVG 用 `fill`、`stroke` 引用变量),不在脚本里读一次存起来:变量晚于页面脚本到达,切换主题时还会变。
66
93
  - **不写固定高度**:房间测量 `body` 的实际高度来定显示高度,内容多高就显示多高,框内不出现滚动条。不用 `100vh`、`height: 100%` 撑满:框的高度就是量到的内容高度,撑满后不会再缩回去;页面很长时考虑拆成几块或用分步切换。
67
- - **不写固定宽度**:显示宽度等于正文栏,随窗口变化;预览窗口更宽。内容设宽度上限并居中,窄到 320px 时仍能用。字号用 `em`,跟随房间字号。
94
+ - **不写固定宽度**:显示宽度等于正文栏,随窗口变化;预览窗口更宽。内容设宽度上限并居中,窄到 320px 时仍能用。字号用 `em`,跟随房间字号。交付前按 340px 与 720px 两种宽度各想一遍排版。
68
95
  - **没有网络**:外部脚本、样式、字体、图片和 `fetch` 都被拦截,CDN 上的库载不进来。CSS、JS、数据都写进代码块;图片用 data URL 或内联 SVG。
69
96
  - **只能运行脚本**:`alert`、`confirm`、打开新窗口、提交表单都不可用。页面读不到房间、网站接口和 Cookie,`localStorage` 不可用(读写放进 `try`)。页面不能写回房间,也不能唤醒成员。
70
97
  - **状态不会保存**:页面滚到附近才开始运行,之后一直保留;但收起、切换房间或刷新后会重新运行,用户调过的参数回到初始值。默认参数要能说明问题。
@@ -73,4 +100,4 @@
73
100
 
74
101
  ## 示例
75
102
 
76
- 写页面前读 [交互式可视化示例](visual-examples.md):一个纯展示,一个提问面板(调权重看排名并交回)。
103
+ 写页面前读 [交互式可视化示例](visual-examples.md):滑块联动的展示、静态流程图、提问面板(调权重看排名并交回)。
@@ -1,27 +1,27 @@
1
1
  # 交互式可视化示例
2
2
 
3
- 写页面前按需读一个,照结构改,不必照抄题材。规则与约束见 [交付交互式可视化](interactive-html.md)。
3
+ 写页面前按需读一个,照结构改,不必照抄题材。优先用统一样式(`cd-*` 类,见规则页),示例 3 的权重滑块要在轨道上画“第一名不变”的区间,统一滑块表达不了,才自己画。规则与约束见 [交付交互式可视化](interactive-html.md)。
4
4
 
5
5
  ## 1. 展示:一个量变了,图跟着变
6
6
 
7
+ 全部用统一样式:`cd-stats` 放关键数字,`cd-field` 放滑块,几乎不写自己的 CSS。
8
+
7
9
  ````markdown
8
10
  年数越长,复利效果越明显:默认 20 年,1000 元变成约 3870 元。
9
11
 
10
12
  ```visual
11
13
  <style>
12
- .wrap { max-width: 560px; margin: 0 auto; }
13
- .muted { color: var(--codiscuss-text-muted, #6b7280); }
14
- .result { font-size: 1.8em; font-weight: 600; font-variant-numeric: tabular-nums; margin: 0; }
15
- .bar { height: 6px; margin: .8em 0; border-radius: 3px; background: var(--codiscuss-border, #d4d4d8); }
14
+ .bar { height: 6px; margin: .9em 0; border-radius: 3px; background: color-mix(in srgb, var(--codiscuss-border, #d4d4d8) 70%, transparent); }
16
15
  .bar i { display: block; height: 100%; border-radius: 3px; background: var(--codiscuss-accent, #2563eb); }
17
- .row { display: flex; gap: 1em; align-items: center; }
18
- .row input { flex: 1; }
19
16
  </style>
20
- <div class="wrap">
21
- <p class="result" id="result"></p>
22
- <p class="muted">本金 1000,年化 7%</p>
17
+ <div class="cd-wrap">
18
+ <div class="cd-stats">
19
+ <div class="cd-stat"><b id="result"></b><span>到期金额(元)</span></div>
20
+ <div class="cd-stat"><b id="times"></b><span>本金倍数</span></div>
21
+ </div>
23
22
  <div class="bar"><i id="fill"></i></div>
24
- <label class="row"><span>年数</span><input id="years" type="range" min="1" max="40" value="20"><output id="out" class="muted"></output></label>
23
+ <label class="cd-field"><span>年数</span><input id="years" type="range" min="1" max="40" value="20"><output id="out"></output></label>
24
+ <p class="cd-hint">本金 1000,年化 7%</p>
25
25
  </div>
26
26
  <script>
27
27
  const PRINCIPAL = 1000, RATE = 0.07, MAX_YEARS = 40;
@@ -30,6 +30,7 @@ function render() {
30
30
  const count = Number(years.value), value = PRINCIPAL * (1 + RATE) ** count;
31
31
  document.getElementById('out').textContent = count + ' 年';
32
32
  document.getElementById('result').textContent = Math.round(value).toLocaleString();
33
+ document.getElementById('times').textContent = (value / PRINCIPAL).toFixed(1) + '×';
33
34
  document.getElementById('fill').style.width = 100 * value / (PRINCIPAL * (1 + RATE) ** MAX_YEARS) + '%';
34
35
  }
35
36
  years.oninput = render;
@@ -40,7 +41,31 @@ render();
40
41
  拖到 40 年约 14975 元:后 20 年多赚的钱,是前 20 年的近 4 倍。
41
42
  ````
42
43
 
43
- ## 2. 提问面板:调权重看方案排名
44
+ ## 2. 静态图示:流程或结构
45
+
46
+ 图文并茂不一定要能操作。用 SVG 加 `cd-*` 类画,`viewBox` 宽度取 400–480;没有脚本也行。
47
+
48
+ ````markdown
49
+ 一条消息从发出到被回答,经过三步:
50
+
51
+ ```visual
52
+ <svg class="cd-chart" viewBox="0 0 460 104" role="img" aria-label="消息处理流程">
53
+ <defs><marker id="arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L8 4L0 8z" class="cd-fill-muted"/></marker></defs>
54
+ <rect x="4" y="14" width="120" height="48" rx="8" class="cd-box"/>
55
+ <text x="64" y="38" text-anchor="middle" dominant-baseline="central" class="cd-label">用户发消息</text>
56
+ <rect x="170" y="14" width="120" height="48" rx="8" class="cd-box"/>
57
+ <text x="230" y="38" text-anchor="middle" dominant-baseline="central" class="cd-label">主持人分派</text>
58
+ <rect x="336" y="14" width="120" height="48" rx="8" class="cd-box-accent"/>
59
+ <text x="396" y="38" text-anchor="middle" dominant-baseline="central" class="cd-label" style="font-weight:600">成员回答</text>
60
+ <path d="M126 38H166M292 38H332" class="cd-axis" marker-end="url(#arrow)"/>
61
+ <text x="230" y="90" text-anchor="middle" class="cd-tick">点名某位成员时跳过分派</text>
62
+ </svg>
63
+ ```
64
+ ````
65
+
66
+ 节点默认用中性的 `cd-box`,只给关键节点 `cd-box-accent` 加粗体文字;文字不要压在实心强调色(`cd-fill`)上,深色主题下看不清。图里的文字在手机上不随图形缩小,所以文字与相邻图形之间留出余量(这里说明文字离节点底边 20 多个单位),文字用 `dominant-baseline="central"` 对准节点中线。
67
+
68
+ ## 3. 提问面板:调权重看方案排名
44
69
 
45
70
  属于问题卡做不到的“联动计算”:用户拖权重,排名当场重算,每个权重的轨道上标出第一名不变的区间;点按钮交回权重与选择。要点:
46
71
 
@@ -78,10 +103,10 @@ render();
78
103
  .slider input { position: absolute; inset: 0; width: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
79
104
  .slider input::-webkit-slider-runnable-track { height: 22px; background: transparent; }
80
105
  .slider input::-moz-range-track { height: 22px; background: transparent; }
81
- .slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: 4px; border-radius: 50%; background: var(--codiscuss-accent, #2563eb); border: 2px solid var(--codiscuss-card, #fff); box-shadow: 0 0 0 1px var(--codiscuss-accent, #2563eb); }
82
- .slider input::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--codiscuss-accent, #2563eb); border: 2px solid var(--codiscuss-card, #fff); box-shadow: 0 0 0 1px var(--codiscuss-accent, #2563eb); }
106
+ .slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: 4px; border: 0; border-radius: 50%; background: var(--codiscuss-accent, #2563eb); }
107
+ .slider input::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--codiscuss-accent, #2563eb); }
83
108
  .slider input:focus-visible { outline: none; }
84
- .slider input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--codiscuss-accent, #2563eb), 0 0 0 5px color-mix(in srgb, var(--codiscuss-accent, #2563eb) 25%, transparent); }
109
+ .slider input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px color-mix(in srgb, var(--codiscuss-accent, #2563eb) 24%, transparent); }
85
110
  .weight .note { margin-top: .15em; font-size: .78em; color: var(--codiscuss-text-hint, #9ca3af); }
86
111
  details { margin-top: 1.2em; font-size: .85em; color: var(--codiscuss-text-muted, #6b7280); }
87
112
  summary { cursor: pointer; width: fit-content; }
@@ -91,8 +116,6 @@ th { color: var(--codiscuss-text-hint, #9ca3af); }
91
116
  .basis { margin: .5em 0 0; line-height: 1.6; }
92
117
  .foot { display: flex; gap: 1em; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 1.2em; }
93
118
  .foot .hint { font-size: .82em; color: var(--codiscuss-text-hint, #9ca3af); }
94
- .primary { border-color: var(--codiscuss-accent, #2563eb) !important; background: var(--codiscuss-accent, #2563eb) !important; color: #fff; padding: .4em 1em !important; }
95
- .primary:hover { filter: brightness(1.08); }
96
119
  </style>
97
120
  <div class="wrap">
98
121
  <p class="eyebrow">按你的权重,主持人最适合</p>
@@ -111,7 +134,7 @@ th { color: var(--codiscuss-text-hint, #9ca3af); }
111
134
 
112
135
  <div class="foot">
113
136
  <span class="hint" id="hint">满分 10 分,按权重加权平均</span>
114
- <button id="submit" class="primary" type="button">按这组权重交给主持人</button>
137
+ <button id="submit" class="cd-primary" type="button">按这组权重交给主持人</button>
115
138
  </div>
116
139
  </div>
117
140
  <script>
package/README.md CHANGED
@@ -33,13 +33,13 @@ The [User Guide](docs/en/guide/README.md) covers each of these in full.
33
33
  - **Structured discussions** — set a goal and round or time limits; the host schedules speakers and follow-ups, and you can produce a sourced report. See [Discussions](docs/en/guide/discussion.md).
34
34
  - **Goal** — give the host an objective; it keeps going, stops when it needs your confirmation and can remind you on WeChat. See [Goal](docs/en/guide/goal.md).
35
35
  - **Workflows** — save a fixed division of work among several agents and start it in a room with one click. See [Workflows](docs/en/guide/workflows.md).
36
- - **Cross-room analytics** — review unassisted rates, folder activity, parallel room peaks, member scorecards and bottlenecks for today, the last 7 or 30 days, or all time, and export a local summary PNG. See [Analytics](docs/en/guide/analytics.md).
36
+ - **Cross-room analytics** — one sentence on how much your AI team did, a list of issues that need you with links to the exact runs, details on folders, models, workflows and bottlenecks, and a local share image about the work done. See [Analytics](docs/en/guide/analytics.md).
37
37
  - **Smart Scheduling** — optionally let a decision model handle routine routing instead of waking the host; it uses your own key, and the room title and recent messages are sent to the provider. See [Smart Scheduling](docs/en/guide/scheduling.md).
38
38
  - **Mix any participant** — local CLIs and desktop apps, model APIs and manually connected sessions in one room; resume existing agent sessions and give each member read-only or writable access. See [Members](docs/en/guide/members.md).
39
39
  - **Shared projects and records** — point a room at project folders and browse them; attachments, export and import between sites, and branching; destroy a room, with its members’ AI sessions, at any time or after a set idle period. See [Rooms](docs/en/guide/rooms.md).
40
40
  - **Deploy as website** — publish a page or built folder a member made to a public address for 7 days, renewable, after you confirm what goes out. See [Working in a room](docs/en/guide/working.md#8-deploy-a-page-as-a-website).
41
41
  - **Borrow an AI from another computer** — bring an agent on someone else's computer into your room, reading only the folders you open, revocable at any time. See [External members](docs/en/guide/external-members.md).
42
- - **Phone and away from your desk** — once your computer is bound to your own free Cloudflare site, pair a phone or tablet by scanning a code. See [Phone and remote use](docs/en/guide/remote.md).
42
+ - **Phone and away from your desk** — once your computer is bound to a self-hosted relay on Cloudflare’s free plan, pair a phone or tablet by scanning a code. See [Phone and remote use](docs/en/guide/remote.md).
43
43
  - **Voice and hosting** — read-aloud and voice input, which can run locally; the admin panel can create hosted accounts for others. See [Voice and notifications](docs/en/guide/voice.md) and [Admin panel and hosted accounts](docs/en/guide/admin.md).
44
44
 
45
45
  ## Supported Participants
package/README.zh-CN.md CHANGED
@@ -33,13 +33,13 @@
33
33
  - **结构化讨论**:设定目标与轮次或时长上限,主持人安排发言与追问,可生成带来源的报告。见[讨论](docs/guide/discussion.md)。
34
34
  - **Goal**:交给主持人一个目标,它持续推进,需要你确认时停下,可发微信提醒。见 [Goal](docs/guide/goal.md)。
35
35
  - **工作流**:把固定的多人分工存成工作流,在房间里一键启用。见[工作流](docs/guide/workflows.md)。
36
- - **全房间统计**:按今日、近 7 天、近 30 天或全部时间复盘免介入率、文件夹精力分布、同时推进的房间数、成员表现与卡点,并本地导出汇总分享图。见[统计](docs/guide/analytics.md)。
36
+ - **全房间统计**:一句话看清 AI 替你干了多少活,列出需要你处理的问题并能点到具体运行;文件夹、模型、工作流与卡点放在明细里;本地导出讲工作量的分享图。见[统计](docs/guide/analytics.md)。
37
37
  - **智能调度**:可选由决策模型处理日常分派,不必每次唤醒主持人;使用你自己的密钥,房间标题与最近消息会发给所选供应商。见[智能调度](docs/guide/scheduling.md)。
38
38
  - **混合接入**:本地 CLI 与桌面 App、模型 API、手动接入的会话同房协作;可续接已有的 AI 会话,为每位成员设置只读或可写。见[成员](docs/guide/members.md)。
39
39
  - **共享项目与记录**:为房间指定项目目录并在“文件”页浏览;附件、跨站点导出导入与分支;房间可随时或按设定期限销毁,连同成员的 AI 会话记录一起删除。见[房间目录与建房](docs/guide/rooms.md)。
40
40
  - **部署为网站**:把成员做出的网页或构建好的目录发布到公网地址,确认上传内容后上线,有效 7 天、可续期。见[在房间里干活](docs/guide/working.md#8-把网页部署成网站)。
41
41
  - **借用另一台电脑上的 AI**:把别人电脑上的 AI 请进你的房间,只读你开放的目录,随时撤销。见[跨电脑协作](docs/guide/external-members.md)。
42
- - **手机与外出**:电脑绑定自托管的免费 Cloudflare 站点后,手机或平板扫码配对即可远程使用。见[手机与外出](docs/guide/remote.md)。
42
+ - **手机与外出**:电脑绑定自建中转(可免费部署在 Cloudflare)后,手机或平板扫码配对即可远程使用。见[手机与外出](docs/guide/remote.md)。
43
43
  - **语音与托管**:朗读与语音输入,可在本机运行;管理面板可给别人开托管账号。见[语音与通知](docs/guide/voice.md)、[管理面板与托管账号](docs/guide/admin.md)。
44
44
 
45
45
  ## 支持的参与者
@@ -10,6 +10,7 @@ from math import floor
10
10
  from time import monotonic
11
11
  from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
12
12
 
13
+ from .analytics_issues import concurrency_series, issues as attention_issues, unfinished_series
13
14
  from .texts import Text
14
15
 
15
16
  CACHE_SECONDS = 60
@@ -377,8 +378,9 @@ def time_stats(connection, requests, executions, bounds, now, sealed):
377
378
  rooms, rooms_at = peak_concurrent(spans)
378
379
  members, members_at = peak_concurrent(member_spans)
379
380
  peak = {"rooms": rooms, "at": rooms_at, "members": members, "members_at": members_at}
381
+ concurrency = concurrency_series(member_spans, start, end)
380
382
  active_rooms = [room for room in room_rows.values() if room["initiated"] or room["execution_seconds"]]
381
- return {"folders": list(folders.values()), "rooms": active_rooms, "peak": peak, "sealed_execution_seconds": counts["execution_seconds"],
383
+ return {"folders": list(folders.values()), "rooms": active_rooms, "peak": peak, "concurrency": concurrency, "sealed_execution_seconds": counts["execution_seconds"],
382
384
  "execution_seconds": sum(f["execution_seconds"] for f in folders.values()) + counts["execution_seconds"],
383
385
  "waiting": distribution(waits, histograms["waiting"]),
384
386
  "execution": distribution(elapsed, histograms["execution"]), "rework": distribution(rework, histograms["rework"]),
@@ -533,6 +535,22 @@ def daily_overview(dates, facts, executions, sealed_days, now):
533
535
  return rows
534
536
 
535
537
 
538
+ def previous_work(rows, start, end, now):
539
+ """Execution time and peak concurrency of the previous period, so the page's figures can show a change.
540
+
541
+ Same rules as the current period (clipped to the window, overlaps merged per room and per room + member), over
542
+ existing rooms only.
543
+ """
544
+ seconds, rooms, members = 0, defaultdict(list), defaultdict(list)
545
+ for r in rows:
546
+ left, right = max(start, r["created_at"]), min(end, r["finished_at"] or now, now)
547
+ if left < right:
548
+ seconds += right - left
549
+ rooms[r["room_id"]].append((left, right))
550
+ members[(r["room_id"], r["name"])].append((left, right))
551
+ return {"execution_seconds": seconds, "peak_rooms": peak_concurrent(rooms)[0], "peak_members": peak_concurrent(members)[0]}
552
+
553
+
536
554
  def snapshot(connection, params, cache, now):
537
555
  """Build one SQLite read snapshot, caching only within the same server and room scope."""
538
556
  earliest = None
@@ -559,6 +577,7 @@ def snapshot(connection, params, cache, now):
559
577
  revived = {r[0] for r in connection.execute("""SELECT DISTINCT json_extract(data,'$.execution_id') FROM room_events
560
578
  WHERE kind='execution.changed' AND json_extract(data,'$.from_status')='failed' AND json_extract(data,'$.status')='started'""")}
561
579
  attempts = [r for r in executions if r["created_at"] >= start]
580
+ earlier_attempts = [r for r in connection.execute(EXECUTIONS, (start, previous, previous)) if r["created_at"] >= previous]
562
581
  assigned = [r for r in requests if start <= r["created_at"] < end]
563
582
  members = member_stats(attempts, assigned, revived)
564
583
  models = member_stats(attempts, assigned, revived, by_model=True)
@@ -571,13 +590,16 @@ def snapshot(connection, params, cache, now):
571
590
  scope = {"mode": mode, "rooms": len(rooms), "sealed_rooms": retained, "included_rooms": len(rooms) + retained,
572
591
  "includes_archived": True, "sealed_day_tz": "UTC", "sealed_counts": SEALED_COUNTS,
573
592
  "sealed_distributions": SEALED_DISTRIBUTIONS,
574
- "current_only": ["folders", "rooms", "peak", "queue", "affected_requests", "members", "models", "workflows", "insights"]}
593
+ "current_only": ["folders", "rooms", "peak", "concurrency", "issues", "queue", "affected_requests", "members", "models", "workflows", "insights"]}
575
594
  result = dict(range=dates, scope=scope,
576
595
  overview=overview(facts, start, end, sealed), previous=overview(facts, previous, start, prior),
577
596
  time={**time_stats(connection, requests, executions, (start, end), now, sealed), **activity},
578
597
  members=members, models=models, workflows=workflow_stats(connection, attempts),
598
+ issues=attention_issues(connection, attempts, earlier_attempts, revived, (previous, start, end)),
579
599
  insights=insights(connection, members, start, end))
580
600
  result["overview"]["daily"] = daily_overview(dates, facts, executions, sealed_days, now)
601
+ result["time"]["concurrency"]["unfinished"] = unfinished_series(attempts, start, end)
602
+ result["previous"].update(previous_work(earlier_attempts, previous, start, now))
581
603
  if len(cache) >= CACHE_ENTRIES:
582
604
  cache.clear()
583
605
  cache[key] = (monotonic() + CACHE_SECONDS, result)
@@ -0,0 +1,210 @@
1
+ """Rule-based “needs your attention” list for the analytics page, with the runs behind each item.
2
+
3
+ Every issue is a fact with its count, the same count for the previous period and the executions that make it up, so
4
+ the page can say what happened and let the owner open each run. Rules only describe what was observed; they never
5
+ recommend switching a model, since different models and efforts take on different work. No model is called.
6
+
7
+ Runs that did not finish are grouped by their reason, not by model (2026-11-27, Fable #14109): one runner fault that
8
+ hit several models is one issue, not one alert per model. Rarer, unchanged problems are left out, and only a high share
9
+ or a clear rise is marked as serious, so a page where 97% of the work went fine does not read as an emergency.
10
+ """
11
+ from collections import Counter, defaultdict
12
+
13
+ USER_STOPS = ("用户打断", "用户停止全部")
14
+ HOST_STOP = "主持人"
15
+ REASON_CHARS = 60
16
+ MIN_COUNT = 3
17
+ UNKNOWN_MODEL_MIN = 10
18
+ RUNS_PER_ISSUE = 30
19
+ MEMBERS_PER_ISSUE = 4
20
+ # An issue is listed when it touches at least this share of the related runs, or clearly rose against last period.
21
+ LIST_SHARE = 0.05
22
+ # It is marked serious from this share, or when it at least doubled by a meaningful margin.
23
+ SERIOUS_SHARE = 0.10
24
+ RISE_FACTOR = 2
25
+ RISE_MIN = 5
26
+ # Ordering weight per occurrence: unfinished work costs more than a stop the owner chose; bookkeeping sinks.
27
+ WEIGHTS = {"not_finished": 3, "late_recovery": 2, "permission": 2, "interrupted": 2, "scheduler": 1, "unknown_model": 0.2}
28
+ LEVELS = {"high": 0, "normal": 1, "info": 2}
29
+
30
+
31
+ def group_of(row):
32
+ """Software, model and effort of a run: the unit the owner configures."""
33
+ return row["adapter"], row["model"] or "", row["effort"] or ""
34
+
35
+
36
+ def user_stopped(row):
37
+ return row["status"] == "cancelled" and row["result"] in USER_STOPS
38
+
39
+
40
+ def not_finished(row):
41
+ """A run that ended without a result for reasons other than the owner or the host deciding to stop it."""
42
+ if row["status"] == "failed":
43
+ return True
44
+ # A host stopping a member is the host's decision about the work, not something that went wrong with the member.
45
+ return row["status"] == "cancelled" and not user_stopped(row) and not (row["result"] or "").startswith(HOST_STOP)
46
+
47
+
48
+ def reason_of(row):
49
+ """The first sentence of a run's result, short enough to count alike failures together."""
50
+ text = (row["result"] or "").strip()
51
+ if not text or text.startswith("message:"):
52
+ return ""
53
+ for mark in ("。", ";", ". ", "\n"):
54
+ text = text.split(mark)[0]
55
+ return text[:REASON_CHARS]
56
+
57
+
58
+ def classify(row, revived):
59
+ """Yield (rule, key, params) for every issue rule one execution row contributes to."""
60
+ adapter, model, effort = group_of(row)
61
+ member = {"adapter": adapter, "model": model, "effort": effort}
62
+ if not_finished(row):
63
+ failure = row["failure_class"] or ""
64
+ reason = "" if failure else reason_of(row)
65
+ yield "not_finished", ("not_finished", failure, reason), {"failure_class": failure, "reason": reason}
66
+ if user_stopped(row):
67
+ yield "interrupted", ("interrupted",) + group_of(row), member
68
+ if row["denied"]:
69
+ yield "permission", ("permission",) + group_of(row), member
70
+ if row["id"] in revived and row["status"] == "completed":
71
+ yield "late_recovery", ("late_recovery",) + group_of(row), member
72
+ if not model:
73
+ yield "unknown_model", ("unknown_model", adapter), {"adapter": adapter}
74
+
75
+
76
+ def collect(rows, revived):
77
+ """Group execution rows by issue key: {key: (rule, params, [rows])}."""
78
+ found = {}
79
+ for row in rows:
80
+ for rule, key, params in classify(row, revived):
81
+ found.setdefault(key, (rule, params, []))[2].append(row)
82
+ return found
83
+
84
+
85
+ def scheduler_counts(connection, start, end):
86
+ """Negative smart-scheduling ratings per room in [start, end)."""
87
+ return {room: bad for room, bad in connection.execute("""SELECT d.room_id,sum(f.rating='bad')
88
+ FROM scheduler_feedback f JOIN scheduler_decisions d ON d.id=f.decision_id
89
+ WHERE CAST(strftime('%s',f.created_at) AS INTEGER)>=? AND CAST(strftime('%s',f.created_at) AS INTEGER)<?
90
+ GROUP BY d.room_id""", (start, end)) if bad}
91
+
92
+
93
+ def run_details(connection, rows):
94
+ """The newest runs of one issue with their room title and the message that asked for them."""
95
+ rows = sorted(rows, key=lambda row: row["created_at"], reverse=True)[:RUNS_PER_ISSUE]
96
+ ids = [row["id"] for row in rows]
97
+ asked, titles = {}, {}
98
+ if ids:
99
+ marks = ",".join("?" * len(ids))
100
+ for execution_id, message_id in connection.execute(
101
+ f"SELECT execution_id,min(message_id) FROM member_requests WHERE execution_id IN ({marks}) GROUP BY execution_id", ids):
102
+ asked[execution_id] = message_id
103
+ rooms = sorted({row["room_id"] for row in rows})
104
+ marks = ",".join("?" * len(rooms))
105
+ titles = dict(connection.execute(f"SELECT id,title FROM rooms WHERE id IN ({marks})", rooms))
106
+ return [{"execution_id": row["id"], "room_id": row["room_id"], "title": titles.get(row["room_id"], ""),
107
+ "member": row["name"], "label": row["label"], "created_at": row["created_at"], "status": row["status"],
108
+ "result": (row["result"] or "")[:120], "failure_class": row["failure_class"] or "",
109
+ "message_id": asked.get(row["id"])} for row in rows]
110
+
111
+
112
+ def judge(count, previous, total, rule):
113
+ """(listed, level) for one issue: share of the related runs and the change against last period decide both."""
114
+ share = count / total if total else 0
115
+ rose = previous > 0 and count >= RISE_FACTOR * previous and count - previous >= RISE_MIN
116
+ if rule == "unknown_model":
117
+ return share >= LIST_SHARE, "info"
118
+ if share < LIST_SHARE and not rose:
119
+ return False, None
120
+ return True, "high" if share >= SERIOUS_SHARE or rose else "normal"
121
+
122
+
123
+ def issues(connection, current, earlier, revived, bounds):
124
+ """Issues of the period, serious ones first, each with its previous-period count, affected members and runs.
125
+
126
+ `current` and `earlier` are execution rows created in this period and in the previous one; `bounds` holds the
127
+ timestamps (previous, start, end) used for the scheduler ratings.
128
+ """
129
+ previous, start, end = bounds
130
+ now_found, before_found = collect(current, revived), collect(earlier, revived)
131
+ by_group, by_adapter = Counter(group_of(row) for row in current), Counter(row["adapter"] for row in current)
132
+ result = []
133
+ for key, (rule, params, rows) in now_found.items():
134
+ threshold = UNKNOWN_MODEL_MIN if rule == "unknown_model" else MIN_COUNT
135
+ if len(rows) < threshold:
136
+ continue
137
+ before = len(before_found.get(key, (None, None, []))[2])
138
+ groups = Counter(group_of(row) for row in rows)
139
+ if rule == "not_finished":
140
+ # Related runs are all runs of the members this reason touched, so a fault confined to one model is
141
+ # measured against that model's work rather than the whole team's.
142
+ total = sum(by_group[group] for group in groups)
143
+ elif "model" in params:
144
+ total = by_group[params["adapter"], params["model"], params["effort"]]
145
+ else:
146
+ total = by_adapter[params["adapter"]]
147
+ listed, level = judge(len(rows), before, total, rule)
148
+ if not listed:
149
+ continue
150
+ members = [{"adapter": adapter, "model": model, "effort": effort, "count": count}
151
+ for (adapter, model, effort), count in groups.most_common(MEMBERS_PER_ISSUE)]
152
+ result.append({"rule": rule, "params": params, "level": level, "count": len(rows), "previous": before,
153
+ "total": total, "score": WEIGHTS[rule] * len(rows), "members": members,
154
+ "first_at": min(row["created_at"] for row in rows), "last_at": max(row["created_at"] for row in rows),
155
+ "runs": run_details(connection, rows)})
156
+ earlier_bad = scheduler_counts(connection, previous, start)
157
+ for room, bad in scheduler_counts(connection, start, end).items():
158
+ if bad >= MIN_COUNT:
159
+ title = connection.execute("SELECT title FROM rooms WHERE id=?", (room,)).fetchone()
160
+ result.append({"rule": "scheduler", "params": {"room_id": room, "title": title[0] if title else ""},
161
+ "level": "normal", "count": bad, "previous": earlier_bad.get(room, 0), "total": None,
162
+ "score": WEIGHTS["scheduler"] * bad, "members": [], "first_at": None, "last_at": None,
163
+ "runs": []})
164
+ return sorted(result, key=lambda item: (LEVELS[item["level"]], -item["score"], item["rule"]))
165
+
166
+
167
+ def series_step(start, end):
168
+ """Bucket length for the period's timelines: an hour up to eight days, six hours up to a month, then a day."""
169
+ length = max(1, end - start)
170
+ return 3600 if length <= 8 * 86400 else 6 * 3600 if length <= 32 * 86400 else 86400
171
+
172
+
173
+ def concurrency_series(spans, start, end):
174
+ """Most experts running at once in each time step of [start, end), for the page's and share card's timeline.
175
+
176
+ Each expert's overlapping runs are merged first, exactly like the peak figure, so the series' maximum equals
177
+ `peak.members`.
178
+ """
179
+ step = series_step(start, end)
180
+ buckets = [0] * -(-max(1, end - start) // step)
181
+ events = defaultdict(int)
182
+ for intervals in spans.values():
183
+ merged = []
184
+ for left, right in sorted(intervals):
185
+ if merged and left <= merged[-1][1]:
186
+ merged[-1][1] = max(merged[-1][1], right)
187
+ else:
188
+ merged.append([left, right])
189
+ for left, right in merged:
190
+ events[left] += 1
191
+ events[right] -= 1
192
+ running, cursor = 0, start
193
+ for stamp in sorted(events):
194
+ # The count held from `cursor` to `stamp` lights every bucket it touches.
195
+ if running and stamp > cursor:
196
+ for index in range((cursor - start) // step, min(len(buckets), -(-(stamp - start) // step))):
197
+ buckets[index] = max(buckets[index], running)
198
+ running += events[stamp]
199
+ cursor = stamp
200
+ return {"step": step, "points": buckets}
201
+
202
+
203
+ def unfinished_series(rows, start, end):
204
+ """Runs that did not finish, per time step of [start, end) by when they started: the red marks on the timeline."""
205
+ step = series_step(start, end)
206
+ buckets = [0] * -(-max(1, end - start) // step)
207
+ for row in rows:
208
+ if not_finished(row) and start <= row["created_at"] < end:
209
+ buckets[(row["created_at"] - start) // step] += 1
210
+ return buckets