@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.
- 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 +9 -0
- package/PARSING-PREVIEW.md +84 -0
- package/PERFORMANCE.md +43 -0
- package/PRIVACY.md +7 -0
- package/PROJECT-RECORD.en.md +778 -0
- package/PROJECT-RECORD.md +789 -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 +11 -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 +4980 -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 +2224 -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 +284 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto'
|
|
2
|
+
import {safePath,atomicJson,locked,digest,fail} from './workbench-state.js'
|
|
3
|
+
import {CATALOG_PATH,CATALOG_FORMAT,readCatalog,inspectOriginals,refreshCatalog,classifyOriginal,repairClassifications} from './file-catalog.js'
|
|
4
|
+
|
|
5
|
+
export function createIndexArchitecture({binding,now=Date.now}){
|
|
6
|
+
const plans=new Map(),fingerprint=scan=>digest(JSON.stringify({files:scan.files,references:scan.references}))
|
|
7
|
+
const check=async b=>{if((await binding(b.st.kbId)).key!==b.key)throw fail('BINDING_CHANGED','资料库已改变,请重新预览')}
|
|
8
|
+
async function preview(b){
|
|
9
|
+
await check(b);const previous=await readCatalog(b.root,b.st.kbId),scan=await inspectOriginals(b,{previous})
|
|
10
|
+
const planId=randomUUID(),revision=fingerprint(scan);plans.set(planId,{key:b.key,revision,expiresAt:now()+600000,previousRevision:previous?.revision??null,files:scan.files})
|
|
11
|
+
for(const [id,p]of plans)if(p.expiresAt<now())plans.delete(id)
|
|
12
|
+
while(plans.size>10)plans.delete(plans.keys().next().value)
|
|
13
|
+
return {planId,revision,kbId:b.st.kbId,root:b.root,active:!!previous,canApply:true,coverage:scan.coverage,
|
|
14
|
+
files:scan.files.map(({identity,sha256,...f})=>f),references:scan.references,storage:CATALOG_PATH,movesExistingFiles:false}
|
|
15
|
+
}
|
|
16
|
+
async function apply(b,args){
|
|
17
|
+
if(args.confirm!==true||args.expectedKbId!==b.st.kbId)throw fail('CONFIRM_REQUIRED','请先预览并确认当前资料库')
|
|
18
|
+
const p=plans.get(args.planId);if(!p||p.key!==b.key||p.revision!==args.revision||p.expiresAt<now())throw fail('MIGRATION_STALE','预览已失效,请重新预览')
|
|
19
|
+
const file=await safePath(b.root,CATALOG_PATH,{missing:true})
|
|
20
|
+
const published=await b.core._internal.withMutationLock(b.root,()=>locked(file,async()=>{
|
|
21
|
+
await check(b);const previous=await readCatalog(b.root,b.st.kbId)
|
|
22
|
+
if((previous?.revision??null)!==p.previousRevision)throw fail('CONFLICT','另一个窗口已迁移或修改分类,请重新预览')
|
|
23
|
+
const scan=await inspectOriginals(b,{previous});if(fingerprint(scan)!==p.revision)throw fail('FILE_CHANGED','预览后原文件已改变,请重新预览')
|
|
24
|
+
const c={format:CATALOG_FORMAT,kbId:b.st.kbId,key:b.key,revision:(previous?.revision??0)+1,policyRevision:(previous?.policyRevision??0)+1,createdAt:previous?.createdAt??now(),updatedAt:now(),migrationId:args.planId,...scan}
|
|
25
|
+
await check(b);await atomicJson(file,c);plans.delete(args.planId);return c
|
|
26
|
+
}))
|
|
27
|
+
// The catalog is the atomic activation point. A failed index rebuild is
|
|
28
|
+
// explicitly pending; originals and the previous fulltext index are retained.
|
|
29
|
+
const result=await b.core.maintainIndex({expectedKbId:b.st.kbId,full:true,knownRemovedPaths:published.references.map(r=>r.path)})
|
|
30
|
+
return {active:true,phase:result.ok?'completed':'index-pending',catalogRevision:published.revision,coverage:published.coverage,index:{ok:result.ok,reason:result.reason??null},storage:CATALOG_PATH}
|
|
31
|
+
}
|
|
32
|
+
async function dispatch(b,args){
|
|
33
|
+
if(args.op==='architecture.preview')return {architecture:await preview(b)}
|
|
34
|
+
if(args.op==='architecture.preview-files'){
|
|
35
|
+
const p=plans.get(args.planId);if(!p||p.key!==b.key||p.expiresAt<now())throw fail('MIGRATION_STALE','预览已失效,请重新预览')
|
|
36
|
+
return {architecture:{planId:args.planId,revision:p.revision,files:p.files}}
|
|
37
|
+
}
|
|
38
|
+
if(args.op==='architecture.apply')return {architecture:await apply(b,args)}
|
|
39
|
+
if(args.op==='architecture.refresh'){await check(b);if(!await readCatalog(b.root,b.st.kbId))throw fail('ARCHITECTURE_REQUIRED','请先预览并确认迁移');await refreshCatalog(b,{force:true});const result=await b.core.maintainIndex({expectedKbId:b.st.kbId,full:true});return {architecture:{active:true,phase:result.ok?'completed':'index-pending',index:result}}}
|
|
40
|
+
if(args.op==='architecture.classify'){await check(b);return classifyOriginal(b,args)}
|
|
41
|
+
if(args.op==='architecture.reclassify'){await check(b);return {classification:await repairClassifications(b)}}
|
|
42
|
+
const catalog=await readCatalog(b.root,b.st.kbId)
|
|
43
|
+
if(args.op==='architecture.status')return {architecture:{active:!!catalog,root:b.root,kbId:b.st.kbId,format:catalog?.format,revision:catalog?.revision,coverage:catalog?.coverage,storage:CATALOG_PATH}}
|
|
44
|
+
if(['architecture.files','architecture.categories'].includes(args.op))return {architecture:{active:!!catalog,revision:catalog?.revision,files:catalog?.files??[]}}
|
|
45
|
+
throw fail('BAD_OPERATION','未知索引架构操作')
|
|
46
|
+
}
|
|
47
|
+
return {dispatch}
|
|
48
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { watch as fsWatch } from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { readIndexPolicy, policyExcluded } from './index-policy.js'
|
|
4
|
+
|
|
5
|
+
// Independent of page refresh. It observes only the currently bound root and
|
|
6
|
+
// excludes generated state; a missed watch event is repaired by the patrol.
|
|
7
|
+
export function createIndexMaintenance({ getCore, onChange = () => {}, watch = fsWatch, resources, now = Date.now, timers = globalThis, quietMs = 750, maximumWaitMs = 5000, minimumMs = 1000, patrolMs = 300000 } = {}) {
|
|
8
|
+
let watcher, root = null, revision = null, enabled = false, stopped = false, ticking = false
|
|
9
|
+
let pending = false, lastEvent = 0, lastStart = -Infinity, lastPatrol = 0, failures = 0, running = false, controller
|
|
10
|
+
let firstPending = null
|
|
11
|
+
let excludes = [], state = 'idle'
|
|
12
|
+
let lastWatchTry = -Infinity, retryAt = 0, transient = false
|
|
13
|
+
const dirty = new Set()
|
|
14
|
+
const relevant = file => {
|
|
15
|
+
const rel = String(file || '').replaceAll('\\', '/')
|
|
16
|
+
const parts = rel.split('/')
|
|
17
|
+
return !parts.some(p => ['.kbmeta', '.kb-state', '索引层', '.git'].includes(p)) && !excludes.some(p => rel === p || rel.startsWith(p + '/')) && !rel.includes('.tmp-') && (!rel.startsWith('90-收件箱/') || !policyExcluded(readIndexPolicy(root), rel)) && path.basename(rel) !== 'INDEX.md' && !(parts.length === 1 && ['README.md', 'AGENTS.md', '知识库清单.md'].includes(rel))
|
|
18
|
+
}
|
|
19
|
+
const mark = file => { if (relevant(file) && (failures < 3 || transient)) { if (transient) { failures = 0; retryAt = 0 }; if (file) dirty.add(String(file).replaceAll('\\', '/')); if (firstPending === null) firstPending = now(); pending = true; lastEvent = now(); if (!running) state = 'waiting' } }
|
|
20
|
+
function connect() {
|
|
21
|
+
lastWatchTry = now()
|
|
22
|
+
try {
|
|
23
|
+
const current = watch(root, { recursive: true }, (_event, file) => mark(file))
|
|
24
|
+
watcher = current; watcher.unref?.()
|
|
25
|
+
current.on?.('error', () => {
|
|
26
|
+
if (watcher !== current) return
|
|
27
|
+
current.close(); watcher = null; pending = true; state = 'watch-unavailable'
|
|
28
|
+
})
|
|
29
|
+
} catch { watcher = null; pending = true; state = 'watch-unavailable' }
|
|
30
|
+
}
|
|
31
|
+
function failure(reason) {
|
|
32
|
+
failures++
|
|
33
|
+
transient = ['ENOSPC', 'EACCES', 'EPERM', 'EBUSY', 'source-unstable', 'ENOENT', 'FILE_CHANGED', 'maintenance-failed'].includes(reason)
|
|
34
|
+
const hard = ['index-drop-confirmation', 'index-kbid-mismatch'].includes(reason)
|
|
35
|
+
state = hard || failures >= 3 && !transient ? 'paused' : 'retrying'
|
|
36
|
+
if (hard) failures = 3
|
|
37
|
+
retryAt = now() + (failures >= 3 ? patrolMs : Math.min(patrolMs, minimumMs * 2 ** (failures - 1)))
|
|
38
|
+
pending = state === 'retrying'
|
|
39
|
+
}
|
|
40
|
+
async function tick() {
|
|
41
|
+
let started = false, attempted = []
|
|
42
|
+
if (stopped || ticking) return
|
|
43
|
+
const core = getCore()
|
|
44
|
+
if (!core) return
|
|
45
|
+
ticking = true
|
|
46
|
+
try {
|
|
47
|
+
const gate = await core.configGate()
|
|
48
|
+
const conf = gate.conf
|
|
49
|
+
const nextRoot = gate.ok && conf.autoIndex !== false ? conf.kbPath : null
|
|
50
|
+
if (nextRoot !== root || conf?.revision !== revision) {
|
|
51
|
+
watcher?.close(); watcher = null; controller?.abort()
|
|
52
|
+
root = nextRoot; revision = conf?.revision; enabled = Boolean(root); dirty.clear(); failures = 0; transient = false; retryAt = 0
|
|
53
|
+
pending = enabled; lastEvent = now(); firstPending = enabled ? now() : null; state = enabled ? 'waiting' : 'disabled'
|
|
54
|
+
excludes = ['_模板', '_手册', '50-底稿', ...(conf?.excludeFromSearch || [])]
|
|
55
|
+
if (root) connect()
|
|
56
|
+
}
|
|
57
|
+
if (enabled && !watcher && now() - lastWatchTry >= minimumMs) connect()
|
|
58
|
+
if (!enabled || running || failures >= 3 && !transient || now() < retryAt) return
|
|
59
|
+
if (now() - lastPatrol >= patrolMs) { pending = true; if (firstPending === null) firstPending = now(); lastPatrol = now() }
|
|
60
|
+
if (!pending || now() - lastEvent < quietMs && (firstPending === null || now() - firstPending < maximumWaitMs) || now() - lastStart < minimumMs) return
|
|
61
|
+
const status = await core.status()
|
|
62
|
+
if (!status.healthy || !status.kbId) { state = 'unhealthy'; return }
|
|
63
|
+
running = true; started = true; pending = false; firstPending = null; lastStart = now(); state = 'running'; controller = new AbortController()
|
|
64
|
+
const active = controller, paths = [...dirty]; attempted = paths; dirty.clear()
|
|
65
|
+
const run = () => core.maintainIndex({ expectedKbId: status.kbId, expectedRevision: revision, paths, automatic: true, signal: active.signal })
|
|
66
|
+
const r = await (resources ? resources.background(run, active.signal) : run())
|
|
67
|
+
if (stopped || !enabled || active.signal.aborted) return
|
|
68
|
+
if (r.ok) { failures = 0; transient = false; retryAt = 0; state = pending ? 'waiting' : 'synced'; if (r.indexWritten) onChange(r) }
|
|
69
|
+
else { paths.forEach(p => dirty.add(p)); failure(r.reason); onChange(r) }
|
|
70
|
+
} catch (error) { attempted.forEach(p => dirty.add(p)); failure(error.code || 'maintenance-failed') }
|
|
71
|
+
finally { if (started) running = false; ticking = false }
|
|
72
|
+
}
|
|
73
|
+
const timer = timers.setInterval(() => { void tick() }, 1000)
|
|
74
|
+
timer?.unref?.()
|
|
75
|
+
return {
|
|
76
|
+
tick, notify: mark,
|
|
77
|
+
resume() { failures = 0; transient = false; retryAt = 0; pending = enabled; lastEvent = now() - quietMs; state = enabled ? 'waiting' : 'disabled' },
|
|
78
|
+
status: () => ({ state, enabled, running, failures, pending, retryAt: retryAt || null, lastStartedAt: Number.isFinite(lastStart) ? new Date(lastStart).toISOString() : null }),
|
|
79
|
+
dispose() { stopped = true; timers.clearInterval(timer); watcher?.close(); controller?.abort(); dirty.clear() },
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { constants, createReadStream } from 'node:fs'
|
|
3
|
+
import { readFile, writeFile, mkdir, stat, copyFile, unlink, rename, open } from 'node:fs/promises'
|
|
4
|
+
import { randomUUID, createHash } from 'node:crypto'
|
|
5
|
+
import { EXCLUDED_PARTITION, readIndexPolicy, groupFor, policyExcluded, pathWithin, policyFile, savePolicy } from './index-policy.js'
|
|
6
|
+
import { locked, safePath, relativePath, atomicJson, readJson, digest, fail } from './workbench-state.js'
|
|
7
|
+
import { walkTree } from './fsindex.js'
|
|
8
|
+
import { extractReferences, extractHtmlReferences } from './workbench-links.js'
|
|
9
|
+
import { isOriginalArchive } from './source-references.js'
|
|
10
|
+
|
|
11
|
+
// A durable file-group journal: policies are committed before the first move.
|
|
12
|
+
// On failure both source/destination remain denied until an explicit retry.
|
|
13
|
+
export function createIndexPolicyService({ userData, getParsing, invalidate, purge, rebuild, notify }) {
|
|
14
|
+
async function fileDigest(file) { const hash = createHash('sha256'); for await (const chunk of createReadStream(file)) hash.update(chunk); return hash.digest('hex') }
|
|
15
|
+
async function discover(b, selected, data, policy) {
|
|
16
|
+
const files = new Set(selected), links = [], jobs = []
|
|
17
|
+
const walk = await walkTree(b.root, b.root, { maxFiles: Number.MAX_SAFE_INTEGER, maxDepth: Number.MAX_SAFE_INTEGER, followLinks: false })
|
|
18
|
+
if (walk.truncated || walk.coverage?.errors) throw fail('SCAN_INCOMPLETE', '无法完整确认资料归属,请排除扫描故障后重试')
|
|
19
|
+
for (const c of data.captures) if (c.entryPath) links.push([c.path, c.entryPath])
|
|
20
|
+
for (const s of Object.values(b.sources || {})) if (s.entryPath && s.originalPath && (s.mode === 'copy' || s.sourceRoot === b.root)) links.push([s.originalPath, s.entryPath])
|
|
21
|
+
for (const g of Object.values(policy.groups)) for (const f of g.files) links.push([g.files[0]?.current, f.current])
|
|
22
|
+
for (const f of walk.files.filter(f => f.path.endsWith('.md'))) {
|
|
23
|
+
const handle = await open(await safePath(b.root, f.path), 'r')
|
|
24
|
+
let text
|
|
25
|
+
try { const buffer = Buffer.alloc(65536), result = await handle.read(buffer, 0, buffer.length, 0); text = buffer.subarray(0, result.bytesRead).toString('utf8') } finally { await handle.close() }
|
|
26
|
+
if (text.startsWith('---') && !/\n---/.test(text)) throw fail('SOURCE_METADATA_TOO_LARGE', '资料来源元数据不完整,未移动:' + f.path)
|
|
27
|
+
const source = b.core._internal.parseFrontmatter(text).data.source
|
|
28
|
+
for (let p of Array.isArray(source) ? source : typeof source === 'string' ? [source] : []) {
|
|
29
|
+
try { p = relativePath(p); links.push([p, f.path]) } catch { /* External provenance is not a local asset. */ }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const parser = getParsing()
|
|
33
|
+
if (parser?.listJobs) {
|
|
34
|
+
for (let offset = 0; ; offset += 500) {
|
|
35
|
+
const result = await parser.listJobs({ offset, limit: 500 })
|
|
36
|
+
if (result.ok === false) throw fail('PARSE_STATE_UNREADABLE', '无法确认解析产物,未移动资料')
|
|
37
|
+
for (const j of result.jobs || []) if (!j.source?.external) { jobs.push(j); if (j.land?.path) links.push([j.source.relPath, j.land.path]) }
|
|
38
|
+
if ((result.jobs || []).length < 500) break
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
let changed = true
|
|
42
|
+
while (changed) { changed = false; for (const [a, z] of links) if (a && z && (files.has(a) || files.has(z))) for (const p of [a, z]) if (!files.has(p)) { files.add(p); changed = true } }
|
|
43
|
+
return { members: [...files].filter(p => walk.files.some(f => f.path === p)), jobs }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function set(b, args) {
|
|
47
|
+
if (typeof args.excluded !== 'boolean') throw fail('BAD_POLICY', '请明确选择排除或取消排除')
|
|
48
|
+
const selected = [...new Set((args.paths || [args.path]).map(relativePath))]
|
|
49
|
+
if (!selected.length || selected.length > 500) throw fail('BAD_SELECTION', '请选择 1–500 份资料')
|
|
50
|
+
for (const file of selected) {
|
|
51
|
+
if (file.split('/')[0].startsWith('.') || /^(?:索引层|_模板|_手册)(?:\/|$)/.test(file) || /^(INDEX|AGENTS|README)\.md$/.test(file)) throw fail('SYSTEM_FILE', '系统文件不能作为资料移动')
|
|
52
|
+
if (!(await stat(await safePath(b.root, file))).isFile()) throw fail('NOT_FILE', '请选择资料文件')
|
|
53
|
+
}
|
|
54
|
+
return locked(path.join(b.root, '.kbmeta', 'index-policy-operation'), async () => {
|
|
55
|
+
const current = readIndexPolicy(b.root)
|
|
56
|
+
if (args.expectedPolicyRevision != null && args.expectedPolicyRevision !== current.revision) throw fail('CONFLICT', '排除状态已变化,请刷新后重试')
|
|
57
|
+
if (selected.every(file => { const g = groupFor(current, file); return g ? g.state === (args.excluded ? 'excluded' : 'included') : !args.excluded && !pathWithin(file, EXCLUDED_PARTITION) })) return { ok: true, unchanged: true, excluded: args.excluded, mapping: {}, groups: [...new Set(selected.map(p => groupFor(current, p)?.id).filter(Boolean))], policyRevision: current.revision }
|
|
58
|
+
let groups, mapping = {}, removed = []
|
|
59
|
+
try {
|
|
60
|
+
await locked(b.dataFile, () => b.core._internal.withMutationLock(b.root, async () => {
|
|
61
|
+
const data = await userData(b), policy = readIndexPolicy(b.root)
|
|
62
|
+
if (args.expectedPolicyRevision != null && args.expectedPolicyRevision !== policy.revision) throw fail('CONFLICT', '排除状态已变化,请刷新后重试')
|
|
63
|
+
const processed = new Set(); groups = []
|
|
64
|
+
for (const file of selected) {
|
|
65
|
+
if (processed.has(file)) continue
|
|
66
|
+
let g = groupFor(policy, file)
|
|
67
|
+
const { members, jobs } = await discover(b, g ? g.files.map(f => f.current) : [file], data, policy)
|
|
68
|
+
if (!g) { const id = randomUUID(); g = policy.groups[id] = { id, files: [], savedLinks: [], pending: file.startsWith('90-收件箱/') && !isOriginalArchive(file) } }
|
|
69
|
+
for (const member of members) {
|
|
70
|
+
const other = groupFor(policy, member)
|
|
71
|
+
if (other && other.id !== g.id) { g.files.push(...other.files.filter(f => !g.files.some(x => x.current === f.current))); g.savedLinks.push(...other.savedLinks || []); delete policy.groups[other.id] }
|
|
72
|
+
if (!g.files.some(f => f.current === member)) g.files.push({ current: member, normal: member.startsWith(EXCLUDED_PARTITION + '/') ? member.slice(EXCLUDED_PARTITION.length + 1) : member })
|
|
73
|
+
processed.add(member)
|
|
74
|
+
}
|
|
75
|
+
if (args.excluded && getParsing()?.readJob) for (const j of jobs.filter(j => ['succeeded','partial'].includes(j.status) && g.files.some(f => [f.current, f.normal, ...(f.aliases || [])].includes(j.source.relPath)))) {
|
|
76
|
+
const job = await getParsing().readJob(j.jobId)
|
|
77
|
+
if (!job?.result || !/^[A-Za-z0-9._-]+$/.test(j.jobId)) continue
|
|
78
|
+
const current = EXCLUDED_PARTITION + '/解析文件/' + j.jobId + '.md'
|
|
79
|
+
if (g.files.some(f => f.current === current)) continue
|
|
80
|
+
const target = await safePath(b.root, current, { missing: true })
|
|
81
|
+
await mkdir(path.dirname(target), { recursive: true })
|
|
82
|
+
const text = '---\nsource: ' + JSON.stringify(j.source.relPath) + '\n---\n\n' + String(job.result.plainText ?? job.result.text ?? '')
|
|
83
|
+
try { await writeFile(target, text, { encoding: 'utf8', flag: 'wx' }) } catch (e) { if (e.code !== 'EEXIST') throw e; if (await readFile(target, 'utf8') !== text) throw fail('DESTINATION_EXISTS', '解析文件已存在不同内容,未覆盖') }
|
|
84
|
+
g.files.push({ current, normal: '50-底稿/解析文件/' + j.jobId + '.md' })
|
|
85
|
+
}
|
|
86
|
+
g.excluded = args.excluded; g.state = args.excluded ? 'excluding' : 'including'; g.error = null
|
|
87
|
+
for (const f of g.files) {
|
|
88
|
+
f.target = args.excluded ? EXCLUDED_PARTITION + '/' + f.normal : f.normal
|
|
89
|
+
if (f.current !== f.target) {
|
|
90
|
+
const source = await safePath(b.root, f.current, { missing: true }), target = await safePath(b.root, f.target, { missing: true })
|
|
91
|
+
const sourceHash = await fileDigest(source).catch(e => { if (e.code === 'ENOENT' && f.sha256) return null; throw e })
|
|
92
|
+
if (sourceHash) f.sha256 = sourceHash
|
|
93
|
+
const existing = await fileDigest(target).catch(e => { if (e.code === 'ENOENT') return null; throw e })
|
|
94
|
+
if (existing && existing !== f.sha256) throw fail('DESTINATION_EXISTS', '归档目标已存在不同内容,未覆盖:' + f.target)
|
|
95
|
+
}
|
|
96
|
+
removed.push(f.current)
|
|
97
|
+
}
|
|
98
|
+
groups.push(g.id)
|
|
99
|
+
}
|
|
100
|
+
// Remove active manual chains; retain their definitions as management
|
|
101
|
+
// metadata so re-inclusion can reconstruct the same user relationships.
|
|
102
|
+
for (const id of groups) {
|
|
103
|
+
const g = policy.groups[id], touched = p => g.files.some(f => [f.normal, f.current, f.target].includes(p))
|
|
104
|
+
const affected = data.links.filter(l => touched(l.from) || touched(l.to))
|
|
105
|
+
for (const l of affected) if (!g.savedLinks.some(x => x.id === l.id)) g.savedLinks.push(l)
|
|
106
|
+
data.links = data.links.filter(l => !touched(l.from) && !touched(l.to))
|
|
107
|
+
}
|
|
108
|
+
await locked(policyFile(b.root), () => savePolicy(b.root, policy))
|
|
109
|
+
data.revision++; await atomicJson(b.dataFile, data)
|
|
110
|
+
}))
|
|
111
|
+
invalidate()
|
|
112
|
+
await purge(b)
|
|
113
|
+
await locked(b.dataFile, () => b.core._internal.withMutationLock(b.root, async () => {
|
|
114
|
+
const data = await userData(b), policy = readIndexPolicy(b.root)
|
|
115
|
+
for (const id of groups) {
|
|
116
|
+
const g = policy.groups[id]
|
|
117
|
+
for (const f of g.files) {
|
|
118
|
+
if (f.current === f.target) continue
|
|
119
|
+
const from = await safePath(b.root, f.current, { missing: true }), to = await safePath(b.root, f.target, { missing: true })
|
|
120
|
+
await mkdir(path.dirname(to), { recursive: true })
|
|
121
|
+
try { await copyFile(from, to, constants.COPYFILE_EXCL) } catch (e) { if (e.code !== 'EEXIST' && e.code !== 'ENOENT') throw e }
|
|
122
|
+
if (await fileDigest(to) !== f.sha256) throw fail('MOVE_VERIFY_FAILED', '资料移动校验失败,原件已保留')
|
|
123
|
+
const original = await fileDigest(from).catch(e => { if (e.code === 'ENOENT') return null; throw e })
|
|
124
|
+
if (original && original !== f.sha256) throw fail('FILE_CHANGED', '资料在移动期间变化,原件已保留')
|
|
125
|
+
if (original) await unlink(from)
|
|
126
|
+
f.aliases = [...new Set([...(f.aliases || []), f.current])]
|
|
127
|
+
mapping[f.current] = f.target; f.current = f.target
|
|
128
|
+
await locked(policyFile(b.root), () => savePolicy(b.root, policy))
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const id of groups) for (const f of policy.groups[id].files) for (const p of f.aliases || []) mapping[p] = f.current
|
|
132
|
+
// Rebase source declarations and links inside moved documents. Incoming
|
|
133
|
+
// links in unrelated notes stay intact and reconnect on restoration.
|
|
134
|
+
for (const id of groups) for (const f of policy.groups[id].files) {
|
|
135
|
+
if (!/\.(md|html?)$/i.test(f.current)) continue
|
|
136
|
+
const originalPath = Object.entries(mapping).find(([, to]) => to === f.current)?.[0] || f.current
|
|
137
|
+
const abs = await safePath(b.root, f.current), text = await readFile(abs, 'utf8')
|
|
138
|
+
const refs = /\.html?$/i.test(f.current) ? extractHtmlReferences(text) : extractReferences(text)
|
|
139
|
+
let output = text
|
|
140
|
+
for (const ref of refs.sort((a, z) => z.start - a.start)) {
|
|
141
|
+
let decoded; try { decoded = decodeURIComponent(ref.target) } catch { continue }
|
|
142
|
+
const relative = path.posix.normalize(path.posix.join(path.posix.dirname(originalPath), decoded))
|
|
143
|
+
const target = mapping[decoded] || mapping[relative]
|
|
144
|
+
if (!target) continue
|
|
145
|
+
const updated = (ref.wiki || ref.type === 'source' ? target : path.posix.relative(path.posix.dirname(f.current), target)) + (ref.anchor || '')
|
|
146
|
+
output = output.slice(0, ref.start) + updated + output.slice(ref.end)
|
|
147
|
+
}
|
|
148
|
+
if (output !== text) { const temp = abs + '.' + randomUUID() + '.tmp'; await writeFile(temp, output, { encoding: 'utf8', flag: 'wx' }); await rename(temp, abs) }
|
|
149
|
+
}
|
|
150
|
+
const resolve = p => mapping[p] || p
|
|
151
|
+
for (const c of data.captures) { c.path = resolve(c.path); if (c.entryPath) c.entryPath = resolve(c.entryPath) }
|
|
152
|
+
for (const a of data.annotations) a.path = resolve(a.path)
|
|
153
|
+
for (const key of ['reading', 'reviews']) data[key] = Object.fromEntries(Object.entries(data[key] || {}).map(([p, v]) => [resolve(p), v]))
|
|
154
|
+
for (const id of groups) {
|
|
155
|
+
const g = policy.groups[id]
|
|
156
|
+
g.state = args.excluded ? 'excluded' : 'included'; g.error = null
|
|
157
|
+
}
|
|
158
|
+
for (const g of Object.values(policy.groups).filter(g => g.state === 'included')) {
|
|
159
|
+
for (const l of g.savedLinks || []) {
|
|
160
|
+
const link = { ...l, from: resolve(l.from), to: resolve(l.to) }
|
|
161
|
+
if (policyExcluded(policy, link.from) || policyExcluded(policy, link.to)) continue
|
|
162
|
+
if (!data.links.some(x => x.id === link.id)) data.links.push(link)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
data.revision++; await atomicJson(b.dataFile, data)
|
|
166
|
+
await locked(policyFile(b.root), () => savePolicy(b.root, policy))
|
|
167
|
+
}))
|
|
168
|
+
invalidate()
|
|
169
|
+
await rebuild(b, removed)
|
|
170
|
+
notify({ type: 'files-changed', kbId: b.st.kbId, operation: 'index.policy.set' })
|
|
171
|
+
return { ok: true, excluded: args.excluded, mapping, groups, policyRevision: readIndexPolicy(b.root).revision }
|
|
172
|
+
} catch (e) {
|
|
173
|
+
if (groups?.length) await locked(policyFile(b.root), async () => {
|
|
174
|
+
const p = readIndexPolicy(b.root)
|
|
175
|
+
for (const id of groups) if (p.groups[id]) { p.groups[id].state = 'failed'; p.groups[id].error = e.message }
|
|
176
|
+
await savePolicy(b.root, p)
|
|
177
|
+
})
|
|
178
|
+
if (groups?.length) {
|
|
179
|
+
await locked(b.dataFile, async () => {
|
|
180
|
+
const data = await userData(b), policy = readIndexPolicy(b.root)
|
|
181
|
+
data.links = data.links.filter(l => !policyExcluded(policy, l.from) && !policyExcluded(policy, l.to))
|
|
182
|
+
data.revision++; await atomicJson(b.dataFile, data)
|
|
183
|
+
}).catch(() => {})
|
|
184
|
+
await purge(b).catch(() => {})
|
|
185
|
+
}
|
|
186
|
+
invalidate(); throw e
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
return { set }
|
|
191
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { readFileSync, statSync } from 'node:fs'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { atomicJson, locked, relativePath, fail } from './workbench-state.js'
|
|
5
|
+
|
|
6
|
+
export const EXCLUDED_PARTITION = '排除索引分区'
|
|
7
|
+
export const policyFile = root => path.join(root, '.kbmeta', 'index-policy.json')
|
|
8
|
+
export const emptyPolicy = () => ({ format: 1, revision: 0, groups: {} })
|
|
9
|
+
const normalized = p => String(p || '').replaceAll('\\', '/').normalize('NFC').toLowerCase()
|
|
10
|
+
const archived = file => /(^|\/)(原件归档|_archive)(\/|$)/i.test(String(file).replaceAll('\\', '/'))
|
|
11
|
+
export const pathWithin = (p, prefix) => normalized(p) === normalized(prefix) || normalized(p).startsWith(normalized(prefix) + '/')
|
|
12
|
+
|
|
13
|
+
// Parsed policies are keyed by file identity. Any write, rename or replace changes
|
|
14
|
+
// at least one field, so a hit is the same bytes the caller would have read. Reads
|
|
15
|
+
// still return a fresh copy: several callers edit the policy before saving it.
|
|
16
|
+
const policyCache = new Map()
|
|
17
|
+
const statKey = st => [String(st.dev), String(st.ino), String(st.size), String(st.mtimeNs), String(st.ctimeNs)].join(':')
|
|
18
|
+
export function indexPolicySignature(root) {
|
|
19
|
+
if (!root) return 'none'
|
|
20
|
+
try { return statKey(statSync(policyFile(root), { bigint: true })) }
|
|
21
|
+
catch (e) { if (e.code === 'ENOENT') return 'none'; throw fail('INDEX_POLICY_CORRUPT', '索引排除策略无法读取,已停止索引操作') }
|
|
22
|
+
}
|
|
23
|
+
function validate(p) {
|
|
24
|
+
if (p?.format !== 1 || !Number.isSafeInteger(p.revision) || !p.groups || typeof p.groups !== 'object' || Array.isArray(p.groups)) throw fail('INDEX_POLICY_CORRUPT', '索引排除策略格式损坏')
|
|
25
|
+
for (const g of Object.values(p.groups)) {
|
|
26
|
+
if (!g || !Array.isArray(g.files) || !['included', 'excluded', 'excluding', 'including', 'failed'].includes(g.state)) throw fail('INDEX_POLICY_CORRUPT', '资料排除记录损坏')
|
|
27
|
+
for (const f of g.files) { relativePath(f.normal); relativePath(f.current); if (f.target) relativePath(f.target) }
|
|
28
|
+
}
|
|
29
|
+
return p
|
|
30
|
+
}
|
|
31
|
+
// Fail closed on damaged policy. Cache entries are always revalidated by identity.
|
|
32
|
+
export function readIndexPolicy(root) {
|
|
33
|
+
if (!root) return emptyPolicy()
|
|
34
|
+
const file = policyFile(root)
|
|
35
|
+
let key
|
|
36
|
+
try { key = statKey(statSync(file, { bigint: true })) }
|
|
37
|
+
catch (e) { if (e.code === 'ENOENT') { policyCache.delete(file); return emptyPolicy() } throw fail('INDEX_POLICY_CORRUPT', '索引排除策略无法读取,已停止索引操作') }
|
|
38
|
+
const hit = policyCache.get(file)
|
|
39
|
+
if (hit && hit.key === key) return structuredClone(hit.value)
|
|
40
|
+
let p
|
|
41
|
+
try { p = validate(JSON.parse(readFileSync(file, 'utf8'))) }
|
|
42
|
+
catch (e) { if (e.code === 'ENOENT') return emptyPolicy(); if (e.code === 'INDEX_POLICY_CORRUPT') throw e; throw fail('INDEX_POLICY_CORRUPT', '索引排除策略无法读取,已停止索引操作') }
|
|
43
|
+
if (policyCache.size >= 32) policyCache.delete(policyCache.keys().next().value)
|
|
44
|
+
policyCache.set(file, { key, value: p })
|
|
45
|
+
return structuredClone(p)
|
|
46
|
+
}
|
|
47
|
+
// One pass over the policy turns every directory entry check into prefix lookups.
|
|
48
|
+
export function createPolicyMatcher(policy) {
|
|
49
|
+
const source = policy?.groups ?? {}
|
|
50
|
+
const exact = new Map(), all = new Set(), pend = new Set(), pendingPrefix = normalized('90-收件箱')
|
|
51
|
+
for (const g of Object.values(source)) {
|
|
52
|
+
const paths = []
|
|
53
|
+
for (const f of g.files ?? []) for (const candidate of [f.normal, f.current, f.target, ...(f.aliases || [])]) if (candidate) paths.push(normalized(candidate))
|
|
54
|
+
for (const n of paths) { if (!exact.has(n)) exact.set(n, g); if (g.state !== 'included' || g.pending) pend.add(n); if (g.state !== 'included') all.add(n) }
|
|
55
|
+
}
|
|
56
|
+
const restrictedAll = [...all], restrictedPending = [...pend]
|
|
57
|
+
const inside = (n, prefix) => n === prefix || n.startsWith(prefix + '/')
|
|
58
|
+
const excludedPartition = normalized(EXCLUDED_PARTITION)
|
|
59
|
+
const excluded = (file, pending = true) => {
|
|
60
|
+
const n = normalized(file)
|
|
61
|
+
if (inside(n, excludedPartition)) return true
|
|
62
|
+
const group = exact.get(n)
|
|
63
|
+
if (pending && inside(n, pendingPrefix) && !archived(file) && group?.pending !== false) return true
|
|
64
|
+
for (const prefix of pending ? restrictedPending : restrictedAll) if (inside(n, prefix)) return true
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
return { excluded, groupFor: file => exact.get(normalized(file)) }
|
|
68
|
+
}
|
|
69
|
+
export function groupFor(policy, file) {
|
|
70
|
+
return Object.values(policy.groups).find(g => g.files.some(f => [f.normal, f.current, f.target, ...(f.aliases || [])].filter(Boolean).some(p => normalized(p) === normalized(file))))
|
|
71
|
+
}
|
|
72
|
+
export function policyExcluded(policy, file, pending = true) {
|
|
73
|
+
if (pathWithin(file, EXCLUDED_PARTITION)) return true
|
|
74
|
+
const group = groupFor(policy, file)
|
|
75
|
+
if (pending && pathWithin(file, '90-收件箱') && !archived(file) && group?.pending !== false) return true
|
|
76
|
+
return Object.values(policy.groups).some(g => (g.state !== 'included' || pending && g.pending) && g.files.some(f => [f.normal, f.current, f.target, ...(f.aliases || [])].filter(Boolean).some(p => pathWithin(file, p))))
|
|
77
|
+
}
|
|
78
|
+
export function policyExcludes(root) {
|
|
79
|
+
const p = readIndexPolicy(root)
|
|
80
|
+
return [EXCLUDED_PARTITION, ...Object.values(p.groups).filter(g => g.state !== 'included' || g.pending).flatMap(g => g.files.flatMap(f => [f.normal, f.current, f.target, ...(f.aliases || [])].filter(Boolean)))]
|
|
81
|
+
}
|
|
82
|
+
export function referenceExcluded(policy, file, target) {
|
|
83
|
+
let name
|
|
84
|
+
try { name = decodeURIComponent(String(target).split('#')[0].split('|')[0]) } catch { return true }
|
|
85
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(name)) return false
|
|
86
|
+
const relative = path.posix.normalize(path.posix.join(path.posix.dirname(file), name))
|
|
87
|
+
if ([name, relative, name + '.md', relative + '.md'].some(p => policyExcluded(policy, p))) return true
|
|
88
|
+
if (!name.includes('/')) {
|
|
89
|
+
const stem = normalized(name).replace(/\.md$/, '')
|
|
90
|
+
return Object.values(policy.groups).filter(g => g.state !== 'included').some(g => g.files.some(f => [f.normal, f.current].some(p => normalized(path.posix.basename(p)).replace(/\.md$/, '') === stem)))
|
|
91
|
+
}
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
export function resolveAssetPath(root, file, policy) {
|
|
95
|
+
const p = policy || readIndexPolicy(root), g = groupFor(p, file)
|
|
96
|
+
return g?.files.find(f => [f.normal, f.current, f.target, ...(f.aliases || [])].filter(Boolean).some(p => normalized(p) === normalized(file)))?.current || file
|
|
97
|
+
}
|
|
98
|
+
export function excludedSource(root, file) {
|
|
99
|
+
const p = readIndexPolicy(root), g = groupFor(p, file)
|
|
100
|
+
return pathWithin(file, EXCLUDED_PARTITION) || Boolean(g && g.state !== 'included')
|
|
101
|
+
}
|
|
102
|
+
export async function savePolicy(root, policy) {
|
|
103
|
+
policy.revision++
|
|
104
|
+
await atomicJson(policyFile(root), policy)
|
|
105
|
+
policyCache.delete(policyFile(root))
|
|
106
|
+
}
|
|
107
|
+
export async function registerDerived(root, source, current, normal) {
|
|
108
|
+
if (!source) return
|
|
109
|
+
await locked(policyFile(root), async () => {
|
|
110
|
+
const p = readIndexPolicy(root)
|
|
111
|
+
let g = groupFor(p, source)
|
|
112
|
+
if (!g && (pathWithin(source, EXCLUDED_PARTITION) || pathWithin(source, '90-收件箱'))) {
|
|
113
|
+
const id = randomUUID()
|
|
114
|
+
const excluded = pathWithin(source, EXCLUDED_PARTITION)
|
|
115
|
+
g = p.groups[id] = { id, state: excluded ? 'excluded' : 'included', excluded, pending: true, files: [{ current: source, normal: excluded ? source.slice(EXCLUDED_PARTITION.length + 1) : source }], savedLinks: [] }
|
|
116
|
+
}
|
|
117
|
+
if (!g) return
|
|
118
|
+
if (!g.files.some(f => normalized(f.current) === normalized(current))) g.files.push({ current, normal, ...(['excluding', 'including', 'failed'].includes(g.state) ? { target: g.excluded ? EXCLUDED_PARTITION + '/' + normal : normal } : {}) })
|
|
119
|
+
await savePolicy(root, p)
|
|
120
|
+
})
|
|
121
|
+
}
|