@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,480 @@
|
|
|
1
|
+
import { constants as fsConstants } from "node:fs";
|
|
2
|
+
import { realpath, open, lstat } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
const UNTRACKED_PREVIEW_MAX = 512 * 1024;
|
|
7
|
+
const SIGNATURE_SAMPLE_BYTES = 4096;
|
|
8
|
+
const readOnlyNoFollow = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0);
|
|
9
|
+
function sameRegularFile(expected, opened) {
|
|
10
|
+
return expected.isFile() && opened.isFile() && expected.dev === opened.dev && expected.ino === opened.ino;
|
|
11
|
+
}
|
|
12
|
+
async function readPrefix(path, maximum, expected) {
|
|
13
|
+
const handle = await open(path, readOnlyNoFollow);
|
|
14
|
+
try {
|
|
15
|
+
if (!sameRegularFile(expected, await handle.stat())) throw new Error("file changed while opening preview");
|
|
16
|
+
const buffer = Buffer.alloc(maximum + 1);
|
|
17
|
+
const { bytesRead } = await handle.read(buffer, 0, maximum + 1, 0);
|
|
18
|
+
return { bytes: buffer.subarray(0, bytesRead), truncated: bytesRead > maximum };
|
|
19
|
+
} finally { await handle.close(); }
|
|
20
|
+
}
|
|
21
|
+
async function sampledFileSignature(path, info) {
|
|
22
|
+
const handle = await open(path, readOnlyNoFollow);
|
|
23
|
+
try {
|
|
24
|
+
if (!sameRegularFile(info, await handle.stat())) throw new Error("file changed while sampling worktree");
|
|
25
|
+
const first = Buffer.alloc(Math.min(SIGNATURE_SAMPLE_BYTES, info.size));
|
|
26
|
+
const firstRead = await handle.read(first, 0, first.length, 0);
|
|
27
|
+
let last = Buffer.alloc(0);
|
|
28
|
+
if (info.size > SIGNATURE_SAMPLE_BYTES) {
|
|
29
|
+
last = Buffer.alloc(SIGNATURE_SAMPLE_BYTES);
|
|
30
|
+
const read = await handle.read(last, 0, last.length, Math.max(0, info.size - last.length));
|
|
31
|
+
last = last.subarray(0, read.bytesRead);
|
|
32
|
+
}
|
|
33
|
+
return createHash("sha256").update(`${info.dev}:${info.ino}:${info.size}:${info.mtimeMs}:${info.ctimeMs}:`).update(first.subarray(0, firstRead.bytesRead)).update(last).digest("hex");
|
|
34
|
+
} finally { await handle.close(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function gitError(code, status, message = code) {
|
|
38
|
+
const error = new Error(message);
|
|
39
|
+
error.code = code;
|
|
40
|
+
error.status = status;
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const refShortName = (name) => name === "HEAD" ? "HEAD" : String(name).replace(/^refs\/(?:heads|remotes|tags)\//, "");
|
|
45
|
+
const HISTORY_STATUS_LETTER = { A: "A", M: "M", D: "D", R: "R", C: "C", T: "T" };
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parse `git log --format=%x00<meta> --name-status -M -z` output into file
|
|
49
|
+
* history entries. Records are NUL-delimited: a `\x00` start marker, the
|
|
50
|
+
* `\x1f`-separated metadata, then `\x00\n<status>` and its NUL-separated paths.
|
|
51
|
+
* A deadline-aborted command may end mid-record; incomplete trailing records
|
|
52
|
+
* are ignored while every fully parsed commit stays usable.
|
|
53
|
+
*/
|
|
54
|
+
function parseFileHistory(stdout) {
|
|
55
|
+
const tokens = String(stdout ?? "").split("\0");
|
|
56
|
+
const entries = [];
|
|
57
|
+
let index = 0;
|
|
58
|
+
while (index < tokens.length) {
|
|
59
|
+
const metadata = tokens[index++];
|
|
60
|
+
if (!metadata || metadata.startsWith("\n")) continue;
|
|
61
|
+
const fields = metadata.split("\x1f");
|
|
62
|
+
if (fields.length < 5) continue;
|
|
63
|
+
const oid = fields[0];
|
|
64
|
+
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(oid)) continue;
|
|
65
|
+
let status = "M";
|
|
66
|
+
if (index < tokens.length) {
|
|
67
|
+
const marker = tokens[index];
|
|
68
|
+
if (typeof marker === "string" && marker.startsWith("\n")) {
|
|
69
|
+
index++;
|
|
70
|
+
const code = marker.slice(1).trim();
|
|
71
|
+
if (code) {
|
|
72
|
+
status = HISTORY_STATUS_LETTER[code[0]] ?? "M";
|
|
73
|
+
index += /^[RC]/.test(code) ? 2 : 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
entries.push({
|
|
78
|
+
oid,
|
|
79
|
+
shortOid: fields[1] || oid.slice(0, 7),
|
|
80
|
+
author: fields[2] ?? "",
|
|
81
|
+
timestamp: Number(fields[3]) || 0,
|
|
82
|
+
subject: fields.slice(4).join("\x1f"),
|
|
83
|
+
status,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return entries;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Bundled, read-only Git provider. Every command uses the host subprocess service. */
|
|
90
|
+
export function createBundledGitReadProvider(ctx) {
|
|
91
|
+
const get = (name) => {
|
|
92
|
+
try { return ctx.get?.(name); } catch { return undefined; }
|
|
93
|
+
};
|
|
94
|
+
const subprocess = () => get("subprocess") ?? ctx.subprocess;
|
|
95
|
+
const workspaces = () => (get("workspaceRegistry")?.list?.() ?? [])
|
|
96
|
+
.map((entry) => entry?.path).filter((path) => typeof path === "string" && path !== "");
|
|
97
|
+
const inside = (child, parent) => {
|
|
98
|
+
const value = relative(resolve(parent), resolve(child));
|
|
99
|
+
return value === "" || (value !== ".." && !value.startsWith(`..${sep}`) && !isAbsolute(value));
|
|
100
|
+
};
|
|
101
|
+
const assertWorkspace = async (path) => {
|
|
102
|
+
if (typeof path !== "string" || path === "") throw gitError("workspace-not-allowed", 403);
|
|
103
|
+
let canonical;
|
|
104
|
+
try { canonical = await realpath(path); } catch { throw gitError("workspace-not-allowed", 403); }
|
|
105
|
+
const roots = await Promise.all(workspaces().map((root) => realpath(root).catch(() => null)));
|
|
106
|
+
if (!roots.some((root) => root && inside(canonical, root))) throw gitError("workspace-not-allowed", 403);
|
|
107
|
+
return canonical;
|
|
108
|
+
};
|
|
109
|
+
const spawnGit = async (root, args, { disableFilters = false, allowNoMatches = false, timeoutMs = 0 } = {}) => {
|
|
110
|
+
root = await assertWorkspace(root);
|
|
111
|
+
const executor = subprocess();
|
|
112
|
+
if (!executor?.spawn) throw gitError("git-provider-unavailable", 503);
|
|
113
|
+
const noHooksPath = process.platform === "win32" ? "NUL" : "/dev/null";
|
|
114
|
+
let filterOverrides = [];
|
|
115
|
+
if (disableFilters) {
|
|
116
|
+
const names = await run(root, ["config", "--null", "--name-only", "--get-regexp", "^filter\\..*\\.(clean|process)$"], false, true);
|
|
117
|
+
filterOverrides = names.split("\0").filter(Boolean).flatMap((name) => ["-c", `${name}=`]);
|
|
118
|
+
}
|
|
119
|
+
// A soft deadline aborts the command and returns the output collected so far,
|
|
120
|
+
// so file history can degrade to a partial, explicitly truncated page instead
|
|
121
|
+
// of failing the request. Hardening below is shared with the batch helper.
|
|
122
|
+
const controller = timeoutMs > 0 ? new AbortController() : null;
|
|
123
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
124
|
+
try {
|
|
125
|
+
const child = executor.spawn({
|
|
126
|
+
argv: [
|
|
127
|
+
process.platform === "win32" ? "git.exe" : "git",
|
|
128
|
+
"-c", "core.fsmonitor=false",
|
|
129
|
+
"-c", `core.hooksPath=${noHooksPath}`,
|
|
130
|
+
...filterOverrides,
|
|
131
|
+
"-C", root,
|
|
132
|
+
"--no-optional-locks",
|
|
133
|
+
...args,
|
|
134
|
+
],
|
|
135
|
+
cwd: root,
|
|
136
|
+
// Prevent ambient Git repository/config overrides from redirecting a
|
|
137
|
+
// session-authorized read. Undefined values are seam tombstones.
|
|
138
|
+
env: {
|
|
139
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
140
|
+
GCM_INTERACTIVE: "never",
|
|
141
|
+
GIT_DIR: undefined,
|
|
142
|
+
GIT_WORK_TREE: undefined,
|
|
143
|
+
GIT_INDEX_FILE: undefined,
|
|
144
|
+
GIT_COMMON_DIR: undefined,
|
|
145
|
+
GIT_OBJECT_DIRECTORY: undefined,
|
|
146
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: undefined,
|
|
147
|
+
GIT_CONFIG: undefined,
|
|
148
|
+
GIT_CONFIG_PARAMETERS: undefined,
|
|
149
|
+
GIT_CONFIG_COUNT: "0",
|
|
150
|
+
// Trace destinations open files even for otherwise read-only Git commands.
|
|
151
|
+
...Object.fromEntries(Object.keys(process.env).filter((key) => /^GIT_TRACE(?:2)?(?:_|$)/.test(key)).map((key) => [key, undefined])),
|
|
152
|
+
GIT_TRACE: undefined,
|
|
153
|
+
GIT_TRACE2: undefined,
|
|
154
|
+
GIT_TRACE2_EVENT: undefined,
|
|
155
|
+
GIT_TRACE2_PERF: undefined,
|
|
156
|
+
},
|
|
157
|
+
stdio: { stdin: "ignore", stdout: { maxBytes: 8 * 1024 * 1024 }, stderr: { maxBytes: 1024 * 1024 } },
|
|
158
|
+
graceMs: 10_000,
|
|
159
|
+
...(controller ? { signal: controller.signal } : {}),
|
|
160
|
+
});
|
|
161
|
+
let done;
|
|
162
|
+
try { done = await child.done; } catch (error) {
|
|
163
|
+
if (!controller?.signal.aborted) throw error;
|
|
164
|
+
done = { exitCode: null };
|
|
165
|
+
}
|
|
166
|
+
const stdoutResult = await child.collected?.stdout?.readFrom?.(0);
|
|
167
|
+
const stderrResult = await child.collected?.stderr?.readFrom?.(0);
|
|
168
|
+
if (stdoutResult?.lossy || stderrResult?.lossy) {
|
|
169
|
+
throw gitError("git-output-too-large", 413);
|
|
170
|
+
}
|
|
171
|
+
const stdout = stdoutResult?.text ?? "";
|
|
172
|
+
const stderr = stderrResult?.text ?? "";
|
|
173
|
+
if (controller?.signal.aborted) return { stdout, stderr, timedOut: true };
|
|
174
|
+
if (done?.exitCode !== 0) {
|
|
175
|
+
if (allowNoMatches && done?.exitCode === 1) return { stdout: "", stderr, timedOut: false };
|
|
176
|
+
if (/not a git repository/i.test(stderr)) throw gitError("not-git-repository", 404);
|
|
177
|
+
throw gitError("git-command-failed", 400);
|
|
178
|
+
}
|
|
179
|
+
return { stdout, stderr, timedOut: false };
|
|
180
|
+
} finally {
|
|
181
|
+
if (timer) clearTimeout(timer);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const run = async (root, args, disableFilters = false, allowNoMatches = false) =>
|
|
185
|
+
(await spawnGit(root, args, { disableFilters, allowNoMatches })).stdout;
|
|
186
|
+
const repositoryRoot = async (cwd) => {
|
|
187
|
+
const allowed = await assertWorkspace(cwd);
|
|
188
|
+
const root = (await run(allowed, ["rev-parse", "--show-toplevel"])).trim();
|
|
189
|
+
return assertWorkspace(root);
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
contractVersion: "1.1.0",
|
|
193
|
+
capabilities() {
|
|
194
|
+
const available = Boolean(subprocess()?.spawn) && workspaces().length > 0;
|
|
195
|
+
return { available, reason: available ? null : !subprocess()?.spawn ? "git-provider-unavailable" : "workspace-registry-unavailable" };
|
|
196
|
+
},
|
|
197
|
+
repositoryRoot,
|
|
198
|
+
async refSignature(root) {
|
|
199
|
+
let refs = "";
|
|
200
|
+
try { refs = await run(root, ["show-ref", "--head", "--dereference"]); } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
201
|
+
return createHash("sha256").update(refs).digest("hex");
|
|
202
|
+
},
|
|
203
|
+
async repositoryInfo(root) {
|
|
204
|
+
let currentBranch = null, headOid = null;
|
|
205
|
+
try { currentBranch = (await run(root, ["symbolic-ref", "--quiet", "HEAD"])).trim() || null; } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
206
|
+
try { headOid = (await run(root, ["rev-parse", "--verify", "HEAD"])).trim() || null; } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
207
|
+
return { ...(headOid ? { headOid } : {}), ...(currentBranch ? { currentBranch } : {}), detached: Boolean(headOid && !currentBranch), empty: !headOid };
|
|
208
|
+
},
|
|
209
|
+
async resolveTip(root, ref) {
|
|
210
|
+
return (await run(root, ["rev-parse", "--verify", `${ref}^{commit}`])).trim();
|
|
211
|
+
},
|
|
212
|
+
async graph(root, { refs, offset, limit, timeoutMs = 0 }) {
|
|
213
|
+
if (refs.length === 0) return [];
|
|
214
|
+
const graphResult = await spawnGit(root, ["log", "--topo-order", "--date-order", `--skip=${offset}`, `--max-count=${limit}`, "--decorate=full", "--format=%H%x1f%P%x1f%an%x1f%at%x1f%s%x1f%D%x00", ...refs], { timeoutMs });
|
|
215
|
+
if (graphResult.timedOut) throw gitError("graph-timeout", 504);
|
|
216
|
+
const text = graphResult.stdout;
|
|
217
|
+
return text.split("\0").map((record) => record.replace(/^[\r\n]+|[\r\n]+$/g, "")).filter(Boolean).map((record) => {
|
|
218
|
+
const [oid, parents, author, timestamp, subject, decorations] = record.split("\x1f");
|
|
219
|
+
return { oid, parents: parents ? parents.split(" ") : [], author, timestamp: Number(timestamp) || 0, subject, refs: decorations ? decorations.split(",").map((value) => value.trim()).filter(Boolean) : [] };
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
async commit(root, oid) {
|
|
223
|
+
if (typeof oid !== "string" || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(oid)) throw gitError("invalid-oid", 400);
|
|
224
|
+
const metadata = (await run(root, ["show", "-s", "--decorate=full", "--format=%H%x1f%P%x1f%an%x1f%at%x1f%D%x1f%B%x00", oid])).split("\0")[0].split("\x1f");
|
|
225
|
+
const [hash, parentText, author, timestamp, decorations, ...messageParts] = metadata;
|
|
226
|
+
const diffBase = parentText ? [parentText.split(" ")[0], hash] : ["--root", hash];
|
|
227
|
+
const statusParts = (await run(root, ["diff-tree", "--no-commit-id", "-r", "-M", "--name-status", "-z", ...diffBase])).split("\0");
|
|
228
|
+
const files = [];
|
|
229
|
+
for (let index = 0; index < statusParts.length;) {
|
|
230
|
+
const code = statusParts[index++];
|
|
231
|
+
if (!code) continue;
|
|
232
|
+
const renamed = code.startsWith("R") || code.startsWith("C");
|
|
233
|
+
const oldPath = renamed ? statusParts[index++] : undefined;
|
|
234
|
+
const path = statusParts[index++];
|
|
235
|
+
if (!path) break;
|
|
236
|
+
const statuses = { A: "added", M: "modified", D: "deleted", R: "renamed", C: "copied", T: "type-changed" };
|
|
237
|
+
files.push({ path, ...(oldPath ? { oldPath } : {}), status: statuses[code[0]] ?? "modified" });
|
|
238
|
+
}
|
|
239
|
+
const statParts = (await run(root, ["diff-tree", "--no-commit-id", "-r", "-M", "--numstat", "-z", ...diffBase])).split("\0");
|
|
240
|
+
const stats = new Map();
|
|
241
|
+
for (let index = 0; index < statParts.length;) {
|
|
242
|
+
const record = statParts[index++];
|
|
243
|
+
if (!record) continue;
|
|
244
|
+
const firstTab = record.indexOf("\t");
|
|
245
|
+
const secondTab = record.indexOf("\t", firstTab + 1);
|
|
246
|
+
if (firstTab < 0 || secondTab < 0) continue;
|
|
247
|
+
const added = record.slice(0, firstTab);
|
|
248
|
+
const deleted = record.slice(firstTab + 1, secondTab);
|
|
249
|
+
let path = record.slice(secondTab + 1);
|
|
250
|
+
if (!path) { index++; path = statParts[index++] ?? ""; }
|
|
251
|
+
stats.set(path, { binary: added === "-" || deleted === "-", additions: added === "-" ? null : Number(added), deletions: deleted === "-" ? null : Number(deleted) });
|
|
252
|
+
}
|
|
253
|
+
for (const file of files) Object.assign(file, stats.get(file.path) ?? { binary: false, additions: 0, deletions: 0 });
|
|
254
|
+
return {
|
|
255
|
+
oid: hash, parents: parentText ? parentText.split(" ") : [], author, timestamp: Number(timestamp) || 0,
|
|
256
|
+
message: messageParts.join("\x1f").trim(),
|
|
257
|
+
refs: decorations ? decorations.split(",").map((value) => value.trim()).filter(Boolean) : [],
|
|
258
|
+
files,
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
/**
|
|
262
|
+
* All branch, remote, tag and HEAD refs with name-level facts plus
|
|
263
|
+
* annotated-tag metadata. Non-commit and nested tag targets carry a hint
|
|
264
|
+
* instead of failing the whole read.
|
|
265
|
+
*/
|
|
266
|
+
async refs(root, { timeoutMs = 0 } = {}) {
|
|
267
|
+
const records = [];
|
|
268
|
+
// NUL/US-delimited fields keep tagger names and tag subjects that contain
|
|
269
|
+
// tabs intact; a tab-delimited line format would corrupt such records.
|
|
270
|
+
const refsResult = await spawnGit(root, ["for-each-ref", "--format=%(refname)%1f%(objectname)%1f%(objecttype)%1f%(HEAD)%1f%(taggername)%1f%(taggerdate:unix)%1f%(subject)%1f%(*objectname)%1f%(*objecttype)%1f%(type)%00", "refs/heads", "refs/remotes", "refs/tags"], { timeoutMs });
|
|
271
|
+
if (refsResult.timedOut) throw gitError("graph-timeout", 504);
|
|
272
|
+
const text = refsResult.stdout;
|
|
273
|
+
for (const raw of text.split("\0")) {
|
|
274
|
+
const record = raw.replace(/^[\r\n]+|[\r\n]+$/g, "");
|
|
275
|
+
if (!record) continue;
|
|
276
|
+
const fields = record.split("\x1f");
|
|
277
|
+
if (fields.length < 10) continue;
|
|
278
|
+
// Peeled fields are fixed at the tail so a subject containing the
|
|
279
|
+
// unit separator cannot swallow them.
|
|
280
|
+
const [name, oid, objectType, headFlag, taggerName, taggerDate] = fields;
|
|
281
|
+
const targetType = fields.at(-1); // %(type) is the direct tag target, including on Git 2.52+.
|
|
282
|
+
const peeledType = fields.at(-2);
|
|
283
|
+
const peeledOid = fields.at(-3);
|
|
284
|
+
const subject = fields.slice(6, -3).join("\x1f");
|
|
285
|
+
if (!name || !oid) continue;
|
|
286
|
+
if (name.startsWith("refs/remotes/") && name.endsWith("/HEAD")) continue;
|
|
287
|
+
if (name.startsWith("refs/heads/") || name.startsWith("refs/remotes/")) {
|
|
288
|
+
const commit = objectType === "commit";
|
|
289
|
+
records.push({
|
|
290
|
+
name, shortName: refShortName(name),
|
|
291
|
+
kind: name.startsWith("refs/heads/") ? "localBranch" : "remoteBranch",
|
|
292
|
+
oid, commitOid: commit ? oid : null, current: headFlag === "*", annotated: false,
|
|
293
|
+
...(commit ? {} : { hint: "non-commit-target" }),
|
|
294
|
+
});
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (!name.startsWith("refs/tags/")) continue;
|
|
298
|
+
if (objectType !== "tag") {
|
|
299
|
+
// Lightweight tag: the ref itself points at the target object.
|
|
300
|
+
const commit = objectType === "commit";
|
|
301
|
+
records.push({
|
|
302
|
+
name, shortName: refShortName(name), kind: "tag",
|
|
303
|
+
oid, commitOid: commit ? oid : null, current: false, annotated: false,
|
|
304
|
+
...(commit ? {} : { hint: "non-commit-target" }),
|
|
305
|
+
});
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
let commitOid = null, hint;
|
|
309
|
+
if (targetType === "tag" && peeledType === "commit") {
|
|
310
|
+
commitOid = peeledOid;
|
|
311
|
+
hint = "nested-tag";
|
|
312
|
+
} else if (peeledType === "commit") commitOid = peeledOid;
|
|
313
|
+
else if (peeledType === "tag") {
|
|
314
|
+
// Nested tag: peel recursively; when the chain ends outside a
|
|
315
|
+
// commit we still keep the name and advertise the hint.
|
|
316
|
+
try { commitOid = (await run(root, ["rev-parse", "--verify", `${name}^{commit}`])).trim() || null; } catch { commitOid = null; }
|
|
317
|
+
hint = commitOid ? "nested-tag" : "non-commit-target";
|
|
318
|
+
} else hint = "non-commit-target";
|
|
319
|
+
const date = Number(taggerDate);
|
|
320
|
+
records.push({
|
|
321
|
+
name, shortName: refShortName(name), kind: "tag", oid, commitOid, current: false, annotated: true,
|
|
322
|
+
...(taggerName ? { tagger: taggerName } : {}),
|
|
323
|
+
...(Number.isFinite(date) && date > 0 ? { date } : {}),
|
|
324
|
+
...(subject ? { subject } : {}),
|
|
325
|
+
...(hint ? { hint } : {}),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
let headOid = null;
|
|
329
|
+
try { headOid = (await run(root, ["rev-parse", "--verify", "HEAD"])).trim() || null; } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
330
|
+
if (headOid) records.unshift({ name: "HEAD", shortName: "HEAD", kind: "head", oid: headOid, commitOid: headOid, current: true, annotated: false });
|
|
331
|
+
return records;
|
|
332
|
+
},
|
|
333
|
+
/** Tracked files at HEAD, bounded and filtered by a case-insensitive path substring. */
|
|
334
|
+
async files(root, { q = "", limit = 200 } = {}) {
|
|
335
|
+
const pageSize = Math.max(1, Math.min(200, Number(limit) || 200));
|
|
336
|
+
// The recursive HEAD path list is bounded by the subprocess stdout cap
|
|
337
|
+
// (8 MiB, see spawnGit). Repositories above that cap fail closed with
|
|
338
|
+
// `git-output-too-large` (413) instead of returning a partial list; the
|
|
339
|
+
// bound is documented in docs/03-api.md §6.19.7.
|
|
340
|
+
let text;
|
|
341
|
+
try { text = await run(root, ["ls-tree", "-r", "-z", "--name-only", "HEAD"]); } catch (error) {
|
|
342
|
+
if (error?.code !== "git-command-failed") throw error;
|
|
343
|
+
// An unborn HEAD is an empty repository, not a failure: /git/files
|
|
344
|
+
// must answer 200 with an empty list for it.
|
|
345
|
+
try { await run(root, ["rev-parse", "--verify", "HEAD"]); } catch (inner) {
|
|
346
|
+
if (inner?.code === "git-command-failed") return { files: [], truncated: false };
|
|
347
|
+
throw inner;
|
|
348
|
+
}
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
const query = typeof q === "string" ? q.toLowerCase() : "";
|
|
352
|
+
let paths = text.split("\0").filter((path) => path !== "");
|
|
353
|
+
if (query) paths = paths.filter((path) => path.toLowerCase().includes(query));
|
|
354
|
+
paths.sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
355
|
+
const truncated = paths.length > pageSize;
|
|
356
|
+
return { files: paths.slice(0, pageSize), truncated };
|
|
357
|
+
},
|
|
358
|
+
/**
|
|
359
|
+
* Commits touching one file, newest first, with the change status that
|
|
360
|
+
* commit applied to the path. Bounded by `maxCommits` or the soft
|
|
361
|
+
* deadline; both report an explicitly truncated (partial) list.
|
|
362
|
+
*/
|
|
363
|
+
async fileHistory(root, path, { maxCommits = 5000, timeoutMs = 20000 } = {}) {
|
|
364
|
+
if (typeof path !== "string" || path === "" || path.includes("\0")) throw gitError("git-command-failed", 400);
|
|
365
|
+
const deadline = Date.now() + timeoutMs;
|
|
366
|
+
const historyRun = (args) => spawnGit(root, args, { timeoutMs: Math.max(1, deadline - Date.now()) });
|
|
367
|
+
try {
|
|
368
|
+
const check = await historyRun(["rev-parse", "--verify", "HEAD"]);
|
|
369
|
+
if (check.timedOut) return { entries: [], truncated: true };
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (error?.code === "git-command-failed") return { entries: [], truncated: false, reason: "no-history" };
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
let tracked = false;
|
|
375
|
+
try {
|
|
376
|
+
const tree = await historyRun(["ls-tree", "-z", "HEAD", "--", `:(literal)${path}`]);
|
|
377
|
+
if (tree.timedOut) return { entries: [], truncated: true };
|
|
378
|
+
for (const record of tree.stdout.split("\0")) {
|
|
379
|
+
const separator = record.indexOf("\t");
|
|
380
|
+
if (separator < 0) continue;
|
|
381
|
+
const entryPath = record.slice(separator + 1);
|
|
382
|
+
const entryType = record.slice(0, separator).split(" ")[1];
|
|
383
|
+
// Directories, gitlinks and other tree entries are not file paths;
|
|
384
|
+
// only blobs (regular files and symlinks) have a file history.
|
|
385
|
+
if (entryPath === path && entryType === "blob") tracked = true;
|
|
386
|
+
}
|
|
387
|
+
} catch (error) {
|
|
388
|
+
if (error?.code !== "git-command-failed") throw error;
|
|
389
|
+
}
|
|
390
|
+
if (!tracked) return { entries: [], truncated: false, reason: "not-tracked" };
|
|
391
|
+
const cap = Math.max(1, Math.min(5000, Number(maxCommits) || 5000));
|
|
392
|
+
const result = await historyRun(["--literal-pathspecs", "log", `--max-count=${cap + 1}`, "--format=%x00%H%x1f%h%x1f%an%x1f%at%x1f%s", "--name-status", "-M", "-z", "--", path]);
|
|
393
|
+
let entries = parseFileHistory(result.stdout);
|
|
394
|
+
let truncated = result.timedOut === true;
|
|
395
|
+
if (entries.length > cap) {
|
|
396
|
+
entries = entries.slice(0, cap);
|
|
397
|
+
truncated = true;
|
|
398
|
+
}
|
|
399
|
+
return { entries, truncated };
|
|
400
|
+
},
|
|
401
|
+
async worktree(root) {
|
|
402
|
+
const text = await run(root, ["status", "--porcelain=v1", "-z", "--untracked-files=all"], true);
|
|
403
|
+
const parts = text.split("\0"); const entries = [];
|
|
404
|
+
for (let i = 0; i < parts.length;) {
|
|
405
|
+
const record = parts[i++]; if (!record) continue;
|
|
406
|
+
const code = record.slice(0, 2); let path = record.slice(3); let oldPath;
|
|
407
|
+
if (/[RC]/.test(code)) { oldPath = parts[i++] ?? ""; }
|
|
408
|
+
const status = code.includes("U") || code === "AA" || code === "DD" ? "conflicted" : code === "??" ? "untracked" : "modified";
|
|
409
|
+
entries.push({ path, ...(oldPath ? { oldPath } : {}), status, conflicted: status === "conflicted", index: code[0] !== " " && code !== "??", worktree: code[1] !== " " && code !== "??" });
|
|
410
|
+
}
|
|
411
|
+
let signatureMaterial = text;
|
|
412
|
+
for (const entry of entries) {
|
|
413
|
+
if (entry.status !== "untracked" && !entry.worktree) continue;
|
|
414
|
+
try { const target = resolve(root, entry.path); const info = await lstat(target); signatureMaterial += `\\0${entry.path}:${info.isSymbolicLink() ? "symlink" : info.isFile() ? await sampledFileSignature(target, info) : "special"}`; } catch { signatureMaterial += `\\0${entry.path}:missing`; }
|
|
415
|
+
}
|
|
416
|
+
try { signatureMaterial += await run(root, ["--literal-pathspecs", "diff", "--raw", "-z", "--no-abbrev", "HEAD"], true); } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
417
|
+
try { signatureMaterial += await run(root, ["--literal-pathspecs", "diff", "--raw", "-z", "--no-abbrev", "--cached"], true); } catch (error) { if (error?.code !== "git-command-failed") throw error; }
|
|
418
|
+
const signature = createHash("sha256").update(signatureMaterial).digest("hex");
|
|
419
|
+
return { entries, signature };
|
|
420
|
+
},
|
|
421
|
+
async worktreePreview(root, kind, path) {
|
|
422
|
+
const args = ["--literal-pathspecs", "diff", "--unified=999999", "--no-ext-diff", "--no-textconv", "--no-color", "--binary"];
|
|
423
|
+
if (kind === "staged") args.push("--cached");
|
|
424
|
+
args.push("--", path);
|
|
425
|
+
if (kind === "untracked") {
|
|
426
|
+
try {
|
|
427
|
+
const target = resolve(root, path); const info = await lstat(target);
|
|
428
|
+
if (info.isSymbolicLink()) return { diff: "", binary: false, additions: null, deletions: null, notice: "symlink preview omitted" };
|
|
429
|
+
if (!info.isFile()) return { diff: "", binary: false, additions: null, deletions: null, notice: "special file preview omitted" };
|
|
430
|
+
const { bytes, truncated } = await readPrefix(target, UNTRACKED_PREVIEW_MAX, info);
|
|
431
|
+
const binary = bytes.includes(0);
|
|
432
|
+
return { diff: binary ? "" : bytes.toString("utf8"), binary, truncated, additions: null, deletions: null, ...(binary ? { notice: "binary preview omitted" } : {}) };
|
|
433
|
+
} catch { return { diff: "", binary: false, additions: 0, deletions: 0, notice: "unavailable" }; }
|
|
434
|
+
}
|
|
435
|
+
return { diff: await run(root, args, true), binary: false, additions: null, deletions: null };
|
|
436
|
+
},
|
|
437
|
+
async commitPreview(root, oid, path) {
|
|
438
|
+
const commit = await this.commit(root, oid);
|
|
439
|
+
if (!commit.parents.length) return { diff: await run(root, ["--literal-pathspecs", "diff-tree", "--root", "--no-commit-id", "-p", "-r", "--unified=999999", "--no-ext-diff", "--no-textconv", "--no-color", "--binary", oid, "--", path]), binary: false };
|
|
440
|
+
return { diff: await run(root, ["--literal-pathspecs", "diff", "--unified=999999", "--no-ext-diff", "--no-textconv", "--no-color", "--binary", `${oid}^1`, oid, "--", path]), binary: false };
|
|
441
|
+
},
|
|
442
|
+
async branches(root) {
|
|
443
|
+
const text = await run(root, ["for-each-ref", "--format=%(HEAD)%09%(refname)%09%(objectname)%09%(upstream:short)%00", "refs/heads", "refs/remotes"]);
|
|
444
|
+
const rows = text.split("\0").map((record) => record.replace(/^[\r\n]+|[\r\n]+$/g, "")).filter(Boolean);
|
|
445
|
+
const branches = [];
|
|
446
|
+
for (const row of rows) {
|
|
447
|
+
const [head, ref, oid, upstream = ""] = row.split("\t");
|
|
448
|
+
if (ref.endsWith("/HEAD")) continue;
|
|
449
|
+
const local = ref.startsWith("refs/heads/");
|
|
450
|
+
let ahead = 0, behind = 0;
|
|
451
|
+
// issue #161:upstream 指向已删除的 remote ref 时,for-each-ref 仍会
|
|
452
|
+
// 返回 upstream:short,但 rev-list 会失败。必须按分支 fail-soft:
|
|
453
|
+
// 该行 tracking=null、ahead/behind=0,**不能让整个 branches() 抛错**。
|
|
454
|
+
let tracking = null;
|
|
455
|
+
if (local && upstream) {
|
|
456
|
+
try {
|
|
457
|
+
const counts = (await run(root, ["rev-list", "--left-right", "--count", `${ref}...${upstream}`]))
|
|
458
|
+
.trim().split(/\s+/).map(Number);
|
|
459
|
+
if (counts.length !== 2 || counts.some((value) => !Number.isSafeInteger(value) || value < 0)) {
|
|
460
|
+
throw new Error("invalid rev-list counts");
|
|
461
|
+
}
|
|
462
|
+
[ahead, behind] = counts;
|
|
463
|
+
tracking = `refs/remotes/${upstream}`;
|
|
464
|
+
} catch {
|
|
465
|
+
// upstream 缺失/非法/命令失败:保留分支,追踪信息降级为未知。
|
|
466
|
+
ahead = 0;
|
|
467
|
+
behind = 0;
|
|
468
|
+
tracking = null;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
branches.push({
|
|
472
|
+
name: ref, displayName: ref.replace(/^refs\/(?:heads|remotes)\//, ""), oid,
|
|
473
|
+
kind: local ? "local" : "remote", current: local && head === "*",
|
|
474
|
+
tracking, ahead, behind,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return branches;
|
|
478
|
+
},
|
|
479
|
+
};
|
|
480
|
+
}
|