dsh-plugin-trim 0.3.1 → 0.3.3
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/README.md +4 -2
- package/client.js +361 -47
- package/dist/index.d.ts +8 -0
- package/dist/index.js +114 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,13 +7,13 @@ DSH 插件生态的**减负**与**兼容性体检**插件。
|
|
|
7
7
|
从 npm 安装(推荐):
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
dsh plugin --profile web add dsh-plugin-trim@0.3.
|
|
10
|
+
dsh plugin --profile web add dsh-plugin-trim@0.3.3
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
从 GitHub Release 安装(备用,无需 npm):
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
dsh plugin --profile web add "https://github.com/Starlit-Sky-code/dsh-experience-optimizer/releases/download/v0.3.
|
|
16
|
+
dsh plugin --profile web add "https://github.com/Starlit-Sky-code/dsh-experience-optimizer/releases/download/v0.3.3/dsh-plugin-trim-0.3.3.tgz"
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
本地开发:
|
|
@@ -63,6 +63,7 @@ dsh plugin --profile web add /absolute/path/to/packages/plugin-trim
|
|
|
63
63
|
config:
|
|
64
64
|
mode: advise
|
|
65
65
|
approvalMode: always
|
|
66
|
+
suggestionPolicy: conservative
|
|
66
67
|
approvalThreshold: 5
|
|
67
68
|
protect:
|
|
68
69
|
- my-important-plugin
|
|
@@ -76,6 +77,7 @@ dsh plugin --profile web add /absolute/path/to/packages/plugin-trim
|
|
|
76
77
|
|---|---|---|
|
|
77
78
|
| `mode` | `advise` | `auto-safe` 只收窄建议范围 |
|
|
78
79
|
| `approvalMode` | `always` | `always`:每次工具应用都请求宿主审批;`risk-based`:仅超过阈值时审批 |
|
|
80
|
+
| `suggestionPolicy` | `conservative` | `conservative`:仅强证据才标“建议关闭”;`balanced`:保留旧评分,仍受周期/调用记录保护 |
|
|
79
81
|
| `approvalThreshold` | `5` | `risk-based` 模式下,超过该数量的草稿需要宿主审批 |
|
|
80
82
|
| `protect` | `[]` | 额外保护包名/entry id |
|
|
81
83
|
| `pinned` | `[]` | 永不建议禁用 |
|
package/client.js
CHANGED
|
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const CSS_ID = 'dsh-experience-optimizer-ui'
|
|
15
15
|
const TASK_TAGS = [
|
|
16
16
|
['unknown', '自动识别'],
|
|
17
|
-
['bugfix', '
|
|
17
|
+
['bugfix', '修复问题'],
|
|
18
18
|
['feature', '新功能'],
|
|
19
19
|
['review', '代码审查'],
|
|
20
20
|
['docs', '文档'],
|
|
@@ -39,12 +39,13 @@ window.__ModuleLoader__.load({
|
|
|
39
39
|
.eo-tab-active:after{content:"";position:absolute;left:0;right:0;bottom:-1px;height:1.5px;background:var(--eo-primary);border-radius:1px}
|
|
40
40
|
.eo-stack{display:flex;flex-direction:column;gap:14px}
|
|
41
41
|
.eo-stack>.eo-metrics{order:0}
|
|
42
|
-
.eo-stack>[data-section="
|
|
43
|
-
.eo-stack>[data-section="
|
|
44
|
-
.eo-stack>[data-section="
|
|
45
|
-
.eo-stack>[data-section="
|
|
46
|
-
.eo-stack>[data-section="
|
|
47
|
-
.eo-stack>[data-section="
|
|
42
|
+
.eo-stack>[data-section="inventory"]{order:1}
|
|
43
|
+
.eo-stack>[data-section="draft"]{order:2}
|
|
44
|
+
.eo-stack>[data-section="compat"]{order:3}
|
|
45
|
+
.eo-stack>[data-section="context"]{order:4}
|
|
46
|
+
.eo-stack>[data-section="result"]{order:5}
|
|
47
|
+
.eo-stack>[data-section="dedupe"]{order:6}
|
|
48
|
+
.eo-stack>[data-section="diagnostics"]{order:7}
|
|
48
49
|
.eo-grid{display:grid;gap:10px}
|
|
49
50
|
.eo-metrics{grid-template-columns:repeat(4,minmax(0,1fr));gap:0;border:.5px solid var(--eo-card-stroke);border-radius:var(--eo-radius);background:var(--eo-card-bg);overflow:hidden}
|
|
50
51
|
.eo-metric{padding:12px 14px;border-right:.5px solid var(--eo-border);min-width:0}
|
|
@@ -144,7 +145,22 @@ window.__ModuleLoader__.load({
|
|
|
144
145
|
.eo-spinner{width:13px;height:13px;border-radius:50%;border:2px solid var(--eo-border-strong);border-top-color:var(--eo-primary);animation:eo-spin .8s linear infinite}
|
|
145
146
|
.eo-error{padding:10px 12px;border-radius:var(--dsw-radius-md,8px);background:color-mix(in srgb,var(--eo-error) 7%,transparent);border:.5px solid color-mix(in srgb,var(--eo-error) 35%,transparent);color:var(--eo-error);font-size:12px;line-height:18px;display:flex;gap:10px;align-items:center;justify-content:space-between}
|
|
146
147
|
.eo-muted{color:var(--eo-tertiary);font-size:12px;line-height:18px}
|
|
148
|
+
.eo-note{padding:9px 12px;border:1px solid var(--dsw-alias-border-l3);border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--eo-secondary);font-size:12px;line-height:19px}
|
|
147
149
|
.eo-code{font:400 11px/16px var(--eo-code);color:var(--eo-secondary);word-break:break-all}
|
|
150
|
+
.eo-steps{margin:0;padding-left:20px;color:var(--eo-secondary);font-size:13px;line-height:22px}
|
|
151
|
+
.eo-steps li{margin:0 0 8px;padding-left:2px}
|
|
152
|
+
.eo-steps strong{color:var(--eo-primary);font-weight:500}
|
|
153
|
+
.eo-settings-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 18px}
|
|
154
|
+
.eo-settings-row{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:7px 0;border-bottom:.5px solid var(--eo-border);font-size:13px;line-height:20px}
|
|
155
|
+
.eo-settings-row:last-child{border-bottom:0}
|
|
156
|
+
.eo-settings-row span:first-child{color:var(--eo-secondary);flex:0 0 auto}
|
|
157
|
+
.eo-settings-row code{font:400 11px/16px var(--eo-code);color:var(--eo-primary);text-align:right;word-break:break-all}
|
|
158
|
+
.eo-codeblock{margin:0;padding:12px;border:.5px solid var(--eo-border-strong);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-module-platform,rgba(127,127,127,.05));font:400 11px/18px var(--eo-code);color:var(--eo-secondary);white-space:pre-wrap;word-break:break-word}
|
|
159
|
+
.eo-faq{border-bottom:.5px solid var(--eo-border);padding:8px 0}
|
|
160
|
+
.eo-faq:last-child{border-bottom:0}
|
|
161
|
+
.eo-faq summary{cursor:pointer;font-size:13px;line-height:20px;color:var(--eo-primary)}
|
|
162
|
+
.eo-faq p{margin:5px 0 0;color:var(--eo-tertiary);font-size:12px;line-height:19px}
|
|
163
|
+
@media(max-width:560px){.eo-settings-grid{grid-template-columns:1fr}}
|
|
148
164
|
.eo-inline{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
|
|
149
165
|
.eo-spacer{height:0}
|
|
150
166
|
@keyframes eo-spin{to{transform:rotate(360deg)}}
|
|
@@ -241,8 +257,8 @@ window.__ModuleLoader__.load({
|
|
|
241
257
|
{
|
|
242
258
|
keep: '保留',
|
|
243
259
|
enable: '建议启用',
|
|
244
|
-
'suggest-disable': '
|
|
245
|
-
'disable-if-unused': '
|
|
260
|
+
'suggest-disable': '建议关闭',
|
|
261
|
+
'disable-if-unused': '未用可关闭',
|
|
246
262
|
review: '人工复核',
|
|
247
263
|
}[action] || action
|
|
248
264
|
)
|
|
@@ -273,7 +289,7 @@ window.__ModuleLoader__.load({
|
|
|
273
289
|
{
|
|
274
290
|
'plugin-runtime': '插件 ↔ DSH',
|
|
275
291
|
'plugin-plugin': '插件 ↔ 插件',
|
|
276
|
-
profile: '
|
|
292
|
+
profile: '配置集',
|
|
277
293
|
workspace: '工作区',
|
|
278
294
|
}[domain] || domain
|
|
279
295
|
)
|
|
@@ -287,6 +303,44 @@ window.__ModuleLoader__.load({
|
|
|
287
303
|
)
|
|
288
304
|
}
|
|
289
305
|
|
|
306
|
+
function taskLabel(tag) {
|
|
307
|
+
return (
|
|
308
|
+
{
|
|
309
|
+
bugfix: '修复',
|
|
310
|
+
feature: '新功能',
|
|
311
|
+
review: '审查',
|
|
312
|
+
docs: '文档',
|
|
313
|
+
release: '发布',
|
|
314
|
+
report: '报告',
|
|
315
|
+
research: '调研',
|
|
316
|
+
unknown: '未知',
|
|
317
|
+
}[tag] || tag
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function riskLabel(risk) {
|
|
322
|
+
return { low: '低', medium: '中', high: '高' }[risk] || risk
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function guardLabel(status) {
|
|
326
|
+
return (
|
|
327
|
+
{
|
|
328
|
+
ok: '正常',
|
|
329
|
+
protected: '受保护',
|
|
330
|
+
incompatible: '不兼容',
|
|
331
|
+
warn: '警告',
|
|
332
|
+
}[status] || status
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function usageLabel(state) {
|
|
337
|
+
return state === 'used' ? '有调用记录' : state === 'unused' ? '窗口内 0 调用' : '无使用账本'
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function evidenceLabel(level) {
|
|
341
|
+
return level === 'strong' ? '证据强' : level === 'weak' ? '证据弱' : '证据不足'
|
|
342
|
+
}
|
|
343
|
+
|
|
290
344
|
function splitList(value) {
|
|
291
345
|
return String(value || '')
|
|
292
346
|
.split(/[,,\n]/)
|
|
@@ -352,6 +406,9 @@ window.__ModuleLoader__.load({
|
|
|
352
406
|
})
|
|
353
407
|
const [recipeResult, setRecipeResult] = useState(null)
|
|
354
408
|
const [recipeBusy, setRecipeBusy] = useState(false)
|
|
409
|
+
const [settings, setSettings] = useState(null)
|
|
410
|
+
const [settingsBusy, setSettingsBusy] = useState(false)
|
|
411
|
+
const [settingsError, setSettingsError] = useState('')
|
|
355
412
|
|
|
356
413
|
const notify = useCallback((message, kind) => {
|
|
357
414
|
setToast({ message, kind: kind || 'ok', id: Date.now() })
|
|
@@ -380,6 +437,18 @@ window.__ModuleLoader__.load({
|
|
|
380
437
|
void refresh()
|
|
381
438
|
}, [refresh])
|
|
382
439
|
|
|
440
|
+
const loadSettings = useCallback(async () => {
|
|
441
|
+
setSettingsBusy(true)
|
|
442
|
+
setSettingsError('')
|
|
443
|
+
try {
|
|
444
|
+
setSettings(await fetchJson(API + '/config'))
|
|
445
|
+
} catch (err) {
|
|
446
|
+
setSettingsError(err instanceof Error ? err.message : String(err))
|
|
447
|
+
} finally {
|
|
448
|
+
setSettingsBusy(false)
|
|
449
|
+
}
|
|
450
|
+
}, [])
|
|
451
|
+
|
|
383
452
|
const findings = useMemo(() => {
|
|
384
453
|
if (!overview) return []
|
|
385
454
|
const query = findingQuery.trim().toLowerCase()
|
|
@@ -423,6 +492,7 @@ window.__ModuleLoader__.load({
|
|
|
423
492
|
? overview.bundles.filter((bundle) => bundle.enabled).length
|
|
424
493
|
: 0
|
|
425
494
|
const totalBundles = overview ? overview.bundles.length : 0
|
|
495
|
+
const totalContextTokens = overview ? overview.context.totalTokens : 0
|
|
426
496
|
const compat = overview ? overview.compat : { error: 0, warn: 0, info: 0 }
|
|
427
497
|
const byOwner = overview ? overview.context.byOwner : []
|
|
428
498
|
const maxOwner = Math.max(1, ...byOwner.map((owner) => owner.tokens))
|
|
@@ -432,6 +502,8 @@ window.__ModuleLoader__.load({
|
|
|
432
502
|
const actionableDraftItems = draftItems.filter(
|
|
433
503
|
(item) => item.action !== 'keep' && item.protected !== true,
|
|
434
504
|
)
|
|
505
|
+
const periodicDraftCount = draftItems.filter((item) => item.periodic === true).length
|
|
506
|
+
const strongDraftCount = draftItems.filter((item) => item.evidenceLevel === 'strong').length
|
|
435
507
|
|
|
436
508
|
const generateDraft = useCallback(async () => {
|
|
437
509
|
setDraftBusy(true)
|
|
@@ -614,7 +686,7 @@ window.__ModuleLoader__.load({
|
|
|
614
686
|
h(
|
|
615
687
|
'span',
|
|
616
688
|
{ className: 'eo-status', title: overview ? overview.profile.dir : '' },
|
|
617
|
-
overview ? '
|
|
689
|
+
overview ? '配置集:' + overview.profile.name : '读取中',
|
|
618
690
|
),
|
|
619
691
|
h(
|
|
620
692
|
Button,
|
|
@@ -644,6 +716,27 @@ window.__ModuleLoader__.load({
|
|
|
644
716
|
},
|
|
645
717
|
'工作流配方',
|
|
646
718
|
),
|
|
719
|
+
h(
|
|
720
|
+
'button',
|
|
721
|
+
{
|
|
722
|
+
type: 'button',
|
|
723
|
+
className: 'eo-tab' + (tab === 'tutorial' ? ' eo-tab-active' : ''),
|
|
724
|
+
onClick: () => setTab('tutorial'),
|
|
725
|
+
},
|
|
726
|
+
'教程',
|
|
727
|
+
),
|
|
728
|
+
h(
|
|
729
|
+
'button',
|
|
730
|
+
{
|
|
731
|
+
type: 'button',
|
|
732
|
+
className: 'eo-tab' + (tab === 'settings' ? ' eo-tab-active' : ''),
|
|
733
|
+
onClick: () => {
|
|
734
|
+
setTab('settings')
|
|
735
|
+
if (settings === null && !settingsBusy) void loadSettings()
|
|
736
|
+
},
|
|
737
|
+
},
|
|
738
|
+
'设置',
|
|
739
|
+
),
|
|
647
740
|
),
|
|
648
741
|
error
|
|
649
742
|
? h(
|
|
@@ -661,11 +754,15 @@ window.__ModuleLoader__.load({
|
|
|
661
754
|
'正在读取插件画像与兼容性数据…',
|
|
662
755
|
)
|
|
663
756
|
: null,
|
|
664
|
-
|
|
665
|
-
?
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
757
|
+
tab === 'tutorial'
|
|
758
|
+
? renderTutorial()
|
|
759
|
+
: tab === 'settings'
|
|
760
|
+
? renderSettings()
|
|
761
|
+
: overview
|
|
762
|
+
? tab === 'trim'
|
|
763
|
+
? renderTrim()
|
|
764
|
+
: renderRecipe()
|
|
765
|
+
: null,
|
|
669
766
|
confirmState
|
|
670
767
|
? h(ConfirmModal, {
|
|
671
768
|
state: confirmState,
|
|
@@ -680,6 +777,188 @@ window.__ModuleLoader__.load({
|
|
|
680
777
|
: null,
|
|
681
778
|
)
|
|
682
779
|
|
|
780
|
+
function renderTutorial() {
|
|
781
|
+
const quickStarts = [
|
|
782
|
+
{
|
|
783
|
+
label: '代码审查',
|
|
784
|
+
desc: '先看兼容性,再生成审查任务的精简方案',
|
|
785
|
+
run: () => {
|
|
786
|
+
setTaskTag('review')
|
|
787
|
+
setGoal('审查当前改动,指出风险、回归点和需要补测的地方')
|
|
788
|
+
setTab('trim')
|
|
789
|
+
notify('已填入审查任务,点击“生成方案”继续')
|
|
790
|
+
},
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
label: '修复问题',
|
|
794
|
+
desc: '排除无关插件,保留调试与文件工具',
|
|
795
|
+
run: () => {
|
|
796
|
+
setTaskTag('bugfix')
|
|
797
|
+
setGoal('修复一个可复现的 bug,并验证没有回归')
|
|
798
|
+
setTab('trim')
|
|
799
|
+
notify('已填入修复任务,点击“生成方案”继续')
|
|
800
|
+
},
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
label: '整理周报',
|
|
804
|
+
desc: '进入工作流配方,生成可导出的周报蓝图',
|
|
805
|
+
run: () => {
|
|
806
|
+
setTab('recipe')
|
|
807
|
+
notify('已打开工作流配方,按表单确认范围与交付方式')
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
]
|
|
811
|
+
return h(
|
|
812
|
+
'div',
|
|
813
|
+
{ className: 'eo-stack' },
|
|
814
|
+
h(
|
|
815
|
+
Card,
|
|
816
|
+
{ title: '5 分钟上手', subtitle: '从扫描到应用,每一步都可回滚' },
|
|
817
|
+
h(
|
|
818
|
+
'ol',
|
|
819
|
+
{ className: 'eo-steps' },
|
|
820
|
+
h('li', null, h('strong', null, '先扫描。'), ' 打开「减负与兼容」,看可归属上下文、兼容性和插件清单;清单里的“占比”就是常驻成本的可见化。'),
|
|
821
|
+
h('li', null, h('strong', null, '再生成方案。'), ' 选任务类型或写一句目标,点击“生成方案”。默认只生成草稿,不会改任何插件。'),
|
|
822
|
+
h('li', null, h('strong', null, '看判断依据。'), ' 只有“窗口内 0 调用 + 有上下文成本 + 非周期 + 任务高置信”才会标为建议关闭;其余进入人工复核。'),
|
|
823
|
+
h('li', null, h('strong', null, '确认后应用。'), ' 勾选低风险项,点击“应用选中”,核对弹窗后写入快照并应用;需要时可一键回滚。'),
|
|
824
|
+
h('li', null, h('strong', null, '需要工作流时。'), ' 打开「工作流配方」,生成带审批级别的蓝图,导出 Markdown/JSON 运行手册。'),
|
|
825
|
+
),
|
|
826
|
+
),
|
|
827
|
+
h(
|
|
828
|
+
Card,
|
|
829
|
+
{ title: '按任务快速开始', subtitle: '只是填入表单,不会直接修改插件' },
|
|
830
|
+
h(
|
|
831
|
+
'div',
|
|
832
|
+
{ className: 'eo-inline' },
|
|
833
|
+
quickStarts.map((item) =>
|
|
834
|
+
h(
|
|
835
|
+
'div',
|
|
836
|
+
{ key: item.label, className: 'eo-issue', style: { flex: '1 1 180px', flexDirection: 'column', alignItems: 'flex-start' } },
|
|
837
|
+
h('strong', null, item.label),
|
|
838
|
+
h('span', { className: 'eo-muted' }, item.desc),
|
|
839
|
+
h(Button, { variant: 'ghost', onClick: item.run }, '开始'),
|
|
840
|
+
),
|
|
841
|
+
),
|
|
842
|
+
),
|
|
843
|
+
),
|
|
844
|
+
h(
|
|
845
|
+
Card,
|
|
846
|
+
{ title: '常见问题', subtitle: '先看证据,再做决定' },
|
|
847
|
+
h('details', { className: 'eo-faq' },
|
|
848
|
+
h('summary', null, '为什么我几乎没有“建议关闭”?'),
|
|
849
|
+
h('p', null, '这是默认的保守策略:没有使用账本、当前任务置信度不够、插件带周期/触发器语义,或已经有调用记录时,只会进入人工复核,不会给出建议关闭。'),
|
|
850
|
+
),
|
|
851
|
+
h('details', { className: 'eo-faq' },
|
|
852
|
+
h('summary', null, '每月才用一次的插件会被误伤吗?'),
|
|
853
|
+
h('p', null, '带“每月/每周/定时/提醒/日程/dream”等语义的插件会被硬保护。仍不放心时,把它加入配置的 protect 列表。'),
|
|
854
|
+
),
|
|
855
|
+
h('details', { className: 'eo-faq' },
|
|
856
|
+
h('summary', null, '应用后出问题怎么办?'),
|
|
857
|
+
h('p', null, '每次应用前都会写入快照;在精简方案底部点击“回滚最近”,或让 Agent 调用 trim_rollback_profile。回滚同样需要宿主审批。'),
|
|
858
|
+
),
|
|
859
|
+
h('details', { className: 'eo-faq' },
|
|
860
|
+
h('summary', null, '为什么应用还需要确认和审批?'),
|
|
861
|
+
h('p', null, 'confirm: true 只是提案标记,真正授权来自宿主审批返回 allowed-once;被拒绝、取消或审批服务不可用时一律不写入。'),
|
|
862
|
+
),
|
|
863
|
+
),
|
|
864
|
+
)
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function configPatch(data) {
|
|
868
|
+
const lines = [
|
|
869
|
+
'- id: dsh-plugin-trim',
|
|
870
|
+
' config:',
|
|
871
|
+
' mode: ' + data.mode,
|
|
872
|
+
' approvalMode: ' + data.approvalMode,
|
|
873
|
+
' suggestionPolicy: ' + data.suggestionPolicy,
|
|
874
|
+
' approvalThreshold: ' + data.approvalThreshold,
|
|
875
|
+
' trackUsage: ' + String(data.trackUsage),
|
|
876
|
+
' usageRetentionDays: ' + data.usageRetentionDays,
|
|
877
|
+
' maxDrafts: ' + data.maxDrafts,
|
|
878
|
+
]
|
|
879
|
+
if (data.protect.length > 0) {
|
|
880
|
+
lines.push(' protect:')
|
|
881
|
+
for (const name of data.protect) lines.push(' - ' + name)
|
|
882
|
+
}
|
|
883
|
+
if (data.pinned.length > 0) {
|
|
884
|
+
lines.push(' pinned:')
|
|
885
|
+
for (const name of data.pinned) lines.push(' - ' + name)
|
|
886
|
+
}
|
|
887
|
+
return lines.join('\n')
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
async function copyConfig(data) {
|
|
891
|
+
try {
|
|
892
|
+
await navigator.clipboard.writeText(configPatch(data))
|
|
893
|
+
notify('配置片段已复制;写入配置补丁后生效')
|
|
894
|
+
} catch {
|
|
895
|
+
notify('无法访问剪贴板,请手动复制配置片段', 'warn')
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function renderSettings() {
|
|
900
|
+
if (settingsBusy && settings === null) {
|
|
901
|
+
return h('div', { className: 'eo-loading' }, h('span', { className: 'eo-spinner' }), '正在读取当前生效设置…')
|
|
902
|
+
}
|
|
903
|
+
if (settingsError && settings === null) {
|
|
904
|
+
return h('div', { className: 'eo-error' }, h('span', null, settingsError), h(Button, { variant: 'ghost', onClick: loadSettings }, '重试'))
|
|
905
|
+
}
|
|
906
|
+
if (!settings) return h('div', { className: 'eo-empty' }, '暂无设置数据。')
|
|
907
|
+
const policyLabel = settings.suggestionPolicy === 'balanced' ? '旧评分(仍保护周期与已用插件)' : '证据优先(推荐)'
|
|
908
|
+
const approvalLabel = settings.approvalMode === 'risk-based' ? '仅超过阈值时审批' : '每次工具写入都审批'
|
|
909
|
+
return h(
|
|
910
|
+
'div',
|
|
911
|
+
{ className: 'eo-stack' },
|
|
912
|
+
h(
|
|
913
|
+
Card,
|
|
914
|
+
{
|
|
915
|
+
title: '当前生效设置',
|
|
916
|
+
subtitle: '只读视图;修改请写入配置补丁',
|
|
917
|
+
extra: h(Button, { variant: 'ghost', onClick: loadSettings, disabled: settingsBusy }, settingsBusy ? '读取中…' : '刷新'),
|
|
918
|
+
},
|
|
919
|
+
h(
|
|
920
|
+
'div',
|
|
921
|
+
{ className: 'eo-settings-grid' },
|
|
922
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '配置集'), h('code', null, settings.profile)),
|
|
923
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '运行模式'), h('code', null, settings.mode === 'auto-safe' ? '自动安全(收窄建议)' : '建议模式')),
|
|
924
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '审批策略'), h('code', null, approvalLabel)),
|
|
925
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '审批阈值'), h('code', null, String(settings.approvalThreshold) + ' 项')),
|
|
926
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '建议策略'), h('code', null, policyLabel)),
|
|
927
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '使用账本'), h('code', null, settings.trackUsage ? '开启' : '关闭')),
|
|
928
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '账本保留'), h('code', null, settings.usageRetentionDays + ' 天')),
|
|
929
|
+
h('div', { className: 'eo-settings-row' }, h('span', null, '草稿/快照上限'), h('code', null, String(settings.maxDrafts))),
|
|
930
|
+
),
|
|
931
|
+
h('div', { className: 'eo-muted', style: { marginTop: '10px' } }, '配置目录:' + settings.profileDir),
|
|
932
|
+
),
|
|
933
|
+
h(
|
|
934
|
+
Card,
|
|
935
|
+
{ title: '保护与固定', subtitle: '这些插件永远不会进入自动建议' },
|
|
936
|
+
settings.protect.length === 0 && settings.pinned.length === 0
|
|
937
|
+
? h('div', { className: 'eo-empty' }, '尚未配置保护 / 固定名单。可在配置补丁中添加需要保底的插件。')
|
|
938
|
+
: h(
|
|
939
|
+
'div',
|
|
940
|
+
{ className: 'eo-inline' },
|
|
941
|
+
settings.protect.map((name) => h(Badge, { key: 'protect-' + name, tone: 'warn' }, '保护 · ' + name)),
|
|
942
|
+
settings.pinned.map((name) => h(Badge, { key: 'pinned-' + name, tone: 'neutral' }, '固定 · ' + name)),
|
|
943
|
+
),
|
|
944
|
+
),
|
|
945
|
+
h(
|
|
946
|
+
Card,
|
|
947
|
+
{
|
|
948
|
+
title: '配置片段',
|
|
949
|
+
subtitle: '复制到配置补丁;写入后由 DSH 重新加载',
|
|
950
|
+
extra: h(Button, { variant: 'accent', onClick: () => void copyConfig(settings) }, '复制片段'),
|
|
951
|
+
},
|
|
952
|
+
h('pre', { className: 'eo-codeblock' }, configPatch(settings)),
|
|
953
|
+
),
|
|
954
|
+
h(
|
|
955
|
+
Card,
|
|
956
|
+
{ title: '说明', subtitle: '设置页不会直接改配置' },
|
|
957
|
+
h('div', { className: 'eo-muted' }, '为避免 UI 绕过 DSH 的配置边界,这里只展示当前生效值与可复制片段。修改后请重新加载插件;审批与保护逻辑不会因为改设置而跳过。'),
|
|
958
|
+
),
|
|
959
|
+
)
|
|
960
|
+
}
|
|
961
|
+
|
|
683
962
|
function renderTrim() {
|
|
684
963
|
return h(
|
|
685
964
|
'div',
|
|
@@ -689,26 +968,26 @@ window.__ModuleLoader__.load({
|
|
|
689
968
|
key: 'tokens',
|
|
690
969
|
label: '可归属上下文',
|
|
691
970
|
value: formatTokens(overview.context.totalTokens),
|
|
692
|
-
hint: 'tokens ·
|
|
971
|
+
hint: 'tokens · 不含未归属',
|
|
693
972
|
}),
|
|
694
973
|
h(Metric, {
|
|
695
974
|
key: 'bundles',
|
|
696
975
|
label: '启用插件',
|
|
697
976
|
value: enabledBundles + ' / ' + totalBundles,
|
|
698
|
-
hint: '
|
|
977
|
+
hint: '已启用 / 全部插件',
|
|
699
978
|
}),
|
|
700
979
|
h(Metric, {
|
|
701
980
|
key: 'compat',
|
|
702
981
|
label: '兼容性',
|
|
703
|
-
value: compat.error + '
|
|
704
|
-
hint: '
|
|
982
|
+
value: compat.error + ' 错 · ' + compat.warn + ' 警',
|
|
983
|
+
hint: '错误 / 警告 · 信息 ' + compat.info,
|
|
705
984
|
tone: compat.error > 0 ? 'danger' : compat.warn > 0 ? 'warn' : 'ok',
|
|
706
985
|
}),
|
|
707
986
|
h(Metric, {
|
|
708
987
|
key: 'manage',
|
|
709
988
|
label: '写操作',
|
|
710
989
|
value: overview.managementAvailable ? '可应用' : '只读',
|
|
711
|
-
hint: overview.managementAvailable ? '
|
|
990
|
+
hint: overview.managementAvailable ? '插件管理器可用' : '缺少插件管理器',
|
|
712
991
|
tone: overview.managementAvailable ? 'ok' : 'danger',
|
|
713
992
|
}),
|
|
714
993
|
]),
|
|
@@ -716,7 +995,7 @@ window.__ModuleLoader__.load({
|
|
|
716
995
|
Card,
|
|
717
996
|
{
|
|
718
997
|
title: '兼容性矩阵',
|
|
719
|
-
subtitle: '插件 ↔ 插件 · 插件 ↔ DSH ·
|
|
998
|
+
subtitle: '插件 ↔ 插件 · 插件 ↔ DSH · 配置集 / 工作区',
|
|
720
999
|
section: 'compat',
|
|
721
1000
|
extra: h(
|
|
722
1001
|
'div',
|
|
@@ -737,7 +1016,7 @@ window.__ModuleLoader__.load({
|
|
|
737
1016
|
variant: 'ghost',
|
|
738
1017
|
onClick: () => setShowInfo((value) => !value),
|
|
739
1018
|
},
|
|
740
|
-
showInfo ? '
|
|
1019
|
+
showInfo ? '隐藏信息' : '显示信息',
|
|
741
1020
|
),
|
|
742
1021
|
h(Badge, { tone: compat.error ? 'danger' : 'ok' }, compat.error ? '需要处理' : '无阻断'),
|
|
743
1022
|
),
|
|
@@ -750,7 +1029,7 @@ window.__ModuleLoader__.load({
|
|
|
750
1029
|
{ label: '搜索兼容性' },
|
|
751
1030
|
h('input', {
|
|
752
1031
|
className: 'eo-input',
|
|
753
|
-
placeholder: '
|
|
1032
|
+
placeholder: '代码 / 标题 / 对象',
|
|
754
1033
|
value: findingQuery,
|
|
755
1034
|
onChange: (event) => setFindingQuery(event.target.value),
|
|
756
1035
|
}),
|
|
@@ -766,9 +1045,9 @@ window.__ModuleLoader__.load({
|
|
|
766
1045
|
onChange: (event) => setFindingSeverity(event.target.value),
|
|
767
1046
|
},
|
|
768
1047
|
h('option', { value: 'all' }, '全部'),
|
|
769
|
-
h('option', { value: 'error' }, '
|
|
770
|
-
h('option', { value: 'warn' }, '
|
|
771
|
-
h('option', { value: 'info' }, '
|
|
1048
|
+
h('option', { value: 'error' }, '错误'),
|
|
1049
|
+
h('option', { value: 'warn' }, '警告'),
|
|
1050
|
+
h('option', { value: 'info' }, '信息'),
|
|
772
1051
|
),
|
|
773
1052
|
),
|
|
774
1053
|
),
|
|
@@ -863,7 +1142,7 @@ window.__ModuleLoader__.load({
|
|
|
863
1142
|
null,
|
|
864
1143
|
h('th', null, 'Section / Tool'),
|
|
865
1144
|
h('th', null, 'Owner'),
|
|
866
|
-
h('th', null, '
|
|
1145
|
+
h('th', null, '上下文'),
|
|
867
1146
|
),
|
|
868
1147
|
),
|
|
869
1148
|
h(
|
|
@@ -922,7 +1201,7 @@ window.__ModuleLoader__.load({
|
|
|
922
1201
|
{ label: '搜索插件' },
|
|
923
1202
|
h('input', {
|
|
924
1203
|
className: 'eo-input',
|
|
925
|
-
placeholder: '
|
|
1204
|
+
placeholder: '名称 / 描述',
|
|
926
1205
|
value: bundleQuery,
|
|
927
1206
|
onChange: (event) => setBundleQuery(event.target.value),
|
|
928
1207
|
}),
|
|
@@ -973,9 +1252,10 @@ window.__ModuleLoader__.load({
|
|
|
973
1252
|
h('th', null, '插件'),
|
|
974
1253
|
h('th', null, '状态'),
|
|
975
1254
|
h('th', null, '保护'),
|
|
976
|
-
h('th', null, '
|
|
977
|
-
h('th', null, '
|
|
978
|
-
h('th', null, '
|
|
1255
|
+
h('th', null, '守卫'),
|
|
1256
|
+
h('th', null, '上下文'),
|
|
1257
|
+
h('th', null, '占比'),
|
|
1258
|
+
h('th', null, '调用'),
|
|
979
1259
|
),
|
|
980
1260
|
),
|
|
981
1261
|
h(
|
|
@@ -999,16 +1279,23 @@ window.__ModuleLoader__.load({
|
|
|
999
1279
|
h(
|
|
1000
1280
|
Badge,
|
|
1001
1281
|
{ tone: bundle.enabled ? 'ok' : 'neutral' },
|
|
1002
|
-
bundle.enabled ? '
|
|
1282
|
+
bundle.enabled ? '已启用' : '已禁用',
|
|
1003
1283
|
),
|
|
1004
1284
|
),
|
|
1005
1285
|
h(
|
|
1006
1286
|
'td',
|
|
1007
1287
|
null,
|
|
1008
|
-
bundle.protected ? h(Badge, { tone: 'warn' }, '
|
|
1288
|
+
bundle.protected ? h(Badge, { tone: 'warn' }, '受保护') : '—',
|
|
1009
1289
|
),
|
|
1010
|
-
h('td', { className: 'eo-muted' }, bundle.guardStatus
|
|
1290
|
+
h('td', { className: 'eo-muted' }, bundle.guardStatus ? guardLabel(bundle.guardStatus) : '—'),
|
|
1011
1291
|
h('td', null, formatNumber(bundle.contextTokens)),
|
|
1292
|
+
h(
|
|
1293
|
+
'td',
|
|
1294
|
+
{ className: 'eo-muted', title: '占可归属上下文的比例' },
|
|
1295
|
+
totalContextTokens > 0
|
|
1296
|
+
? Math.round((bundle.contextTokens / totalContextTokens) * 100) + '%'
|
|
1297
|
+
: '—',
|
|
1298
|
+
),
|
|
1012
1299
|
h(
|
|
1013
1300
|
'td',
|
|
1014
1301
|
null,
|
|
@@ -1071,19 +1358,26 @@ window.__ModuleLoader__.load({
|
|
|
1071
1358
|
null,
|
|
1072
1359
|
h(
|
|
1073
1360
|
'div',
|
|
1074
|
-
{ className: 'eo-
|
|
1361
|
+
{ className: 'eo-note' },
|
|
1362
|
+
'判断依据:描述匹配只说明“可能相关”;出现周期/触发器语义、已有调用记录、无使用账本或任务置信度不足时,只进入人工复核。只有“窗口内 0 调用 + 有上下文成本 + 非周期 + 任务高置信”才会标为建议关闭,且仍需确认与宿主审批。',
|
|
1363
|
+
),
|
|
1364
|
+
h(
|
|
1365
|
+
'div',
|
|
1366
|
+
{ className: 'eo-summary', style: { marginTop: '10px' } },
|
|
1075
1367
|
h(Badge, { tone: 'neutral' }, '保留 ' + draft.summary.keep),
|
|
1076
1368
|
h(Badge, { tone: 'ok' }, '启用 ' + draft.summary.enable),
|
|
1077
|
-
h(Badge, { tone: 'danger' }, '
|
|
1369
|
+
h(Badge, { tone: 'danger' }, '建议关闭 ' + draft.summary.disable),
|
|
1078
1370
|
h(Badge, { tone: 'info' }, '复核 ' + draft.summary.review),
|
|
1079
1371
|
h(Badge, { tone: 'neutral' }, '受保护 ' + draft.summary.protected),
|
|
1080
|
-
h(Badge, { tone: 'warn' }, '
|
|
1372
|
+
h(Badge, { tone: 'warn' }, '周期保护 ' + periodicDraftCount),
|
|
1373
|
+
h(Badge, { tone: 'ok' }, '证据强 ' + strongDraftCount),
|
|
1374
|
+
h(Badge, { tone: 'warn' }, '任务:' + taskLabel(draft.task.tag)),
|
|
1081
1375
|
),
|
|
1082
1376
|
actionableDraftItems.length === 0
|
|
1083
1377
|
? h(
|
|
1084
1378
|
'div',
|
|
1085
1379
|
{ className: 'eo-empty' },
|
|
1086
|
-
'
|
|
1380
|
+
'本轮没有强证据候选:周期/触发器、已有调用记录、无使用账本或低置信项只进入人工复核。',
|
|
1087
1381
|
)
|
|
1088
1382
|
: h(
|
|
1089
1383
|
'div',
|
|
@@ -1118,8 +1412,28 @@ window.__ModuleLoader__.load({
|
|
|
1118
1412
|
{ tone: actionTone(item.action) },
|
|
1119
1413
|
actionLabel(item.action),
|
|
1120
1414
|
),
|
|
1121
|
-
h(Badge, { tone: riskTone(item.risk) }, '
|
|
1415
|
+
h(Badge, { tone: riskTone(item.risk) }, '风险:' + riskLabel(item.risk)),
|
|
1122
1416
|
item.protected ? h(Badge, { tone: 'neutral' }, '受保护') : null,
|
|
1417
|
+
item.periodic ? h(Badge, { tone: 'warn' }, '周期/触发器') : null,
|
|
1418
|
+
item.usageState
|
|
1419
|
+
? h(
|
|
1420
|
+
Badge,
|
|
1421
|
+
{
|
|
1422
|
+
tone:
|
|
1423
|
+
item.usageState === 'used'
|
|
1424
|
+
? 'ok'
|
|
1425
|
+
: item.usageState === 'unused'
|
|
1426
|
+
? 'info'
|
|
1427
|
+
: 'neutral',
|
|
1428
|
+
},
|
|
1429
|
+
usageLabel(item.usageState),
|
|
1430
|
+
)
|
|
1431
|
+
: null,
|
|
1432
|
+
item.evidenceLevel === 'strong'
|
|
1433
|
+
? h(Badge, { tone: 'ok' }, '证据强')
|
|
1434
|
+
: item.evidenceLevel === 'insufficient'
|
|
1435
|
+
? h(Badge, { tone: 'neutral' }, '证据不足')
|
|
1436
|
+
: null,
|
|
1123
1437
|
),
|
|
1124
1438
|
h('div', { className: 'eo-item-reason' }, item.reason),
|
|
1125
1439
|
h(
|
|
@@ -1138,7 +1452,7 @@ window.__ModuleLoader__.load({
|
|
|
1138
1452
|
'div',
|
|
1139
1453
|
{ className: 'eo-item-side' },
|
|
1140
1454
|
h('span', null, Number(item.score).toFixed(2)),
|
|
1141
|
-
h('small', null, '
|
|
1455
|
+
h('small', null, '评分'),
|
|
1142
1456
|
),
|
|
1143
1457
|
),
|
|
1144
1458
|
),
|
|
@@ -1184,7 +1498,7 @@ window.__ModuleLoader__.load({
|
|
|
1184
1498
|
Card,
|
|
1185
1499
|
{
|
|
1186
1500
|
title: '应用结果',
|
|
1187
|
-
subtitle: applyResult.rolledBack ? '中途失败,已自动回滚' : '
|
|
1501
|
+
subtitle: applyResult.rolledBack ? '中途失败,已自动回滚' : '变更已写入配置集',
|
|
1188
1502
|
section: 'result',
|
|
1189
1503
|
extra: h(
|
|
1190
1504
|
Badge,
|
|
@@ -1463,10 +1777,10 @@ window.__ModuleLoader__.load({
|
|
|
1463
1777
|
h(
|
|
1464
1778
|
'div',
|
|
1465
1779
|
{ className: 'eo-summary' },
|
|
1466
|
-
h(Badge, { tone: 'info' }, '
|
|
1467
|
-
h(Badge, { tone: 'neutral' }, '
|
|
1468
|
-
h(Badge, { tone: 'warn' }, '
|
|
1469
|
-
h(Badge, { tone: 'neutral' }, '
|
|
1780
|
+
h(Badge, { tone: 'info' }, '模板:' + blueprint.template),
|
|
1781
|
+
h(Badge, { tone: 'neutral' }, '权限:' + blueprint.permissions.length),
|
|
1782
|
+
h(Badge, { tone: 'warn' }, '需审批:' + blueprint.steps.filter((step) => step.approvalLevel === 'required' || step.needsConfirm).length),
|
|
1783
|
+
h(Badge, { tone: 'neutral' }, '最小插件:' + blueprint.minPluginSet.length),
|
|
1470
1784
|
),
|
|
1471
1785
|
h(
|
|
1472
1786
|
'table',
|
|
@@ -1649,7 +1963,7 @@ window.__ModuleLoader__.load({
|
|
|
1649
1963
|
{ className: 'eo-item-title' },
|
|
1650
1964
|
h('span', { className: 'eo-item-name' }, item.name),
|
|
1651
1965
|
h(Badge, { tone: actionTone(item.action) }, actionLabel(item.action)),
|
|
1652
|
-
h(Badge, { tone: riskTone(item.risk) }, '
|
|
1966
|
+
h(Badge, { tone: riskTone(item.risk) }, '风险:' + riskLabel(item.risk)),
|
|
1653
1967
|
),
|
|
1654
1968
|
h('div', { className: 'eo-item-reason' }, item.reason),
|
|
1655
1969
|
),
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface Config {
|
|
|
6
6
|
mode: 'advise' | 'auto-safe';
|
|
7
7
|
/** `always` asks the host approval service before every tool apply; `risk-based` auto-applies small low-risk drafts. */
|
|
8
8
|
approvalMode: 'always' | 'risk-based';
|
|
9
|
+
/** `conservative` only labels strong, non-periodic evidence as a disable candidate; `balanced` keeps the older scoring. */
|
|
10
|
+
suggestionPolicy: 'conservative' | 'balanced';
|
|
9
11
|
/** In `risk-based` mode, drafts larger than this many items require host approval. */
|
|
10
12
|
approvalThreshold: number;
|
|
11
13
|
/** Extra package names or entry ids that must never be suggested for disable. */
|
|
@@ -136,6 +138,12 @@ interface SlimItem {
|
|
|
136
138
|
evidence: Evidence[];
|
|
137
139
|
observedEnabled: boolean;
|
|
138
140
|
protected: boolean;
|
|
141
|
+
/** Cadence/trigger hint detected in the bundle metadata; such items are never auto-candidates. */
|
|
142
|
+
periodic?: boolean;
|
|
143
|
+
/** What the local usage ledger can actually prove. */
|
|
144
|
+
usageState?: 'used' | 'unused' | 'unknown';
|
|
145
|
+
/** Strength of the evidence behind a disable suggestion. */
|
|
146
|
+
evidenceLevel?: 'strong' | 'weak' | 'insufficient';
|
|
139
147
|
reason: string;
|
|
140
148
|
findings: CompatFinding[];
|
|
141
149
|
}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { scopeOf } from "@deepseek-ai/dsh-scope";
|
|
|
14
14
|
const DEFAULT_CONFIG = {
|
|
15
15
|
mode: "advise",
|
|
16
16
|
approvalMode: "always",
|
|
17
|
+
suggestionPolicy: "conservative",
|
|
17
18
|
approvalThreshold: 5,
|
|
18
19
|
protect: [],
|
|
19
20
|
pinned: [],
|
|
@@ -45,6 +46,7 @@ function normalizeConfig(config) {
|
|
|
45
46
|
const Config = z.object({
|
|
46
47
|
mode: z.union(["advise", "auto-safe"]).default("advise"),
|
|
47
48
|
approvalMode: z.union(["always", "risk-based"]).default("always"),
|
|
49
|
+
suggestionPolicy: z.union(["conservative", "balanced"]).default("conservative"),
|
|
48
50
|
approvalThreshold: z.natural().min(1).max(100).default(5),
|
|
49
51
|
protect: z.array(z.string()).default([]),
|
|
50
52
|
pinned: z.array(z.string()).default([]),
|
|
@@ -2553,8 +2555,8 @@ function computeOverlapSet(scan) {
|
|
|
2553
2555
|
}
|
|
2554
2556
|
return overlap;
|
|
2555
2557
|
}
|
|
2556
|
-
function scoreBundle(scan, task, bundle, overlap) {
|
|
2557
|
-
return scoreCommon({
|
|
2558
|
+
function scoreBundle(scan, task, bundle, overlap, policy = "conservative") {
|
|
2559
|
+
return scoreCommon(policy, {
|
|
2558
2560
|
scan,
|
|
2559
2561
|
task,
|
|
2560
2562
|
overlap,
|
|
@@ -2573,9 +2575,9 @@ function scoreBundle(scan, task, bundle, overlap) {
|
|
|
2573
2575
|
findings: bundle.findings
|
|
2574
2576
|
});
|
|
2575
2577
|
}
|
|
2576
|
-
function scoreEntry(scan, task, entry, overlap) {
|
|
2578
|
+
function scoreEntry(scan, task, entry, overlap, policy = "conservative") {
|
|
2577
2579
|
const parent = scan.bundles.find((bundle) => bundle.name === entry.bundleName);
|
|
2578
|
-
return scoreCommon({
|
|
2580
|
+
return scoreCommon(policy, {
|
|
2579
2581
|
scan,
|
|
2580
2582
|
task,
|
|
2581
2583
|
overlap,
|
|
@@ -2596,7 +2598,7 @@ function scoreEntry(scan, task, entry, overlap) {
|
|
|
2596
2598
|
fiberPhase: entry.fiberPhase
|
|
2597
2599
|
});
|
|
2598
2600
|
}
|
|
2599
|
-
function scoreCommon(input) {
|
|
2601
|
+
function scoreCommon(policy, input) {
|
|
2600
2602
|
const evidence = [];
|
|
2601
2603
|
if (input.protectedItem) return {
|
|
2602
2604
|
id: input.id,
|
|
@@ -2646,14 +2648,21 @@ function scoreCommon(input) {
|
|
|
2646
2648
|
const historical = Math.min(1, input.usageCalls / 20) * successRate;
|
|
2647
2649
|
const session = Math.min(1, input.usageSessionCalls / 5) * .8;
|
|
2648
2650
|
const usage = Math.max(historical, session);
|
|
2649
|
-
|
|
2651
|
+
const anyUsage = Object.values(input.scan.usage.byTool).some((stats) => stats.calls + stats.sessionCalls > 0);
|
|
2652
|
+
const usageState = input.usageCalls + input.usageSessionCalls > 0 ? "used" : anyUsage ? "unused" : "unknown";
|
|
2653
|
+
if (usageState === "used") evidence.push({
|
|
2650
2654
|
kind: "usage",
|
|
2651
2655
|
summary: `历史调用 ${input.usageCalls},会话内 ${input.usageSessionCalls},成功率 ${round(successRate, 2)}`,
|
|
2652
2656
|
weight: WEIGHTS.usage * usage
|
|
2653
2657
|
});
|
|
2658
|
+
else if (usageState === "unused") evidence.push({
|
|
2659
|
+
kind: "usage",
|
|
2660
|
+
summary: "使用账本有活动,但本插件在保留窗口内 0 次调用",
|
|
2661
|
+
weight: 0
|
|
2662
|
+
});
|
|
2654
2663
|
else evidence.push({
|
|
2655
2664
|
kind: "usage",
|
|
2656
|
-
summary: "
|
|
2665
|
+
summary: "使用账本无记录(未开启 trackUsage 或尚未产生调用)",
|
|
2657
2666
|
weight: 0
|
|
2658
2667
|
});
|
|
2659
2668
|
const overlap = input.overlap.has(input.name) || input.bundleName !== void 0 && input.overlap.has(input.bundleName);
|
|
@@ -2673,6 +2682,12 @@ function scoreCommon(input) {
|
|
|
2673
2682
|
summary: "没有可归属的 host 上下文成本",
|
|
2674
2683
|
weight: 0
|
|
2675
2684
|
});
|
|
2685
|
+
const periodic = detectPeriodic(input);
|
|
2686
|
+
if (periodic) evidence.push({
|
|
2687
|
+
kind: "guard",
|
|
2688
|
+
summary: "检测到周期/触发器语义;不自动建议关闭,只进入人工复核",
|
|
2689
|
+
weight: .4
|
|
2690
|
+
});
|
|
2676
2691
|
for (const finding of input.findings.slice(0, 4)) evidence.push({
|
|
2677
2692
|
kind: "compat",
|
|
2678
2693
|
summary: `${finding.code}: ${finding.title}`,
|
|
@@ -2700,8 +2715,25 @@ function scoreCommon(input) {
|
|
|
2700
2715
|
if (action === "suggest-disable" && risk !== "low") action = "review";
|
|
2701
2716
|
if (action === "enable" && risk === "high") action = "review";
|
|
2702
2717
|
if (action === "enable" && hasError) action = "review";
|
|
2718
|
+
let guard = "";
|
|
2719
|
+
if (action === "suggest-disable") {
|
|
2720
|
+
if (periodic) {
|
|
2721
|
+
action = "review";
|
|
2722
|
+
guard = "疑似周期/触发器插件,已阻止自动建议关闭";
|
|
2723
|
+
} else if (usageState === "used") {
|
|
2724
|
+
action = "review";
|
|
2725
|
+
guard = "已有使用记录,不自动建议关闭";
|
|
2726
|
+
} else if (usageState === "unknown" && policy === "conservative") {
|
|
2727
|
+
action = "review";
|
|
2728
|
+
guard = "使用账本无记录,证据不足";
|
|
2729
|
+
} else if (policy === "conservative" && (input.contextTokens <= 0 || input.task.confidence < .75 || taskMatch > 0)) {
|
|
2730
|
+
action = "review";
|
|
2731
|
+
guard = "证据不足:需要窗口内 0 调用、非周期、有上下文成本且任务高置信";
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2703
2734
|
if (input.task.tag === "unknown" && action === "suggest-disable") action = "review";
|
|
2704
2735
|
if (input.task.confidence < .6 && action === "suggest-disable") action = "review";
|
|
2736
|
+
const evidenceLevel = usageState === "unused" && !periodic && input.contextTokens > 0 && input.task.confidence >= .75 && taskMatch === 0 ? "strong" : periodic || usageState === "unknown" || input.task.confidence < .6 ? "insufficient" : "weak";
|
|
2705
2737
|
return {
|
|
2706
2738
|
id: input.id,
|
|
2707
2739
|
kind: input.kind,
|
|
@@ -2713,7 +2745,10 @@ function scoreCommon(input) {
|
|
|
2713
2745
|
evidence,
|
|
2714
2746
|
observedEnabled: input.enabled,
|
|
2715
2747
|
protected: false,
|
|
2716
|
-
|
|
2748
|
+
periodic,
|
|
2749
|
+
usageState,
|
|
2750
|
+
evidenceLevel,
|
|
2751
|
+
reason: reasonFor(action, input, taskMatch, usage, cost, guard),
|
|
2717
2752
|
findings: []
|
|
2718
2753
|
};
|
|
2719
2754
|
}
|
|
@@ -2724,7 +2759,11 @@ function compatEvidence(findings) {
|
|
|
2724
2759
|
weight: .5
|
|
2725
2760
|
}));
|
|
2726
2761
|
}
|
|
2727
|
-
function reasonFor(action, input, taskMatch, usage, cost) {
|
|
2762
|
+
function reasonFor(action, input, taskMatch, usage, cost, guard) {
|
|
2763
|
+
if (guard.length > 0) return `${guard};${reasonForBase(action, input, taskMatch, usage, cost)}`;
|
|
2764
|
+
return reasonForBase(action, input, taskMatch, usage, cost);
|
|
2765
|
+
}
|
|
2766
|
+
function reasonForBase(action, input, taskMatch, usage, cost) {
|
|
2728
2767
|
switch (action) {
|
|
2729
2768
|
case "keep": return `任务匹配 ${round(taskMatch, 2)}、使用 ${round(usage, 2)}、成本 ${round(cost, 2)},收益可覆盖成本`;
|
|
2730
2769
|
case "enable": return "已禁用但与当前任务强相关;可在确认后启用";
|
|
@@ -2733,6 +2772,47 @@ function reasonFor(action, input, taskMatch, usage, cost) {
|
|
|
2733
2772
|
default: return input.task.confidence < .6 ? "任务识别置信度不足,只建议人工复核" : "证据不足或存在兼容性风险,建议人工复核";
|
|
2734
2773
|
}
|
|
2735
2774
|
}
|
|
2775
|
+
const PERIODIC_HINTS = [
|
|
2776
|
+
"schedule",
|
|
2777
|
+
"cron",
|
|
2778
|
+
"timer",
|
|
2779
|
+
"reminder",
|
|
2780
|
+
"periodic",
|
|
2781
|
+
"interval",
|
|
2782
|
+
"recurring",
|
|
2783
|
+
"daily",
|
|
2784
|
+
"weekly",
|
|
2785
|
+
"monthly",
|
|
2786
|
+
"hourly",
|
|
2787
|
+
"calendar",
|
|
2788
|
+
"digest",
|
|
2789
|
+
"webhook",
|
|
2790
|
+
"trigger",
|
|
2791
|
+
"subscription",
|
|
2792
|
+
"watch",
|
|
2793
|
+
"dream",
|
|
2794
|
+
"定时",
|
|
2795
|
+
"周期",
|
|
2796
|
+
"每月",
|
|
2797
|
+
"每周",
|
|
2798
|
+
"每日",
|
|
2799
|
+
"每小时",
|
|
2800
|
+
"提醒",
|
|
2801
|
+
"日程",
|
|
2802
|
+
"日历",
|
|
2803
|
+
"月报",
|
|
2804
|
+
"周报",
|
|
2805
|
+
"日报",
|
|
2806
|
+
"订阅",
|
|
2807
|
+
"触发器",
|
|
2808
|
+
"轮询",
|
|
2809
|
+
"梦整理",
|
|
2810
|
+
"梦境"
|
|
2811
|
+
];
|
|
2812
|
+
function detectPeriodic(input) {
|
|
2813
|
+
const text = `${input.name} ${input.description ?? ""} ${input.moduleName ?? ""}`.toLowerCase();
|
|
2814
|
+
return PERIODIC_HINTS.some((hint) => text.includes(hint));
|
|
2815
|
+
}
|
|
2736
2816
|
// src/draft.ts
|
|
2737
2817
|
/** Build a local, reversible slim-profile draft. Does not change plugin state. */
|
|
2738
2818
|
function buildSlimProfile(scan, task, config, options = {}) {
|
|
@@ -2740,11 +2820,11 @@ function buildSlimProfile(scan, task, config, options = {}) {
|
|
|
2740
2820
|
const items = [];
|
|
2741
2821
|
for (const bundle of scan.bundles) {
|
|
2742
2822
|
if (!bundle.enabled && bundle.availability === "missing") continue;
|
|
2743
|
-
items.push(scoreBundle(scan, task, bundle, overlap));
|
|
2823
|
+
items.push(scoreBundle(scan, task, bundle, overlap, config.suggestionPolicy));
|
|
2744
2824
|
}
|
|
2745
2825
|
for (const entry of scan.entries) {
|
|
2746
2826
|
if (entry.bundleName === void 0 || entry.patchId === void 0) continue;
|
|
2747
|
-
items.push(scoreEntry(scan, task, entry, overlap));
|
|
2827
|
+
items.push(scoreEntry(scan, task, entry, overlap, config.suggestionPolicy));
|
|
2748
2828
|
}
|
|
2749
2829
|
const bundleDisables = new Set(items.filter((item) => item.kind === "bundle" && item.action === "suggest-disable").map((item) => item.bundleName).filter((name) => name !== void 0));
|
|
2750
2830
|
let filtered = items.filter((item) => !(item.kind === "entry" && item.bundleName !== void 0 && bundleDisables.has(item.bundleName)));
|
|
@@ -4561,6 +4641,13 @@ async function handle(req, res, ctx, config, ledger) {
|
|
|
4561
4641
|
});
|
|
4562
4642
|
return;
|
|
4563
4643
|
}
|
|
4644
|
+
if (req.method === "GET" && path === "/config") {
|
|
4645
|
+
sendJson(res, 200, {
|
|
4646
|
+
ok: true,
|
|
4647
|
+
data: publicConfig(ctx, config)
|
|
4648
|
+
});
|
|
4649
|
+
return;
|
|
4650
|
+
}
|
|
4564
4651
|
if (req.method === "POST" && path === "/suggest") {
|
|
4565
4652
|
sendJson(res, 200, {
|
|
4566
4653
|
ok: true,
|
|
@@ -4587,6 +4674,22 @@ async function handle(req, res, ctx, config, ledger) {
|
|
|
4587
4674
|
sendError(res, 500, error instanceof Error ? error.message : String(error));
|
|
4588
4675
|
}
|
|
4589
4676
|
}
|
|
4677
|
+
function publicConfig(ctx, config) {
|
|
4678
|
+
const profile = resolveProfileFacts(ctx);
|
|
4679
|
+
return {
|
|
4680
|
+
profile: profile.name,
|
|
4681
|
+
profileDir: profile.dir,
|
|
4682
|
+
mode: config.mode,
|
|
4683
|
+
approvalMode: config.approvalMode,
|
|
4684
|
+
suggestionPolicy: config.suggestionPolicy,
|
|
4685
|
+
approvalThreshold: config.approvalThreshold,
|
|
4686
|
+
protect: [...config.protect],
|
|
4687
|
+
pinned: [...config.pinned],
|
|
4688
|
+
trackUsage: config.trackUsage,
|
|
4689
|
+
usageRetentionDays: config.usageRetentionDays,
|
|
4690
|
+
maxDrafts: config.maxDrafts
|
|
4691
|
+
};
|
|
4692
|
+
}
|
|
4590
4693
|
async function overview(ctx, config, ledger) {
|
|
4591
4694
|
const compat = await analyzeCompatibility(ctx, config, {
|
|
4592
4695
|
scope: "current",
|