@marktrue/dsh-mobile-remote 3.2.4-alpha.14 → 3.2.4-alpha.15-app

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/DSH-Remote-v3.2.4.apk +4 -0
  2. package/README.md +6 -256
  3. package/manifest.json +21 -0
  4. package/package.json +12 -68
  5. package/CHANGELOG.md +0 -1720
  6. package/CONTRIBUTING.md +0 -59
  7. package/FAQ.md +0 -111
  8. package/cordis.patch.yml +0 -14
  9. package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +0 -125
  10. package/docs/01-PRD.md +0 -148
  11. package/docs/02-architecture.md +0 -249
  12. package/docs/03-api.md +0 -1421
  13. package/docs/04-security.md +0 -108
  14. package/docs/05-test-cases.md +0 -405
  15. package/docs/06-install-run.md +0 -372
  16. package/docs/07-user-manual.md +0 -70
  17. package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +0 -86
  18. package/docs/09-compatibility.md +0 -238
  19. package/docs/10-release.md +0 -1040
  20. package/docs/11-notification-reliability.md +0 -45
  21. package/docs/12-implementation-status.md +0 -41
  22. package/docs/13-device-acceptance-2026-11-03.md +0 -37
  23. package/docs/16-next-window-handoff-2026-11-04.md +0 -44
  24. package/docs/17-remaining-work-review-2026-11-04.md +0 -53
  25. package/docs/18-device-reliability-acceptance-2026-11-04.md +0 -63
  26. package/docs/19-issue-followup-2026-11-04.md +0 -39
  27. package/docs/20-dsh-022-compatibility-2026-11-05.md +0 -32
  28. package/docs/screenshots/01-home.png +0 -0
  29. package/docs/screenshots/02-notifications.png +0 -0
  30. package/docs/screenshots/03-sessions.png +0 -0
  31. package/docs/screenshots/04-chat.png +0 -0
  32. package/docs/screenshots/05-settings.png +0 -0
  33. package/docs/screenshots/06-new-session.png +0 -0
  34. package/docs/screenshots/pgy-appstore.jpg +0 -0
  35. package/docs/screenshots/pgy-mobile-app.jpg +0 -0
  36. package/docs/screenshots/pgy-pc-client.jpg +0 -0
  37. package/lib/account-usage.js +0 -145
  38. package/lib/app-alignment.js +0 -112
  39. package/lib/app-carrier-store.js +0 -1972
  40. package/lib/app-carrier.js +0 -609
  41. package/lib/client.js +0 -1196
  42. package/lib/desktop-form.js +0 -738
  43. package/lib/endpoint-registry.js +0 -184
  44. package/lib/git-read-bundled-provider.js +0 -464
  45. package/lib/git-read-service.js +0 -766
  46. package/lib/host-manager-update.js +0 -178
  47. package/lib/host-update-capabilities.js +0 -203
  48. package/lib/index.js +0 -11564
  49. package/lib/npm-update-source.js +0 -226
  50. package/lib/plugin-content-digest.js +0 -80
  51. package/lib/plugin-self-update.js +0 -1098
  52. package/lib/plugin-update-controller.js +0 -340
  53. package/lib/plugin-update-log.js +0 -164
  54. package/lib/plugin-update-transaction.js +0 -322
  55. package/lib/plugin-update.js +0 -309
  56. package/lib/runtime-dependency-snapshot.js +0 -345
  57. package/lib/session-title-cache.js +0 -123
  58. package/lib/session-title-refresh.js +0 -261
  59. package/lib/tool-process.js +0 -20
  60. package/lib/update-fetch.js +0 -24
  61. package/lib/update-lock-arbiter.js +0 -170
  62. package/lib/update-supervisor.js +0 -346
  63. package/node_modules/ansi-regex/index.d.ts +0 -37
  64. package/node_modules/ansi-regex/index.js +0 -10
  65. package/node_modules/ansi-regex/license +0 -9
  66. package/node_modules/ansi-regex/package.json +0 -55
  67. package/node_modules/ansi-regex/readme.md +0 -78
  68. package/node_modules/ansi-styles/index.d.ts +0 -345
  69. package/node_modules/ansi-styles/index.js +0 -163
  70. package/node_modules/ansi-styles/license +0 -9
  71. package/node_modules/ansi-styles/package.json +0 -56
  72. package/node_modules/ansi-styles/readme.md +0 -152
  73. package/node_modules/camelcase/index.d.ts +0 -63
  74. package/node_modules/camelcase/index.js +0 -76
  75. package/node_modules/camelcase/license +0 -9
  76. package/node_modules/camelcase/package.json +0 -43
  77. package/node_modules/camelcase/readme.md +0 -99
  78. package/node_modules/cliui/CHANGELOG.md +0 -76
  79. package/node_modules/cliui/LICENSE.txt +0 -14
  80. package/node_modules/cliui/README.md +0 -115
  81. package/node_modules/cliui/index.js +0 -354
  82. package/node_modules/cliui/package.json +0 -65
  83. package/node_modules/color-convert/CHANGELOG.md +0 -54
  84. package/node_modules/color-convert/LICENSE +0 -21
  85. package/node_modules/color-convert/README.md +0 -68
  86. package/node_modules/color-convert/conversions.js +0 -839
  87. package/node_modules/color-convert/index.js +0 -81
  88. package/node_modules/color-convert/package.json +0 -48
  89. package/node_modules/color-convert/route.js +0 -97
  90. package/node_modules/color-name/LICENSE +0 -8
  91. package/node_modules/color-name/README.md +0 -11
  92. package/node_modules/color-name/index.js +0 -152
  93. package/node_modules/color-name/package.json +0 -28
  94. package/node_modules/decamelize/index.js +0 -13
  95. package/node_modules/decamelize/license +0 -21
  96. package/node_modules/decamelize/package.json +0 -38
  97. package/node_modules/decamelize/readme.md +0 -48
  98. package/node_modules/dijkstrajs/.travis.yml +0 -4
  99. package/node_modules/dijkstrajs/CONTRIBUTING.md +0 -8
  100. package/node_modules/dijkstrajs/LICENSE.md +0 -19
  101. package/node_modules/dijkstrajs/README.md +0 -18
  102. package/node_modules/dijkstrajs/dijkstra.js +0 -165
  103. package/node_modules/dijkstrajs/package.json +0 -60
  104. package/node_modules/dijkstrajs/test/dijkstra.test.js +0 -96
  105. package/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
  106. package/node_modules/emoji-regex/README.md +0 -73
  107. package/node_modules/emoji-regex/es2015/index.js +0 -6
  108. package/node_modules/emoji-regex/es2015/text.js +0 -6
  109. package/node_modules/emoji-regex/index.d.ts +0 -23
  110. package/node_modules/emoji-regex/index.js +0 -6
  111. package/node_modules/emoji-regex/package.json +0 -50
  112. package/node_modules/emoji-regex/text.js +0 -6
  113. package/node_modules/find-up/index.d.ts +0 -137
  114. package/node_modules/find-up/index.js +0 -89
  115. package/node_modules/find-up/license +0 -9
  116. package/node_modules/find-up/package.json +0 -53
  117. package/node_modules/find-up/readme.md +0 -156
  118. package/node_modules/get-caller-file/LICENSE.md +0 -6
  119. package/node_modules/get-caller-file/README.md +0 -41
  120. package/node_modules/get-caller-file/index.d.ts +0 -2
  121. package/node_modules/get-caller-file/index.js +0 -22
  122. package/node_modules/get-caller-file/index.js.map +0 -1
  123. package/node_modules/get-caller-file/package.json +0 -42
  124. package/node_modules/is-fullwidth-code-point/index.d.ts +0 -17
  125. package/node_modules/is-fullwidth-code-point/index.js +0 -50
  126. package/node_modules/is-fullwidth-code-point/license +0 -9
  127. package/node_modules/is-fullwidth-code-point/package.json +0 -42
  128. package/node_modules/is-fullwidth-code-point/readme.md +0 -39
  129. package/node_modules/locate-path/index.d.ts +0 -83
  130. package/node_modules/locate-path/index.js +0 -65
  131. package/node_modules/locate-path/license +0 -9
  132. package/node_modules/locate-path/package.json +0 -45
  133. package/node_modules/locate-path/readme.md +0 -122
  134. package/node_modules/p-limit/index.d.ts +0 -38
  135. package/node_modules/p-limit/index.js +0 -57
  136. package/node_modules/p-limit/license +0 -9
  137. package/node_modules/p-limit/package.json +0 -52
  138. package/node_modules/p-limit/readme.md +0 -101
  139. package/node_modules/p-locate/index.d.ts +0 -64
  140. package/node_modules/p-locate/index.js +0 -52
  141. package/node_modules/p-locate/license +0 -9
  142. package/node_modules/p-locate/package.json +0 -53
  143. package/node_modules/p-locate/readme.md +0 -90
  144. package/node_modules/p-try/index.d.ts +0 -39
  145. package/node_modules/p-try/index.js +0 -9
  146. package/node_modules/p-try/license +0 -9
  147. package/node_modules/p-try/package.json +0 -42
  148. package/node_modules/p-try/readme.md +0 -58
  149. package/node_modules/path-exists/index.d.ts +0 -28
  150. package/node_modules/path-exists/index.js +0 -23
  151. package/node_modules/path-exists/license +0 -9
  152. package/node_modules/path-exists/package.json +0 -39
  153. package/node_modules/path-exists/readme.md +0 -52
  154. package/node_modules/pngjs/.eslintignore +0 -2
  155. package/node_modules/pngjs/.eslintrc.json +0 -19
  156. package/node_modules/pngjs/.prettierignore +0 -3
  157. package/node_modules/pngjs/LICENSE +0 -20
  158. package/node_modules/pngjs/README.md +0 -429
  159. package/node_modules/pngjs/browser.js +0 -16096
  160. package/node_modules/pngjs/coverage/lcov-report/base.css +0 -354
  161. package/node_modules/pngjs/coverage/lcov-report/bitmapper.js.html +0 -881
  162. package/node_modules/pngjs/coverage/lcov-report/bitpacker.js.html +0 -554
  163. package/node_modules/pngjs/coverage/lcov-report/block-navigation.js +0 -77
  164. package/node_modules/pngjs/coverage/lcov-report/chunkstream.js.html +0 -647
  165. package/node_modules/pngjs/coverage/lcov-report/constants.js.html +0 -176
  166. package/node_modules/pngjs/coverage/lcov-report/crc.js.html +0 -200
  167. package/node_modules/pngjs/coverage/lcov-report/favicon.png +0 -0
  168. package/node_modules/pngjs/coverage/lcov-report/filter-pack.js.html +0 -593
  169. package/node_modules/pngjs/coverage/lcov-report/filter-parse-async.js.html +0 -152
  170. package/node_modules/pngjs/coverage/lcov-report/filter-parse-sync.js.html +0 -143
  171. package/node_modules/pngjs/coverage/lcov-report/filter-parse.js.html +0 -611
  172. package/node_modules/pngjs/coverage/lcov-report/format-normaliser.js.html +0 -359
  173. package/node_modules/pngjs/coverage/lcov-report/index.html +0 -426
  174. package/node_modules/pngjs/coverage/lcov-report/interlace.js.html +0 -365
  175. package/node_modules/pngjs/coverage/lcov-report/packer-async.js.html +0 -230
  176. package/node_modules/pngjs/coverage/lcov-report/packer-sync.js.html +0 -248
  177. package/node_modules/pngjs/coverage/lcov-report/packer.js.html +0 -467
  178. package/node_modules/pngjs/coverage/lcov-report/paeth-predictor.js.html +0 -128
  179. package/node_modules/pngjs/coverage/lcov-report/parser-async.js.html +0 -575
  180. package/node_modules/pngjs/coverage/lcov-report/parser-sync.js.html +0 -404
  181. package/node_modules/pngjs/coverage/lcov-report/parser.js.html +0 -950
  182. package/node_modules/pngjs/coverage/lcov-report/png-sync.js.html +0 -116
  183. package/node_modules/pngjs/coverage/lcov-report/png.js.html +0 -662
  184. package/node_modules/pngjs/coverage/lcov-report/prettify.css +0 -101
  185. package/node_modules/pngjs/coverage/lcov-report/prettify.js +0 -1007
  186. package/node_modules/pngjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  187. package/node_modules/pngjs/coverage/lcov-report/sorter.js +0 -169
  188. package/node_modules/pngjs/coverage/lcov-report/sync-inflate.js.html +0 -584
  189. package/node_modules/pngjs/coverage/lcov-report/sync-reader.js.html +0 -215
  190. package/node_modules/pngjs/coverage/lcov.info +0 -2177
  191. package/node_modules/pngjs/lib/bitmapper.js +0 -267
  192. package/node_modules/pngjs/lib/bitpacker.js +0 -158
  193. package/node_modules/pngjs/lib/chunkstream.js +0 -189
  194. package/node_modules/pngjs/lib/constants.js +0 -32
  195. package/node_modules/pngjs/lib/crc.js +0 -40
  196. package/node_modules/pngjs/lib/filter-pack.js +0 -171
  197. package/node_modules/pngjs/lib/filter-parse-async.js +0 -24
  198. package/node_modules/pngjs/lib/filter-parse-sync.js +0 -21
  199. package/node_modules/pngjs/lib/filter-parse.js +0 -177
  200. package/node_modules/pngjs/lib/format-normaliser.js +0 -93
  201. package/node_modules/pngjs/lib/interlace.js +0 -95
  202. package/node_modules/pngjs/lib/packer-async.js +0 -50
  203. package/node_modules/pngjs/lib/packer-sync.js +0 -56
  204. package/node_modules/pngjs/lib/packer.js +0 -129
  205. package/node_modules/pngjs/lib/paeth-predictor.js +0 -16
  206. package/node_modules/pngjs/lib/parser-async.js +0 -165
  207. package/node_modules/pngjs/lib/parser-sync.js +0 -108
  208. package/node_modules/pngjs/lib/parser.js +0 -290
  209. package/node_modules/pngjs/lib/png-sync.js +0 -12
  210. package/node_modules/pngjs/lib/png.js +0 -194
  211. package/node_modules/pngjs/lib/sync-inflate.js +0 -168
  212. package/node_modules/pngjs/lib/sync-reader.js +0 -45
  213. package/node_modules/pngjs/package.json +0 -73
  214. package/node_modules/qrcode/README.md +0 -770
  215. package/node_modules/qrcode/bin/qrcode +0 -159
  216. package/node_modules/qrcode/helper/to-sjis-browser.js +0 -2
  217. package/node_modules/qrcode/helper/to-sjis.js +0 -105
  218. package/node_modules/qrcode/lib/browser.js +0 -76
  219. package/node_modules/qrcode/lib/can-promise.js +0 -7
  220. package/node_modules/qrcode/lib/core/alignment-pattern.js +0 -83
  221. package/node_modules/qrcode/lib/core/alphanumeric-data.js +0 -59
  222. package/node_modules/qrcode/lib/core/bit-buffer.js +0 -37
  223. package/node_modules/qrcode/lib/core/bit-matrix.js +0 -65
  224. package/node_modules/qrcode/lib/core/byte-data.js +0 -30
  225. package/node_modules/qrcode/lib/core/error-correction-code.js +0 -135
  226. package/node_modules/qrcode/lib/core/error-correction-level.js +0 -50
  227. package/node_modules/qrcode/lib/core/finder-pattern.js +0 -22
  228. package/node_modules/qrcode/lib/core/format-info.js +0 -29
  229. package/node_modules/qrcode/lib/core/galois-field.js +0 -69
  230. package/node_modules/qrcode/lib/core/kanji-data.js +0 -54
  231. package/node_modules/qrcode/lib/core/mask-pattern.js +0 -234
  232. package/node_modules/qrcode/lib/core/mode.js +0 -167
  233. package/node_modules/qrcode/lib/core/numeric-data.js +0 -43
  234. package/node_modules/qrcode/lib/core/polynomial.js +0 -62
  235. package/node_modules/qrcode/lib/core/qrcode.js +0 -495
  236. package/node_modules/qrcode/lib/core/reed-solomon-encoder.js +0 -56
  237. package/node_modules/qrcode/lib/core/regex.js +0 -31
  238. package/node_modules/qrcode/lib/core/segments.js +0 -330
  239. package/node_modules/qrcode/lib/core/utils.js +0 -63
  240. package/node_modules/qrcode/lib/core/version-check.js +0 -9
  241. package/node_modules/qrcode/lib/core/version.js +0 -163
  242. package/node_modules/qrcode/lib/index.js +0 -12
  243. package/node_modules/qrcode/lib/renderer/canvas.js +0 -63
  244. package/node_modules/qrcode/lib/renderer/png.js +0 -78
  245. package/node_modules/qrcode/lib/renderer/svg-tag.js +0 -81
  246. package/node_modules/qrcode/lib/renderer/svg.js +0 -19
  247. package/node_modules/qrcode/lib/renderer/terminal/terminal-small.js +0 -85
  248. package/node_modules/qrcode/lib/renderer/terminal/terminal.js +0 -49
  249. package/node_modules/qrcode/lib/renderer/terminal.js +0 -9
  250. package/node_modules/qrcode/lib/renderer/utf8.js +0 -71
  251. package/node_modules/qrcode/lib/renderer/utils.js +0 -99
  252. package/node_modules/qrcode/lib/server.js +0 -138
  253. package/node_modules/qrcode/license +0 -10
  254. package/node_modules/qrcode/package.json +0 -77
  255. package/node_modules/require-directory/.jshintrc +0 -67
  256. package/node_modules/require-directory/.npmignore +0 -1
  257. package/node_modules/require-directory/.travis.yml +0 -3
  258. package/node_modules/require-directory/LICENSE +0 -22
  259. package/node_modules/require-directory/README.markdown +0 -184
  260. package/node_modules/require-directory/index.js +0 -86
  261. package/node_modules/require-directory/package.json +0 -40
  262. package/node_modules/require-main-filename/CHANGELOG.md +0 -26
  263. package/node_modules/require-main-filename/LICENSE.txt +0 -14
  264. package/node_modules/require-main-filename/README.md +0 -26
  265. package/node_modules/require-main-filename/index.js +0 -18
  266. package/node_modules/require-main-filename/package.json +0 -35
  267. package/node_modules/set-blocking/CHANGELOG.md +0 -26
  268. package/node_modules/set-blocking/LICENSE.txt +0 -14
  269. package/node_modules/set-blocking/README.md +0 -31
  270. package/node_modules/set-blocking/index.js +0 -7
  271. package/node_modules/set-blocking/package.json +0 -42
  272. package/node_modules/string-width/index.d.ts +0 -29
  273. package/node_modules/string-width/index.js +0 -47
  274. package/node_modules/string-width/license +0 -9
  275. package/node_modules/string-width/package.json +0 -56
  276. package/node_modules/string-width/readme.md +0 -50
  277. package/node_modules/strip-ansi/index.d.ts +0 -17
  278. package/node_modules/strip-ansi/index.js +0 -4
  279. package/node_modules/strip-ansi/license +0 -9
  280. package/node_modules/strip-ansi/package.json +0 -54
  281. package/node_modules/strip-ansi/readme.md +0 -46
  282. package/node_modules/which-module/LICENSE +0 -13
  283. package/node_modules/which-module/README.md +0 -58
  284. package/node_modules/which-module/index.js +0 -9
  285. package/node_modules/which-module/package.json +0 -41
  286. package/node_modules/wrap-ansi/index.js +0 -186
  287. package/node_modules/wrap-ansi/license +0 -9
  288. package/node_modules/wrap-ansi/package.json +0 -61
  289. package/node_modules/wrap-ansi/readme.md +0 -97
  290. package/node_modules/y18n/CHANGELOG.md +0 -35
  291. package/node_modules/y18n/LICENSE +0 -13
  292. package/node_modules/y18n/README.md +0 -109
  293. package/node_modules/y18n/index.js +0 -188
  294. package/node_modules/y18n/package.json +0 -39
  295. package/node_modules/yargs/CHANGELOG.md +0 -420
  296. package/node_modules/yargs/LICENSE +0 -21
  297. package/node_modules/yargs/README.md +0 -140
  298. package/node_modules/yargs/build/lib/apply-extends.d.ts +0 -2
  299. package/node_modules/yargs/build/lib/apply-extends.js +0 -65
  300. package/node_modules/yargs/build/lib/argsert.d.ts +0 -2
  301. package/node_modules/yargs/build/lib/argsert.js +0 -65
  302. package/node_modules/yargs/build/lib/command.d.ts +0 -64
  303. package/node_modules/yargs/build/lib/command.js +0 -416
  304. package/node_modules/yargs/build/lib/common-types.d.ts +0 -36
  305. package/node_modules/yargs/build/lib/common-types.js +0 -25
  306. package/node_modules/yargs/build/lib/completion-templates.d.ts +0 -2
  307. package/node_modules/yargs/build/lib/completion-templates.js +0 -50
  308. package/node_modules/yargs/build/lib/completion.d.ts +0 -21
  309. package/node_modules/yargs/build/lib/completion.js +0 -135
  310. package/node_modules/yargs/build/lib/is-promise.d.ts +0 -1
  311. package/node_modules/yargs/build/lib/is-promise.js +0 -9
  312. package/node_modules/yargs/build/lib/levenshtein.d.ts +0 -1
  313. package/node_modules/yargs/build/lib/levenshtein.js +0 -58
  314. package/node_modules/yargs/build/lib/middleware.d.ts +0 -10
  315. package/node_modules/yargs/build/lib/middleware.js +0 -57
  316. package/node_modules/yargs/build/lib/obj-filter.d.ts +0 -1
  317. package/node_modules/yargs/build/lib/obj-filter.js +0 -14
  318. package/node_modules/yargs/build/lib/parse-command.d.ts +0 -11
  319. package/node_modules/yargs/build/lib/parse-command.js +0 -36
  320. package/node_modules/yargs/build/lib/process-argv.d.ts +0 -2
  321. package/node_modules/yargs/build/lib/process-argv.js +0 -31
  322. package/node_modules/yargs/build/lib/usage.d.ts +0 -49
  323. package/node_modules/yargs/build/lib/usage.js +0 -540
  324. package/node_modules/yargs/build/lib/validation.d.ts +0 -34
  325. package/node_modules/yargs/build/lib/validation.js +0 -330
  326. package/node_modules/yargs/build/lib/yargs.d.ts +0 -274
  327. package/node_modules/yargs/build/lib/yargs.js +0 -1190
  328. package/node_modules/yargs/build/lib/yerror.d.ts +0 -4
  329. package/node_modules/yargs/build/lib/yerror.js +0 -11
  330. package/node_modules/yargs/index.js +0 -40
  331. package/node_modules/yargs/locales/be.json +0 -46
  332. package/node_modules/yargs/locales/de.json +0 -46
  333. package/node_modules/yargs/locales/en.json +0 -51
  334. package/node_modules/yargs/locales/es.json +0 -46
  335. package/node_modules/yargs/locales/fi.json +0 -49
  336. package/node_modules/yargs/locales/fr.json +0 -53
  337. package/node_modules/yargs/locales/hi.json +0 -49
  338. package/node_modules/yargs/locales/hu.json +0 -46
  339. package/node_modules/yargs/locales/id.json +0 -50
  340. package/node_modules/yargs/locales/it.json +0 -46
  341. package/node_modules/yargs/locales/ja.json +0 -51
  342. package/node_modules/yargs/locales/ko.json +0 -49
  343. package/node_modules/yargs/locales/nb.json +0 -44
  344. package/node_modules/yargs/locales/nl.json +0 -49
  345. package/node_modules/yargs/locales/nn.json +0 -44
  346. package/node_modules/yargs/locales/pirate.json +0 -13
  347. package/node_modules/yargs/locales/pl.json +0 -49
  348. package/node_modules/yargs/locales/pt.json +0 -45
  349. package/node_modules/yargs/locales/pt_BR.json +0 -48
  350. package/node_modules/yargs/locales/ru.json +0 -46
  351. package/node_modules/yargs/locales/th.json +0 -46
  352. package/node_modules/yargs/locales/tr.json +0 -48
  353. package/node_modules/yargs/locales/zh_CN.json +0 -48
  354. package/node_modules/yargs/locales/zh_TW.json +0 -47
  355. package/node_modules/yargs/package.json +0 -92
  356. package/node_modules/yargs/yargs.js +0 -14
  357. package/node_modules/yargs-parser/CHANGELOG.md +0 -601
  358. package/node_modules/yargs-parser/LICENSE.txt +0 -14
  359. package/node_modules/yargs-parser/README.md +0 -449
  360. package/node_modules/yargs-parser/index.js +0 -1032
  361. package/node_modules/yargs-parser/lib/tokenize-arg-string.js +0 -40
  362. package/node_modules/yargs-parser/package.json +0 -46
