dsh-plugin-trim 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.0
10
+ dsh plugin --profile web add dsh-plugin-trim@0.3.2
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.0/dsh-plugin-trim-0.3.0.tgz"
16
+ dsh plugin --profile web add "https://github.com/Starlit-Sky-code/dsh-experience-optimizer/releases/download/v0.3.2/dsh-plugin-trim-0.3.2.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
@@ -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="draft"]{order:1}
43
- .eo-stack>[data-section="compat"]{order:2}
44
- .eo-stack>[data-section="context"]{order:3}
45
- .eo-stack>[data-section="result"]{order:4}
46
- .eo-stack>[data-section="dedupe"]{order:5}
47
- .eo-stack>[data-section="diagnostics"]{order:6}
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,6 +145,7 @@ 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}
148
150
  .eo-inline{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
149
151
  .eo-spacer{height:0}
@@ -241,8 +243,8 @@ window.__ModuleLoader__.load({
241
243
  {
242
244
  keep: '保留',
243
245
  enable: '建议启用',
244
- 'suggest-disable': '建议禁用',
245
- 'disable-if-unused': '未用可禁用',
246
+ 'suggest-disable': '建议关闭',
247
+ 'disable-if-unused': '未用可关闭',
246
248
  review: '人工复核',
247
249
  }[action] || action
248
250
  )
@@ -287,6 +289,14 @@ window.__ModuleLoader__.load({
287
289
  )
288
290
  }
289
291
 
292
+ function usageLabel(state) {
293
+ return state === 'used' ? '有调用记录' : state === 'unused' ? '窗口内 0 调用' : '无使用账本'
294
+ }
295
+
296
+ function evidenceLabel(level) {
297
+ return level === 'strong' ? '证据强' : level === 'weak' ? '证据弱' : '证据不足'
298
+ }
299
+
290
300
  function splitList(value) {
291
301
  return String(value || '')
292
302
  .split(/[,,\n]/)
@@ -423,6 +433,7 @@ window.__ModuleLoader__.load({
423
433
  ? overview.bundles.filter((bundle) => bundle.enabled).length
424
434
  : 0
425
435
  const totalBundles = overview ? overview.bundles.length : 0
436
+ const totalContextTokens = overview ? overview.context.totalTokens : 0
426
437
  const compat = overview ? overview.compat : { error: 0, warn: 0, info: 0 }
427
438
  const byOwner = overview ? overview.context.byOwner : []
428
439
  const maxOwner = Math.max(1, ...byOwner.map((owner) => owner.tokens))
@@ -432,6 +443,8 @@ window.__ModuleLoader__.load({
432
443
  const actionableDraftItems = draftItems.filter(
433
444
  (item) => item.action !== 'keep' && item.protected !== true,
434
445
  )
446
+ const periodicDraftCount = draftItems.filter((item) => item.periodic === true).length
447
+ const strongDraftCount = draftItems.filter((item) => item.evidenceLevel === 'strong').length
435
448
 
436
449
  const generateDraft = useCallback(async () => {
437
450
  setDraftBusy(true)
@@ -975,6 +988,7 @@ window.__ModuleLoader__.load({
975
988
  h('th', null, '保护'),
976
989
  h('th', null, 'Guard'),
977
990
  h('th', null, 'Tokens'),
991
+ h('th', null, '占比'),
978
992
  h('th', null, 'Calls'),
979
993
  ),
980
994
  ),
@@ -1009,6 +1023,13 @@ window.__ModuleLoader__.load({
1009
1023
  ),
1010
1024
  h('td', { className: 'eo-muted' }, bundle.guardStatus || '—'),
1011
1025
  h('td', null, formatNumber(bundle.contextTokens)),
1026
+ h(
1027
+ 'td',
1028
+ { className: 'eo-muted', title: '占可归属上下文的比例' },
1029
+ totalContextTokens > 0
1030
+ ? Math.round((bundle.contextTokens / totalContextTokens) * 100) + '%'
1031
+ : '—',
1032
+ ),
1012
1033
  h(
1013
1034
  'td',
1014
1035
  null,
@@ -1071,19 +1092,26 @@ window.__ModuleLoader__.load({
1071
1092
  null,
1072
1093
  h(
1073
1094
  'div',
1074
- { className: 'eo-summary' },
1095
+ { className: 'eo-note' },
1096
+ '判断依据:描述匹配只说明“可能相关”;出现周期/触发器语义、已有调用记录、无使用账本或任务置信度不足时,只进入人工复核。只有“窗口内 0 调用 + 有上下文成本 + 非周期 + 任务高置信”才会标为建议关闭,且仍需确认与宿主审批。',
1097
+ ),
1098
+ h(
1099
+ 'div',
1100
+ { className: 'eo-summary', style: { marginTop: '10px' } },
1075
1101
  h(Badge, { tone: 'neutral' }, '保留 ' + draft.summary.keep),
1076
1102
  h(Badge, { tone: 'ok' }, '启用 ' + draft.summary.enable),
1077
- h(Badge, { tone: 'danger' }, '禁用 ' + draft.summary.disable),
1103
+ h(Badge, { tone: 'danger' }, '建议关闭 ' + draft.summary.disable),
1078
1104
  h(Badge, { tone: 'info' }, '复核 ' + draft.summary.review),
1079
1105
  h(Badge, { tone: 'neutral' }, '受保护 ' + draft.summary.protected),
1106
+ h(Badge, { tone: 'warn' }, '周期保护 ' + periodicDraftCount),
1107
+ h(Badge, { tone: 'ok' }, '证据强 ' + strongDraftCount),
1080
1108
  h(Badge, { tone: 'warn' }, 'task: ' + draft.task.tag),
1081
1109
  ),
1082
1110
  actionableDraftItems.length === 0
1083
1111
  ? h(
1084
1112
  'div',
1085
1113
  { className: 'eo-empty' },
1086
- '当前没有可裁剪项:所有插件均受保护,或与当前任务匹配。',
1114
+ '本轮没有强证据候选:周期/触发器、已有调用记录、无使用账本或低置信项只进入人工复核。',
1087
1115
  )
1088
1116
  : h(
1089
1117
  'div',
@@ -1120,6 +1148,26 @@ window.__ModuleLoader__.load({
1120
1148
  ),
1121
1149
  h(Badge, { tone: riskTone(item.risk) }, 'risk: ' + item.risk),
1122
1150
  item.protected ? h(Badge, { tone: 'neutral' }, '受保护') : null,
1151
+ item.periodic ? h(Badge, { tone: 'warn' }, '周期/触发器') : null,
1152
+ item.usageState
1153
+ ? h(
1154
+ Badge,
1155
+ {
1156
+ tone:
1157
+ item.usageState === 'used'
1158
+ ? 'ok'
1159
+ : item.usageState === 'unused'
1160
+ ? 'info'
1161
+ : 'neutral',
1162
+ },
1163
+ usageLabel(item.usageState),
1164
+ )
1165
+ : null,
1166
+ item.evidenceLevel === 'strong'
1167
+ ? h(Badge, { tone: 'ok' }, '证据强')
1168
+ : item.evidenceLevel === 'insufficient'
1169
+ ? h(Badge, { tone: 'neutral' }, '证据不足')
1170
+ : null,
1123
1171
  ),
1124
1172
  h('div', { className: 'eo-item-reason' }, item.reason),
1125
1173
  h(
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
- if (input.usageCalls > 0 || input.usageSessionCalls > 0) evidence.push({
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
- reason: reasonFor(action, input, taskMatch, usage, cost),
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)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-trim",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "DSH plugin ecosystem diet and compatibility analyzer",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",