@lijian-ui/dsh-file-manager 0.1.20

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 (169) hide show
  1. package/LICENSE +38 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +66 -0
  4. package/README.zh.md +66 -0
  5. package/cordis.patch.yml +13 -0
  6. package/lib/assets/mermaid.min.js +3587 -0
  7. package/lib/client.js +7621 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/index.js +3207 -0
  10. package/lib/tsconfig.client.tsbuildinfo +1 -0
  11. package/lib/tsconfig.host.tsbuildinfo +1 -0
  12. package/lib/types/client/FileManagerSettingsCard.d.ts +56 -0
  13. package/lib/types/client/FileManagerSettingsCard.d.ts.map +1 -0
  14. package/lib/types/client/PluginSettingsCard.d.ts +104 -0
  15. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -0
  16. package/lib/types/client/api.d.ts +75 -0
  17. package/lib/types/client/api.d.ts.map +1 -0
  18. package/lib/types/client/chat/AttachedFilesDock.d.ts +51 -0
  19. package/lib/types/client/chat/AttachedFilesDock.d.ts.map +1 -0
  20. package/lib/types/client/chat/file-ref.d.ts +35 -0
  21. package/lib/types/client/chat/file-ref.d.ts.map +1 -0
  22. package/lib/types/client/chat/mermaid-chat.d.ts +30 -0
  23. package/lib/types/client/chat/mermaid-chat.d.ts.map +1 -0
  24. package/lib/types/client/chat/placeholder-hint.d.ts +16 -0
  25. package/lib/types/client/chat/placeholder-hint.d.ts.map +1 -0
  26. package/lib/types/client/components/ExplorerPanel.d.ts +26 -0
  27. package/lib/types/client/components/ExplorerPanel.d.ts.map +1 -0
  28. package/lib/types/client/components/FileIcon.d.ts +15 -0
  29. package/lib/types/client/components/FileIcon.d.ts.map +1 -0
  30. package/lib/types/client/components/ScmPanel.d.ts +23 -0
  31. package/lib/types/client/components/ScmPanel.d.ts.map +1 -0
  32. package/lib/types/client/components/a11y.d.ts +12 -0
  33. package/lib/types/client/components/a11y.d.ts.map +1 -0
  34. package/lib/types/client/components/icons.d.ts +41 -0
  35. package/lib/types/client/components/icons.d.ts.map +1 -0
  36. package/lib/types/client/components/overlay.d.ts +45 -0
  37. package/lib/types/client/components/overlay.d.ts.map +1 -0
  38. package/lib/types/client/drag/DragFileInlay.d.ts +31 -0
  39. package/lib/types/client/drag/DragFileInlay.d.ts.map +1 -0
  40. package/lib/types/client/drag/file-drag.d.ts +47 -0
  41. package/lib/types/client/drag/file-drag.d.ts.map +1 -0
  42. package/lib/types/client/drag.d.ts +31 -0
  43. package/lib/types/client/drag.d.ts.map +1 -0
  44. package/lib/types/client/file-source.d.ts +29 -0
  45. package/lib/types/client/file-source.d.ts.map +1 -0
  46. package/lib/types/client/fileType.d.ts +31 -0
  47. package/lib/types/client/fileType.d.ts.map +1 -0
  48. package/lib/types/client/floating.d.ts +27 -0
  49. package/lib/types/client/floating.d.ts.map +1 -0
  50. package/lib/types/client/hooks/useResizableSplit.d.ts +37 -0
  51. package/lib/types/client/hooks/useResizableSplit.d.ts.map +1 -0
  52. package/lib/types/client/hooks/useStore.d.ts +10 -0
  53. package/lib/types/client/hooks/useStore.d.ts.map +1 -0
  54. package/lib/types/client/index.d.ts +57 -0
  55. package/lib/types/client/index.d.ts.map +1 -0
  56. package/lib/types/client/layout.d.ts +104 -0
  57. package/lib/types/client/layout.d.ts.map +1 -0
  58. package/lib/types/client/locales.d.ts +125 -0
  59. package/lib/types/client/locales.d.ts.map +1 -0
  60. package/lib/types/client/maximize.d.ts +24 -0
  61. package/lib/types/client/maximize.d.ts.map +1 -0
  62. package/lib/types/client/mention.d.ts +44 -0
  63. package/lib/types/client/mention.d.ts.map +1 -0
  64. package/lib/types/client/mount.d.ts +22 -0
  65. package/lib/types/client/mount.d.ts.map +1 -0
  66. package/lib/types/client/persist.d.ts +55 -0
  67. package/lib/types/client/persist.d.ts.map +1 -0
  68. package/lib/types/client/picker/FilePickerModal.d.ts +47 -0
  69. package/lib/types/client/picker/FilePickerModal.d.ts.map +1 -0
  70. package/lib/types/client/picker/file-picker.d.ts +62 -0
  71. package/lib/types/client/picker/file-picker.d.ts.map +1 -0
  72. package/lib/types/client/preview/PreviewPanel.d.ts +17 -0
  73. package/lib/types/client/preview/PreviewPanel.d.ts.map +1 -0
  74. package/lib/types/client/preview/PreviewTabs.d.ts +30 -0
  75. package/lib/types/client/preview/PreviewTabs.d.ts.map +1 -0
  76. package/lib/types/client/preview/PreviewToolbar.d.ts +37 -0
  77. package/lib/types/client/preview/PreviewToolbar.d.ts.map +1 -0
  78. package/lib/types/client/preview/content.d.ts +43 -0
  79. package/lib/types/client/preview/content.d.ts.map +1 -0
  80. package/lib/types/client/preview/markdown.d.ts +60 -0
  81. package/lib/types/client/preview/markdown.d.ts.map +1 -0
  82. package/lib/types/client/preview/mermaid.d.ts +78 -0
  83. package/lib/types/client/preview/mermaid.d.ts.map +1 -0
  84. package/lib/types/client/preview/selection.d.ts +26 -0
  85. package/lib/types/client/preview/selection.d.ts.map +1 -0
  86. package/lib/types/client/reference.d.ts +75 -0
  87. package/lib/types/client/reference.d.ts.map +1 -0
  88. package/lib/types/client/settings-form.d.ts +206 -0
  89. package/lib/types/client/settings-form.d.ts.map +1 -0
  90. package/lib/types/client/store.d.ts +279 -0
  91. package/lib/types/client/store.d.ts.map +1 -0
  92. package/lib/types/core/types.d.ts +132 -0
  93. package/lib/types/core/types.d.ts.map +1 -0
  94. package/lib/types/host/fs-service.d.ts +96 -0
  95. package/lib/types/host/fs-service.d.ts.map +1 -0
  96. package/lib/types/host/gate.d.ts +45 -0
  97. package/lib/types/host/gate.d.ts.map +1 -0
  98. package/lib/types/host/git-runner.d.ts +80 -0
  99. package/lib/types/host/git-runner.d.ts.map +1 -0
  100. package/lib/types/host/git-service.d.ts +130 -0
  101. package/lib/types/host/git-service.d.ts.map +1 -0
  102. package/lib/types/host/loopback.d.ts +25 -0
  103. package/lib/types/host/loopback.d.ts.map +1 -0
  104. package/lib/types/host/poll-guard.d.ts +55 -0
  105. package/lib/types/host/poll-guard.d.ts.map +1 -0
  106. package/lib/types/host/routes.d.ts +54 -0
  107. package/lib/types/host/routes.d.ts.map +1 -0
  108. package/lib/types/index.d.ts +35 -0
  109. package/lib/types/index.d.ts.map +1 -0
  110. package/lib/types/mount-once.d.ts +25 -0
  111. package/lib/types/mount-once.d.ts.map +1 -0
  112. package/package.json +85 -0
  113. package/src/client/FileManagerSettingsCard.tsx +117 -0
  114. package/src/client/PluginSettingsCard.tsx +337 -0
  115. package/src/client/api.ts +141 -0
  116. package/src/client/chat/file-ref.ts +144 -0
  117. package/src/client/chat/mermaid-chat.tsx +102 -0
  118. package/src/client/chat/placeholder-hint.tsx +46 -0
  119. package/src/client/components/ExplorerPanel.tsx +534 -0
  120. package/src/client/components/FileIcon.tsx +46 -0
  121. package/src/client/components/ScmPanel.tsx +480 -0
  122. package/src/client/components/a11y.ts +20 -0
  123. package/src/client/components/icons.tsx +274 -0
  124. package/src/client/components/overlay.tsx +225 -0
  125. package/src/client/css-modules.d.ts +5 -0
  126. package/src/client/drag/DragFileInlay.tsx +89 -0
  127. package/src/client/drag/file-drag.ts +67 -0
  128. package/src/client/drag.ts +154 -0
  129. package/src/client/file-source.ts +58 -0
  130. package/src/client/fileType.ts +129 -0
  131. package/src/client/floating.ts +63 -0
  132. package/src/client/hooks/useResizableSplit.ts +91 -0
  133. package/src/client/hooks/useStore.ts +15 -0
  134. package/src/client/index.ts +389 -0
  135. package/src/client/layout.ts +546 -0
  136. package/src/client/locales.ts +247 -0
  137. package/src/client/maximize.ts +34 -0
  138. package/src/client/mount.tsx +74 -0
  139. package/src/client/persist.ts +194 -0
  140. package/src/client/picker/FilePickerModal.tsx +506 -0
  141. package/src/client/picker/file-picker.ts +86 -0
  142. package/src/client/preview/PreviewPanel.tsx +233 -0
  143. package/src/client/preview/PreviewTabs.tsx +159 -0
  144. package/src/client/preview/PreviewToolbar.tsx +160 -0
  145. package/src/client/preview/content.tsx +617 -0
  146. package/src/client/preview/markdown.ts +351 -0
  147. package/src/client/preview/mermaid.ts +274 -0
  148. package/src/client/preview/selection.ts +82 -0
  149. package/src/client/reference.ts +161 -0
  150. package/src/client/settings-card.module.css +316 -0
  151. package/src/client/settings-form.ts +451 -0
  152. package/src/client/store.ts +1290 -0
  153. package/src/client/styles/chip.module.css +38 -0
  154. package/src/client/styles/drag.module.css +30 -0
  155. package/src/client/styles/explorer.module.css +371 -0
  156. package/src/client/styles/picker.module.css +344 -0
  157. package/src/client/styles/preview.module.css +904 -0
  158. package/src/client/styles/scm.module.css +380 -0
  159. package/src/client/styles/tokens.module.css +480 -0
  160. package/src/core/types.ts +162 -0
  161. package/src/host/fs-service.ts +513 -0
  162. package/src/host/gate.ts +74 -0
  163. package/src/host/git-runner.ts +116 -0
  164. package/src/host/git-service.ts +395 -0
  165. package/src/host/loopback.ts +63 -0
  166. package/src/host/poll-guard.ts +109 -0
  167. package/src/host/routes.ts +695 -0
  168. package/src/index.ts +97 -0
  169. package/src/mount-once.ts +48 -0
