dsh-context-compression-improved 0.2.4 → 0.2.5

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.
Files changed (127) hide show
  1. package/.gitattributes +2 -1
  2. package/.githooks/pre-push +37 -0
  3. package/.github/workflows/ci.yml +8 -8
  4. package/CHANGELOG.ja.md +169 -39
  5. package/CHANGELOG.ko.md +167 -39
  6. package/CHANGELOG.md +212 -16
  7. package/CHANGELOG.zh.md +152 -39
  8. package/CONTRIBUTING.md +22 -22
  9. package/README.ja.md +85 -104
  10. package/README.ko.md +85 -103
  11. package/README.md +1 -19
  12. package/README.zh.md +85 -101
  13. package/THIRD_PARTY_NOTICES.md +14 -14
  14. package/docs/compat-0.1.5-report.md +77 -0
  15. package/docs/installation.ja.md +78 -76
  16. package/docs/installation.ko.md +78 -76
  17. package/docs/installation.md +103 -76
  18. package/docs/installation.zh.md +100 -76
  19. package/docs/repair-log.md +657 -582
  20. package/eslint.config.js +30 -30
  21. package/package.json +75 -54
  22. package/packages/selector/README.md +7 -12
  23. package/packages/selector/README.zh.md +6 -13
  24. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
  25. package/packages/selector/cordis.patch.yml +27 -19
  26. package/packages/selector/dsh.plugin.json +16 -16
  27. package/packages/selector/lib/client.d.ts +97 -5
  28. package/packages/selector/lib/client.js +1884 -92
  29. package/packages/selector/lib/config.js +863 -6
  30. package/packages/selector/lib/index.d.ts +29 -21
  31. package/packages/selector/lib/index.js +424 -18
  32. package/packages/selector/lib/invariant.js +4 -4
  33. package/packages/selector/lib/pruner.d.ts +179 -4
  34. package/packages/selector/lib/pruner.js +1406 -371
  35. package/packages/selector/lib/style.css +42 -0
  36. package/packages/selector/lib/tail-trim.js +13 -4
  37. package/packages/selector/package.json +18 -27
  38. package/packages/selector/screenshots.json +3 -6
  39. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
  40. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  41. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
  42. package/packages/selector/src/client/EstimatorControls.tsx +277 -281
  43. package/packages/selector/src/client/decode.ts +57 -49
  44. package/packages/selector/src/client/index.ts +200 -62
  45. package/packages/selector/src/client/locales/de.ts +141 -0
  46. package/packages/selector/src/client/locales/es.ts +141 -0
  47. package/packages/selector/src/client/locales/fr.ts +141 -0
  48. package/packages/selector/src/client/locales/it.ts +141 -0
  49. package/packages/selector/src/client/locales/ja.ts +141 -0
  50. package/packages/selector/src/client/locales/ko.ts +141 -0
  51. package/packages/selector/src/client/locales/ru.ts +141 -0
  52. package/packages/selector/src/client/locales.ts +282 -198
  53. package/packages/selector/src/client/monitor-fab.ts +336 -0
  54. package/packages/selector/src/client/preset-options.ts +88 -70
  55. package/packages/selector/src/client/savings-card.tsx +150 -0
  56. package/packages/selector/src/client/settings-section.tsx +140 -126
  57. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
  58. package/packages/selector/src/index.ts +671 -327
  59. package/packages/selector/src/invariant.ts +113 -113
  60. package/packages/selector/src/profiles.ts +431 -342
  61. package/packages/selector/src/pruner/state.ts +57 -43
  62. package/packages/selector/src/pruner.ts +2736 -2154
  63. package/packages/selector/src/runtime/audit.ts +303 -231
  64. package/packages/selector/src/runtime/config.ts +756 -642
  65. package/packages/selector/src/runtime/measurement.ts +436 -432
  66. package/packages/selector/src/runtime/monitor.ts +235 -0
  67. package/packages/selector/src/runtime/retrieve.ts +479 -457
  68. package/packages/selector/src/runtime/savings.ts +337 -0
  69. package/packages/selector/src/runtime/session-events.ts +30 -17
  70. package/packages/selector/src/runtime/summary-command.ts +127 -0
  71. package/packages/selector/src/runtime/tail-trim.ts +166 -166
  72. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
  73. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
  74. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
  75. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
  76. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
  77. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  78. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  79. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  80. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  81. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -275
  82. package/packages/selector/src/runtime/types.ts +365 -325
  83. package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
  84. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
  85. package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
  86. package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
  87. package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
  88. package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
  89. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
  90. package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
  91. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  92. package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
  93. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
  94. package/packages/selector/tests/preset-overlay.host.spec.ts +8 -18
  95. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  96. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
  97. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
  98. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
  99. package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
  100. package/packages/selector/tests/runtime/audit.spec.ts +275 -172
  101. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
  102. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  103. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  104. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  105. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2702
  106. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  107. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  108. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  109. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
  110. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
  111. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
  112. package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
  113. package/packages/selector/tests/standing-generation.host.spec.ts +142 -87
  114. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
  115. package/pnpm-workspace.yaml +66 -19
  116. package/scripts/capture-profile-baseline.mjs +42 -0
  117. package/scripts/generate-tokenizer-fixtures.py +81 -81
  118. package/scripts/generate-vision-fixtures.py +208 -208
  119. package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
  120. package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
  121. package/scripts/toolclass-corpus-replay.mjs +281 -273
  122. package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
  123. package/tests/TEST_INVENTORY.md +41 -42
  124. package/scripts/capture-profile-baseline.ts +0 -80
  125. package/tsconfig.scripts.json +0 -13
  126. /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
  127. /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
