@fantasticit/sumi 0.15.1 → 0.15.2

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 (71) hide show
  1. package/dist/host-messages.d.ts +6 -0
  2. package/dist/host-messages.js +8 -0
  3. package/dist/host-messages.js.map +1 -0
  4. package/dist/host-transcripts.d.ts +5 -0
  5. package/dist/host-transcripts.js +86 -0
  6. package/dist/host-transcripts.js.map +1 -0
  7. package/dist/hub/board.d.ts +43 -1
  8. package/dist/hub/board.js +87 -13
  9. package/dist/hub/board.js.map +1 -1
  10. package/dist/hub/page-icons.d.ts +1 -0
  11. package/dist/hub/page-icons.js +5 -0
  12. package/dist/hub/page-icons.js.map +1 -0
  13. package/dist/hub/page-model.d.ts +102 -0
  14. package/dist/hub/page-model.js +302 -0
  15. package/dist/hub/page-model.js.map +1 -0
  16. package/dist/hub/page-overlays.d.ts +1 -0
  17. package/dist/hub/page-overlays.js +115 -0
  18. package/dist/hub/page-overlays.js.map +1 -0
  19. package/dist/hub/page-sessions.d.ts +1 -0
  20. package/dist/hub/page-sessions.js +588 -0
  21. package/dist/hub/page-sessions.js.map +1 -0
  22. package/dist/hub/page-style.d.ts +1 -0
  23. package/dist/hub/page-style.js +346 -0
  24. package/dist/hub/page-style.js.map +1 -0
  25. package/dist/hub/page-tips.d.ts +2 -0
  26. package/dist/hub/page-tips.js +93 -0
  27. package/dist/hub/page-tips.js.map +1 -0
  28. package/dist/hub/page-usage.d.ts +2 -0
  29. package/dist/hub/page-usage.js +360 -0
  30. package/dist/hub/page-usage.js.map +1 -0
  31. package/dist/hub/page-workbench.d.ts +1 -0
  32. package/dist/hub/page-workbench.js +901 -0
  33. package/dist/hub/page-workbench.js.map +1 -0
  34. package/dist/hub/pages.d.ts +1 -0
  35. package/dist/hub/pages.js +68 -182
  36. package/dist/hub/pages.js.map +1 -1
  37. package/dist/hub/server.js +2 -4
  38. package/dist/hub/server.js.map +1 -1
  39. package/dist/hub/snapshot.d.ts +9 -0
  40. package/dist/hub/snapshot.js +97 -20
  41. package/dist/hub/snapshot.js.map +1 -1
  42. package/dist/hub/usage-summary.d.ts +36 -0
  43. package/dist/hub/usage-summary.js +76 -0
  44. package/dist/hub/usage-summary.js.map +1 -0
  45. package/dist/hub/usage.d.ts +50 -0
  46. package/dist/hub/usage.js +285 -0
  47. package/dist/hub/usage.js.map +1 -0
  48. package/dist/visualize-sessions.d.ts +6 -0
  49. package/dist/visualize-sessions.js +9 -2
  50. package/dist/visualize-sessions.js.map +1 -1
  51. package/dist/visualize.d.ts +6 -0
  52. package/dist/visualize.js +1 -1
  53. package/dist/visualize.js.map +1 -1
  54. package/node_modules/@sumi/create/package.json +2 -2
  55. package/node_modules/@sumi/kernel/package.json +2 -2
  56. package/node_modules/@sumi/plugin-sdk/dist/hub.d.ts +21 -2
  57. package/node_modules/@sumi/plugin-sdk/dist/hub.js +42 -0
  58. package/node_modules/@sumi/plugin-sdk/dist/hub.js.map +1 -1
  59. package/node_modules/@sumi/plugin-sdk/package.json +1 -1
  60. package/node_modules/@sumi/plugins-core/package.json +3 -3
  61. package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.d.ts +1 -1
  62. package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js +52 -10
  63. package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js.map +1 -1
  64. package/node_modules/@sumi/plugins-governance/dist/index.d.ts +1 -1
  65. package/node_modules/@sumi/plugins-governance/dist/index.js +1 -1
  66. package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
  67. package/node_modules/@sumi/plugins-governance/package.json +4 -4
  68. package/node_modules/@sumi/plugins-openspec/package.json +6 -6
  69. package/node_modules/@sumi/plugins-precedent/package.json +3 -3
  70. package/node_modules/@sumi/plugins-review/package.json +6 -6
  71. package/package.json +10 -10
