@chatcode/cco-better-sidebar 0.18.0-alpha.4 → 0.18.0-rc.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.
Files changed (44) hide show
  1. package/README.md +3 -3
  2. package/README_EN.md +3 -3
  3. package/cordis.patch.yml +6 -5
  4. package/lib/client-editor.js +11140 -724
  5. package/lib/client-mermaid.js +10730 -317
  6. package/lib/client-registry.js +2258 -1652
  7. package/lib/client-terminal.js +257 -257
  8. package/lib/client.js +2254 -1648
  9. package/lib/index.js +61 -40
  10. package/lib/types/client/builtins/tabs.d.ts +9 -0
  11. package/lib/types/client/icons.d.ts +26 -8
  12. package/lib/types/client/service.d.ts +1 -1
  13. package/lib/types/config.d.ts +4 -3
  14. package/lib/types/context-types.d.ts +12 -14
  15. package/lib/types/prefs-shared.d.ts +1 -1
  16. package/lib/types/ui-tweaks/index.d.ts +2 -3
  17. package/package.json +1 -1
  18. package/src/client/BrowserView.tsx +1 -1
  19. package/src/client/DiffTab.tsx +1 -1
  20. package/src/client/EditorHost.tsx +1 -1
  21. package/src/client/FileTree.tsx +10 -5
  22. package/src/client/FreeWindow.tsx +2 -1
  23. package/src/client/GitView.tsx +7 -3
  24. package/src/client/SideCardSection.tsx +2 -8
  25. package/src/client/Sidebar.tsx +2 -2
  26. package/src/client/TabBar.tsx +2 -4
  27. package/src/client/TextEditor.tsx +2 -1
  28. package/src/client/TreePanel.tsx +1 -2
  29. package/src/client/UsageHeatmapSection.tsx +1 -1
  30. package/src/client/builtins/tabs.tsx +9 -2
  31. package/src/client/builtins/viewers.tsx +2 -1
  32. package/src/client/icons.tsx +57 -4
  33. package/src/client/intercept.tsx +1 -1
  34. package/src/client/md-toc.tsx +1 -1
  35. package/src/client/mermaid.tsx +2 -1
  36. package/src/client/open-with-settings.tsx +1 -1
  37. package/src/client/service.ts +1 -1
  38. package/src/client/ui-tweaks/branding.tsx +2 -2
  39. package/src/config.ts +22 -2
  40. package/src/context-types.ts +5 -15
  41. package/src/index.ts +22 -20
  42. package/src/prefs-shared.ts +1 -1
  43. package/src/ui-tweaks/config.ts +1 -1
  44. package/src/ui-tweaks/index.ts +7 -13
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { useLayoutEffect, useRef, useState } from 'react'
20
20
  import type { ReactNode } from 'react'
21
- import { IconListPenOutline16 } from '@deepseek-ai/dsh-client-ui-primitives'
21
+ import { IconListPenOutline16 } from './icons.tsx'
22
22
  import { t } from './locales.ts'
23
23
  import css from './sidebar.module.css'
24
24
 
@@ -28,7 +28,8 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState, type MouseEv
28
28
  import { createPortal } from 'react-dom'
29
29
  import { createRoot, type Root } from 'react-dom/client'
30
30
  import mermaid from 'mermaid'