@@ -1,766 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
3
- import { lstat, realpath } from "node:fs/promises";
4
- import { createBundledGitReadProvider } from "./git-read-bundled-provider.js";
5
-
6
- // task-28(issue #86 方案 B):GET 仍 ≤32;POST 支持 ≤128(URL 16KB 限制解除)。
7
- const MAX_GRAPH_TIPS_GET = 32;
8
- const MAX_GRAPH_TIPS_POST = 128;
9
- const GRAPH_DEADLINE_MS = 25_000;
10
- const MAX_TRACKED_FILES = 200;
11
- const FILE_HISTORY_DEFAULT_LIMIT = 20;
12
- const FILE_HISTORY_MAX_LIMIT = 100;
13
- const FILE_HISTORY_MAX_COMMITS = 5000;
14
- const FILE_HISTORY_TIMEOUT_MS = 20_000;
15
- const MAX_FILE_HISTORY_SNAPSHOTS = 8;
16
- const REF_KIND_ORDER = { head: 0, localBranch: 1, remoteBranch: 2, other: 3 };
17
- const FILE_HISTORY_REASONS = new Set(["not-tracked", "no-history", "path-invalid"]);
18
-
19
- function failure(code, status, message = code) {
20
- const error = new Error(message);
21
- error.code = code;
22
- error.status = status;
23
- return error;
24
- }
25
-
26
- // The provider contract is additive: v1.1.0 providers expose the new methods,
27
- // while legacy v1.0.0 providers stay compatible and their raw ref strings are
28
- // projected into the structured DTO by this facade.
29
- const providerCompatible = (provider) => /^1\.\d+\.\d+$/.test(String(provider?.contractVersion ?? ""))
30
- && ["repositoryRoot", "branches", "resolveTip", "graph", "commit"].every((method) => typeof provider[method] === "function");
31
-
32
- const compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
33
- const refShortName = (name) => name === "HEAD" ? "HEAD" : String(name).replace(/^refs\/(?:heads|remotes|tags)\//, "");
34
- const trimSubject = (value) => [...String(value)].slice(0, 200).join("");
35
- const emptyRefDetails = () => ({ refsDetail: [], tagsDetail: [] });
36
- const sortRefDetails = (rows) => rows.sort((left, right) => (REF_KIND_ORDER[left.kind] ?? 9) - (REF_KIND_ORDER[right.kind] ?? 9) || compareText(left.name, right.name));
37
- const sortTagDetails = (rows) => rows.sort((left, right) => compareText(left.name, right.name));
38
-
39
- /** Project provider-owned ref records onto the commit they resolve to. */
40
- function refDetailsFromRecords(records, commitOid, { fullTags = false } = {}) {
41
- const target = String(commitOid ?? "").toLowerCase();
42
- const refs = [], tags = [], seen = new Set();
43
- for (const record of Array.isArray(records) ? records : []) {
44
- if (!record || String(record.commitOid ?? "").toLowerCase() !== target) continue;
45
- const name = typeof record.name === "string" ? record.name : "";
46
- if (!name) continue;
47
- const shortName = typeof record.shortName === "string" && record.shortName ? record.shortName : refShortName(name);
48
- if (record.kind === "tag") {
49
- const key = `tag\0${shortName}`;
50
- if (seen.has(key)) continue;
51
- seen.add(key);
52
- const tag = { name, shortName, oid: target, annotated: record.annotated === true };
53
- if (fullTags) {
54
- if (typeof record.tagger === "string" && record.tagger) tag.tagger = record.tagger;
55
- const date = Number(record.date);
56
- if (Number.isFinite(date) && date > 0) tag.date = date;
57
- if (typeof record.subject === "string" && record.subject) tag.subject = trimSubject(record.subject);
58
- if (typeof record.hint === "string" && record.hint) tag.hint = record.hint;
59
- }
60
- tags.push(tag);
61
- continue;
62
- }
63
- const kind = ["head", "localBranch", "remoteBranch"].includes(record.kind) ? record.kind : "other";
64
- const key = `${kind}\0${shortName}`;
65
- if (seen.has(key)) continue;
66
- seen.add(key);
67
- const detail = { kind, name, shortName, oid: target };
68
- if (record.current === true) detail.current = true;
69
- refs.push(detail);
70
- }
71
- return { refsDetail: sortRefDetails(refs), tagsDetail: sortTagDetails(tags) };
72
- }
73
-
74
- /**
75
- * String fallback for legacy providers: parse raw decorations such as
76
- * `HEAD -> refs/heads/main`, `refs/remotes/origin/main` and
77
- * `tag: refs/tags/v1.0.0`. Annotated metadata is unavailable here, so tags
78
- * are advertised as lightweight name-level entries.
79
- */
80
- function refDetailsFromLegacyRefs(rawRefs, commitOid, { tags = [] } = {}) {
81
- const target = String(commitOid ?? "");
82
- const refs = [], tagRows = [], seen = new Set();
83
- let currentBranch = null;
84
- const addRef = (kind, name, shortName, extra = {}) => {
85
- const key = `${kind}\0${shortName}`;
86
- if (seen.has(key)) return;
87
- seen.add(key);
88
- refs.push({ kind, name, shortName, oid: target, ...extra });
89
- };
90
- const addTag = (value) => {
91
- let name = String(value ?? "").trim();
92
- if (name.startsWith("tag: ")) name = name.slice(5).trim();
93
- if (!name) return;
94
- if (!name.startsWith("refs/tags/")) name = `refs/tags/${name}`;
95
- const shortName = name.slice(10);
96
- if (!shortName) return;
97
- const key = `tag\0${shortName}`;
98
- if (seen.has(key)) return;
99
- seen.add(key);
100
- tagRows.push({ name, shortName, oid: target, annotated: false });
101
- };
102
- const addRefValue = (value) => {
103
- const raw = String(value ?? "").trim();
104
- if (!raw) return;
105
- if (raw === "HEAD") return addRef("head", "HEAD", "HEAD", { current: true });
106
- if (raw.startsWith("HEAD -> ")) {
107
- addRef("head", "HEAD", "HEAD", { current: true });
108
- const next = raw.slice(8).trim();
109
- if (!next) return undefined;
110
- // Providers may decorate with shortened branch names (`HEAD -> main`)
111
- // instead of full ref names; normalize the branch form here. The target
112
- // of HEAD is by definition the current branch, marked after parsing.
113
- if (next.startsWith("refs/heads/")) { currentBranch = next.slice(11); return addRef("localBranch", next, currentBranch); }
114
- if (next.startsWith("refs/")) return addRefValue(next);
115
- currentBranch = next;
116
- return addRef("localBranch", `refs/heads/${next}`, next);
117
- }
118
- if (raw.startsWith("tag: ")) return addTag(raw.slice(5));
119
- if (raw === "refs/stash") return;
120
- if (raw.startsWith("refs/heads/")) return addRef("localBranch", raw, raw.slice(11));
121
- if (raw.startsWith("refs/remotes/")) return raw.endsWith("/HEAD") ? undefined : addRef("remoteBranch", raw, raw.slice(13));
122
- if (raw.startsWith("refs/tags/")) return addTag(raw);
123
- return addRef("other", raw, raw);
124
- };
125
- for (const raw of Array.isArray(rawRefs) ? rawRefs : []) addRefValue(raw);
126
- for (const raw of Array.isArray(tags) ? tags : []) addTag(raw);
127
- // `current` is set once HEAD has been seen, so decoration order does not matter.
128
- if (currentBranch !== null) {
129
- const row = refs.find((entry) => entry.kind === "localBranch" && entry.shortName === currentBranch);
130
- if (row) row.current = true;
131
- }
132
- return { refsDetail: sortRefDetails(refs), tagsDetail: sortTagDetails(tagRows) };
133
- }
134
-
135
- const mergeRefDetails = (primary, secondary) => {
136
- const refs = new Map(), tags = new Map();
137
- for (const row of [...primary.refsDetail, ...secondary.refsDetail]) {
138
- const key = `${row.kind}\0${row.shortName}`;
139
- if (!refs.has(key)) refs.set(key, row);
140
- }
141
- for (const row of [...primary.tagsDetail, ...secondary.tagsDetail]) {
142
- if (!tags.has(row.shortName)) tags.set(row.shortName, row);
143
- }
144
- return { refsDetail: sortRefDetails([...refs.values()]), tagsDetail: sortTagDetails([...tags.values()]) };
145
- };
146
-
147
- const HISTORY_STATUS_WORDS = { added: "A", modified: "M", deleted: "D", renamed: "R", copied: "C", "type-changed": "T" };
148
- const historyStatus = (value) => {
149
- const text = String(value ?? "").trim();
150
- const word = HISTORY_STATUS_WORDS[text.toLowerCase()];
151
- if (word) return word;
152
- const upper = text.toUpperCase();
153
- return ["A", "M", "D", "R", "C", "T"].includes(upper[0]) ? upper[0] : "M";
154
- };
155
-
156
- /** Session-authorized read facade over an optional external or bundled provider. */
157
- export function createGitReadService(ctx, { bundledProvider, now = () => Date.now(), snapshotTtlMs = 5 * 60_000, pollIntervalMs = 30_000, onChanged, graphDeadlineMs = GRAPH_DEADLINE_MS, onSnapshotDisposed } = {}) {
158
- const get = (name) => { try { return ctx.get?.(name); } catch { return undefined; } };
159
- const external = get("gitReadProvider");
160
- let externalAvailable = false;
161
- try { externalAvailable = providerCompatible(external) && external.capabilities?.().available === true; } catch {}
162
- const bundled = bundledProvider ?? createBundledGitReadProvider(ctx);
163
- const provider = externalAvailable ? external : bundled;
164
- const bindings = new Map();
165
- const repositoryIdFor = (sessionId, root) => `repo_${createHash("sha256").update(`${sessionId}\0${root}`).digest("base64url").slice(0, 32)}`;
166
- const inside = (child, parent) => {
167
- const path = relative(resolve(parent), resolve(child));
168
- return path === "" || (path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path));
169
- };
170
- const authorizedRoot = async (cwd) => {
171
- if (typeof cwd !== "string" || !cwd) throw failure("repository-not-authorized", 403);
172
- try {
173
- const canonicalCwd = await realpath(cwd);
174
- const workspacePaths = get("workspaceRegistry")?.list?.()?.map((entry) => entry?.path) ?? [];
175
- const workspaces = await Promise.all(workspacePaths.filter((path) => typeof path === "string").map((path) => realpath(path).catch(() => null)));
176
- if (!workspaces.some((path) => path && inside(canonicalCwd, path))) throw failure("repository-not-authorized", 403);
177
- const root = await realpath(await provider.repositoryRoot(canonicalCwd));
178
- if (!inside(canonicalCwd, root) || !workspaces.some((path) => path && inside(root, path))) throw failure("repository-not-authorized", 403);
179
- return root;
180
- } catch (error) {
181
- if (["git-provider-unavailable", "not-git-repository"].includes(error?.code)) throw failure(error.code, error.status);
182
- throw failure("repository-not-authorized", 403);
183
- }
184
- };
185
- const session = (sessionId) => {
186
- if (typeof sessionId !== "string" || sessionId === "") throw failure("session-not-found", 404);
187
- const value = get("sessions")?.get?.(sessionId);
188
- if (!value) throw failure("session-not-found", 404);
189
- return value;
190
- };
191
- const binding = async (sessionId, repositoryId) => {
192
- const value = bindings.get(repositoryId);
193
- if (!value || value.sessionId !== sessionId) throw failure("repository-not-authorized", 403);
194
- const current = session(sessionId);
195
- const currentRoot = await authorizedRoot(current?.header?.cwd);
196
- if (currentRoot !== value.root) throw failure("repository-not-authorized", 403);
197
- return value;
198
- };
199
- const worktreeSnapshots = new Map();
200
- const snapshots = new Map();
201
- const fileCursors = new Map();
202
- const historySnapshots = new Map();
203
- const historyCursors = new Map();
204
- const refSignatures = new Map();
205
- const keepBounded = (map, maximum) => {
206
- while (map.size > maximum) map.delete(map.keys().next().value);
207
- };
208
- const prune = () => {
209
- for (const [id, item] of snapshots) if (item.expiresAt <= now()) snapshots.delete(id);
210
- for (const [id, item] of fileCursors) if (item.expiresAt <= now()) fileCursors.delete(id);
211
- for (const [id, item] of historySnapshots) if (item.expiresAt <= now()) historySnapshots.delete(id);
212
- for (const [id, item] of historyCursors) if (item.expiresAt <= now()) historyCursors.delete(id);
213
- };
214
- let pollTimer = null;
215
- let pollInFlight = null;
216
- let unsubscribeProvider = null;
217
- const validOid = (value) => typeof value === "string" && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(value);
218
- const safeFilePath = (value) => typeof value === "string" && value !== "" && !isAbsolute(value) && !/^(?:[A-Za-z]:[\\/]|\\\\|[a-z][a-z\d+.-]*:\/\/)/i.test(value) && !value.split(/[\\/]/).includes("..") && !value.includes("\0");
219
- const validRef = (value) => value === "HEAD" || (typeof value === "string" && /^refs\/(?:heads|remotes)\/[A-Za-z0-9._/-]+$/.test(value) && !value.includes("..") && !value.includes("//") && !value.includes("@{") && !/(^|\/)\.|\/$|\.lock(?:\/|$)|[/.]$/.test(value));
220
- const stale = () => failure("graph-stale", 409);
221
- const hasNewFileMethods = (candidate) => typeof candidate?.files === "function" && typeof candidate?.fileHistory === "function";
222
- const bundledProviderReady = () => {
223
- try { return bundled.capabilities?.().available === true; } catch { return false; }
224
- };
225
- // Truthful capability: only the ACTIVE provider may serve the new endpoints.
226
- // A legacy external provider must not be mixed with bundled data (its graph
227
- // and commit facts come from a different source); a bundled provider also
228
- // needs its Git subprocess to be usable.
229
- const fileHistoryFeature = () => {
230
- if (!hasNewFileMethods(provider)) return false;
231
- if (provider !== bundled) return true;
232
- return bundledProviderReady();
233
- };
234
- const fileReader = () => {
235
- if (!hasNewFileMethods(provider)) throw failure("provider-incompatible", 503);
236
- return provider;
237
- };
238
- const readRefRecords = async (root) => {
239
- if (typeof provider.refs !== "function") return null;
240
- try {
241
- const records = await provider.refs(root);
242
- return Array.isArray(records) ? records : null;
243
- } catch { return null; }
244
- };
245
- const graphTimeout = () => failure("graph-timeout", 504);
246
- /** 单次 provider 调用的 25s 硬截止(provider 自身超时/挂起兜底)。 */
247
- const graphRace = async (factory, deadline) => {
248
- const remaining = Math.max(1, deadline - Date.now());
249
- const call = Promise.resolve().then(factory);
250
- let timer = null;
251
- const timeout = new Promise((_, reject) => {
252
- timer = setTimeout(() => reject(graphTimeout()), remaining);
253
- });
254
- try {
255
- return await Promise.race([call, timeout]);
256
- } finally {
257
- if (timer) clearTimeout(timer);
258
- // 超时后底层 promise 仍可能 settle:吞掉,避免 unhandledRejection。
259
- void call.catch(() => {});
260
- }
261
- };
262
- /** provider.refs 一次映射(name → commit oid);无 refs 能力/调用失败返回 null → 逐 tip 回退。 */
263
- const graphRefsByName = async (root, deadline) => {
264
- if (typeof provider.refs !== "function") return null;
265
- try {
266
- const records = await graphRace(
267
- () => provider.refs(root, { timeoutMs: Math.max(1, deadline - Date.now()) }),
268
- deadline,
269
- );
270
- if (!Array.isArray(records)) return null;
271
- const byName = new Map();
272
- for (const record of records) {
273
- if (!record || typeof record.name !== "string") continue;
274
- byName.set(record.name, validOid(record.commitOid) ? String(record.commitOid) : null);
275
- }
276
- return byName;
277
- } catch (error) {
278
- if (error?.code === "graph-timeout") throw error;
279
- return null; // 外部 provider 无 refs/调用失败 → 逐 tip(兼容旧契约)
280
- }
281
- };
282
- /** 批量解析新快照 tips:一次 refs 映射优先,缺项才逐 tip resolveTip。 */
283
- const resolveGraphTips = async (root, selected, deadline) => {
284
- const byName = await graphRefsByName(root, deadline);
285
- const resolved = [];
286
- for (const tip of selected) {
287
- let oid;
288
- if (byName && byName.has(tip.name)) {
289
- oid = byName.get(tip.name);
290
- if (!validOid(oid)) throw failure("graph-tip-invalid", 409);
291
- } else {
292
- try {
293
- oid = await graphRace(() => provider.resolveTip(root, tip.name), deadline);
294
- } catch (error) {
295
- if (error?.code === "graph-timeout") throw error;
296
- if (tip.name === "HEAD" && error?.code === "git-command-failed") continue;
297
- throw failure("graph-tip-invalid", 409);
298
- }
299
- if (!validOid(oid)) throw failure("graph-tip-invalid", 409);
300
- }
301
- if (tip.tipOid != null && tip.tipOid.toLowerCase() !== oid.toLowerCase()) throw failure("graph-tip-invalid", 409);
302
- resolved.push({ name: tip.name, tipOid: oid });
303
- if (Date.now() > deadline) throw graphTimeout();
304
- }
305
- return resolved;
306
- };
307
- /** 续页/前后校验:一次 refs 映射比对 tips 未移动;失败抛 graph-stale。 */
308
- const verifyGraphTips = async (root, tips, deadline) => {
309
- const byName = await graphRefsByName(root, deadline);
310
- for (const tip of tips) {
311
- let current;
312
- if (byName && byName.has(tip.name)) current = byName.get(tip.name);
313
- else {
314
- try {
315
- current = await graphRace(() => provider.resolveTip(root, tip.name), deadline);
316
- } catch (error) {
317
- if (error?.code === "graph-timeout") throw error;
318
- throw stale();
319
- }
320
- }
321
- if (!validOid(current) || current.toLowerCase() !== tip.tipOid.toLowerCase()) throw stale();
322
- if (Date.now() > deadline) throw graphTimeout();
323
- }
324
- };
325
- /** graph 专用:readRefRecords 纳入同一 absolute deadline(挂起→504,不返回半页)。 */
326
- const readRefRecordsWithin = async (root, deadline) => {
327
- if (typeof provider.refs !== "function") return null;
328
- try {
329
- const records = await graphRace(
330
- () => provider.refs(root, { timeoutMs: Math.max(1, deadline - Date.now()) }),
331
- deadline,
332
- );
333
- return Array.isArray(records) ? records : null;
334
- } catch (error) {
335
- if (error?.code === "graph-timeout") throw error;
336
- return null;
337
- }
338
- };
339
- const capabilities = () => {
340
- const base = provider.capabilities?.() ?? { available: true, reason: null };
341
- return {
342
- contractVersion: "1.1.0", available: base.available !== false,
343
- reason: ["git-provider-unavailable", "workspace-registry-unavailable"].includes(base.reason) ? base.reason : null,
344
- readOnly: true, provider: provider === external ? "external" : "bundled",
345
- // task-28:POST graph 的 tips 上限(旧宿主缺该字段,App 回退 5/5)。
346
- graphTips: { max: MAX_GRAPH_TIPS_POST, getMax: MAX_GRAPH_TIPS_GET },
347
- features: {
348
- repository: true, branches: true, graph: true, commit: true, worktree: true, preview: true,
349
- // Both flags are independent and additive: refsDetail can be
350
- // synthesized from legacy strings; fileHistory is true only when the
351
- // active provider implements the new methods (see fileHistoryFeature).
352
- refsDetail: true, fileHistory: fileHistoryFeature(),
353
- },
354
- };
355
- };
356
- /**
357
- * Normalize a client-supplied path to a repository-relative POSIX path.
358
- * Returns null for paths that escape the repository (reported as
359
- * `path-invalid`), and throws 400 for directories.
360
- */
361
- const normalizeHistoryPath = async (root, input) => {
362
- if (typeof input !== "string" || input === "" || input.includes("\0")) return null;
363
- // Windows-style absolute paths cannot be mapped on a POSIX host; report
364
- // them as invalid instead of treating them as a relative filename.
365
- if (/^(?:[A-Za-z]:[\\/]|\\\\)/.test(input) && !isAbsolute(input)) return null;
366
- let candidate = isAbsolute(input) ? resolve(input) : resolve(root, input);
367
- // Windows clients can send an 8.3 alias while the authorized repository
368
- // uses its canonical long name. Canonicalize the nearest existing parent,
369
- // preserving the final filename (a tracked symlink is itself a file).
370
- let parent = dirname(candidate);
371
- const tail = [basename(candidate)];
372
- for (;;) {
373
- try { candidate = resolve(await realpath(parent), ...tail); break; }
374
- catch {
375
- const next = dirname(parent);
376
- if (next === parent) break;
377
- tail.unshift(basename(parent)); parent = next;
378
- }
379
- }
380
- const rel = relative(root, candidate);
381
- if (rel === "") throw failure("path-invalid", 400);
382
- if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;
383
- const normalized = sep === "/" ? rel : rel.split(sep).join("/");
384
- try {
385
- const info = await lstat(candidate);
386
- if (info.isDirectory()) throw failure("path-invalid", 400);
387
- } catch (error) {
388
- if (error?.code === "path-invalid") throw error;
389
- }
390
- return normalized;
391
- };
392
- const service = {
393
- capabilities,
394
- async capabilitiesForSession(sessionId) {
395
- const current = session(sessionId);
396
- const base = capabilities();
397
- if (!base.available) return base;
398
- try {
399
- await authorizedRoot(current?.header?.cwd);
400
- return base;
401
- } catch (error) {
402
- const reason = ["not-git-repository", "git-provider-unavailable"].includes(error?.code)
403
- ? error.code : "repository-not-authorized";
404
- return { ...base, available: false, reason };
405
- }
406
- },
407
- async repositoryForSession(sessionId) {
408
- const current = session(sessionId);
409
- const root = await authorizedRoot(current?.header?.cwd);
410
- const repositoryId = repositoryIdFor(sessionId, root);
411
- bindings.set(repositoryId, { sessionId, root });
412
- keepBounded(bindings, 256);
413
- const rawInfo = typeof provider.repositoryInfo === "function" ? await provider.repositoryInfo(root) : {};
414
- if (typeof provider.refSignature === "function") refSignatures.set(repositoryId, await provider.refSignature(root));
415
- return {
416
- repositoryId, name: basename(root) || "repository",
417
- ...(validOid(rawInfo.headOid) ? { headOid: rawInfo.headOid } : {}),
418
- ...(typeof rawInfo.currentBranch === "string" && rawInfo.currentBranch.startsWith("refs/heads/") && validRef(rawInfo.currentBranch) ? { currentBranch: rawInfo.currentBranch } : {}),
419
- detached: rawInfo.detached === true, empty: rawInfo.empty === true,
420
- };
421
- },
422
- async worktree(sessionId, repositoryId) {
423
- const authorized = await binding(sessionId, repositoryId);
424
- let reader = typeof provider.worktree === "function" ? provider : bundled;
425
- let raw = await reader.worktree(authorized.root);
426
- if (typeof raw?.signature !== "string" || raw.signature === "" || !Array.isArray(raw.entries)) {
427
- reader = bundled;
428
- raw = await reader.worktree(authorized.root);
429
- }
430
- const entries = (raw.entries ?? []).filter((entry) => safeFilePath(entry.path)).slice(0, 2000);
431
- const snapshotId = createHash("sha256").update(`${repositoryId}\0${raw.signature}\0${JSON.stringify(entries)}`).digest("base64url");
432
- worktreeSnapshots.set(snapshotId, { sessionId, repositoryId, root: authorized.root, signature: raw.signature, entries, reader, expiresAt: now() + snapshotTtlMs });
433
- keepBounded(worktreeSnapshots, 128);
434
- return { repositoryId, snapshotId, staged: entries.filter((e) => e.index).map(({ path, oldPath, status, conflicted }) => ({ path, ...(oldPath ? { oldPath } : {}), status, conflicted })), unstaged: entries.filter((e) => e.worktree).map(({ path, oldPath, status, conflicted }) => ({ path, ...(oldPath ? { oldPath } : {}), status, conflicted })), untracked: entries.filter((e) => e.status === "untracked").map(({ path, status, conflicted }) => ({ path, status, conflicted })), truncated: (raw.entries ?? []).length > 2000 };
435
- },
436
- async preview(sessionId, repositoryId, { kind, snapshotId, path, oid } = {}) {
437
- const authorized = await binding(sessionId, repositoryId);
438
- if (!safeFilePath(path) || !["staged", "unstaged", "untracked", "commit"].includes(kind)) throw failure("preview-invalid", 400);
439
- const reader = bundled;
440
- let raw;
441
- if (kind === "commit") {
442
- if (!validOid(oid)) throw failure("invalid-oid", 400);
443
- const commit = typeof provider.commit === "function"
444
- ? await provider.commit(authorized.root, oid)
445
- : await reader.commit(authorized.root, oid);
446
- const commitFile = (Array.isArray(commit?.files) ? commit.files : []).find((file) => file.path === path || file.oldPath === path);
447
- if (!commitFile) throw failure("preview-file-not-found", 404);
448
- raw = { ...await reader.commitPreview(authorized.root, oid, path), ...(commitFile.oldPath ? { oldPath: commitFile.oldPath } : {}) };
449
- } else {
450
- const snap = worktreeSnapshots.get(snapshotId);
451
- if (!snap || snap.sessionId !== sessionId || snap.repositoryId !== repositoryId || snap.root !== authorized.root || snap.expiresAt <= now()) throw stale();
452
- const current = await snap.reader.worktree(authorized.root);
453
- if (current.signature !== snap.signature) throw stale();
454
- const member = snap.entries.find((entry) => entry.path === path && (kind === "untracked" ? entry.status === "untracked" : kind === "staged" ? entry.index : entry.worktree));
455
- if (!member) throw failure("preview-file-not-found", 404);
456
- if (member.conflicted) raw = { diff: "", binary: false, notice: "merge conflict preview omitted" };
457
- else {
458
- const previewReader = typeof snap.reader.worktreePreview === "function" ? snap.reader : reader;
459
- const preview = await previewReader.worktreePreview(authorized.root, kind, path);
460
- const afterPreview = await snap.reader.worktree(authorized.root);
461
- if (afterPreview.signature !== snap.signature) throw stale();
462
- raw = { ...preview, ...(member.oldPath ? { oldPath: member.oldPath } : {}) };
463
- }
464
- }
465
- let diff = String(raw.diff ?? ""); const max = 512 * 1024; const truncated = raw.truncated === true || Buffer.byteLength(diff) > max;
466
- if (Buffer.byteLength(diff) > max) diff = Buffer.from(diff).subarray(0, max).toString("utf8");
467
- const binary = raw.binary === true || /Binary files? .* differ/.test(diff) || diff.includes("GIT binary patch");
468
- let notice = raw.notice;
469
- if (!notice && binary) { notice = "binary preview omitted"; diff = ""; }
470
- else if (!notice && /(?:new file mode|old mode|new mode) 120000/.test(diff)) { notice = "symlink text preview omitted"; diff = ""; }
471
- else if (!notice && /^\+(?:Subproject commit )|^-(?:Subproject commit )/m.test(diff)) { notice = "submodule preview omitted"; diff = ""; }
472
- else if (!notice && !/^@@/m.test(diff) && /^(?:old mode|new mode) /m.test(diff)) { notice = "file mode changed; no text changes"; diff = ""; }
473
- return { repositoryId, kind, path, ...(raw.oldPath ? { oldPath: raw.oldPath } : {}), diff, truncated, binary, additions: raw.additions ?? null, deletions: raw.deletions ?? null, ...(notice ? { notice } : {}) };
474
- },
475
- async branches(sessionId, repositoryId) {
476
- const authorized = await binding(sessionId, repositoryId);
477
- if (typeof provider.branches !== "function") throw failure("provider-incompatible", 503);
478
- const rows = await provider.branches(authorized.root);
479
- const branches = (Array.isArray(rows) ? rows : []).filter((row) => row && row.name !== "HEAD" && validRef(row.name) && validOid(row.oid)).map((row) => ({
480
- name: row.name, displayName: row.name.replace(/^refs\/(?:heads|remotes)\//, ""), oid: row.oid,
481
- kind: row.name.startsWith("refs/remotes/") ? "remote" : "local", current: row.current === true,
482
- tracking: typeof row.tracking === "string" && row.tracking.startsWith("refs/remotes/") && validRef(row.tracking) ? row.tracking : null,
483
- ahead: Math.max(0, Number(row.ahead) || 0), behind: Math.max(0, Number(row.behind) || 0),
484
- }));
485
- return { repositoryId, branches };
486
- },
487
- async commit(sessionId, repositoryId, oid, { filesCursor, filesLimit = 100 } = {}) {
488
- const authorized = await binding(sessionId, repositoryId);
489
- if (!validOid(oid)) throw failure("invalid-oid", 400);
490
- if (typeof provider.commit !== "function") throw failure("provider-incompatible", 503);
491
- const limit = Math.max(1, Math.min(200, Number(filesLimit) || 100));
492
- prune();
493
- let offset = 0;
494
- if (filesCursor) {
495
- const saved = fileCursors.get(filesCursor);
496
- if (!saved || saved.expiresAt <= now() || saved.sessionId !== sessionId || saved.repositoryId !== repositoryId || saved.oid !== String(oid).toLowerCase()) throw failure("invalid-files-cursor", 400);
497
- offset = saved.offset;
498
- }
499
- const value = await provider.commit(authorized.root, oid);
500
- const allFiles = (Array.isArray(value.files) ? value.files : []).filter((file) => safeFilePath(file?.path) && (file.oldPath == null || safeFilePath(file.oldPath))).map((file) => ({
501
- path: String(file.path ?? ""), ...(typeof file.oldPath === "string" ? { oldPath: file.oldPath } : {}),
502
- status: String(file.status ?? "modified"), binary: file.binary === true,
503
- additions: file.additions == null ? null : Math.max(0, Number(file.additions) || 0),
504
- deletions: file.deletions == null ? null : Math.max(0, Number(file.deletions) || 0),
505
- }));
506
- const items = allFiles.slice(offset, offset + limit);
507
- let nextCursor = null;
508
- if (offset + items.length < allFiles.length) {
509
- nextCursor = randomUUID();
510
- fileCursors.set(nextCursor, { sessionId, repositoryId, oid: value.oid.toLowerCase(), offset: offset + items.length, expiresAt: now() + snapshotTtlMs });
511
- keepBounded(fileCursors, 1024);
512
- }
513
- const stats = allFiles.reduce((sum, file) => ({ additions: sum.additions + (file.additions ?? 0), deletions: sum.deletions + (file.deletions ?? 0), files: sum.files + 1 }), { additions: 0, deletions: 0, files: 0 });
514
- const commitOid = String(value.oid ?? oid);
515
- const legacyRefs = Array.isArray(value.refs) ? value.refs.map(String) : [];
516
- const legacyTags = Array.isArray(value.tags) ? value.tags.map(String) : [];
517
- const records = await readRefRecords(authorized.root);
518
- const refDetails = mergeRefDetails(
519
- records ? refDetailsFromRecords(records, commitOid, { fullTags: true }) : emptyRefDetails(),
520
- refDetailsFromLegacyRefs(legacyRefs, commitOid, { tags: legacyTags }),
521
- );
522
- return {
523
- repositoryId, oid: commitOid, parents: Array.isArray(value.parents) ? value.parents.map(String) : [],
524
- author: String(value.author ?? ""), timestamp: Number(value.timestamp) || 0, message: String(value.message ?? ""),
525
- refs: legacyRefs, tags: legacyTags, refsDetail: refDetails.refsDetail, tagsDetail: refDetails.tagsDetail,
526
- stats, files: { items, total: allFiles.length, nextCursor },
527
- };
528
- },
529
- /**
530
- * 图分页。task-28:`maxTips` 由 HTTP 层按传输方式传入(GET=32 / POST=128),
531
- * 续页可省略 tips;snapshotId/cursor 与传输方式无关(GET/POST 互通)。
532
- */
533
- async graph(sessionId, repositoryId, { tips, snapshotId, cursor, limit = 100, maxTips = MAX_GRAPH_TIPS_GET } = {}) {
534
- const authorized = await binding(sessionId, repositoryId);
535
- prune();
536
- const deadline = Date.now() + graphDeadlineMs;
537
- const tipCap = maxTips === MAX_GRAPH_TIPS_POST ? MAX_GRAPH_TIPS_POST : MAX_GRAPH_TIPS_GET;
538
- const pageSize = Math.max(1, Math.min(200, Number(limit) || 100));
539
- let snapshot, offset = 0;
540
- let snapshotCreatedNow = false;
541
- if (snapshotId !== undefined || cursor !== undefined) {
542
- if (!snapshotId || !cursor) throw stale();
543
- snapshot = snapshots.get(snapshotId);
544
- if (!snapshot || snapshot.sessionId !== sessionId || snapshot.repositoryId !== repositoryId || snapshot.root !== authorized.root || snapshot.expiresAt <= now()) throw stale();
545
- offset = snapshot.cursors.get(cursor);
546
- if (!Number.isInteger(offset)) throw stale();
547
- } else {
548
- const selected = tips === undefined ? [{ name: "HEAD", tipOid: null }] : tips;
549
- if (!Array.isArray(selected) || selected.length > tipCap) throw failure("graph-too-many-tips", 400, `tips limit is ${tipCap}`);
550
- if (selected.length === 0) throw failure("graph-tip-invalid", 400);
551
- const names = selected.map((tip) => tip?.name);
552
- if (new Set(names).size !== names.length || names.some((name) => !validRef(name)) || selected.some((tip) => tip?.tipOid != null && !validOid(tip.tipOid))) throw failure("graph-tip-invalid", 400);
553
- // P0 批量解析:128 tips 只做一次 provider.refs(外部 provider 无 refs 才逐 tip)。
554
- const resolved = await resolveGraphTips(authorized.root, selected, deadline);
555
- snapshot = { id: randomUUID(), sessionId, repositoryId, root: authorized.root, tips: resolved, expiresAt: now() + snapshotTtlMs, cursors: new Map() };
556
- snapshotCreatedNow = true;
557
- snapshots.set(snapshot.id, snapshot);
558
- keepBounded(snapshots, 128);
559
- }
560
- // 统一 snapshot 清理策略(re-review P1):
561
- // - 纯 graph-timeout:本次请求**新建且尚未交付**的 initial 快照可删;
562
- // 已交付/续页快照保留至 TTL,同 cursor 可重试;
563
- // - graph-stale / ref 变化 / 鉴权失败等确定性失效:立即删除。
564
- // 该策略覆盖 pre/post verify、provider.graph、装饰 readRefRecords 所有阶段。
565
- const disposeSnapshot = () => {
566
- if (snapshots.delete(snapshot.id)) onSnapshotDisposed?.(snapshot.id);
567
- };
568
- const disposeOnGraphFailure = (error) => {
569
- if (error?.code === "graph-timeout") {
570
- if (snapshotCreatedNow) disposeSnapshot();
571
- return;
572
- }
573
- disposeSnapshot();
574
- };
575
- try {
576
- await verifyGraphTips(authorized.root, snapshot.tips, deadline);
577
- } catch (error) {
578
- disposeOnGraphFailure(error);
579
- throw error;
580
- }
581
- let rawCommits;
582
- try {
583
- rawCommits = await graphRace(
584
- () => provider.graph(authorized.root, {
585
- refs: snapshot.tips.map((tip) => tip.tipOid),
586
- offset,
587
- limit: pageSize,
588
- timeoutMs: Math.max(1, deadline - Date.now()),
589
- }),
590
- deadline,
591
- );
592
- // provider 自报 timedOut(不得把半页当完整页返回)。
593
- if (rawCommits && rawCommits.timedOut === true) throw graphTimeout();
594
- } catch (error) {
595
- // 超时是明确失败(504 graph-timeout),不做 stale 转换(否则面板看不到)。
596
- // 已交付续页快照保留;非确定性 provider 错误保留快照供重试(verify 失败才 stale)。
597
- if (error?.code === "graph-timeout") {
598
- disposeOnGraphFailure(error);
599
- throw error;
600
- }
601
- try {
602
- await verifyGraphTips(authorized.root, snapshot.tips, deadline);
603
- } catch (verifyError) {
604
- // 混合错误:provider.graph 先抛临时 503,随后为判 stale 的二次
605
- // verify 因 deadline 挂起 —— 必须原样透传 504,并按统一策略
606
- // (已交付保留 / 未交付新建清理),不能误判成 ref 真变化的 stale。
607
- if (verifyError?.code === "graph-timeout") {
608
- disposeOnGraphFailure(verifyError);
609
- throw verifyError;
610
- }
611
- disposeSnapshot();
612
- throw stale();
613
- }
614
- throw error;
615
- }
616
- try {
617
- await verifyGraphTips(authorized.root, snapshot.tips, deadline);
618
- } catch (error) {
619
- disposeOnGraphFailure(error);
620
- throw error;
621
- }
622
- let records;
623
- try {
624
- records = await readRefRecordsWithin(authorized.root, deadline);
625
- } catch (error) {
626
- // 装饰(refs 记录)阶段超时同样按统一策略处理:已交付快照可重试。
627
- disposeOnGraphFailure(error);
628
- throw error;
629
- }
630
- const commits = (Array.isArray(rawCommits) ? rawCommits : []).map((row) => {
631
- const oid = String(row.oid ?? "");
632
- const legacy = Array.isArray(row.refs) ? row.refs.map(String) : [];
633
- // Graph rows only guarantee name-level refs plus `annotated`; full
634
- // tag metadata is reserved for commit details.
635
- const refDetails = mergeRefDetails(
636
- records ? refDetailsFromRecords(records, oid) : emptyRefDetails(),
637
- refDetailsFromLegacyRefs(legacy, oid),
638
- );
639
- return {
640
- oid, parents: Array.isArray(row.parents) ? row.parents.map(String) : [],
641
- author: String(row.author ?? ""), timestamp: Number(row.timestamp) || 0, subject: String(row.subject ?? ""),
642
- refs: legacy, refsDetail: refDetails.refsDetail, tagsDetail: refDetails.tagsDetail,
643
- };
644
- });
645
- let nextCursor = null;
646
- if (commits.length === pageSize) {
647
- nextCursor = randomUUID();
648
- snapshot.cursors.set(nextCursor, offset + commits.length);
649
- keepBounded(snapshot.cursors, 128);
650
- }
651
- return { repositoryId, snapshotId: snapshot.id, tips: snapshot.tips, commits, nextCursor };
652
- },
653
- async files(sessionId, repositoryId, { q, limit } = {}) {
654
- const authorized = await binding(sessionId, repositoryId);
655
- const pageSize = Math.max(1, Math.min(MAX_TRACKED_FILES, Number(limit) || MAX_TRACKED_FILES));
656
- const query = typeof q === "string" ? q : "";
657
- const raw = await fileReader().files(authorized.root, { q: query, limit: pageSize });
658
- const files = [...new Set((Array.isArray(raw?.files) ? raw.files : [])
659
- .map((path) => String(path ?? ""))
660
- .filter((path) => safeFilePath(path)))].sort(compareText).slice(0, pageSize);
661
- return { repositoryId, files, truncated: raw?.truncated === true };
662
- },
663
- async fileHistory(sessionId, repositoryId, { path, cursor, limit } = {}) {
664
- const authorized = await binding(sessionId, repositoryId);
665
- const pageSize = Math.max(1, Math.min(FILE_HISTORY_MAX_LIMIT, Number(limit) || FILE_HISTORY_DEFAULT_LIMIT));
666
- prune();
667
- const normalized = await normalizeHistoryPath(authorized.root, path);
668
- if (normalized === null) {
669
- return { repositoryId, path: String(path ?? ""), entries: [], nextCursor: null, truncated: false, reason: "path-invalid" };
670
- }
671
- let snapshot = null, offset = 0;
672
- if (cursor !== undefined && cursor !== null && cursor !== "") {
673
- const saved = historyCursors.get(String(cursor));
674
- if (!saved || saved.expiresAt <= now() || saved.sessionId !== sessionId || saved.repositoryId !== repositoryId || saved.path !== normalized) throw failure("invalid-history-cursor", 400);
675
- snapshot = historySnapshots.get(saved.snapshotId);
676
- if (!snapshot || snapshot.expiresAt <= now() || snapshot.root !== authorized.root) throw failure("invalid-history-cursor", 400);
677
- offset = saved.offset;
678
- }
679
- if (!snapshot) {
680
- const raw = await fileReader().fileHistory(authorized.root, normalized, {
681
- maxCommits: FILE_HISTORY_MAX_COMMITS,
682
- timeoutMs: FILE_HISTORY_TIMEOUT_MS,
683
- });
684
- const reason = FILE_HISTORY_REASONS.has(raw?.reason) ? raw.reason : null;
685
- const entries = (Array.isArray(raw?.entries) ? raw.entries : []).map((entry) => ({
686
- oid: String(entry?.oid ?? ""),
687
- shortOid: String(entry?.shortOid ?? String(entry?.oid ?? "").slice(0, 7)),
688
- author: String(entry?.author ?? ""),
689
- timestamp: Number(entry?.timestamp) || 0,
690
- subject: String(entry?.subject ?? ""),
691
- status: historyStatus(entry?.status),
692
- })).filter((entry) => validOid(entry.oid));
693
- if (reason && entries.length === 0) {
694
- return { repositoryId, path: normalized, entries: [], nextCursor: null, truncated: false, reason };
695
- }
696
- snapshot = {
697
- id: randomUUID(), sessionId, repositoryId, root: authorized.root, path: normalized,
698
- entries, truncated: raw?.truncated === true, expiresAt: now() + snapshotTtlMs,
699
- };
700
- historySnapshots.set(snapshot.id, snapshot);
701
- keepBounded(historySnapshots, MAX_FILE_HISTORY_SNAPSHOTS);
702
- }
703
- const items = snapshot.entries.slice(offset, offset + pageSize);
704
- let nextCursor = null;
705
- if (offset + items.length < snapshot.entries.length) {
706
- nextCursor = randomUUID();
707
- historyCursors.set(nextCursor, {
708
- sessionId, repositoryId, path: normalized, snapshotId: snapshot.id,
709
- offset: offset + items.length, expiresAt: now() + snapshotTtlMs,
710
- });
711
- keepBounded(historyCursors, 1024);
712
- }
713
- return { repositoryId, path: normalized, entries: items, nextCursor, truncated: snapshot.truncated };
714
- },
715
- _pollOnce() {
716
- if (pollInFlight) return pollInFlight;
717
- pollInFlight = (async () => {
718
- for (const [repositoryId, authorized] of bindings) {
719
- try {
720
- await binding(authorized.sessionId, repositoryId);
721
- if (typeof provider.refSignature === "function") {
722
- const signature = await provider.refSignature(authorized.root);
723
- const previous = refSignatures.get(repositoryId); refSignatures.set(repositoryId, signature);
724
- if (previous !== undefined && previous !== signature) onChanged?.(repositoryId, "refs");
725
- }
726
- } catch { bindings.delete(repositoryId); refSignatures.delete(repositoryId); }
727
- }
728
- })().finally(() => { pollInFlight = null; });
729
- return pollInFlight;
730
- },
731
- start() {
732
- if (unsubscribeProvider || pollTimer) return;
733
- if (typeof provider.subscribeChanges === "function") {
734
- try { unsubscribeProvider = provider.subscribeChanges((change) => {
735
- void (async () => {
736
- for (const [repositoryId, authorized] of bindings) {
737
- if (change?.root !== authorized.root) continue;
738
- try {
739
- await binding(authorized.sessionId, repositoryId);
740
- if (typeof provider.refSignature === "function") {
741
- const signature = await provider.refSignature(authorized.root);
742
- const previous = refSignatures.get(repositoryId);
743
- refSignatures.set(repositoryId, signature);
744
- if (previous === signature) continue;
745
- }
746
- onChanged?.(repositoryId);
747
- } catch { bindings.delete(repositoryId); refSignatures.delete(repositoryId); }
748
- }
749
- })();
750
- }); } catch { unsubscribeProvider = null; }
751
- if (typeof unsubscribeProvider !== "function") unsubscribeProvider = null;
752
- }
753
- // Ref polling is server-side; worktree polling stays scoped to an open mobile page.
754
- pollTimer = setInterval(() => { void service._pollOnce(); }, pollIntervalMs);
755
- pollTimer.unref?.();
756
- },
757
- stop() {
758
- if (pollTimer) clearInterval(pollTimer);
759
- pollTimer = null;
760
- try { unsubscribeProvider?.(); } catch { /* optional provider teardown must not break host shutdown */ }
761
- unsubscribeProvider = null;
762
- return pollInFlight ?? Promise.resolve();
763
- },
764
- };
765
- return service;
766
- }