@kingsleyasher/dsh-knowledge-base 0.0.0-stage → 3.1.4

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 (516) hide show
  1. package/ARCHITECTURE.en.md +35 -0
  2. package/ARCHITECTURE.md +40 -0
  3. package/BETA4.md +31 -0
  4. package/BETA7.md +35 -0
  5. package/BETA8.md +39 -0
  6. package/BETA9.md +38 -0
  7. package/CONTRIBUTING.md +5 -0
  8. package/DEVELOPMENT.en.md +26 -0
  9. package/DEVELOPMENT.md +27 -0
  10. package/EXISTING-FRAMEWORK-OPTIMIZATION.md +101 -0
  11. package/LICENSE +21 -0
  12. package/MONOREPO.md +34 -0
  13. package/NPM-EDITION.md +9 -0
  14. package/PARSING-PREVIEW.md +84 -0
  15. package/PERFORMANCE.md +43 -0
  16. package/PRIVACY.md +7 -0
  17. package/PROJECT-RECORD.en.md +778 -0
  18. package/PROJECT-RECORD.md +789 -0
  19. package/README.md +109 -3
  20. package/README.zh-CN.md +117 -0
  21. package/RELEASE.en.md +559 -0
  22. package/RELEASE.md +570 -0
  23. package/RETRIEVAL.md +93 -0
  24. package/SECURITY.md +7 -0
  25. package/THIRD-PARTY-NOTICES.md +5 -0
  26. package/VERSIONING.en.md +51 -0
  27. package/VERSIONING.md +50 -0
  28. package/WORKBENCH.en.md +201 -0
  29. package/WORKBENCH.md +195 -0
  30. package/browser-extension/background.js +146 -0
  31. package/browser-extension/icons/knowledge-base-128.png +0 -0
  32. package/browser-extension/icons/knowledge-base-16.png +0 -0
  33. package/browser-extension/icons/knowledge-base-32.png +0 -0
  34. package/browser-extension/icons/knowledge-base-48.png +0 -0
  35. package/browser-extension/manifest.json +25 -0
  36. package/browser-extension/options.html +22 -0
  37. package/browser-extension/options.js +41 -0
  38. package/browser-extension/popup.html +17 -0
  39. package/browser-extension/popup.js +58 -0
  40. package/browser-extension/style.css +11 -0
  41. package/cordis.patch.yml +88 -0
  42. package/docs/LEGACY-246-BOOTSTRAP.md +21 -0
  43. package/docs/LIBRARY-FRAMEWORK-MIGRATION.md +45 -0
  44. package/docs/ORIGINAL-FILE-INDEX-ARCHITECTURE.md +43 -0
  45. package/docs/TODO-LIFECYCLE-VALIDATION.md +42 -0
  46. package/docs/UPDATE-RECOVERY.en.md +18 -0
  47. package/docs/UPDATE-RECOVERY.md +70 -0
  48. package/docs/WINDOWS-SIGNING.md +30 -0
  49. package/docs/client/ARCHITECTURE.en.md +17 -0
  50. package/docs/client/ARCHITECTURE.md +17 -0
  51. package/docs/client/CONTRIBUTING.md +5 -0
  52. package/docs/client/CROSS-VOLUME-TRASH.md +13 -0
  53. package/docs/client/DEVELOPMENT.en.md +33 -0
  54. package/docs/client/DEVELOPMENT.md +33 -0
  55. package/docs/client/EXISTING-FRAMEWORK-OPTIMIZATION.md +3 -0
  56. package/docs/client/PERFORMANCE.md +3 -0
  57. package/docs/client/PRIVACY.md +7 -0
  58. package/docs/client/PROJECT-RECORD.en.md +199 -0
  59. package/docs/client/PROJECT-RECORD.md +219 -0
  60. package/docs/client/README.md +55 -0
  61. package/docs/client/README.zh-CN.md +45 -0
  62. package/docs/client/RELEASE.en.md +148 -0
  63. package/docs/client/RELEASE.md +149 -0
  64. package/docs/client/RETRIEVAL.md +3 -0
  65. package/docs/client/SECURITY.md +7 -0
  66. package/docs/client/THIRD-PARTY-NOTICES.md +5 -0
  67. package/docs/client/VERSIONING.en.md +9 -0
  68. package/docs/client/VERSIONING.md +9 -0
  69. package/docs/client/WORKBENCH.en.md +24 -0
  70. package/docs/client/WORKBENCH.md +24 -0
  71. package/docs/client/skills/personal-knowledge-base/SKILL.md +38 -0
  72. package/docs/releases/client-1.0.1.md +32 -0
  73. package/docs/releases/client-1.0.2.md +32 -0
  74. package/docs/releases/client-1.0.3.md +31 -0
  75. package/docs/releases/client-1.1.1.md +28 -0
  76. package/docs/releases/client-1.1.2.md +16 -0
  77. package/docs/releases/client-1.1.4.md +7 -0
  78. package/docs/releases/client-2.0.0.en.md +13 -0
  79. package/docs/releases/client-2.0.0.md +13 -0
  80. package/docs/releases/client-2.0.1.en.md +10 -0
  81. package/docs/releases/client-2.0.1.md +10 -0
  82. package/docs/releases/client-2.0.3.en.md +8 -0
  83. package/docs/releases/client-2.0.3.md +8 -0
  84. package/docs/releases/plugin-2.4.1.md +24 -0
  85. package/docs/releases/plugin-2.4.10.md +22 -0
  86. package/docs/releases/plugin-2.4.11.md +14 -0
  87. package/docs/releases/plugin-2.4.12.md +14 -0
  88. package/docs/releases/plugin-2.4.13.md +27 -0
  89. package/docs/releases/plugin-2.4.14.md +18 -0
  90. package/docs/releases/plugin-2.4.2.md +31 -0
  91. package/docs/releases/plugin-2.4.3.md +25 -0
  92. package/docs/releases/plugin-2.4.4.md +31 -0
  93. package/docs/releases/plugin-2.4.5.md +23 -0
  94. package/docs/releases/plugin-2.4.6.md +23 -0
  95. package/docs/releases/plugin-2.4.7.md +14 -0
  96. package/docs/releases/plugin-2.4.8.md +14 -0
  97. package/docs/releases/plugin-2.4.9.md +18 -0
  98. package/docs/releases/plugin-2.5.10.md +11 -0
  99. package/docs/releases/plugin-2.5.13.en.md +11 -0
  100. package/docs/releases/plugin-2.5.13.md +11 -0
  101. package/docs/releases/plugin-2.5.3.md +28 -0
  102. package/docs/releases/plugin-2.5.4.md +14 -0
  103. package/docs/releases/plugin-2.5.5.md +16 -0
  104. package/docs/releases/plugin-2.5.6.md +3 -0
  105. package/docs/releases/plugin-2.5.7.md +7 -0
  106. package/docs/releases/plugin-2.5.8.md +7 -0
  107. package/docs/releases/plugin-2.5.9.md +7 -0
  108. package/docs/releases/plugin-3.0.0.en.md +13 -0
  109. package/docs/releases/plugin-3.0.0.md +13 -0
  110. package/docs/releases/plugin-3.0.1.en.md +10 -0
  111. package/docs/releases/plugin-3.0.1.md +10 -0
  112. package/docs/releases/plugin-3.1.3.en.md +11 -0
  113. package/docs/releases/plugin-3.1.3.md +11 -0
  114. package/docs/validation/windows-auto-update-2.4.13.md +31 -0
  115. package/docs/validation/windows-direct-246-to-2413.md +32 -0
  116. package/package.json +78 -6
  117. package/packages/kb-contracts/desktop.js +29 -0
  118. package/packages/kb-contracts/index.js +132 -0
  119. package/packages/kb-contracts/node.js +3 -0
  120. package/packages/kb-contracts/package.json +17 -0
  121. package/packages/kb-contracts/schema.js +42 -0
  122. package/packages/kb-contracts/tools.js +1 -0
  123. package/packages/kb-contracts/version-policy.js +45 -0
  124. package/packages/kb-core/index.js +9 -0
  125. package/packages/kb-core/package.json +15 -0
  126. package/packages/kb-core/src/capture-surface.js +22 -0
  127. package/packages/kb-core/src/documents.js +105 -0
  128. package/packages/kb-core/src/embedded.js +29 -0
  129. package/packages/kb-core/src/file-catalog.js +151 -0
  130. package/packages/kb-core/src/file-classification.js +60 -0
  131. package/packages/kb-core/src/flow-workspace.js +66 -0
  132. package/packages/kb-core/src/flows.js +1136 -0
  133. package/packages/kb-core/src/fsindex.js +293 -0
  134. package/packages/kb-core/src/import-service.js +486 -0
  135. package/packages/kb-core/src/importer.js +909 -0
  136. package/packages/kb-core/src/inbox-flow.js +2 -0
  137. package/packages/kb-core/src/index-architecture.js +48 -0
  138. package/packages/kb-core/src/index-maintenance.js +81 -0
  139. package/packages/kb-core/src/index-policy-service.js +191 -0
  140. package/packages/kb-core/src/index-policy.js +121 -0
  141. package/packages/kb-core/src/kbcore.js +2519 -0
  142. package/packages/kb-core/src/library-framework.js +186 -0
  143. package/packages/kb-core/src/library-state.js +68 -0
  144. package/packages/kb-core/src/managed-files.js +69 -0
  145. package/packages/kb-core/src/map.js +171 -0
  146. package/packages/kb-core/src/parse-credentials.js +49 -0
  147. package/packages/kb-core/src/parse-discovery.js +119 -0
  148. package/packages/kb-core/src/parse-job-storage.js +40 -0
  149. package/packages/kb-core/src/parse-native.js +87 -0
  150. package/packages/kb-core/src/parse-presets.js +46 -0
  151. package/packages/kb-core/src/parse-source-authority.js +72 -0
  152. package/packages/kb-core/src/parsing.js +2307 -0
  153. package/packages/kb-core/src/relation-name-lookup.js +43 -0
  154. package/packages/kb-core/src/retrieval-api.js +79 -0
  155. package/packages/kb-core/src/retrieval-cache.js +22 -0
  156. package/packages/kb-core/src/retrieval-chunks.js +128 -0
  157. package/packages/kb-core/src/retrieval-pool.js +102 -0
  158. package/packages/kb-core/src/retrieval-worker.js +190 -0
  159. package/packages/kb-core/src/retrieval.js +618 -0
  160. package/packages/kb-core/src/runtime-resources.js +73 -0
  161. package/packages/kb-core/src/service-ownership.js +18 -0
  162. package/packages/kb-core/src/source-references.js +61 -0
  163. package/packages/kb-core/src/storage-io.js +121 -0
  164. package/packages/kb-core/src/system-upgrades.js +104 -0
  165. package/packages/kb-core/src/workbench-backup.js +219 -0
  166. package/packages/kb-core/src/workbench-deliverables.js +73 -0
  167. package/packages/kb-core/src/workbench-files.js +25 -0
  168. package/packages/kb-core/src/workbench-inbox.js +57 -0
  169. package/packages/kb-core/src/workbench-links.js +236 -0
  170. package/packages/kb-core/src/workbench-question.js +131 -0
  171. package/packages/kb-core/src/workbench-relation-index.js +110 -0
  172. package/packages/kb-core/src/workbench-state.js +102 -0
  173. package/packages/kb-core/src/workbench-trash.js +213 -0
  174. package/packages/kb-core/src/workbench.js +936 -0
  175. package/packages/kb-service/auth.js +39 -0
  176. package/packages/kb-service/build.js +18 -0
  177. package/packages/kb-service/cli.js +26 -0
  178. package/packages/kb-service/client.js +64 -0
  179. package/packages/kb-service/clipper.js +15 -0
  180. package/packages/kb-service/compatibility.js +34 -0
  181. package/packages/kb-service/desktop-files.js +514 -0
  182. package/packages/kb-service/desktop-host-links.js +39 -0
  183. package/packages/kb-service/dsh-broker.js +64 -0
  184. package/packages/kb-service/dsh-host.js +168 -0
  185. package/packages/kb-service/dsh-stream-relay.js +32 -0
  186. package/packages/kb-service/engines.js +32 -0
  187. package/packages/kb-service/extension.js +8 -0
  188. package/packages/kb-service/first-library-handoff.js +28 -0
  189. package/packages/kb-service/handoff-api.js +22 -0
  190. package/packages/kb-service/host-adapter.js +151 -0
  191. package/packages/kb-service/host-assets.js +9 -0
  192. package/packages/kb-service/host-python.js +30 -0
  193. package/packages/kb-service/host-updates.js +11 -0
  194. package/packages/kb-service/inbox-host.js +47 -0
  195. package/packages/kb-service/inbox-jobs.js +54 -0
  196. package/packages/kb-service/index.js +3 -0
  197. package/packages/kb-service/io.js +24 -0
  198. package/packages/kb-service/launch-lock.js +27 -0
  199. package/packages/kb-service/launcher.js +18 -0
  200. package/packages/kb-service/legacy-handoff.js +27 -0
  201. package/packages/kb-service/legacy-ports.js +18 -0
  202. package/packages/kb-service/main.js +13 -0
  203. package/packages/kb-service/memory-channel.js +57 -0
  204. package/packages/kb-service/memory-sync.js +42 -0
  205. package/packages/kb-service/migration.js +131 -0
  206. package/packages/kb-service/native.py +216 -0
  207. package/packages/kb-service/operations.js +19 -0
  208. package/packages/kb-service/package.json +1 -0
  209. package/packages/kb-service/runtime.js +185 -0
  210. package/packages/kb-service/safe-update.js +104 -0
  211. package/packages/kb-service/service.js +494 -0
  212. package/packages/kb-service/tool-definitions.json +934 -0
  213. package/packages/kb-service/tool-router.js +45 -0
  214. package/packages/kb-service/vector-profiles.js +41 -0
  215. package/presets/01-knowledge-agent.patch.yml +347 -0
  216. package/runtime/python/LICENSE.txt +676 -0
  217. package/runtime/python/_asyncio.pyd +0 -0
  218. package/runtime/python/_bz2.pyd +0 -0
  219. package/runtime/python/_ctypes.pyd +0 -0
  220. package/runtime/python/_decimal.pyd +0 -0
  221. package/runtime/python/_elementtree.pyd +0 -0
  222. package/runtime/python/_hashlib.pyd +0 -0
  223. package/runtime/python/_lzma.pyd +0 -0
  224. package/runtime/python/_multiprocessing.pyd +0 -0
  225. package/runtime/python/_overlapped.pyd +0 -0
  226. package/runtime/python/_queue.pyd +0 -0
  227. package/runtime/python/_remote_debugging.pyd +0 -0
  228. package/runtime/python/_socket.pyd +0 -0
  229. package/runtime/python/_sqlite3.pyd +0 -0
  230. package/runtime/python/_ssl.pyd +0 -0
  231. package/runtime/python/_uuid.pyd +0 -0
  232. package/runtime/python/_wmi.pyd +0 -0
  233. package/runtime/python/_zoneinfo.pyd +0 -0
  234. package/runtime/python/_zstd.pyd +0 -0
  235. package/runtime/python/libcrypto-3.dll +0 -0
  236. package/runtime/python/libffi-8.dll +0 -0
  237. package/runtime/python/libssl-3.dll +0 -0
  238. package/runtime/python/libtommath.dll +0 -0
  239. package/runtime/python/pyexpat.pyd +0 -0
  240. package/runtime/python/python.cat +0 -0
  241. package/runtime/python/python.exe +0 -0
  242. package/runtime/python/python3.dll +0 -0
  243. package/runtime/python/python314._pth +5 -0
  244. package/runtime/python/python314.dll +0 -0
  245. package/runtime/python/python314.zip +0 -0
  246. package/runtime/python/pythonw.exe +0 -0
  247. package/runtime/python/select.pyd +0 -0
  248. package/runtime/python/sqlite3.dll +0 -0
  249. package/runtime/python/unicodedata.pyd +0 -0
  250. package/runtime/python/vcruntime140.dll +0 -0
  251. package/runtime/python/vcruntime140_1.dll +0 -0
  252. package/runtime/python/winsound.pyd +0 -0
  253. package/skills/personal-knowledge-base/SKILL.md +38 -0
  254. package/src/client/capture-icon-192.png +0 -0
  255. package/src/client/capture-icon-512.png +0 -0
  256. package/src/client/capture-icon.svg +12 -0
  257. package/src/client/capture-sw.js +10 -0
  258. package/src/client/capture.css +1 -0
  259. package/src/client/capture.html +1 -0
  260. package/src/client/capture.js +37 -0
  261. package/src/client/capture.webmanifest +1 -0
  262. package/src/client/inbox-organize-bridge.js +22 -0
  263. package/src/client/index.js +4980 -0
  264. package/src/client/knowledge-ui.css +255 -0
  265. package/src/client/pdfjs/LICENSE +177 -0
  266. package/src/client/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  267. package/src/client/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  268. package/src/client/pdfjs/cmaps/78-H.bcmap +0 -0
  269. package/src/client/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  270. package/src/client/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  271. package/src/client/pdfjs/cmaps/78-V.bcmap +0 -0
  272. package/src/client/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  273. package/src/client/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  274. package/src/client/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  275. package/src/client/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  276. package/src/client/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  277. package/src/client/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  278. package/src/client/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  279. package/src/client/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  280. package/src/client/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  281. package/src/client/pdfjs/cmaps/Add-H.bcmap +0 -0
  282. package/src/client/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  283. package/src/client/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  284. package/src/client/pdfjs/cmaps/Add-V.bcmap +0 -0
  285. package/src/client/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  286. package/src/client/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  287. package/src/client/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  288. package/src/client/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  289. package/src/client/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  290. package/src/client/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  291. package/src/client/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  292. package/src/client/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  293. package/src/client/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  294. package/src/client/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  295. package/src/client/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  296. package/src/client/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  297. package/src/client/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  298. package/src/client/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  299. package/src/client/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  300. package/src/client/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  301. package/src/client/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  302. package/src/client/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  303. package/src/client/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  304. package/src/client/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  305. package/src/client/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  306. package/src/client/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  307. package/src/client/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  308. package/src/client/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  309. package/src/client/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  310. package/src/client/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  311. package/src/client/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  312. package/src/client/pdfjs/cmaps/B5-H.bcmap +0 -0
  313. package/src/client/pdfjs/cmaps/B5-V.bcmap +0 -0
  314. package/src/client/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  315. package/src/client/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  316. package/src/client/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  317. package/src/client/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  318. package/src/client/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  319. package/src/client/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  320. package/src/client/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  321. package/src/client/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  322. package/src/client/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  323. package/src/client/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  324. package/src/client/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  325. package/src/client/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  326. package/src/client/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  327. package/src/client/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  328. package/src/client/pdfjs/cmaps/EUC-H.bcmap +0 -0
  329. package/src/client/pdfjs/cmaps/EUC-V.bcmap +0 -0
  330. package/src/client/pdfjs/cmaps/Ext-H.bcmap +0 -0
  331. package/src/client/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  332. package/src/client/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  333. package/src/client/pdfjs/cmaps/Ext-V.bcmap +0 -0
  334. package/src/client/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  335. package/src/client/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  336. package/src/client/pdfjs/cmaps/GB-H.bcmap +4 -0
  337. package/src/client/pdfjs/cmaps/GB-V.bcmap +0 -0
  338. package/src/client/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  339. package/src/client/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  340. package/src/client/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  341. package/src/client/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  342. package/src/client/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  343. package/src/client/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  344. package/src/client/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  345. package/src/client/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  346. package/src/client/pdfjs/cmaps/GBT-H.bcmap +0 -0
  347. package/src/client/pdfjs/cmaps/GBT-V.bcmap +0 -0
  348. package/src/client/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  349. package/src/client/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  350. package/src/client/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  351. package/src/client/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  352. package/src/client/pdfjs/cmaps/H.bcmap +0 -0
  353. package/src/client/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  354. package/src/client/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  355. package/src/client/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  356. package/src/client/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  357. package/src/client/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  358. package/src/client/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  359. package/src/client/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  360. package/src/client/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  361. package/src/client/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  362. package/src/client/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  363. package/src/client/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  364. package/src/client/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  365. package/src/client/pdfjs/cmaps/Hankaku.bcmap +0 -0
  366. package/src/client/pdfjs/cmaps/Hiragana.bcmap +0 -0
  367. package/src/client/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  368. package/src/client/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  369. package/src/client/pdfjs/cmaps/KSC-H.bcmap +0 -0
  370. package/src/client/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  371. package/src/client/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  372. package/src/client/pdfjs/cmaps/KSC-V.bcmap +0 -0
  373. package/src/client/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  374. package/src/client/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  375. package/src/client/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  376. package/src/client/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  377. package/src/client/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  378. package/src/client/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  379. package/src/client/pdfjs/cmaps/Katakana.bcmap +0 -0
  380. package/src/client/pdfjs/cmaps/LICENSE +36 -0
  381. package/src/client/pdfjs/cmaps/NWP-H.bcmap +0 -0
  382. package/src/client/pdfjs/cmaps/NWP-V.bcmap +0 -0
  383. package/src/client/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  384. package/src/client/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  385. package/src/client/pdfjs/cmaps/Roman.bcmap +0 -0
  386. package/src/client/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  387. package/src/client/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  388. package/src/client/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  389. package/src/client/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  390. package/src/client/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  391. package/src/client/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  392. package/src/client/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  393. package/src/client/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  394. package/src/client/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  395. package/src/client/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  396. package/src/client/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  397. package/src/client/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  398. package/src/client/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  399. package/src/client/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  400. package/src/client/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  401. package/src/client/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  402. package/src/client/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  403. package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  404. package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  405. package/src/client/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  406. package/src/client/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  407. package/src/client/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  408. package/src/client/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  409. package/src/client/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  410. package/src/client/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  411. package/src/client/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  412. package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  413. package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  414. package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  415. package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  416. package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  417. package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  418. package/src/client/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  419. package/src/client/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  420. package/src/client/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  421. package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  422. package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  423. package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  424. package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  425. package/src/client/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  426. package/src/client/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  427. package/src/client/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  428. package/src/client/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  429. package/src/client/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  430. package/src/client/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  431. package/src/client/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  432. package/src/client/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  433. package/src/client/pdfjs/cmaps/V.bcmap +0 -0
  434. package/src/client/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  435. package/src/client/pdfjs/pdf.mjs +26779 -0
  436. package/src/client/pdfjs/pdf.worker.mjs +63420 -0
  437. package/src/client/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  438. package/src/client/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  439. package/src/client/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  440. package/src/client/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  441. package/src/client/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  442. package/src/client/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  443. package/src/client/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  444. package/src/client/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  445. package/src/client/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  446. package/src/client/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  447. package/src/client/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  448. package/src/client/pdfjs/standard_fonts/LICENSE_LIBERATION +102 -0
  449. package/src/client/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  450. package/src/client/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  451. package/src/client/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  452. package/src/client/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  453. package/src/client/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  454. package/src/client/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  455. package/src/client/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  456. package/src/client/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  457. package/src/client/pdfjs/wasm/LICENSE_PDFJS_QCMS +22 -0
  458. package/src/client/pdfjs/wasm/LICENSE_QCMS +21 -0
  459. package/src/client/pdfjs/wasm/jbig2.wasm +0 -0
  460. package/src/client/pdfjs/wasm/openjpeg.wasm +0 -0
  461. package/src/client/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
  462. package/src/client/pdfjs/wasm/qcms_bg.wasm +0 -0
  463. package/src/client/todo-lifecycle-ui.js +58 -0
  464. package/src/client/workbench-features.js +148 -0
  465. package/src/client/workbench-relations.js +86 -0
  466. package/src/client/workbench-theme.css +81 -0
  467. package/src/client/workbench-ui.js +1761 -0
  468. package/src/host/capture-surface.js +2 -0
  469. package/src/host/citation-guard.js +40 -0
  470. package/src/host/command-description.js +43 -0
  471. package/src/host/flow-workspace.js +62 -0
  472. package/src/host/flows.js +2 -0
  473. package/src/host/fsindex.js +2 -0
  474. package/src/host/gateway.js +916 -0
  475. package/src/host/import-service.js +2 -0
  476. package/src/host/importer.js +2 -0
  477. package/src/host/index-maintenance.js +2 -0
  478. package/src/host/index-policy-service.js +2 -0
  479. package/src/host/index-policy.js +2 -0
  480. package/src/host/index.js +2224 -0
  481. package/src/host/kbcore.js +2 -0
  482. package/src/host/managed-files.js +2 -0
  483. package/src/host/map.js +2 -0
  484. package/src/host/parse-credentials.js +2 -0
  485. package/src/host/parse-discovery.js +2 -0
  486. package/src/host/parse-native.js +2 -0
  487. package/src/host/parse-presets.js +2 -0
  488. package/src/host/parse-source-authority.js +2 -0
  489. package/src/host/parsing.js +7 -0
  490. package/src/host/relation-name-lookup.js +2 -0
  491. package/src/host/retrieval-api.js +2 -0
  492. package/src/host/retrieval-cache.js +2 -0
  493. package/src/host/retrieval-chunks.js +2 -0
  494. package/src/host/retrieval-pool.js +2 -0
  495. package/src/host/retrieval-worker.js +2 -0
  496. package/src/host/retrieval.js +2 -0
  497. package/src/host/runtime-resources.js +2 -0
  498. package/src/host/selftest.js +747 -0
  499. package/src/host/storage-io.js +2 -0
  500. package/src/host/system-upgrades.js +2 -0
  501. package/src/host/todo-lifecycle.js +66 -0
  502. package/src/host/updates.js +281 -0
  503. package/src/host/versioning.js +2 -0
  504. package/src/host/workbench-backup.js +2 -0
  505. package/src/host/workbench-deliverables.js +2 -0
  506. package/src/host/workbench-files.js +2 -0
  507. package/src/host/workbench-inbox.js +2 -0
  508. package/src/host/workbench-links.js +2 -0
  509. package/src/host/workbench-question.js +2 -0
  510. package/src/host/workbench-relation-index.js +2 -0
  511. package/src/host/workbench-state.js +2 -0
  512. package/src/host/workbench-trash.js +2 -0
  513. package/src/host/workbench.js +5 -0
  514. package/tools/kb-local-model.py +141 -0
  515. package/tools/kb-pdf-pages.py +78 -0
  516. package/tools/kb-transactional-update.py +284 -0
