@keith9681/dsh-sidebar 0.15.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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/README_EN.md +0 -0
  4. package/cordis.patch.yml +49 -0
  5. package/lib/client-editor.js +34651 -0
  6. package/lib/client-mermaid.js +200629 -0
  7. package/lib/client-registry.js +13388 -0
  8. package/lib/client-terminal.js +8904 -0
  9. package/lib/client.js +13388 -0
  10. package/lib/index.js +3959 -0
  11. package/lib/invariant.js +22 -0
  12. package/lib/types/agent-pty.d.ts +226 -0
  13. package/lib/types/browser-probe.d.ts +15 -0
  14. package/lib/types/bundle-route.d.ts +12 -0
  15. package/lib/types/client/BrowserView.d.ts +22 -0
  16. package/lib/types/client/DiffTab.d.ts +6 -0
  17. package/lib/types/client/DiffView.d.ts +51 -0
  18. package/lib/types/client/EditorHost.d.ts +12 -0
  19. package/lib/types/client/FileTree.d.ts +36 -0
  20. package/lib/types/client/GitView.d.ts +8 -0
  21. package/lib/types/client/OrphanedTab.d.ts +11 -0
  22. package/lib/types/client/PdfView.d.ts +6 -0
  23. package/lib/types/client/RenderBoundary.d.ts +32 -0
  24. package/lib/types/client/SandboxStatusBar.d.ts +10 -0
  25. package/lib/types/client/SideCardSection.d.ts +74 -0
  26. package/lib/types/client/SideChatView.d.ts +16 -0
  27. package/lib/types/client/Sidebar.d.ts +6 -0
  28. package/lib/types/client/SubagentView.d.ts +16 -0
  29. package/lib/types/client/TabBar.d.ts +43 -0
  30. package/lib/types/client/TerminalView.d.ts +24 -0
  31. package/lib/types/client/TextEditor.d.ts +10 -0
  32. package/lib/types/client/TreePanel.d.ts +23 -0
  33. package/lib/types/client/UploadOverlay.d.ts +20 -0
  34. package/lib/types/client/add-plugin-modal.d.ts +15 -0
  35. package/lib/types/client/api.d.ts +268 -0
  36. package/lib/types/client/binary-download.d.ts +12 -0
  37. package/lib/types/client/breakpoints.d.ts +12 -0
  38. package/lib/types/client/browser.d.ts +50 -0
  39. package/lib/types/client/builtins/index.d.ts +18 -0
  40. package/lib/types/client/builtins/tabs.d.ts +11 -0
  41. package/lib/types/client/builtins/viewers.d.ts +3 -0
  42. package/lib/types/client/chunk-loader.d.ts +124 -0
  43. package/lib/types/client/chunks/editor.d.ts +9 -0
  44. package/lib/types/client/chunks/mermaid.d.ts +10 -0
  45. package/lib/types/client/chunks/terminal.d.ts +9 -0
  46. package/lib/types/client/cm-themes.d.ts +24 -0
  47. package/lib/types/client/conversation-draft.d.ts +14 -0
  48. package/lib/types/client/desktop-env.d.ts +35 -0
  49. package/lib/types/client/editable-state.d.ts +27 -0
  50. package/lib/types/client/editor-load.d.ts +66 -0
  51. package/lib/types/client/frame-batcher.d.ts +24 -0
  52. package/lib/types/client/icons.d.ts +57 -0
  53. package/lib/types/client/image-types.d.ts +3 -0
  54. package/lib/types/client/ime-guard.d.ts +36 -0
  55. package/lib/types/client/index.d.ts +19 -0
  56. package/lib/types/client/intercept.d.ts +33 -0
  57. package/lib/types/client/lang.d.ts +12 -0
  58. package/lib/types/client/lazy-chunk.d.ts +25 -0
  59. package/lib/types/client/link-intercept.d.ts +42 -0
  60. package/lib/types/client/locales.d.ts +366 -0
  61. package/lib/types/client/mermaid-blocks.d.ts +41 -0
  62. package/lib/types/client/mermaid-sanitize.d.ts +2 -0
  63. package/lib/types/client/mermaid.d.ts +12 -0
  64. package/lib/types/client/open-when-sized.d.ts +20 -0
  65. package/lib/types/client/open-with-settings.d.ts +4 -0
  66. package/lib/types/client/open-with.d.ts +87 -0
  67. package/lib/types/client/openpath-intercept.d.ts +41 -0
  68. package/lib/types/client/paths.d.ts +35 -0
  69. package/lib/types/client/pdf-types.d.ts +2 -0
  70. package/lib/types/client/plugin-settings.d.ts +8 -0
  71. package/lib/types/client/plugins-shared.d.ts +27 -0
  72. package/lib/types/client/plugins-tabs.d.ts +3 -0
  73. package/lib/types/client/plugins-viewers.d.ts +3 -0
  74. package/lib/types/client/prefs.d.ts +41 -0
  75. package/lib/types/client/produced-files.d.ts +23 -0
  76. package/lib/types/client/selection-payload.d.ts +27 -0
  77. package/lib/types/client/service.d.ts +440 -0
  78. package/lib/types/client/settings-nav-icon.d.ts +19 -0
  79. package/lib/types/client/shell-presets.d.ts +48 -0
  80. package/lib/types/client/sidechat-transcript.d.ts +103 -0
  81. package/lib/types/client/split-pane.d.ts +30 -0
  82. package/lib/types/client/state.d.ts +359 -0
  83. package/lib/types/client/subagent-detect.d.ts +54 -0
  84. package/lib/types/client/subagent-jobs.d.ts +63 -0
  85. package/lib/types/client/tab-content-memo.d.ts +33 -0
  86. package/lib/types/client/terminal-font.d.ts +20 -0
  87. package/lib/types/client/theme.d.ts +45 -0
  88. package/lib/types/client/titlebar-strip.d.ts +23 -0
  89. package/lib/types/client/upload.d.ts +69 -0
  90. package/lib/types/client/wco.d.ts +47 -0
  91. package/lib/types/config.d.ts +64 -0
  92. package/lib/types/context-types.d.ts +603 -0
  93. package/lib/types/fs-operations.d.ts +28 -0
  94. package/lib/types/fs-search.d.ts +24 -0
  95. package/lib/types/fs-tree.d.ts +51 -0
  96. package/lib/types/git.d.ts +82 -0
  97. package/lib/types/html-route.d.ts +59 -0
  98. package/lib/types/index.d.ts +47 -0
  99. package/lib/types/invariant.d.ts +15 -0
  100. package/lib/types/jobs-routes.d.ts +45 -0
  101. package/lib/types/open-external.d.ts +24 -0
  102. package/lib/types/prefs-shared.d.ts +225 -0
  103. package/lib/types/pty-deps.d.ts +78 -0
  104. package/lib/types/pty-manager.d.ts +168 -0
  105. package/lib/types/sidechat-core.d.ts +172 -0
  106. package/lib/types/sidechat-routes.d.ts +30 -0
  107. package/lib/types/subagent-activity.d.ts +44 -0
  108. package/lib/types/subagent-live-route.d.ts +44 -0
  109. package/lib/types/tools.d.ts +31 -0
  110. package/lib/types/trust-fence.d.ts +24 -0
  111. package/lib/types/wire.d.ts +38 -0
  112. package/package.json +173 -0
  113. package/scripts/install.ps1 +289 -0
  114. package/scripts/install.sh +287 -0
  115. package/src/agent-pty.ts +527 -0
  116. package/src/browser-probe.ts +26 -0
  117. package/src/bundle-route.ts +129 -0
  118. package/src/client/BrowserView.tsx +253 -0
  119. package/src/client/DiffTab.tsx +110 -0
  120. package/src/client/DiffView.tsx +305 -0
  121. package/src/client/EditorHost.tsx +525 -0
  122. package/src/client/FileTree.tsx +653 -0
  123. package/src/client/GitView.tsx +558 -0
  124. package/src/client/OrphanedTab.tsx +27 -0
  125. package/src/client/PdfView.tsx +110 -0
  126. package/src/client/RenderBoundary.tsx +49 -0
  127. package/src/client/SandboxStatusBar.tsx +60 -0
  128. package/src/client/SideCardSection.module.css +960 -0
  129. package/src/client/SideCardSection.tsx +1152 -0
  130. package/src/client/SideChatView.module.css +437 -0
  131. package/src/client/SideChatView.tsx +644 -0
  132. package/src/client/Sidebar.tsx +1148 -0
  133. package/src/client/SubagentView.module.css +547 -0
  134. package/src/client/SubagentView.tsx +883 -0
  135. package/src/client/TabBar.tsx +305 -0
  136. package/src/client/TerminalView.tsx +383 -0
  137. package/src/client/TextEditor.tsx +500 -0
  138. package/src/client/TreePanel.tsx +273 -0
  139. package/src/client/UploadOverlay.tsx +62 -0
  140. package/src/client/add-plugin-modal.tsx +199 -0
  141. package/src/client/api.ts +335 -0
  142. package/src/client/binary-download.tsx +23 -0
  143. package/src/client/breakpoints.ts +51 -0
  144. package/src/client/browser.ts +119 -0
  145. package/src/client/builtins/index.ts +37 -0
  146. package/src/client/builtins/tabs.tsx +331 -0
  147. package/src/client/builtins/viewers.tsx +125 -0
  148. package/src/client/chunk-loader.ts +351 -0
  149. package/src/client/chunks/editor.tsx +9 -0
  150. package/src/client/chunks/mermaid.tsx +10 -0
  151. package/src/client/chunks/terminal.tsx +9 -0
  152. package/src/client/cm-themes.ts +129 -0
  153. package/src/client/conversation-draft.ts +29 -0
  154. package/src/client/css-modules.d.ts +5 -0
  155. package/src/client/desktop-env.ts +72 -0
  156. package/src/client/editable-state.ts +70 -0
  157. package/src/client/editor-load.ts +92 -0
  158. package/src/client/frame-batcher.ts +56 -0
  159. package/src/client/icons.tsx +161 -0
  160. package/src/client/image-types.ts +8 -0
  161. package/src/client/ime-guard.ts +47 -0
  162. package/src/client/index.tsx +369 -0
  163. package/src/client/intercept.tsx +110 -0
  164. package/src/client/lang.ts +103 -0
  165. package/src/client/layout.css +94 -0
  166. package/src/client/lazy-chunk.tsx +89 -0
  167. package/src/client/link-intercept.ts +73 -0
  168. package/src/client/locales.ts +734 -0
  169. package/src/client/mermaid-blocks.ts +110 -0
  170. package/src/client/mermaid-sanitize.ts +93 -0
  171. package/src/client/mermaid.tsx +401 -0
  172. package/src/client/open-when-sized.ts +43 -0
  173. package/src/client/open-with-settings.tsx +135 -0
  174. package/src/client/open-with.ts +221 -0
  175. package/src/client/openpath-intercept.ts +62 -0
  176. package/src/client/paths.ts +47 -0
  177. package/src/client/pdf-types.ts +4 -0
  178. package/src/client/plugin-settings.ts +43 -0
  179. package/src/client/plugins-shared.ts +29 -0
  180. package/src/client/plugins-tabs.ts +87 -0
  181. package/src/client/plugins-viewers.ts +30 -0
  182. package/src/client/prefs.ts +207 -0
  183. package/src/client/produced-files.ts +91 -0
  184. package/src/client/selection-payload.ts +86 -0
  185. package/src/client/service.ts +838 -0
  186. package/src/client/settings-nav-icon.ts +45 -0
  187. package/src/client/shell-presets.ts +83 -0
  188. package/src/client/sidebar.module.css +2577 -0
  189. package/src/client/sidechat-transcript.ts +321 -0
  190. package/src/client/split-pane.tsx +322 -0
  191. package/src/client/state.ts +1175 -0
  192. package/src/client/subagent-detect.ts +137 -0
  193. package/src/client/subagent-jobs.ts +161 -0
  194. package/src/client/tab-content-memo.ts +46 -0
  195. package/src/client/terminal-font.ts +28 -0
  196. package/src/client/theme.ts +110 -0
  197. package/src/client/titlebar-strip.ts +37 -0
  198. package/src/client/upload.ts +187 -0
  199. package/src/client/wco.ts +120 -0
  200. package/src/config.ts +155 -0
  201. package/src/context-types.ts +610 -0
  202. package/src/fs-operations.ts +99 -0
  203. package/src/fs-search.ts +86 -0
  204. package/src/fs-tree.ts +158 -0
  205. package/src/git.ts +244 -0
  206. package/src/html-route.ts +106 -0
  207. package/src/index.ts +1132 -0
  208. package/src/invariant.ts +32 -0
  209. package/src/jobs-routes.ts +257 -0
  210. package/src/open-external.ts +90 -0
  211. package/src/prefs-shared.ts +268 -0
  212. package/src/pty-deps.ts +240 -0
  213. package/src/pty-manager.ts +376 -0
  214. package/src/sidechat-core.ts +468 -0
  215. package/src/sidechat-routes.ts +344 -0
  216. package/src/subagent-activity.ts +91 -0
  217. package/src/subagent-live-route.ts +93 -0
  218. package/src/tools.ts +479 -0
  219. package/src/trust-fence.ts +77 -0
  220. package/src/wire.ts +100 -0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Client-side read of the user-facing "Side card" preferences. The host owns
