@kingsleyasher/dsh-knowledge-base 0.0.0-stage → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.en.md +35 -0
- package/ARCHITECTURE.md +40 -0
- package/BETA4.md +31 -0
- package/BETA7.md +35 -0
- package/BETA8.md +39 -0
- package/BETA9.md +38 -0
- package/CONTRIBUTING.md +5 -0
- package/DEVELOPMENT.en.md +26 -0
- package/DEVELOPMENT.md +27 -0
- package/EXISTING-FRAMEWORK-OPTIMIZATION.md +101 -0
- package/LICENSE +21 -0
- package/MONOREPO.md +34 -0
- package/NPM-EDITION.md +12 -0
- package/PARSING-PREVIEW.md +84 -0
- package/PERFORMANCE.md +43 -0
- package/PRIVACY.md +7 -0
- package/PROJECT-RECORD.en.md +782 -0
- package/PROJECT-RECORD.md +793 -0
- package/README.md +109 -3
- package/README.zh-CN.md +117 -0
- package/RELEASE.en.md +559 -0
- package/RELEASE.md +570 -0
- package/RETRIEVAL.md +93 -0
- package/SECURITY.md +7 -0
- package/THIRD-PARTY-NOTICES.md +5 -0
- package/VERSIONING.en.md +51 -0
- package/VERSIONING.md +50 -0
- package/WORKBENCH.en.md +201 -0
- package/WORKBENCH.md +195 -0
- package/browser-extension/background.js +146 -0
- package/browser-extension/icons/knowledge-base-128.png +0 -0
- package/browser-extension/icons/knowledge-base-16.png +0 -0
- package/browser-extension/icons/knowledge-base-32.png +0 -0
- package/browser-extension/icons/knowledge-base-48.png +0 -0
- package/browser-extension/manifest.json +25 -0
- package/browser-extension/options.html +22 -0
- package/browser-extension/options.js +41 -0
- package/browser-extension/popup.html +17 -0
- package/browser-extension/popup.js +58 -0
- package/browser-extension/style.css +11 -0
- package/cordis.patch.yml +88 -0
- package/docs/LEGACY-246-BOOTSTRAP.md +21 -0
- package/docs/LIBRARY-FRAMEWORK-MIGRATION.md +45 -0
- package/docs/ORIGINAL-FILE-INDEX-ARCHITECTURE.md +43 -0
- package/docs/TODO-LIFECYCLE-VALIDATION.md +42 -0
- package/docs/UPDATE-RECOVERY.en.md +18 -0
- package/docs/UPDATE-RECOVERY.md +70 -0
- package/docs/WINDOWS-SIGNING.md +30 -0
- package/docs/client/ARCHITECTURE.en.md +17 -0
- package/docs/client/ARCHITECTURE.md +17 -0
- package/docs/client/CONTRIBUTING.md +5 -0
- package/docs/client/CROSS-VOLUME-TRASH.md +13 -0
- package/docs/client/DEVELOPMENT.en.md +33 -0
- package/docs/client/DEVELOPMENT.md +33 -0
- package/docs/client/EXISTING-FRAMEWORK-OPTIMIZATION.md +3 -0
- package/docs/client/PERFORMANCE.md +3 -0
- package/docs/client/PRIVACY.md +7 -0
- package/docs/client/PROJECT-RECORD.en.md +199 -0
- package/docs/client/PROJECT-RECORD.md +219 -0
- package/docs/client/README.md +55 -0
- package/docs/client/README.zh-CN.md +45 -0
- package/docs/client/RELEASE.en.md +148 -0
- package/docs/client/RELEASE.md +149 -0
- package/docs/client/RETRIEVAL.md +3 -0
- package/docs/client/SECURITY.md +7 -0
- package/docs/client/THIRD-PARTY-NOTICES.md +5 -0
- package/docs/client/VERSIONING.en.md +9 -0
- package/docs/client/VERSIONING.md +9 -0
- package/docs/client/WORKBENCH.en.md +24 -0
- package/docs/client/WORKBENCH.md +24 -0
- package/docs/client/skills/personal-knowledge-base/SKILL.md +38 -0
- package/docs/releases/client-1.0.1.md +32 -0
- package/docs/releases/client-1.0.2.md +32 -0
- package/docs/releases/client-1.0.3.md +31 -0
- package/docs/releases/client-1.1.1.md +28 -0
- package/docs/releases/client-1.1.2.md +16 -0
- package/docs/releases/client-1.1.4.md +7 -0
- package/docs/releases/client-2.0.0.en.md +13 -0
- package/docs/releases/client-2.0.0.md +13 -0
- package/docs/releases/client-2.0.1.en.md +10 -0
- package/docs/releases/client-2.0.1.md +10 -0
- package/docs/releases/client-2.0.3.en.md +8 -0
- package/docs/releases/client-2.0.3.md +8 -0
- package/docs/releases/plugin-2.4.1.md +24 -0
- package/docs/releases/plugin-2.4.10.md +22 -0
- package/docs/releases/plugin-2.4.11.md +14 -0
- package/docs/releases/plugin-2.4.12.md +14 -0
- package/docs/releases/plugin-2.4.13.md +27 -0
- package/docs/releases/plugin-2.4.14.md +18 -0
- package/docs/releases/plugin-2.4.2.md +31 -0
- package/docs/releases/plugin-2.4.3.md +25 -0
- package/docs/releases/plugin-2.4.4.md +31 -0
- package/docs/releases/plugin-2.4.5.md +23 -0
- package/docs/releases/plugin-2.4.6.md +23 -0
- package/docs/releases/plugin-2.4.7.md +14 -0
- package/docs/releases/plugin-2.4.8.md +14 -0
- package/docs/releases/plugin-2.4.9.md +18 -0
- package/docs/releases/plugin-2.5.10.md +11 -0
- package/docs/releases/plugin-2.5.13.en.md +11 -0
- package/docs/releases/plugin-2.5.13.md +11 -0
- package/docs/releases/plugin-2.5.3.md +28 -0
- package/docs/releases/plugin-2.5.4.md +14 -0
- package/docs/releases/plugin-2.5.5.md +16 -0
- package/docs/releases/plugin-2.5.6.md +3 -0
- package/docs/releases/plugin-2.5.7.md +7 -0
- package/docs/releases/plugin-2.5.8.md +7 -0
- package/docs/releases/plugin-2.5.9.md +7 -0
- package/docs/releases/plugin-3.0.0.en.md +13 -0
- package/docs/releases/plugin-3.0.0.md +13 -0
- package/docs/releases/plugin-3.0.1.en.md +10 -0
- package/docs/releases/plugin-3.0.1.md +10 -0
- package/docs/releases/plugin-3.1.3.en.md +11 -0
- package/docs/releases/plugin-3.1.3.md +11 -0
- package/docs/validation/windows-auto-update-2.4.13.md +31 -0
- package/docs/validation/windows-direct-246-to-2413.md +32 -0
- package/package.json +78 -6
- package/packages/kb-contracts/desktop.js +29 -0
- package/packages/kb-contracts/index.js +132 -0
- package/packages/kb-contracts/node.js +3 -0
- package/packages/kb-contracts/package.json +17 -0
- package/packages/kb-contracts/schema.js +42 -0
- package/packages/kb-contracts/tools.js +1 -0
- package/packages/kb-contracts/version-policy.js +45 -0
- package/packages/kb-core/index.js +9 -0
- package/packages/kb-core/package.json +15 -0
- package/packages/kb-core/src/capture-surface.js +22 -0
- package/packages/kb-core/src/documents.js +105 -0
- package/packages/kb-core/src/embedded.js +29 -0
- package/packages/kb-core/src/file-catalog.js +151 -0
- package/packages/kb-core/src/file-classification.js +60 -0
- package/packages/kb-core/src/flow-workspace.js +66 -0
- package/packages/kb-core/src/flows.js +1136 -0
- package/packages/kb-core/src/fsindex.js +293 -0
- package/packages/kb-core/src/import-service.js +486 -0
- package/packages/kb-core/src/importer.js +909 -0
- package/packages/kb-core/src/inbox-flow.js +2 -0
- package/packages/kb-core/src/index-architecture.js +48 -0
- package/packages/kb-core/src/index-maintenance.js +81 -0
- package/packages/kb-core/src/index-policy-service.js +191 -0
- package/packages/kb-core/src/index-policy.js +121 -0
- package/packages/kb-core/src/kbcore.js +2519 -0
- package/packages/kb-core/src/library-framework.js +186 -0
- package/packages/kb-core/src/library-state.js +68 -0
- package/packages/kb-core/src/managed-files.js +69 -0
- package/packages/kb-core/src/map.js +171 -0
- package/packages/kb-core/src/parse-credentials.js +49 -0
- package/packages/kb-core/src/parse-discovery.js +119 -0
- package/packages/kb-core/src/parse-job-storage.js +40 -0
- package/packages/kb-core/src/parse-native.js +87 -0
- package/packages/kb-core/src/parse-presets.js +46 -0
- package/packages/kb-core/src/parse-source-authority.js +72 -0
- package/packages/kb-core/src/parsing.js +2307 -0
- package/packages/kb-core/src/relation-name-lookup.js +43 -0
- package/packages/kb-core/src/retrieval-api.js +79 -0
- package/packages/kb-core/src/retrieval-cache.js +22 -0
- package/packages/kb-core/src/retrieval-chunks.js +128 -0
- package/packages/kb-core/src/retrieval-pool.js +102 -0
- package/packages/kb-core/src/retrieval-worker.js +190 -0
- package/packages/kb-core/src/retrieval.js +618 -0
- package/packages/kb-core/src/runtime-resources.js +73 -0
- package/packages/kb-core/src/service-ownership.js +18 -0
- package/packages/kb-core/src/source-references.js +61 -0
- package/packages/kb-core/src/storage-io.js +121 -0
- package/packages/kb-core/src/system-upgrades.js +104 -0
- package/packages/kb-core/src/workbench-backup.js +219 -0
- package/packages/kb-core/src/workbench-deliverables.js +73 -0
- package/packages/kb-core/src/workbench-files.js +25 -0
- package/packages/kb-core/src/workbench-inbox.js +57 -0
- package/packages/kb-core/src/workbench-links.js +236 -0
- package/packages/kb-core/src/workbench-question.js +131 -0
- package/packages/kb-core/src/workbench-relation-index.js +110 -0
- package/packages/kb-core/src/workbench-state.js +102 -0
- package/packages/kb-core/src/workbench-trash.js +213 -0
- package/packages/kb-core/src/workbench.js +936 -0
- package/packages/kb-service/auth.js +39 -0
- package/packages/kb-service/build.js +18 -0
- package/packages/kb-service/cli.js +26 -0
- package/packages/kb-service/client.js +64 -0
- package/packages/kb-service/clipper.js +15 -0
- package/packages/kb-service/compatibility.js +34 -0
- package/packages/kb-service/desktop-files.js +514 -0
- package/packages/kb-service/desktop-host-links.js +39 -0
- package/packages/kb-service/dsh-broker.js +64 -0
- package/packages/kb-service/dsh-host.js +168 -0
- package/packages/kb-service/dsh-stream-relay.js +32 -0
- package/packages/kb-service/engines.js +32 -0
- package/packages/kb-service/extension.js +8 -0
- package/packages/kb-service/first-library-handoff.js +28 -0
- package/packages/kb-service/handoff-api.js +22 -0
- package/packages/kb-service/host-adapter.js +151 -0
- package/packages/kb-service/host-assets.js +9 -0
- package/packages/kb-service/host-python.js +30 -0
- package/packages/kb-service/host-updates.js +97 -0
- package/packages/kb-service/inbox-host.js +47 -0
- package/packages/kb-service/inbox-jobs.js +54 -0
- package/packages/kb-service/index.js +3 -0
- package/packages/kb-service/io.js +24 -0
- package/packages/kb-service/launch-lock.js +27 -0
- package/packages/kb-service/launcher.js +18 -0
- package/packages/kb-service/legacy-handoff.js +27 -0
- package/packages/kb-service/legacy-ports.js +18 -0
- package/packages/kb-service/main.js +13 -0
- package/packages/kb-service/memory-channel.js +57 -0
- package/packages/kb-service/memory-sync.js +42 -0
- package/packages/kb-service/migration.js +131 -0
- package/packages/kb-service/native.py +216 -0
- package/packages/kb-service/operations.js +19 -0
- package/packages/kb-service/package.json +1 -0
- package/packages/kb-service/runtime.js +185 -0
- package/packages/kb-service/safe-update.js +104 -0
- package/packages/kb-service/service.js +494 -0
- package/packages/kb-service/tool-definitions.json +934 -0
- package/packages/kb-service/tool-router.js +45 -0
- package/packages/kb-service/vector-profiles.js +41 -0
- package/presets/01-knowledge-agent.patch.yml +347 -0
- package/runtime/python/LICENSE.txt +676 -0
- package/runtime/python/_asyncio.pyd +0 -0
- package/runtime/python/_bz2.pyd +0 -0
- package/runtime/python/_ctypes.pyd +0 -0
- package/runtime/python/_decimal.pyd +0 -0
- package/runtime/python/_elementtree.pyd +0 -0
- package/runtime/python/_hashlib.pyd +0 -0
- package/runtime/python/_lzma.pyd +0 -0
- package/runtime/python/_multiprocessing.pyd +0 -0
- package/runtime/python/_overlapped.pyd +0 -0
- package/runtime/python/_queue.pyd +0 -0
- package/runtime/python/_remote_debugging.pyd +0 -0
- package/runtime/python/_socket.pyd +0 -0
- package/runtime/python/_sqlite3.pyd +0 -0
- package/runtime/python/_ssl.pyd +0 -0
- package/runtime/python/_uuid.pyd +0 -0
- package/runtime/python/_wmi.pyd +0 -0
- package/runtime/python/_zoneinfo.pyd +0 -0
- package/runtime/python/_zstd.pyd +0 -0
- package/runtime/python/libcrypto-3.dll +0 -0
- package/runtime/python/libffi-8.dll +0 -0
- package/runtime/python/libssl-3.dll +0 -0
- package/runtime/python/libtommath.dll +0 -0
- package/runtime/python/pyexpat.pyd +0 -0
- package/runtime/python/python.cat +0 -0
- package/runtime/python/python.exe +0 -0
- package/runtime/python/python3.dll +0 -0
- package/runtime/python/python314._pth +5 -0
- package/runtime/python/python314.dll +0 -0
- package/runtime/python/python314.zip +0 -0
- package/runtime/python/pythonw.exe +0 -0
- package/runtime/python/select.pyd +0 -0
- package/runtime/python/sqlite3.dll +0 -0
- package/runtime/python/unicodedata.pyd +0 -0
- package/runtime/python/vcruntime140.dll +0 -0
- package/runtime/python/vcruntime140_1.dll +0 -0
- package/runtime/python/winsound.pyd +0 -0
- package/skills/personal-knowledge-base/SKILL.md +38 -0
- package/src/client/capture-icon-192.png +0 -0
- package/src/client/capture-icon-512.png +0 -0
- package/src/client/capture-icon.svg +12 -0
- package/src/client/capture-sw.js +10 -0
- package/src/client/capture.css +1 -0
- package/src/client/capture.html +1 -0
- package/src/client/capture.js +37 -0
- package/src/client/capture.webmanifest +1 -0
- package/src/client/inbox-organize-bridge.js +22 -0
- package/src/client/index.js +4975 -0
- package/src/client/knowledge-ui.css +255 -0
- package/src/client/pdfjs/LICENSE +177 -0
- package/src/client/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/src/client/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/src/client/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-H.bcmap +4 -0
- package/src/client/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/src/client/pdfjs/cmaps/LICENSE +36 -0
- package/src/client/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Roman.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/src/client/pdfjs/pdf.mjs +26779 -0
- package/src/client/pdfjs/pdf.worker.mjs +63420 -0
- package/src/client/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/src/client/pdfjs/standard_fonts/LICENSE_LIBERATION +102 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/src/client/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/src/client/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_QCMS +22 -0
- package/src/client/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/src/client/pdfjs/wasm/jbig2.wasm +0 -0
- package/src/client/pdfjs/wasm/openjpeg.wasm +0 -0
- package/src/client/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
- package/src/client/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/src/client/todo-lifecycle-ui.js +58 -0
- package/src/client/workbench-features.js +148 -0
- package/src/client/workbench-relations.js +86 -0
- package/src/client/workbench-theme.css +81 -0
- package/src/client/workbench-ui.js +1761 -0
- package/src/host/capture-surface.js +2 -0
- package/src/host/citation-guard.js +40 -0
- package/src/host/command-description.js +43 -0
- package/src/host/flow-workspace.js +62 -0
- package/src/host/flows.js +2 -0
- package/src/host/fsindex.js +2 -0
- package/src/host/gateway.js +916 -0
- package/src/host/import-service.js +2 -0
- package/src/host/importer.js +2 -0
- package/src/host/index-maintenance.js +2 -0
- package/src/host/index-policy-service.js +2 -0
- package/src/host/index-policy.js +2 -0
- package/src/host/index.js +2220 -0
- package/src/host/kbcore.js +2 -0
- package/src/host/managed-files.js +2 -0
- package/src/host/map.js +2 -0
- package/src/host/parse-credentials.js +2 -0
- package/src/host/parse-discovery.js +2 -0
- package/src/host/parse-native.js +2 -0
- package/src/host/parse-presets.js +2 -0
- package/src/host/parse-source-authority.js +2 -0
- package/src/host/parsing.js +7 -0
- package/src/host/relation-name-lookup.js +2 -0
- package/src/host/retrieval-api.js +2 -0
- package/src/host/retrieval-cache.js +2 -0
- package/src/host/retrieval-chunks.js +2 -0
- package/src/host/retrieval-pool.js +2 -0
- package/src/host/retrieval-worker.js +2 -0
- package/src/host/retrieval.js +2 -0
- package/src/host/runtime-resources.js +2 -0
- package/src/host/selftest.js +747 -0
- package/src/host/storage-io.js +2 -0
- package/src/host/system-upgrades.js +2 -0
- package/src/host/todo-lifecycle.js +66 -0
- package/src/host/updates.js +281 -0
- package/src/host/versioning.js +2 -0
- package/src/host/workbench-backup.js +2 -0
- package/src/host/workbench-deliverables.js +2 -0
- package/src/host/workbench-files.js +2 -0
- package/src/host/workbench-inbox.js +2 -0
- package/src/host/workbench-links.js +2 -0
- package/src/host/workbench-question.js +2 -0
- package/src/host/workbench-relation-index.js +2 -0
- package/src/host/workbench-state.js +2 -0
- package/src/host/workbench-trash.js +2 -0
- package/src/host/workbench.js +5 -0
- package/tools/kb-local-model.py +141 -0
- package/tools/kb-pdf-pages.py +78 -0
- package/tools/kb-transactional-update.py +292 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
import { lstat, mkdir, readFile, readdir, link, unlink, rmdir } from 'node:fs/promises'
|
|
4
|
+
import { TEMPLATES, VERSION } from './kbcore.js'
|
|
5
|
+
import { digest, safePath, readJson, atomicJson, locked, fail } from './workbench-state.js'
|
|
6
|
+
import { atomicText } from './managed-files.js'
|
|
7
|
+
|
|
8
|
+
export const FRAMEWORK_VERSION = 'library-framework-v1'
|
|
9
|
+
const PHASES = new Set(['applying', 'failed', 'rolling-back', 'rolled-back', 'completed'])
|
|
10
|
+
const DIRECTORIES = ['00-画像', '10-项目', '20-知识笔记', '30-人物关系', '40-素材资源', '50-底稿', '90-收件箱', '_模板', '_手册']
|
|
11
|
+
const GUIDE = `# 知识库框架与管理规则
|
|
12
|
+
|
|
13
|
+
本框架提供标准目录和模板;已有资料继续留在原位置,自定义目录继续使用。
|
|
14
|
+
|
|
15
|
+
## 标准目录
|
|
16
|
+
|
|
17
|
+
${DIRECTORIES.map(name => '- ' + name + '/').join('\n')}
|
|
18
|
+
|
|
19
|
+
00-画像用于画像,10-项目用于项目,20-知识笔记用于知识,30-人物关系用于人物,40-素材资源用于素材。50-底稿保留加工底稿,90-收件箱接收待整理原件。_模板与_手册不作为普通知识条目检索。
|
|
20
|
+
|
|
21
|
+
## 管理规则
|
|
22
|
+
|
|
23
|
+
- 遵守本库已有 AGENTS.md、用户约定与隐私分区设置;本手册不覆盖既有规则。
|
|
24
|
+
- 原件与来源保持可追溯;框架升级不搬移、删除或重写已有资料。
|
|
25
|
+
- 使用知识库工具创建条目时保留标题、类型、标签、状态、更新时间等字段;来源与推断分别注明。
|
|
26
|
+
- 插件更新与知识库框架迁移分别记录。缺失目录和模板可补齐;内容不同的已有文件保留,需用户查看差异后决定如何合并。
|
|
27
|
+
- 全文和向量索引属于可重建派生数据;模板迁移不会重建资料或调用模型。
|
|
28
|
+
`
|
|
29
|
+
const RULES = '# 知识库管理规则\n\n本库采用可扩展的目录框架,说明见 [_手册/知识库框架.md](_手册/知识库框架.md)。\n\n保留原件、来源与用户自定义结构。整理和生成知识笔记应遵守用户要求及隐私分区设置。不要因插件更新而搬移、删除或覆盖已有资料。\n'
|
|
30
|
+
const INDEX = '# 知识库导航\n\n人工维护的导航页,插件不会覆盖已有内容。\n\n' + DIRECTORIES.map(name => '- [' + name + '/](' + name + '/)').join('\n') + '\n'
|
|
31
|
+
|
|
32
|
+
function catalog() {
|
|
33
|
+
return [...DIRECTORIES.map(name => ({ path: name, kind: 'directory' })),
|
|
34
|
+
...Object.entries(TEMPLATES).map(([name, content]) => ({ path: '_模板/' + name, kind: 'file', content })),
|
|
35
|
+
{ path: '_手册/知识库框架.md', kind: 'file', content: GUIDE },
|
|
36
|
+
{ path: 'AGENTS.md', kind: 'file', content: RULES }, { path: 'INDEX.md', kind: 'file', content: INDEX }]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Additive migration: existing bytes never become replacement/deletion targets.
|
|
40
|
+
// Preview is read-only. Apply needs the same binding and exact preview state.
|
|
41
|
+
export function createLibraryFramework({ binding, now = Date.now, fault = async () => {} }) {
|
|
42
|
+
const plans = new Map()
|
|
43
|
+
const receipt = async b => safePath(b.root, '.kbmeta/framework-migrations/last.json', { missing: true })
|
|
44
|
+
const assertIdentity = async b => {
|
|
45
|
+
if ((await binding(b.st.kbId)).key !== b.key) throw fail('BINDING_CHANGED', '知识库已切换,请重新预览')
|
|
46
|
+
}
|
|
47
|
+
async function inspect(b) {
|
|
48
|
+
const rows = []
|
|
49
|
+
for (const item of catalog()) {
|
|
50
|
+
const file = await safePath(b.root, item.path, { missing: true })
|
|
51
|
+
let stat
|
|
52
|
+
try { stat = await lstat(file) } catch (e) { if (e.code !== 'ENOENT') throw e }
|
|
53
|
+
const beforeHash = stat?.isFile() ? digest(await readFile(file)) : null
|
|
54
|
+
const desiredHash = item.kind === 'file' ? digest(item.content) : null
|
|
55
|
+
const blocked = Boolean(stat && (item.kind === 'file' ? !stat.isFile() : !stat.isDirectory()))
|
|
56
|
+
rows.push({ path: item.path, kind: item.kind, beforeHash, desiredHash,
|
|
57
|
+
status: blocked ? 'blocked' : !stat ? 'create' : item.kind === 'directory' || beforeHash === desiredHash ? 'current' : 'preserved' })
|
|
58
|
+
}
|
|
59
|
+
return rows
|
|
60
|
+
}
|
|
61
|
+
const fingerprint = (b, rows) => digest(JSON.stringify({ key: b.key, version: FRAMEWORK_VERSION, rows }))
|
|
62
|
+
async function status(b) {
|
|
63
|
+
const journal = await readJson(await receipt(b), null)
|
|
64
|
+
if (!journal) return null
|
|
65
|
+
if (journal.format !== 1 || journal.key !== b.key || !PHASES.has(journal.phase) || !Array.isArray(journal.rows) || journal.rows.some(row => !row || typeof row.path !== 'string')) throw fail('STATE_CORRUPT', '迁移记录无法核对,未覆盖')
|
|
66
|
+
return { phase: journal.phase, frameworkVersion: journal.frameworkVersion, programVersion: journal.programVersion,
|
|
67
|
+
created: journal.rows.filter(row => row.state === 'created').map(row => row.path), error: journal.error || null,
|
|
68
|
+
needsRecovery: ['applying', 'failed', 'rolling-back'].includes(journal.phase) }
|
|
69
|
+
}
|
|
70
|
+
async function preview(b) {
|
|
71
|
+
await assertIdentity(b)
|
|
72
|
+
const previous = await status(b), rows = await inspect(b)
|
|
73
|
+
const planId = randomUUID(), revision = fingerprint(b, rows)
|
|
74
|
+
for (const [id, plan] of plans) if (plan.expiresAt < now()) plans.delete(id)
|
|
75
|
+
plans.set(planId, { key: b.key, revision, expiresAt: now() + 600000 })
|
|
76
|
+
return { planId, revision, kbId: b.st.kbId, frameworkVersion: FRAMEWORK_VERSION, programVersion: VERSION,
|
|
77
|
+
rows: rows.map(row => row.status === 'preserved' ? { ...row, candidate: catalog().find(item => item.path === row.path).content } : row),
|
|
78
|
+
canApply: !rows.some(row => row.status === 'blocked') && !previous?.needsRecovery,
|
|
79
|
+
creates: rows.filter(row => row.status === 'create').length, preserved: rows.filter(row => row.status === 'preserved').length,
|
|
80
|
+
previous, movesExistingFiles: false }
|
|
81
|
+
}
|
|
82
|
+
async function loadJournal(b) {
|
|
83
|
+
const file = await receipt(b), journal = await readJson(file, null)
|
|
84
|
+
if (!journal || journal.format !== 1 || journal.key !== b.key || !PHASES.has(journal.phase) || !Array.isArray(journal.rows) || !/^[a-f0-9-]{36}$/.test(journal.id)) throw fail('STATE_CORRUPT', '迁移记录无法核对,未自动恢复')
|
|
85
|
+
// A damaged receipt must not turn arbitrary paths into deletion targets.
|
|
86
|
+
const allowed = new Map(catalog().map(item => [item.path, item]))
|
|
87
|
+
const seen = new Set()
|
|
88
|
+
for (const row of journal.rows) {
|
|
89
|
+
const item = allowed.get(row?.path)
|
|
90
|
+
if (!item || seen.has(row.path) || row.kind !== item.kind || row.beforeHash !== null ||
|
|
91
|
+
row.kind === 'file' && row.desiredHash !== digest(item.content)) throw fail('STATE_CORRUPT', '迁移恢复范围无法核对')
|
|
92
|
+
seen.add(row.path)
|
|
93
|
+
}
|
|
94
|
+
return { file, journal }
|
|
95
|
+
}
|
|
96
|
+
async function rollback(b, file, journal) {
|
|
97
|
+
await assertIdentity(b)
|
|
98
|
+
const owned = journal.rows.filter(row => ['creating', 'created'].includes(row.state))
|
|
99
|
+
const ownedPaths = new Set(owned.map(row => row.path))
|
|
100
|
+
// Validate every target before removing any new file. New user edits stop
|
|
101
|
+
// recovery and remain available for manual reconciliation.
|
|
102
|
+
for (const row of owned) {
|
|
103
|
+
const target = await safePath(b.root, row.path, { missing: true })
|
|
104
|
+
let stat
|
|
105
|
+
try { stat = await lstat(target) } catch (e) { if (e.code === 'ENOENT') continue; throw e }
|
|
106
|
+
if (row.kind === 'file') {
|
|
107
|
+
if (!stat.isFile() || !row.identity || String(stat.ino) !== row.identity.ino || String(stat.dev) !== row.identity.dev || digest(await readFile(target)) !== row.desiredHash) throw fail('MIGRATION_CHANGED', '迁移新增文件已有后续改动,已保留:' + row.path)
|
|
108
|
+
} else {
|
|
109
|
+
if (!stat.isDirectory() || !row.identity || String(stat.ino) !== row.identity.ino || String(stat.dev) !== row.identity.dev || (await readdir(target)).some(name => !ownedPaths.has(row.path + '/' + name))) throw fail('MIGRATION_CHANGED', '迁移目录身份或内容无法核对,已保留:' + row.path)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
journal.phase = 'rolling-back'; await atomicJson(file, journal)
|
|
113
|
+
for (const row of [...owned].reverse()) {
|
|
114
|
+
await assertIdentity(b)
|
|
115
|
+
const target = await safePath(b.root, row.path, { missing: true })
|
|
116
|
+
try {
|
|
117
|
+
const stat = await lstat(target)
|
|
118
|
+
if (String(stat.ino) !== row.identity.ino || String(stat.dev) !== row.identity.dev) throw fail('MIGRATION_CHANGED', '文件身份已改变,未删除:' + row.path)
|
|
119
|
+
if (row.kind === 'file') {
|
|
120
|
+
if (digest(await readFile(target)) !== row.desiredHash) throw fail('MIGRATION_CHANGED', '文件已改变,未删除:' + row.path)
|
|
121
|
+
await unlink(target)
|
|
122
|
+
} else await rmdir(target) // Empty only; never recursive removal.
|
|
123
|
+
} catch (e) { if (e.code !== 'ENOENT') throw e }
|
|
124
|
+
row.state = 'rolled-back'; await atomicJson(file, journal)
|
|
125
|
+
}
|
|
126
|
+
journal.phase = 'rolled-back'; await atomicJson(file, journal)
|
|
127
|
+
}
|
|
128
|
+
async function apply(b, args) {
|
|
129
|
+
if (args.confirm !== true || args.expectedKbId !== b.st.kbId) throw fail('CONFIRM_REQUIRED', '请先预览并确认当前知识库的迁移内容')
|
|
130
|
+
const plan = plans.get(args.planId)
|
|
131
|
+
if (!plan || plan.key !== b.key || plan.revision !== args.revision || plan.expiresAt < now()) throw fail('MIGRATION_STALE', '迁移预览已失效,请重新检查')
|
|
132
|
+
const file = await receipt(b)
|
|
133
|
+
return locked(file, async () => {
|
|
134
|
+
await assertIdentity(b)
|
|
135
|
+
if ((await status(b))?.needsRecovery) throw fail('RECOVERY_REQUIRED', '请先恢复未完成的框架迁移')
|
|
136
|
+
const rows = await inspect(b)
|
|
137
|
+
if (fingerprint(b, rows) !== plan.revision) throw fail('FILE_CHANGED', '预览后框架文件已改变,请重新检查')
|
|
138
|
+
if (rows.some(row => row.status === 'blocked')) throw fail('MIGRATION_BLOCKED', '存在同名文件或目录冲突,未迁移')
|
|
139
|
+
plans.delete(args.planId)
|
|
140
|
+
if (!rows.some(row => row.status === 'create')) return { phase: 'completed', frameworkVersion: FRAMEWORK_VERSION, created: [], preserved: rows.filter(row => row.status === 'preserved').map(row => row.path) }
|
|
141
|
+
const journal = { format: 1, id: args.planId, key: b.key, frameworkVersion: FRAMEWORK_VERSION, programVersion: VERSION,
|
|
142
|
+
phase: 'applying', createdAt: now(), rows: rows.filter(row => row.status === 'create').map(row => ({ ...row, state: 'pending' })) }
|
|
143
|
+
const items = new Map(catalog().map(item => [item.path, item]))
|
|
144
|
+
await atomicJson(file, journal)
|
|
145
|
+
try {
|
|
146
|
+
for (const row of journal.rows) {
|
|
147
|
+
await assertIdentity(b)
|
|
148
|
+
const target = await safePath(b.root, row.path, { missing: true })
|
|
149
|
+
// Persist intent before publication. Hard-linking a completely staged
|
|
150
|
+
// file is atomic and exclusive: a newly appearing file is not replaced.
|
|
151
|
+
if (row.kind === 'file') {
|
|
152
|
+
const staged = await safePath(b.root, '.kbmeta/framework-migrations/' + journal.id + '/staged/' + row.path, { missing: true })
|
|
153
|
+
await atomicText(staged, items.get(row.path).content)
|
|
154
|
+
const identity = await lstat(staged); row.identity = { ino: String(identity.ino), dev: String(identity.dev) }
|
|
155
|
+
row.state = 'creating'; await atomicJson(file, journal)
|
|
156
|
+
try { await link(staged, target) } catch (e) { row.state = 'pending'; await atomicJson(file, journal); throw e }
|
|
157
|
+
} else {
|
|
158
|
+
row.state = 'creating'; await atomicJson(file, journal)
|
|
159
|
+
try { await mkdir(target) } catch (e) { row.state = 'pending'; await atomicJson(file, journal); throw e }
|
|
160
|
+
const identity = await lstat(target); row.identity = { ino: String(identity.ino), dev: String(identity.dev) }
|
|
161
|
+
}
|
|
162
|
+
row.state = 'created'; await atomicJson(file, journal)
|
|
163
|
+
await fault(row.path)
|
|
164
|
+
}
|
|
165
|
+
journal.phase = 'completed'; journal.completedAt = now(); await atomicJson(file, journal)
|
|
166
|
+
} catch (e) {
|
|
167
|
+
journal.phase = 'failed'; journal.error = { code: e.code || 'FRAMEWORK_FAILED', message: '迁移未完成,已有资料保持原位' }; await atomicJson(file, journal)
|
|
168
|
+
try { await rollback(b, file, journal) } catch (recovery) { journal.phase = 'failed'; journal.error.recovery = recovery.code || 'RECOVERY_REQUIRED'; await atomicJson(file, journal) }
|
|
169
|
+
throw fail('FRAMEWORK_FAILED', journal.phase === 'rolled-back' ? '迁移未完成,本次新增内容已撤销,已有资料未改动' : '迁移未完成,部分新增内容需核对;请保留迁移记录并恢复')
|
|
170
|
+
}
|
|
171
|
+
return { phase: journal.phase, frameworkVersion: FRAMEWORK_VERSION, created: journal.rows.map(row => row.path), preserved: rows.filter(row => row.status === 'preserved').map(row => row.path) }
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
async function dispatch(b, args) {
|
|
175
|
+
if (args.op === 'upgrade.framework-preview') return { framework: await preview(b) }
|
|
176
|
+
if (args.op === 'upgrade.framework-status') return { framework: await status(b) }
|
|
177
|
+
if (args.op === 'upgrade.framework-apply') return { framework: await apply(b, args) }
|
|
178
|
+
if (args.op === 'upgrade.framework-recover') {
|
|
179
|
+
const file = await receipt(b)
|
|
180
|
+
await locked(file, async () => { const { journal } = await loadJournal(b); if (['applying', 'failed', 'rolling-back'].includes(journal.phase)) await rollback(b, file, journal) })
|
|
181
|
+
return { framework: await status(b) }
|
|
182
|
+
}
|
|
183
|
+
throw fail('BAD_OPERATION', '未知框架迁移操作')
|
|
184
|
+
}
|
|
185
|
+
return { dispatch }
|
|
186
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { stat, realpath } from 'node:fs/promises'
|
|
3
|
+
import { effectivePrivateDirs, derivedPrivatePartitions, readImportSources } from './fsindex.js'
|
|
4
|
+
import { deliverablesOf } from './workbench-deliverables.js'
|
|
5
|
+
import {readCatalog} from './file-catalog.js'
|
|
6
|
+
import { readIndexPolicy, resolveAssetPath } from './index-policy.js'
|
|
7
|
+
import { digest, fail, safePath, readJson, atomicJson, locked, DEFAULT_PREFERENCES, validatePreferences } from './workbench-state.js'
|
|
8
|
+
|
|
9
|
+
const INITIAL = { format: 1, revision: 0, defaults: DEFAULT_PREFERENCES, libraries: {}, onboarding: {}, pairs: {} }
|
|
10
|
+
const LIBRARY = { format: 1, revision: 0, links: [], captures: [], annotations: [], reading: {}, reviews: {}, tasks: [] }
|
|
11
|
+
|
|
12
|
+
export function createLibraryState({ stateDir, getCore, onMutation = () => {}, sharedState = false, restrictPreferences = x => x, policyScope = () => "" }) {
|
|
13
|
+
const profileFile = path.join(stateDir, 'workbench', 'profile.json')
|
|
14
|
+
const profile = () => readJson(profileFile, INITIAL)
|
|
15
|
+
async function binding(expected) {
|
|
16
|
+
const core = getCore()
|
|
17
|
+
if (!core) throw fail('NOT_READY', '知识库服务尚未就绪')
|
|
18
|
+
const st = await core.status({ bindingOnly: true })
|
|
19
|
+
if (!st.kbPath || !st.kbId) throw fail('UNBOUND', '请先绑定并初始化知识库')
|
|
20
|
+
if (expected != null && expected !== st.kbId) throw fail('BINDING_CHANGED', '知识库已切换,请刷新')
|
|
21
|
+
const root = await realpath(st.kbPath)
|
|
22
|
+
await core._internal.assertRuntimeOwner?.(root)
|
|
23
|
+
const key = digest(st.kbId + '\0' + root.toLowerCase()).slice(0, 24)
|
|
24
|
+
const prefs = await profile()
|
|
25
|
+
if (sharedState) { const policy = await readJson(path.join(root, ".kbmeta/shared-policy.json"), null); if (policy?.preferences) prefs.libraries[key] = { value: policy.preferences, revision: policy.revision } }
|
|
26
|
+
const stored = prefs.libraries[key]
|
|
27
|
+
const preferences = restrictPreferences(validatePreferences(stored?.value ?? DEFAULT_PREFERENCES))
|
|
28
|
+
const conf = await core.getConfig()
|
|
29
|
+
const sources = await readImportSources(root)
|
|
30
|
+
const deliverables = await deliverablesOf(root)
|
|
31
|
+
const privateDirs = effectivePrivateDirs(conf.privateDirs, derivedPrivatePartitions(sources))
|
|
32
|
+
const needsConfirmation = !stored && JSON.stringify(validatePreferences(prefs.defaults)) !== JSON.stringify(validatePreferences(DEFAULT_PREFERENCES))
|
|
33
|
+
const fileCatalog=await readCatalog(root,st.kbId)
|
|
34
|
+
return { core, st, root, key, preferences, needsConfirmation, preferencesRevision: stored?.revision ?? 0, profile: prefs, conf, sources, privateDirs,fileCatalog,
|
|
35
|
+
deliverables, indexPolicy: readIndexPolicy(root), dataFile: sharedState ? path.join(root, '.kbmeta/shared-state.json') : path.join(stateDir, 'workbench', 'libraries', key + '.json') }
|
|
36
|
+
}
|
|
37
|
+
const versionOf = b => digest([b.key, b.preferencesRevision, b.conf.revision, b.indexPolicy?.revision || 0, b.fileCatalog?.policyRevision || 0, ...(policyScope() ? [policyScope()] : [])].join('|')).slice(0, 20)
|
|
38
|
+
const userData = async b => {
|
|
39
|
+
try { await stat(b.dataFile); const data = await readJson(b.dataFile, LIBRARY), policy = readIndexPolicy(b.root); for (const c of data.captures) { c.path = resolveAssetPath(b.root, c.path, policy); if (c.entryPath) c.entryPath = resolveAssetPath(b.root, c.entryPath, policy) }; return data }
|
|
40
|
+
catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
41
|
+
let restored
|
|
42
|
+
try { restored = await readJson(await safePath(b.root, '.kbmeta/workbench-user-data.json'), LIBRARY) }
|
|
43
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; return structuredClone(LIBRARY) }
|
|
44
|
+
if (restored.format !== 1 || !Array.isArray(restored.links) || !Array.isArray(restored.annotations) || !Array.isArray(restored.captures)) throw fail('STATE_CORRUPT', '恢复的用户数据格式不兼容')
|
|
45
|
+
const result = { ...structuredClone(LIBRARY), ...restored }
|
|
46
|
+
const policy = readIndexPolicy(b.root)
|
|
47
|
+
for (const c of result.captures) { c.path = resolveAssetPath(b.root, c.path, policy); if (c.entryPath) c.entryPath = resolveAssetPath(b.root, c.entryPath, policy) }
|
|
48
|
+
return result
|
|
49
|
+
}
|
|
50
|
+
async function mutate(b, args, fn) {
|
|
51
|
+
if (args.expectedKbId !== b.st.kbId) throw fail('IDENTITY_REQUIRED', '写入必须绑定当前知识库身份')
|
|
52
|
+
return locked(b.dataFile, async () => {
|
|
53
|
+
const current = await binding(b.st.kbId)
|
|
54
|
+
if (versionOf(current) !== versionOf(b)) throw fail('SETTINGS_CHANGED', '设置已改变,请刷新')
|
|
55
|
+
const data = await userData(b)
|
|
56
|
+
if (args.expectedRevision !== data.revision) throw fail('CONFLICT', '内容已被其他窗口修改,请刷新后重试')
|
|
57
|
+
const result = await fn(data)
|
|
58
|
+
await binding(b.st.kbId)
|
|
59
|
+
if (sharedState && args.operationId) data.lastOperationId = args.operationId
|
|
60
|
+
data.revision++
|
|
61
|
+
await atomicJson(b.dataFile, data)
|
|
62
|
+
onMutation(args)
|
|
63
|
+
return { ...result, revision: data.revision }
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
return { profileFile, profile, binding, versionOf, userData, mutate,
|
|
67
|
+
policySnapshot: b => ({ kbId: b.st.kbId, key: b.key, policyVersion: versionOf(b), configurationRevision: b.conf.revision, preferencesRevision: b.preferencesRevision, indexPolicyRevision: b.indexPolicy?.revision || 0 }) }
|
|
68
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { mkdir, readFile, writeFile, rename, unlink } from 'node:fs/promises'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { digest, safePath, readJson, atomicJson, locked, fail } from './workbench-state.js'
|
|
5
|
+
|
|
6
|
+
export async function atomicText(file, content) {
|
|
7
|
+
await mkdir(path.dirname(file), { recursive: true })
|
|
8
|
+
const temp = file + '.' + randomUUID() + '.tmp'
|
|
9
|
+
try { await writeFile(temp, content, { flag: 'wx' }); await rename(temp, file) }
|
|
10
|
+
finally { await unlink(temp).catch(() => {}) }
|
|
11
|
+
}
|
|
12
|
+
const readOptional = file => readFile(file).catch(e => { if (e.code === 'ENOENT') return null; throw e })
|
|
13
|
+
|
|
14
|
+
// Shared by bundled skills and library templates. Applied hashes only advance
|
|
15
|
+
// after a successful write/read-back; preserving local edits never advances them.
|
|
16
|
+
export async function syncManagedFiles({ root, items, manifest = '.kb-managed.json', backup = '.kb-managed-backups', candidates = '.kb-managed-candidates', check = async () => {}, now = Date.now }) {
|
|
17
|
+
await mkdir(root, { recursive: true })
|
|
18
|
+
const manifestFile = await safePath(root, manifest, { missing: true })
|
|
19
|
+
return locked(manifestFile, async () => {
|
|
20
|
+
const old = await readJson(manifestFile, {})
|
|
21
|
+
if(old.format!==undefined&&old.format!==2)throw fail('STATE_CORRUPT','托管清单格式不兼容,未覆盖')
|
|
22
|
+
const records = old.format === 2 ? old.files : Object.fromEntries(Object.entries(old).filter(([,v]) => typeof v === 'string').map(([k,v]) => [k, { appliedHash: v }]))
|
|
23
|
+
if (!records || typeof records !== 'object' || Array.isArray(records)) throw fail('STATE_CORRUPT', '托管清单损坏,已保留文件')
|
|
24
|
+
const state = { format: 2, files: records }, result = []
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
await check()
|
|
27
|
+
const file = await safePath(root, item.path, { missing: true }), current = await readOptional(file)
|
|
28
|
+
const desired = Buffer.from(item.content), previous = records[item.path] || {}
|
|
29
|
+
let existing = current, replacement = desired, malformed = false
|
|
30
|
+
if (item.block && current) {
|
|
31
|
+
const text = current.toString('utf8'), { start, end } = item.block
|
|
32
|
+
const a = text.indexOf(start), z = text.indexOf(end, a + start.length)
|
|
33
|
+
malformed = a < 0 || z < 0 || text.indexOf(start, a + start.length) >= 0 || text.indexOf(end, z + end.length) >= 0
|
|
34
|
+
if (!malformed) { existing = Buffer.from(text.slice(a, z + end.length)); replacement = Buffer.from(text.slice(0,a) + item.content + text.slice(z + end.length)) }
|
|
35
|
+
} else if (item.block) malformed = true
|
|
36
|
+
const currentHash = current ? digest(current) : null, appliedPart = existing ? digest(existing) : null, desiredHash = digest(desired)
|
|
37
|
+
let status = malformed ? 'conflict' : appliedPart === desiredHash ? 'current' : !current ? 'created' : previous.appliedHash === appliedPart || (item.knownHashes || []).includes(appliedPart) ? 'updated' : 'conflict'
|
|
38
|
+
const record = { ...previous, desiredHash, currentHash, version: item.version, status, needsNewSession: Boolean(item.instructions) }
|
|
39
|
+
if (status === 'conflict') {
|
|
40
|
+
if (previous.status === 'kept-local' && previous.desiredHash === desiredHash && previous.currentHash === currentHash) record.status = 'kept-local'
|
|
41
|
+
record.candidate = candidates + '/' + item.path + '.new'
|
|
42
|
+
await atomicText(await safePath(root, record.candidate, { missing: true }), desired)
|
|
43
|
+
} else {
|
|
44
|
+
if (status !== 'current') {
|
|
45
|
+
if (current) {
|
|
46
|
+
record.backup = backup + '/' + now() + '-' + randomUUID() + '/' + item.path + '.bak'
|
|
47
|
+
await atomicText(await safePath(root, record.backup, { missing: true }), current)
|
|
48
|
+
}
|
|
49
|
+
records[item.path] = { ...record, status: 'applying' }; await atomicJson(manifestFile, state)
|
|
50
|
+
await check()
|
|
51
|
+
const live = await readOptional(file)
|
|
52
|
+
if ((live ? digest(live) : null) !== currentHash) throw fail('FILE_CHANGED', '托管文件已改变,未覆盖')
|
|
53
|
+
await atomicText(file, replacement)
|
|
54
|
+
if (!(await readFile(file)).equals(replacement)) throw fail('UPGRADE_VERIFY', '托管文件写入校验失败')
|
|
55
|
+
}
|
|
56
|
+
record.appliedHash = desiredHash
|
|
57
|
+
record.currentHash = digest(replacement)
|
|
58
|
+
delete record.candidate
|
|
59
|
+
}
|
|
60
|
+
records[item.path] = record
|
|
61
|
+
await atomicJson(manifestFile, state)
|
|
62
|
+
result.push({ path: item.path, ...record })
|
|
63
|
+
}
|
|
64
|
+
const paths=new Set(items.map(i=>i.path))
|
|
65
|
+
for(const [file,record] of Object.entries(records))if(!paths.has(file)){record.status='retired-pending';result.push({path:file,...record})}
|
|
66
|
+
await atomicJson(manifestFile,state)
|
|
67
|
+
return { files: result, conflicts: result.filter(r => ['conflict','retired-pending'].includes(r.status)).length }
|
|
68
|
+
})
|
|
69
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// 知识库地图(只读扫描):给顶栏「知识库」页签用。
|
|
2
|
+
// 铁律:
|
|
3
|
+
// · 只读 —— 只 readdir/stat,绝不写、不建索引、不建 .kbmeta
|
|
4
|
+
// · 隐私区(默认 00-画像、30-人物关系)只出计数与体积,不出文件名,不进最近变更
|
|
5
|
+
// · 不跟随符号链接/Junction(避免扫到库外)
|
|
6
|
+
// · 根目录默认是**当前绑定**的库;要观察别的只读库必须显式传 root + readOnly
|
|
7
|
+
// R5 变更:返回 status(ok/empty/missing/denied/partial/not-a-directory)+ errors[],
|
|
8
|
+
// 让"空库 / 路径失效 / 无权限 / 部分扫描"四种情况不再长得一样;
|
|
9
|
+
// 系统元数据与备份目录(.kbmeta、.kb-state)不进分区统计与最近变更。
|
|
10
|
+
import { readdir, stat } from 'node:fs/promises'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { privateRootOf } from './fsindex.js'
|
|
13
|
+
import { readIndexPolicy, policyExcluded } from './index-policy.js'
|
|
14
|
+
|
|
15
|
+
export const MAP_RULES_VERSION = 'map-v2'
|
|
16
|
+
export const DEFAULT_PRIVATE = ['00-画像', '30-人物关系']
|
|
17
|
+
export const DEFAULT_SKIP = ['.kb', '.kbmeta', '.kb-state', '_模板', '_手册', '知识库地图']
|
|
18
|
+
const ROOT_FILES_NAME = '(根目录文件)'
|
|
19
|
+
|
|
20
|
+
const isDir = (d) => d.isDirectory()
|
|
21
|
+
const skipName = (name, skip) => skip.includes(name)
|
|
22
|
+
|
|
23
|
+
function toPosix(p) {
|
|
24
|
+
return String(p).split(path.sep).join('/')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function walk(dir, ctx, rel = '') {
|
|
28
|
+
let items = []
|
|
29
|
+
try {
|
|
30
|
+
items = await readdir(dir, { withFileTypes: true })
|
|
31
|
+
} catch (error) {
|
|
32
|
+
ctx.errors.push(`${rel || '.'}: ${(error && (error.code || error.message)) ?? error}`)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
if (skipName(item.name, ctx.skip)) continue
|
|
37
|
+
// 链接一律不跟(与 kbcore 的 scanDisk 口径一致)
|
|
38
|
+
if (item.isSymbolicLink()) {
|
|
39
|
+
ctx.links += 1
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
const full = path.join(dir, item.name)
|
|
43
|
+
const relPath = rel ? rel + '/' + item.name : item.name
|
|
44
|
+
if (policyExcluded(ctx.policy, relPath)) continue
|
|
45
|
+
if (isDir(item)) {
|
|
46
|
+
ctx.dirs += 1
|
|
47
|
+
await walk(full, ctx, relPath)
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
let st = null
|
|
51
|
+
try {
|
|
52
|
+
st = await stat(full)
|
|
53
|
+
} catch (error) {
|
|
54
|
+
ctx.errors.push(`${relPath}: ${(error && (error.code || error.message)) ?? error}`)
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
ctx.files += 1
|
|
58
|
+
ctx.bytes += st.size
|
|
59
|
+
// 根目录下的散文件不算「分区」,统一聚到一行,避免把 AGENTS.md 当成板块
|
|
60
|
+
const isTopLevelFile = !relPath.includes('/')
|
|
61
|
+
const top = isTopLevelFile ? ROOT_FILES_NAME : relPath.slice(0, relPath.indexOf('/'))
|
|
62
|
+
const sec = ctx.sections.get(top) ?? { name: top, files: 0, bytes: 0, latestAt: 0, rootFiles: isTopLevelFile }
|
|
63
|
+
sec.files += 1
|
|
64
|
+
sec.bytes += st.size
|
|
65
|
+
if (st.mtimeMs > sec.latestAt) sec.latestAt = st.mtimeMs
|
|
66
|
+
ctx.sections.set(top, sec)
|
|
67
|
+
if (!ctx.privateTop.has(top)) {
|
|
68
|
+
ctx.recent.push({ path: relPath, bytes: st.size, mtimeMs: st.mtimeMs })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 扫描一个只读根目录,返回地图数据。
|
|
75
|
+
* @param {string} root 绝对路径
|
|
76
|
+
* @param {{privateDirs?: string[], skipDirs?: string[], recentLimit?: number, readOnly?: boolean}} opts
|
|
77
|
+
*/
|
|
78
|
+
export async function buildMap(root, opts = {}) {
|
|
79
|
+
const privateDirs = opts.privateDirs ?? DEFAULT_PRIVATE
|
|
80
|
+
const skip = [...DEFAULT_SKIP, ...(opts.skipDirs ?? [])]
|
|
81
|
+
const recentLimit = opts.recentLimit ?? 12
|
|
82
|
+
const absRoot = path.resolve(root)
|
|
83
|
+
const started = Date.now()
|
|
84
|
+
const base = {
|
|
85
|
+
root: toPosix(absRoot),
|
|
86
|
+
scannedAt: new Date().toISOString(),
|
|
87
|
+
elapsedMs: 0,
|
|
88
|
+
rulesVersion: MAP_RULES_VERSION,
|
|
89
|
+
readOnly: opts.readOnly === true,
|
|
90
|
+
sections: [],
|
|
91
|
+
recent: [],
|
|
92
|
+
privacy: { privateDirs, note: '标记 private 的分区只统计数量与体积,不列出文件名,也不进入最近变更' },
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 1) 根目录本身要先判"在不在 / 是不是目录 / 能不能读"——三者不能都显示成"0 文件的正常库"
|
|
96
|
+
let st = null
|
|
97
|
+
let statError = null
|
|
98
|
+
try {
|
|
99
|
+
st = await stat(absRoot)
|
|
100
|
+
} catch (error) {
|
|
101
|
+
statError = error
|
|
102
|
+
}
|
|
103
|
+
if (st === null) {
|
|
104
|
+
const code = statError && (statError.code || statError.message)
|
|
105
|
+
const missing = code === 'ENOENT' || code === 'ENOTDIR'
|
|
106
|
+
return {
|
|
107
|
+
...base,
|
|
108
|
+
elapsedMs: Date.now() - started,
|
|
109
|
+
status: missing ? 'missing' : 'denied',
|
|
110
|
+
errors: [`根目录不可访问(${code ?? 'unknown'}):${base.root}`],
|
|
111
|
+
totals: { files: 0, dirs: 0, bytes: 0, links: 0, sections: 0 },
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!st.isDirectory()) {
|
|
115
|
+
return {
|
|
116
|
+
...base,
|
|
117
|
+
elapsedMs: Date.now() - started,
|
|
118
|
+
status: 'not-a-directory',
|
|
119
|
+
errors: [`根目录不是目录:${base.root}`],
|
|
120
|
+
totals: { files: 0, dirs: 0, bytes: 0, links: 0, sections: 0 },
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const ctx = { files: 0, dirs: 0, bytes: 0, links: 0, sections: new Map(), recent: [], skip, privateTop: new Set(privateDirs), errors: [], policy: readIndexPolicy(absRoot) }
|
|
125
|
+
await walk(absRoot, ctx)
|
|
126
|
+
|
|
127
|
+
const sections = [...ctx.sections.values()]
|
|
128
|
+
.map((s) => ({
|
|
129
|
+
name: s.name,
|
|
130
|
+
files: s.files,
|
|
131
|
+
bytes: s.bytes,
|
|
132
|
+
latestAt: s.latestAt ? new Date(s.latestAt).toISOString() : null,
|
|
133
|
+
private: privateDirs.includes(s.name),
|
|
134
|
+
rootFiles: s.rootFiles === true,
|
|
135
|
+
}))
|
|
136
|
+
// 目录按名字排,根目录文件永远排最后
|
|
137
|
+
.sort((a, b) => {
|
|
138
|
+
if (a.rootFiles !== b.rootFiles) return a.rootFiles ? 1 : -1
|
|
139
|
+
return a.name > b.name ? 1 : a.name < b.name ? -1 : 0
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const recent = ctx.recent
|
|
143
|
+
// R3:嵌套私密目录(如 10-项目/私密)也不进"最近变更"
|
|
144
|
+
.filter((r) => privateRootOf(r.path, privateDirs) === null)
|
|
145
|
+
.sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
146
|
+
.slice(0, recentLimit)
|
|
147
|
+
.map((r) => ({ path: r.path, bytes: r.bytes, mtime: new Date(r.mtimeMs).toISOString() }))
|
|
148
|
+
|
|
149
|
+
// R3:错误详情里的私密路径/文件名同样要隐藏(否则等于从错误信息里泄漏清单)
|
|
150
|
+
const errors = ctx.errors.map((e) => {
|
|
151
|
+
const head = String(e).split(':')[0]
|
|
152
|
+
return privateRootOf(head, privateDirs) !== null ? '(私密路径):枚举异常(路径与文件名已隐藏)' : e
|
|
153
|
+
})
|
|
154
|
+
const status = errors.length > 0 ? 'partial' : ctx.files === 0 ? 'empty' : 'ok'
|
|
155
|
+
return {
|
|
156
|
+
...base,
|
|
157
|
+
elapsedMs: Date.now() - started,
|
|
158
|
+
status,
|
|
159
|
+
errors,
|
|
160
|
+
totals: {
|
|
161
|
+
files: ctx.files,
|
|
162
|
+
dirs: ctx.dirs,
|
|
163
|
+
bytes: ctx.bytes,
|
|
164
|
+
links: ctx.links,
|
|
165
|
+
// 只数真分区:根目录散文件那一行是聚合项,不算分区
|
|
166
|
+
sections: sections.filter((s) => s.rootFiles !== true).length,
|
|
167
|
+
},
|
|
168
|
+
sections,
|
|
169
|
+
recent,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile, mkdir, writeFile, rename } from 'node:fs/promises'
|
|
2
|
+
import { spawn } from 'node:child_process'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
// The fixed helper reads its input over stdin; no key is placed in argv, an
|
|
7
|
+
// environment variable, or a temporary plaintext file. No plaintext fallback.
|
|
8
|
+
function dpapi(mode, value) {
|
|
9
|
+
if (process.platform !== 'win32') throw new Error('当前平台没有可用的凭据存储;请使用环境变量引用')
|
|
10
|
+
const operation = mode === 'protect' ? 'Protect' : 'Unprotect'
|
|
11
|
+
const script = `Add-Type -AssemblyName System.Security; $s=[Console]::In.ReadToEnd(); $b=[Convert]::FromBase64String($s); $r=[Security.Cryptography.ProtectedData]::${operation}($b,$null,[Security.Cryptography.DataProtectionScope]::CurrentUser); [Console]::Out.Write([Convert]::ToBase64String($r))`
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const c = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
14
|
+
let out = ''
|
|
15
|
+
const timer = setTimeout(() => { c.kill(); reject(new Error('凭据存储操作超时')) }, 15000)
|
|
16
|
+
c.stdout.on('data', b => { out += b; if (out.length > 100000) c.kill() })
|
|
17
|
+
c.stderr.resume()
|
|
18
|
+
c.on('error', () => { clearTimeout(timer); reject(new Error('无法调用 Windows 凭据保护')) })
|
|
19
|
+
c.on('close', code => { clearTimeout(timer); code === 0 ? resolve(Buffer.from(out.trim(), 'base64')) : reject(new Error('Windows 凭据保护失败')) })
|
|
20
|
+
c.stdin.on('error', () => {})
|
|
21
|
+
c.stdin.end(Buffer.from(value).toString('base64'))
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createParseCredentials(stateDir, { protect = b => dpapi('protect', b), unprotect = b => dpapi('unprotect', b) } = {}) {
|
|
26
|
+
const dir = path.join(stateDir, 'parse-credentials')
|
|
27
|
+
const valid = ref => /^KB_STORED_[A-F0-9]{32}$/.test(ref || '')
|
|
28
|
+
return {
|
|
29
|
+
async save(values) {
|
|
30
|
+
if (!values?.apiKey || typeof values.apiKey !== 'string' || values.apiKey.length > 8192 || (values.secretKey && (typeof values.secretKey !== 'string' || values.secretKey.length > 8192))) throw new Error('请填写有效的 API Key')
|
|
31
|
+
const ref = 'KB_STORED_' + randomUUID().replaceAll('-', '').toUpperCase()
|
|
32
|
+
const encrypted = await protect(Buffer.from(JSON.stringify({ apiKey: values.apiKey.trim(), secretKey: (values.secretKey || '').trim() }), 'utf8'))
|
|
33
|
+
await mkdir(dir, { recursive: true })
|
|
34
|
+
const file = path.join(dir, ref)
|
|
35
|
+
await writeFile(file + '.tmp', encrypted, { mode: 0o600 })
|
|
36
|
+
await rename(file + '.tmp', file)
|
|
37
|
+
return ref
|
|
38
|
+
},
|
|
39
|
+
async read(ref) {
|
|
40
|
+
if (!ref) return {}
|
|
41
|
+
if (!valid(ref)) return { apiKey: process.env[ref] || '' }
|
|
42
|
+
try { return JSON.parse((await unprotect(await readFile(path.join(dir, ref)))).toString('utf8')) }
|
|
43
|
+
catch { throw new Error('无法读取保存的凭据,请重新填写') }
|
|
44
|
+
},
|
|
45
|
+
async configured(ref) {
|
|
46
|
+
try { return Boolean((await this.read(ref)).apiKey) } catch { return false }
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|