@@ -0,0 +1,93 @@
1
+ /** 一个委托控制器服务所有动态视图,提示不保存到浏览器存储。 */
2
+ export const TIPS_SCRIPT = String.raw `
3
+ const TIP_CANDIDATES =
4
+ '[data-tip],.t,.s,.status-text,.nm,.path,.trunc,.cmd code,.agent,.command-result strong,.command-result span,.metric .d,.metric .v,.ustrip .v,.flow .d,.tk,.ii .m .mono,.crumbs b,.search-placeholder';
5
+ function tipText(node) {
6
+ const style = getComputedStyle(node);
7
+ return tooltipContent(
8
+ node.dataset.tip,
9
+ node.textContent,
10
+ style.textOverflow === 'ellipsis' || Number.parseInt(style.webkitLineClamp) > 0,
11
+ node.scrollWidth,
12
+ node.clientWidth,
13
+ node.scrollHeight,
14
+ node.clientHeight,
15
+ );
16
+ }
17
+ function findTip(node) {
18
+ if (!(node instanceof Element)) return null;
19
+ for (let el = node; el && el !== document.body; el = el.parentElement) {
20
+ const text = tipText(el);
21
+ if (text) return [el, text];
22
+ if (el.matches('a,button,[tabindex]')) {
23
+ for (const child of el.querySelectorAll(TIP_CANDIDATES)) {
24
+ const nested = tipText(child);
25
+ if (nested) return [el, nested];
26
+ }
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+ function prepareTooltips(root) {
32
+ if (tipOwner && !tipOwner.isConnected) tipController.close();
33
+ for (const node of root.querySelectorAll(TIP_CANDIDATES)) {
34
+ if (!node.closest('a,button') && tipText(node)) node.tabIndex = 0;
35
+ }
36
+ }
37
+ const tooltip = byId('workbench-tip');
38
+ let tipOwner = null;
39
+ let previousDescription = null;
40
+ let previousTitle = null;
41
+ const tipController = createTooltipController({
42
+ show: (node, text) => {
43
+ const dialog = node.closest('dialog[open]');
44
+ const parent = dialog || document.body;
45
+ if (tooltip.parentElement !== parent) parent.append(tooltip);
46
+ tooltip.textContent = text;
47
+ tooltip.hidden = false;
48
+ if (tipOwner !== node) {
49
+ tipOwner = node;
50
+ previousDescription = node.getAttribute('aria-describedby');
51
+ previousTitle = node.getAttribute('title');
52
+ if (previousTitle !== null) node.removeAttribute('title');
53
+ node.setAttribute('aria-describedby', [previousDescription, 'workbench-tip'].filter(Boolean).join(' '));
54
+ }
55
+ const position = tooltipPosition(
56
+ node.getBoundingClientRect(),
57
+ tooltip.offsetWidth,
58
+ tooltip.offsetHeight,
59
+ innerWidth,
60
+ innerHeight,
61
+ );
62
+ tooltip.style.left = position.left + 'px';
63
+ tooltip.style.top = position.top + 'px';
64
+ },
65
+ hide: (node) => {
66
+ tooltip.hidden = true;
67
+ if (previousDescription === null) node.removeAttribute('aria-describedby');
68
+ else node.setAttribute('aria-describedby', previousDescription);
69
+ if (previousTitle !== null) node.setAttribute('title', previousTitle);
70
+ previousTitle = null;
71
+ tipOwner = null;
72
+ previousDescription = null;
73
+ },
74
+ });
75
+ document.addEventListener('mouseover', (event) => {
76
+ const value = findTip(event.target);
77
+ if (value) tipController.enter(...value);
78
+ else tipController.close();
79
+ });
80
+ document.addEventListener('mouseout', (event) => {
81
+ if (tipOwner && !tipOwner.contains(event.relatedTarget)) tipController.leave();
82
+ });
83
+ document.addEventListener('focusin', (event) => {
84
+ const value = findTip(event.target);
85
+ if (value) tipController.enter(...value);
86
+ else tipController.close();
87
+ });
88
+ document.addEventListener('focusout', () => tipController.close());
89
+ document.addEventListener('scroll', () => tipController.scroll(), true);
90
+ addEventListener('keydown', (event) => tipController.key(event.key));
91
+ addEventListener('resize', () => tipController.close());
92
+ `;
93
+ //# sourceMappingURL=page-tips.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-tips.js","sourceRoot":"","sources":["../../src/hub/page-tips.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0FpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** 用量视图只渲染已统计的中性事实,所有文本来自真实数据或固定口径。 */
2
+ export declare const USAGE_SCRIPT: string;
@@ -0,0 +1,360 @@
1
+ /** 用量视图只渲染已统计的中性事实,所有文本来自真实数据或固定口径。 */
2
+ export const USAGE_SCRIPT = String.raw `
3
+ function panel(title) {
4
+ const node = make('section', 'panel');
5
+ const head = make('div', 'hd');
6
+ head.append(make('h3', '', title));
7
+ const body = make('div', 'bd');
8
+ node.append(head, body);
9
+ return [node, body, head];
10
+ }
11
+ const tokenTotal = (value) => value.input + value.cacheRead + value.cacheWrite + value.output;
12
+ const tokenNumber = (value) =>
13
+ value >= 1e8
14
+ ? (value / 1e8).toLocaleString('zh-CN', { maximumFractionDigits: 2 }) + ' 亿'
15
+ : value >= 1e4
16
+ ? (value / 1e4).toLocaleString('zh-CN', { maximumFractionDigits: 1 }) + ' 万'
17
+ : value.toLocaleString('zh-CN');
18
+ const usageDuration = (value) => {
19
+ const minutes = Math.floor(value / 60000);
20
+ return minutes >= 60 ? Math.floor(minutes / 60) + ' 小时 ' + (minutes % 60) + ' 分' : minutes + ' 分';
21
+ };
22
+ const percent = (value) => (value * 100).toFixed(1) + '%';
23
+ const usageReady = (value) => value && ('available' in value ? value.available > 0 : 'input' in value);
24
+ function usageLabel(value) {
25
+ if (!value) return '需升级项目的 Sumi';
26
+ if (typeof value.unavailable === 'string') return value.unavailable === '升级项目的 Sumi 后显示' ? '需升级项目的 Sumi' : '用量不可用';
27
+ if (value.pending === true) return '统计中';
28
+ if ('sessions' in value && !value.sessions) return '暂无关联会话';
29
+ if ('available' in value && !value.available) return value.pending ? '统计中' : '用量不可用';
30
+ return tokenNumber(tokenTotal(value));
31
+ }
32
+ function usageTip(value) {
33
+ if (!value) return '需升级项目的 Sumi';
34
+ if (typeof value.unavailable === 'string') return value.unavailable.replace('升级项目的 Sumi 后显示', '需升级项目的 Sumi');
35
+ if (value.pending === true) return '统计中';
36
+ if ('available' in value && !value.available)
37
+ return value.sessions
38
+ ? [
39
+ '已统计 0/' + value.sessions + ' 个会话;统计中 ' + value.pending + ',不可用 ' + value.unavailable,
40
+ ...value.reasons,
41
+ ].join('\n')
42
+ : '暂无关联会话';
43
+ return [
44
+ '未命中输入 ' + tokenNumber(value.input),
45
+ '缓存读取 ' + tokenNumber(value.cacheRead),
46
+ '写入缓存 ' + tokenNumber(value.cacheWrite),
47
+ '输出 ' + tokenNumber(value.output),
48
+ '缓存命中率 ' + percent(value.hitRate),
49
+ ...(typeof value.activeMs === 'number' ? ['AI 工作时长 ' + usageDuration(value.activeMs)] : []),
50
+ ...('available' in value
51
+ ? [
52
+ value.sessions +
53
+ ' 个关联会话;已统计 ' +
54
+ value.available +
55
+ ',统计中 ' +
56
+ value.pending +
57
+ ',不可用 ' +
58
+ value.unavailable,
59
+ ...value.reasons,
60
+ ]
61
+ : []),
62
+ ].join('\n');
63
+ }
64
+ function usageCoverage(value) {
65
+ return value.available + '/' + value.sessions + ' 个会话已统计 · ' + value.unavailable + ' 个不可用' +
66
+ (value.pending ? ' · ' + value.pending + ' 个统计中' : '');
67
+ }
68
+ function tokenLabel(value) {
69
+ const node = make('span', 'tk', usageLabel(value));
70
+ node.dataset.tip = usageTip(value);
71
+ node.tabIndex = 0;
72
+ const note = tokenUnavailableNote(value);
73
+ if (note) node.append(make('small', 'usage-coverage', note));
74
+ return node;
75
+ }
76
+ function usageScope(board) {
77
+ const sum = board.usage?.total;
78
+ return (
79
+ '按最近活动筛选近 7 天会话,每项目最多 50 个,统计整份会话记录。' +
80
+ (sum ? '共 ' + sum.sessions + ' 个会话,已统计 ' + sum.available + ',统计中 ' + sum.pending + ',不可用 ' + sum.unavailable + '。' : '')
81
+ );
82
+ }
83
+ function usageStack(value) {
84
+ const node = make('div', 'stack');
85
+ if (!usageReady(value)) return node;
86
+ for (const [key, color] of [
87
+ ['cacheRead', 'var(--ok)'],
88
+ ['cacheWrite', 'var(--warn)'],
89
+ ['input', 'var(--info)'],
90
+ ['output', 'var(--ink-2)'],
91
+ ]) {
92
+ const item = make('i');
93
+ item.style.flex = String(value[key]);
94
+ item.style.background = color;
95
+ node.append(item);
96
+ }
97
+ node.dataset.tip = usageTip(value);
98
+ node.tabIndex = 0;
99
+ return node;
100
+ }
101
+ function usageStrip(board, withLink = true) {
102
+ const sum = board.usage?.total;
103
+ const strip = make('div', 'ustrip');
104
+ const ready = usageReady(sum);
105
+ for (const [label, value, note] of [
106
+ [
107
+ '近 7 天 Token',
108
+ usageLabel(sum),
109
+ sum ? usageCoverage(sum) : '统计中',
110
+ ],
111
+ ['缓存命中率', ready ? percent(sum.hitRate) : '—', ready ? '缓存读取 ' + tokenNumber(sum.cacheRead) : '暂无数据'],
112
+ ['未命中输入 + 写入缓存', ready ? tokenNumber(sum.input + sum.cacheWrite) : '—', '不含缓存读取与输出'],
113
+ ['AI 工作时长', ready ? usageDuration(sum.activeMs) : '—', '不含 5 分钟以上空闲'],
114
+ ]) {
115
+ const box = make('div');
116
+ box.append(make('div', 'l', label), make('div', 'v', value), make('div', 'd', note));
117
+ box.dataset.tip = usageTip(sum);
118
+ box.tabIndex = 0;
119
+ strip.append(box);
120
+ }
121
+ if (withLink) {
122
+ const go = make('a', 'go', '查看用量');
123
+ go.href = '/usage';
124
+ go.append(icon('right', 14));
125
+ strip.append(go);
126
+ } else strip.classList.add('without-link');
127
+ return strip;
128
+ }
129
+ function costPanel(value, title = '用量') {
130
+ const [box, body, head] = panel(title);
131
+ head.append(copyTip('汇总在此工作目录运行过、且在近 7 天范围内的会话。'));
132
+ if (!value?.sessions) {
133
+ body.append(make('p', 'muted', '暂无关联会话'));
134
+ return box;
135
+ }
136
+ head.append(make('span', 'sub', value.sessions + ' 个关联会话'));
137
+ body.append(usageStack(value));
138
+ const facts = make('dl', 'kv');
139
+ for (const [label, text] of [
140
+ ['Token', usageLabel(value)],
141
+ ['缓存命中率', usageReady(value) ? percent(value.hitRate) : '—'],
142
+ ['AI 工作时长', usageReady(value) ? usageDuration(value.activeMs) : '—'],
143
+ ['对话与工具调用', usageReady(value) ? value.turns + ' 轮 · ' + value.tools + ' 次' : '—'],
144
+ ]) {
145
+ const detail = make('dd');
146
+ if (label === 'Token') detail.append(tokenLabel(value));
147
+ else detail.textContent = text;
148
+ facts.append(make('dt', '', label), detail);
149
+ }
150
+ body.append(facts);
151
+ return box;
152
+ }
153
+ function inlineMarkdown(node, text) {
154
+ const marker = String.fromCharCode(96);
155
+ const pattern = new RegExp(
156
+ '(?<!' + marker + ')' + marker + '([^' + marker + ']+)' + marker + '(?!' + marker + ')',
157
+ 'g',
158
+ );
159
+ let offset = 0;
160
+ for (const match of text.matchAll(pattern)) {
161
+ node.append(document.createTextNode(text.slice(offset, match.index)), make('code', '', match[1]));
162
+ offset = match.index + match[0].length;
163
+ }
164
+ node.append(document.createTextNode(text.slice(offset)));
165
+ }
166
+
167
+ function markdownBody(text, attention) {
168
+ const body = make('div', 'note-markdown');
169
+ let list = null;
170
+ let paragraph = null;
171
+ for (const { text: line, highlight } of noteLines(text, attention)) {
172
+ const heading = /^(#{1,3})\s+(.+)$/.exec(line);
173
+ const bullet = /^\s*[-*]\s+(.+)$/.exec(line);
174
+ if (heading) {
175
+ list = null;
176
+ paragraph = null;
177
+ const node = make('h' + (Number(heading[1].length) + 1));
178
+ if (highlight) node.className += ' hl';
179
+ inlineMarkdown(node, heading[2]);
180
+ body.append(node);
181
+ } else if (bullet) {
182
+ paragraph = null;
183
+ if (!list) {
184
+ list = make('ul');
185
+ body.append(list);
186
+ }
187
+ const item = make('li');
188
+ if (highlight) item.className += ' hl';
189
+ inlineMarkdown(item, bullet[1]);
190
+ list.append(item);
191
+ } else if (!line.trim()) {
192
+ paragraph = null;
193
+ list = null;
194
+ } else {
195
+ list = null;
196
+ if (!paragraph || highlight) {
197
+ paragraph = make('p');
198
+ body.append(paragraph);
199
+ } else paragraph.append(document.createTextNode('\n'));
200
+ if (highlight) paragraph.className += ' hl';
201
+ inlineMarkdown(paragraph, line);
202
+ if (highlight) paragraph = null;
203
+ }
204
+ }
205
+ return body;
206
+ }
207
+ function notesPanels(notes, attention) {
208
+ const root = make('div', 'notes-panels');
209
+ for (const [index, note] of (notes || []).entries()) {
210
+ const [box, body, head] = panel(note.title);
211
+ if (note.status) head.append(make('span', 'pill', note.status));
212
+ if (note.at && Number.isFinite(Date.parse(note.at))) head.append(relativeTime(note.at));
213
+ const lines = note.markdown.split(/\r?\n/);
214
+ body.append(markdownBody(lines.slice(0, 40).join('\n'), attention));
215
+ if (lines.length > 40) {
216
+ const details = make('details', 'bmore');
217
+ details.dataset.keep = 'note-' + index + '-' + (note.at || note.title);
218
+ details.append(make('summary', '', '展开全文'), markdownBody(lines.slice(40).join('\n'), attention));
219
+ body.append(details);
220
+ }
221
+ root.append(box);
222
+ }
223
+ return root;
224
+ }
225
+ function tokenCell(value) { const cell = make('td'); cell.append(tokenLabel(value)); return cell; }
226
+ function scopeCaption(board) {
227
+ const sum = board.usage?.total;
228
+ return '近 7 天 · ' + (sum?.sessions || 0) + ' 个会话 · ' + (sum?.unavailable || 0) + ' 个不可用 · ' + (sum?.pending || 0) + ' 个统计中';
229
+ }
230
+ function dailyPanel(board, detailed = false) {
231
+ const [box, body, head] = panel('每天 Token');
232
+ head.append(make('span', 'sub', scopeCaption(board)), copyTip('按本机时区统计近 7 天 Token,无有效时间的记录不计入。会话累计包含更早记录,可能与每日合计不同。'));
233
+ if (!usageReady(board.usage?.total)) { body.append(make('p', 'muted', '暂无每日用量数据')); return box; }
234
+ const daily = Object.entries(board.usage?.total.daily || {});
235
+ const max = Math.max(1, ...daily.map(([, value]) => tokenTotal(value)));
236
+ const legend = make('div', 'token-legend');
237
+ for (const [label, color] of [['缓存读取', 'var(--ok)'], ['写入缓存', 'var(--warn)'], ['未命中', 'var(--info)'], ['输出', 'var(--ink-2)']]) {
238
+ const item = make('span', '', label);
239
+ const dot = make('i');
240
+ dot.style.background = color;
241
+ item.prepend(dot);
242
+ legend.append(item);
243
+ }
244
+ head.append(legend);
245
+ if (detailed) {
246
+ const sum = daily.reduce((sum, [, day]) => ({ input: sum.input + day.input, cacheRead: sum.cacheRead + day.cacheRead, cacheWrite: sum.cacheWrite + day.cacheWrite, output: sum.output + day.output }), { input: 0, cacheRead: 0, cacheWrite: 0, output: 0 });
247
+ const metrics = make('div', 'kpis');
248
+ for (const [label, value] of [['合计', tokenNumber(tokenTotal(sum))], ['缓存命中率', percent(sum.cacheRead / (sum.input + sum.cacheRead + sum.cacheWrite || 1))], ['未命中输入 + 写入缓存', tokenNumber(sum.input + sum.cacheWrite)], ['输出', tokenNumber(sum.output)], ['日均', tokenNumber(tokenTotal(sum) / Math.max(1, daily.length))]]) {
249
+ const metric = make('div');
250
+ metric.append(make('span', '', label), make('b', '', value));
251
+ metric.dataset.tip = '近 7 天按发生日期统计;' + label + ' ' + value;
252
+ metric.tabIndex = 0;
253
+ metrics.append(metric);
254
+ }
255
+ body.append(metrics);
256
+ }
257
+ const chart = make('div', 'bars');
258
+ for (const [day, value] of daily) {
259
+ const total = tokenTotal(value);
260
+ const column = make('div', 'bcol');
261
+ column.dataset.tip = day + '\n未命中输入 ' + value.input + '\n缓存读取 ' + value.cacheRead + '\n写入缓存 ' + value.cacheWrite + '\n输出 ' + value.output + '\n缓存命中率 ' + percent(value.cacheRead / (value.input + value.cacheRead + value.cacheWrite || 1));
262
+ column.tabIndex = 0;
263
+ column.append(make('em', '', tokenNumber(total)));
264
+ const stack = make('div', 'stv');
265
+ stack.style.height = (total / max * (detailed ? 200 : 140)) + 'px';
266
+ for (const [key, color] of [['cacheRead', 'var(--ok)'], ['cacheWrite', 'var(--warn)'], ['input', 'var(--info)'], ['output', 'var(--ink-2)']]) {
267
+ if (!value[key]) continue;
268
+ const part = make('i');
269
+ part.style.height = (value[key] / total * 100) + '%';
270
+ part.style.background = color;
271
+ stack.append(part);
272
+ }
273
+ column.append(stack, make('span', '', day.slice(5)));
274
+ chart.append(column);
275
+ }
276
+ body.append(chart);
277
+ if (!daily.length) body.append(make('p', 'muted', '暂无每日用量数据'));
278
+ return box;
279
+ }
280
+ function usagePage(root, board) {
281
+ const wrap = make('div', 'wrap');
282
+ wrap.append(
283
+ pageHeading('用量', '统计自本机 Claude Code 与 Codex 会话记录', 'usage'),
284
+ make('p', 'usage-window', '近 7 天会话'),
285
+ usageStrip(board, false),
286
+ dailyPanel(board, true),
287
+ );
288
+ const grid = make('div', 'grid g2');
289
+ const [top, topBody, topHead] = panel('Token 最多的会话');
290
+ topHead.append(make('span', 'sub', scopeCaption(board)));
291
+ const table = make('table', 'usage-table');
292
+ const rows = make('tbody');
293
+ const sessions = (board.usage?.topSessions || [])
294
+ .filter((s) => usageReady(s.usage))
295
+ .sort((a, b) => tokenTotal(b.usage) - tokenTotal(a.usage))
296
+ .slice(0, 10);
297
+ for (const session of sessions) {
298
+ const row = make('tr');
299
+ const title = make('td');
300
+ const a = make('a', 't', session.title || '(无提示词)');
301
+ a.href = '/sessions#' + encodeURIComponent(session.projectId + ':' + session.id);
302
+ const description = make('div', 's');
303
+ session.projects.forEach((project, index) => description.append(...(index ? [document.createTextNode('、')] : []), projectTag(project)));
304
+ description.append(make('span', '', ' · ' + session.usage.turns + ' 轮 · 工具 ' + session.usage.tools + ' 次 · 缓存命中率 ' + percent(session.usage.hitRate)));
305
+ title.append(a, description);
306
+ const amount = make('td');
307
+ amount.append(tokenLabel(session.usage));
308
+ row.append(title, amount);
309
+ rows.append(row);
310
+ }
311
+ table.append(rows);
312
+ topBody.append(table);
313
+ if (!sessions.length) topBody.append(make('div', 'empty', '暂无用量数据'));
314
+ const [models, modelsBody, modelsHead] = panel('按模型');
315
+ modelsHead.append(make('span', 'sub', scopeCaption(board)));
316
+ const mt = make('table', 'usage-table');
317
+ const th = make('thead');
318
+ const hr = make('tr');
319
+ for (const text of ['模型', '会话', 'Token', '缓存命中率']) hr.append(make('th', '', text));
320
+ th.append(hr);
321
+ mt.append(th);
322
+ const mb = make('tbody');
323
+ for (const model of board.usage?.models || []) {
324
+ const row = make('tr');
325
+ row.append(
326
+ make('td', 'mono', model.model),
327
+ make('td', '', model.sessions),
328
+ tokenCell(model),
329
+ make('td', '', percent(model.hitRate)),
330
+ );
331
+ mb.append(row);
332
+ }
333
+ mt.append(mb);
334
+ modelsBody.append(mt);
335
+ if (!mb.children.length) modelsBody.append(make('div', 'empty', '暂无模型用量数据'));
336
+ grid.append(models, top);
337
+ wrap.append(grid);
338
+ const [projects, pb, projectsHead] = panel('按项目');
339
+ projectsHead.append(make('span', 'sub', scopeCaption(board)));
340
+ const pt = make('table', 'usage-table');
341
+ const tb = make('tbody');
342
+ for (const project of board.usage?.projects || []) {
343
+ const row = make('tr');
344
+ const name = make('td');
345
+ name.append(projectTag(project.name));
346
+ const amount = make('td');
347
+ amount.append(tokenLabel(project.usage));
348
+ row.append(name, make('td', '', project.usage.sessions + ' 个会话'), amount);
349
+ tb.append(row);
350
+ }
351
+ pt.append(tb);
352
+ projectsHead.append(copyTip('跨项目会话在每个所属项目各计一次,项目之和可能大于合计。'));
353
+ pb.append(pt);
354
+ const scope = make('details', 'usage-scope');
355
+ scope.append(make('summary', '', '口径'), make('p', '', usageScope(board)), make('p', '', '全局按会话记录去重,工作目录汇总可能重叠;Claude Code 包含其记录目录中的子会话,不推断跨会话父子关系。'), make('p', '', 'AI 工作时长不含 5 分钟以上空闲;子会话独立计时后相加,可能重叠。'));
356
+ wrap.append(projects, scope);
357
+ root.append(wrap);
358
+ }
359
+ `;
360
+ //# sourceMappingURL=page-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-usage.js","sourceRoot":"","sources":["../../src/hub/page-usage.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqWrC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const WORKBENCH_SCRIPT: string;