3
+ * the namespace through the settings seam (in-process); the DSH settings RPC
4
+ * domain only serves allowlisted namespaces to configuration clients, so the
5
+ * client reads and writes THIS namespace through the plugin's own fenced
6
+ * /sidebar routes instead (api.settingsGet/settingsUpdate). Any failure
7
+ * (route rejected, namespace absent, a field of the wrong type, a value out
8
+ * of the contract range) falls back to the schema defaults — the side card
9
+ * must keep working exactly as composed when the settings surface is missing.
10
+ */
11
+ import type { api } from './api.ts';
12
+ import { clampTerminalFontSize, clampTitleBarStrip, clampWidthPercent, SIDEBAR_PREFS_DEFAULTS, TITLE_BAR_SCHEMES, TITLE_BAR_STRIP_DEFAULT, type SidebarPrefs, type TitleBarScheme } from '../prefs-shared.ts';
13
+ export { SIDEBAR_PREFS_DEFAULTS, TITLE_BAR_SCHEMES, TITLE_BAR_STRIP_DEFAULT, clampTerminalFontSize, clampTitleBarStrip, clampWidthPercent, };
14
+ export type { SidebarPrefs, TitleBarScheme };
15
+ /** The settings wire face the preferences need (a subset of the plugin api). */
16
+ export type SidebarSettingsClient = Pick<typeof api, 'settingsGet' | 'settingsUpdate'>;
17
+ /** Validate one raw resolved value into {@link SidebarPrefs}. Used for the
18
+ * settings.get payload AND the settings.update response (both carry the
19
+ * layered resolved value); any malformed field falls back to its default.
20
+ * @param value - the raw resolved section from the settings wire.
21
+ * @returns validated prefs (always well-formed).
22
+ */
23
+ export declare function parsePrefs(value: unknown): SidebarPrefs;
24
+ /**
25
+ * Read the resolved side card preferences through the plugin's settings route.
26
+ * @param settings - the settings wire face (the plugin api by default).
27
+ * @returns validated prefs, or the schema defaults when the route rejects,
28
+ * the namespace is absent, or a stored value violates the contract.
29
+ */
30
+ export declare function loadPrefs(settings: SidebarSettingsClient): Promise<SidebarPrefs>;
31
+ /**
32
+ * Read the external-disable flag from the same settings route: the
33
+ * dsh-web-ui family's aionui-panel provider choice. True only when the host
34
+ * resolved `aionui-panel.rightPanel` to 'aionui-panel' — while true the
35
+ * sidebar must not mount (the two right panels are mutually exclusive). Any
36
+ * failure (route rejected, aionui absent, malformed response) reads false,
37
+ * so a missing family never hides the sidebar.
38
+ * @param settings - the settings wire face (the plugin api by default).
39
+ * @returns the external-disable flag (false on any failure).
40
+ */
41
+ export declare function loadExternalDisable(settings: SidebarSettingsClient): Promise<boolean>;
@@ -0,0 +1,23 @@
1
+ /** Paths a tool-result view reports as produced, by render intent. */
2
+ export declare function producedPaths(view: unknown): readonly string[];
3
+ /**
4
+ * Files produced by the turn the assistant at `seq` closes. Accumulation
5
+ * resets on turn boundaries (a user message, or a node reporting a different
6
+ * turn number); paths keep first-seen order and appear once.
7
+ * @param nodes - snapshot nodes in surface order (structural, unknown-safe).
8
+ * @param seq - the closing assistant's seq (the render site's anchor).
9
+ * @returns produced paths; empty when the turn wrote nothing.
10
+ */
11
+ export declare function producedForClosing(nodes: readonly unknown[], seq: number): readonly string[];
12
+ /**
13
+ * Claim the turn-tail chain only when the closing turn produced files.
14
+ * @param owner - the turn-tail owner currency ({nodes, seq}).
15
+ * @returns produced paths as the matched value, or null to decline.
16
+ */
17
+ export declare function selectProducedFiles(owner: unknown): readonly string[] | null;
18
+ /**
19
+ * Resolve a (possibly relative) path against the session cwd for the sidebar.
20
+ * Absolute detection mirrors the host (see client/paths.isAbsolutePath):
21
+ * POSIX roots, drive letters and UNC shares must not be joined onto the cwd.
22
+ */
23
+ export declare function resolveSidebarPath(cwd: string | undefined, path: string): string;
@@ -0,0 +1,27 @@
1
+ /** Max inserted selection length (UTF-16 code units, i.e. JS `.length`). */
2
+ export declare const SELECTION_LIMIT = 500;
3
+ /** The source line span a selection maps to (1-based, inclusive). */
4
+ export interface SelectionLines {
5
+ start: number;
6
+ end: number;
7
+ }
8
+ /**
9
+ * The fence info line: `rel[:start[-end]]` — lines are omitted entirely
10
+ * when unknown (the preview reverse-search missed).
11
+ */
12
+ export declare function headerOf(path: string, cwd: string | undefined, lines?: SelectionLines): string;
13
+ /**
14
+ * The full text appended to the composer draft for one selection.
15
+ * Over the limit the content is dropped: the plain path line is the whole
16
+ * payload (an empty fenced block would just occupy the draft).
17
+ */
18
+ export declare function buildSelectionInsert(path: string, cwd: string | undefined, lines: SelectionLines | undefined, selected: string): string;
19
+ /**
20
+ * Reverse-map a rendered-DOM selection back to source line numbers. The
21
+ * preview selection is plain text (block boundaries come out as `\n`), so
22
+ * this is a best-effort substring search: a single trailing newline is
23
+ * stripped first (DOM block selections tend to carry one), and only an
24
+ * EXACTLY-ONE occurrence yields lines — an ambiguous or missing match
25
+ * returns null (the header then carries the path without line numbers).
26
+ */
27
+ export declare function linesOfSelection(source: string, selected: string): SelectionLines | null;
@@ -0,0 +1,440 @@
1
+ /**
2
+ * The BetterSidebar client service: a registry that external plugins use
3
+ * to contribute sidebar tab types and file previewers. The service is
4
+ * published to the cordis context as `ctx.betterSidebar` (see
5
+ * {@link ../context-types.ts}); consumers declare it in `inject` and call
6
+ * `registerTab` / `registerFileViewer`, both returning a disposer that
7
+ * cordis auto-invokes on fiber disposal (HMR-safe).
8
+ *
9
+ * Design notes:
10
+ * - The registry is synchronous-snapshot (Map + listener set) so React
11
+ * can read it through `useSyncExternalStore` without tearing.
12
+ * - `dedupeKey` unifies the three open-tab strategies the builtins used to
13
+ * hardcode: single-instance (`() => type`), per-path (`tab => tab.path`),
14
+ * and per-id (`tab => tab.id` for diff tabs whose id is change-derived).
15
+ * `single: true` is sugar for `dedupeKey: () => id`.
16
+ * - `createTab` lets a descriptor own tab instantiation (the terminal
17
+ * builtin uses it to mint `terminal:<n>` ids and bump `nextTerminal`).
18
+ * - `matchFileViewer` walks descriptors in priority order (desc, stable):
19
+ * per descriptor it tries `detect` first (when `head` bytes are given),
20
+ * then `exts`; `exts: []` is a catch-all that matches any path.
21
+ */
22
+ import type { ReactNode } from 'react';
23
+ import type { Context } from '../context-types.ts';
24
+ import { type SidebarSnapshot, type SidebarState, type SidebarStore, type SidebarTab } from './state.ts';
25
+ import type { SessionScope } from './api.ts';
26
+ import type { SidebarPrefs } from '../prefs-shared.ts';
27
+ /**
28
+ * Public state vocabulary re-exported for consumers (type-only; the values
29
+ * stay internal). External plugins name these types in their descriptors —
30
+ * e.g. `dedupeKey: (tab: SidebarTab) => tab.id`, `createTab: (state: SidebarState) => …`,
31
+ * or `badge: (…, state: SidebarState) => …`.
32
+ */
33
+ export type { SidebarTab, SidebarState, SidebarStore, SidebarSnapshot, SidebarDiffRef, TabType, } from './state.ts';
34
+ export type { SessionScope } from './api.ts';
35
+ export type { SidebarPrefs } from '../prefs-shared.ts';
36
+ /** The row control a declarative setting renders as in the settings popup. */
37
+ export type SidebarSettingToggleType = 'switch' | 'text' | 'number' | 'select';
38
+ /** One option of a `type: 'select'` setting row. */
39
+ export interface SidebarSettingSelectOption {
40
+ /** The value written to the setting key when this option is picked
41
+ * (JSON-serializable: string / number / boolean). */
42
+ value: string | number | boolean;
43
+ /** Option title (i18n friendly: string or () => string). */
44
+ title: string | (() => string);
45
+ /** Option description (i18n friendly); rendered under the title in the
46
+ * icon dropdown. */
47
+ desc?: string | (() => string);
48
+ /** Option icon: when ANY option declares one, the dropdown renders
49
+ * big-icon option cards and the closed control shows the selected
50
+ * option's icon too; without icons both are a single line of text. */
51
+ icon?: ReactNode | ((size: number) => ReactNode);
52
+ }
53
+ /** One declarative setting of a tab/viewer, rendered as a nested row in the
54
+ * Side card settings page (e.g. the Subagent page's "auto-open when a
55
+ * subagent appears" switch, or the terminal's custom font rows). `type`
56
+ * selects the control: 'switch' (default) renders the custom switch,
57
+ * 'text' a free-form input committed on blur/Enter, 'number' a numeric
58
+ * input clamped to `min`/`max`, 'select' a dropdown over the declared
59
+ * `options` (single-pick writes the option's value; `multi: true` writes
60
+ * the array of picked values and defaults to false). */
61
+ export interface SidebarSettingToggle {
62
+ /** The SidebarPrefs field this toggle reads and writes ('autoOpenSubagent'). */
63
+ key: string;
64
+ /** Row title (i18n friendly: string or () => string). */
65
+ title: string | (() => string);
66
+ /** Row description (i18n friendly). */
67
+ desc?: string | (() => string);
68
+ /** Row control type; defaults to 'switch' (backward compatible). */
69
+ type?: SidebarSettingToggleType;
70
+ /** Lower bound for `type: 'number'` rows (clamped on commit). */
71
+ min?: number;
72
+ /** Upper bound for `type: 'number'` rows (clamped on commit). */
73
+ max?: number;
74
+ /** Input placeholder for `type: 'text'` rows. */
75
+ placeholder?: string;
76
+ /** Unit suffix rendered after the input (e.g. 'px' for a size row). */
77
+ unit?: string;
78
+ /** Options of a `type: 'select'` row. */
79
+ options?: readonly SidebarSettingSelectOption[];
80
+ /** Whether a `type: 'select'` row allows picking several options (the
81
+ * stored value is then an array of option values); defaults to false. */
82
+ multi?: boolean;
83
+ }
84
+ /** Props of a descriptor's custom settings panel (`settings.render`). */
85
+ export interface SidebarSettingsRenderProps {
86
+ store: SidebarStore;
87
+ service: BetterSidebarService;
88
+ prefs: SidebarPrefs;
89
+ /** This descriptor's own persisted settings blob (from `pluginSettings[id]`). */
90
+ pluginSettings: Record<string, unknown>;
91
+ /** Persist one plugin-owned setting of this descriptor. */
92
+ updatePluginSetting(key: string, value: unknown): void;
93
+ /** Close the settings popup. */
94
+ close(): void;
95
+ }
96
+ /** Declarative settings of one registered tab or file viewer. */
97
+ export interface SidebarSettingsDeclaration {
98
+ /**
99
+ * Extra settings rows rendered under the feature's own row in the
100
+ * settings page (only while the feature is enabled). Keys must be fields
101
+ * of the host's PrefsSchema (built-ins: 'autoOpenSubagent',
102
+ * 'agentTerminalTools', 'terminalFontFamily'); unknown keys are dropped
103
+ * by the settings seam.
104
+ */
105
+ toggles?: readonly SidebarSettingToggle[];
106
+ /**
107
+ * Plugin-owned settings rows (v0.12.0+): same row controls as `toggles`
108
+ * (switch/text/number), but the keys are plugin-local and persisted in
109
+ * the sidebar's own prefs document under `pluginSettings[<descriptor id>]`
110
+ * — no host PrefsSchema field needed. Values must be JSON-serializable
111
+ * (the row controls produce strings / numbers / booleans).
112
+ */
113
+ pluginToggles?: readonly SidebarSettingToggle[];
114
+ /**
115
+ * Custom settings panel (v0.12.0+): when given, the gear popup renders
116
+ * this instead of the row lists (`toggles` / `pluginToggles`). Receives
117
+ * the shared store/service, the live prefs, the descriptor's own
118
+ * `pluginSettings` blob, and a persistence helper.
119
+ */
120
+ render?: (props: SidebarSettingsRenderProps) => ReactNode;
121
+ }
122
+ /** Props every tab component receives (builtins and external alike). */
123
+ export interface TabComponentProps {
124
+ ctx: Context;
125
+ store: SidebarStore;
126
+ scope: SessionScope;
127
+ tab: SidebarTab;
128
+ /** Whether this tab is the active one AND the panel is open (live views pause otherwise). */
129
+ visible: boolean;
130
+ /** The explorer's expanded directory set (ExplorerView). */
131
+ expanded?: string[];
132
+ onToggleDir?: (path: string) => void;
133
+ onReferenceFile?: (path: string) => void;
134
+ onOpenFile?: (path: string) => void;
135
+ onOpenDiff?: (tab: SidebarTab) => void;
136
+ onSubagentJump?: (childSessionId: string) => void;
137
+ }
138
+ /** Describes one kind of sidebar tab (builtins register themselves too). */
139
+ export interface TabDescriptor {
140
+ /** Unique id; also the `SidebarTab.type` value (`'explorer'`, `'my-plugin:db'`). */
141
+ id: string;
142
+ title: string | (() => string);
143
+ icon?: ReactNode | ((size: number) => ReactNode);
144
+ /** + menu sort order (ascending); default 100. */
145
+ order?: number;
146
+ /** Hide from the + menu (the editor tab is opened by file-open, not by the menu). */
147
+ hidden?: boolean;
148
+ /**
149
+ * + menu disabled predicate (e.g. terminal at capacity). Receives the
150
+ * session scope and the live sidebar state (counts, expansions).
151
+ */
152
+ available?: (ctx: Context, scope: SessionScope, state: SidebarState) => boolean;
153
+ /**
154
+ * Single-instance sugar: `true` is shorthand for `dedupeKey: () => id`
155
+ * (opening the tab focuses an existing one of the same type instead of
156
+ * creating a duplicate). An explicit `dedupeKey` always wins when both
157
+ * are given. Builtins: explorer/git/subagent use `single: true`.
158
+ */
159
+ single?: boolean;
160
+ /**
161
+ * If provided, opening a tab whose `dedupeKey(tab)` matches an existing
162
+ * tab's key focuses the existing one instead of creating a new one.
163
+ * Returning `undefined` means "no dedup — always open a new tab".
164
+ * Builtins: editor uses `tab => tab.path`; diff uses `tab => tab.id`
165
+ * (openDiffTab mints change-derived ids).
166
+ */
167
+ dedupeKey?: (tab: SidebarTab) => string | undefined;
168
+ /**
169
+ * Custom tab creation (minting the `SidebarTab` and any state patches).
170
+ * Return `null` to refuse creation. The terminal builtin uses this to
171
+ * mint `terminal:<n>` ids and bump `nextTerminal`.
172
+ * When omitted, a default `{ id, type, title }` tab is created.
173
+ */
174
+ createTab?: (state: SidebarState) => {
175
+ tab: SidebarTab;
176
+ patch?: Partial<SidebarState>;
177
+ } | null;
178
+ /**
179
+ * External-link target claim (v0.13.0+): when a GUI external-link click
180
+ * is taken over (the `browserInterceptLinks` master AND the URL's
181
+ * protocol flag — `browserInterceptHttp` / `browserInterceptHttps` —
182
+ * are on), the first registered tab whose `urlTarget(url)` returns true
183
+ * is opened with `openTab({ type, url, title: hostname })` — the URL is
184
+ * the whole payload (the tab reads it from `tab.path`). Registration
185
+ * order wins (first claim first served); a disabled tab type is skipped;
186
+ * a throwing predicate is swallowed (console.error, the type is skipped).
187
+ * The built-in browser tab declares NO urlTarget — it stays the implicit
188
+ * fallback target, so plugins can never be shadowed by it. To host more
189
+ * than one URL at a time, mint per-URL ids through `createTab` (the
190
+ * browser builtin's pattern); otherwise the id safety net focuses the
191
+ * existing tab of the same type and the new URL is not applied.
192
+ */
193
+ urlTarget?: (url: URL) => boolean;
194
+ /**
195
+ * Declarative settings shown in the Side card settings page: every
196
+ * registered tab gets an enable/disable switch (icon + title + id), and
197
+ * `settings.toggles` adds nested switches tied to SidebarPrefs fields
198
+ * (e.g. the subagent tab's 'autoOpenSubagent').
199
+ */
200
+ settings?: SidebarSettingsDeclaration;
201
+ /**
202
+ * Tab-strip badge (v0.12.0+): a small pill rendered on the tab next to
203
+ * the icon — a number renders as a count (99+ capped), a string renders
204
+ * as-is, null/undefined hides the badge. Called on every tab-bar render,
205
+ * so keep it cheap; a throw is swallowed (no badge shown).
206
+ */
207
+ badge?: (ctx: Context, scope: SessionScope, state: SidebarState) => string | number | null | undefined;
208
+ /**
209
+ * Lifecycle callbacks (v0.12.0+). Fired by the SERVICE paths only:
210
+ * `onOpen` when an open actually creates a tab (a dedupe/id-safety-net
211
+ * focus is NOT an open — it fires `onActivate` instead), `onActivate`
212
+ * when a tab is focused (dedupe focus, id-safety-net focus, or the
213
+ * tab-bar activation), `onClose` when a tab is closed through
214
+ * `closeTab`. Builtin-only flows that mutate state directly (the diff
215
+ * split placement, agent-terminal reconcile) never touch external tabs
216
+ * and fire no callbacks. A throwing callback is logged and never breaks
217
+ * the open/close/activate flow.
218
+ */
219
+ onOpen?: (tab: SidebarTab, scope: SessionScope) => void;
220
+ onActivate?: (tab: SidebarTab, scope: SessionScope) => void;
221
+ onClose?: (tab: SidebarTab, scope: SessionScope) => void;
222
+ component: (props: TabComponentProps) => ReactNode;
223
+ }
224
+ /** How the host loads a file's bytes for one viewer. */
225
+ export type FileFetchStrategy = 'none' | 'fsRead' | 'mediaUrl' | 'custom' | 'binary-download';
226
+ /** Props every file viewer component receives. */
227
+ export interface FileViewerProps {
228
+ ctx: Context;
229
+ store: SidebarStore;
230
+ scope: SessionScope;
231
+ path: string;
232
+ title: string;
233
+ /** The matching descriptor's id (`'code'`, `'my-plugin:csv'`). */
234
+ viewerId: string;
235
+ /** fsRead text content (fetchStrategy='fsRead'). */
236
+ content?: string;
237
+ truncated?: boolean;
238
+ /** mediaUrl for the path (fetchStrategy='mediaUrl'). */
239
+ mediaUrl?: string;
240
+ /** custom load() return value (fetchStrategy='custom'). */
241
+ customData?: unknown;
242
+ /** Internal (built-in text editor): 'host' asks the viewer to skip its own
243
+ * toolbar row — the editor host's merged-mode header renders it instead,
244
+ * fed through the two callbacks below. Viewers that ignore these fields
245
+ * render exactly as before. */
246
+ toolbar?: 'self' | 'host';
247
+ /** Internal: the viewer reports its toolbar state (mode/dirty/save). */
248
+ onToolbarState?: (state: EditorToolbarState) => void;
249
+ /** Internal: the viewer registers its toolbar commands on mount (null on
250
+ * unmount). */
251
+ onToolbarControls?: (controls: EditorToolbarControls | null) => void;
252
+ }
253
+ /** The toolbar state a text editor reports to the host's merged-mode header. */
254
+ export interface EditorToolbarState {
255
+ /** Whether the preview/edit mode toggle applies (markdown/html). */
256
+ modes: boolean;
257
+ mode: 'preview' | 'edit';
258
+ dirty: boolean;
259
+ /** Whether saving applies (text content loaded). */
260
+ editable: boolean;
261
+ saveState: 'idle' | 'saving' | 'saved' | 'failed';
262
+ }
263
+ /** The commands the host's merged-mode header sends back to the viewer. */
264
+ export interface EditorToolbarControls {
265
+ setMode(mode: 'preview' | 'edit'): void;
266
+ save(): void;
267
+ }
268
+ /** Describes one file previewer (builtins register themselves too). */
269
+ export interface FileViewerDescriptor {
270
+ /** Unique id (`'image'`, `'pdf'`, `'my-plugin:csv'`). */
271
+ id: string;
272
+ /** Display name for the settings inventory (falls back to `id` when absent). */
273
+ title?: string | (() => string);
274
+ /** Icon shown in the settings inventory. */
275
+ icon?: ReactNode | ((size: number) => ReactNode);
276
+ /** Lowercase extensions without leading dot (`['png','jpg']`). `[]` = match any (catch-all). */
277
+ exts: readonly string[];
278
+ /** Higher wins; default 0. Builtins use 0; the catch-all `code` viewer uses -100. */
279
+ priority?: number;
280
+ fetchStrategy: FileFetchStrategy;
281
+ /**
282
+ * Content sniff: when `head` bytes are available the descriptor's `detect`
283
+ * is consulted before its `exts` (per-descriptor, in priority order).
284
+ */
285
+ detect?: (path: string, head: Uint8Array) => boolean;
286
+ /** fetchStrategy='custom' loader. `signal` (v0.12.0+) aborts on viewer
287
+ * teardown / re-match; loaders that ignore it keep working. */
288
+ load?: (path: string, scope: SessionScope, signal?: AbortSignal) => Promise<unknown>;
289
+ /**
290
+ * Declarative settings shown in the Side card settings page: every
291
+ * registered viewer gets an enable/disable switch (icon + title + exts).
292
+ */
293
+ settings?: SidebarSettingsDeclaration;
294
+ component: (props: FileViewerProps) => ReactNode;
295
+ }
296
+ /** One `openTab` request. */
297
+ export interface OpenTabSeed {
298
+ type: string;
299
+ /** Overrides the descriptor's title when given (the editor tab shows the file name). */
300
+ title?: string;
301
+ /** A file path (the editor tab's content seed). */
302
+ path?: string;
303
+ /** A diff reference (the diff tab's content seed). */
304
+ diff?: SidebarTab['diff'];
305
+ /** Explicit tab id (defaults to the type). */
306
+ id?: string;
307
+ /** A URL the tab navigates to on mount (the browser tab's seed). */
308
+ url?: string;
309
+ /** JSON-serializable custom state carried on the minted tab (persisted across reloads; v0.12.0+). */
310
+ meta?: unknown;
311
+ }
312
+ /**
313
+ * The registry service published as `ctx.betterSidebar`.
314
+ */
315
+ export interface BetterSidebarService {
316
+ registerTab(descriptor: TabDescriptor): () => void;
317
+ registerFileViewer(descriptor: FileViewerDescriptor): () => void;
318
+ getTabs(): readonly TabDescriptor[];
319
+ getFileViewers(): readonly FileViewerDescriptor[];
320
+ /** Find a tab descriptor by id (undefined if not registered). */
321
+ getTab(id: string): TabDescriptor | undefined;
322
+ /**
323
+ * Whether a tab type is enabled in the side card prefs. An absent
324
+ * `tabsEnabled[id]` entry means enabled — only an explicit `false`
325
+ * disables the type (hidden from the + menu, `openTab` refuses, and
326
+ * derived flows gate on it).
327
+ */
328
+ isTabEnabled(id: string): boolean;
329
+ /** Whether a file viewer is enabled (absent `viewersEnabled[id]` = enabled). */
330
+ isViewerEnabled(id: string): boolean;
331
+ /**
332
+ * Find a file viewer for a path (priority desc; detect first, then exts).
333
+ * Disabled viewers are skipped, so files fall through to the next match.
334
+ */
335
+ matchFileViewer(path: string, head?: Uint8Array): FileViewerDescriptor | undefined;
336
+ /**
337
+ * Open a tab (used by external tabs and the + menu). `title` overrides
338
+ * the descriptor's title when given (the editor tab shows the file name);
339
+ * when the descriptor provides `createTab` it mints the tab itself and
340
+ * `title`/`path`/`id` are ignored. `url` lands the tab with its `path`
341
+ * pre-set to the URL (the browser tab's navigation seed; the caller
342
+ * usually pairs it with a hostname `title`). A disabled tab type is a
343
+ * no-op.
344
+ *
345
+ * `scope` (v0.12.0+) targets a specific session: when given, the open
346
+ * lands in THAT session's sidebar state (loading it if it has none yet)
347
+ * without switching the UI's active session; when absent the open lands
348
+ * in the currently active session (the pre-0.12 behavior).
349
+ *
350
+ * A CONTENT open (a `path` or `url` seed) must land in sight: when the
351
+ * panel hosting the landing pane is collapsed, it is expanded
352
+ * automatically (the right panel by default, the bottom panel when the
353
+ * active pane lives there; on narrow viewports the merged drawer opens).
354
+ * Type-only opens (the + menu, agent-terminal auto-tabs) never expand —
355
+ * the panel behavior is their caller's business.
356
+ *
357
+ * Note: `available` gates the + menu's disabled state only — it does NOT
358
+ * refuse `openTab` (only the settings disable switch does).
359
+ */
360
+ openTab(seed: OpenTabSeed, scope?: SessionScope): void;
361
+ /**
362
+ * Close a tab by id (fires descriptor.onClose). An unknown tab id is a
363
+ * strict no-op (no state churn, no callbacks). `scope` (v0.12.0+) rides
364
+ * to the callback (its optional cwd included); absent, the callback gets
365
+ * `{ sessionId }` of the active session.
366
+ */
367
+ closeTab(tabId: string, scope?: SessionScope): void;
368
+ /** Subscribe to registry changes (register/dispose). */
369
+ subscribe(listener: () => void): () => void;
370
+ /** The plugin version this service instance was built from ('0.12.0'). */
371
+ readonly version: string;
372
+ /**
373
+ * Monotonic capability list (v0.12.0+): 'badge' | 'tabLifecycle' |
374
+ * 'updateTab' | 'openFile' | 'targetedOpen' | 'stateSubscription' |
375
+ * 'tabMeta' | 'pluginSettings'. Features are never removed — consumers
376
+ * gate new API usage on membership.
377
+ */
378
+ readonly features: readonly string[];
379
+ /**
380
+ * The current sidebar snapshot: the active session id, its state (panel
381
+ * geometry, open tabs, expansions), and the side card prefs (v0.12.0+).
382
+ * `state`/`sessionId` are undefined until a session becomes active.
383
+ */
384
+ getSnapshot(): SidebarSnapshot;
385
+ /** Subscribe to snapshot changes (session switch, state changes, prefs changes). Returns the disposer. */
386
+ subscribeState(listener: () => void): () => void;
387
+ /** Update an open tab's display fields (title / path / meta); a missing tab id is a no-op. */
388
+ updateTab(tabId: string, patch: {
389
+ title?: string;
390
+ path?: string;
391
+ meta?: unknown;
392
+ }): void;
393
+ /**
394
+ * Activate an open tab (the tab-bar activation path; fires
395
+ * descriptor.onActivate). An unknown tab id is a strict no-op. `scope`
396
+ * (v0.12.0+) rides to the callback like `closeTab`'s.
397
+ */
398
+ activateTab(tabId: string, scope?: SessionScope): void;
399
+ /** Open a file in the sidebar editor of `scope`'s session (title defaults to the file name). */
400
+ openFile(scope: SessionScope, path: string, title?: string): void;
401
+ }
402
+ /**
403
+ * Find the tab type that claims an intercepted external-link URL (v0.13.0+).
404
+ * Walks the descriptors in REGISTRATION order and returns the first one
405
+ * that declares `urlTarget` and matches `url`; a throwing predicate is
406
+ * swallowed (console.error, type skipped) so one broken plugin can never
407
+ * break the whole link pipeline. The caller passes the ENABLED tab
408
+ * descriptors (enablement is the caller's prefs domain — filter
409
+ * `service.getTabs()` through `tabsEnabled` before matching) and falls
410
+ * back to the built-in browser tab when nothing claims the URL (the
411
+ * browser never declares `urlTarget` itself, so it can never shadow a
412
+ * plugin claim).
413
+ */
414
+ export declare function matchUrlTarget(tabs: readonly TabDescriptor[], url: URL): TabDescriptor | undefined;
415
+ /**
416
+ * The plugin version this service instance reports. Keep in lockstep with
417
+ * `package.json`'s version — `tests/service.spec.ts` asserts the pair.
418
+ */
419
+ export declare const SIDEBAR_SERVICE_VERSION = "0.15.2";
420
+ /**
421
+ * Monotonic capability list consumers use to gate new API usage (features
422
+ * are never removed). Each string names a v0.12.0+ capability:
423
+ * - 'badge': TabDescriptor.badge
424
+ * - 'tabLifecycle': TabDescriptor.onOpen/onActivate/onClose
425
+ * - 'updateTab': BetterSidebarService.updateTab
426
+ * - 'openFile': BetterSidebarService.openFile
427
+ * - 'targetedOpen': BetterSidebarService.openTab(seed, scope?)
428
+ * - 'stateSubscription': getSnapshot/subscribeState
429
+ * - 'tabMeta': SidebarTab.meta (seeds, createTab, updateTab, persistence)
430
+ * - 'pluginSettings': SidebarSettingsDeclaration.pluginToggles/render
431
+ * - 'urlTarget' (v0.13.0): TabDescriptor.urlTarget (external-link claims)
432
+ * - 'settingSelect': SidebarSettingToggle type 'select' (options/multi)
433
+ */
434
+ export declare const SIDEBAR_FEATURES: readonly ["badge", "tabLifecycle", "updateTab", "openFile", "targetedOpen", "stateSubscription", "tabMeta", "pluginSettings", "urlTarget", "settingSelect"];
435
+ /**
436
+ * Create one BetterSidebar service bound to a store. The service owns the
437
+ * tab/viewer registries (Map + listener set) and proxies openTab/closeTab
438
+ * to the store's reducer. One instance per client plugin activation.
439
+ */
440
+ export declare function createBetterSidebarService(store: SidebarStore): BetterSidebarService;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Mark this plugin's row in the DSH settings navigation so its bundled CSS
3
+ * can replace the shell's fallback gear with the Side card glyph.
4
+ *
5
+ * DSH 0.1.x projects only `id`, `order`, and `label` from a
6
+ * `settings.section` registration, then chooses icons inside the settings
7
+ * shell from a closed list of built-in ids. Until that public contract grows
8
+ * an icon field, the plugin identifies only its own localized row after the
9
+ * dialog mounts. The marker owns no shell structure and is removed on fiber
10
+ * disposal, so the adaptation remains HMR-safe.
11
+ */
12
+ export declare const SETTINGS_NAV_MARKER = "data-dsh-better-sidebar-settings-nav";
13
+ /**
14
+ * Keep the marker on the settings-nav button whose visible text is this
15
+ * plugin's current localized section label.
16
+ * @param label - locale-aware label resolver used by the section registration.
17
+ * @returns disposer that disconnects observation and removes owned markers.
18
+ */
19
+ export declare function registerSettingsNavIcon(label: () => string): () => void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Built-in desktop-shell presets for the "位置兼容模式" secondary setting
3
+ * (scheme `preset`). DATA-DRIVEN by design: each shell's adaptation lives
4
+ * in one entry (strip values / optional CSS), the core applies it through
5
+ * the SAME generic strip variable and CSS-injection mechanism — adding a
6
+ * shell is adding data, never a code path.
7
+ *
8
+ * Inclusion rule (maintained in AGENTS.md §8): only shells that (a) appear
9
+ * in this repo's issues/PRs (a user actually hit a problem) and (b) have
10
+ * 100+ GitHub stars (a real user base). The mechanism is opt-in: auto
11
+ * detection never applies a preset — the settings badge only SUGGESTS it.
12
+ */
13
+ import type { DesktopEnv } from './desktop-env.ts';
14
+ export interface ShellPreset {
15
+ /** Stable preset id (persisted in `titleBarPresetId`). */
16
+ readonly id: string;
17
+ /** User-facing name of the shell. */
18
+ readonly title: string;
19
+ /** One-line description shown in the settings popup. */
20
+ readonly desc: string;
21
+ /**
22
+ * The top strip (px) this shell reserves over web content, per
23
+ * environment — the fallback used when neither the standard WCO API nor
24
+ * the `dsh-desktop-titlebar-inset` contract parameter is available.
25
+ * Return undefined when the shell needs no strip in that environment.
26
+ * MUST be pure (called during render).
27
+ */
28
+ readonly stripFor?: (env: DesktopEnv) => number | undefined;
29
+ /**
30
+ * Extra CSS applied while the preset is enabled (injected last, after the
31
+ * plugin's own styles). Targets the plugin's stable data attributes and
32
+ * shell-declared body/URL markers only — never other shells' class names.
33
+ * Empty for presets fully covered by the strip variable.
34
+ */
35
+ readonly css?: string;
36
+ /**
37
+ * Whether this shell's marker is currently visible (URL stamps / preload
38
+ * markers — see desktop-env.ts). Used ONLY for the settings "已检测"
39
+ * badge; never auto-applies anything. MUST be pure.
40
+ */
41
+ readonly detect?: (env: DesktopEnv) => boolean;
42
+ }
43
+ /** All built-in shell presets (registration order = settings list order). */
44
+ export declare function getShellPresets(): readonly ShellPreset[];
45
+ /** One preset by id, or undefined for an unknown/empty id. */
46
+ export declare function getShellPreset(id: string): ShellPreset | undefined;
47
+ /** The strip the active preset contributes for the given environment. */
48
+ export declare function presetStripFor(preset: ShellPreset | undefined, env: DesktopEnv): number | undefined;