@marktrue/dsh-mobile-remote 3.3.1-rc.1-app → 3.3.1-rc.1
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/CHANGELOG.md +2220 -0
- package/CONTRIBUTING.md +114 -0
- package/FAQ.md +111 -0
- package/README.md +256 -6
- package/cordis.patch.yml +14 -0
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +125 -0
- package/docs/01-PRD.md +148 -0
- package/docs/02-architecture.md +249 -0
- package/docs/03-api.md +1683 -0
- package/docs/04-security.md +195 -0
- package/docs/05-test-cases.md +405 -0
- package/docs/06-install-run.md +342 -0
- package/docs/07-user-manual.md +70 -0
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +86 -0
- package/docs/09-compatibility.md +261 -0
- package/docs/10-release.md +1032 -0
- package/docs/11-notification-reliability.md +45 -0
- package/docs/12-implementation-status.md +41 -0
- package/docs/20-dsh-022-compatibility-2026-11-05.md +32 -0
- package/docs/README.md +109 -0
- package/docs/history/13-device-acceptance-2026-11-03.md +37 -0
- package/docs/history/16-next-window-handoff-2026-11-04.md +44 -0
- package/docs/history/17-remaining-work-review-2026-11-04.md +53 -0
- package/docs/history/18-device-reliability-acceptance-2026-11-04.md +63 -0
- package/docs/history/19-issue-followup-2026-11-04.md +39 -0
- package/docs/screenshots/01-home.png +0 -0
- package/docs/screenshots/02-notifications.png +0 -0
- package/docs/screenshots/03-sessions.png +0 -0
- package/docs/screenshots/04-chat.png +0 -0
- package/docs/screenshots/05-settings.png +0 -0
- package/docs/screenshots/06-new-session.png +0 -0
- package/docs/screenshots/pgy-appstore.jpg +0 -0
- package/docs/screenshots/pgy-mobile-app.jpg +0 -0
- package/docs/screenshots/pgy-pc-client.jpg +0 -0
- package/lib/account-usage.js +145 -0
- package/lib/app-alignment.js +112 -0
- package/lib/app-carrier-store.js +1972 -0
- package/lib/app-carrier.js +609 -0
- package/lib/client.js +1196 -0
- package/lib/desktop-form.js +738 -0
- package/lib/endpoint-registry.js +210 -0
- package/lib/experimental-bundles.js +121 -0
- package/lib/git-read-bundled-provider.js +480 -0
- package/lib/git-read-service.js +901 -0
- package/lib/host-manager-update.js +222 -0
- package/lib/host-settings-whitelist.js +207 -0
- package/lib/host-settings.js +695 -0
- package/lib/host-update-capabilities.js +209 -0
- package/lib/index.js +15808 -0
- package/lib/npm-update-source.js +226 -0
- package/lib/plugin-content-digest.js +80 -0
- package/lib/plugin-self-update.js +1112 -0
- package/lib/plugin-update-check.js +268 -0
- package/lib/plugin-update-controller.js +416 -0
- package/lib/plugin-update-log.js +164 -0
- package/lib/plugin-update-transaction.js +358 -0
- package/lib/plugin-update.js +309 -0
- package/lib/runtime-dependency-snapshot.js +345 -0
- package/lib/session-title-cache.js +123 -0
- package/lib/session-title-refresh.js +261 -0
- package/lib/sse-connections.js +172 -0
- package/lib/tool-process.js +20 -0
- package/lib/update-fetch.js +24 -0
- package/lib/update-lock-arbiter.js +210 -0
- package/lib/update-supervisor.js +379 -0
- package/node_modules/ansi-regex/index.d.ts +37 -0
- package/node_modules/ansi-regex/index.js +10 -0
- package/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-regex/package.json +55 -0
- package/node_modules/ansi-regex/readme.md +78 -0
- package/node_modules/ansi-styles/index.d.ts +345 -0
- package/node_modules/ansi-styles/index.js +163 -0
- package/node_modules/ansi-styles/license +9 -0
- package/node_modules/ansi-styles/package.json +56 -0
- package/node_modules/ansi-styles/readme.md +152 -0
- package/node_modules/camelcase/index.d.ts +63 -0
- package/node_modules/camelcase/index.js +76 -0
- package/node_modules/camelcase/license +9 -0
- package/node_modules/camelcase/package.json +43 -0
- package/node_modules/camelcase/readme.md +99 -0
- package/node_modules/cliui/CHANGELOG.md +76 -0
- package/node_modules/cliui/LICENSE.txt +14 -0
- package/node_modules/cliui/README.md +115 -0
- package/node_modules/cliui/index.js +354 -0
- package/node_modules/cliui/package.json +65 -0
- package/node_modules/color-convert/CHANGELOG.md +54 -0
- package/node_modules/color-convert/LICENSE +21 -0
- package/node_modules/color-convert/README.md +68 -0
- package/node_modules/color-convert/conversions.js +839 -0
- package/node_modules/color-convert/index.js +81 -0
- package/node_modules/color-convert/package.json +48 -0
- package/node_modules/color-convert/route.js +97 -0
- package/node_modules/color-name/LICENSE +8 -0
- package/node_modules/color-name/README.md +11 -0
- package/node_modules/color-name/index.js +152 -0
- package/node_modules/color-name/package.json +28 -0
- package/node_modules/decamelize/index.js +13 -0
- package/node_modules/decamelize/license +21 -0
- package/node_modules/decamelize/package.json +38 -0
- package/node_modules/decamelize/readme.md +48 -0
- package/node_modules/dijkstrajs/.travis.yml +4 -0
- package/node_modules/dijkstrajs/CONTRIBUTING.md +8 -0
- package/node_modules/dijkstrajs/LICENSE.md +19 -0
- package/node_modules/dijkstrajs/README.md +18 -0
- package/node_modules/dijkstrajs/dijkstra.js +165 -0
- package/node_modules/dijkstrajs/package.json +60 -0
- package/node_modules/dijkstrajs/test/dijkstra.test.js +96 -0
- package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/emoji-regex/README.md +73 -0
- package/node_modules/emoji-regex/es2015/index.js +6 -0
- package/node_modules/emoji-regex/es2015/text.js +6 -0
- package/node_modules/emoji-regex/index.d.ts +23 -0
- package/node_modules/emoji-regex/index.js +6 -0
- package/node_modules/emoji-regex/package.json +50 -0
- package/node_modules/emoji-regex/text.js +6 -0
- package/node_modules/find-up/index.d.ts +137 -0
- package/node_modules/find-up/index.js +89 -0
- package/node_modules/find-up/license +9 -0
- package/node_modules/find-up/package.json +53 -0
- package/node_modules/find-up/readme.md +156 -0
- package/node_modules/get-caller-file/LICENSE.md +6 -0
- package/node_modules/get-caller-file/README.md +41 -0
- package/node_modules/get-caller-file/index.d.ts +2 -0
- package/node_modules/get-caller-file/index.js +22 -0
- package/node_modules/get-caller-file/index.js.map +1 -0
- package/node_modules/get-caller-file/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
- package/node_modules/is-fullwidth-code-point/index.js +50 -0
- package/node_modules/is-fullwidth-code-point/license +9 -0
- package/node_modules/is-fullwidth-code-point/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/readme.md +39 -0
- package/node_modules/locate-path/index.d.ts +83 -0
- package/node_modules/locate-path/index.js +65 -0
- package/node_modules/locate-path/license +9 -0
- package/node_modules/locate-path/package.json +45 -0
- package/node_modules/locate-path/readme.md +122 -0
- package/node_modules/p-limit/index.d.ts +38 -0
- package/node_modules/p-limit/index.js +57 -0
- package/node_modules/p-limit/license +9 -0
- package/node_modules/p-limit/package.json +52 -0
- package/node_modules/p-limit/readme.md +101 -0
- package/node_modules/p-locate/index.d.ts +64 -0
- package/node_modules/p-locate/index.js +52 -0
- package/node_modules/p-locate/license +9 -0
- package/node_modules/p-locate/package.json +53 -0
- package/node_modules/p-locate/readme.md +90 -0
- package/node_modules/p-try/index.d.ts +39 -0
- package/node_modules/p-try/index.js +9 -0
- package/node_modules/p-try/license +9 -0
- package/node_modules/p-try/package.json +42 -0
- package/node_modules/p-try/readme.md +58 -0
- package/node_modules/path-exists/index.d.ts +28 -0
- package/node_modules/path-exists/index.js +23 -0
- package/node_modules/path-exists/license +9 -0
- package/node_modules/path-exists/package.json +39 -0
- package/node_modules/path-exists/readme.md +52 -0
- package/node_modules/pngjs/.eslintignore +2 -0
- package/node_modules/pngjs/.eslintrc.json +19 -0
- package/node_modules/pngjs/.prettierignore +3 -0
- package/node_modules/pngjs/LICENSE +20 -0
- package/node_modules/pngjs/README.md +429 -0
- package/node_modules/pngjs/browser.js +16096 -0
- package/node_modules/pngjs/coverage/lcov-report/base.css +354 -0
- package/node_modules/pngjs/coverage/lcov-report/bitmapper.js.html +881 -0
- package/node_modules/pngjs/coverage/lcov-report/bitpacker.js.html +554 -0
- package/node_modules/pngjs/coverage/lcov-report/block-navigation.js +77 -0
- package/node_modules/pngjs/coverage/lcov-report/chunkstream.js.html +647 -0
- package/node_modules/pngjs/coverage/lcov-report/constants.js.html +176 -0
- package/node_modules/pngjs/coverage/lcov-report/crc.js.html +200 -0
- package/node_modules/pngjs/coverage/lcov-report/favicon.png +0 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-pack.js.html +593 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse-async.js.html +152 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse-sync.js.html +143 -0
- package/node_modules/pngjs/coverage/lcov-report/filter-parse.js.html +611 -0
- package/node_modules/pngjs/coverage/lcov-report/format-normaliser.js.html +359 -0
- package/node_modules/pngjs/coverage/lcov-report/index.html +426 -0
- package/node_modules/pngjs/coverage/lcov-report/interlace.js.html +365 -0
- package/node_modules/pngjs/coverage/lcov-report/packer-async.js.html +230 -0
- package/node_modules/pngjs/coverage/lcov-report/packer-sync.js.html +248 -0
- package/node_modules/pngjs/coverage/lcov-report/packer.js.html +467 -0
- package/node_modules/pngjs/coverage/lcov-report/paeth-predictor.js.html +128 -0
- package/node_modules/pngjs/coverage/lcov-report/parser-async.js.html +575 -0
- package/node_modules/pngjs/coverage/lcov-report/parser-sync.js.html +404 -0
- package/node_modules/pngjs/coverage/lcov-report/parser.js.html +950 -0
- package/node_modules/pngjs/coverage/lcov-report/png-sync.js.html +116 -0
- package/node_modules/pngjs/coverage/lcov-report/png.js.html +662 -0
- package/node_modules/pngjs/coverage/lcov-report/prettify.css +101 -0
- package/node_modules/pngjs/coverage/lcov-report/prettify.js +1007 -0
- package/node_modules/pngjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/node_modules/pngjs/coverage/lcov-report/sorter.js +169 -0
- package/node_modules/pngjs/coverage/lcov-report/sync-inflate.js.html +584 -0
- package/node_modules/pngjs/coverage/lcov-report/sync-reader.js.html +215 -0
- package/node_modules/pngjs/coverage/lcov.info +2177 -0
- package/node_modules/pngjs/lib/bitmapper.js +267 -0
- package/node_modules/pngjs/lib/bitpacker.js +158 -0
- package/node_modules/pngjs/lib/chunkstream.js +189 -0
- package/node_modules/pngjs/lib/constants.js +32 -0
- package/node_modules/pngjs/lib/crc.js +40 -0
- package/node_modules/pngjs/lib/filter-pack.js +171 -0
- package/node_modules/pngjs/lib/filter-parse-async.js +24 -0
- package/node_modules/pngjs/lib/filter-parse-sync.js +21 -0
- package/node_modules/pngjs/lib/filter-parse.js +177 -0
- package/node_modules/pngjs/lib/format-normaliser.js +93 -0
- package/node_modules/pngjs/lib/interlace.js +95 -0
- package/node_modules/pngjs/lib/packer-async.js +50 -0
- package/node_modules/pngjs/lib/packer-sync.js +56 -0
- package/node_modules/pngjs/lib/packer.js +129 -0
- package/node_modules/pngjs/lib/paeth-predictor.js +16 -0
- package/node_modules/pngjs/lib/parser-async.js +165 -0
- package/node_modules/pngjs/lib/parser-sync.js +108 -0
- package/node_modules/pngjs/lib/parser.js +290 -0
- package/node_modules/pngjs/lib/png-sync.js +12 -0
- package/node_modules/pngjs/lib/png.js +194 -0
- package/node_modules/pngjs/lib/sync-inflate.js +168 -0
- package/node_modules/pngjs/lib/sync-reader.js +45 -0
- package/node_modules/pngjs/package.json +73 -0
- package/node_modules/qrcode/README.md +770 -0
- package/node_modules/qrcode/bin/qrcode +159 -0
- package/node_modules/qrcode/helper/to-sjis-browser.js +2 -0
- package/node_modules/qrcode/helper/to-sjis.js +105 -0
- package/node_modules/qrcode/lib/browser.js +76 -0
- package/node_modules/qrcode/lib/can-promise.js +7 -0
- package/node_modules/qrcode/lib/core/alignment-pattern.js +83 -0
- package/node_modules/qrcode/lib/core/alphanumeric-data.js +59 -0
- package/node_modules/qrcode/lib/core/bit-buffer.js +37 -0
- package/node_modules/qrcode/lib/core/bit-matrix.js +65 -0
- package/node_modules/qrcode/lib/core/byte-data.js +30 -0
- package/node_modules/qrcode/lib/core/error-correction-code.js +135 -0
- package/node_modules/qrcode/lib/core/error-correction-level.js +50 -0
- package/node_modules/qrcode/lib/core/finder-pattern.js +22 -0
- package/node_modules/qrcode/lib/core/format-info.js +29 -0
- package/node_modules/qrcode/lib/core/galois-field.js +69 -0
- package/node_modules/qrcode/lib/core/kanji-data.js +54 -0
- package/node_modules/qrcode/lib/core/mask-pattern.js +234 -0
- package/node_modules/qrcode/lib/core/mode.js +167 -0
- package/node_modules/qrcode/lib/core/numeric-data.js +43 -0
- package/node_modules/qrcode/lib/core/polynomial.js +62 -0
- package/node_modules/qrcode/lib/core/qrcode.js +495 -0
- package/node_modules/qrcode/lib/core/reed-solomon-encoder.js +56 -0
- package/node_modules/qrcode/lib/core/regex.js +31 -0
- package/node_modules/qrcode/lib/core/segments.js +330 -0
- package/node_modules/qrcode/lib/core/utils.js +63 -0
- package/node_modules/qrcode/lib/core/version-check.js +9 -0
- package/node_modules/qrcode/lib/core/version.js +163 -0
- package/node_modules/qrcode/lib/index.js +12 -0
- package/node_modules/qrcode/lib/renderer/canvas.js +63 -0
- package/node_modules/qrcode/lib/renderer/png.js +78 -0
- package/node_modules/qrcode/lib/renderer/svg-tag.js +81 -0
- package/node_modules/qrcode/lib/renderer/svg.js +19 -0
- package/node_modules/qrcode/lib/renderer/terminal/terminal-small.js +85 -0
- package/node_modules/qrcode/lib/renderer/terminal/terminal.js +49 -0
- package/node_modules/qrcode/lib/renderer/terminal.js +9 -0
- package/node_modules/qrcode/lib/renderer/utf8.js +71 -0
- package/node_modules/qrcode/lib/renderer/utils.js +99 -0
- package/node_modules/qrcode/lib/server.js +138 -0
- package/node_modules/qrcode/license +10 -0
- package/node_modules/qrcode/package.json +77 -0
- package/node_modules/require-directory/.jshintrc +67 -0
- package/node_modules/require-directory/.npmignore +1 -0
- package/node_modules/require-directory/.travis.yml +3 -0
- package/node_modules/require-directory/LICENSE +22 -0
- package/node_modules/require-directory/README.markdown +184 -0
- package/node_modules/require-directory/index.js +86 -0
- package/node_modules/require-directory/package.json +40 -0
- package/node_modules/require-main-filename/CHANGELOG.md +26 -0
- package/node_modules/require-main-filename/LICENSE.txt +14 -0
- package/node_modules/require-main-filename/README.md +26 -0
- package/node_modules/require-main-filename/index.js +18 -0
- package/node_modules/require-main-filename/package.json +35 -0
- package/node_modules/set-blocking/CHANGELOG.md +26 -0
- package/node_modules/set-blocking/LICENSE.txt +14 -0
- package/node_modules/set-blocking/README.md +31 -0
- package/node_modules/set-blocking/index.js +7 -0
- package/node_modules/set-blocking/package.json +42 -0
- package/node_modules/string-width/index.d.ts +29 -0
- package/node_modules/string-width/index.js +47 -0
- package/node_modules/string-width/license +9 -0
- package/node_modules/string-width/package.json +56 -0
- package/node_modules/string-width/readme.md +50 -0
- package/node_modules/strip-ansi/index.d.ts +17 -0
- package/node_modules/strip-ansi/index.js +4 -0
- package/node_modules/strip-ansi/license +9 -0
- package/node_modules/strip-ansi/package.json +54 -0
- package/node_modules/strip-ansi/readme.md +46 -0
- package/node_modules/which-module/LICENSE +13 -0
- package/node_modules/which-module/README.md +58 -0
- package/node_modules/which-module/index.js +9 -0
- package/node_modules/which-module/package.json +41 -0
- package/node_modules/wrap-ansi/index.js +186 -0
- package/node_modules/wrap-ansi/license +9 -0
- package/node_modules/wrap-ansi/package.json +61 -0
- package/node_modules/wrap-ansi/readme.md +97 -0
- package/node_modules/y18n/CHANGELOG.md +35 -0
- package/node_modules/y18n/LICENSE +13 -0
- package/node_modules/y18n/README.md +109 -0
- package/node_modules/y18n/index.js +188 -0
- package/node_modules/y18n/package.json +39 -0
- package/node_modules/yargs/CHANGELOG.md +420 -0
- package/node_modules/yargs/LICENSE +21 -0
- package/node_modules/yargs/README.md +140 -0
- package/node_modules/yargs/build/lib/apply-extends.d.ts +2 -0
- package/node_modules/yargs/build/lib/apply-extends.js +65 -0
- package/node_modules/yargs/build/lib/argsert.d.ts +2 -0
- package/node_modules/yargs/build/lib/argsert.js +65 -0
- package/node_modules/yargs/build/lib/command.d.ts +64 -0
- package/node_modules/yargs/build/lib/command.js +416 -0
- package/node_modules/yargs/build/lib/common-types.d.ts +36 -0
- package/node_modules/yargs/build/lib/common-types.js +25 -0
- package/node_modules/yargs/build/lib/completion-templates.d.ts +2 -0
- package/node_modules/yargs/build/lib/completion-templates.js +50 -0
- package/node_modules/yargs/build/lib/completion.d.ts +21 -0
- package/node_modules/yargs/build/lib/completion.js +135 -0
- package/node_modules/yargs/build/lib/is-promise.d.ts +1 -0
- package/node_modules/yargs/build/lib/is-promise.js +9 -0
- package/node_modules/yargs/build/lib/levenshtein.d.ts +1 -0
- package/node_modules/yargs/build/lib/levenshtein.js +58 -0
- package/node_modules/yargs/build/lib/middleware.d.ts +10 -0
- package/node_modules/yargs/build/lib/middleware.js +57 -0
- package/node_modules/yargs/build/lib/obj-filter.d.ts +1 -0
- package/node_modules/yargs/build/lib/obj-filter.js +14 -0
- package/node_modules/yargs/build/lib/parse-command.d.ts +11 -0
- package/node_modules/yargs/build/lib/parse-command.js +36 -0
- package/node_modules/yargs/build/lib/process-argv.d.ts +2 -0
- package/node_modules/yargs/build/lib/process-argv.js +31 -0
- package/node_modules/yargs/build/lib/usage.d.ts +49 -0
- package/node_modules/yargs/build/lib/usage.js +540 -0
- package/node_modules/yargs/build/lib/validation.d.ts +34 -0
- package/node_modules/yargs/build/lib/validation.js +330 -0
- package/node_modules/yargs/build/lib/yargs.d.ts +274 -0
- package/node_modules/yargs/build/lib/yargs.js +1190 -0
- package/node_modules/yargs/build/lib/yerror.d.ts +4 -0
- package/node_modules/yargs/build/lib/yerror.js +11 -0
- package/node_modules/yargs/index.js +40 -0
- package/node_modules/yargs/locales/be.json +46 -0
- package/node_modules/yargs/locales/de.json +46 -0
- package/node_modules/yargs/locales/en.json +51 -0
- package/node_modules/yargs/locales/es.json +46 -0
- package/node_modules/yargs/locales/fi.json +49 -0
- package/node_modules/yargs/locales/fr.json +53 -0
- package/node_modules/yargs/locales/hi.json +49 -0
- package/node_modules/yargs/locales/hu.json +46 -0
- package/node_modules/yargs/locales/id.json +50 -0
- package/node_modules/yargs/locales/it.json +46 -0
- package/node_modules/yargs/locales/ja.json +51 -0
- package/node_modules/yargs/locales/ko.json +49 -0
- package/node_modules/yargs/locales/nb.json +44 -0
- package/node_modules/yargs/locales/nl.json +49 -0
- package/node_modules/yargs/locales/nn.json +44 -0
- package/node_modules/yargs/locales/pirate.json +13 -0
- package/node_modules/yargs/locales/pl.json +49 -0
- package/node_modules/yargs/locales/pt.json +45 -0
- package/node_modules/yargs/locales/pt_BR.json +48 -0
- package/node_modules/yargs/locales/ru.json +46 -0
- package/node_modules/yargs/locales/th.json +46 -0
- package/node_modules/yargs/locales/tr.json +48 -0
- package/node_modules/yargs/locales/zh_CN.json +48 -0
- package/node_modules/yargs/locales/zh_TW.json +47 -0
- package/node_modules/yargs/package.json +92 -0
- package/node_modules/yargs/yargs.js +14 -0
- package/node_modules/yargs-parser/CHANGELOG.md +601 -0
- package/node_modules/yargs-parser/LICENSE.txt +14 -0
- package/node_modules/yargs-parser/README.md +449 -0
- package/node_modules/yargs-parser/index.js +1032 -0
- package/node_modules/yargs-parser/lib/tokenize-arg-string.js +40 -0
- package/node_modules/yargs-parser/package.json +46 -0
- package/package.json +68 -12
- package/DSH-Remote-v3.3.1.apk +0 -4
- package/manifest.json +0 -21
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
// issue #106:手机端「电脑端设置(只读)」的**宿主侧投影与二次脱敏**。
|
|
2
|
+
//
|
|
3
|
+
// 为什么不能只信宿主:`settings.describe({redactSecrets:true})` 会剥掉
|
|
4
|
+
// `role('secret')` 字段,但本插件仍要自己做一遍,理由有三:
|
|
5
|
+
// 1. 我们是**另一条 wire**(`/m/api/host-settings`),脱敏逻辑不能只存在于上游一处;
|
|
6
|
+
// 2. 白名单之外的字段(`baseURL`、`headers`、`cwd`…)宿主不会剥,投影时必须
|
|
7
|
+
// **整段不取**;只取白名单叶子能从根上避免"顺手带出去";
|
|
8
|
+
// 3. `value`/`base`/`user` 三层都可能旁路泄露(默认值层最容易被忘),必须逐层处理。
|
|
9
|
+
//
|
|
10
|
+
// 本模块是**纯函数**(不碰 ctx、不写日志、不读文件、不回显原文),由 `lib/index.js`
|
|
11
|
+
// 注入 `settings` 服务与既有严格读取器,便于用假设置做负例测试。
|
|
12
|
+
//
|
|
13
|
+
// 失败即关(fail-closed),且**整段而不是半段**:
|
|
14
|
+
// - 读不到 / describe 形状漂移 / schema 解析失败 / 脱敏异常 → 该命名空间不返回任何字段;
|
|
15
|
+
// - 任何白名单字段的**值**或**键名**过不了擦除器(绝对路径、URL、形似凭据、过长、
|
|
16
|
+
// 非标量)→ 整个命名空间 fail-closed,绝不"先给一半";
|
|
17
|
+
// - secret 只给 `{path, set}`,永不带值/长度/前缀。
|
|
18
|
+
import {
|
|
19
|
+
HOST_SETTINGS_GROUPS,
|
|
20
|
+
HOST_SETTINGS_WHITELIST,
|
|
21
|
+
HOST_SETTINGS_WHITELIST_VERSION,
|
|
22
|
+
hostSettingsWhitelistIsEmpty,
|
|
23
|
+
} from "./host-settings-whitelist.js";
|
|
24
|
+
|
|
25
|
+
/** 单个命名空间最多产出的字段数(防御异常 schema / 巨大 dict 展开)。 */
|
|
26
|
+
const MAX_FIELDS_PER_NAMESPACE = 200;
|
|
27
|
+
/** 一个 dict/数组通配展开的项数上限(超过即形状异常,fail-closed)。 */
|
|
28
|
+
const MAX_WILDCARD_ITEMS = 50;
|
|
29
|
+
/** 展示值的最大字符数;超过即 fail-closed(长文本多半是正文/提示词,不属于设置项)。 */
|
|
30
|
+
const MAX_VALUE_TEXT = 512;
|
|
31
|
+
/** schema/值递归深度上限(懒加载 schema 可能成环)。 */
|
|
32
|
+
const MAX_DEPTH = 24;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 键名黑名单(**精确名**比较,不做子串匹配)。
|
|
36
|
+
*
|
|
37
|
+
* 用子串会把 `maxTokens` / `contextWindow` 这类正常字段误伤;用精确名既挡住凭据类键,
|
|
38
|
+
* 又不会把额度/窗口字段当成 secret。schema 声明的 secret 另走 `role` 通路,两条取并集。
|
|
39
|
+
*/
|
|
40
|
+
const DENY_KEY_NAMES = new Set([
|
|
41
|
+
"key",
|
|
42
|
+
"apikey",
|
|
43
|
+
"secret",
|
|
44
|
+
"token",
|
|
45
|
+
"accesstoken",
|
|
46
|
+
"refreshtoken",
|
|
47
|
+
"sessiontoken",
|
|
48
|
+
"bearertoken",
|
|
49
|
+
"password",
|
|
50
|
+
"passwd",
|
|
51
|
+
"passphrase",
|
|
52
|
+
"authorization",
|
|
53
|
+
"cookie",
|
|
54
|
+
"cookies",
|
|
55
|
+
"credential",
|
|
56
|
+
"credentials",
|
|
57
|
+
"privatekey",
|
|
58
|
+
"apikeyenv",
|
|
59
|
+
"headers",
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
/** 形似凭据的值前缀(命中即 fail-closed,不回显原文)。 */
|
|
63
|
+
const CREDENTIAL_VALUE_PREFIXES = [
|
|
64
|
+
"sk-",
|
|
65
|
+
"sk_",
|
|
66
|
+
"ghp_",
|
|
67
|
+
"gho_",
|
|
68
|
+
"ghs_",
|
|
69
|
+
"github_pat_",
|
|
70
|
+
"xoxb-",
|
|
71
|
+
"xoxp-",
|
|
72
|
+
"akia",
|
|
73
|
+
"asia",
|
|
74
|
+
"bearer ",
|
|
75
|
+
"basic ",
|
|
76
|
+
"-----begin ",
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
/** 只允许出现在 dict 键/数组下标里的安全字符(挡住把路径/URL/凭据塞进键名)。 */
|
|
80
|
+
const SAFE_KEY_SEGMENT = /^[A-Za-z0-9._:@+-]{1,128}$/;
|
|
81
|
+
|
|
82
|
+
/** 判断是否普通对象(可递归)。 */
|
|
83
|
+
const isPlainRecord = (value) =>
|
|
84
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
85
|
+
|
|
86
|
+
/** JSON 形状深比较(值都是 JSON 形状,够用且不引入依赖)。 */
|
|
87
|
+
const sameJson = (a, b) => {
|
|
88
|
+
if (a === b) return true;
|
|
89
|
+
if (typeof a !== typeof b) return false;
|
|
90
|
+
if (a === null || b === null) return false;
|
|
91
|
+
if (typeof a !== "object") return false;
|
|
92
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
93
|
+
if (Array.isArray(a)) {
|
|
94
|
+
return a.length === b.length && a.every((item, index) => sameJson(item, b[index]));
|
|
95
|
+
}
|
|
96
|
+
const ak = Object.keys(a);
|
|
97
|
+
const bk = Object.keys(b);
|
|
98
|
+
if (ak.length !== bk.length) return false;
|
|
99
|
+
return ak.every((key) => Object.hasOwn(b, key) && sameJson(a[key], b[key]));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ── schema 解析(schemastery toJSON 信封:{uid, refs}) ────────────────────────
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 解析序列化 schema 信封。
|
|
106
|
+
*
|
|
107
|
+
* 兼容信封 `{uid, refs}` 与节点内以 uid 数字自引用的形式(schemastery `toJSON()` 的实测形状)。
|
|
108
|
+
* 任何不认识的形状返回 `undefined` —— 调用方据此让该命名空间 fail-closed。
|
|
109
|
+
*/
|
|
110
|
+
const parseSchemaEnvelope = (schema) => {
|
|
111
|
+
if (!isPlainRecord(schema)) return undefined;
|
|
112
|
+
const refs = schema.refs;
|
|
113
|
+
if (!isPlainRecord(refs)) return undefined;
|
|
114
|
+
if (typeof schema.uid !== "number") return undefined;
|
|
115
|
+
const resolveNode = (node) => {
|
|
116
|
+
if (typeof node === "number") return isPlainRecord(refs[node]) ? refs[node] : undefined;
|
|
117
|
+
return isPlainRecord(node) ? node : undefined;
|
|
118
|
+
};
|
|
119
|
+
const root = resolveNode(schema.uid);
|
|
120
|
+
if (!root) return undefined;
|
|
121
|
+
return { root, resolveNode };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 遍历 schema,收集 secret 路径模式与 schema 默认值。
|
|
126
|
+
*
|
|
127
|
+
* secret 判定:`meta.role === "secret"`(密文本身)或 `"credential-ref"`(凭据引用名,
|
|
128
|
+
* 常内嵌账号 id,保守起见同待遇)。命中 secret 的节点**不再下钻**(整棵子树即 secret)。
|
|
129
|
+
*
|
|
130
|
+
* 路径里的 `*` 表示 dict 键或数组下标(schema 不知道具体键)。
|
|
131
|
+
* 注意宿主 `describe()` 的 schema 已过 `plainSchema()`:secret 节点的 `meta.default`
|
|
132
|
+
* 被删掉,其余节点保留(且其 default 已被 `redactSecrets` 处理过)。
|
|
133
|
+
*/
|
|
134
|
+
const scanSchema = (parsed) => {
|
|
135
|
+
const secretPatterns = [];
|
|
136
|
+
const defaults = new Map(); // JSON.stringify(pattern) → default
|
|
137
|
+
const seen = new Set();
|
|
138
|
+
const walk = (node, pattern, depth) => {
|
|
139
|
+
if (!node || depth > MAX_DEPTH) return;
|
|
140
|
+
const uid = typeof node.uid === "number" ? node.uid : undefined;
|
|
141
|
+
const guard = `${pattern.join("\u0000")}|${uid ?? "inline"}`;
|
|
142
|
+
if (seen.has(guard)) return;
|
|
143
|
+
seen.add(guard);
|
|
144
|
+
const role = node?.meta?.role;
|
|
145
|
+
if (role === "secret" || role === "credential-ref") {
|
|
146
|
+
secretPatterns.push([...pattern]);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (Object.hasOwn(node?.meta ?? {}, "default")) {
|
|
150
|
+
defaults.set(JSON.stringify(pattern), node.meta.default);
|
|
151
|
+
}
|
|
152
|
+
const dict = isPlainRecord(node?.dict) ? node.dict : undefined;
|
|
153
|
+
if (dict) {
|
|
154
|
+
for (const [key, child] of Object.entries(dict)) {
|
|
155
|
+
walk(parsed.resolveNode(child), [...pattern, key], depth + 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (node?.inner !== undefined) {
|
|
159
|
+
walk(parsed.resolveNode(node.inner), [...pattern, "*"], depth + 1);
|
|
160
|
+
}
|
|
161
|
+
if (Array.isArray(node?.list)) {
|
|
162
|
+
// union/intersect:所有分支都算(保守并集),仍按当前路径记录。
|
|
163
|
+
for (const child of node.list) walk(parsed.resolveNode(child), pattern, depth + 1);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
walk(parsed.root, [], 0);
|
|
167
|
+
return { secretPatterns, defaults };
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// ── 污点判定 / 结构剥离 ──────────────────────────────────────────────────────
|
|
171
|
+
|
|
172
|
+
/** 路径前缀匹配(pattern 里的 `*` 匹配任意单段)。 */
|
|
173
|
+
const patternIsPrefix = (pattern, path) => {
|
|
174
|
+
if (pattern.length > path.length) return false;
|
|
175
|
+
return pattern.every((segment, index) => segment === "*" || segment === path[index]);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** 键名黑名单判定(大小写与分隔符不敏感)。 */
|
|
179
|
+
const keyNameDenied = (segment) => {
|
|
180
|
+
const collapsed = String(segment).toLowerCase().replace(/[_\-\s.]/g, "");
|
|
181
|
+
return DENY_KEY_NAMES.has(collapsed);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 一条具体路径是否**位于 secret 子树内**(祖先规则)。
|
|
186
|
+
*
|
|
187
|
+
* 只做"祖先"方向:P 是 path 的前缀 ⇒ 整个子树移除。反方向(path 是 P 的前缀)**不在这里**
|
|
188
|
+
* 处理——它是"这个字段内含 secret",属于**投影取舍**(见 `overlapsSecret`),而不是剥离规则。
|
|
189
|
+
* 两者混用会把 `providers` 这样的大对象整棵删掉,反而让白名单里同级的正常字段凭空消失。
|
|
190
|
+
*/
|
|
191
|
+
const pathInsideSecret = (path, secretPatterns) => {
|
|
192
|
+
if (path.some(keyNameDenied)) return true;
|
|
193
|
+
return secretPatterns.some((pattern) => patternIsPrefix(pattern, path));
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 结构化剥离:从值里删掉所有 secret 污染路径(保留其余结构与数组形状)。
|
|
198
|
+
*
|
|
199
|
+
* 这不是展示通路(白名单叶子单独投影),而是"即便将来白名单加字段也不会顺手带出
|
|
200
|
+
* secret"的第二道保险,也是 `value`/`base`/`user` 三层都要过一遍的原因。
|
|
201
|
+
*/
|
|
202
|
+
const stripSecretSubtrees = (value, secretPatterns, path = [], depth = 0) => {
|
|
203
|
+
if (depth > MAX_DEPTH) return undefined;
|
|
204
|
+
if (Array.isArray(value)) {
|
|
205
|
+
return value.map((item, index) =>
|
|
206
|
+
pathInsideSecret([...path, String(index)], secretPatterns)
|
|
207
|
+
? null
|
|
208
|
+
: stripSecretSubtrees(item, secretPatterns, [...path, String(index)], depth + 1) ?? null,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (isPlainRecord(value)) {
|
|
212
|
+
const out = {};
|
|
213
|
+
for (const [key, item] of Object.entries(value)) {
|
|
214
|
+
const next = [...path, key];
|
|
215
|
+
if (pathInsideSecret(next, secretPatterns)) continue;
|
|
216
|
+
const stripped = stripSecretSubtrees(item, secretPatterns, next, depth + 1);
|
|
217
|
+
if (stripped === undefined) continue;
|
|
218
|
+
out[key] = stripped;
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// ── 值擦除(绝对路径 / URL / 凭据 / 连接串) ──────────────────────────────────
|
|
226
|
+
|
|
227
|
+
/** 擦除失败原因码(稳定代号,**不含原文**;进入响应也不泄露原值)。 */
|
|
228
|
+
export const SCRUB_REASON = Object.freeze({
|
|
229
|
+
PATH: "value-with-absolute-path",
|
|
230
|
+
URL: "value-with-url",
|
|
231
|
+
CREDENTIAL: "value-with-credential",
|
|
232
|
+
CONNECTION_STRING: "value-with-connection-string",
|
|
233
|
+
KEY: "value-with-unsafe-key",
|
|
234
|
+
LENGTH: "value-too-long",
|
|
235
|
+
SHAPE: "value-not-scalar",
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 判断一个标量值能不能安全展示。
|
|
240
|
+
*
|
|
241
|
+
* 命中即 fail-closed:**不带原文、也不做部分打码**——部分打码仍可能泄露前缀,
|
|
242
|
+
* 而设计稿要求"宁可不显示,也不透出未擦除值"。
|
|
243
|
+
*
|
|
244
|
+
* @returns `{ok:true, text, kind, ...}` 或 `{ok:false, reason}`
|
|
245
|
+
*/
|
|
246
|
+
export const scrubScalar = (value) => {
|
|
247
|
+
if (typeof value === "boolean") {
|
|
248
|
+
return { ok: true, text: value ? "true" : "false", kind: "boolean", boolValue: value };
|
|
249
|
+
}
|
|
250
|
+
if (typeof value === "number") {
|
|
251
|
+
if (!Number.isFinite(value)) return { ok: false, reason: SCRUB_REASON.SHAPE };
|
|
252
|
+
return { ok: true, text: String(value), kind: "number", numberValue: value };
|
|
253
|
+
}
|
|
254
|
+
if (typeof value !== "string") return { ok: false, reason: SCRUB_REASON.SHAPE };
|
|
255
|
+
const text = value.trim();
|
|
256
|
+
if (text.length > MAX_VALUE_TEXT) return { ok: false, reason: SCRUB_REASON.LENGTH };
|
|
257
|
+
if (text === "") return { ok: true, text: "", kind: "string" };
|
|
258
|
+
const lower = text.toLowerCase();
|
|
259
|
+
// 1) URL:白名单里不应出现任何端点;一旦出现就整项不显示(userinfo / 主机 / 端口 /
|
|
260
|
+
// 路径都可能是凭据或拓扑)。`scheme://` 形态一律拦。
|
|
261
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(text)) return { ok: false, reason: SCRUB_REASON.URL };
|
|
262
|
+
// 2) 连接串形态:`k=v;k=v;…` 至少两对(如 `Server=…;Password=…`)。
|
|
263
|
+
if (/^(?:[A-Za-z][\w.-]*=[^;]*;){2,}/.test(text)) {
|
|
264
|
+
return { ok: false, reason: SCRUB_REASON.CONNECTION_STRING };
|
|
265
|
+
}
|
|
266
|
+
// 3) 绝对路径:POSIX / Home / Windows 盘符 / UNC。
|
|
267
|
+
if (
|
|
268
|
+
text.startsWith("/") ||
|
|
269
|
+
text.startsWith("~/") ||
|
|
270
|
+
text === "~" ||
|
|
271
|
+
/^[A-Za-z]:[\\/]/.test(text) ||
|
|
272
|
+
text.startsWith("\\\\")
|
|
273
|
+
) {
|
|
274
|
+
return { ok: false, reason: SCRUB_REASON.PATH };
|
|
275
|
+
}
|
|
276
|
+
// 4) 形似凭据:已知前缀,或"无分隔符长令牌"(base64/hex/超长单串)。
|
|
277
|
+
// 刻意**不**把 `a-b_c.d` 式标识串(模型名、路由名、预设名)当凭据。
|
|
278
|
+
if (CREDENTIAL_VALUE_PREFIXES.some((prefix) => lower.startsWith(prefix))) {
|
|
279
|
+
return { ok: false, reason: SCRUB_REASON.CREDENTIAL };
|
|
280
|
+
}
|
|
281
|
+
if (
|
|
282
|
+
/^[A-Za-z0-9+/]{32,}={0,2}$/.test(text) ||
|
|
283
|
+
/^[0-9a-fA-F]{32,}$/.test(text) ||
|
|
284
|
+
/^[A-Za-z0-9_-]{40,}$/.test(text)
|
|
285
|
+
) {
|
|
286
|
+
return { ok: false, reason: SCRUB_REASON.CREDENTIAL };
|
|
287
|
+
}
|
|
288
|
+
return { ok: true, text, kind: "string" };
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/** dict 键 / 数组下标同样要过擦除器:用户可能把预设名写成路径或令牌。 */
|
|
292
|
+
const scrubKeySegment = (segment) => {
|
|
293
|
+
const text = String(segment);
|
|
294
|
+
if (!SAFE_KEY_SEGMENT.test(text)) return { ok: false, reason: SCRUB_REASON.KEY };
|
|
295
|
+
if (keyNameDenied(text)) return { ok: false, reason: SCRUB_REASON.KEY };
|
|
296
|
+
const scrubbed = scrubScalar(text);
|
|
297
|
+
if (!scrubbed.ok) return { ok: false, reason: SCRUB_REASON.KEY };
|
|
298
|
+
return { ok: true, text };
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// ── 分层取值 ────────────────────────────────────────────────────────────────
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 按白名单路径取值,`*` 展开为具体键。
|
|
305
|
+
*
|
|
306
|
+
* @returns `{ok:true, entries:[{path, value}]}` 或 `{ok:false, reason}`
|
|
307
|
+
*/
|
|
308
|
+
const collectPathEntries = (value, pattern, path = [], depth = 0) => {
|
|
309
|
+
if (depth > MAX_DEPTH) return { ok: false, reason: "path-too-deep" };
|
|
310
|
+
if (pattern.length === 0) return { ok: true, entries: [{ path, value }] };
|
|
311
|
+
const [head, ...rest] = pattern;
|
|
312
|
+
if (head === "*") {
|
|
313
|
+
if (Array.isArray(value)) {
|
|
314
|
+
if (value.length > MAX_WILDCARD_ITEMS) return { ok: false, reason: "wildcard-overflow" };
|
|
315
|
+
const entries = [];
|
|
316
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
317
|
+
const keyCheck = scrubKeySegment(String(index));
|
|
318
|
+
if (!keyCheck.ok) return { ok: false, reason: keyCheck.reason };
|
|
319
|
+
const next = collectPathEntries(value[index], rest, [...path, String(index)], depth + 1);
|
|
320
|
+
if (!next.ok) return next;
|
|
321
|
+
entries.push(...next.entries);
|
|
322
|
+
}
|
|
323
|
+
return { ok: true, entries };
|
|
324
|
+
}
|
|
325
|
+
if (isPlainRecord(value)) {
|
|
326
|
+
const keys = Object.keys(value);
|
|
327
|
+
if (keys.length > MAX_WILDCARD_ITEMS) return { ok: false, reason: "wildcard-overflow" };
|
|
328
|
+
const entries = [];
|
|
329
|
+
for (const key of keys) {
|
|
330
|
+
const keyCheck = scrubKeySegment(key);
|
|
331
|
+
if (!keyCheck.ok) return { ok: false, reason: keyCheck.reason };
|
|
332
|
+
const next = collectPathEntries(value[key], rest, [...path, key], depth + 1);
|
|
333
|
+
if (!next.ok) return next;
|
|
334
|
+
entries.push(...next.entries);
|
|
335
|
+
}
|
|
336
|
+
return { ok: true, entries };
|
|
337
|
+
}
|
|
338
|
+
return { ok: true, entries: [] };
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(value)) {
|
|
341
|
+
// schema 说这里是对象键,实际是数组:形状漂移,不猜。
|
|
342
|
+
return { ok: false, reason: "shape-mismatch" };
|
|
343
|
+
}
|
|
344
|
+
if (!isPlainRecord(value)) return { ok: true, entries: [] };
|
|
345
|
+
if (!Object.hasOwn(value, head)) return { ok: true, entries: [] };
|
|
346
|
+
const keyCheck = scrubKeySegment(head);
|
|
347
|
+
if (!keyCheck.ok) return { ok: false, reason: keyCheck.reason };
|
|
348
|
+
return collectPathEntries(value[head], rest, [...path, head], depth + 1);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/** 该具体路径是否出现在 user 覆盖层(决定"用户覆盖"来源标签)。 */
|
|
352
|
+
const userLayerHasPath = (user, path) => {
|
|
353
|
+
if (!isPlainRecord(user)) return false;
|
|
354
|
+
let current = user;
|
|
355
|
+
for (const segment of path) {
|
|
356
|
+
if (Array.isArray(current)) {
|
|
357
|
+
const index = Number(segment);
|
|
358
|
+
if (!Number.isInteger(index) || index < 0 || index >= current.length) return false;
|
|
359
|
+
current = current[index];
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (!isPlainRecord(current) || !Object.hasOwn(current, segment)) return false;
|
|
363
|
+
current = current[segment];
|
|
364
|
+
}
|
|
365
|
+
return true;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/** 按具体路径取 schema 默认值(回落到带 `*` 的 pattern)。 */
|
|
369
|
+
const defaultForPath = (defaults, path) => {
|
|
370
|
+
if (defaults.size === 0) return { known: false };
|
|
371
|
+
const exact = defaults.get(JSON.stringify(path));
|
|
372
|
+
if (exact !== undefined) return { known: true, value: exact };
|
|
373
|
+
for (const [key, value] of defaults) {
|
|
374
|
+
let pattern;
|
|
375
|
+
try {
|
|
376
|
+
pattern = JSON.parse(key);
|
|
377
|
+
} catch {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (
|
|
381
|
+
Array.isArray(pattern) &&
|
|
382
|
+
pattern.length === path.length &&
|
|
383
|
+
pattern.every((segment, index) => segment === "*" || segment === path[index])
|
|
384
|
+
) {
|
|
385
|
+
return { known: true, value };
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return { known: false };
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 取某一层(value/base)在给定路径上的标量,并**当场擦除**。
|
|
393
|
+
*
|
|
394
|
+
* @returns `{ok:true, text, absent:boolean}` 或 `{ok:false, reason}`
|
|
395
|
+
*/
|
|
396
|
+
const scrubLayerValue = (layer, path) => {
|
|
397
|
+
const collected = collectPathEntries(layer, path);
|
|
398
|
+
if (!collected.ok) return { ok: false, reason: collected.reason ?? "path-expand-failed" };
|
|
399
|
+
if (collected.entries.length === 0) return { ok: true, absent: true };
|
|
400
|
+
const raw = collected.entries[0].value;
|
|
401
|
+
const scrubbed = scrubScalar(raw);
|
|
402
|
+
if (!scrubbed.ok) return { ok: false, reason: scrubbed.reason };
|
|
403
|
+
// `raw` 只用于**来源判定**(与 schema 默认值原样比较),不进入响应。
|
|
404
|
+
return { ok: true, absent: false, text: scrubbed.text, raw };
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// ── 来源判定(只给语义标签,不给原始路径) ────────────────────────────────────
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 来源:
|
|
411
|
+
* - `user` 用户覆盖(user 层含该路径);
|
|
412
|
+
* - `base` 组合默认(base 层有值且与 schema 默认不同);
|
|
413
|
+
* - `default` schema 默认;
|
|
414
|
+
* - `unknown` base/user 层**缺失**(不是"空")→ 不猜。
|
|
415
|
+
*
|
|
416
|
+
* "层存在但值为空"与"层根本不存在"必须分开:`describe()` 在 0.2.x 上总是给出
|
|
417
|
+
* `base`/`user` 键(值可能是 undefined,表示该层没有内容),旧宿主才会缺键。
|
|
418
|
+
*/
|
|
419
|
+
const sourceOfPath = ({ path, baseRaw, hasBaseLayer, hasUserLayer, user, schemaDefault }) => {
|
|
420
|
+
if (!hasBaseLayer || !hasUserLayer) return "unknown";
|
|
421
|
+
if (userLayerHasPath(user, path)) return "user";
|
|
422
|
+
// 与 schema 默认**原样**比较:擦除后是展示字符串,拿它比数字/布尔会永远"不同"。
|
|
423
|
+
if (baseRaw !== undefined && (!schemaDefault.known || !sameJson(baseRaw, schemaDefault.value))) return "base";
|
|
424
|
+
return "default";
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// ── 单个命名空间投影 ────────────────────────────────────────────────────────
|
|
428
|
+
|
|
429
|
+
const namespaceError = (entries, reason) => ({
|
|
430
|
+
ns: entries[0].ns,
|
|
431
|
+
title: entries[0].namespaceTitle,
|
|
432
|
+
titleEn: entries[0].namespaceTitleEn,
|
|
433
|
+
groupId: entries[0].group,
|
|
434
|
+
revision: null,
|
|
435
|
+
complete: false,
|
|
436
|
+
reason,
|
|
437
|
+
fields: [],
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 把一个命名空间投影成白名单字段列表。
|
|
442
|
+
*
|
|
443
|
+
* @param {object|undefined} row `describe({redactSecrets:true})` 的一行
|
|
444
|
+
* @param {ReadonlyArray<object>} entries 该命名空间的白名单条目
|
|
445
|
+
* @param {{ok:boolean, reason?:string, value?:unknown}} strictRead 严格读取器结果
|
|
446
|
+
*/
|
|
447
|
+
const projectNamespace = (row, entries, strictRead) => {
|
|
448
|
+
const fail = (reason) => namespaceError(entries, reason);
|
|
449
|
+
if (!strictRead.ok) return fail(strictRead.reason ?? "settings-unreadable");
|
|
450
|
+
if (!isPlainRecord(row)) return fail("settings-descriptor-invalid");
|
|
451
|
+
|
|
452
|
+
const parsed = parseSchemaEnvelope(row.schema);
|
|
453
|
+
if (!parsed) return fail("schema-unparsable");
|
|
454
|
+
let secretPatterns;
|
|
455
|
+
let defaults;
|
|
456
|
+
try {
|
|
457
|
+
const scanned = scanSchema(parsed);
|
|
458
|
+
secretPatterns = scanned.secretPatterns;
|
|
459
|
+
defaults = scanned.defaults;
|
|
460
|
+
} catch {
|
|
461
|
+
return fail("schema-unparsable");
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// "层存在"以**键存在**为准(值可能是 undefined),与"旧宿主缺键"区分开。
|
|
465
|
+
const hasBaseLayer = Object.hasOwn(row, "base");
|
|
466
|
+
const hasUserLayer = Object.hasOwn(row, "user");
|
|
467
|
+
|
|
468
|
+
let value;
|
|
469
|
+
let base;
|
|
470
|
+
let user;
|
|
471
|
+
try {
|
|
472
|
+
value = stripSecretSubtrees(row.value, secretPatterns);
|
|
473
|
+
base = hasBaseLayer ? stripSecretSubtrees(row.base, secretPatterns) : undefined;
|
|
474
|
+
user = hasUserLayer ? stripSecretSubtrees(row.user, secretPatterns) : undefined;
|
|
475
|
+
} catch {
|
|
476
|
+
return fail("redaction-failed");
|
|
477
|
+
}
|
|
478
|
+
if (!isPlainRecord(value)) return fail("settings-value-invalid");
|
|
479
|
+
|
|
480
|
+
// describe 已剥过 secret,但仍按 schema 收集槽位的 set 状态,供"已设置/未设置"。
|
|
481
|
+
const secretStates = new Map();
|
|
482
|
+
for (const item of Array.isArray(row.secrets) ? row.secrets : []) {
|
|
483
|
+
if (!isPlainRecord(item) || !Array.isArray(item.path)) continue;
|
|
484
|
+
secretStates.set(JSON.stringify(item.path.map(String)), item.set === true);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const fields = [];
|
|
488
|
+
for (const entry of entries) {
|
|
489
|
+
const pattern = entry.path;
|
|
490
|
+
const exactSecret = secretPatterns.some((secret) => {
|
|
491
|
+
if (secret.length !== pattern.length) return false;
|
|
492
|
+
return secret.every((segment, index) => segment === "*" || segment === pattern[index]);
|
|
493
|
+
});
|
|
494
|
+
// 祖先/后代关系一律不投影:祖先会把 secret 子树当普通值展开,后代则拿不到
|
|
495
|
+
// 正确槽位。两者都 fail-closed,不猜。
|
|
496
|
+
const overlapsSecret = secretPatterns.some(
|
|
497
|
+
(secret) => patternIsPrefix(secret, pattern) || patternIsPrefix(pattern, secret),
|
|
498
|
+
);
|
|
499
|
+
if (exactSecret) {
|
|
500
|
+
const set = secretStates.get(JSON.stringify(pattern.map(String)));
|
|
501
|
+
if (set === undefined) return fail("secret-slot-missing");
|
|
502
|
+
fields.push({
|
|
503
|
+
ns: entry.ns,
|
|
504
|
+
groupId: entry.group,
|
|
505
|
+
title: entry.title,
|
|
506
|
+
titleEn: entry.titleEn,
|
|
507
|
+
keyPath: pattern.join("."),
|
|
508
|
+
kind: "secret",
|
|
509
|
+
secretSet: set,
|
|
510
|
+
source: "unknown",
|
|
511
|
+
defaultText: null,
|
|
512
|
+
baseText: null,
|
|
513
|
+
layers: { user: null, base: null, schema: false },
|
|
514
|
+
});
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (overlapsSecret) return fail("field-overlaps-secret");
|
|
518
|
+
|
|
519
|
+
const collected = collectPathEntries(value, pattern);
|
|
520
|
+
if (!collected.ok) return fail(collected.reason ?? "path-expand-failed");
|
|
521
|
+
for (const found of collected.entries) {
|
|
522
|
+
if (fields.length >= MAX_FIELDS_PER_NAMESPACE) return fail("too-many-fields");
|
|
523
|
+
const scrubbed = scrubScalar(found.value);
|
|
524
|
+
if (!scrubbed.ok) return fail(scrubbed.reason);
|
|
525
|
+
const baseLayer = hasBaseLayer ? scrubLayerValue(base, found.path) : { ok: true, absent: true };
|
|
526
|
+
if (!baseLayer.ok) return fail(baseLayer.reason);
|
|
527
|
+
const schemaDefault = defaultForPath(defaults, found.path);
|
|
528
|
+
let defaultText = null;
|
|
529
|
+
if (schemaDefault.known && schemaDefault.value !== undefined) {
|
|
530
|
+
const scrubbedDefault = scrubScalar(schemaDefault.value);
|
|
531
|
+
// 默认值层同样过擦除器 —— 这一条专治"从默认值旁路泄露"。
|
|
532
|
+
if (!scrubbedDefault.ok) return fail(scrubbedDefault.reason);
|
|
533
|
+
defaultText = scrubbedDefault.text;
|
|
534
|
+
}
|
|
535
|
+
const baseText = baseLayer.absent ? null : baseLayer.text;
|
|
536
|
+
const source = sourceOfPath({
|
|
537
|
+
path: found.path,
|
|
538
|
+
baseRaw: baseLayer.raw,
|
|
539
|
+
hasBaseLayer,
|
|
540
|
+
hasUserLayer,
|
|
541
|
+
user,
|
|
542
|
+
schemaDefault,
|
|
543
|
+
});
|
|
544
|
+
fields.push({
|
|
545
|
+
ns: entry.ns,
|
|
546
|
+
groupId: entry.group,
|
|
547
|
+
title: entry.title,
|
|
548
|
+
titleEn: entry.titleEn,
|
|
549
|
+
keyPath: found.path.join("."),
|
|
550
|
+
kind: "value",
|
|
551
|
+
valueText: scrubbed.text,
|
|
552
|
+
valueKind: scrubbed.kind,
|
|
553
|
+
...(scrubbed.kind === "boolean" ? { boolValue: scrubbed.boolValue === true } : {}),
|
|
554
|
+
...(scrubbed.kind === "number" ? { numberValue: scrubbed.numberValue } : {}),
|
|
555
|
+
defaultText,
|
|
556
|
+
baseText,
|
|
557
|
+
hasDefault: defaultText !== null,
|
|
558
|
+
source,
|
|
559
|
+
layers: {
|
|
560
|
+
user: hasUserLayer ? userLayerHasPath(user, found.path) : null,
|
|
561
|
+
base: hasBaseLayer ? baseText !== null : null,
|
|
562
|
+
schema: schemaDefault.known && schemaDefault.value !== undefined,
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return {
|
|
569
|
+
ns: entries[0].ns,
|
|
570
|
+
title: entries[0].namespaceTitle,
|
|
571
|
+
titleEn: entries[0].namespaceTitleEn,
|
|
572
|
+
groupId: entries[0].group,
|
|
573
|
+
revision: typeof row.revision === "number" ? row.revision : null,
|
|
574
|
+
complete: true,
|
|
575
|
+
reason: "",
|
|
576
|
+
fields,
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// ── 端点级投影 ──────────────────────────────────────────────────────────────
|
|
581
|
+
|
|
582
|
+
/** 把白名单按 namespace 分组,保持首次出现顺序。 */
|
|
583
|
+
const groupWhitelistByNamespace = () => {
|
|
584
|
+
const order = [];
|
|
585
|
+
const byNs = new Map();
|
|
586
|
+
for (const entry of HOST_SETTINGS_WHITELIST) {
|
|
587
|
+
if (!byNs.has(entry.ns)) {
|
|
588
|
+
byNs.set(entry.ns, []);
|
|
589
|
+
order.push(entry.ns);
|
|
590
|
+
}
|
|
591
|
+
byNs.get(entry.ns).push(entry);
|
|
592
|
+
}
|
|
593
|
+
return order.map((ns) => byNs.get(ns));
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* 构造 `/m/api/host-settings` 的响应体(**只读、只含白名单项**)。
|
|
598
|
+
*
|
|
599
|
+
* 降级形状(全部 HTTP 200,App 据此区分"不支持/部分可见",不是网络失败):
|
|
600
|
+
* - 没有 settings 服务 / 没有 describe / describe 抛错或形状漂移:`supported:false` + `reason`;
|
|
601
|
+
* - 白名单为空:`supported:false` + `reason:"whitelist-empty"`;
|
|
602
|
+
* - 单个命名空间失败:该命名空间 `complete:false` + `reason`,`fields` 为空数组;
|
|
603
|
+
* - 任一命名空间失败:`complete:false`(页面级提示"部分设置不可用")。
|
|
604
|
+
* - 命名空间在本宿主上不存在:整段省略(白名单项不可见,不算错误)。
|
|
605
|
+
*
|
|
606
|
+
* @param {object} input
|
|
607
|
+
* @param {object|undefined} input.settings 宿主 settings 服务(`ctx.get("settings")`)
|
|
608
|
+
* @param {(settings: object, ns: string) => {ok: boolean, value?: unknown, reason?: string}} input.readSection
|
|
609
|
+
* 既有严格读取器 `readSettingsSectionStrict`(由调用方注入,避免循环依赖)
|
|
610
|
+
* @param {() => string} [input.hostVersion] DSH 版本(取不到就是空串,不猜)
|
|
611
|
+
* @param {() => string} [input.pluginVersion] 本插件版本
|
|
612
|
+
* @param {() => string} [input.now] 时间戳(测试可注入)
|
|
613
|
+
*/
|
|
614
|
+
export const buildHostSettingsView = ({
|
|
615
|
+
settings,
|
|
616
|
+
readSection,
|
|
617
|
+
hostVersion,
|
|
618
|
+
pluginVersion,
|
|
619
|
+
now,
|
|
620
|
+
} = {}) => {
|
|
621
|
+
const generatedAt = typeof now === "function" ? now() : new Date().toISOString();
|
|
622
|
+
const shell = {
|
|
623
|
+
ok: true,
|
|
624
|
+
supported: true,
|
|
625
|
+
complete: true,
|
|
626
|
+
reason: "",
|
|
627
|
+
writable: false,
|
|
628
|
+
whitelistVersion: HOST_SETTINGS_WHITELIST_VERSION,
|
|
629
|
+
generatedAt,
|
|
630
|
+
// 主机事实(不是设置项):只给版本串,不给地址、路径、主机名。
|
|
631
|
+
host: {
|
|
632
|
+
dshVersion: typeof hostVersion === "function" ? String(hostVersion() ?? "") : "",
|
|
633
|
+
pluginVersion: typeof pluginVersion === "function" ? String(pluginVersion() ?? "") : "",
|
|
634
|
+
},
|
|
635
|
+
groups: HOST_SETTINGS_GROUPS.map((group) => ({ ...group })),
|
|
636
|
+
namespaces: [],
|
|
637
|
+
};
|
|
638
|
+
if (hostSettingsWhitelistIsEmpty()) {
|
|
639
|
+
return { ...shell, supported: false, complete: false, reason: "whitelist-empty" };
|
|
640
|
+
}
|
|
641
|
+
if (!settings) {
|
|
642
|
+
return { ...shell, supported: false, complete: false, reason: "settings-service-missing" };
|
|
643
|
+
}
|
|
644
|
+
// 0.1.x 只有 `get(ns)`:拿不到 base/user/secrets/schema,无法保证三层脱敏 →
|
|
645
|
+
// 整页降级,不退回"只给 value"的半吊子实现。
|
|
646
|
+
if (typeof settings.describe !== "function") {
|
|
647
|
+
return { ...shell, supported: false, complete: false, reason: "settings-describe-unavailable" };
|
|
648
|
+
}
|
|
649
|
+
if (typeof readSection !== "function") {
|
|
650
|
+
return { ...shell, supported: false, complete: false, reason: "settings-reader-missing" };
|
|
651
|
+
}
|
|
652
|
+
let rows;
|
|
653
|
+
try {
|
|
654
|
+
rows = settings.describe({ redactSecrets: true });
|
|
655
|
+
} catch {
|
|
656
|
+
return { ...shell, supported: false, complete: false, reason: "settings-describe-threw" };
|
|
657
|
+
}
|
|
658
|
+
if (!Array.isArray(rows)) {
|
|
659
|
+
return { ...shell, supported: false, complete: false, reason: "settings-describe-shape-invalid" };
|
|
660
|
+
}
|
|
661
|
+
const rowByNs = new Map();
|
|
662
|
+
for (const row of rows) {
|
|
663
|
+
if (isPlainRecord(row) && typeof row.ns === "string") rowByNs.set(row.ns, row);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const namespaces = [];
|
|
667
|
+
const failures = [];
|
|
668
|
+
for (const entries of groupWhitelistByNamespace()) {
|
|
669
|
+
const ns = entries[0].ns;
|
|
670
|
+
let strictRead;
|
|
671
|
+
try {
|
|
672
|
+
strictRead = readSection(settings, ns);
|
|
673
|
+
} catch {
|
|
674
|
+
strictRead = { ok: false, reason: "settings-reader-threw" };
|
|
675
|
+
}
|
|
676
|
+
if (!isPlainRecord(strictRead) || typeof strictRead.ok !== "boolean") {
|
|
677
|
+
strictRead = { ok: false, reason: "settings-reader-shape-invalid" };
|
|
678
|
+
}
|
|
679
|
+
if (strictRead.ok && strictRead.value === undefined) {
|
|
680
|
+
// 该命名空间在本宿主上不存在 → 白名单项不可见(不是错误,也不是"关闭")。
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const projected = projectNamespace(rowByNs.get(ns), entries, strictRead);
|
|
684
|
+
if (!projected.complete) failures.push(projected.reason);
|
|
685
|
+
namespaces.push(projected);
|
|
686
|
+
}
|
|
687
|
+
const complete = failures.length === 0;
|
|
688
|
+
return {
|
|
689
|
+
...shell,
|
|
690
|
+
complete,
|
|
691
|
+
// 只回传**稳定原因码**,不回显任何原始值或路径。
|
|
692
|
+
reason: complete ? "" : failures[0],
|
|
693
|
+
namespaces,
|
|
694
|
+
};
|
|
695
|
+
};
|