dsh-context-compression-improved 0.14.3 → 0.14.4

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-context-compression-improved",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "description": "Token-saving context-compression selector bundle for DeepSeek Harness — fewer tool-result tokens on every turn, fully auditable",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,112 @@
1
+ /**
2
+ * CutTimeline: per-cut audit timeline with strategy classification.
3
+ *
4
+ * Plan: cci-longterm-refactor v0.14.3 (F6)
5
+ *
6
+ * Displays a scrollable table of all cuts from cuts.jsonl.
7
+ * Each row: timestamp | strategy badge | before→after | netGain | cacheRecompute
8
+ * Top KPIs: total cut / net saved / active savings / card count
9
+ *
10
+ * @module dsh-context-compression-improved/client/CutTimeline
11
+ */
12
+ import { useEffect, useState } from 'react'
13
+
14
+ interface CutRow {
15
+ ts: string
16
+ strategy: 'small-knife' | 'big-knife' | 'card-merge' | 'skeleton'
17
+ component: string
18
+ tokensBefore: number
19
+ tokensAfter: number
20
+ netGain: number
21
+ cacheRecomputeEst: number
22
+ }
23
+
24
+ const STRATEGY_COLORS: Record<string, string> = {
25
+ 'small-knife': '#4a9eff',
26
+ 'big-knife': '#ff6b35',
27
+ 'card-merge': '#9b59b6',
28
+ 'skeleton': '#27ae60',
29
+ }
30
+
31
+ const STRATEGY_LABELS: Record<string, string> = {
32
+ 'small-knife': '小刀',
33
+ 'big-knife': '大刀',
34
+ 'card-merge': '中刀',
35
+ 'skeleton': '骨架',
36
+ }
37
+
38
+ export interface CutTimelineProps {
39
+ /** Fetch URL for cuts data. Default: '/api/dsh-context-compression-cuts'. */
40
+ readonly fetchUrl?: string
41
+ readonly sessionId?: string
42
+ }
43
+
44
+ export function CutTimeline({ fetchUrl = '/api/dsh-context-compression-cuts', sessionId }: CutTimelineProps) {
45
+ const [cuts, setCuts] = useState<CutRow[]>([])
46
+ const [loading, setLoading] = useState(true)
47
+ const [filter, setFilter] = useState<string>('all')
48
+
49
+ useEffect(() => {
50
+ const url = sessionId ? `${fetchUrl}?session=${sessionId}` : fetchUrl
51
+ fetch(url)
52
+ .then(r => r.ok ? r.json() : [])
53
+ .then((data: CutRow[]) => { setCuts(data); setLoading(false) })
54
+ .catch(() => { setLoading(false) })
55
+ }, [fetchUrl, sessionId])
56
+
57
+ const filtered = filter === 'all' ? cuts : cuts.filter(c => c.strategy === filter)
58
+ const totalSaved = filtered.reduce((s, c) => s + Math.max(0, c.netGain), 0)
59
+ const totalCuts = filtered.length
60
+
61
+ if (loading) return <div role="status">加载刀法记录...</div>
62
+
63
+ return (
64
+ <div style={{ fontSize: '0.85em' }}>
65
+ {/* KPI */}
66
+ <div style={{ display: 'flex', gap: 16, marginBottom: 12 }}>
67
+ <span>总刀数: <strong>{totalCuts}</strong></span>
68
+ <span>累计净省: <strong>{totalSaved.toLocaleString()}</strong> tokens</span>
69
+ </div>
70
+ {/* Filter */}
71
+ <div style={{ marginBottom: 8 }}>
72
+ <select value={filter} onChange={e => setFilter(e.target.value)} aria-label="策略筛选">
73
+ <option value="all">全部</option>
74
+ <option value="small-knife">小刀</option>
75
+ <option value="big-knife">大刀</option>
76
+ <option value="card-merge">中刀</option>
77
+ <option value="skeleton">骨架</option>
78
+ </select>
79
+ </div>
80
+ {/* Table */}
81
+ <div style={{ maxHeight: 400, overflow: 'auto', border: '1px solid #ddd', borderRadius: 4 }}>
82
+ <table style={{ width: '100%', borderCollapse: 'collapse', fontSize: '0.9em' }}>
83
+ <thead>
84
+ <tr style={{ background: '#f5f5f5', position: 'sticky', top: 0 }}>
85
+ <th style={{ padding: 4, textAlign: 'left' }}>时间</th>
86
+ <th style={{ padding: 4 }}>策略</th>
87
+ <th style={{ padding: 4, textAlign: 'right' }}>Before→After</th>
88
+ <th style={{ padding: 4, textAlign: 'right' }}>净省</th>
89
+ <th style={{ padding: 4, textAlign: 'right' }}>重算</th>
90
+ </tr>
91
+ </thead>
92
+ <tbody>
93
+ {filtered.slice(0, 200).map((cut, i) => (
94
+ <tr key={i} style={{ borderBottom: '1px solid #eee' }}>
95
+ <td style={{ padding: 4, whiteSpace: 'nowrap' }}>{new Date(cut.ts).toLocaleTimeString()}</td>
96
+ <td style={{ padding: 4, textAlign: 'center' }}>
97
+ <span style={{ color: '#fff', background: STRATEGY_COLORS[cut.strategy], padding: '1px 5px', borderRadius: 3, fontSize: '0.8em' }}>
98
+ {STRATEGY_LABELS[cut.strategy] ?? cut.strategy}
99
+ </span>
100
+ </td>
101
+ <td style={{ padding: 4, textAlign: 'right' }}>{cut.tokensBefore.toLocaleString()}→{cut.tokensAfter.toLocaleString()}</td>
102
+ <td style={{ padding: 4, textAlign: 'right', color: cut.netGain > 0 ? '#27ae60' : '#e74c3c' }}>{cut.netGain.toLocaleString()}</td>
103
+ <td style={{ padding: 4, textAlign: 'right', opacity: 0.7 }}>{cut.cacheRecomputeEst.toLocaleString()}</td>
104
+ </tr>
105
+ ))}
106
+ </tbody>
107
+ </table>
108
+ {filtered.length > 200 ? <div style={{ padding: 8, opacity: 0.7 }}>显示前 200 条,共 {filtered.length} 条</div> : null}
109
+ </div>
110
+ </div>
111
+ )
112
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * FieldTooltip: per-parameter help tooltip with ? icon.
3
+ *
4
+ * Plan: cci-longterm-refactor v0.14.2 (F21)
5
+ *
6
+ * Shows on hover/focus. Content includes: one-line purpose, default, range,
7
+ * effect of increase/decrease, and whether the field is session-frozen.
8
+ *
9
+ * @module dsh-context-compression-improved/client/FieldTooltip
10
+ */
11
+ import { useState, type ReactNode } from 'react'
12
+
13
+ export interface FieldTooltipProps {
14
+ readonly purpose: string
15
+ readonly defaultValue: string
16
+ readonly range: string
17
+ readonly effect: string
18
+ readonly frozen?: boolean
19
+ readonly children: ReactNode
20
+ }
21
+
22
+ export function FieldTooltip({ purpose, defaultValue, range, effect, frozen = false, children }: FieldTooltipProps) {
23
+ const [visible, setVisible] = useState(false)
24
+
25
+ return (
26
+ <span style={{ position: 'relative', display: 'inline-flex', alignItems: 'center', gap: 4 }}>
27
+ {children}
28
+ <button
29
+ type="button"
30
+ aria-label={`Help: ${purpose}`}
31
+ onMouseEnter={() => setVisible(true)}
32
+ onMouseLeave={() => setVisible(false)}
33
+ onFocus={() => setVisible(true)}
34
+ onBlur={() => setVisible(false)}
35
+ style={{ background: 'none', border: '1px solid currentColor', borderRadius: '50%', width: 16, height: 16, fontSize: 10, cursor: 'help', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', opacity: 0.6 }}
36
+ >
37
+ ?
38
+ </button>
39
+ {visible ? (
40
+ <div role="tooltip" style={{ position: 'absolute', bottom: '120%', left: 0, zIndex: 100, background: 'var(--surface-raised, #fff)', border: '1px solid #ccc', borderRadius: 6, padding: '8px 12px', fontSize: '0.8em', lineHeight: 1.5, maxWidth: 280, boxShadow: '0 2px 8px rgba(0,0,0,0.12)' }}>
41
+ <div><strong>{purpose}</strong></div>
42
+ <div>默认: {defaultValue} · 范围: {range}</div>
43
+ <div>{effect}</div>
44
+ {frozen ? <div style={{ marginTop: 4, opacity: 0.7 }}>🔒 修改仅影响新会话(重启生效)</div> : null}
45
+ </div>
46
+ ) : null}
47
+ </span>
48
+ )
49
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * SettingsGroup: collapsible section container for the refactored settings panel.
3
+ *
4
+ * Plan: cci-longterm-refactor v0.14.2 (F22)
5
+ *
6
+ * Renders a titled, collapsible region with an "N modified" badge
7
+ * when child values differ from their defaults.
8
+ *
9
+ * @module dsh-context-compression-improved/client/SettingsGroup
10
+ */
11
+ import { useState, type ReactNode } from 'react'
12
+
13
+ export interface SettingsGroupProps {
14
+ readonly title: string
15
+ readonly badge?: string
16
+ readonly defaultOpen: boolean
17
+ readonly modifiedCount?: number
18
+ readonly children: ReactNode
19
+ }
20
+
21
+ /** Persistent collapse state via localStorage key derived from title. */
22
+ function storageKey(title: string): string {
23
+ return `cci-group-${title.toLowerCase().replace(/\s+/g, '-')}`
24
+ }
25
+
26
+ export function SettingsGroup({ title, badge, defaultOpen, modifiedCount = 0, children }: SettingsGroupProps) {
27
+ const key = storageKey(title)
28
+ const [open, setOpen] = useState<boolean>(() => {
29
+ try {
30
+ const stored = localStorage.getItem(key)
31
+ return stored !== null ? stored === '1' : defaultOpen
32
+ } catch { return defaultOpen }
33
+ })
34
+
35
+ const toggle = () => {
36
+ const next = !open
37
+ setOpen(next)
38
+ try { localStorage.setItem(key, next ? '1' : '0') } catch { /* private mode */ }
39
+ }
40
+
41
+ return (
42
+ <section style={{ marginBottom: 12 }}>
43
+ <button
44
+ type="button"
45
+ onClick={toggle}
46
+ aria-expanded={open}
47
+ style={{ display: 'flex', alignItems: 'center', gap: 6, width: '100%', textAlign: 'left', background: 'none', border: 'none', cursor: 'pointer', padding: '6px 0', fontWeight: 600, fontSize: '0.95em' }}
48
+ >
49
+ <span>{open ? '▾' : '▸'}</span>
50
+ <span>{title}</span>
51
+ {badge ? <span style={{ fontSize: '0.75em', opacity: 0.7, marginLeft: 4 }}>[{badge}]</span> : null}
52
+ {modifiedCount > 0 ? (
53
+ <span style={{ fontSize: '0.75em', background: 'var(--accent, #5b8def)', color: '#fff', borderRadius: 10, padding: '1px 6px', marginLeft: 6 }}>
54
+ {modifiedCount} 项已修改
55
+ </span>
56
+ ) : null}
57
+ </button>
58
+ {open ? <div style={{ paddingLeft: 12 }}>{children}</div> : null}
59
+ </section>
60
+ )
61
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Cross-plugin conflict detection (F11).
3
+ *
4
+ * Plan: cci-longterm-refactor v0.15.2
5
+ *
6
+ * Detects co-installed plugins at startup. Warns once, does NOT disable.
7
+ * The plugins occupy independent multiplication zones:
8
+ * - CCI: selector-level tool-result trimming (what/how to cut)
9
+ * - live-compact: turn-end small cuts (when to cut, prefix cache)
10
+ * - billion-context: model-driven fold (model decides what to compress)
11
+ * - flash-presets: global threshold + tool schema pruning
12
+ *
13
+ * @module dsh-context-compression-improved/runtime/conflict-detect
14
+ */
15
+
16
+ export interface PluginPresence {
17
+ readonly name: string
18
+ readonly version: string
19
+ }
20
+
21
+ /** Known compaction-adjacent plugins to detect. */
22
+ const WATCH_PLUGINS = [
23
+ 'dsh-live-compact',
24
+ 'dsh-live-compact-x',
25
+ 'billion-context',
26
+ 'billion-context-dsh',
27
+ 'dsh-flash-presets',
28
+ ] as const
29
+
30
+ export interface CoexistenceReport {
31
+ readonly detected: readonly PluginPresence[]
32
+ readonly mode: 'solo' | 'coexist'
33
+ readonly note: string
34
+ }
35
+
36
+ /**
37
+ * Given a list of installed plugins (from ctx.plugin.list() or equivalent),
38
+ * produce a coexistence report. Call once at startup.
39
+ */
40
+ export function detectCoexistence(installed: readonly PluginPresence[]): CoexistenceReport {
41
+ const detected = installed.filter(p =>
42
+ (WATCH_PLUGINS as readonly string[]).includes(p.name),
43
+ )
44
+ if (detected.length === 0) {
45
+ return { detected: [], mode: 'solo', note: '' }
46
+ }
47
+ const names = detected.map(p => `${p.name}@${p.version}`).join(', ')
48
+ return {
49
+ detected,
50
+ mode: 'coexist',
51
+ note: `Co-installed: ${names}. CCI handles selector-level trimming; these plugins handle other compaction layers. Independent multiplication zones — no conflict expected.`,
52
+ }
53
+ }