@ssamurias/dsh-fish 1.0.7 → 1.0.9
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.
- package/AGENTS.md +32 -3
- package/CHANGELOG.md +4366 -4265
- package/README.md +243 -627
- package/RELEASE-NOTES-1.0.8.md +81 -0
- package/RELEASE-NOTES-1.0.9.md +79 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/docs/troubleshooting.md +79 -1
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +112 -0
- package/lib/appoint.js +106 -22
- package/lib/ask.js +8 -3
- package/lib/at.js +16 -1
- package/lib/capture.js +51 -1
- package/lib/claim.js +103 -0
- package/lib/client/00-shell.js +500 -0
- package/lib/client/01-state-load.js +860 -0
- package/lib/client/02-actions.js +670 -0
- package/lib/client/03-widgets-header.js +721 -0
- package/lib/client/04-pressure-lab.js +891 -0
- package/lib/client/05-pressure-charts.js +431 -0
- package/lib/client/06-tab-status-grow.js +468 -0
- package/lib/client/07-tab-home-bili.js +542 -0
- package/lib/client/08-tab-memory-plugins.js +733 -0
- package/lib/client/09-tab-outing.js +710 -0
- package/lib/client/10-data-handlers.js +519 -0
- package/lib/client/11-tab-data-frame.js +661 -0
- package/lib/client/12-pressure-chip-mount.js +565 -0
- package/lib/client.js +109 -24
- package/lib/comment.js +18 -3
- package/lib/cue.js +102 -5
- package/lib/deliver.js +3 -1
- package/lib/derive.js +308 -41
- package/lib/doing.js +31 -15
- package/lib/drive.js +3 -5
- package/lib/env.d.ts +224 -0
- package/lib/health.js +56 -0
- package/lib/hear.js +70 -0
- package/lib/home.js +48 -20
- package/lib/identity.js +25 -2
- package/lib/index.js +32 -18
- package/lib/look.js +2 -1
- package/lib/loops.js +39 -0
- package/lib/make.js +60 -12
- package/lib/markup.js +77 -1
- package/lib/match.js +262 -0
- package/lib/observe-bili.js +331 -0
- package/lib/observe-config.js +223 -0
- package/lib/observe-data.js +522 -0
- package/lib/observe-home.js +383 -0
- package/lib/observe-http.js +250 -0
- package/lib/observe-outing.js +650 -0
- package/lib/observe-state.js +419 -0
- package/lib/observe-trip.js +286 -0
- package/lib/observe.js +99 -3574
- package/lib/persona.js +187 -40
- package/lib/proactive.js +48 -47
- package/lib/pronounask.js +15 -1
- package/lib/restrict.js +146 -9
- package/lib/say.js +68 -4
- package/lib/scheduler.js +63 -25
- package/lib/schema.js +57 -4
- package/lib/scrub.js +16 -1
- package/lib/settings.js +128 -12
- package/lib/stance.js +131 -19
- package/lib/status.js +14 -5
- package/lib/store.js +24 -2
- package/lib/sub.js +7 -1
- package/lib/talkmem.js +12 -8
- package/lib/transcript.js +205 -0
- package/lib/turns.js +147 -19
- package/lib/types.d.ts +513 -0
- package/lib/voices.js +26 -1
- package/lib/wiki.js +47 -13
- package/lib/works.js +200 -49
- package/media/banner.jpg +0 -0
- package/package.json +1 -1
- package/scripts/build-client.mjs +83 -0
- package/scripts/sync-pressure-formulas.mjs +12 -15
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
function pressureLines(points, lines, endpoints = []) {
|
|
2
|
+
const first = points[0]?.round ?? 1
|
|
3
|
+
const last = points.at(-1)?.round ?? first
|
|
4
|
+
const x = round => 43 + 617 * (round - first) / Math.max(1, last - first)
|
|
5
|
+
const y = score => 189 - score * 1.65
|
|
6
|
+
if (!points.some(point => lines.some(line => Number.isFinite(line.read(point))))) {
|
|
7
|
+
return h('p', { className: 'hint' }, '暂无可绘制的轮末分数。')
|
|
8
|
+
}
|
|
9
|
+
return h('svg', { viewBox: '0 0 680 220', role: 'group', 'aria-label': '轮末压力走势(0–100)', style: { width: '100%' } },
|
|
10
|
+
...[0, 25, 50, 75, 100].map(value => h('g', { key: value },
|
|
11
|
+
h('line', { x1: 43, x2: 660, y1: y(value), y2: y(value), stroke: 'currentColor', opacity: .16 }),
|
|
12
|
+
h('text', { x: 35, y: y(value) + 4, fill: 'currentColor', fontSize: 12, textAnchor: 'end' }, value))),
|
|
13
|
+
...[...new Set([first, Math.floor((first + last) / 2), last])].map(round => h('text', {
|
|
14
|
+
key: round, x: x(round), y: 209, fill: 'currentColor', fontSize: 12, textAnchor: 'middle',
|
|
15
|
+
}, round)),
|
|
16
|
+
...endpoints.map((round, index) => h('line', { key: index, x1: x(round), x2: x(round), y1: 20, y2: 190,
|
|
17
|
+
stroke: 'currentColor', strokeDasharray: '4 3', opacity: .6 })),
|
|
18
|
+
...lines.flatMap(line => trendSegments(points.map(point => ({ round: point.round, score: line.read(point) })))
|
|
19
|
+
.map((segment, i) => h('polyline', { key: line.label + ':' + i, stroke: line.color, strokeWidth: 2,
|
|
20
|
+
fill: 'none', points: segment.map(point => x(point.round) + ',' + y(point.score)).join(' ') }))),
|
|
21
|
+
...points.flatMap(point => {
|
|
22
|
+
const values = lines.map(line => [line, line.read(point)]).filter(([, score]) => Number.isFinite(score))
|
|
23
|
+
const label = ['第 ' + point.round + ' 轮', ...values.map(([line, score]) => line.label + ' ' + scoreOf(score) + ' 分'),
|
|
24
|
+
routeDetails(point), ...point.markers.map(marker => marker.type)].filter(Boolean).join(' · ')
|
|
25
|
+
return values.length || point.markers.length ? [h('g', { key: point.round, tabIndex: 0, 'aria-label': label },
|
|
26
|
+
h('title', null, label),
|
|
27
|
+
...values.map(([line, score]) => h('circle', { key: line.label, cx: x(point.round), cy: y(score), r: 3, fill: line.color })),
|
|
28
|
+
point.markers.length ? h('path', { d: 'M ' + x(point.round) + ' 13 l 4 4 -4 4 -4 -4 z', fill: 'currentColor' }) : null)] : []
|
|
29
|
+
}))
|
|
30
|
+
}
|
|
31
|
+
function lineToggles(key, options) {
|
|
32
|
+
const hidden = trendConfig[key] ?? []
|
|
33
|
+
return h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 12 } }, ...options.map(item => h('label', { key: item.id },
|
|
34
|
+
h('input', { type: 'checkbox', checked: !hidden.includes(item.id), onChange: event => changeTrend({
|
|
35
|
+
[key]: event.currentTarget.checked ? hidden.filter(id => id !== item.id) : [...hidden, item.id],
|
|
36
|
+
}) }), h('span', { style: { color: item.color } }, ' ' + item.label))))
|
|
37
|
+
}
|
|
38
|
+
const currentLines = plans.map(([id]) => ({ id, label: id, color: schemeColors[id], read: point => point.scores?.[id]?.score }))
|
|
39
|
+
const currentRange = trendConfig.currentRange ?? 20
|
|
40
|
+
const homePoints = currentRange ? currentSeries.slice(-currentRange) : currentSeries
|
|
41
|
+
const recentChanges = currentSeries.slice(-10).flatMap((point, index, recent) => plans.flatMap(([id]) => {
|
|
42
|
+
const previous = recent[index - 1]
|
|
43
|
+
const before = previous?.scores?.[id]?.score
|
|
44
|
+
const after = point.scores?.[id]?.score
|
|
45
|
+
return previous?.round === point.round - 1 && Number.isFinite(before) && Number.isFinite(after) && before !== after
|
|
46
|
+
? [{ round: point.round, id, difference: after - before }] : []
|
|
47
|
+
})).sort((a, b) => Math.abs(b.difference) - Math.abs(a.difference)).slice(0, 3)
|
|
48
|
+
const currentCards = h('div', { style: pressureGrid }, ...plans.map(([id, name], index) => {
|
|
49
|
+
const stats = homeSchemeStats[id]
|
|
50
|
+
const last = latestPoint?.scores?.[id]?.score
|
|
51
|
+
const previous = priorPoint?.scores?.[id]?.score
|
|
52
|
+
return h('section', { key: id, className: 'card', style: { minWidth: 0, borderBlockStart: '3px solid ' + schemeColors[id] } },
|
|
53
|
+
h('h4', null, id + ' · ' + name),
|
|
54
|
+
pressureMetric('当前实时压力', scoreOf(compositeScores[id].score) + ' / 100',
|
|
55
|
+
['综合均衡视角', '多维风险视角', '容量优先视角'][index]),
|
|
56
|
+
h('div', { className: 'hint' }, '最近完成轮变化(5 轮) ' + (Number.isFinite(last) && Number.isFinite(previous) ? signedScore(last - previous) : '—')),
|
|
57
|
+
h('div', { className: 'hint' }, '轮末历史同轮次 · 百分位 ' + (Number.isFinite(stats.percentile) ? scoreOf(stats.percentile) + '%' : '—')
|
|
58
|
+
+ ' · 中位数差 ' + signedScore(stats.difference)),
|
|
59
|
+
h('div', { className: 'hint' }, stats.count ? stats.count + ' 个历史样本' : '暂无可比样本'))
|
|
60
|
+
}))
|
|
61
|
+
const advice = sessionCapacityAdvice(occupancy, observedGrowth)
|
|
62
|
+
const capacityStatus = {
|
|
63
|
+
continue: ['✓', '继续使用', '#58ab86', '当前窗口仍有余量,可以继续使用这个会话。'],
|
|
64
|
+
watch: ['◉', '继续使用,留意变化', '#5c9ded', '可以继续使用,接下来留意上下文占用的变化。'],
|
|
65
|
+
prepare: ['△', '建议准备新会话', '#cc8b46', '建议在下一段任务前准备新会话,给后续对话留出空间。'],
|
|
66
|
+
switch: ['!', '强烈建议切换', '#db726b', '当前上下文已接近或达到有效窗口上限,建议在下一段任务前改用新会话。'],
|
|
67
|
+
unknown: ['?', '数据不足,暂不能判断', '#8e99a7', '缺少有效窗口或当前请求输入,暂时无法判断容量余量。'],
|
|
68
|
+
}[advice.level]
|
|
69
|
+
const unstableTrend = growthWindows.some(window => window.rounds <= 10 && window.compacted)
|
|
70
|
+
|| currentSeries.slice(-10).some(point => point.markers.some(marker =>
|
|
71
|
+
['压缩成功', '裁剪', '模型切换', '窗口切换'].includes(marker.type)))
|
|
72
|
+
const occupancyText = value => Number.isFinite(value) ? scoreOf(value) + '%' : '—'
|
|
73
|
+
const tShare = structureData?.currentShare
|
|
74
|
+
const evidence = [
|
|
75
|
+
[Number.isFinite(occupancy) ? '当前窗口已使用 ' + occupancyText(occupancy) : '当前占用未知',
|
|
76
|
+
'最新模型请求实报输入 ' + measureText(rowFor('C', '请求输入'))
|
|
77
|
+
+ ',有效窗口 ' + measureText(rowFor('C', '有效窗口'))
|
|
78
|
+
+ ',剩余 ' + measureText(rowFor('C', '剩余容量')) + '。占用率按本次请求的输入除以有效窗口计算。'],
|
|
79
|
+
[advice.five == null ? '近期趋势未知' : observedGrowth < 0 ? '最近可比轮次的占用呈净下降'
|
|
80
|
+
: advice.five >= 95 - 1e-10 ? '按近期趋势,5 轮后可能接近窗口上限'
|
|
81
|
+
: advice.ten >= 85 - 1e-10 ? '按近期趋势,10 轮后可能达到较高占用'
|
|
82
|
+
: '按近期趋势,10 轮内预计低于 85%',
|
|
83
|
+
advice.five == null ? '缺少当前占用或可比的轮末增长采样。' : '当前加权净增长 '
|
|
84
|
+
+ signedScore(observedGrowth) + ' 个百分点/轮,复用 C + G 的近期窗口加权和容量推演。'
|
|
85
|
+
+ '预计占用以 0–100% 显示。'],
|
|
86
|
+
...(Number.isFinite(tShare) && tShare >= .5 ? [[
|
|
87
|
+
'工具结果约占宿主可见请求的一半或更多',
|
|
88
|
+
'同请求估算占比 ' + dictionaryValue(tShare, '%') + '。这描述工具内容占用,仅用于解释压力来源。',
|
|
89
|
+
]] : []),
|
|
90
|
+
]
|
|
91
|
+
const adviceCard = h('section', { className: 'card', style: { borderInlineStart: '4px solid ' + capacityStatus[2] } },
|
|
92
|
+
h('h4', { className: 'load-heading' }, h('span', null,
|
|
93
|
+
h('span', { 'aria-hidden': true, style: { color: capacityStatus[2], marginInlineEnd: 8 } }, capacityStatus[0]), capacityStatus[1]),
|
|
94
|
+
h('span', { className: 'hint' }, '实验规则 · 阈值尚未校准')),
|
|
95
|
+
h('p', null, capacityStatus[3]),
|
|
96
|
+
h('ul', null, ...evidence.map(([label]) => h('li', { key: label }, label))))
|
|
97
|
+
const adviceDetails = h('section', { className: 'card' }, h('h4', null, '为什么这样判断'),
|
|
98
|
+
h('div', { style: pressureGrid },
|
|
99
|
+
...[['当前占用', occupancy], ['预计 5 轮后', advice.five], ['预计 10 轮后', advice.ten]].map(([label, value]) =>
|
|
100
|
+
h('div', { key: label }, pressureMetric(label, occupancyText(value))))),
|
|
101
|
+
advice.five == null ? h('p', { className: 'hint' }, '趋势未知,现有建议仅依据可用的当前占用。')
|
|
102
|
+
: h('p', { className: 'hint' }, '按当前增长趋势估算,不保证实际结果。'),
|
|
103
|
+
unstableTrend ? h('p', { className: 'hint' }, '近期记录了压缩、裁剪或配置切换,趋势可能不稳定。') : null,
|
|
104
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '查看具体依据'),
|
|
105
|
+
...evidence.map(([label, detail]) => h('details', { key: label }, h('summary', null, label), h('p', null, detail))),
|
|
106
|
+
h('p', { className: 'hint' }, '建议采用真实采样和固定的 5、10 轮窗口。公式试算、A/B/C 分数与累计用量用于分析,不参与建议分级。'),
|
|
107
|
+
h('button', { type: 'button', onClick: () => setPressureTab('factors') }, '查看诊断指标')))
|
|
108
|
+
const pressureCurrent = h('div', { className: 'load-panel' }, adviceCard, currentCards,
|
|
109
|
+
isScenario ? h('p', { className: 'hint' }, 'A/B/C 使用当前情景参数试算。') : null,
|
|
110
|
+
invalidStructure ? h('p', { role: 'alert' }, '工具残留数据异常,当前 T + E 和 A/B/C 分数无效。') : null,
|
|
111
|
+
adviceDetails,
|
|
112
|
+
h('section', { className: 'card' },
|
|
113
|
+
h('h4', null, '压力走势'),
|
|
114
|
+
h('label', null, '轮次范围 ', h('select', { value: currentRange,
|
|
115
|
+
onChange: event => changeTrend({ currentRange: Number(event.currentTarget.value) }) },
|
|
116
|
+
...[10, 20, 50, 0].map(value => h('option', { key: value, value }, value ? '最近 ' + value + ' 轮' : '全部轮次')))),
|
|
117
|
+
lineToggles('homeHidden', currentLines),
|
|
118
|
+
pressureLines(homePoints, currentLines.filter(line => !(trendConfig.homeHidden ?? []).includes(line.id))),
|
|
119
|
+
h('button', { type: 'button', onClick: () => { changeTrend({ historyPage: 'compare' }); setPressureTab('history') } }, '查看完整压力走势'),
|
|
120
|
+
h('button', { type: 'button', onClick: () => { changeTrend({ historyPage: 'same', round: null }); setPressureTab('history') } }, '查看历史同轮次比较')),
|
|
121
|
+
h('section', { className: 'card' },
|
|
122
|
+
h('h4', null, '压力构成'),
|
|
123
|
+
h('div', { style: pressureGrid }, ...['C + G · 容量压力', 'U + A + K · 请求负担', 'T + E · 结构与稳定性'].map((name, index) => {
|
|
124
|
+
const last = latestPoint?.children?.[index]
|
|
125
|
+
const previous = priorPoint?.children?.[index]
|
|
126
|
+
return h('div', { key: name }, pressureMetric(name, scoreOf(subScores[index]) + ' / 100',
|
|
127
|
+
'近 5 轮 ' + (Number.isFinite(last) && Number.isFinite(previous) ? signedScore(last - previous) : '—')),
|
|
128
|
+
Number.isFinite(subScores[index]) ? h('progress', { max: 100, value: subScores[index], 'aria-label': name }) : null)
|
|
129
|
+
})),
|
|
130
|
+
h('button', { type: 'button', onClick: () => setPressureTab('calculation') }, '查看详细计算方式')),
|
|
131
|
+
h('section', { className: 'card' }, h('h4', null, '关键诊断'),
|
|
132
|
+
h('div', { style: pressureGrid }, ...summaryMeasures.map(([name, row]) => h('div', { key: name },
|
|
133
|
+
pressureMetric(name, measureText(row), row?.confidence))),
|
|
134
|
+
pressureMetric('最近失败与重试', latestUsage ? latestUsage.attempts + ' 次尝试失败 · ' + latestUsage.retries + ' 次已匹配重试' : '—'))),
|
|
135
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '近期变化与事件'),
|
|
136
|
+
recentChanges.length ? h('ul', null, ...recentChanges.map(row => h('li', { key: row.round + ':' + row.id },
|
|
137
|
+
'第 ' + row.round + ' 轮 · 方案 ' + row.id + ' ' + signedScore(row.difference) + ' 分'))) : null,
|
|
138
|
+
eventTable(currentSeries.slice(-10))))
|
|
139
|
+
const toolOrder = trendConfig.toolOrder ?? 'tokens'
|
|
140
|
+
const currentTools = (pressure?.usage?.toolResults ?? []).slice().sort((a, b) => toolOrder === 'turn'
|
|
141
|
+
? b.turn - a.turn : toolOrder === 'age' ? a.turn - b.turn : b.tokens - a.tokens)
|
|
142
|
+
const rawRecords = new Map((pressure?.usage?.roundDiagnostics ?? []).map(row => [row.turn, row]))
|
|
143
|
+
const roundNumbers = [...new Set([...rows.map(row => row.turn), ...rawRecords.keys()])].sort((a, b) =>
|
|
144
|
+
trendConfig.roundAscending ? a - b : b - a)
|
|
145
|
+
const sampleByRound = new Map(rows.map(row => [row.turn, row]))
|
|
146
|
+
const diagnosticsView = h('div', { className: 'load-panel' },
|
|
147
|
+
h('div', { style: pressureGrid }, ...dictionary.map(metric => {
|
|
148
|
+
const row = metric.rows.find(value => Number.isFinite(value.value))
|
|
149
|
+
return h('div', { key: metric.id, className: 'card' }, pressureMetric(metric.id + ' · ' + metric.title,
|
|
150
|
+
measureText(row), row ? row.scope + ' · ' + row.confidence : '缺少数据'))
|
|
151
|
+
})),
|
|
152
|
+
pressureFactors, contextDiagnostics,
|
|
153
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '工具结果分析'),
|
|
154
|
+
h('label', null, '查看 ', h('select', { value: trendConfig.toolView ?? 'retained',
|
|
155
|
+
onChange: event => changeTrend({ toolView: event.currentTarget.value }) },
|
|
156
|
+
h('option', { value: 'retained' }, '当前残留'), h('option', { value: 'carry' }, '历史累计携带'))),
|
|
157
|
+
trendConfig.toolView === 'carry'
|
|
158
|
+
? pressureTable(['工具', '采样调用数', '轮末采样 Token', '跨轮可见次数', '累计重复携带 Token(估算)'],
|
|
159
|
+
[...new Set([...tools.map(row => row.name), ...burden.map(row => row.name)])].map(name => {
|
|
160
|
+
const sample = tools.find(row => row.name === name)
|
|
161
|
+
const carry = burden.find(row => row.name === name)
|
|
162
|
+
return [name, name, formatPressure(sample?.calls), formatPressure(sample?.tokens),
|
|
163
|
+
formatPressure(carry?.exposures), formatPressure(carry?.tokensAcrossRequests)]
|
|
164
|
+
}))
|
|
165
|
+
: h('div', null,
|
|
166
|
+
h('label', null, '排序 ', h('select', { value: toolOrder, onChange: event => changeTrend({ toolOrder: event.currentTarget.value }) },
|
|
167
|
+
h('option', { value: 'tokens' }, 'Token'), h('option', { value: 'turn' }, '产生轮次'), h('option', { value: 'age' }, '年龄'))),
|
|
168
|
+
pressureTable(['工具', '估算 Token', '产生轮次', '年龄(轮)', '后续携带次数', '仍可见'], currentTools.map(row =>
|
|
169
|
+
[row.seq, row.name, formatPressure(row.tokens), row.turn,
|
|
170
|
+
formatPressure(Number.isFinite(latestUsage?.turn) ? latestUsage.turn - row.turn : null),
|
|
171
|
+
formatPressure(row.carried), row.retained == null ? '—' : row.retained ? '是' : '否'])))),
|
|
172
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '逐轮诊断记录'),
|
|
173
|
+
h('button', { type: 'button', onClick: () => changeTrend({ roundAscending: !trendConfig.roundAscending }) },
|
|
174
|
+
trendConfig.roundAscending ? '最新轮在前' : '最早轮在前'),
|
|
175
|
+
h('label', null, '跳到轮次 ', h('input', { type: 'number', min: 1, value: trendConfig.diagnosticRound ?? '',
|
|
176
|
+
onChange: event => changeTrend({ diagnosticRound: event.currentTarget.valueAsNumber || null }) })),
|
|
177
|
+
...roundNumbers.filter(round => !trendConfig.diagnosticRound || round === trendConfig.diagnosticRound).slice(0, 25).map(round => {
|
|
178
|
+
const record = rawRecords.get(round)
|
|
179
|
+
const meter = sampleByRound.get(round)
|
|
180
|
+
return h('details', { key: round, className: 'pressure-section' }, h('summary', null, '第 ' + round + ' 轮'),
|
|
181
|
+
pressureTable(['诊断', '读数'], [
|
|
182
|
+
['input', '请求输入', dictionaryValue(record?.input, 'Token')], ['output', '请求输出', dictionaryValue(record?.output, 'Token')],
|
|
183
|
+
['delta', '轮末净增长', dictionaryValue(meter?.delta, 'Token')], ['occupancy', '轮末窗口占用率', dictionaryValue(meter?.contextWindow > 0 ? meter.tokens / meter.contextWindow : null, '%')],
|
|
184
|
+
['requests', '请求次数', formatPressure(record?.requests)], ['tools', '工具残留', dictionaryValue(record?.retained, 'Token')],
|
|
185
|
+
['cache', '缓存未命中', dictionaryValue(record?.cache ? 1 - record.cache.ratio : null, '%')],
|
|
186
|
+
['events', '记录事件', meter?.compacted ? '压缩或裁剪' : '—'],
|
|
187
|
+
]))
|
|
188
|
+
})))
|
|
189
|
+
const pressureCalculation = h('div', { className: 'load-panel' },
|
|
190
|
+
h('h4', null, '七项诊断 → 三个子压力 → A/B/C'),
|
|
191
|
+
h('button', { type: 'button', onClick: () => {
|
|
192
|
+
setCapacityExperiment({}); setRequestExperiment({}); setStructureExperiment({}); setCompositeExperiment({})
|
|
193
|
+
} }, '恢复全部实验默认值'),
|
|
194
|
+
[capacityExperiment, requestExperiment, structureExperiment, ...Object.values(compositeExperiment)]
|
|
195
|
+
.some(values => Object.keys(values).length) ? h('p', { className: 'hint' }, '实验参数已修改') : null,
|
|
196
|
+
...[
|
|
197
|
+
['capacity', 'C + G · 容量压力', subScores[0], 'γ ' + gamma + ' · H ' + horizon + ' · λ ' + lambda, capacityCalculation],
|
|
198
|
+
['request', 'U + A + K · 请求负担', subScores[1], 'ρ ' + rho + ' · β ' + beta + ' · τ ' + tau, requestCalculation],
|
|
199
|
+
['structure', 'T + E · 结构与稳定性', subScores[2], 'wₜ ' + toolWeight + ' · ε ' + epsilon + ' · η ' + eta, structureCalculation],
|
|
200
|
+
].map(([id, label, value, params, content]) => h('details', { key: id, className: 'pressure-section',
|
|
201
|
+
open: !!trendConfig['formula:' + id], onToggle: event => {
|
|
202
|
+
const open = event.currentTarget.open
|
|
203
|
+
if (!!trendConfig['formula:' + id] !== open) changeTrend({ ['formula:' + id]: open })
|
|
204
|
+
} }, h('summary', null, label + ' · ' + scoreOf(value) + ' / 100 · ' + params
|
|
205
|
+
+ (Number.isFinite(value) ? '' : ' · 缺少采样')), content)),
|
|
206
|
+
compositeCalculation)
|
|
207
|
+
const headerModel = pressure?.lastRequest?.model ?? (comparison?.current?.route ? JSON.parse(comparison.current.route)[1] : null)
|
|
208
|
+
const pressureHeader = h('div', { className: 'load-heading', style: { flexWrap: 'wrap' } },
|
|
209
|
+
h('strong', null, trendChoices.find(row => row.current)?.title || '当前 Session'),
|
|
210
|
+
h('span', { className: 'hint' }, [latestRound ? latestRound + ' 轮' : '— 轮', headerModel || '模型未知',
|
|
211
|
+
pressure?.updatedAt ? new Date(pressure.updatedAt).toLocaleTimeString() : '—',
|
|
212
|
+
pressure?.failed ? '读取失败' : pressure?.availability === 'analyzed' ? '已读取诊断' : '等待诊断'].join(' · ')))
|
|
213
|
+
function eventTable(points) {
|
|
214
|
+
const events = points.flatMap(point => point.markers.map((marker, index) => [point.round + ':' + index,
|
|
215
|
+
point.round, marker.time == null ? '—' : new Date(marker.time).toLocaleString(), marker.type,
|
|
216
|
+
Number.isFinite(marker.tokenChange) ? signedScore(marker.tokenChange) + ' Token' : '—',
|
|
217
|
+
h('details', null, h('summary', null, '记录详情'),
|
|
218
|
+
marker.seq != null ? '日志序号 ' + marker.seq + '。' : '',
|
|
219
|
+
marker.from && marker.to ? marker.from.join(' / ') + ' → ' + marker.to.join(' / ') + '。' : '',
|
|
220
|
+
marker.count ? '匹配重试 ' + marker.count + ' 次。' : '',
|
|
221
|
+
Number.isFinite(marker.tokens) ? '归因耗用 ' + formatPressure(marker.tokens) + ' Token。' : '',
|
|
222
|
+
Number.isFinite(marker.tokenChange) ? '有成对采样。' : '该事件无成对 Token 变化读数。')]))
|
|
223
|
+
return events.length ? pressureTable(['轮次', '时间', '事件', 'Token 变化', '来源详情'], events)
|
|
224
|
+
: h('p', { className: 'hint' }, '该区间暂无已记录的结构性事件。')
|
|
225
|
+
}
|
|
226
|
+
const attributionPoints = scoredTrends[attributionId] ?? []
|
|
227
|
+
const endpoints = attributionPoints.filter(point => point.children?.length === 3 && point.children.every(Number.isFinite))
|
|
228
|
+
const endpoint = (round, fallback) => endpoints.find(point => point.round === round) ?? fallback
|
|
229
|
+
const startPoint = endpoint(trendConfig.attributionStart, endpoints[Math.max(0, endpoints.length - 6)])
|
|
230
|
+
const endPoint = endpoint(trendConfig.attributionEnd, endpoints.at(-1))
|
|
231
|
+
const attributionPlan = trendConfig.attributionPlan ?? 'A'
|
|
232
|
+
const lowRound = Math.min(startPoint?.round ?? 0, endPoint?.round ?? 0)
|
|
233
|
+
const highRound = Math.max(startPoint?.round ?? 0, endPoint?.round ?? 0)
|
|
234
|
+
const interval = attributionPoints.filter(point => point.round >= lowRound && point.round <= highRound)
|
|
235
|
+
const contribution = pressureContributions(startPoint?.children, endPoint?.children, attributionPlan, compositeParameters)
|
|
236
|
+
const forecastLink = trendConfig.attributionForecast
|
|
237
|
+
const errorRecord = forecastLink ? records.find(row => row.sessionId === attributionId && row.origin === startPoint?.round
|
|
238
|
+
&& row.target === endPoint?.round && row.plan === attributionPlan && row.method === forecastLink.method) : null
|
|
239
|
+
const errorParts = errorRecord && pressureContributions(endPoint?.children, errorRecord.predictedChildren, attributionPlan, compositeParameters)
|
|
240
|
+
const childLines = scoreNames.map((label, index) => ({ id: index, label, color: childColors[index], read: point => point.children?.[index] }))
|
|
241
|
+
const delta = (start, end) => Number.isFinite(start) && Number.isFinite(end) ? signedScore(end - start) : '—'
|
|
242
|
+
function contributionBars(values, name) {
|
|
243
|
+
if (!values) return h('p', { className: 'hint' }, '该公式或端点缺少可分解的分数。')
|
|
244
|
+
const scale = 208 / Math.max(1, ...values.map(Math.abs))
|
|
245
|
+
return h('svg', { viewBox: '0 0 650 132', role: 'group', 'aria-label': name, style: { width: '100%' } },
|
|
246
|
+
h('line', { x1: 320, x2: 320, y1: 6, y2: 116, stroke: 'currentColor', opacity: .6 }),
|
|
247
|
+
...values.map((value, index) => {
|
|
248
|
+
const y = 15 + 35 * index
|
|
249
|
+
const label = scoreNames[index] + '贡献 ' + signedScore(value) + ' 分'
|
|
250
|
+
return h('g', { key: index, tabIndex: 0, 'aria-label': label },
|
|
251
|
+
h('title', null, label), h('text', { x: 10, y: y + 13, fill: 'currentColor', fontSize: 14 }, scoreNames[index]),
|
|
252
|
+
h('rect', { x: 320 + Math.min(0, value * scale), y, width: Math.abs(value * scale), height: 17, fill: childColors[index] }),
|
|
253
|
+
h('text', { x: 555, y: y + 13, fill: 'currentColor', fontSize: 14 }, signedScore(value)))
|
|
254
|
+
}))
|
|
255
|
+
}
|
|
256
|
+
const attributionPanel = !wantAttribution ? null : h('section', { className: 'load-panel' },
|
|
257
|
+
h('h4', null, '压力变化归因 · v0.1'),
|
|
258
|
+
h('div', { style: { display: 'flex', gap: 12, flexWrap: 'wrap' } },
|
|
259
|
+
h('label', null, 'Session ', h('select', { value: attributionId ?? '',
|
|
260
|
+
onChange: event => changeTrend({ attributionId: event.currentTarget.value, attributionStart: null,
|
|
261
|
+
attributionEnd: null, attributionForecast: null }) },
|
|
262
|
+
...trendChoices.map(row => h('option', { key: row.id, value: row.id }, row.title || '未命名 Session')))),
|
|
263
|
+
...[['attributionStart', '起始轮次', startPoint], ['attributionEnd', '结束轮次', endPoint]].map(([key, label, value]) =>
|
|
264
|
+
h('label', { key }, label, ' ', h('select', { value: value?.round ?? '',
|
|
265
|
+
onChange: event => changeTrend({ [key]: Number(event.currentTarget.value), attributionForecast: null }) },
|
|
266
|
+
...endpoints.map(point => h('option', { key: point.round, value: point.round }, point.round))))),
|
|
267
|
+
h('label', null, '综合公式 ', h('select', { value: attributionPlan,
|
|
268
|
+
onChange: event => changeTrend({ attributionPlan: event.currentTarget.value }) },
|
|
269
|
+
...plans.map(([id, name]) => h('option', { key: id, value: id }, id + ' · ' + name)))),
|
|
270
|
+
startPoint && endPoint ? h('button', { type: 'button', onClick: () => changeTrend({
|
|
271
|
+
attributionStart: endPoint.round, attributionEnd: startPoint.round, attributionForecast: null,
|
|
272
|
+
}) }, '交换起止轮') : null),
|
|
273
|
+
trendLoading ? h('p', { role: 'status' }, '正在读取逐轮诊断…') : null,
|
|
274
|
+
forecastLink ? h('section', { className: 'card' }, h('h4', null, '预测误差归因'),
|
|
275
|
+
errorRecord ? h('div', null,
|
|
276
|
+
h('p', null, '第 ' + errorRecord.origin + ' → ' + errorRecord.target + ' 轮 · ' + methodLabels[errorRecord.method]
|
|
277
|
+
+ ' · 实际 ' + scoreOf(errorRecord.actual) + ' · 预测 ' + scoreOf(errorRecord.estimate)
|
|
278
|
+
+ ' · 误差 ' + signedScore(errorRecord.estimate - errorRecord.actual)),
|
|
279
|
+
pressureTable(['子压力', '实际', '预测'], scoreNames.map((name, index) =>
|
|
280
|
+
[index, name, scoreOf(endPoint.children[index]), scoreOf(errorRecord.predictedChildren[index])])),
|
|
281
|
+
contributionBars(errorParts, '预测误差贡献'))
|
|
282
|
+
: h('p', { className: 'hint' }, '当前端点或公式的该次预测无法可靠重建。')) : null,
|
|
283
|
+
!startPoint || !endPoint ? h('p', { className: 'hint' }, '该会话暂无有效的归因端点。') : h('div', { className: 'load-panel' },
|
|
284
|
+
interval.length < highRound - lowRound + 1 || interval.some(point => !point.children?.every(Number.isFinite))
|
|
285
|
+
? h('p', { className: 'hint' }, '区间诊断不完整。贡献依据有效端点,图中保留断点。') : null,
|
|
286
|
+
h('section', { className: 'card' }, h('h4', null, '端点分数'),
|
|
287
|
+
pressureTable(['压力项', '起点', '终点', '变化'], [
|
|
288
|
+
...scoreNames.map((name, i) => [name, name + '子压力', scoreOf(startPoint.children[i]), scoreOf(endPoint.children[i]),
|
|
289
|
+
delta(startPoint.children[i], endPoint.children[i])]),
|
|
290
|
+
...plans.map(([id, name]) => [id, id + ' · ' + name, scoreOf(startPoint.scores?.[id]?.score),
|
|
291
|
+
scoreOf(endPoint.scores?.[id]?.score), delta(startPoint.scores?.[id]?.score, endPoint.scores?.[id]?.score)]),
|
|
292
|
+
])),
|
|
293
|
+
h('section', { className: 'card' }, h('h4', null, '三个子压力的变化'),
|
|
294
|
+
lineToggles('attributionHidden', childLines),
|
|
295
|
+
pressureLines(interval, childLines.filter(line => !(trendConfig.attributionHidden ?? []).includes(line.id)),
|
|
296
|
+
[...new Set([startPoint.round, endPoint.round])])),
|
|
297
|
+
h('section', { className: 'card' }, h('h4', null, '综合压力贡献'),
|
|
298
|
+
contributionBars(contribution, '综合压力变化贡献'),
|
|
299
|
+
h('p', { className: 'hint' }, '贡献表示评分公式中的数学影响,不代表现实因果关系。')),
|
|
300
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '七项诊断变化明细'),
|
|
301
|
+
...dictionary.map(metric => {
|
|
302
|
+
const keys = row => JSON.stringify([row.label, row.scope, row.unit])
|
|
303
|
+
const start = new Map((startPoint.diagnostics?.find(item => item.id === metric.id)?.rows ?? []).map(row => [keys(row), row]))
|
|
304
|
+
const end = new Map((endPoint.diagnostics?.find(item => item.id === metric.id)?.rows ?? []).map(row => [keys(row), row]))
|
|
305
|
+
return h('details', { key: metric.id, className: 'pressure-section' }, h('summary', null, metric.id + ' · ' + metric.title),
|
|
306
|
+
pressureTable(['读数', '起点', '终点', '差值', '来源', '范围'], [...new Set([...start.keys(), ...end.keys()])].map(key => {
|
|
307
|
+
const a = start.get(key)
|
|
308
|
+
const b = end.get(key)
|
|
309
|
+
const row = a ?? b
|
|
310
|
+
const d = a && b ? b.value - a.value : null
|
|
311
|
+
const unit = row.unit === '%' || row.unit === '百分点' ? '百分点' : row.unit
|
|
312
|
+
return [key, row.label, measureText(a), measureText(b), dictionaryValue(d, unit), row.source, row.scope]
|
|
313
|
+
})))
|
|
314
|
+
})),
|
|
315
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '结构性事件时间线'), eventTable(interval))))
|
|
316
|
+
const selectedSessionsSummary = h('details', { className: 'pressure-section' }, h('summary', null, 'Session 概览'),
|
|
317
|
+
pressureTable(['Session', '实际轮数', '最后有效轮', '最后模型 / 窗口', '配置切换', '成功压缩', '有效轮'], trendIds.map(id => {
|
|
318
|
+
const points = scoredTrends[id] ?? []
|
|
319
|
+
const valid = points.filter(point => Number.isFinite(point.scores?.[displayedPlans[0]]?.score))
|
|
320
|
+
return [id, trendChoices.find(row => row.id === id)?.title || '未命名 Session',
|
|
321
|
+
points.length || '—', valid.at(-1)?.round ?? '—', routeDetails(points.at(-1) ?? {}) || '—',
|
|
322
|
+
points.length ? points.some(point => point.switched) ? '有' : '无' : '—',
|
|
323
|
+
points.length ? points.reduce((count, point) => count + point.markers.filter(marker => marker.type === '压缩成功').length, 0) : '—',
|
|
324
|
+
points.length ? valid.length + ' / ' + points.length : '—']
|
|
325
|
+
})))
|
|
326
|
+
const historyView = h('div', { className: 'load-panel' }, pressureHistory,
|
|
327
|
+
h('div', { className: 'tabs load-tabs', role: 'group', 'aria-label': '历史分析视图' },
|
|
328
|
+
...[['compare', 'Session 对比'], ['same', '同轮次比较'], ['backtest', '预测回测'], ['attribution', '变化归因']].map(([id, label]) =>
|
|
329
|
+
h('button', { key: id, type: 'button', className: 'tab' + (id === historyPage ? ' on' : ''),
|
|
330
|
+
'aria-pressed': id === historyPage, onClick: () => changeTrend({ historyPage: id }) }, label))),
|
|
331
|
+
historyPage === 'compare' ? h('div', null, trendChart, selectedSessionsSummary)
|
|
332
|
+
: historyPage === 'same' ? sameRoundPanel : historyPage === 'backtest' ? pressureBacktest : attributionPanel)
|
|
333
|
+
|
|
334
|
+
const pressureCard = h('details', { className: 'card full',
|
|
335
|
+
onToggle: event => setPressureOpen(event.currentTarget.open) },
|
|
336
|
+
h('summary', null, h('strong', null, '会话压力')),
|
|
337
|
+
pressureOpen ? h('div', null,
|
|
338
|
+
pressure?.usage?.partial || pressure?.usage?.pendingCount > 0
|
|
339
|
+
? h('p', { className: 'hint', role: 'status' }, '部分结果 · 历史已分析 '
|
|
340
|
+
+ pressure.usage.analyzedCount + ' / ' + pressure.usage.selectedCount
|
|
341
|
+
+ ' · 待处理 ' + pressure.usage.pendingCount) : null,
|
|
342
|
+
pressureHeader, loadTabBar,
|
|
343
|
+
pressureTab === 'current' ? pressureCurrent : pressureTab === 'history' ? historyView : pressureTab === 'factors' ? diagnosticsView : pressureCalculation) : null)
|
|
344
|
+
|
|
345
|
+
const tabBar = h('div', { className: 'tabs' },
|
|
346
|
+
...TABS.map(([id, name]) => h('button', {
|
|
347
|
+
key: id,
|
|
348
|
+
className: 'tab' + (tab === id ? ' on' : ''),
|
|
349
|
+
title: TAB_HELP[id] || '',
|
|
350
|
+
onClick: () => setTab(id),
|
|
351
|
+
}, name)),
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
// 一页里的一组设置。title 之外还可以给 note(这一组整体的一句话)。
|
|
355
|
+
const group = (title, note, ...items) => h('div', { className: 'card' },
|
|
356
|
+
h('h3', null, title),
|
|
357
|
+
note ? h('p', { className: 'hint', style: { marginBottom: '10px' } }, note) : null,
|
|
358
|
+
...items)
|
|
359
|
+
// 长内容(清单、事件流、信箱)横跨整行:内容多、又窄又高,两列反而更难读。
|
|
360
|
+
const groupFull = (title, note, ...items) => h('div', { className: 'card full' },
|
|
361
|
+
h('h3', null, title),
|
|
362
|
+
note ? h('p', { className: 'hint', style: { marginBottom: '10px' } }, note) : null,
|
|
363
|
+
...items)
|
|
364
|
+
// 一行「名称 — 值」,tip 存在时在值后面挂一个可悬停的 ⓘ。
|
|
365
|
+
// 用它代替纯 kv:那一版用户看到「下一道门」和「稳定 0.87」都不知道在说什么。
|
|
366
|
+
const rowTip = (k, v, tip) => h('div', {
|
|
367
|
+
style: { display: 'flex', gap: '8px', alignItems: 'baseline', fontSize: '13px', marginBottom: '5px' },
|
|
368
|
+
},
|
|
369
|
+
h('span', { style: { opacity: 0.65, flex: '0 0 auto', minWidth: '84px' } }, k),
|
|
370
|
+
h('span', { style: { flex: '1' } }, v,
|
|
371
|
+
tip ? h('span', { title: tip, style: { opacity: 0.45, marginLeft: '5px', cursor: 'help' } }, 'ⓘ') : null))
|
|
372
|
+
|
|
373
|
+
// 2026-10-24(用户):底部「保存改动」整组删掉。原来每个页签都挂一颗,
|
|
374
|
+
// 让人以为必须先点;住所页根本没有设置项也挂着一颗。现在改完即存,
|
|
375
|
+
// 没有设置的页签自然什么都不需要。
|
|
376
|
+
|
|
377
|
+
// 数据文件夹路径一律由服务端 /paths 现算(用户 m03440)。
|
|
378
|
+
// 原来这里按 workspace 目录名以 home 结尾去反推根目录、再用反斜杠拼子路径:
|
|
379
|
+
// 目录一改名就推错,而且反斜杠是 Windows 假设。客户端不该重复实现服务端的事实。
|
|
380
|
+
|
|
381
|
+
const copyPath = async (p) => {
|
|
382
|
+
try {
|
|
383
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
|
384
|
+
await navigator.clipboard.writeText(p)
|
|
385
|
+
setNote('已复制到剪贴板。粘到资源管理器地址栏回车就能打开。')
|
|
386
|
+
} else {
|
|
387
|
+
setNote('这个环境不让写剪贴板,复制失败。')
|
|
388
|
+
}
|
|
389
|
+
} catch {
|
|
390
|
+
setNote('这个环境不让写剪贴板,复制失败。')
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// 导出报告:纯前端拼一个 markdown 文件下载,不新开任何服务端路由。
|
|
395
|
+
const downloadReport = () => {
|
|
396
|
+
const md = reports?.md || ''
|
|
397
|
+
if (!md) { setNote('这一天的报告正文还没取到,没有可导出的。点一下上面那天的日期再取一次。'); return }
|
|
398
|
+
if (typeof document === 'undefined' || typeof Blob === 'undefined') { setNote('这个环境不支持下载。'); return }
|
|
399
|
+
try {
|
|
400
|
+
const blob = new Blob([md], { type: 'text/markdown;charset=utf-8' })
|
|
401
|
+
const a = document.createElement('a')
|
|
402
|
+
a.href = URL.createObjectURL(blob)
|
|
403
|
+
a.download = `大肥鱼-报告-${reports.date || 'latest'}.md`
|
|
404
|
+
a.click()
|
|
405
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 4000)
|
|
406
|
+
setNote(`已导出 ${a.download}`)
|
|
407
|
+
} catch (e) { setErr(e.message) }
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// 2026-10-25:B 站登录提示卡。存好之后自己消失;也可以手动点「不用了」
|
|
411
|
+
// (选择记进 config.ui.ownerHintDismissed,别再反复出现)。
|
|
412
|
+
const ownerHintCard = (ow && !ow.hasCookie && !uiHintDismissed)
|
|
413
|
+
? h('div', { className: 'card', style: { borderColor: 'var(--dsw-alias-border-l2)' } },
|
|
414
|
+
h('h3', null, '还没存 B 站登录'),
|
|
415
|
+
h('div', { className: 'dim' },
|
|
416
|
+
'发评论和回复要用到它;读热评、读回复不用它;看画面没有它也会试着取,但不一定取得到,有它更稳。存好之后这张卡会自己消失——不想存就点「不用了」,以后不再提示。'),
|
|
417
|
+
h('div', { className: 'row', style: { gap: '8px', marginTop: '6px' } },
|
|
418
|
+
// issue #12(TulleyT,2026-10-29):这里原写 showTab('bili'),而 showTab 是
|
|
419
|
+
// 「现在是不是这个页」的判据(返回布尔),真正的切换是 setTab。返回值被丢弃,
|
|
420
|
+
// 所以点了既不跳页也不报错。从 0.6.1 起就这样,一直没人点到过。
|
|
421
|
+
h('button', { onClick: () => setTab('bili') }, '去上网页存'),
|
|
422
|
+
h('button', {
|
|
423
|
+
className: 'ghost',
|
|
424
|
+
onClick: async () => {
|
|
425
|
+
try {
|
|
426
|
+
await jpost('/config', { ui: { ownerHintDismissed: true } })
|
|
427
|
+
setUiHintDismissed(true)
|
|
428
|
+
} catch (e) { setErr(e.message) }
|
|
429
|
+
},
|
|
430
|
+
}, '不用了')))
|
|
431
|
+
: null
|