dsh-config-manager 0.3.1 → 0.4.0
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/lib/client.d.ts +33 -1
- package/lib/client.js +1060 -835
- package/lib/core/env-lock-lifecycle.d.ts +45 -0
- package/lib/core/env-lock-lifecycle.js +43 -0
- package/lib/core/history-prune.d.ts +34 -0
- package/lib/core/history-prune.js +43 -0
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/migration-history.d.ts +28 -2
- package/lib/core/migration-history.js +41 -4
- package/lib/index.d.ts +2 -2
- package/lib/index.js +24 -6
- package/lib/routes/history.js +70 -5
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/messages.d.ts +1 -0
- package/lib/routes/messages.js +3 -0
- package/lib/sync/autosync-scheduler.js +6 -0
- package/lib/sync/backup-scheduler.js +6 -0
- package/lib/sync/ui-prefs.d.ts +8 -0
- package/lib/sync/ui-prefs.js +8 -0
- package/lib/utils/env-lock.d.ts +55 -1
- package/lib/utils/env-lock.js +131 -2
- package/lib/utils/messages-utils.d.ts +3 -0
- package/lib/utils/messages-utils.js +6 -0
- package/package.json +1 -1
- package/src/client/common/InfoHint.tsx +12 -3
- package/src/client/common/Skeleton.tsx +45 -8
- package/src/client/common/info-hint-guard.test.ts +196 -0
- package/src/client/common/routes.ts +3 -1
- package/src/client/common/skeleton-guard.test.ts +58 -0
- package/src/client/common/ui.tsx +17 -4
- package/src/client/config-manager.module.css +256 -27
- package/src/client/css-motion-guard.test.ts +230 -0
- package/src/client/environment/EnvironmentPanel.tsx +41 -29
- package/src/client/environment/maintenance/DiskUsageCard.tsx +28 -33
- package/src/client/environment/profiles-incomplete-ui.test.ts +9 -5
- package/src/client/export/ExportView.tsx +6 -6
- package/src/client/history/HistoryPanel.tsx +87 -2
- package/src/client/history/history-api.ts +49 -3
- package/src/client/history/history-locales.ts +30 -0
- package/src/client/home/HomePanel.tsx +55 -23
- package/src/client/market/MyConfigsWizard.tsx +12 -3
- package/src/client/recovery/RecoveryPanel.tsx +93 -92
- package/src/client/recovery/RollbackCard.tsx +25 -16
- package/src/client/sync/AutosyncCard.tsx +12 -6
- package/src/client/sync/ChannelConfigDialog.tsx +45 -45
- package/src/client/sync/DecryptPasswordCard.tsx +3 -3
- package/src/client/sync/SecurityOptionsCard.tsx +3 -3
- package/src/client/sync/SyncSectionPickerDialog.tsx +3 -3
- package/src/core/env-lock-lifecycle.ts +73 -0
- package/src/core/history-prune.test.ts +115 -0
- package/src/core/history-prune.ts +61 -0
- package/src/core/index.ts +2 -0
- package/src/core/migration-history.test.ts +78 -0
- package/src/core/migration-history.ts +46 -4
- package/src/index.ts +25 -6
- package/src/routes/history.ts +81 -4
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/messages.ts +3 -0
- package/src/sync/autosync-scheduler.ts +3 -0
- package/src/sync/backup-scheduler.ts +3 -0
- package/src/sync/ui-prefs.test.ts +32 -0
- package/src/sync/ui-prefs.ts +16 -0
- package/src/utils/env-lock.test.ts +107 -0
- package/src/utils/env-lock.ts +124 -2
- package/src/utils/messages-utils.ts +6 -0
|
@@ -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
|
-
{
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
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
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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
|
-
<
|
|
718
|
-
{
|
|
719
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
<
|
|
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
|
-
</
|
|
454
|
-
<
|
|
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
|
-
</
|
|
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
|
|
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
|
-
|
|
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}>
|
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 端点契约(Host 半 src/index.ts makeRoutes 按此实现):
|
|
5
5
|
* ```
|
|
6
|
-
* GET /api/dsh-config-manager/history?kind=…&result=…&from=…&to=…§ions
|
|
7
|
-
* → { ok:true, entries: StoredMigrationHistoryEntry[], stats, corrupted }
|
|
6
|
+
* GET /api/dsh-config-manager/history?kind=…&result=…&from=…&to=…§ions=…&limit=N
|
|
7
|
+
* → { ok:true, entries: StoredMigrationHistoryEntry[], stats, corrupted, total, scanned, limit }
|
|
8
|
+
* limit = 只读最近 N 条(尾部窗口;缺省全量)。total = 目录内合法文件总数。
|
|
8
9
|
* GET /api/dsh-config-manager/history/export?format=markdown|json&…(同过滤)
|
|
9
10
|
* → markdown:下载附件;json:{ ok, generatedAt, text }
|
|
11
|
+
* GET /api/dsh-config-manager/history/retention
|
|
12
|
+
* → { ok, maxEntries, total, defaultMaxEntries, allowedMin, allowedMax }
|
|
13
|
+
* POST /api/dsh-config-manager/history/retention { maxEntries }
|
|
14
|
+
* → { ok, maxEntries, removed, total }(改策略并立即清理一次;0 = 不限制)
|
|
10
15
|
* ```
|
|
11
16
|
*
|
|
12
17
|
* 安全约束:
|
|
@@ -16,7 +21,7 @@
|
|
|
16
21
|
*/
|
|
17
22
|
import type { StoredMigrationHistoryEntry, MigrationKind, MigrationResult } from '../../core/migration-history.ts';
|
|
18
23
|
import type { MigrationHistoryStats } from '../../core/migration-history.ts';
|
|
19
|
-
import { getJson, openStream, readJson, type RequestOptions } from '../common/http.ts';
|
|
24
|
+
import { getJson, openStream, postJson, readJson, type RequestOptions } from '../common/http.ts';
|
|
20
25
|
import type { UiT } from '../../ui/i18n.ts';
|
|
21
26
|
import { HISTORY_API } from '../common/routes.ts';
|
|
22
27
|
|
|
@@ -34,6 +39,34 @@ export interface HistoryListResult {
|
|
|
34
39
|
entries: StoredMigrationHistoryEntry[];
|
|
35
40
|
stats: MigrationHistoryStats;
|
|
36
41
|
corrupted: string[];
|
|
42
|
+
/** 目录内合法历史文件总数(含被 limit 窗口挡在外的旧条目;老宿主可能不返回)。 */
|
|
43
|
+
total?: number;
|
|
44
|
+
/** 本次实际读取条数(= 窗口大小;用于「仅显示最近 N 条」提示)。 */
|
|
45
|
+
scanned?: number;
|
|
46
|
+
/** 本次生效的 limit(0 = 全量)。 */
|
|
47
|
+
limit?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 自动清理策略现状(GET /history/retention)。 */
|
|
51
|
+
export interface HistoryRetentionState {
|
|
52
|
+
ok: boolean;
|
|
53
|
+
/** 当前保留上限;0 = 不限制。 */
|
|
54
|
+
maxEntries: number;
|
|
55
|
+
/** 目录内当前条数。 */
|
|
56
|
+
total: number;
|
|
57
|
+
/** 缺省上限(UI「恢复默认」用)。 */
|
|
58
|
+
defaultMaxEntries: number;
|
|
59
|
+
allowedMin: number;
|
|
60
|
+
allowedMax: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 保存策略后的结果(POST /history/retention)。 */
|
|
64
|
+
export interface HistoryRetentionResult {
|
|
65
|
+
ok: boolean;
|
|
66
|
+
maxEntries: number;
|
|
67
|
+
/** 本次立即清理删除的条数。 */
|
|
68
|
+
removed: number;
|
|
69
|
+
total: number;
|
|
37
70
|
}
|
|
38
71
|
|
|
39
72
|
/** 导出 JSON 返回体(markdown 走附件下载,不返回 JSON body)。 */
|
|
@@ -67,6 +100,8 @@ export class HistoryApi {
|
|
|
67
100
|
from?: number;
|
|
68
101
|
to?: number;
|
|
69
102
|
sections?: string[];
|
|
103
|
+
/** 只读最近 N 条(缺省/0 = 全量;首页只取几十条避免全量读+回传)。 */
|
|
104
|
+
limit?: number;
|
|
70
105
|
} = {}): Promise<HistoryListResult> {
|
|
71
106
|
const query: Record<string, string | undefined> = {};
|
|
72
107
|
if (params.kind !== undefined) query['kind'] = Array.isArray(params.kind) ? params.kind.join(',') : params.kind;
|
|
@@ -74,9 +109,20 @@ export class HistoryApi {
|
|
|
74
109
|
if (params.from !== undefined) query['from'] = String(params.from);
|
|
75
110
|
if (params.to !== undefined) query['to'] = String(params.to);
|
|
76
111
|
if (params.sections !== undefined && params.sections.length > 0) query['sections'] = params.sections.join(',');
|
|
112
|
+
if (params.limit !== undefined && params.limit > 0) query['limit'] = String(params.limit);
|
|
77
113
|
return getJson<HistoryListResult>(this.buildListUrl(query), this.t, HISTORY_OPTS);
|
|
78
114
|
}
|
|
79
115
|
|
|
116
|
+
/** GET /history/retention:当前自动清理策略 + 目录现状。 */
|
|
117
|
+
async getRetention(): Promise<HistoryRetentionState> {
|
|
118
|
+
return getJson<HistoryRetentionState>(HISTORY_API.retention, this.t, HISTORY_OPTS);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** POST /history/retention:改保留上限并立即清理一次(0 = 不限制)。 */
|
|
122
|
+
async setRetention(maxEntries: number): Promise<HistoryRetentionResult> {
|
|
123
|
+
return postJson<HistoryRetentionResult>(HISTORY_API.retention, { maxEntries }, this.t, HISTORY_OPTS);
|
|
124
|
+
}
|
|
125
|
+
|
|
80
126
|
/**
|
|
81
127
|
* 导出历史报告(markdown → 下载附件;json → { text })。
|
|
82
128
|
* 过滤参数与 list 相同。
|
|
@@ -31,6 +31,16 @@ type CommonKey =
|
|
|
31
31
|
| 'history.exportError'
|
|
32
32
|
| 'history.refresh'
|
|
33
33
|
| 'history.refreshError'
|
|
34
|
+
| 'history.retention.label'
|
|
35
|
+
| 'history.retention.hint'
|
|
36
|
+
| 'history.retention.unlimited'
|
|
37
|
+
| 'history.retention.units'
|
|
38
|
+
| 'history.retention.current'
|
|
39
|
+
| 'history.retention.runNow'
|
|
40
|
+
| 'history.retention.running'
|
|
41
|
+
| 'history.retention.cleaned'
|
|
42
|
+
| 'history.retention.noop'
|
|
43
|
+
| 'history.retention.saveError'
|
|
34
44
|
/** ⓘ 说明按钮的可访问名(与主字典 / market / sync / recovery 同口径,见 info-hint-guard t6-4) */
|
|
35
45
|
| 'common.infoHint';
|
|
36
46
|
|
|
@@ -61,6 +71,16 @@ export const zh = {
|
|
|
61
71
|
'history.exportError': '导出失败',
|
|
62
72
|
'history.refresh': '刷新',
|
|
63
73
|
'history.refreshError': '刷新失败',
|
|
74
|
+
'history.retention.label': '自动清理',
|
|
75
|
+
'history.retention.hint': '历史条目超过上限时自动删除最旧的;0 = 不限制。清理本身不写历史条目,避免「清理把自己写进历史」的死循环。',
|
|
76
|
+
'history.retention.unlimited': '不限制',
|
|
77
|
+
'history.retention.units': '{count} 条',
|
|
78
|
+
'history.retention.current': '磁盘上 {count} 条',
|
|
79
|
+
'history.retention.runNow': '立即清理',
|
|
80
|
+
'history.retention.running': '清理中…',
|
|
81
|
+
'history.retention.cleaned': '已清理 {count} 条',
|
|
82
|
+
'history.retention.noop': '无需清理',
|
|
83
|
+
'history.retention.saveError': '保存自动清理策略失败',
|
|
64
84
|
'history.kind.import': '导入',
|
|
65
85
|
'history.kind.restore': '快照恢复',
|
|
66
86
|
'history.kind.rollback': '回滚',
|
|
@@ -108,6 +128,16 @@ export const en = {
|
|
|
108
128
|
'history.exportError': 'Export failed',
|
|
109
129
|
'history.refresh': 'Refresh',
|
|
110
130
|
'history.refreshError': 'Refresh failed',
|
|
131
|
+
'history.retention.label': 'Auto-cleanup',
|
|
132
|
+
'history.retention.hint': 'Delete the oldest entries once the limit is exceeded; 0 = unlimited. Cleanup writes no history entry, so it can never feed itself.',
|
|
133
|
+
'history.retention.unlimited': 'Unlimited',
|
|
134
|
+
'history.retention.units': '{count} entries',
|
|
135
|
+
'history.retention.current': '{count} on disk',
|
|
136
|
+
'history.retention.runNow': 'Clean up now',
|
|
137
|
+
'history.retention.running': 'Cleaning…',
|
|
138
|
+
'history.retention.cleaned': 'Removed {count}',
|
|
139
|
+
'history.retention.noop': 'Nothing to remove',
|
|
140
|
+
'history.retention.saveError': 'Failed to save auto-cleanup policy',
|
|
111
141
|
'history.kind.import': 'Import',
|
|
112
142
|
'history.kind.restore': 'Snapshot restore',
|
|
113
143
|
'history.kind.rollback': 'Rollback',
|