dsh-config-manager 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/lib/client.d.ts +54 -3
  2. package/lib/client.js +1078 -845
  3. package/lib/core/env-lock-lifecycle.d.ts +45 -0
  4. package/lib/core/env-lock-lifecycle.js +43 -0
  5. package/lib/core/history-prune.d.ts +34 -0
  6. package/lib/core/history-prune.js +43 -0
  7. package/lib/core/index.d.ts +1 -1
  8. package/lib/core/index.js +1 -1
  9. package/lib/core/messages-core.d.ts +1 -0
  10. package/lib/core/messages-core.js +2 -0
  11. package/lib/core/migration-history.d.ts +46 -4
  12. package/lib/core/migration-history.js +60 -7
  13. package/lib/index.d.ts +2 -2
  14. package/lib/index.js +26 -8
  15. package/lib/routes/history.js +70 -5
  16. package/lib/routes/index.d.ts +1 -1
  17. package/lib/routes/kit.d.ts +2 -2
  18. package/lib/routes/messages.d.ts +1 -0
  19. package/lib/routes/messages.js +3 -0
  20. package/lib/sync/autosync-scheduler.js +12 -2
  21. package/lib/sync/backup-scheduler.js +6 -0
  22. package/lib/sync/baseline-heal.d.ts +35 -0
  23. package/lib/sync/baseline-heal.js +39 -0
  24. package/lib/sync/push-precheck.d.ts +35 -0
  25. package/lib/sync/push-precheck.js +58 -0
  26. package/lib/sync/sync-engine.d.ts +9 -12
  27. package/lib/sync/sync-engine.js +24 -43
  28. package/lib/sync/ui-prefs.d.ts +8 -0
  29. package/lib/sync/ui-prefs.js +8 -0
  30. package/lib/ui/history-model.js +3 -2
  31. package/lib/ui/overview-view.d.ts +3 -3
  32. package/lib/ui/overview-view.js +9 -1
  33. package/lib/utils/env-lock.d.ts +55 -1
  34. package/lib/utils/env-lock.js +131 -2
  35. package/lib/utils/messages-utils.d.ts +3 -0
  36. package/lib/utils/messages-utils.js +6 -0
  37. package/package.json +1 -1
  38. package/src/client/common/InfoHint.tsx +12 -3
  39. package/src/client/common/Skeleton.tsx +45 -8
  40. package/src/client/common/info-hint-guard.test.ts +196 -0
  41. package/src/client/common/routes.ts +3 -1
  42. package/src/client/common/skeleton-guard.test.ts +58 -0
  43. package/src/client/common/ui.tsx +17 -4
  44. package/src/client/config-manager.module.css +256 -27
  45. package/src/client/css-motion-guard.test.ts +230 -0
  46. package/src/client/environment/EnvironmentPanel.tsx +41 -29
  47. package/src/client/environment/maintenance/DiskUsageCard.tsx +28 -33
  48. package/src/client/environment/profiles-incomplete-ui.test.ts +9 -5
  49. package/src/client/export/ExportView.tsx +6 -6
  50. package/src/client/history/HistoryPanel.tsx +87 -2
  51. package/src/client/history/history-api.ts +49 -3
  52. package/src/client/history/history-locales.ts +32 -0
  53. package/src/client/home/HomePanel.tsx +64 -26
  54. package/src/client/locales.ts +2 -0
  55. package/src/client/market/MyConfigsWizard.tsx +12 -3
  56. package/src/client/recovery/RecoveryPanel.tsx +93 -92
  57. package/src/client/recovery/RollbackCard.tsx +25 -16
  58. package/src/client/sync/AutosyncCard.tsx +12 -6
  59. package/src/client/sync/ChannelConfigDialog.tsx +45 -45
  60. package/src/client/sync/DecryptPasswordCard.tsx +3 -3
  61. package/src/client/sync/SecurityOptionsCard.tsx +3 -3
  62. package/src/client/sync/SyncSectionPickerDialog.tsx +3 -3
  63. package/src/client/sync/history-model.ts +3 -0
  64. package/src/client/sync/sync-locales.ts +2 -0
  65. package/src/core/env-lock-lifecycle.ts +73 -0
  66. package/src/core/history-prune.test.ts +115 -0
  67. package/src/core/history-prune.ts +61 -0
  68. package/src/core/index.ts +2 -0
  69. package/src/core/messages-core.ts +2 -0
  70. package/src/core/migration-history.test.ts +97 -0
  71. package/src/core/migration-history.ts +74 -9
  72. package/src/index.ts +27 -8
  73. package/src/routes/history.ts +81 -4
  74. package/src/routes/index.ts +1 -1
  75. package/src/routes/kit.ts +2 -2
  76. package/src/routes/messages.ts +3 -0
  77. package/src/sync/autosync-scheduler.test.ts +23 -0
  78. package/src/sync/autosync-scheduler.ts +9 -2
  79. package/src/sync/backup-scheduler.ts +3 -0
  80. package/src/sync/baseline-heal.ts +74 -0
  81. package/src/sync/push-precheck.ts +75 -0
  82. package/src/sync/sync-engine.test.ts +88 -0
  83. package/src/sync/sync-engine.ts +33 -43
  84. package/src/sync/ui-prefs.test.ts +32 -0
  85. package/src/sync/ui-prefs.ts +16 -0
  86. package/src/ui/history-model.test.ts +2 -1
  87. package/src/ui/history-model.ts +3 -2
  88. package/src/ui/overview-view.test.ts +12 -0
  89. package/src/ui/overview-view.ts +12 -4
  90. package/src/utils/env-lock.test.ts +107 -0
  91. package/src/utils/env-lock.ts +124 -2
  92. package/src/utils/messages-utils.ts +6 -0
