@surfishs/dsh-prompt-enhance 0.0.8 → 0.1.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@surfishs/dsh-prompt-enhance",
3
3
  "description": "Prompt enhancement for the dsh web GUI: rewrite the composer draft into a well-structured prompt through the harness LLM service, preview the before/after, then fill back, copy, or undo. Original draft is always preserved.",
4
- "version": "0.0.8",
4
+ "version": "0.1.0",
5
5
  "author": "surfishs",
6
6
  "type": "module",
7
7
  "engines": {
@@ -20,7 +20,8 @@
20
20
  "./package.json": "./package.json",
21
21
  "./locale/en.json": "./locale/en.json",
22
22
  "./locale/zh.json": "./locale/zh.json",
23
- "./locale/*.json": "./locale/*.json"
23
+ "./locale/*.json": "./locale/*.json",
24
+ "./icon": "./icon.svg"
24
25
  },
25
26
  "dsh": {
26
27
  "engines": {
@@ -85,6 +86,7 @@
85
86
  "src",
86
87
  "cordis.patch.yml",
87
88
  "locale/*.json",
89
+ "icon.svg",
88
90
  "docs/images/**",
89
91
  "README.md",
90
92
  "README.en.md"
@@ -114,6 +116,7 @@
114
116
  "format:check": "prettier --check .",
115
117
  "test": "vitest run",
116
118
  "test:watch": "vitest",
119
+ "check:host-primitives": "node scripts/check-host-primitives.mjs",
117
120
  "prepublishOnly": "npm run build && npm test"
118
121
  },
119
122
  "publishConfig": {
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Admission control for every entry that can spend a model call: a
3
+ * sliding-window rate cap, a concurrency cap, and a consecutive-failure breaker.
4
+ *
5
+ * The composer route and the `/enhance` command reach the model through the same
6
+ * host process, so they must share ONE gate. Separate gates would let the
7
+ * command plane sidestep the caps the settings page advertises.
8
+ * @module dsh-prompt-enhance/admission
9
+ */
10
+
11
+ import type { EnhanceError, EnhanceErrorCode } from './shared/protocol'
12
+
13
+ /**
14
+ * Consecutive failed calls that trip the cool-down, and how long it lasts.
15
+ *
16
+ * The sliding window counts successful calls only, so a run of timeouts never
17
+ * burns the user's quota. That leaves one hole: a deterministic upstream
18
+ * failure — a wrong API key, a mistyped provider, a model the account cannot
19
+ * reach — fails in milliseconds, and a retry loop against such a failure is
20
+ * bounded only by the concurrency cap, i.e. barely at all. Three consecutive
21
+ * failures are enough to tell "the model is flaky" from "this route cannot
22
+ * work", so the gate pauses instead of hammering the provider.
23
+ */
24
+ export const FAILURE_STREAK_LIMIT = 3
25
+ export const FAILURE_COOLDOWN_MS = 30_000
26
+
27
+ /** Caps of one admission decision, read from the live configuration. */
28
+ export interface AdmissionLimits {
29
+ rateLimitPerMinute: number
30
+ maxConcurrent: number
31
+ }
32
+
33
+ /**
34
+ * How one admitted call ended, as the gate counts it.
35
+ *
36
+ * `neutral` exists for a failure that is NOT the route's fault — no model
37
+ * configured, an effort the route refuses — because counting it would trip the
38
+ * breaker and hide the actionable error behind a cool-down that blames the
39
+ * model. It releases the slot and records nothing, like a cancellation.
40
+ */
41
+ export type AdmissionOutcome = 'success' | 'failure' | 'aborted' | 'neutral'
42
+
43
+ /**
44
+ * Wire codes that mean "this route cannot work", not "the model flaked".
45
+ *
46
+ * Both fail locally in milliseconds without any model traffic, so retrying them
47
+ * costs nothing; the useful answer is the error itself ("configure a model",
48
+ * "pick another tier"), not a cool-down.
49
+ */
50
+ const NON_BREAKER_CODES: ReadonlySet<EnhanceErrorCode> = new Set(['unconfigured', 'effort-unsupported'])
51
+
52
+ /**
53
+ * Classify one settled call for {@link AdmissionGate.settle}.
54
+ *
55
+ * Both entries (the composer route and the /enhance command) call THIS function,
56
+ * so "which failures count" is decided in one place and cannot drift apart
57
+ * between them.
58
+ * @param aborted - whether the caller went away mid-flight.
59
+ * @param code - the wire error code of the failure.
60
+ * @returns the outcome to settle with.
61
+ */
62
+ export function breakerOutcome(aborted: boolean, code: EnhanceErrorCode): AdmissionOutcome {
63
+ if (aborted) return 'aborted'
64
+ return NON_BREAKER_CODES.has(code) ? 'neutral' : 'failure'
65
+ }
66
+
67
+ /** One admission answer. */
68
+ export type AdmissionDecision = { ok: true } | { ok: false; error: EnhanceError; retryAfterSeconds?: number }
69
+
70
+ /**
71
+ * One process-wide admission gate.
72
+ *
73
+ * The rate window counts SUCCESSFUL calls only: counting attempts would burn
74
+ * the user's window on a run of timeouts or upstream errors and lock them out
75
+ * right when the model recovers. The concurrency cap still bounds in-flight
76
+ * calls regardless of outcome, and a cancellation is neither a success nor a
77
+ * failure.
78
+ */
79
+ export class AdmissionGate {
80
+ private stamps: number[] = []
81
+ private active = 0
82
+ private failures = 0
83
+ private cooldownUntil = 0
84
+
85
+ /**
86
+ * Ask for a slot.
87
+ * @param now - epoch millis of the admission attempt.
88
+ * @param limits - the live caps.
89
+ * @returns the decision; a refusal carries the wire error, plus the
90
+ * advertised wait when the gate can predict one.
91
+ */
92
+ admit(now: number, limits: AdmissionLimits): AdmissionDecision {
93
+ // Failure breaker first: a host stuck on a broken route must refuse before
94
+ // spending a window slot, and the wait is advertised so the caller can say
95
+ // when to try again.
96
+ if (now < this.cooldownUntil) {
97
+ const retryAfterSeconds = Math.max(1, Math.ceil((this.cooldownUntil - now) / 1000))
98
+ return { ok: false, error: { code: 'cooldown', params: { retryAfterSeconds, failures: FAILURE_STREAK_LIMIT } }, retryAfterSeconds }
99
+ }
100
+ // Trim the window in one splice instead of a `while (shift)` loop: with the
101
+ // configured cap at 600 the worst case drops from O(N²) array shifts to a
102
+ // single O(N) relocation.
103
+ const cut = now - 60_000
104
+ let validFrom = 0
105
+ while (validFrom < this.stamps.length && (this.stamps[validFrom] ?? cut) < cut) validFrom++
106
+ if (validFrom > 0) this.stamps.splice(0, validFrom)
107
+ if (this.stamps.length >= limits.rateLimitPerMinute) {
108
+ // The window is bounded, so the oldest surviving stamp tells exactly when
109
+ // a slot frees up — advertise it instead of making the caller guess.
110
+ const oldest = this.stamps[0] ?? now
111
+ const retryAfterSeconds = Math.max(1, Math.ceil((60_000 - (now - oldest)) / 1000))
112
+ return { ok: false, error: { code: 'rate-limit', params: { limit: limits.rateLimitPerMinute, retryAfterSeconds } }, retryAfterSeconds }
113
+ }
114
+ // No retry-after here: a busy slot frees whenever some in-flight call
115
+ // settles, which is not a delay this gate can predict.
116
+ if (this.active >= limits.maxConcurrent) {
117
+ return { ok: false, error: { code: 'concurrency-limit', params: { max: limits.maxConcurrent } } }
118
+ }
119
+ this.active += 1
120
+ return { ok: true }
121
+ }
122
+
123
+ /**
124
+ * Release the slot one admitted call held and record how it ended.
125
+ * @param outcome - success, failure, or neither (a cancellation, or a neutral
126
+ * failure that is not the route's fault).
127
+ * @param now - epoch millis when the call settled.
128
+ */
129
+ settle(outcome: AdmissionOutcome, now: number): void {
130
+ if (this.active > 0) this.active -= 1
131
+ if (outcome === 'success') {
132
+ // Stamped at completion, not admission: a slow success still counts as
133
+ // one call, and failures never consume the window.
134
+ this.stamps.push(now)
135
+ this.failures = 0
136
+ return
137
+ }
138
+ if (outcome === 'failure') {
139
+ this.failures += 1
140
+ if (this.failures >= FAILURE_STREAK_LIMIT) {
141
+ this.cooldownUntil = now + FAILURE_COOLDOWN_MS
142
+ this.failures = 0
143
+ }
144
+ }
145
+ }
146
+ }
@@ -24,24 +24,30 @@ import { useSessionKey, serverSessionId } from './session-key'
24
24
  /** Props of the input.right entry: the InputZone owner share + session kit + locale seat. */
25
25
  export type EnhanceButtonProps = PropsRuntime<'conversation.input.right'> & PropsLocale<'dsh-prompt-enhance'>
26
26
 
27
+ /** Sentinel of {@link occurrenceCountOf} for a host that exposes no chip view. */
28
+ const OCCURRENCES_UNKNOWN = -1
29
+
27
30
  /**
28
- * Read the length of an optional array-shaped field out of the host's input
29
- * state.
31
+ * Read the composer's reference-chip count, or {@link OCCURRENCES_UNKNOWN} when
32
+ * the host state cannot answer.
33
+ *
34
+ * Why this is not a plain `Array.isArray(x) ? x.length : 0`: applying a result
35
+ * happens through `inputActions.setDraft`, which replaces the editor document
36
+ * with plain text. A command or file-reference chip is not text, so that write
37
+ * destroys it — irreversibly, and with no undo entry covering the chip. "The
38
+ * host did not tell us" is therefore not the same answer as "there are none":
39
+ * the guard below fails CLOSED on it.
30
40
  *
31
- * Attachment ids are part of the conversation input snapshot in the dsh lines
32
- * this plugin targets, but the field was RENAMED between generations
33
- * (`imageIds` on the 0.1.x line, `attachmentIds` from 0.2.0 on) and a slot host
34
- * is not obliged to expose either. Reading `.length` off a missing field throws
35
- * *during render* — which React answers by unmounting the whole slot entry
36
- * behind its error boundary, so the composer loses the button and the console
37
- * fills with a stack trace instead of a usable feature. Reading defensively
38
- * turns an absent or malformed field into "no such count", which only disables
39
- * the corresponding advisory guard; the enhancement itself still runs.
41
+ * Reading `.length` off a missing field was the original bug class here: it
42
+ * threw DURING RENDER and React unmounted the whole slot entry behind its error
43
+ * boundary. This reader keeps the defensive shape (never throws, never assumes
44
+ * a type) but hands the uncertainty to the guard instead of silently answering
45
+ * "zero".
40
46
  * @param value - the untrusted field.
41
- * @returns the array length, or 0 when the field is absent/not an array.
47
+ * @returns the chip count, or {@link OCCURRENCES_UNKNOWN} when unreadable.
42
48
  */
43
- function countOf(value: unknown): number {
44
- return Array.isArray(value) ? value.length : 0
49
+ function occurrenceCountOf(value: unknown): number {
50
+ return Array.isArray(value) ? value.length : OCCURRENCES_UNKNOWN
45
51
  }
46
52
 
47
53
  /**
@@ -65,7 +71,7 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
65
71
  const wireId = serverSessionId(sessionId)
66
72
  const draft = useInput((state: InputState) => stringOf((state as { draft?: unknown }).draft))
67
73
  const phase = useInput((state: InputState) => (state as { phase?: unknown }).phase)
68
- const occurrenceCount = useInput((state: InputState) => countOf((state as { occurrences?: unknown }).occurrences))
74
+ const occurrenceCount = useInput((state: InputState) => occurrenceCountOf((state as { occurrences?: unknown }).occurrences))
69
75
  const settings = useSyncExternalStore(subscribeClientSettings, getClientSettings)
70
76
  const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
71
77
  const rootRef = useRef<HTMLButtonElement | null>(null)
@@ -100,6 +106,15 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
100
106
  ui.openError(uiKey, source, { code: 'rejected', localized: message })
101
107
  return
102
108
  }
109
+ // Fail CLOSED on an unreadable chip view (see occurrenceCountOf): the
110
+ // fill-back writes plain text over the editor document, so a chip we
111
+ // cannot see is a chip we would destroy. Refusing is recoverable; the
112
+ // destroyed reference is not.
113
+ if (occurrenceCount === OCCURRENCES_UNKNOWN) {
114
+ const unknown = t('error.chipsUnknown')
115
+ ui.openError(uiKey, source, { code: 'rejected', localized: unknown })
116
+ return
117
+ }
103
118
  if (occurrenceCount > 0) {
104
119
  const occurrences = t('error.occurrences')
105
120
  ui.openError(uiKey, source, { code: 'rejected', localized: occurrences })
@@ -166,6 +181,10 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
166
181
  <button
167
182
  ref={rootRef}
168
183
  type="button"
184
+ // Session anchor for the dock entries this plugin renders: the composer
185
+ // card has to be found per session, and this button lives inside it.
186
+ // Read by useDockAlignment (same attribute constant).
187
+ data-dsh-pe-key={uiKey}
169
188
  className={`dsh-pe-btn${busy ? ' is-busy' : ''}${otherBusy && !empty ? ' is-blocked' : ''}${empty && !busy ? ' is-empty' : ''}`}
170
189
  title={busy ? t('button.busy') : otherBusy ? t('button.otherBusy') : empty ? t('button.emptyTitle') : t('button.title')}
171
190
  aria-label={busy ? t('button.busy') : otherBusy ? t('button.otherBusy') : empty ? t('button.emptyTitle') : t('button.title')}
@@ -25,7 +25,7 @@ export function ResultDock(props: ResultDockProps): ReactNode {
25
25
  // host id for UI keying when present, else a stable per-mount fallback.
26
26
  const uiKey = useSessionKey(sessionId, inputActions)
27
27
  const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
28
- const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey)
28
+ const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey, uiKey)
29
29
  const [undone, setUndone] = useState(false)
30
30
  const [regenerated, setRegenerated] = useState(false)
31
31
  const [pendingRegenerate, setPendingRegenerate] = useState(false)
@@ -1,9 +1,16 @@
1
1
  /**
2
- * The composer mark: the DeepSeek fish with the two-star sparkle tucked into
3
- * its upper-left corner. The fish is the brand path used by the Harness
4
- * bundles; the star is the NovelAI-style enhance mark. Both are painted with
5
- * currentColor so the icon follows the button's label color, and the busy
6
- * state pulses the whole mark instead of swapping glyphs.
2
+ * The composer mark: the DeepSeek fish with a four-point sparkle at its
3
+ * upper-left corner. The fish is the brand path used by the Harness bundles; the
4
+ * star is the NovelAI-style enhance mark. Both are painted with currentColor so
5
+ * the icon follows the button's label color, and the busy state pulses the whole
6
+ * mark instead of swapping glyphs.
7
+ *
8
+ * The arrangement is the one approved for the plugin icon: the star is larger and
9
+ * sits further outside the whale, so the two shapes stop crowding each other.
10
+ * `icon.svg` draws the same arrangement at 1.2027, bounding-box centred, so its
11
+ * ink fills 94% of that 36-unit canvas; here the pair is scaled to 0.835 and
12
+ * shifted so the glyph keeps the 26x20 footprint and margins it had before,
13
+ * which is what keeps the button the same size. Change one, change the other.
7
14
  * @module dsh-prompt-enhance/client/SparkleFishIcon
8
15
  */
9
16
 
@@ -16,15 +23,23 @@ const FISH_PATH =
16
23
  /** A four-point star, used at the fish's upper-left corner. */
17
24
  const STAR_PATH = 'M5.715 0 L7.2 4.2 L11.43 5.715 L7.2 7.2 L5.715 11.43 L4.2 7.2 L0 5.715 L4.2 4.2 Z'
18
25
 
26
+ /**
27
+ * Placement of the two paths inside the 26x20 glyph box, derived from the
28
+ * approved A+C arrangement by a single 0.834684 scale plus the offset that keeps
29
+ * the ink box at its previous 1.20..24.68 x 0.81..17.74 position.
30
+ */
31
+ const FISH_TRANSFORM = 'translate(6.4976 4.3528) scale(0.78502)'
32
+ const STAR_TRANSFORM = 'translate(1.1944 0.7969) scale(0.60097)'
33
+
19
34
  /** A fish-plus-sparkle mark sized to its container. */
20
35
  export function SparkleFishIcon(props: { size?: number; spinning?: boolean }): ReactElement {
21
36
  const size = props.size ?? 15
22
37
  return (
23
38
  <svg width={size * 1.3} height={size} viewBox="0 0 26 20" fill="none" aria-hidden="true" focusable="false" style={{ display: 'block', flexShrink: 0 }}>
24
- <g transform="translate(5,3) scale(0.85)">
39
+ <g transform={FISH_TRANSFORM}>
25
40
  <path d={FISH_PATH} fill="currentColor" />
26
41
  </g>
27
- <path d={STAR_PATH} transform="translate(1.2,0.8) scale(0.55)" fill="currentColor" />
42
+ <path d={STAR_PATH} transform={STAR_TRANSFORM} fill="currentColor" />
28
43
  {props.spinning === true ? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" /> : null}
29
44
  </svg>
30
45
  )
@@ -43,7 +43,7 @@ export function UndoBar(props: UndoBarProps): ReactNode {
43
43
  // row takes over only after the card is closed.
44
44
  const panel = ui.getPanel()
45
45
  const visible = (panel === undefined || panel.sessionId !== uiKey) && entry !== undefined && entry.applied === draft
46
- const rootRef = useDockAlignment(visible)
46
+ const rootRef = useDockAlignment(visible, uiKey)
47
47
  if (!visible) return null
48
48
 
49
49
  const undo = (): void => {
@@ -103,6 +103,12 @@ function parseResult(value: unknown): EnhanceResult {
103
103
  model: record.model,
104
104
  elapsedMs: record.elapsedMs,
105
105
  ...(usage === undefined ? {} : { usage }),
106
+ // Carried explicitly, not optional-by-accident: the panel's "output hit
107
+ // the token cap" warning is driven by this flag alone, so rebuilding the
108
+ // object without it left the host setting it, the wire carrying it, and
109
+ // the UI never seeing it. Only `true` is ever normalized in, matching the
110
+ // host, which sets the field solely on a capped finish.
111
+ ...(record.truncated === true ? { truncated: true } : {}),
106
112
  }
107
113
  }
108
114
  throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed' } })
@@ -11,3 +11,6 @@
11
11
 
12
12
  /** Plugin version injected by the client build; `typeof`-guarded at use. */
13
13
  declare const __PLUGIN_VERSION__: string
14
+
15
+ /** Package name injected by the client build; `typeof`-guarded at use. */
16
+ declare const __PLUGIN_NAME__: string
@@ -42,8 +42,8 @@ export const zh = {
42
42
  'undo.dismiss': '关闭提示',
43
43
  'error.empty': '输入框为空,请先输入要增强的提示词。',
44
44
  'error.tooLong': '内容共 {count} 个字符,超过 {max} 个字符上限(按 Unicode 字符数统计,不是 token 数)。为避免改变原意不会自动截断,请精简后再试。',
45
- 'error.attachmentsOnly': '输入框只附加了附件(图片或文件),请补充要增强的文本。',
46
45
  'error.occurrences': '输入内容包含命令或文件引用,暂不支持增强;请先移除后再试。',
46
+ 'error.chipsUnknown': '无法读取输入框的引用状态(宿主未提供引用信息)。为避免覆盖已添加的命令或文件引用,本次增强已阻止;请清空输入框后输入纯文本草稿,或升级 DSH 后重试。',
47
47
  'error.phase': '当前输入正被占用(提交中),请稍后再试。',
48
48
  'error.disabled': '提示词增强已在插件设置中关闭。',
49
49
  'error.rejected': '增强请求被拒绝。',
@@ -141,7 +141,7 @@ export const zh = {
141
141
  'settings.strategy.extend': '追加在内置策略后',
142
142
  'settings.reasoning.inherit': '提供方默认',
143
143
  'settings.reasoning.loading': '正在读取该模型的档位…',
144
- 'settings.reasoning.unavailable': '无法读取该模型的档位,仅可跟随提供方默认。',
144
+ 'settings.reasoning.unavailable': '无法读取该模型的档位列表;已保存的档位仍会照常发送。',
145
145
  'settings.reasoning.noTiers': '该模型未声明推理档位,调用时将跟随提供方默认。',
146
146
  'settings.reasoning.unsupported': '当前值「{effort}」不在该模型支持的档位中。',
147
147
  'settings.reasoning.current': '当前值:{value}',
@@ -193,8 +193,9 @@ export const en: Record<PromptEnhanceKey, string> = {
193
193
  'undo.dismiss': 'Dismiss',
194
194
  'error.empty': 'The input box is empty — type a prompt to enhance first.',
195
195
  'error.tooLong': 'The draft is {count} characters, above the {max} cap (Unicode characters, not tokens). It is never auto-truncated (that would change your meaning) — please shorten it.',
196
- 'error.attachmentsOnly': 'The composer only has attachments; add the text you want enhanced.',
197
196
  'error.occurrences': 'The draft contains commands or file references, which are not supported yet — remove them first.',
197
+ 'error.chipsUnknown':
198
+ 'The composer reference state could not be read on this host, so the enhancement was blocked to avoid overwriting a command or file reference. Clear the input box and type plain text, or update DSH, then retry.',
198
199
  'error.phase': 'The input box is busy (submitting) — try again in a moment.',
199
200
  'error.disabled': 'Prompt enhance is disabled in the plugin settings.',
200
201
  'error.rejected': 'The enhance request was rejected.',
@@ -296,7 +297,7 @@ export const en: Record<PromptEnhanceKey, string> = {
296
297
  'settings.strategy.extend': 'Append after the built-in strategy',
297
298
  'settings.reasoning.inherit': 'Provider default',
298
299
  'settings.reasoning.loading': 'Reading this model’s tiers…',
299
- 'settings.reasoning.unavailable': 'Could not read this model’s tiers; only “follow provider default” is available.',
300
+ 'settings.reasoning.unavailable': 'Could not read this model’s tier list; your saved tier is still sent.',
300
301
  'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls follow the provider default.',
301
302
  'settings.reasoning.unsupported': 'The current value “{effort}” is not one of this model’s tiers.',
302
303
  'settings.reasoning.current': 'Current value: {value}',
@@ -39,7 +39,15 @@ export const SETTINGS_ROW_CONFIG_SLOT = 'plugins.row.config'
39
39
  export const SETTINGS_NAMESPACE = 'dsh-prompt-enhance'
40
40
 
41
41
  /** The bundle whose patch declares the row, and that row's id. */
42
- export const SETTINGS_BUNDLE = '@surfishs/dsh-prompt-enhance'
42
+ /**
43
+ * Package name of this bundle, injected by the client build from
44
+ * `package.json.name` (see `scripts/build.mjs`), exactly like the version.
45
+ * It must not be a literal: the plugin manager keys a row's config page as
46
+ * `<package name>#<row id>`, so a fork that renames the package would silently
47
+ * lose that page. The fallback is the shipped name, for environments that
48
+ * execute the source without the build (unit tests).
49
+ */
50
+ export const SETTINGS_BUNDLE = typeof __PLUGIN_NAME__ === 'string' ? __PLUGIN_NAME__ : '@surfishs/dsh-prompt-enhance'
43
51
  export const SETTINGS_ROW_ID = 'dsh-prompt-enhance'
44
52
 
45
53
  /**
@@ -1,9 +1,14 @@
1
1
  /**
2
2
  * Self-contained stylesheet, injected once as a <style> element: the plugin
3
3
  * ships no CSS build step, and class names are prefixed to stay collision
4
- * free inside the web shell. Colors are declared as panel-scoped variables
5
- * with a dark default and a light `prefers-color-scheme` override, so the
6
- * panel follows the OS/shell theme without depending on host theme internals.
4
+ * free inside the web shell.
5
+ *
6
+ * Colors resolve from the shell's own theme tokens (`--dsw-alias-*`) so the
7
+ * panel follows the application's light/dark switch. The literals after each
8
+ * comma are fallbacks for a host that exposes no tokens; `prefers-color-scheme`
9
+ * is deliberately NOT used, because the OS preference and the app's theme can
10
+ * disagree — that mismatch is exactly what left the panel dark inside a light
11
+ * shell.
7
12
  * @module dsh-prompt-enhance/client/styles
8
13
  */
9
14
 
@@ -14,16 +19,19 @@ export const CSS = `
14
19
  .dsh-pe-dock { width: 100%; }
15
20
  .dsh-pe-panel {
16
21
  box-sizing: border-box;
17
- --pe-bg: #1f2127;
18
- --pe-fg: #e6e8ee;
19
- --pe-fg-dim: rgba(230, 232, 238, 0.55);
20
- --pe-border: rgba(127, 127, 127, 0.35);
21
- --pe-separator: rgba(127, 127, 127, 0.25);
22
+ --pe-bg: var(--dsw-alias-bg-layer-1, #1f2127);
23
+ --pe-fg: var(--dsw-alias-label-primary, #e6e8ee);
24
+ --pe-fg-dim: var(--dsw-alias-label-secondary, rgba(230, 232, 238, 0.55));
25
+ --pe-border: var(--dsw-alias-border-l2, rgba(127, 127, 127, 0.35));
26
+ --pe-separator: var(--dsw-alias-border-l1, rgba(127, 127, 127, 0.25));
27
+ /* No hover token exists: a neutral grey alpha is already theme-agnostic. */
22
28
  --pe-hover: rgba(127, 127, 127, 0.18);
23
- --pe-danger: #ffb4a8;
24
- --pe-warn-fg: #e8c07d;
25
- --pe-warn-border: rgba(230, 158, 60, 0.35);
26
- --pe-warn-bg: rgba(230, 158, 60, 0.12);
29
+ --pe-danger: var(--dsw-alias-state-error-primary, #ffb4a8);
30
+ --pe-warn-fg: var(--dsw-alias-state-warn-primary, #e8c07d);
31
+ /* Tints of the themed warning color, so the banner cannot keep an amber cast
32
+ from the other scheme. */
33
+ --pe-warn-border: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #e8c07d) 35%, transparent);
34
+ --pe-warn-bg: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #e8c07d) 12%, transparent);
27
35
  display: flex;
28
36
  flex-direction: column;
29
37
  width: 100%;
@@ -35,20 +43,6 @@ export const CSS = `
35
43
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05);
36
44
  overflow: hidden;
37
45
  }
38
- @media (prefers-color-scheme: light) {
39
- .dsh-pe-panel {
40
- --pe-bg: #ffffff;
41
- --pe-fg: #1c1e24;
42
- --pe-fg-dim: rgba(28, 30, 36, 0.55);
43
- --pe-border: rgba(0, 0, 0, 0.18);
44
- --pe-separator: rgba(0, 0, 0, 0.12);
45
- --pe-hover: rgba(0, 0, 0, 0.08);
46
- --pe-danger: #a63a2e;
47
- --pe-warn-fg: #8a5a00;
48
- --pe-warn-border: rgba(176, 122, 0, 0.4);
49
- --pe-warn-bg: rgba(230, 158, 60, 0.15);
50
- }
51
- }
52
46
  .dsh-pe-head {
53
47
  display: flex;
54
48
  align-items: center;
@@ -140,7 +134,7 @@ export const CSS = `
140
134
  .dsh-pe-spin.small { width: 11px; height: 11px; border-width: 1px; }
141
135
  .dsh-pe-spin {
142
136
  width: 22px; height: 22px; border-radius: 50%;
143
- border: 2px solid var(--pe-separator); border-top-color: #6ea8ff;
137
+ border: 2px solid var(--pe-separator); border-top-color: var(--dsw-alias-brand-primary, #6ea8ff);
144
138
  animation: dsh-pe-spin 0.9s linear infinite;
145
139
  }
146
140
  .dsh-pe-foot {
@@ -171,10 +165,20 @@ export const CSS = `
171
165
  .dsh-pe-btn-action.primary {
172
166
  min-width: 112px;
173
167
  border-color: transparent;
174
- background: #3f76e1;
175
- color: #fff;
168
+ /* Fill and label are a PAIR: the alias layer flips brand-primary from
169
+ near-black (light theme) to near-white (dark theme), so the label has to
170
+ flip with it — a hardcoded foreground turns the dark theme into
171
+ white-on-white. label-primary-inverted is the color the shell itself
172
+ paints onto an inverted surface; the fallback chain keeps an inverted label
173
+ on hosts that predate that token. */
174
+ background: var(--dsw-alias-brand-primary, #3f76e1);
175
+ color: var(--dsw-alias-label-primary-inverted, var(--dsw-alias-bg-base, #ffffff));
176
+ }
177
+ .dsh-pe-btn-action.primary:hover {
178
+ /* Blend toward the panel surface, not toward white: in the dark theme white
179
+ IS the fill, so a white-ward blend would show no hover change at all. */
180
+ background: color-mix(in srgb, var(--dsw-alias-brand-primary, #3f76e1) 88%, var(--dsw-alias-bg-layer-1, #1f2127));
176
181
  }
177
- .dsh-pe-btn-action.primary:hover { background: #4d82ec; }
178
182
  .dsh-pe-btn-action.plain { background: transparent; color: inherit; }
179
183
  .dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
180
184
  .dsh-pe-btn-action.dsh-pe-copy { min-width: 96px; }