31
- import { IconCopyOutline16, MarkdownText, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives'
31
+ import { MarkdownText, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives'
32
+ import { IconCopyOutline16 } from './icons.tsx'
32
33
  import { isDarkScheme, subscribeColorScheme } from './theme.ts'
33
34
  import { markdownTextProps } from './markdown-labels.tsx'
34
35
  import { t } from './locales.ts'
@@ -10,7 +10,7 @@
10
10
  * this component owns only its own section.
11
11
  */
12
12
  import { useState } from 'react'
13
- import { IconCloseOutline16 } from '@deepseek-ai/dsh-client-ui-primitives'
13
+ import { IconCloseOutline16 } from './icons.tsx'
14
14
  import {
15
15
  isValidCustomEditor,
16
16
  newCustomEditorId,
@@ -472,7 +472,7 @@ export function matchUrlTarget(tabs: readonly TabDescriptor[], url: URL): TabDes
472
472
  * The plugin version this service instance reports. Keep in lockstep with
473
473
  * `package.json`'s version — `tests/service.spec.ts` asserts the pair.
474
474
  */
475
- export const SIDEBAR_SERVICE_VERSION = '0.18.0-alpha.0'
475
+ export const SIDEBAR_SERVICE_VERSION = '0.18.0-alpha.4'
476
476
 
477
477
  /**
478
478
  * Monotonic capability list consumers use to gate new API usage (features
@@ -29,7 +29,7 @@ export const PROJECT_LOGO_URL = '/_dsh/ui-tweaks/assets/logo.svg'
29
29
  const PROJECT_NAME = 'ChatCode CLI'
30
30
  const HERO_TITLE = '与世界,深一度对话'
31
31
  const LEGACY_HOST_BRAND_TEXT = /DSH\s*(?:Local\s*Build|本地构建)|DeepSeek\s*Harness|ChatCode\s*CLI/giu
32
- const HOST_BRAND_LABEL_TEXT = /^(?:DSH\s*(?:Local\s*Build|本地构建)|ChatCode\s*CLI)$/iu
32
+ const LEGACY_HOST_BRAND_LABEL_TEXT = /^(?:DSH\s*(?:Local\s*Build|本地构建)|ChatCode\s*CLI)$/iu
33
33
  const HOST_BUILD_VERSION_TEXT = /^v?\d+\.\d+\.\d+(?:[-+][0-9a-z.-]+)*$/iu
34
34
  const HERO_HEADLINE = /探索未至之境/u
35
35
  const HERO_PREVIEW_TEXT = /^(?:预览版|Preview)$/iu
@@ -194,7 +194,7 @@ function syncBranding(): void {
194
194
  // The sidebar label identifies the precise icon to its left. Process it
195
195
  // before the generic text pass so the sibling relationship is still intact.
196
196
  document.querySelectorAll<HTMLElement>('body *').forEach((element) => {
197
- if (element.childElementCount !== 0 || !HOST_BRAND_LABEL_TEXT.test(element.textContent?.trim() ?? '')) return
197
+ if (element.childElementCount !== 0 || !LEGACY_HOST_BRAND_LABEL_TEXT.test(element.textContent?.trim() ?? '')) return
198
198
  if (element.textContent !== PROJECT_NAME) element.textContent = PROJECT_NAME
199
199
  element.classList.add('dut-brand-title')
200
200
  replaceLogoBesideBrandLabel(element)
package/src/config.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import z from 'schemastery'
9
+ import { Config as UITweaksSchema, type UITweaksConfig } from './ui-tweaks/config.ts'
9
10
  import {
10
11
  SIDEBAR_PREFS_DEFAULTS,
11
12
  SIDEBAR_PREFS_NS,
@@ -37,7 +38,7 @@ export {
37
38
  } from './prefs-shared.ts'
38
39
 
39
40
  /** Tunable sidebar host limits (every field optional; defaults fill in). */
40
- export interface SidebarConfig {
41
+ export interface SidebarConfig extends Partial<SidebarPrefs>, UITweaksConfig {
41
42
  /** Read cap of one text file (bytes); larger files return truncated. */
42
43
  readLimit?: number
43
44
  /** Media route cap (bytes); larger binaries are refused. */
@@ -88,7 +89,7 @@ export interface CodingPlanConfig {
88
89
  }
89
90
 
90
91
  /** Schemastery schema for the plugin configuration. */
91
- export const Config: z<SidebarConfig> = z.object({
92
+ const HostConfig = z.object({
92
93
  readLimit: z.number().step(1).min(1).default(512 * 1024),
93
94
  mediaLimit: z.number().step(1).min(1).default(20 * 1024 * 1024),
94
95
  uploadLimit: z.number().step(1).min(1).default(128 * 1024 * 1024),
@@ -205,3 +206,22 @@ export const PrefsSchema: z<SidebarPrefs> = z.object({
205
206
  // keys as unknown schema fields.
206
207
  pluginSettings: z.dict(z.dict(z.any())).default({}),
207
208
  })
209
+
210
+ function live<T>(schema: z<T>): z<T> {
211
+ Reflect.set(schema.meta, 'volatile', true)
212
+ return schema
213
+ }
214
+
215
+ function liveFields(schema: z): Record<string, z> {
216
+ if (schema.type !== 'object' || schema.dict === undefined) {
217
+ throw new TypeError('Live settings schema must be an object')
218
+ }
219
+ return Object.fromEntries(Object.entries(schema.dict).map(([key, field]) => [key, live(field)]))
220
+ }
221
+
222
+ /** One entry schema: deployment fields stay fixed while sidebar and UI preferences are live-editable. */
223
+ export const Config = z.object({
224
+ ...HostConfig.dict,
225
+ ...liveFields(PrefsSchema),
226
+ ...liveFields(UITweaksSchema),
227
+ }) as z<SidebarConfig>
@@ -446,22 +446,10 @@ export interface SidebarInvariantsService {
446
446
  ): () => void
447
447
  }
448
448
 
449
- /** The settings service face (mirror of @deepseek-ai/dsh-settings' SettingsProvider). */
449
+ /** The settings service face (mirror of @deepseek-ai/dsh-settings' SettingsForms). */
450
450
  export interface SidebarSettingsService {
451
- /**
452
- * Register one namespace schema (the resolved value layers schema defaults,
453
- * then the composition base, then the user document).
454
- */
455
- register<T>(
456
- ns: string,
457
- schema: unknown,
458
- options?: { base?: Partial<T>; applies?: 'live' | 'restart' },
459
- ): {
460
- get(): T
461
- watch(callback: (next: T, prev: T) => void | Promise<void>): () => void
462
- update(patch: object): Promise<void>
463
- replace(section: object): Promise<void>
464
- }
451
+ /** Whether the active profile accepts form edits. */
452
+ readonly writable: boolean
465
453
  /** Redacted descriptors of every registered namespace (secrets stripped). */
466
454
  describe(options?: { redactSecrets?: boolean }): Array<{
467
455
  ns: string
@@ -473,6 +461,8 @@ export interface SidebarSettingsService {
473
461
  }>
474
462
  /** Service-level merge write with the revision guard (a stale writer is refused). */
475
463
  update(ns: string, patch: object, expectedRevision?: number): Promise<void>
464
+ /** Apply path edits without restating fields hidden from the caller. */
465
+ mutate(ns: string, ops: readonly ({ op: 'set'; path: readonly string[]; value: unknown } | { op: 'unset'; path: readonly string[] })[], expectedRevision?: number): Promise<void>
476
466
  }
477
467
 
478
468
  /**
package/src/index.ts CHANGED
@@ -21,7 +21,6 @@ import { WebSocket, WebSocketServer } from 'ws'
21
21
  import type { Context, SidebarHttpRequest } from './context-types.ts'
22
22
  import {
23
23
  Config,
24
- PrefsSchema,
25
24
  resolveSidebarConfig,
26
25
  SIDEBAR_PREFS_DEFAULTS,
27
26
  SIDEBAR_PREFS_NS,
@@ -829,9 +828,8 @@ function buildApi(
829
828
  * {@link resolveSidebarConfig}.
830
829
  */
831
830
  export function apply(ctx: Context, config?: SidebarConfig): void {
832
- // dsh-ui-tweaks is embedded as an intact feature module. Its historical
833
- // settings namespace and /_dsh/ui-tweaks routes stay unchanged so existing
834
- // settings.yaml values and browser behavior carry over without migration.
831
+ // dsh-ui-tweaks is embedded as an intact feature module. Its routes stay
832
+ // unchanged while its live fields share this entry's generated settings form.
835
833
  // Cordis honours the root `inject` list in production. Keeping this guard
836
834
  // lets lightweight embedders that call apply() directly retain the sidebar
837
835
  // subset when they intentionally omit the settings service.
@@ -886,8 +884,8 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
886
884
  void codingPlanCatalogue.refresh().catch(() => { /* catalogue returns a safe unavailable snapshot */ })
887
885
 
888
886
  // ── User-facing "Side card" preferences ──────────────────────────────────
889
- // Register the namespace with the settings provider so the Settings page
890
- // (client half) can render and persist the new-conversation defaults. The
887
+ // The Settings page (client half) renders and persists the
888
+ // new-conversation defaults from this entry's volatile Config fields. The
891
889
  // DSH settings RPC domain (api-proxy) only serves allowlisted namespaces to
892
890
  // configuration clients, so the client reaches this namespace through the
893
891
  // plugin's own fenced routes below ('settings.get'/'settings.update'),
@@ -921,17 +919,7 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
921
919
  }
922
920
  }
923
921
  ctx.inject(['settings'], (sctx) => {
924
- // DSH 0.1.2-alpha.2 validates namespaces at compile time
925
- // (SettingsNamespaceInput); the 'dsh-better-sidebar' literal passes, so the
926
- // runtime helper this used to call (settingsNamespace) is gone upstream.
927
922
  const ns = SIDEBAR_PREFS_NS
928
- // The structural settings mirror types `schema` as unknown, so the
929
- // generic is not inferred here; the real service resolves it from the
930
- // schemastery schema (PrefsSchema) — narrow the owner scope explicitly.
931
- const scope = sctx.settings.register(ns, PrefsSchema) as {
932
- get(): SidebarPrefs
933
- watch(callback: (next: SidebarPrefs, prev: SidebarPrefs) => void): () => void
934
- }
935
923
  const viewOf = (): { value?: unknown; revision?: number } => {
936
924
  const descriptor = sctx.settings.describe({ redactSecrets: true }).find(candidate => candidate.ns === ns)
937
925
  return descriptor === undefined
@@ -957,6 +945,15 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
957
945
  return viewOf()
958
946
  },
959
947
  }
948
+ const scope = {
949
+ get: (): SidebarPrefs => {
950
+ const value = viewOf().value
951
+ return {
952
+ ...SIDEBAR_PREFS_DEFAULTS,
953
+ ...(typeof value === 'object' && value !== null ? value : {}),
954
+ } as SidebarPrefs
955
+ },
956
+ }
960
957
  // Register (or unregister) the terminal tools from the current setting,
961
958
  // and keep them in sync with every settings commit.
962
959
  syncToolsGate(scope)
@@ -988,10 +985,15 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
988
985
  }
989
986
  }
990
987
  syncOpenToolsGate()
991
- // ONE watch subscription drives both gates: settings commits re-evaluate
992
- // the terminal tools AND the open tool together (each gate is idempotent
993
- // and owns its own disposer).
994
- scope.watch(() => { syncToolsGate(scope); syncOpenToolsGate() })
988
+ // Volatile Config writes preserve the plugin fiber. Re-read the projected
989
+ // form after each Loader update so both gates track the committed values.
990
+ const updates = sctx as unknown as {
991
+ on(event: 'loader/volatile-update', listener: () => void): () => void
992
+ }
993
+ updates.on('loader/volatile-update', () => {
994
+ syncToolsGate(scope)
995
+ syncOpenToolsGate()
996
+ })
995
997
  })
996
998
 
997
999
  // ── JSON API ────────────────────────────────────────────────────────────
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  /** The user-settings namespace holding the side card preferences. */
10
- export const SIDEBAR_PREFS_NS = 'dsh-better-sidebar'
10
+ export const SIDEBAR_PREFS_NS = 'better-sidebar'
11
11
 
12
12
  /** User-facing side card preferences (new-conversation defaults). */
13
13
  export interface SidebarPrefs {
@@ -14,7 +14,7 @@ import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
14
14
  // `settingsNamespace()` was removed in DSH 0.1.2-alpha.2. Keep the opaque
15
15
  // namespace type for source compatibility with older DSH declarations, while
16
16
  // emitting the plain validated literal required by the current runtime.
17
- export const UI_TWEAKS_SETTINGS_NAMESPACE = 'ui-tweaks' as SettingsNamespace
17
+ export const UI_TWEAKS_SETTINGS_NAMESPACE = 'better-sidebar' as SettingsNamespace
18
18
 
19
19
  /** Raw user-facing configuration (partial inputs receive schema defaults). */
20
20
  export interface UITweaksConfig {
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * dsh-ui-tweaks — server half.
3
3
  *
4
- * Registers the `ui-tweaks` settings namespace so users can tune the
5
- * conversation UI either from the Settings panel or by editing the settings
6
- * document directly (settings.yaml `ui-tweaks:` section). All rendering work
4
+ * Uses the owning sidebar entry's live settings so users can tune the
5
+ * conversation UI from the Settings panel. All rendering work
7
6
  * happens in the browser bundle (`src/client`), which reads and writes this
8
7
  * namespace through the same-origin route mounted here — the Web settings RPC
9
8
  * only exposes a fixed allowlist of namespaces since rc.6, so a custom route is
@@ -12,11 +11,7 @@
12
11
  */
13
12
 
14
13
  import type { Context } from '@deepseek-ai/cordis'
15
- import {
16
- UI_TWEAKS_SETTINGS_NAMESPACE,
17
- Config,
18
- type UITweaksConfig,
19
- } from './config.ts'
14
+ import { UI_TWEAKS_SETTINGS_NAMESPACE, type UITweaksConfig } from './config.ts'
20
15
  import { installTurnOutcomeProjection } from './turn-outcome.ts'
21
16
  import { UITweaksWebBackend, installUITweaksWeb } from './web.ts'
22
17
  import { GitBackend } from './git.ts'
@@ -30,10 +25,6 @@ export const name = 'dsh-ui-tweaks'
30
25
  export const inject = ['settings']
31
26
 
32
27
  export function apply(ctx: Context): void {
33
- ctx.settings.register(UI_TWEAKS_SETTINGS_NAMESPACE, Config, {
34
- applies: 'live',
35
- })
36
-
37
28
  // The task notifier classifies turn endings (completed / aborted / failed)
38
29
  // through this session projection (same registration pattern as above).
39
30
  installTurnOutcomeProjection(ctx)
@@ -44,7 +35,10 @@ export function apply(ctx: Context): void {
44
35
 
45
36
  // The GitBar runs git in the session's working directory through these
46
37
  // same-origin routes (sessions/llm are optional services, duck-typed).
47
- const readConfig = (): UITweaksConfig => ctx.settings.get(UI_TWEAKS_SETTINGS_NAMESPACE) as UITweaksConfig
38
+ const readConfig = (): UITweaksConfig => {
39
+ const descriptor = ctx.settings.describe().find(candidate => candidate.ns === UI_TWEAKS_SETTINGS_NAMESPACE)
40
+ return descriptor?.value as UITweaksConfig | undefined ?? {}
41
+ }
48
42
  installGitWeb(ctx, new GitBackend(ctx, readConfig))
49
43
 
50
44
  // The Archive panel lists archived sessions and restores ("deletes") them