@@ -0,0 +1,230 @@
1
+ /**
2
+ * 动效守卫(源码级、零依赖、只读):2026-11-04 用户提的「按压回弹」与「勾形描边」两条。
3
+ *
4
+ * 钉住三件事(每条都带负向自检,删掉即红):
5
+ * 1. **按压回弹的两侧必须同时成立**:CSS 端 `\:active` 缩到 96%、松手用 `linear()` 弹簧曲线过冲
6
+ * 再落回;JSX 端**外链按钮**(Button 的 href 分支渲染 `<a>`)必须打 `data-pressable` ——
7
+ * 选择器是 `:is(button, [data-pressable])`,属性没人写就等于外链按钮永远没有按压反馈。
8
+ * 这条是实测发现的漂移(CSS 写了、JSX 漏了),所以两侧一起钉。
9
+ * 2. **勾形描边的落点**:勾不是原生 UA 画的(原生 checkbox 只有一次淡入,::before/::after
10
+ * 画不进去),而是 `appearance:none` + SVG mask 当笔画 + `clip-path` 从左往右揭开;
11
+ * 柱子必须有显式 `box-sizing: border-box`(本仓库没有全局 `*{box-sizing}` 复位)。
12
+ * 3. **reduced-motion 的终态**:关掉动画后**必须补上揭开的终态** clip-path,否则勾形永远是
13
+ * 裁掉的样子(勾选框看起来全空)。这是「减法动画」最容易踩的坑,单列一条钉住。
14
+ *
15
+ * 复现:`node --test src/client/css-motion-guard.test.ts`
16
+ */
17
+ import test from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+
22
+ import { stripJsComments } from '../utils/bundle-scan.ts';
23
+
24
+ /** 仓库根(本文件位于 <root>/src/client/)。 */
25
+ const ROOT = path.resolve(import.meta.dirname, '../..');
26
+ const STYLE_FILE = 'src/client/config-manager.module.css';
27
+ const UI_FILE = 'src/client/common/ui.tsx';
28
+
29
+ /** 读取即折 LF(issue #70 同口径:锚点全是含 \n 的源码字面量)。 */
30
+ const read = (rel: string): string => fs.readFileSync(path.join(ROOT, rel), 'utf8').replace(/\r\n?/g, '\n');
31
+
32
+ /** 负向自检的改写:锚点必须命中(源码改了要同步守卫,而不是静默绿灯)。 */
33
+ function mutate(text: string, from: string, to: string): string {
34
+ assert.ok(text.includes(from), '负向自检锚点未命中(源码改写后需同步守卫):' + from);
35
+ return text.replace(from, to);
36
+ }
37
+
38
+ /** 取一条选择器规则的声明块(含嵌套花括号也要正确闭合)。 */
39
+ function ruleBody(css: string, selector: string): string | null {
40
+ const at = css.indexOf(selector);
41
+ if (at === -1) return null;
42
+ const open = css.indexOf('{', at);
43
+ if (open === -1) return null;
44
+ let depth = 0;
45
+ for (let i = open; i < css.length; i++) {
46
+ if (css[i] === '{') depth++;
47
+ else if (css[i] === '}') {
48
+ depth--;
49
+ if (depth === 0) return css.slice(open + 1, i);
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+
55
+ /**
56
+ * 所有 reduced-motion 媒体块的正文。
57
+ * 为什么是复数:样式表里有多个 `@media (prefers-reduced-motion: reduce)` 块(历史遗留 + 本次追加),
58
+ * 只取第一处会让守卫看漏(第一处恰是 `.taskPanel`,与本次改动无关)。
59
+ */
60
+ function reducedMotionBodies(css: string): string[] {
61
+ const out: string[] = [];
62
+ const needle = '@media (prefers-reduced-motion: reduce)';
63
+ let from = 0;
64
+ for (;;) {
65
+ const at = css.indexOf(needle, from);
66
+ if (at === -1) break;
67
+ const body = ruleBody(css.slice(at), needle);
68
+ if (body !== null) out.push(body);
69
+ from = at + needle.length;
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** reduced-motion 违规扫描:关动画的同时必须补终态。 */
75
+ function findReducedMotionViolations(css: string): string[] {
76
+ const bodies = reducedMotionBodies(css).join('\n');
77
+ if (bodies === '') return ['缺少 @media (prefers-reduced-motion: reduce) 块'];
78
+ const violations: string[] = [];
79
+ if (!/:is\(button, \[data-pressable\]\):not\(:disabled\):active\s*\{[^}]*transform:\s*none/.test(bodies)) {
80
+ violations.push('reduced-motion 下必须关掉按压缩放(transform: none)');
81
+ }
82
+ const checked = ruleBody(bodies, ".section input[type='checkbox']:checked::after {");
83
+ if (checked === null) {
84
+ violations.push('reduced-motion 下必须单独处理勾选态');
85
+ return violations;
86
+ }
87
+ if (!/animation:\s*none/.test(checked)) violations.push('reduced-motion 下必须关掉描边动画');
88
+ if (!/clip-path:\s*inset\(0 0 0 0\)/.test(checked)) {
89
+ violations.push('reduced-motion 下必须补上「全部露出」的终态(只关 animation 会让勾形永远被裁掉)');
90
+ }
91
+ return violations;
92
+ }
93
+
94
+ /** 按压回弹违规扫描(CSS 侧)。 */
95
+ function findPressCssViolations(css: string): string[] {
96
+ const violations: string[] = [];
97
+ if (!/--cm-press-spring:\s*linear\(/.test(css)) {
98
+ violations.push('缺少 --cm-press-spring: linear(…) —— 三次贝塞尔的过冲在按钮尺寸上肉眼无感,只能用 linear() 的 >1 进度');
99
+ }
100
+ const base = ruleBody(css, '.section :is(button, [data-pressable]) {');
101
+ if (base === null) {
102
+ violations.push('缺少按压回弹的基础规则 .section :is(button, [data-pressable])');
103
+ } else {
104
+ if (!/transition-property:[^;]*transform/.test(base)) violations.push('基础规则必须把 transform 放进 transition-property(否则缩放是瞬跳)');
105
+ if (!/transition-timing-function:[^;]*--cm-press-spring/.test(base)) violations.push('松手必须用 --cm-press-spring(弹簧过冲的来源)');
106
+ // 三色过渡不能被顶掉:简写会整体覆盖列表,这里要求列表里同时有颜色与 transform
107
+ if (!/transition-property:[^;]*background-color/.test(base) || !/transition-property:[^;]*color/.test(base)) {
108
+ violations.push('transform 必须并进三色过渡的列表,不得用 transition 简写顶掉 hover 变色');
109
+ }
110
+ }
111
+ const active = ruleBody(css, '.section :is(button, [data-pressable]):not(:disabled):active {');
112
+ if (active === null) {
113
+ violations.push('缺少 :active 规则(按下时的缩小态)');
114
+ } else {
115
+ if (!/transform:\s*scale\(0\.96\)/.test(active)) violations.push(':active 必须缩到 scale(0.96)(用户要求 96%)');
116
+ if (!/transition-timing-function:[^;]*ease-out/.test(active)) violations.push(':active 的 transform 必须回到 ease-out(跟手、不飘)');
117
+ }
118
+ return violations;
119
+ }
120
+
121
+ test('t13-1 按压回弹:按到 96%、松手弹簧过冲(CSS 侧的曲线与档位)', () => {
122
+ const css = read(STYLE_FILE);
123
+ const violations = findPressCssViolations(css);
124
+ assert.deepEqual(violations, [], '按压回弹的样式不完整:\n' + violations.join('\n'));
125
+
126
+ const noScale = mutate(css, ' transform: scale(0.96);', ' transform: none;');
127
+ assert.ok(findPressCssViolations(noScale).length >= 1, '去掉 96% 缩放必须报红');
128
+ const noSpring = mutate(css, 'transition-timing-function: ease, ease, ease, var(--cm-press-spring);', 'transition-timing-function: ease;');
129
+ assert.ok(findPressCssViolations(noSpring).length >= 1, '松手不用弹簧曲线必须报红');
130
+ const shorthand = mutate(
131
+ css,
132
+ ' transition-property: background-color, border-color, color, transform;\n transition-duration: var(--cm-motion-fast), var(--cm-motion-fast), var(--cm-motion-fast), var(--cm-motion-base);\n transition-timing-function: ease, ease, ease, var(--cm-press-spring);',
133
+ ' transition: transform var(--cm-motion-base) var(--cm-press-spring);',
134
+ );
135
+ assert.ok(findPressCssViolations(shorthand).length >= 1, '退回 transition 简写(会顶掉 hover 变色)必须报红');
136
+ });
137
+
138
+ /** Button 的 href 分支渲染出的 `<a>` 开标签原文(找不到返回 null)。 */
139
+ function anchorTagOf(ui: string): string | null {
140
+ const branch = ui.indexOf('if (href !== undefined) {');
141
+ if (branch === -1) return null;
142
+ const start = ui.indexOf('<a', branch);
143
+ if (start === -1) return null;
144
+ const end = ui.indexOf('>', start);
145
+ if (end === -1) return null;
146
+ return ui.slice(start, end + 1);
147
+ }
148
+
149
+ test('t13-2 外链按钮必须打 data-pressable(选择器靠属性入队,漏写就没有按压反馈)', () => {
150
+ const ui = stripJsComments(read(UI_FILE), true, false);
151
+ const tag = anchorTagOf(ui);
152
+ assert.ok(tag !== null, UI_FILE + ' 里找不到 Button 的 href 分支渲染的 <a>(守卫需同步)');
153
+ assert.ok(
154
+ tag.includes('data-pressable'),
155
+ '外链按钮必须带 data-pressable=""(CSS 的按压选择器只认 button 与该属性):' + tag.replace(/\s+/g, ' '),
156
+ );
157
+ // 负向自检:删掉属性后同一条判据必须红
158
+ const stripped = mutate(ui, ' data-pressable=""\n', '');
159
+ const strippedTag = anchorTagOf(stripped);
160
+ assert.ok(strippedTag !== null && !strippedTag.includes('data-pressable'), '负向自检:删掉属性后必须判定为缺属性');
161
+ });
162
+
163
+ /** 勾形描边违规扫描(自绘 + 笔画方向 + 播放时机)。 */
164
+ function findCheckStrokeViolations(css: string): string[] {
165
+ const violations: string[] = [];
166
+ const base = ruleBody(css, ".section input[type='checkbox'] {");
167
+ if (base === null) {
168
+ violations.push('缺少勾选框自绘的基础规则 input[type=checkbox]');
169
+ } else {
170
+ if (!/appearance:\s*none/.test(base)) violations.push('必须 appearance:none 接管原生勾选框(原生只有一次淡入,画不出描边)');
171
+ if (!/box-sizing:\s*border-box/.test(base)) violations.push('必须显式 box-sizing:border-box(仓库没有全局 *{box-sizing} 复位)');
172
+ }
173
+ const mark = ruleBody(css, ".section input[type='checkbox']::after {");
174
+ if (mark === null) {
175
+ violations.push('缺少 ::after 的勾形');
176
+ } else {
177
+ if (!/mask-image:\s*url\("data:image\/svg\+xml/.test(mark)) violations.push('勾形必须是 SVG 笔画 mask(不是字符、不是第二张图)');
178
+ if (!/clip-path:\s*inset\(0 100% 0 0\)/.test(mark)) violations.push('未勾选时必须整条裁掉(起点 = 左下起笔)');
179
+ }
180
+ if (!/@keyframes checkStroke\s*\{[\s\S]*?from\s*\{[^}]*clip-path:\s*inset\(0 100% 0 0\)[\s\S]*?to\s*\{[^}]*clip-path:\s*inset\(0 0 0 0\)/.test(css)) {
181
+ violations.push('checkStroke 必须从「整条裁掉」到「全部露出」——即从左往右一路画过去');
182
+ }
183
+ const checked = ruleBody(css, ".section input[type='checkbox']:checked::after {");
184
+ if (checked === null || !/animation:\s*checkStroke/.test(checked)) violations.push('勾选态必须播放 checkStroke');
185
+ else if (!/animation:\s*checkStroke\s+var\(--cm-motion-draw\)/.test(checked)) {
186
+ // 用户实测(2026-11-04 第二条):「没有动画或者太快」—— 180ms 的 base 在 16px 方框上只是一闪。
187
+ violations.push('勾选态必须用 --cm-motion-draw 播描边(base 的 180ms 太快,读不出笔画移动)');
188
+ } else if (!/var\(--cm-motion-draw\)\s+var\(--cm-motion-ease-draw\)/.test(checked)) {
189
+ // 缓动也是观感的一部分:ease-out 前 60ms 就画完 82%(仍像瞬间出现),ease-in-out 前 60ms 只有 6%(像先卡住)。
190
+ violations.push('勾选态必须用 --cm-motion-ease-draw(通用缓动的前段进度不适合「画」,实测要么一闪要么先卡住)');
191
+ }
192
+ const draw = /--cm-motion-draw:\s*(\d+)ms;/.exec(css);
193
+ if (draw === null) {
194
+ violations.push('--cm-motion-draw 必须定义在 body 上(缺定义 ⇒ 时长在 computed-value 阶段失效,动画静默不播)');
195
+ } else if (Number(draw[1]) < 300) {
196
+ violations.push('--cm-motion-draw 至少 300ms(用户实测 180ms 太快)');
197
+ }
198
+ if (!/--cm-motion-ease-draw:\s*cubic-bezier\(/.test(css)) {
199
+ violations.push('--cm-motion-ease-draw 必须以 cubic-bezier(…) 定义在 body 上');
200
+ }
201
+ return violations;
202
+ }
203
+
204
+ test('t13-3 勾选框自绘 + 勾形从左下画到右上(mask 笔画 + 左→右揭开)', () => {
205
+ const css = read(STYLE_FILE);
206
+ const violations = findCheckStrokeViolations(css);
207
+ assert.deepEqual(violations, [], '勾形描边不完整:\n' + violations.join('\n'));
208
+
209
+ const noAppearance = mutate(css, ' appearance: none;\n box-sizing: border-box;', ' box-sizing: border-box;');
210
+ assert.ok(findCheckStrokeViolations(noAppearance).length >= 1, '负向自检:退回原生勾选框必须报红');
211
+ const noReveal = mutate(css, ' clip-path: inset(0 100% 0 0);\n }\n to {', ' }\n to {');
212
+ assert.ok(findCheckStrokeViolations(noReveal).length >= 1, '负向自检:描边起点不裁掉必须报红');
213
+ const tooFast = mutate(css, ' animation: checkStroke var(--cm-motion-draw)', ' animation: checkStroke var(--cm-motion-base)');
214
+ assert.ok(findCheckStrokeViolations(tooFast).length >= 1, '负向自检:退回 180ms 的 base 必须报红');
215
+ const genericEase = mutate(css, 'var(--cm-motion-draw) var(--cm-motion-ease-draw)', 'var(--cm-motion-draw) var(--cm-motion-ease-out)');
216
+ assert.ok(findCheckStrokeViolations(genericEase).length >= 1, '负向自检:改用通用 ease-out 必须报红');
217
+ const noToken = mutate(css, ' --cm-motion-draw: 340ms;', ' --cm-motion-draw: 150ms;');
218
+ assert.ok(findCheckStrokeViolations(noToken).length >= 1, '负向自检:描边时长低于 300ms 必须报红');
219
+ });
220
+
221
+ test('t13-4 reduced-motion:关动画必须补终态(否则勾形永远看不见)', () => {
222
+ const css = read(STYLE_FILE);
223
+ const violations = findReducedMotionViolations(css);
224
+ assert.deepEqual(violations, [], 'reduced-motion 的终态不完整:\n' + violations.join('\n'));
225
+
226
+ const broken = mutate(css, ' animation: none;\n clip-path: inset(0 0 0 0);\n }', ' animation: none;\n }');
227
+ assert.ok(findReducedMotionViolations(broken).length >= 1, '负向自检:去掉勾形终态必须报红');
228
+ const noPress = mutate(css, ' transform: none;\n }', ' }');
229
+ assert.ok(findReducedMotionViolations(noPress).length >= 1, '负向自检:reduced-motion 下留着按压缩放必须报红');
230
+ });
@@ -35,7 +35,8 @@ import { runStore, toProfilesStoreSlice, type ProfilesStoreSlice } from '../run-
35
35
  import { RecoveryPanel } from '../recovery/RecoveryPanel.tsx'
36
36
  import type { RecoveryPort } from '../../ui/types.ts'
37
37
  import type { IncidentApi } from '../recovery/incident-api.ts'
38
- import { Badge, Banner, Button, Card, Checkbox, Empty, SectionTitle, Segmented } from '../common/ui.tsx'
38
+ import { Badge, Banner, Button, Card, Checkbox, Empty, IconButton, SectionTitle, Segmented } from '../common/ui.tsx'
39
+ import { Icon } from '../common/Icon.tsx'
39
40
  import { InfoHint } from '../common/InfoHint.tsx'
40
41
  import { Skeleton, SkeletonList } from '../common/Skeleton.tsx'
41
42
  import { Select } from '../common/Select.tsx'
@@ -625,12 +626,10 @@ export function EnvironmentPanel({ api, t, recoveryApi, recoveryT, incidentApi }
625
626
  )}
626
627
  {/* 残留行必须自报「未完成的副本」——不得伪装成普通「自定义」档案(t50);非残留行走原形态键 */}
627
628
  <Badge kind={incomplete ? 'warn' : 'info'}>{t(profileShapeLabelKey(profile))}</Badge>
628
- {version.dshVersion !== null && (
629
- <Badge kind="info">{t('profiles.version.dsh', { version: version.dshVersion })}</Badge>
630
- )}
631
- {version.sessionFormatVersion !== null && (
632
- <Badge kind="info">{t('profiles.version.format', { version: String(version.sessionFormatVersion) })}</Badge>
633
- )}
629
+ {/* 2026-11-04:DSH 版本 / 会话格式版本两个徽章移到行摘要(meta 行)。
630
+ 徽章区是「这一行有没有问题」的扫描带,最多时挤了 7 个 pill(≈300px),
631
+ 把档案名和摘要一起压到省略号。版本号是**描述**不是**状态**:
632
+ 它几乎总是不变、也从不改变你要不要动这一行 —— 属于 meta 行的料。 */}
634
633
  {formatRisk !== 'none' && (
635
634
  <Badge kind={formatRisk === 'newer' ? 'warn' : 'error'}>
636
635
  {t(formatRisk === 'newer' ? 'profiles.format.newer' : 'profiles.format.older')}
@@ -656,7 +655,11 @@ export function EnvironmentPanel({ api, t, recoveryApi, recoveryT, incidentApi }
656
655
  {/* 2026-11-01:这里原来还跟着「node_modules present · patch hot reload」
657
656
  两段 —— 它们与详情弹窗里的同名徽章重复(EnvironmentPanel 详情区),
658
657
  而三颗动作按钮已经把这一行压到尾部截断。行摘要只留三个计数,
659
- 那两段在点开详情时仍然逐字可见。 */}
658
+ 那两段在点开详情时仍然逐字可见。
659
+ 2026-11-04:DSH / 会话格式版本从徽章区挪到这里(同一行事实桶:
660
+ 「这行是什么版本、什么时候变过」),徽章区只留状态。 */}
661
+ {version.dshVersion !== null && <>{t('profiles.version.dsh', { version: version.dshVersion })}{' · '}</>}
662
+ {version.sessionFormatVersion !== null && <>{t('profiles.version.format', { version: String(version.sessionFormatVersion) })}{' · '}</>}
660
663
  {t('profiles.row.summary', { bundles: facts.bundles, patch: facts.patchEntries, deps: facts.deps })}
661
664
  {profile.updatedAtMs !== null && ` · ${t('profiles.updatedAt', { time: formatProfileTime(profile.updatedAtMs) })}`}
662
665
  </>
@@ -692,31 +695,40 @@ export function EnvironmentPanel({ api, t, recoveryApi, recoveryT, incidentApi }
692
695
  {t('profiles.launch')}
693
696
  </Button>
694
697
  )}
698
+ {/* 2026-11-04:复制 / 重命名 / 删除 收成图标按钮(复制与删除带危险语义)。
699
+ 三颗文字按钮合起来 ≈150px,全部花在「复制」「重命名」「删除」这六个字上;
700
+ 它们是**低频且不需要读**的动作 —— 图标 + title + aria-label 已经够认,
701
+ 省下的宽度还给档案名与徽章。启动/停止仍用文字按钮:那是这一行的主 CTA,
702
+ 图标化会让「现在能不能点、点了会发生什么」多绕一步。 */}
695
703
  {caps.duplicate && (
696
- <Button
697
- size="sm"
698
- title={t('profiles.duplicateHint')}
699
- disabled={state.copying}
700
- onClick={() => {
701
- patch({
702
- copyTargetName: profile.name,
703
- copyValue: suggestCopyName(profile.name, profileList.map((p) => p.name)),
704
- copyIncludeModules: profile.hasNodeModules,
705
- error: null,
706
- })
707
- }}
708
- >
709
- {t('profiles.duplicate')}
710
- </Button>
704
+ <IconButton
705
+ icon={<Icon name="copy" />}
706
+ label={t('profiles.duplicate')}
707
+ title={t('profiles.duplicateHint')}
708
+ disabled={state.copying}
709
+ onClick={() => {
710
+ patch({
711
+ copyTargetName: profile.name,
712
+ copyValue: suggestCopyName(profile.name, profileList.map((p) => p.name)),
713
+ copyIncludeModules: profile.hasNodeModules,
714
+ error: null,
715
+ })
716
+ }}
717
+ />
711
718
  )}
712
719
  {caps.rename && (
713
- <Button size="sm" onClick={() => { patch({ renameTargetName: profile.name, renameValue: profile.name, error: null }) }}>
714
- {t('profiles.rename')}
715
- </Button>
720
+ <IconButton
721
+ icon={<Icon name="pencil" />}
722
+ label={t('profiles.rename')}
723
+ onClick={() => { patch({ renameTargetName: profile.name, renameValue: profile.name, error: null }) }}
724
+ />
716
725
  )}
717
- <Button size="sm" variant="danger" onClick={() => { patch({ deleteTargetName: profile.name, deleteCurrentConfirmed: false, error: null }) }}>
718
- {t('profiles.delete')}
719
- </Button>
726
+ <IconButton
727
+ icon={<Icon name="delete" />}
728
+ label={t('profiles.delete')}
729
+ danger
730
+ onClick={() => { patch({ deleteTargetName: profile.name, deleteCurrentConfirmed: false, error: null }) }}
731
+ />
720
732
  </span>
721
733
  </div>
722
734
  </div>
@@ -171,39 +171,33 @@ export function DiskUsageCard({ api, infoHintLabel, onBackupsChanged }: DiskUsag
171
171
  {/* 读不到的子区如实说明:既不显示 0,也不整卡报错(硬边界:unreadable ≠ 0) */}
172
172
  {vm.summary.anyUnreadable && <div className={css.hint}>{t('diskUsage.partial')}</div>}
173
173
 
174
- <div className={css.planScroll + ' ' + css.diskUsageScroll}>
175
- <table className={`${css.dataTable} ${css.tableFixed} ${css.tableCompact}`}>
176
- <thead>
177
- <tr>
178
- <th>{t('diskUsage.col.area')}</th>
179
- <th className={css.num}>{t('diskUsage.col.size')}</th>
180
- <th className={css.num}>{t('diskUsage.col.files')}</th>
181
- <th>{t('diskUsage.col.policy')}</th>
182
- </tr>
183
- </thead>
184
- <tbody>
185
- {vm.rows.map((row) => (
186
- <tr key={row.id}>
187
- <td>
188
- <div>{row.label}</div>
189
- <div className={css.cellMetaNoteText}>{row.desc}</div>
190
- </td>
191
- <td className={css.num}>
192
- {row.unreadable ? <span className={css.dim}>{t('diskUsage.unreadable')}</span> : row.size}
193
- </td>
194
- <td className={css.num}>{row.unreadable ? '—' : row.files}</td>
195
- <td>
196
- {row.policy === 'regenerable' && <Badge kind="ok">{t('diskUsage.policy.regenerable')}</Badge>}
197
- {row.policy === 'retained' && <Badge kind="info">{t('diskUsage.policy.retained', { retention: row.retention })}</Badge>}
198
- {row.policy === 'protected' && <span className={css.dim}>{t('diskUsage.policy.protected')}</span>}
199
- {row.expired !== null && (
200
- <div className={css.cellMetaNoteText}>{t('diskUsage.expiredHint', { size: row.expired })}</div>
201
- )}
202
- </td>
203
- </tr>
204
- ))}
205
- </tbody>
206
- </table>
174
+ {/*
175
+ * 两行式行卡(2026-11-04):原先四列表格在 564px 画布下把「回收策略」列压到 160px,
176
+ * "Your data / safety net (never auto-removed)" 折成三行;表头还固定吃掉 24px。
177
+ * 现在第一行 = 区域名 + 右对齐占用(唯一右边缘),第二行 = 文件数 + 策略 + 过期量
178
+ * —— 策略拿到整行宽度,不再折行;表头由行内语义承担(占用单位在数值里,文件数自带
179
+ * 「个文件」)。desc 进 title:它说明「这块是哪来的」,不改变「能不能删」这个决定。
180
+ */}
181
+ <div className={css.planScroll + ' ' + css.diskUsageScroll + ' ' + css.duList} role="list">
182
+ {vm.rows.map((row) => (
183
+ <div key={row.id} className={css.duRow} role="listitem" title={row.desc}>
184
+ <div className={css.duRowTop}>
185
+ <span className={css.duRowName}>{row.label}</span>
186
+ <span className={css.duRowSize}>
187
+ {row.unreadable ? t('diskUsage.unreadable') : row.size}
188
+ </span>
189
+ </div>
190
+ <div className={css.duRowMeta}>
191
+ <span className={css.duRowFiles}>{row.unreadable ? '—' : row.files}</span>
192
+ {row.policy === 'regenerable' && <Badge kind="ok">{t('diskUsage.policy.regenerable')}</Badge>}
193
+ {row.policy === 'retained' && <Badge kind="info">{t('diskUsage.policy.retained', { retention: row.retention })}</Badge>}
194
+ {row.policy === 'protected' && <span>{t('diskUsage.policy.protected')}</span>}
195
+ {row.expired !== null && (
196
+ <span className={css.cellMetaNoteText}>{t('diskUsage.expiredHint', { size: row.expired })}</span>
197
+ )}
198
+ </div>
199
+ </div>
200
+ ))}
207
201
  </div>
208
202
 
209
203
  {/*
@@ -273,6 +267,7 @@ export function DiskUsageCard({ api, infoHintLabel, onBackupsChanged }: DiskUsag
273
267
  variant={includeExpired ? 'danger' : 'primary'}
274
268
  disabled={busy || nothingToReclaim}
275
269
  loading={busy}
270
+ title={nothingToReclaim ? t('diskUsage.clean.nothing') : undefined}
276
271
  onClick={() => { setConfirmOpen(true) }}
277
272
  >
278
273
  {busy ? t('diskUsage.clean.cleaning') : t('diskUsage.clean.now')}
@@ -55,11 +55,15 @@ test('cross-F3 UI:动作行三处把守 + 删除不被把守', () => {
55
55
  assert.match(block, /caps\.launchOrStop && rowAction === 'stop'/, '停止按钮必须由 caps.launchOrStop 把守')
56
56
  assert.match(block, /caps\.duplicate &&/, '复制按钮必须由 caps.duplicate 把守')
57
57
  assert.match(block, /caps\.rename &&/, '改名按钮必须由 caps.rename 把守')
58
- // 删除是残留行的唯一动作:它必须出现在改名把守闭合之后,本身不带任何 caps 条件
59
- assert.match(block, /\)\}\s*<Button size="sm" variant="danger"/,
60
- '删除按钮必须紧跟最后一个把守闭合、自身不带条件(残留行也要能点删除)')
61
- const dangerIndex = block.indexOf('variant="danger"')
62
- assert.ok(dangerIndex > 0 && !/caps\./.test(block.slice(dangerIndex)), '删除按钮内部不得再夹 caps 条件')
58
+ // 删除是残留行的唯一动作:它必须出现在改名把守闭合之后,本身不带任何 caps 条件。
59
+ // 2026-11-04:删除从文字按钮收成图标按钮(<IconButton danger>,行密度改造),控件形态变了、
60
+ // 判据不变 —— 仍是「紧跟最后一个把守闭合 + 自身不带 caps 条件」。
61
+ // rename 把守闭合之后紧跟着的必须是无条件的删除控件(危险语义)。
62
+ // 不按 lastIndexOf 取尾巴:`label={t('profiles.delete')}` 自身就以 `)}` 结尾。
63
+ assert.match(block, /caps\.rename &&[\s\S]*?\n\s*\)\}\s*<IconButton[\s\S]*?label=\{t\('profiles\.delete'\)\}[\s\S]*?\bdanger\b/,
64
+ '删除控件必须紧跟最后一个把守闭合、自身不带条件(残留行也要能点删除),且是危险语义')
65
+ const deleteStart = block.lastIndexOf('<IconButton', block.indexOf("profiles.delete'"))
66
+ assert.ok(deleteStart > 0 && !/caps\./.test(block.slice(deleteStart)), '删除控件内部不得再夹 caps 条件')
63
67
  })
64
68
 
65
69
  test('cross-F3 UI:残留行展示来源 / 开始时间 / 目录(目录经 redact)', () => {
@@ -429,14 +429,14 @@ export function ExportView({ api, t }: ExportViewProps) {
429
429
  {/* 4. 命名行:文件名 + 备注(双列)。两个 field 自带可见 label,
430
430
  分组标题「文件名与备注(可选)」只是把字段名再念一遍,已删除。 */}
431
431
  <div className={css.secretFields}>
432
- <label className={css.field}>
432
+ <div className={css.field}>
433
433
  <span className={css.fieldLabel}>
434
434
  {t('export.fileName')}
435
435
  {/* 输入规则属 MOVE 类(规则行收进字段标签旁的 ⓘ):非法时下面的 css.formError
436
436
  仍常驻重申字符规则(校验错误属 KEEP ①),规则不会因此不可见。 */}
437
437
  <InfoHint text={t('export.fileNameHint')} label={t('common.infoHint')} />
438
438
  </span>
439
- <input
439
+ <input aria-label={t('export.fileName')}
440
440
  type="text"
441
441
  className={css.input}
442
442
  value={fileName}
@@ -450,21 +450,21 @@ export function ExportView({ api, t }: ExportViewProps) {
450
450
  {/* KEEP ①:校验错误仍常驻(export.fileNameInvalid 本身就重申了允许的字符集),
451
451
  渲染与改前逐字一致;规则说明已收进字段标签旁的 ⓘ。 */}
452
452
  {fileNameInvalid && <span className={css.formError}>{t('export.fileNameInvalid')}</span>}
453
- </label>
454
- <label className={css.field}>
453
+ </div>
454
+ <div className={css.field}>
455
455
  <span className={css.fieldLabel}>
456
456
  {t('export.note')}
457
457
  {/* 备注说明属 MOVE 类(补充背景):收进字段标签旁的 ⓘ,不再常驻占一行 */}
458
458
  <InfoHint text={t('export.noteHint')} label={t('common.infoHint')} />
459
459
  </span>
460
- <input
460
+ <input aria-label={t('export.note')}
461
461
  type="text"
462
462
  className={css.input}
463
463
  value={note}
464
464
  placeholder={t('export.notePlaceholder')}
465
465
  onChange={(e: ChangeEvent<HTMLInputElement>) => { setNote(e.target.value) }}
466
466
  />
467
- </label>
467
+ </div>
468
468
  </div>
469
469
 
470
470
  {/* Phase 1:内容选择弹窗(分区 → 最小可拆单元;选择即生效,合计实时更新) */}
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { useEffect, useRef, useState } from 'react'
13
13
  import { redact } from '../../security/redaction.ts'
14
- import { HistoryApi, type HistoryListResult, type HistoryExportFormat } from './history-api.ts'
14
+ import { HistoryApi, type HistoryExportFormat, type HistoryListResult, type HistoryRetentionState } from './history-api.ts'
15
15
  import type { TranslateNS } from '../client-types.ts'
16
16
  import { Badge, Banner, Button, Card, Empty } from '../common/ui.tsx'
17
17
  import { InfoHint } from '../common/InfoHint.tsx'
@@ -48,6 +48,10 @@ interface PanelState {
48
48
  * 首次加载仍走 status='loading' 的骨架分支。
49
49
  */
50
50
  refreshing: boolean
51
+ /** 自动清理策略(上限 + 目录现状);读取失败为 null → 该行整行不渲染(不假装有策略)。 */
52
+ retention: HistoryRetentionState | null
53
+ /** 保存策略 / 立即清理进行中(同一颗按钮的 loading)。 */
54
+ retentionBusy: boolean
51
55
  }
52
56
 
53
57
  export function HistoryPanel({ historyApi, t }: HistoryPanelProps) {
@@ -58,6 +62,8 @@ export function HistoryPanel({ historyApi, t }: HistoryPanelProps) {
58
62
  filter: { query: '' },
59
63
  exporting: null,
60
64
  refreshing: false,
65
+ retention: null,
66
+ retentionBusy: false,
61
67
  })
62
68
  const mounted = useRef(true)
63
69
  useEffect(() => {
@@ -88,7 +94,47 @@ export function HistoryPanel({ historyApi, t }: HistoryPanelProps) {
88
94
  }
89
95
  }
90
96
  }
91
- useEffect(() => { void load() }, [historyApi]) // eslint-disable-line react-hooks/exhaustive-deps
97
+ /**
98
+ * 读自动清理策略。失败**不阻塞**历史列表:策略只是附加操作面,
99
+ * 读不到就整行不显示(渲染一个「上限未知」的下拉比没有更糟)。
100
+ */
101
+ const loadRetention = async (): Promise<void> => {
102
+ try {
103
+ const next = await historyApi.getRetention()
104
+ if (mounted.current) setState((s) => ({ ...s, retention: next }))
105
+ } catch { /* 策略读取失败 → 该行隐藏;历史列表照常可用 */ }
106
+ }
107
+
108
+ /**
109
+ * 保存保留上限并立即清理一次(把上限调小时用户期望「现在就收敛」,不是等下一次写入)。
110
+ * 清理只删旧文件、不写历史条目(宿主口径),所以结果反馈走 Toast,不改统计徽章语义。
111
+ */
112
+ const applyRetention = async (maxEntries: number): Promise<void> => {
113
+ setState((s) => ({ ...s, retentionBusy: true }))
114
+ try {
115
+ const saved = await historyApi.setRetention(maxEntries)
116
+ if (mounted.current) {
117
+ setState((s) => ({
118
+ ...s,
119
+ retentionBusy: false,
120
+ retention: s.retention === null ? s.retention : { ...s.retention, maxEntries: saved.maxEntries, total: saved.total },
121
+ }))
122
+ toast.ok(saved.removed > 0
123
+ ? t('history.retention.cleaned', { count: String(saved.removed) })
124
+ : t('history.retention.noop'))
125
+ }
126
+ // 真的删了旧条目才重载列表(quiet:不闪骨架;没删就什么都不用做)
127
+ if (saved.removed > 0) await load(true)
128
+ } catch (error) {
129
+ if (mounted.current) setState((s) => ({ ...s, retentionBusy: false }))
130
+ toast.error(t('history.retention.saveError') + ': ' + redact(error instanceof Error ? error.message : String(error)))
131
+ }
132
+ }
133
+
134
+ useEffect(() => {
135
+ void load()
136
+ void loadRetention()
137
+ }, [historyApi]) // eslint-disable-line react-hooks/exhaustive-deps
92
138
 
93
139
  const setFilter = (patch: Partial<HistoryFilter>): void => {
94
140
  setState((s) => ({ ...s, filter: { ...s.filter, ...patch } }))
@@ -142,6 +188,17 @@ export function HistoryPanel({ historyApi, t }: HistoryPanelProps) {
142
188
  // 并强制并入当前选中值 —— 否则会出现「选中了却在下拉里找不到该项」的怪状态。
143
189
  const kindOptions = collectHistoryKinds(entries, state.filter.kind)
144
190
  const resultOptions = collectHistoryResults(entries, state.filter.result)
191
+ // 自动清理上限下拉:预设档 + 当前值(有人在 ui-prefs.json 里手写过非预设值,
192
+ // 下拉也必须能显示真实策略,否则控件显示的上限与宿主实际执行的上限不是同一件事)。
193
+ const retention = state.retention
194
+ const retentionPresets = [0, 500, 1000, 5000, 10000]
195
+ const retentionValues = retention === null || retentionPresets.includes(retention.maxEntries)
196
+ ? retentionPresets
197
+ : [...retentionPresets, retention.maxEntries].sort((a, b) => a - b)
198
+ const retentionOptions = retentionValues.map((v) => ({
199
+ value: String(v),
200
+ label: v === 0 ? t('history.retention.unlimited') : t('history.retention.units', { count: String(v) }),
201
+ }))
145
202
 
146
203
  return (
147
204
  <div className={css.viewBody}>
@@ -164,6 +221,34 @@ export function HistoryPanel({ historyApi, t }: HistoryPanelProps) {
164
221
  </Banner>
165
222
  )}
166
223
 
224
+ {/* 自动清理:上限是**持久策略**(宿主在每次写历史后节流执行),与下面「过滤 / 导出」这类一次性操作
225
+ 分隔成独立卡。磁盘现状用徽章(状态),不写成第二句灰字;超限徽章转 warn —— 停在超限说明
226
+ 清理还没跑到(节流 60s 或本轮刚写过),不是「已收敛」。 */}
227
+ {retention !== null && (
228
+ <Card>
229
+ <div className={css.actionRow}>
230
+ <span className={css.fieldLabel}>
231
+ {t('history.retention.label')} <InfoHint text={t('history.retention.hint')} label={t('common.infoHint')} />
232
+ </span>
233
+ <Select
234
+ value={String(retention.maxEntries)}
235
+ onChange={(next) => void applyRetention(Number(next))}
236
+ options={retentionOptions}
237
+ />
238
+ <Badge kind={retention.maxEntries > 0 && retention.total > retention.maxEntries ? 'warn' : 'info'}>
239
+ {t('history.retention.current', { count: String(retention.total) })}
240
+ </Badge>
241
+ <Button
242
+ onClick={() => void applyRetention(retention.maxEntries)}
243
+ loading={state.retentionBusy}
244
+ disabled={state.retentionBusy}
245
+ >
246
+ {state.retentionBusy ? t('history.retention.running') : t('history.retention.runNow')}
247
+ </Button>
248
+ </div>
249
+ </Card>
250
+ )}
251
+
167
252
  {/* 过滤 + 导出:控件各自带维度标签(「操作类型: 全部」…),不再另起一行区块标题。 */}
168
253
  <Card>
169
254
  <div className={css.actionRow}>