package/src/index.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @lijian-ui/dsh-file-manager — host half: the workspace-gated
3
+ * filesystem + git services and the /filemgr/* HTTP routes (JSON
4
+ * operations + SSE change stream) on the shared webserver. The browser half
5
+ * (exports "./client") is served by client-modules from the same package's
6
+ * dsh.client declaration.
7
+ *
8
+ * The host half also announces the plugin to every agent through the
9
+ * system-prompt section mechanism (the same band task-board uses), so agents
10
+ * know the right-panel system exists and how to cooperate with it.
11
+ *
12
+ * FileManager right-panel design (Apache-2.0, iOfficeAI/FileManager) — re-implemented
13
+ * from measured behavior and architecture, not copied code.
14
+ * @module @lijian-ui/dsh-file-manager
15
+ */
16
+
17
+ import type { Context } from '@deepseek-ai/cordis'
18
+ import type {} from '@deepseek-ai/dsh-host-webserver'
19
+ import type {} from '@deepseek-ai/dsh-subprocess'
20
+ import type {} from '@deepseek-ai/dsh-workspace'
21
+ import type {} from '@deepseek-ai/dsh-system-prompt'
22
+ import { installSettingsSection, settingsNamespace } from '@deepseek-ai/dsh-settings'
23
+ import z from 'schemastery'
24
+ import { FsService } from './host/fs-service.ts'
25
+ import { GitService, subprocessRunner } from './host/git-service.ts'
26
+ import { createWorkspaceGate } from './host/gate.ts'
27
+ import { registerPanelRoutes } from './host/routes.ts'
28
+ import { mountOnce } from './mount-once.ts'
29
+
30
+ /** Required services: the route registry, the managed subprocess seam, the workspace registry, and the prompt band. */
31
+ export const inject = ['webServer', 'subprocess', 'workspaceRegistry', 'systemPrompt']
32
+
33
+ /** Settings namespace the browser settings card edits (the Host registers it). */
34
+ export const FILEMANAGER_PANEL_SETTINGS_NAMESPACE = 'filemgr'
35
+
36
+ /** Order of the announcement section within the tool-guidance band. */
37
+ const SECTION_ORDER = 210
38
+
39
+ /** Model-facing announcement: plugin presence, capabilities, and limits. */
40
+ export const FILEMANAGER_PANEL_GUIDANCE = '本机已安装 dsh-filemgr 插件(DSH Web GUI 的右侧面板系统):项目会话打开时,聊天区右侧出现「预览」与「文件/变更」两块面板。能力:Explorer 文件树(点击文件在预览面板打开、整行点击展开文件夹、按文件名搜索定位);Preview 多 tab 预览(markdown/html/code/diff/csv/pdf/office/图片/文本等格式,支持源码/预览切换、分屏编辑、保存;markdown 与聊天消息中的 mermaid 代码块会渲染成图表,图源语法错误时回退为代码块);SCM 变更面板(真实 git stage/unstage/discard);面板宽度可拖拽调整(Explorer 220~500px、Preview 340~1200px),双击把手复位默认宽度,折叠状态与宽度按项目持久化(localStorage)。数据源为当前会话工作目录的真实文件系统与真实 git 仓库,宿主进程经 /filemgr/* 路由提供。用户提到「右侧面板 / 预览面板 / 文件树 / 变更面板」时即指本插件,请据此协作。'
41
+
42
+ /** Settings section the browser card edits: a total on/off switch (issue #307). */
43
+ export interface FileManagerPanelSettings {
44
+ /** Whether the right-panel system is mounted at all; default on. */
45
+ enabled?: boolean
46
+ }
47
+
48
+ /**
49
+ * Mount the panel data services and their routes.
50
+ * @param ctx - context carrying webServer, subprocess, workspaceRegistry, systemPrompt.
51
+ */
52
+ export const apply = mountOnce('@lijian-ui/dsh-file-manager', applyImpl)
53
+
54
+ function applyImpl(ctx: Context, config: FileManagerPanelSettings = {}): void {
55
+ const gate = createWorkspaceGate(ctx)
56
+ const fs = new FsService(gate)
57
+ const git = new GitService(subprocessRunner(ctx), gate, (root, rel) => fs.delete(root, rel))
58
+
59
+ // Settings the browser card edits through the 'filemgr' namespace:
60
+ // turning the panel off unmounts the /filemgr/* routes (which stops
61
+ // the workspace fs watch and git polling, since both live behind the SSE
62
+ // stream) and the agent-facing announcement, mirroring the pet's model.
63
+ let current: () => FileManagerPanelSettings = () => base
64
+ const base: FileManagerPanelSettings = { enabled: config.enabled ?? true }
65
+ let disposePanel: (() => void) | undefined
66
+ let disposePrompt: (() => void) | undefined
67
+ const syncPanel = (): void => {
68
+ const enabled = current().enabled ?? true
69
+ if (disposePanel === undefined && enabled) {
70
+ disposePanel = ctx.effect(() => {
71
+ const disposeRoutes = registerPanelRoutes(ctx, fs, git)
72
+ return () => disposeRoutes()
73
+ }, 'dsh-filemgr: /filemgr routes')
74
+ disposePrompt = ctx.effect(() => ctx.systemPrompt.section({
75
+ name: 'plugin:filemgr',
76
+ order: SECTION_ORDER,
77
+ text: FILEMANAGER_PANEL_GUIDANCE,
78
+ }), 'dsh-filemgr: prompt section')
79
+ } else if (disposePanel !== undefined && !enabled) {
80
+ disposePanel()
81
+ disposePanel = undefined
82
+ disposePrompt?.()
83
+ disposePrompt = undefined
84
+ }
85
+ }
86
+ installSettingsSection(
87
+ ctx,
88
+ settingsNamespace(FILEMANAGER_PANEL_SETTINGS_NAMESPACE),
89
+ z.object({ enabled: z.boolean().default(true) }),
90
+ base,
91
+ {
92
+ setSource: (source) => { current = source },
93
+ onChange: () => syncPanel(),
94
+ },
95
+ )
96
+ syncPanel()
97
+ }
@@ -0,0 +1,48 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/host/mount-once.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Host single-instance guard shared by the plugin family. The family bundle
4
+ * (dsh-web-ui-all / dsh-skins) namespaces every child row id (web-ui-*), so
5
+ * the loader accepts a standalone install of the same package side by side;
6
+ * without this guard the second instance would still re-register the same
7
+ * webserver routes, tools, settings namespaces, and system-prompt sections
8
+ * and fail the boot. mountOnce makes the second host apply a no-op for the
9
+ * lifetime of the first instance (the browser half is already deduped by
10
+ * package name in the client module host).
11
+ *
12
+ * The registry rides a global symbol so two module instances of the same
13
+ * package (npm copy vs repository link) still share one verdict. cordis
14
+ * `ctx.effect` runs its callback immediately and treats the callback's
15
+ * return value as the fiber disposer, so the unmarker is returned, not run.
16
+ */
17
+
18
+ const MOUNTED = Symbol.for('dsh-web-ui.mounted-plugins')
19
+
20
+ interface MountRegistry {
21
+ [MOUNTED]?: Set<string>
22
+ }
23
+
24
+ function mountedSet(): Set<string> {
25
+ const registry = globalThis as MountRegistry
26
+ return (registry[MOUNTED] ??= new Set())
27
+ }
28
+
29
+ /**
30
+ * Wrap a cordis plugin apply so the package runs at most once per process.
31
+ * The first mount registers normally and unmarks when its fiber disposes;
32
+ * any later mount of the same package name is a no-op.
33
+ * @param packageName - npm package identity shared by every install source.
34
+ * @param fn - the original plugin apply.
35
+ * @returns an apply of the same shape.
36
+ */
37
+ export function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T {
38
+ return ((...args: unknown[]) => {
39
+ const mounted = mountedSet()
40
+ if (mounted.has(packageName)) return
41
+ mounted.add(packageName)
42
+ const ctx = args[0] as { effect?: (effect: () => unknown) => unknown } | undefined
43
+ ctx?.effect?.(() => () => {
44
+ mounted.delete(packageName)
45
+ })
46
+ return fn(...args)
47
+ }) as T
48
+ }