@@ -1,229 +1,293 @@
1
- /**
2
- * CompressionProfileControls: dropdown selector for compression profiles,
3
- * plus AutoCompactThresholdControls and CodeSkeletonControls sub-components.
4
- *
5
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
6
- *
7
- * @module dsh-context-compression-improved/client/CompressionProfileControls
8
- */
9
-
10
- import { useEffect, useId, useState } from 'react'
11
- import { IconChevronDownOutline14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
12
- import type { ContextCompressionLocaleKey } from './locales.ts'
13
- import css from './CompressionProfileSelector.module.css'
14
- import {
15
- AUTO_COMPACT_THRESHOLD_LIMITS,
16
- COMPRESSION_PROFILES,
17
- isValidAutoCompactThresholdPercent,
18
- type CompressionProfile,
19
- type CustomCompressionPolicyV3,
20
- } from '../profiles.ts'
21
- import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
22
- import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
23
-
24
- export function CompressionProfileControls({
25
- useCompression, useSessions, select, saveCustom, resetCustom, t, showCustomEditor,
26
- }: CompressionProfileSelectorProps & { showCustomEditor: boolean }) {
27
- const state = useCompression(snapshot => snapshot)
28
- const currentPreset = useSessions((sessions) => {
29
- const current = sessions.current
30
- return current === undefined ? undefined : sessions.byId[current]?.agentPreset
31
- })
32
- // A profile is Host-global. A cold Session may not have reported a live
33
- // capability yet, so only Minimal blocks initial configuration.
34
- const contextCompressionAvailable = currentPreset !== 'minimal'
35
- const [open, setOpen] = useState(false)
36
- const [saving, setSaving] = useState(false)
37
- const [saveError, setSaveError] = useState<string | null>(null)
38
- const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
39
- const unavailableId = useId()
40
- const current = state.value?.profile ?? 'balanced'
41
- useEffect(() => {
42
- if (state.status === 'ready' && state.writable && contextCompressionAvailable) return
43
- setOpen(false)
44
- }, [contextCompressionAvailable, state.status, state.writable])
45
- useEffect(() => {
46
- const custom = state.value?.custom
47
- setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
48
- }, [current, state.value?.custom])
49
- if (state.status === 'unavailable') return null
50
- const busy = state.status === 'loading' || saving
51
- const label = busy ? t('status.loading') : t(`profile.${current}`)
52
- return (
53
- <div className={css.root}>
54
- <Menu
55
- open={open && contextCompressionAvailable}
56
- onClose={() => { setOpen(false) }}
57
- selectedId={current}
58
- items={COMPRESSION_PROFILES.map(profile => ({
59
- id: profile,
60
- label: (
61
- <span className={css.menuCopy}>
62
- <span className={css.menuTitle}>{t(`profile.${profile}`)}</span>
63
- <span className={css.menuDetail}>{t(`detail.${profile}`)}</span>
64
- </span>
65
- ),
66
- }))}
67
- onSelect={(id) => {
68
- setOpen(false)
69
- if (id === current || !COMPRESSION_PROFILES.includes(id as CompressionProfile)) return
70
- setSaveError(null)
71
- setSaving(true)
72
- void select(id as CompressionProfile).then(
73
- () => { setSaving(false) },
74
- (error: unknown) => {
75
- setSaving(false)
76
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
77
- },
78
- )
79
- }}
80
- align="start"
81
- portal
82
- anchor={(
83
- <button
84
- type="button"
85
- className={css.button}
86
- aria-haspopup="menu"
87
- aria-expanded={open && contextCompressionAvailable}
88
- aria-describedby={contextCompressionAvailable ? undefined : unavailableId}
89
- disabled={busy || !state.writable || !contextCompressionAvailable}
90
- onClick={() => { setOpen(value => !value) }}
91
- >
92
- <span className={css.copy}>
93
- <span className={css.label}>{t('label')}</span>
94
- <span className={css.value}>{label}</span>
95
- </span>
96
- <IconChevronDownOutline14 className={css.chevron} />
97
- </button>
98
- )}
99
- />
100
- {contextCompressionAvailable ? null : (
101
- <div id={unavailableId} className={css.unavailable} role="status">
102
- {t('status.minimalUnavailable')}
103
- </div>
104
- )}
105
- <div className={css.pricing}>{t('pricing.disclosure')}</div>
106
- <div className={css.settingsHint}>
107
- {t('autoCompact.summaryHint').replace('{percent}', String(state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default))}
108
- </div>
109
- {current !== 'custom' || showCustomEditor ? null : (
110
- <div className={css.settingsHint}>{t('custom.settingsHint')}</div>
111
- )}
112
- {current !== 'custom' || draft === null || !showCustomEditor ? null : (
113
- <CustomPolicyEditor
114
- value={draft}
115
- disabled={busy || !state.writable || !contextCompressionAvailable}
116
- setValue={setDraft}
117
- save={() => saveCustom(structuredClone(draft))}
118
- reset={resetCustom}
119
- settle={(operation) => {
120
- setSaveError(null)
121
- setSaving(true)
122
- void operation().then(
123
- () => { setSaving(false) },
124
- (error: unknown) => {
125
- setSaving(false)
126
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
127
- },
128
- )
129
- }}
130
- t={t}
131
- />
132
- )}
133
- {saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
134
- </div>
135
- )
136
- }
137
-
138
- interface AutoCompactThresholdControlsProps {
139
- value: number
140
- disabled: boolean
141
- save: (thresholdPercent: number) => Promise<void>
142
- settle: (operation: () => Promise<void>) => void
143
- t: (key: ContextCompressionLocaleKey) => string
144
- }
145
-
146
- /**
147
- * The authoritative Auto Compact threshold editor for the context-compression
148
- * section. A typed number input and its save path are kept deliberately simple;
149
- * values outside the recommended 70–85 band warn without blocking.
150
- */
151
- export function AutoCompactThresholdControls({ value, disabled, save, settle, t }: AutoCompactThresholdControlsProps) {
152
- const [draft, setDraft] = useState(String(value))
153
- useEffect(() => { setDraft(String(value)) }, [value])
154
- const parsed = Number(draft)
155
- // Number inputs legally produce value-equivalent drafts such as '8e1';
156
- // only the parsed value needs to be a valid threshold.
157
- const valid = isValidAutoCompactThresholdPercent(parsed)
158
- const risk = !valid
159
- ? 'autoCompact.invalid'
160
- : parsed < 70 ? 'autoCompact.riskLow'
161
- : parsed > 85 ? 'autoCompact.riskHigh'
162
- : undefined
163
- return (
164
- <section className={css.autoCompact} aria-labelledby="context-compression-autocompact-title">
165
- <h3 id="context-compression-autocompact-title" className={css.autoCompactTitle}>{t('autoCompact.title')}</h3>
166
- <p className={css.customNote}>{t('autoCompact.description')}</p>
167
- <label className={css.field}>
168
- <span>{t('autoCompact.inputLabel')}</span>
169
- <input
170
- type="number"
171
- value={draft}
172
- min={AUTO_COMPACT_THRESHOLD_LIMITS.min}
173
- max={AUTO_COMPACT_THRESHOLD_LIMITS.max}
174
- step={AUTO_COMPACT_THRESHOLD_LIMITS.step}
175
- disabled={disabled}
176
- aria-invalid={!valid}
177
- onChange={(event) => { setDraft(event.currentTarget.value) }}
178
- />
179
- </label>
180
- {risk === undefined ? null : (
181
- <div className={risk === 'autoCompact.invalid' ? css.error : css.autoCompactRisk} role={risk === 'autoCompact.invalid' ? 'alert' : 'note'}>
182
- {t(risk)}
183
- </div>
184
- )}
185
- <div className={css.actions}>
186
- <button
187
- type="button"
188
- disabled={disabled || !valid || parsed === value}
189
- onClick={() => { settle(() => save(parsed)) }}
190
- >
191
- {t('autoCompact.save')}
192
- </button>
193
- </div>
194
- </section>
195
- )
196
- }
197
-
198
- interface CodeSkeletonControlsProps {
199
- value: boolean
200
- disabled: boolean
201
- save: (enabled: boolean) => Promise<void>
202
- settle: (operation: () => Promise<void>) => void
203
- t: (key: ContextCompressionLocaleKey) => string
204
- }
205
-
206
- /**
207
- * The authoritative code-skeleton reducer gate for the context-compression
208
- * section. Deliberately minimal — an on/off select plus its own save path —
209
- * because the gate is orthogonal to every profile and carries no parameters.
210
- */
211
- export function CodeSkeletonControls({ value, disabled, save, settle, t }: CodeSkeletonControlsProps) {
212
- return (
213
- <section className={css.autoCompact} aria-labelledby="context-compression-codeskeleton-title">
214
- <h3 id="context-compression-codeskeleton-title" className={css.autoCompactTitle}>{t('codeSkeleton.title')}</h3>
215
- <p className={css.customNote}>{t('codeSkeleton.description')}</p>
216
- <label className={css.field}>
217
- <span>{t('codeSkeleton.enabled')}</span>
218
- <select
219
- value={value ? 'on' : 'off'}
220
- disabled={disabled}
221
- onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
222
- >
223
- <option value="on">{t('codeSkeleton.enabled.on')}</option>
224
- <option value="off">{t('codeSkeleton.enabled.off')}</option>
225
- </select>
226
- </label>
227
- </section>
228
- )
229
- }
1
+ /**
2
+ * CompressionProfileControls: dropdown selector for compression profiles,
3
+ * plus AutoCompactThresholdControls and CodeSkeletonControls sub-components.
4
+ *
5
+ * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
6
+ *
7
+ * @module dsh-context-compression-improved/client/CompressionProfileControls
8
+ */
9
+
10
+ import { useEffect, useId, useState } from 'react'
11
+ import { IconChevronDownOutline14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
12
+ import type { ContextCompressionLocaleKey } from './locales.ts'
13
+ import css from './CompressionProfileSelector.module.css'
14
+ import {
15
+ AUTO_COMPACT_THRESHOLD_LIMITS,
16
+ COMPRESSION_PROFILES,
17
+ isValidAutoCompactThresholdPercent,
18
+ type CompressionProfile,
19
+ type CustomCompressionPolicyV3,
20
+ } from '../profiles.ts'
21
+ import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
22
+ import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
23
+
24
+ export function CompressionProfileControls({
25
+ useCompression, select, saveCustom, resetCustom, t, showCustomEditor,
26
+ }: CompressionProfileSelectorProps & { showCustomEditor: boolean }) {
27
+ const state = useCompression(snapshot => snapshot)
28
+ // Harness 0.1.5 dropped browser-side agentPreset from session summaries; see
29
+ // the section component note. Only Minimal used to block initial
30
+ // configuration, and that signal is no longer available client-side.
31
+ const contextCompressionAvailable = true
32
+ const [open, setOpen] = useState(false)
33
+ const [saving, setSaving] = useState(false)
34
+ const [saveError, setSaveError] = useState<string | null>(null)
35
+ const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
36
+ const unavailableId = useId()
37
+ const current = state.value?.profile ?? 'balanced'
38
+ useEffect(() => {
39
+ if (state.status === 'ready' && state.writable && contextCompressionAvailable) return
40
+ setOpen(false)
41
+ }, [contextCompressionAvailable, state.status, state.writable])
42
+ useEffect(() => {
43
+ const custom = state.value?.custom
44
+ setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
45
+ }, [current, state.value?.custom])
46
+ if (state.status === 'unavailable') return null
47
+ const busy = state.status === 'loading' || saving
48
+ const label = busy ? t('status.loading') : t(`profile.${current}`)
49
+ return (
50
+ <div className={css.root}>
51
+ <Menu
52
+ open={open && contextCompressionAvailable}
53
+ onClose={() => { setOpen(false) }}
54
+ selectedId={current}
55
+ items={COMPRESSION_PROFILES.map(profile => ({
56
+ id: profile,
57
+ label: (
58
+ <span className={css.menuCopy}>
59
+ <span className={css.menuTitle}>{t(`profile.${profile}`)}</span>
60
+ <span className={css.menuDetail}>{t(`detail.${profile}`)}</span>
61
+ </span>
62
+ ),
63
+ }))}
64
+ onSelect={(id) => {
65
+ setOpen(false)
66
+ if (id === current || !COMPRESSION_PROFILES.includes(id as CompressionProfile)) return
67
+ setSaveError(null)
68
+ setSaving(true)
69
+ void select(id as CompressionProfile).then(
70
+ () => { setSaving(false) },
71
+ (error: unknown) => {
72
+ setSaving(false)
73
+ setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
74
+ },
75
+ )
76
+ }}
77
+ align="start"
78
+ portal
79
+ anchor={(
80
+ <button
81
+ type="button"
82
+ className={css.button}
83
+ aria-haspopup="menu"
84
+ aria-expanded={open && contextCompressionAvailable}
85
+ aria-describedby={contextCompressionAvailable ? undefined : unavailableId}
86
+ disabled={busy || !state.writable || !contextCompressionAvailable}
87
+ onClick={() => { setOpen(value => !value) }}
88
+ >
89
+ <span className={css.copy}>
90
+ <span className={css.label}>{t('label')}</span>
91
+ <span className={css.value}>{label}</span>
92
+ </span>
93
+ <IconChevronDownOutline14 className={css.chevron} />
94
+ </button>
95
+ )}
96
+ />
97
+ {contextCompressionAvailable ? null : (
98
+ <div id={unavailableId} className={css.unavailable} role="status">
99
+ {t('status.minimalUnavailable')}
100
+ </div>
101
+ )}
102
+ <div className={css.pricing}>{t('pricing.disclosure')}</div>
103
+ <div className={css.settingsHint}>
104
+ {t('autoCompact.summaryHint').replace('{percent}', String(state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default))}
105
+ </div>
106
+ {current !== 'custom' || showCustomEditor ? null : (
107
+ <div className={css.settingsHint}>{t('custom.settingsHint')}</div>
108
+ )}
109
+ {current !== 'custom' || draft === null || !showCustomEditor ? null : (
110
+ <CustomPolicyEditor
111
+ value={draft}
112
+ disabled={busy || !state.writable || !contextCompressionAvailable}
113
+ setValue={setDraft}
114
+ save={() => saveCustom(structuredClone(draft))}
115
+ reset={resetCustom}
116
+ settle={(operation) => {
117
+ setSaveError(null)
118
+ setSaving(true)
119
+ void operation().then(
120
+ () => { setSaving(false) },
121
+ (error: unknown) => {
122
+ setSaving(false)
123
+ setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
124
+ },
125
+ )
126
+ }}
127
+ t={t}
128
+ />
129
+ )}
130
+ {saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
131
+ </div>
132
+ )
133
+ }
134
+
135
+ interface AutoCompactThresholdControlsProps {
136
+ value: number
137
+ disabled: boolean
138
+ save: (thresholdPercent: number) => Promise<void>
139
+ settle: (operation: () => Promise<void>) => void
140
+ t: (key: ContextCompressionLocaleKey) => string
141
+ }
142
+
143
+ /**
144
+ * The authoritative Auto Compact threshold editor for the context-compression
145
+ * section. A typed number input and its save path are kept deliberately simple;
146
+ * values outside the recommended 70–85 band warn without blocking.
147
+ */
148
+ export function AutoCompactThresholdControls({ value, disabled, save, settle, t }: AutoCompactThresholdControlsProps) {
149
+ const [draft, setDraft] = useState(String(value))
150
+ useEffect(() => { setDraft(String(value)) }, [value])
151
+ const parsed = Number(draft)
152
+ // Number inputs legally produce value-equivalent drafts such as '8e1';
153
+ // only the parsed value needs to be a valid threshold.
154
+ const valid = isValidAutoCompactThresholdPercent(parsed)
155
+ const risk = !valid
156
+ ? 'autoCompact.invalid'
157
+ : parsed < 70 ? 'autoCompact.riskLow'
158
+ : parsed > 85 ? 'autoCompact.riskHigh'
159
+ : undefined
160
+ return (
161
+ <section className={css.autoCompact} aria-labelledby="context-compression-autocompact-title">
162
+ <h3 id="context-compression-autocompact-title" className={css.autoCompactTitle}>{t('autoCompact.title')}</h3>
163
+ <p className={css.customNote}>{t('autoCompact.description')}</p>
164
+ <label className={css.field}>
165
+ <span>{t('autoCompact.inputLabel')}</span>
166
+ <input
167
+ type="number"
168
+ value={draft}
169
+ min={AUTO_COMPACT_THRESHOLD_LIMITS.min}
170
+ max={AUTO_COMPACT_THRESHOLD_LIMITS.max}
171
+ step={AUTO_COMPACT_THRESHOLD_LIMITS.step}
172
+ disabled={disabled}
173
+ aria-invalid={!valid}
174
+ onChange={(event) => { setDraft(event.currentTarget.value) }}
175
+ />
176
+ </label>
177
+ {risk === undefined ? null : (
178
+ <div className={risk === 'autoCompact.invalid' ? css.error : css.autoCompactRisk} role={risk === 'autoCompact.invalid' ? 'alert' : 'note'}>
179
+ {t(risk)}
180
+ </div>
181
+ )}
182
+ <div className={css.actions}>
183
+ <button
184
+ type="button"
185
+ disabled={disabled || !valid || parsed === value}
186
+ onClick={() => { settle(() => save(parsed)) }}
187
+ >
188
+ {t('autoCompact.save')}
189
+ </button>
190
+ </div>
191
+ </section>
192
+ )
193
+ }
194
+
195
+ interface CodeSkeletonControlsProps {
196
+ value: boolean
197
+ disabled: boolean
198
+ save: (enabled: boolean) => Promise<void>
199
+ settle: (operation: () => Promise<void>) => void
200
+ t: (key: ContextCompressionLocaleKey) => string
201
+ }
202
+
203
+ /**
204
+ * The authoritative code-skeleton reducer gate for the context-compression
205
+ * section. Deliberately minimal — an on/off select plus its own save path —
206
+ * because the gate is orthogonal to every profile and carries no parameters.
207
+ */
208
+ interface IntentSummaryControlsProps {
209
+ value: boolean
210
+ disabled: boolean
211
+ save: (enabled: boolean) => Promise<void>
212
+ settle: (operation: () => Promise<void>) => void
213
+ t: (key: ContextCompressionLocaleKey) => string
214
+ }
215
+
216
+ /**
217
+ * The turn-tail intent summary fold gate. Same deliberately minimal shape as
218
+ * the code-skeleton gate: an on/off select with its own save path; the fold
219
+ * itself is gated by the growth constants and the per-session /ctx-summary
220
+ * override, none of which belong in this card.
221
+ */
222
+ export function IntentSummaryControls({ value, disabled, save, settle, t }: IntentSummaryControlsProps) {
223
+ return (
224
+ <section className={css.autoCompact} aria-labelledby="context-compression-intentsummary-title">
225
+ <h3 id="context-compression-intentsummary-title" className={css.autoCompactTitle}>{t('intentSummary.title')}</h3>
226
+ <p className={css.customNote}>{t('intentSummary.description')}</p>
227
+ <label className={css.field}>
228
+ <span>{t('intentSummary.enabled')}</span>
229
+ <select
230
+ value={value ? 'on' : 'off'}
231
+ disabled={disabled}
232
+ onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
233
+ >
234
+ <option value="on">{t('intentSummary.enabled.on')}</option>
235
+ <option value="off">{t('intentSummary.enabled.off')}</option>
236
+ </select>
237
+ </label>
238
+ </section>
239
+ )
240
+ }
241
+
242
+ interface MonitorPanelControlsProps {
243
+ value: boolean
244
+ disabled: boolean
245
+ save: (enabled: boolean) => Promise<void>
246
+ settle: (operation: () => Promise<void>) => void
247
+ t: (key: ContextCompressionLocaleKey) => string
248
+ }
249
+
250
+ /**
251
+ * Visibility switch of the floating compression-monitor panel (FAB). The
252
+ * panel itself is a body-level overlay driven by the monitor route; this card
253
+ * only decides whether it mounts.
254
+ */
255
+ export function MonitorPanelControls({ value, disabled, save, settle, t }: MonitorPanelControlsProps) {
256
+ return (
257
+ <section className={css.autoCompact} aria-labelledby="context-compression-monitorpanel-title">
258
+ <h3 id="context-compression-monitorpanel-title" className={css.autoCompactTitle}>{t('monitorPanel.title')}</h3>
259
+ <p className={css.customNote}>{t('monitorPanel.description')}</p>
260
+ <label className={css.field}>
261
+ <span>{t('monitorPanel.enabled')}</span>
262
+ <select
263
+ value={value ? 'on' : 'off'}
264
+ disabled={disabled}
265
+ onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
266
+ >
267
+ <option value="on">{t('monitorPanel.enabled.on')}</option>
268
+ <option value="off">{t('monitorPanel.enabled.off')}</option>
269
+ </select>
270
+ </label>
271
+ </section>
272
+ )
273
+ }
274
+
275
+ export function CodeSkeletonControls({ value, disabled, save, settle, t }: CodeSkeletonControlsProps) {
276
+ return (
277
+ <section className={css.autoCompact} aria-labelledby="context-compression-codeskeleton-title">
278
+ <h3 id="context-compression-codeskeleton-title" className={css.autoCompactTitle}>{t('codeSkeleton.title')}</h3>
279
+ <p className={css.customNote}>{t('codeSkeleton.description')}</p>
280
+ <label className={css.field}>
281
+ <span>{t('codeSkeleton.enabled')}</span>
282
+ <select
283
+ value={value ? 'on' : 'off'}
284
+ disabled={disabled}
285
+ onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
286
+ >
287
+ <option value="on">{t('codeSkeleton.enabled.on')}</option>
288
+ <option value="off">{t('codeSkeleton.enabled.off')}</option>
289
+ </select>
290
+ </label>
291
+ </section>
292
+ )
293
+ }