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