@@ -0,0 +1,105 @@
1
+ import path from 'node:path'
2
+ import { readFile, stat, mkdir, open, rename, unlink } from 'node:fs/promises'
3
+ import { constants } from 'node:fs'
4
+ import { randomUUID } from 'node:crypto'
5
+ import { TextDecoder } from 'node:util'
6
+ import { digest, relativePath, safePath, fail, atomicJson } from './workbench-state.js'
7
+ import { fileRole, writableFile } from './workbench-files.js'
8
+
9
+ const MAX_EDIT_BYTES = 1024 * 1024
10
+ const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
11
+ const fingerprint = info => [info.dev, info.ino, info.size, info.mtimeNs, info.ctimeNs].join(':')
12
+ const revisionOf = bytes => 'raw-sha256:' + digest(bytes)
13
+ const lineEndings = text => {
14
+ const crlf = (text.match(/\r\n/g) ?? []).length
15
+ const lf = (text.match(/(?<!\r)\n/g) ?? []).length
16
+ const cr = (text.match(/\r(?!\n)/g) ?? []).length
17
+ return [crlf > 0, lf > 0, cr > 0].filter(Boolean).length > 1 ? 'mixed' : crlf ? 'crlf' : lf ? 'lf' : cr ? 'cr' : 'none'
18
+ }
19
+
20
+ /** Trusted application boundary. A Host/controller must supply real caller authorization. */
21
+ export function createDocumentService({ binding, versionOf, assertVisible, notify, invalidate, authorize = async () => false }) {
22
+ async function checked(input, action, caller) {
23
+ if (!input || typeof input !== 'object') throw fail('BAD_REQUEST', 'Document request required')
24
+ const b = await binding(input.expectedKbId)
25
+ if (input.expectedKbId !== b.st.kbId) throw fail('IDENTITY_REQUIRED', 'Current knowledge identity is required')
26
+ if (input.policyVersion !== versionOf(b)) throw fail('SETTINGS_CHANGED', 'Knowledge policy changed')
27
+ if (await authorize({ action, caller, kbId: b.st.kbId, root: b.root }) !== true) throw fail('FORBIDDEN', 'Document access requires a trusted caller')
28
+ const file = relativePath(input.path)
29
+ assertVisible(b, file)
30
+ if (fileRole(file) !== 'document' || /^(?:_模板|_手册|索引层)\//.test(file)) throw fail('READ_ONLY', 'Generated and system files cannot be edited')
31
+ if (!/\.md$/i.test(file)) throw fail('UNSUPPORTED_EDIT', 'The embedded editor supports Markdown only')
32
+ const absolute = await safePath(b.root, file)
33
+ const capabilities = await writableFile(b.root, file)
34
+ if (!capabilities.canDelete) throw fail('READ_ONLY', 'Document or directory is not writable')
35
+ const latest = await binding(b.st.kbId)
36
+ if (latest.key !== b.key) throw fail('BINDING_CHANGED', 'Knowledge binding changed')
37
+ if (versionOf(latest) !== input.policyVersion) throw fail('SETTINGS_CHANGED', 'Knowledge policy changed during authorization')
38
+ assertVisible(latest, file)
39
+ return { b: latest, file, absolute }
40
+ }
41
+ async function load(absolute) {
42
+ const before = await stat(absolute, { bigint: true })
43
+ if (!before.isFile()) throw fail('READ_ONLY', 'A regular document is required')
44
+ if (before.size > BigInt(MAX_EDIT_BYTES)) throw fail('EDIT_TOO_LARGE', 'Document exceeds the complete editing limit')
45
+ const bytes = await readFile(absolute)
46
+ if (bytes.length > MAX_EDIT_BYTES) throw fail('EDIT_TOO_LARGE', 'Document exceeds the complete editing limit')
47
+ const after = await stat(absolute, { bigint: true })
48
+ if (fingerprint(before) !== fingerprint(after)) throw fail('CONFLICT', 'Document changed during read')
49
+ const bom = bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf
50
+ let text
51
+ try { text = decoder.decode(bom ? bytes.subarray(3) : bytes) }
52
+ catch { throw fail('UNSUPPORTED_ENCODING', 'Only lossless UTF-8 editing is supported') }
53
+ return { bytes, text, bom, revision: revisionOf(bytes), fingerprint: fingerprint(after), newline: lineEndings(text) }
54
+ }
55
+ async function recheck(input, original, action, caller) {
56
+ const current = await checked(input, action, caller)
57
+ if (current.b.key !== original.b.key || current.absolute !== original.absolute) throw fail('BINDING_CHANGED', 'Knowledge binding changed')
58
+ return current
59
+ }
60
+ return {
61
+ async readForEdit(input, caller) {
62
+ const current = await checked(input, 'readForEdit', caller)
63
+ const content = await load(current.absolute)
64
+ await recheck(input, current, 'readForEdit', caller)
65
+ return { kbId: current.b.st.kbId, path: current.file, text: content.text, revision: content.revision,
66
+ encoding: 'utf-8', bom: content.bom, newline: content.newline,
67
+ original: true, complete: true, canEdit: true, maxBytes: MAX_EDIT_BYTES }
68
+ },
69
+ async save(input, caller) {
70
+ if (typeof input?.text !== 'string' || !input.expectedRevision?.startsWith('raw-sha256:')) throw fail('BAD_REQUEST', 'Complete original text and its editing revision are required')
71
+ if (input.text.startsWith('\ufeff') || Buffer.from(input.text, 'utf8').toString('utf8') !== input.text) throw fail('BAD_REQUEST', 'Text must be lossless UTF-8 without a caller-supplied BOM')
72
+ const original = await checked(input, 'save', caller)
73
+ const result = await original.b.core._internal.withMutationLock(original.b.root, async () => {
74
+ const current = await recheck(input, original, 'save', caller)
75
+ const before = await load(current.absolute)
76
+ if (before.revision !== input.expectedRevision) throw fail('CONFLICT', 'Document was modified by another writer')
77
+ const payload = Buffer.concat([before.bom ? Buffer.from([0xef, 0xbb, 0xbf]) : Buffer.alloc(0), Buffer.from(input.text, 'utf8')])
78
+ if (payload.length > MAX_EDIT_BYTES) throw fail('EDIT_TOO_LARGE', 'Document exceeds the complete editing limit')
79
+ const transaction = input.operationId ?? randomUUID(); if (!/^[a-f0-9-]{32,64}$/.test(transaction)) throw fail('BAD_REQUEST', 'Invalid internal operation identity'); const backupRelative = '.kbmeta/backups/editor-' + transaction
80
+ const backup = await safePath(current.b.root, backupRelative, { missing: true })
81
+ await mkdir(backup, { recursive: false })
82
+ const backupFile = path.join(backup, 'original.md')
83
+ let backupHandle
84
+ try { backupHandle = await open(backupFile, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY); await backupHandle.writeFile(before.bytes); await backupHandle.sync() }
85
+ finally { await backupHandle?.close() }
86
+ await atomicJson(path.join(backup, 'manifest.json'), { format: 1, path: current.file, revision: before.revision, bytes: before.bytes.length, sha256: digest(before.bytes) })
87
+ const temporary = current.absolute + '.tmp-kb-editor-' + transaction
88
+ let handle
89
+ try {
90
+ handle = await open(temporary, 'wx'); await handle.writeFile(payload); await handle.sync(); await handle.close(); handle = null
91
+ await recheck(input, current, 'save', caller)
92
+ const final = await load(current.absolute)
93
+ if (final.revision !== before.revision || final.fingerprint !== before.fingerprint) throw fail('CONFLICT', 'Document changed before publish')
94
+ await rename(temporary, current.absolute)
95
+ } finally { await handle?.close(); await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error }) }
96
+ invalidate()
97
+ notify({ type: 'files-changed', kbId: current.b.st.kbId, paths: [current.file] })
98
+ return { committed: true, kbId: current.b.st.kbId, path: current.file, revision: revisionOf(payload), backup: backupRelative,
99
+ index: { state: 'pending' } }
100
+ })
101
+ if (result?.ok === false) throw fail('STATE_BUSY', result.detail || result.reason || 'Knowledge writer is busy')
102
+ return result
103
+ },
104
+ }
105
+ }
@@ -0,0 +1,29 @@
1
+ import { createCore } from './kbcore.js'
2
+ import { createWorkbench } from './workbench.js'
3
+
4
+ /** In-process composition. No daemon, connection discovery or storage migration. */
5
+ export function createEmbeddedKernel({ stateDir, config = {}, ports = {} }) {
6
+ if (typeof stateDir !== 'string' || !stateDir.trim()) throw new TypeError('stateDir is required')
7
+ let core = null, disposed = false
8
+ const workbench = createWorkbench({ ...ports, stateDir, getCore: () => core })
9
+ return {
10
+ mode: 'embedded',
11
+ workbench,
12
+ documents: workbench.documents,
13
+ openCore(log = ports.log ?? (() => {})) {
14
+ if (disposed) throw new Error('embedded kernel disposed')
15
+ if (core === null) core = createCore({ ...config, stateDir, resources: workbench.resources }, log)
16
+ return core
17
+ },
18
+ get core() { return core },
19
+ dispatch(args, caller) {
20
+ if (disposed) throw new Error('embedded kernel disposed')
21
+ return workbench.dispatch(args, caller)
22
+ },
23
+ dispose() {
24
+ if (disposed) return
25
+ disposed = true
26
+ workbench.dispose()
27
+ },
28
+ }
29
+ }
@@ -0,0 +1,151 @@
1
+ import path from 'node:path'
2
+ import {createReadStream,readFileSync,statSync} from 'node:fs'
3
+ import {readFile,lstat,stat} from 'node:fs/promises'
4
+ import {createHash} from 'node:crypto'
5
+ import {walkTree,privateRootOf} from './fsindex.js'
6
+ import {safePath,readJson,atomicJson,locked,digest,fail,relativePath} from './workbench-state.js'
7
+ import {CLASSIFICATION_VERSION,presentClassifiedFile} from './file-classification.js'
8
+
9
+ export const CATALOG_PATH='索引层/文件目录.json'
10
+ export const CATALOG_FORMAT='original-files-v1'
11
+ const TEXT=/\.(md|markdown|txt|text|csv|tsv|json|jsonl|log|ya?ml|html?|xml|[cm]?js|tsx?|jsx|py|css|sql)$/i
12
+ const categories={'00-画像':'画像','10-项目':'项目','20-知识笔记':'知识','30-人物关系':'人物','40-素材资源':'素材'}
13
+ const label=(value,fallback)=>typeof value==='string'&&value.trim()?value.trim().slice(0,200):fallback
14
+ const tagsOf=value=>Array.isArray(value)?[...new Set(value.filter(t=>typeof t==='string').map(t=>t.slice(0,100)))].slice(0,32):[]
15
+ const activeCache=new Map()
16
+ export function catalogActive(root){
17
+ try{const file=path.join(root,CATALOG_PATH),meta=path.join(root,'.kbmeta/kb.json'),a=statSync(file,{bigint:true}),b=statSync(meta,{bigint:true}),key=[a.ino,a.size,a.mtimeNs,a.ctimeNs,b.ino,b.mtimeNs,b.ctimeNs].join(':');if(activeCache.get(root)===key)return true
18
+ const c=JSON.parse(readFileSync(file,'utf8')),kb=JSON.parse(readFileSync(meta,'utf8'));if(c.format!==CATALOG_FORMAT||c.kbId!==kb.kbId||!Array.isArray(c.files)||!Array.isArray(c.references))throw Error('invalid catalog')
19
+ if(activeCache.size>=16)activeCache.delete(activeCache.keys().next().value);activeCache.set(root,key);return true
20
+ }catch(e){activeCache.delete(root);if(e.code==='ENOENT')return false;throw fail('STATE_CORRUPT','索引架构记录无法读取,未退回旧模式')}
21
+ }
22
+ // Every desktop request binds the library, and binding reads this catalog. The
23
+ // parsed copy is reused while the file identity is unchanged; any write, replace
24
+ // or rename invalidates it. Callers that edit a catalog must clone it first.
25
+ const catalogCache=new Map()
26
+ const fileStatKey=st=>[String(st.dev),String(st.ino),String(st.size),String(st.mtimeNs),String(st.ctimeNs)].join(':')
27
+ export async function readCatalog(root,kbId){
28
+ const file=await safePath(root,CATALOG_PATH,{missing:true})
29
+ let st
30
+ try{st=await stat(file,{bigint:true})}
31
+ catch(e){if(e.code==='ENOENT'){catalogCache.delete(path.resolve(root).toLowerCase());return null}throw e}
32
+ const cacheKey=path.resolve(root).toLowerCase(),key=fileStatKey(st)+'|'+String(kbId??'')
33
+ const hit=catalogCache.get(cacheKey)
34
+ if(hit?.key===key)return hit.value
35
+ const c=await readJson(file,null)
36
+ if(!c)return null
37
+ if(c.format!==CATALOG_FORMAT||!Array.isArray(c.files)||!Array.isArray(c.references)||kbId&&c.kbId!==kbId||c.files.some(f=>!f||typeof f.path!=='string'||relativePath(f.path)!==f.path||f.path.startsWith('索引层/')))throw fail('STATE_CORRUPT','文件目录身份或格式不符,已保留现场')
38
+ const value=c.classificationVersion===CLASSIFICATION_VERSION?c:{...c,files:c.files.map(presentClassifiedFile),classificationPending:true}
39
+ if(catalogCache.size>=4)catalogCache.delete(catalogCache.keys().next().value)
40
+ catalogCache.set(cacheKey,{key,value})
41
+ return value
42
+ }
43
+ const identity=st=>String(st.dev)+':'+String(st.ino)
44
+ async function fileHash(file){const hash=createHash('sha256');for await(const chunk of createReadStream(file))hash.update(chunk);return hash.digest('hex')}
45
+ const system=file=>/(^|\/)(_模板|_手册)(\/|$)/.test(file)||/^(AGENTS|INDEX|README|知识库清单)\.md$/i.test(file)
46
+
47
+ // No body is stored here. Every catalog record addresses an ordinary original.
48
+ export async function inspectOriginals(b,{previous=null,paths=[],walk=null}={}){
49
+ walk=walk??await walkTree(b.root,b.root,{maxFiles:Number.MAX_SAFE_INTEGER,maxDepth:128,followLinks:false})
50
+ if(walk.truncated||walk.errors.some(e=>!String(e.reason??e.code??'').includes('link')&&!String(e.reason??e.code??'').includes('LINK')))throw fail('SCAN_INCOMPLETE','文件枚举不完整,未发布迁移;请检查不可访问目录或链接')
51
+ const old=new Map((previous?.files??[]).map(f=>[f.path,f])),byIdentity=new Map()
52
+ for(const f of old.values()){const list=byIdentity.get(f.identity)??[];list.push(f);byIdentity.set(f.identity,list)}
53
+ const candidates=[],refs=new Map(),known=new Set()
54
+ const requests=await readJson(await safePath(b.root,'.kbmeta/requests.json',{missing:true}),{})
55
+ for(const [id,r]of Object.entries(requests.items??{}))if(id.startsWith('capture-')&&r.op==='create'&&r.path)known.add(r.path)
56
+ const imports=await readJson(await safePath(b.root,'.kbmeta/import-sources.json',{missing:true}),{})
57
+ for(const r of Object.values(imports.entries??{}))if((!r.kbId||r.kbId===b.st.kbId)&&r.entryPath&&r.originalPath&&r.entryPath!==r.originalPath)known.add(r.entryPath)
58
+ const livePaths=new Set(walk.files.map(f=>f.path))
59
+ for(const f of walk.files){
60
+ if(system(f.path))continue
61
+ const absolute=await safePath(b.root,f.path),before=await lstat(absolute)
62
+ const cached=old.get(f.path)
63
+ if(cached?.status==='available'&&!cached.referencePaths?.length&&cached.identity===identity(before)&&cached.size===before.size&&cached.mtimeMs===before.mtimeMs&&cached.ctimeMs===before.ctimeMs&&!paths.some(p=>f.path===p||f.path.startsWith(p+'/'))){candidates.push({...cached,private:cached.private===true||privateRootOf(f.path,b.privateDirs)!==null});continue}
64
+ let fm={},text=''
65
+ if(TEXT.test(f.path)&&before.size<=8*1024*1024){text=await readFile(absolute,'utf8');fm=b.core._internal.parseFrontmatter(text).data}
66
+ const source=typeof fm.source==='string'?fm.source:null
67
+ if(source&&(known.has(f.path)||text.includes('<!-- kb:source-reference -->'))){
68
+ let rel;try{rel=relativePath(source)}catch{throw fail('SOURCE_INVALID','旧索引的原件指向无效:'+f.path)}
69
+ const priorReference=previous?.references?.find(r=>r.path===f.path);if(!livePaths.has(rel)&&priorReference&&old.has(priorReference.source))rel=priorReference.source;
70
+ if(rel===f.path||!livePaths.has(rel)&&!old.has(rel))throw fail('SOURCE_MISSING','旧索引的原件缺失,未把旧正文当作原件:'+f.path)
71
+ if(livePaths.has(rel))await safePath(b.root,rel);refs.set(f.path,{source:rel,fm});continue
72
+ }
73
+ const hash=await fileHash(absolute),after=await lstat(absolute)
74
+ if(before.size!==after.size||before.mtimeMs!==after.mtimeMs||before.ctimeMs!==after.ctimeMs||identity(before)!==identity(after))throw fail('FILE_CHANGED','扫描期间文件已改变,请重新预览')
75
+ const moved=byIdentity.get(identity(after)),prior=old.get(f.path)??(moved?.length===1&&moved[0].sha256===hash?moved[0]:null)
76
+ const folder=path.posix.dirname(f.path),kind=label(fm.type,categories[f.path.split('/')[0]]||'素材')
77
+ candidates.push({id:prior?.id??'file-'+digest(b.st.kbId+'\0'+identity(after)+'\0'+f.path).slice(0,24),path:f.path,identity:identity(after),sha256:hash,size:after.size,mtimeMs:after.mtimeMs,ctimeMs:after.ctimeMs,
78
+ title:typeof fm.title==='string'?fm.title.slice(0,512):path.posix.basename(f.path,path.posix.extname(f.path)),originalType:label(fm.type,null),originalCategory:label(fm.category,null),kind:prior?.manual?prior.kind:kind,
79
+ category:prior?.manual?prior.category:label(fm.category,folder==='.'?'未分类':folder),tags:prior?.manual?prior.tags:tagsOf(fm.tags),manual:prior?.manual===true,
80
+ private:prior?.private===true||kind==='画像'||kind==='人物'||privateRootOf(f.path,b.privateDirs)!==null,status:'available',...(prior&&prior.path!==f.path?{previousPath:prior.path}:{})})
81
+ }
82
+ const files=new Map(candidates.map(f=>[f.path,f]))
83
+ for(const [alias,{source,fm}]of [...refs].sort(([a],[b])=>a.localeCompare(b))){const f=files.get(source)??candidates.find(row=>row.previousPath===source);if(!f&&old.has(source))continue;if(!f)throw fail('SOURCE_INVALID','原件指向另一个索引条目,未迁移:'+alias)
84
+ if(f.path!==source)refs.set(alias,{source:f.path,fm});
85
+ if(!f.manual&&!f.originalCategory&&!f.referencePaths?.length){
86
+ // Old classified references contain the user's classification. The date
87
+ // archive containing the original is a storage location, not that category.
88
+ f.category=label(fm.category,path.posix.dirname(alias)==='.'?'未分类':path.posix.dirname(alias))
89
+ }
90
+ f.referencePaths=[...(f.referencePaths??[]),alias];if(!f.manual){if(!f.originalType)f.kind=label(fm.type,f.kind);f.tags=tagsOf([...f.tags,...tagsOf(fm.tags)])}
91
+ f.private ||=f.kind==='画像'||f.kind==='人物'||privateRootOf(alias,b.privateDirs)!==null
92
+ }
93
+ const ids=new Set(candidates.map(f=>f.id))
94
+ for(const f of old.values())if(!ids.has(f.id))candidates.push({...f,status:'missing'})
95
+ return {classificationVersion:CLASSIFICATION_VERSION,files:candidates.map(presentClassifiedFile).sort((a,b)=>a.path.localeCompare(b.path)),references:[...refs].map(([path,r])=>({path,source:r.source})),coverage:{files:walk.files.length,originals:candidates.filter(f=>f.status==='available').length,references:refs.size,errors:walk.errors}}
96
+ }
97
+
98
+ async function fileContentKey(file){try{return digest(await readFile(file))}catch(e){if(e.code==='ENOENT')return 'none';throw e}}
99
+ // A full original scan takes seconds on a large library. The patrol runs it even
100
+ // when nothing changed, so compare cheap stat/content hints first and reuse the
101
+ // persisted catalog when every input of the scan is identical.
102
+ async function catalogHints(b){
103
+ const walk=await walkTree(b.root,b.root,{maxFiles:Number.MAX_SAFE_INTEGER,maxDepth:128,followLinks:false})
104
+ const complete=!walk.truncated&&!walk.errors.some(e=>!String(e.reason??e.code??'').includes('link')&&!String(e.reason??e.code??'').includes('LINK'))
105
+ return {walk,hints:{complete,walk:digest(JSON.stringify(walk.files.map(f=>[f.path,f.bytes,f.mtimeMs,f.ctimeMs]))),requests:await fileContentKey(path.join(b.root,'.kbmeta/requests.json')),imports:await fileContentKey(path.join(b.root,'.kbmeta/import-sources.json')),privateDirs:JSON.stringify([...(b.privateDirs??[])])}}
106
+ }
107
+ export async function refreshCatalog(b,options={}){
108
+ if(!catalogActive(b.root))return null
109
+ const file=await safePath(b.root,CATALOG_PATH)
110
+ return locked(file,async()=>{
111
+ const old=await readCatalog(b.root,b.st.kbId)
112
+ const {walk,hints}=await catalogHints(b)
113
+ const prior=old?.scanHints,unchanged=!options.force&&!(options.paths??[]).length&&old&&!old.classificationPending&&old.classificationVersion===CLASSIFICATION_VERSION&&hints.complete&&prior?.complete===true&&prior.walk===hints.walk&&prior.requests===hints.requests&&prior.imports===hints.imports&&prior.privateDirs===hints.privateDirs
114
+ if(unchanged)return old
115
+ const scan=await inspectOriginals(b,{previous:old,...options,walk})
116
+ const privatePaths=files=>files.filter(f=>f.private&&f.status==='available').map(f=>f.path).sort();
117
+ const privacyChanged=JSON.stringify(privatePaths(old.files))!==JSON.stringify(privatePaths(scan.files));
118
+ const next={...old,...scan,classificationPending:false,scanHints:hints};if(old.classificationPending||digest(JSON.stringify(scan.files))!==digest(JSON.stringify(old.files))||digest(JSON.stringify(scan.references))!==digest(JSON.stringify(old.references))){
119
+ if(old.classificationPending){const raw=await readJson(file,null);await atomicJson(await safePath(b.root,'索引层/分类历史/'+Date.now()+'-'+old.revision+'.json',{missing:true}),raw);}
120
+ if(old.classificationPending||privacyChanged)next.policyRevision=(old.policyRevision??0)+1
121
+ next.revision++;next.updatedAt=Date.now();await atomicJson(file,next)
122
+ }else if(!old.scanHints||JSON.stringify(old.scanHints)!==JSON.stringify(hints)){
123
+ // Persist the hints once so later patrols can reuse this catalog without a scan.
124
+ await atomicJson(file,{...old,scanHints:hints})
125
+ }return next})
126
+ }
127
+
128
+ export async function repairClassifications(b){
129
+ const file=await safePath(b.root,CATALOG_PATH)
130
+ return b.core._internal.withMutationLock(b.root,()=>locked(file,async()=>{
131
+ const old=await readJson(file,null);if(!old||old.kbId!==b.st.kbId)throw fail('BINDING_CHANGED','当前库文件目录身份不符')
132
+ const files=old.files.map(presentClassifiedFile),changed=files.filter((f,i)=>f.category!==old.files[i].category||f.presentationRole!==old.files[i].presentationRole).length
133
+ if(!changed&&old.classificationVersion===CLASSIFICATION_VERSION)return {changed:0,revision:old.revision}
134
+ const backup='索引层/分类历史/'+Date.now()+'-'+old.revision+'.json';await atomicJson(await safePath(b.root,backup,{missing:true}),old)
135
+ const next={...old,files,classificationVersion:CLASSIFICATION_VERSION,classificationPending:false,revision:old.revision+1,policyRevision:(old.policyRevision??0)+1,updatedAt:Date.now()};await atomicJson(file,next)
136
+ return {changed,revision:next.revision,backup,manualPreserved:files.filter(f=>f.manual).length}
137
+ }))
138
+ }
139
+
140
+ export async function classifyOriginal(b,args){
141
+ const file=await safePath(b.root,CATALOG_PATH)
142
+ return locked(file,async()=>{const c=structuredClone(await readCatalog(b.root,b.st.kbId));if(!c)throw fail('ARCHITECTURE_REQUIRED','请先迁移到索引架构');if(args.revision!==undefined&&args.revision!==c.revision)throw fail('CONFLICT','分类已改变,请刷新')
143
+ const rel=relativePath(args.path),f=c.files.find(f=>f.path===rel&&f.status==='available');if(!f)throw fail('NOT_FOUND','没有可分类的真实文件')
144
+ await safePath(b.root,rel)
145
+ for(const key of ['kind','category'])if(args[key]!==undefined&&(typeof args[key]!=='string'||!args[key].trim()||args[key].length>200))throw fail('BAD_SETTINGS','分类名称无效')
146
+ if(args.tags!==undefined&&(!Array.isArray(args.tags)||args.tags.length>32||args.tags.some(t=>typeof t!=='string'||t.length>100)))throw fail('BAD_SETTINGS','标签无效')
147
+ if(args.kind!==undefined)f.kind=args.kind;if(args.category!==undefined)f.category=args.category;if(args.tags!==undefined)f.tags=args.tags
148
+ f.private ||=args.kind==='画像'||args.kind==='人物';f.manual=true;c.revision++;c.policyRevision=(c.policyRevision??0)+1;c.updatedAt=Date.now();await atomicJson(file,c)
149
+ return {ok:true,entryId:f.id,path:f.path,revision:f.sha256.slice(0,12),catalogRevision:c.revision,indexSynced:true,original:true}
150
+ })
151
+ }
@@ -0,0 +1,60 @@
1
+ import path from 'node:path'
2
+
3
+ export const CLASSIFICATION_VERSION=3
4
+ const roots={'00-画像':'个人与关系/个人资料','10-项目':'项目与开发','20-知识笔记':'知识笔记','30-人物关系':'个人与关系/人物与关系','40-素材资源':'资料与素材'}
5
+ const clean=s=>String(s??'').replaceAll('\\','/').split('/').map(p=>p.trim().replace(/^\d{2}[-_]/,'')).filter(Boolean)
6
+ const storage=s=>/^(?:原件归档|收件箱|归档|_archive|archive|排除索引分区|未分类|待分类|底稿)$|^20\d{2}[-_年]?\d{2}|^[a-f\d]{12,}$|^\d{6}(?:[-_][a-f\d]+)?$|^\d{8,}$/i.test(s)
7
+
8
+ export function filePresentationRole(f){
9
+ const p=String(f.path??'').replaceAll('\\','/')
10
+ if(/^50-底稿\//.test(p))return 'derived'
11
+ if(/^(00-知识库请求通道|知识库地图)\//.test(p)||/^(AGENTS|INDEX|README|知识库清单)\.md$/i.test(p))return 'support'
12
+ return 'original'
13
+ }
14
+
15
+ export function classifyFile(f){
16
+ const role=filePresentationRole(f)
17
+ if(f.manual)return {category:f.category,classificationSource:'manual',presentationRole:role}
18
+ if(String(f.path??'').replaceAll('\\','/').startsWith('任务成品/'))return {category:path.posix.dirname(String(f.path).replaceAll('\\','/')),classificationSource:'deliverable-directory',presentationRole:'original'}
19
+ if(role==='support')return {category:'知识库管理/请求与导航',classificationSource:'system',presentationRole:role}
20
+ const signal=[path.posix.basename(f.path??''),f.title,...(f.tags??[]),...clean(path.posix.dirname(f.path??'')).filter(p=>!storage(p))].join(' ')
21
+ const rules=[
22
+ [/数学分析|微积分|柯西|函数极限/,'学习与课程/数学分析'],
23
+ [/高等代数|线性代数/,'学习与课程/高等代数'],
24
+ [/集合函数|实变函数|测度论/,'学习与课程/集合与实变函数'],
25
+ [/英语|英文|英语阅读|English|IELTS|TOEFL/i,'学习与课程/英语'],
26
+ [/培养方案|本科培养|课表|课程表|选课|学分|大学生手册|教务/,'学习与课程/课程与教务'],
27
+ [/每日信息|信息报|新闻|资讯/,'资讯与阅读/每日资讯'],
28
+ [/散文|小说|诗歌|诗集|书稿|人物设定|收信人/,'写作与创作/文学写作'],
29
+ [/保险|保单|合同|友邦/,'生活与事务/保险与合同'],
30
+ [/账单|流水|收支|预算|报销/,'生活与事务/账单与财务'],
31
+ [/校园|学生事务|奖学金|助学金|宿舍|竞赛|创新创业大赛/,'学习与课程/校园事务'],
32
+ [/DSH|DeepSeek|知识库|智能体|Agent|MCP|ComfyUI|Qwen|ASR|TTS|API|插件/i,'项目与开发/智能工具'],
33
+ ]
34
+ let category,source
35
+ // An explicit category is user-authored evidence. A storage path is not.
36
+ const explicit=clean(f.originalCategory),legacy=clean(f.category)
37
+ if(explicit.length&&!explicit.some(storage)){category=explicit.join('/');source='metadata'}
38
+ if(!category){const rule=rules.find(([test])=>test.test(signal));if(rule){category=rule[1];source='name-and-tags'}}
39
+ if(!category){
40
+ const originalRoot=String(f.category??'').split('/')[0],meaningful=legacy.filter(s=>!storage(s))
41
+ const mapped=roots[originalRoot]
42
+ if(mapped){const tail=meaningful.slice(1).filter(s=>!/^20\d{2}/.test(s));category=[mapped,...tail].join('/');source='existing-category'}
43
+ else if(meaningful.length&&!/^(50-底稿|90-收件箱|排除索引分区)(\/|$)/.test(f.category??'')){category=meaningful.join('/');source='existing-category'}
44
+ }
45
+ if(!category){
46
+ const ext=path.posix.extname(f.path??'').toLowerCase()
47
+ if(/\.(png|jpe?g|webp|gif|svg|heic)$/.test(ext))category='资料与素材/图片'
48
+ else if(/\.(mp3|m4a|wav|flac|ogg|mp4|mov|mkv|webm)$/.test(ext))category='资料与素材/音视频'
49
+ else if(/\.(zip|7z|rar)$/.test(ext))category='资料与素材/压缩包'
50
+ else if(['画像'].includes(f.kind))category='个人与关系/个人资料'
51
+ else if(['人物','人物关系'].includes(f.kind))category='个人与关系/人物与关系'
52
+ else if(f.kind==='知识')category='知识笔记/其他笔记'
53
+ else if(f.kind==='项目')category='项目与开发/其他项目'
54
+ else category='待分类'
55
+ source=category==='待分类'?'unclassified':'file-type'
56
+ }
57
+ return {category:category.slice(0,200),classificationSource:source,presentationRole:role}
58
+ }
59
+
60
+ export function presentClassifiedFile(f){return {...f,...classifyFile(f),classificationVersion:CLASSIFICATION_VERSION}}
@@ -0,0 +1,66 @@
1
+ import path from 'node:path'
2
+ import { lstat, mkdir, realpath, readFile } from 'node:fs/promises'
3
+
4
+ export const FLOW_WORKSPACE_NAME = '流程工作区'
5
+ const canonical = value => process.platform === 'win32' ? path.resolve(value).toLowerCase() : path.resolve(value)
6
+ const inside = (parent, child) => {
7
+ const relative = path.relative(canonical(parent), canonical(child))
8
+ return relative === '' || (relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative))
9
+ }
10
+
11
+ export function createFlowWorkspaceManager({ getRegistry,isolated=false,displayName=FLOW_WORKSPACE_NAME,singleName=false }) {
12
+ // Serialize registrations across different browser windows and flow buttons.
13
+ let tail = Promise.resolve()
14
+ async function ensure(kbPath) {
15
+ const registry = getRegistry()
16
+ if (!registry || typeof registry.resolveByPath !== 'function' || typeof registry.create !== 'function' || typeof registry.list !== 'function') {
17
+ throw new Error('宿主工作区服务尚未就绪,未创建流程会话')
18
+ }
19
+ const library = await realpath(kbPath)
20
+ const kbId=isolated?JSON.parse(await readFile(path.join(library,'.kbmeta/kb.json'),'utf8')).kbId:null
21
+ if(isolated&&!/^[a-zA-Z0-9-]{1,128}$/.test(kbId))throw Error('知识库身份无效')
22
+ const title=isolated&&!singleName?displayName+' · '+path.basename(library):displayName
23
+ let directory = path.join(path.dirname(library), FLOW_WORKSPACE_NAME,...(isolated?[kbId]:[]))
24
+ if (inside(library, directory)) throw new Error('无法在知识库外建立同级流程工作区:请将知识库放在独立子文件夹中')
25
+ // Check the global display name before touching the filesystem or registering.
26
+ const named = registry.list().find(item => item.title === title)
27
+ if(named&&singleName)directory=path.resolve(named.path)
28
+ if (named && canonical(named.path) !== canonical(directory)) {
29
+ throw new Error('已有同名「流程工作区」指向其他位置:' + named.path + '。请先重命名该工作区,避免流程写错位置')
30
+ }
31
+ try { await mkdir(directory,{recursive:isolated}) } catch (error) { if (error.code !== 'EEXIST') throw new Error('无法创建流程工作区目录:' + error.message) }
32
+ const info = await lstat(directory)
33
+ if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('流程工作区路径已被文件或目录链接占用:' + directory)
34
+ const resolved = await realpath(directory)
35
+ if (inside(library, resolved) || canonical(resolved) !== canonical(directory)) throw new Error('流程工作区实际路径不符合知识库同级目录要求')
36
+ let workspace = await registry.resolveByPath(directory)
37
+ if (!workspace) workspace = await registry.create(directory)
38
+ if (!workspace || !workspace.id || canonical(workspace.path) !== canonical(directory)) throw new Error('宿主未返回正确的流程工作区,未创建会话')
39
+ if (workspace.title !== title) {
40
+ if (typeof workspace.setTitle !== 'function') throw new Error('宿主无法设置流程工作区名称,未创建会话')
41
+ await workspace.setTitle(title)
42
+ }
43
+ return { workspaceId: workspace.id, workspaceName: title, workspacePath: resolved }
44
+ }
45
+ return {
46
+ ensure(kbPath) {
47
+ const current = tail.catch(() => {}).then(() => ensure(kbPath))
48
+ tail = current
49
+ return current
50
+ },
51
+ }
52
+ }
53
+
54
+ export async function prepareFlowConversation(engine, workspaceManager, input) {
55
+ const prepared = await engine.prepareConversation(input)
56
+ if (!prepared.ok) return prepared
57
+ const kbPath = prepared.kbPath || prepared.cwd
58
+ const workspace = await workspaceManager.ensure(kbPath)
59
+ const prompt = prepared.flowId === 'builtin-inbox-organize' ? prepared.prompt : [prepared.prompt, '', '【执行目录】',
60
+ '本会话工作区:' + workspace.workspacePath,
61
+ '知识库绝对路径:' + kbPath,
62
+ '草稿、下载和临时文件保存在流程工作区。知识库操作使用知识库工具或上述绝对路径,不要将当前工作区误当成知识库。',
63
+ '最终成果仍按流程输出规则落库。',
64
+ ].join('\n')
65
+ return { ...prepared, ...workspace, cwd: workspace.workspacePath, prompt }
66
+ }