dsh-context-compression-improved 0.8.0-beta.2 → 0.8.0-beta.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.
@@ -1,124 +1,126 @@
1
- /**
2
- * Full-page Settings surface backed by the same durable selector state.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/settings-section
7
- */
8
-
9
- import { useEffect, useState } from 'react'
10
- import css from './CompressionProfileSelector.module.css'
11
- import {
12
- AUTO_COMPACT_THRESHOLD_LIMITS,
13
- COMPRESSION_PROFILES,
14
- type CompressionProfile,
15
- type CustomCompressionPolicyV3,
16
- } from '../profiles.ts'
17
- import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
18
- import { AutoCompactThresholdControls, CodeSkeletonControls } from './CompressionProfileControls.tsx'
19
- import { EstimatorControls, EstimatorInactiveNotice } from './EstimatorControls.tsx'
20
- import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
21
-
22
- /** Full-page Settings surface backed by the same durable selector state. */
23
- export function ContextCompressionSettingsSection(props: CompressionProfileSelectorProps) {
24
- return <SettingsCompressionProfileControls {...props} />
25
- }
26
-
27
- export function SettingsCompressionProfileControls({
28
- useCompression, select, saveCustom, resetCustom, saveAutoCompact, saveCodeSkeleton,
29
- savePresetOptions, t,
30
- }: CompressionProfileSelectorProps) {
31
- const state = useCompression(snapshot => snapshot)
32
- // Harness 0.1.5 dropped browser-side agentPreset from session summaries, so
33
- // the old Minimal-preset gate has no data source; the selector stays enabled.
34
- const selectorAvailable = true
35
- const [saving, setSaving] = useState(false)
36
- const [saveError, setSaveError] = useState<string | null>(null)
37
- const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
38
- const current = state.value?.profile ?? 'balanced'
39
- useEffect(() => {
40
- const custom = state.value?.custom
41
- setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
42
- }, [current, state.value?.custom])
43
- if (state.status === 'unavailable') return null
44
-
45
- const busy = state.status === 'loading' || saving
46
- const selectProfile = (profile: CompressionProfile): void => {
47
- if (!selectorAvailable || !state.writable || profile === current) return
48
- setSaveError(null)
49
- setSaving(true)
50
- void select(profile).then(
51
- () => { setSaving(false) },
52
- (error: unknown) => {
53
- setSaving(false)
54
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
55
- },
56
- )
57
- }
58
- const settle = (operation: () => Promise<void>): void => {
59
- setSaveError(null)
60
- setSaving(true)
61
- void operation().then(
62
- () => { setSaving(false) },
63
- (error: unknown) => {
64
- setSaving(false)
65
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
66
- },
67
- )
68
- }
69
-
70
- return (
71
- <section className={css.settingsSection}>
72
- <h2 className={css.settingsTitle}>{t('settings.title')}</h2>
73
- <p className={css.settingsDescription}>{t('settings.description')}</p>
74
- {selectorAvailable ? (
75
- <div className={css.profileGrid} aria-label={t('label')}>
76
- {COMPRESSION_PROFILES.map((profile) => {
77
- const selected = profile === current
78
- return (
79
- <button key={profile} type="button" className={css.profileCard} aria-pressed={selected}
80
- disabled={busy || !state.writable} onClick={() => { selectProfile(profile) }}>
81
- <span className={css.profileCardTop}>
82
- <span className={css.profileCardTitle}>{t(`profile.${profile}`)}</span>
83
- {selected ? <span className={css.profileCurrent}>{t('profile.current')}</span> : null}
84
- </span>
85
- <span className={css.profileCardDetail}>{t(`detail.${profile}`)}</span>
86
- </button>
87
- )
88
- })}
89
- </div>
90
- ) : <div className={css.unavailable} role="status">{t('status.minimalUnavailable')}</div>}
91
- <AutoCompactThresholdControls
92
- value={state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default}
93
- disabled={busy || !state.writable || !selectorAvailable}
94
- save={saveAutoCompact}
95
- settle={settle}
96
- t={t}
97
- />
98
- <CodeSkeletonControls
99
- value={state.value?.codeSkeleton?.enabled ?? false}
100
- disabled={busy || !state.writable || !selectorAvailable}
101
- save={saveCodeSkeleton}
102
- settle={settle}
103
- t={t}
104
- />
105
- {current !== 'tokenpilot-inspired' ? (
106
- <EstimatorInactiveNotice profile={t(`profile.${current}`)} t={t} />
107
- ) : (
108
- <EstimatorControls
109
- options={state.value?.presetOptions ?? {}}
110
- disabled={busy || !state.writable || !selectorAvailable}
111
- save={savePresetOptions}
112
- settle={settle}
113
- t={t}
114
- />
115
- )}
116
- <div className={css.pricing}>{t('pricing.disclosure')}</div>
117
- {current !== 'custom' || draft === null || !selectorAvailable ? null : (
118
- <CustomPolicyEditor value={draft} disabled={busy || !state.writable} setValue={setDraft}
119
- save={() => saveCustom(structuredClone(draft))} reset={resetCustom} settle={settle} t={t} />
120
- )}
121
- {saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
122
- </section>
123
- )
124
- }
1
+ /**
2
+ * Full-page Settings surface backed by the same durable selector state.
3
+ *
4
+ * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
+ *
6
+ * @module dsh-context-compression-improved/client/settings-section
7
+ */
8
+
9
+ import { useEffect, useState } from 'react'
10
+ import css from './CompressionProfileSelector.module.css'
11
+ import {
12
+ AUTO_COMPACT_THRESHOLD_LIMITS,
13
+ COMPRESSION_PROFILES,
14
+ type CompressionProfile,
15
+ type CustomCompressionPolicyV3,
16
+ } from '../profiles.ts'
17
+ import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
18
+ import { AutoCompactThresholdControls, CodeSkeletonControls } from './CompressionProfileControls.tsx'
19
+ import { EstimatorControls, EstimatorInactiveNotice } from './EstimatorControls.tsx'
20
+ import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
21
+ import { SavingsCard } from './savings-card'
22
+
23
+ /** Full-page Settings surface backed by the same durable selector state. */
24
+ export function ContextCompressionSettingsSection(props: CompressionProfileSelectorProps) {
25
+ return <SettingsCompressionProfileControls {...props} />
26
+ }
27
+
28
+ export function SettingsCompressionProfileControls({
29
+ useCompression, select, saveCustom, resetCustom, saveAutoCompact, saveCodeSkeleton,
30
+ savePresetOptions, t,
31
+ }: CompressionProfileSelectorProps) {
32
+ const state = useCompression(snapshot => snapshot)
33
+ // Harness 0.1.5 dropped browser-side agentPreset from session summaries, so
34
+ // the old Minimal-preset gate has no data source; the selector stays enabled.
35
+ const selectorAvailable = true
36
+ const [saving, setSaving] = useState(false)
37
+ const [saveError, setSaveError] = useState<string | null>(null)
38
+ const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
39
+ const current = state.value?.profile ?? 'balanced'
40
+ useEffect(() => {
41
+ const custom = state.value?.custom
42
+ setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
43
+ }, [current, state.value?.custom])
44
+ if (state.status === 'unavailable') return null
45
+
46
+ const busy = state.status === 'loading' || saving
47
+ const selectProfile = (profile: CompressionProfile): void => {
48
+ if (!selectorAvailable || !state.writable || profile === current) return
49
+ setSaveError(null)
50
+ setSaving(true)
51
+ void select(profile).then(
52
+ () => { setSaving(false) },
53
+ (error: unknown) => {
54
+ setSaving(false)
55
+ setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
56
+ },
57
+ )
58
+ }
59
+ const settle = (operation: () => Promise<void>): void => {
60
+ setSaveError(null)
61
+ setSaving(true)
62
+ void operation().then(
63
+ () => { setSaving(false) },
64
+ (error: unknown) => {
65
+ setSaving(false)
66
+ setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
67
+ },
68
+ )
69
+ }
70
+
71
+ return (
72
+ <section className={css.settingsSection}>
73
+ <h2 className={css.settingsTitle}>{t('settings.title')}</h2>
74
+ <p className={css.settingsDescription}>{t('settings.description')}</p>
75
+ {selectorAvailable ? (
76
+ <div className={css.profileGrid} aria-label={t('label')}>
77
+ {COMPRESSION_PROFILES.map((profile) => {
78
+ const selected = profile === current
79
+ return (
80
+ <button key={profile} type="button" className={css.profileCard} aria-pressed={selected}
81
+ disabled={busy || !state.writable} onClick={() => { selectProfile(profile) }}>
82
+ <span className={css.profileCardTop}>
83
+ <span className={css.profileCardTitle}>{t(`profile.${profile}`)}</span>
84
+ {selected ? <span className={css.profileCurrent}>{t('profile.current')}</span> : null}
85
+ </span>
86
+ <span className={css.profileCardDetail}>{t(`detail.${profile}`)}</span>
87
+ </button>
88
+ )
89
+ })}
90
+ </div>
91
+ ) : <div className={css.unavailable} role="status">{t('status.minimalUnavailable')}</div>}
92
+ <AutoCompactThresholdControls
93
+ value={state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default}
94
+ disabled={busy || !state.writable || !selectorAvailable}
95
+ save={saveAutoCompact}
96
+ settle={settle}
97
+ t={t}
98
+ />
99
+ <CodeSkeletonControls
100
+ value={state.value?.codeSkeleton?.enabled ?? false}
101
+ disabled={busy || !state.writable || !selectorAvailable}
102
+ save={saveCodeSkeleton}
103
+ settle={settle}
104
+ t={t}
105
+ />
106
+ {current !== 'tokenpilot-inspired' ? (
107
+ <EstimatorInactiveNotice profile={t(`profile.${current}`)} t={t} />
108
+ ) : (
109
+ <EstimatorControls
110
+ options={state.value?.presetOptions ?? {}}
111
+ disabled={busy || !state.writable || !selectorAvailable}
112
+ save={savePresetOptions}
113
+ settle={settle}
114
+ t={t}
115
+ />
116
+ )}
117
+ <SavingsCard t={t} />
118
+ <div className={css.pricing}>{t('pricing.disclosure')}</div>
119
+ {current !== 'custom' || draft === null || !selectorAvailable ? null : (
120
+ <CustomPolicyEditor value={draft} disabled={busy || !state.writable} setValue={setDraft}
121
+ save={() => saveCustom(structuredClone(draft))} reset={resetCustom} settle={settle} t={t} />
122
+ )}
123
+ {saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
124
+ </section>
125
+ )
126
+ }