@marktrue/dsh-mobile-remote 3.3.0-rc.1 → 3.3.1-alpha.1-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 (364) hide show
  1. package/DSH-Remote-v3.3.1.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 -2025
  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 -1601
  13. package/docs/04-security.md +0 -119
  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 -199
  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 -14240
  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/sse-connections.js +0 -172
  61. package/lib/tool-process.js +0 -20
  62. package/lib/update-fetch.js +0 -24
  63. package/lib/update-lock-arbiter.js +0 -210
  64. package/lib/update-supervisor.js +0 -379
  65. package/node_modules/ansi-regex/index.d.ts +0 -37
  66. package/node_modules/ansi-regex/index.js +0 -10
  67. package/node_modules/ansi-regex/license +0 -9
  68. package/node_modules/ansi-regex/package.json +0 -55
  69. package/node_modules/ansi-regex/readme.md +0 -78
  70. package/node_modules/ansi-styles/index.d.ts +0 -345
  71. package/node_modules/ansi-styles/index.js +0 -163
  72. package/node_modules/ansi-styles/license +0 -9
  73. package/node_modules/ansi-styles/package.json +0 -56
  74. package/node_modules/ansi-styles/readme.md +0 -152
  75. package/node_modules/camelcase/index.d.ts +0 -63
  76. package/node_modules/camelcase/index.js +0 -76
  77. package/node_modules/camelcase/license +0 -9
  78. package/node_modules/camelcase/package.json +0 -43
  79. package/node_modules/camelcase/readme.md +0 -99
  80. package/node_modules/cliui/CHANGELOG.md +0 -76
  81. package/node_modules/cliui/LICENSE.txt +0 -14
  82. package/node_modules/cliui/README.md +0 -115
  83. package/node_modules/cliui/index.js +0 -354
  84. package/node_modules/cliui/package.json +0 -65
  85. package/node_modules/color-convert/CHANGELOG.md +0 -54
  86. package/node_modules/color-convert/LICENSE +0 -21
  87. package/node_modules/color-convert/README.md +0 -68
  88. package/node_modules/color-convert/conversions.js +0 -839
  89. package/node_modules/color-convert/index.js +0 -81
  90. package/node_modules/color-convert/package.json +0 -48
  91. package/node_modules/color-convert/route.js +0 -97
  92. package/node_modules/color-name/LICENSE +0 -8
  93. package/node_modules/color-name/README.md +0 -11
  94. package/node_modules/color-name/index.js +0 -152
  95. package/node_modules/color-name/package.json +0 -28
  96. package/node_modules/decamelize/index.js +0 -13
  97. package/node_modules/decamelize/license +0 -21
  98. package/node_modules/decamelize/package.json +0 -38
  99. package/node_modules/decamelize/readme.md +0 -48
  100. package/node_modules/dijkstrajs/.travis.yml +0 -4
  101. package/node_modules/dijkstrajs/CONTRIBUTING.md +0 -8
  102. package/node_modules/dijkstrajs/LICENSE.md +0 -19
  103. package/node_modules/dijkstrajs/README.md +0 -18
  104. package/node_modules/dijkstrajs/dijkstra.js +0 -165
  105. package/node_modules/dijkstrajs/package.json +0 -60
  106. package/node_modules/dijkstrajs/test/dijkstra.test.js +0 -96
  107. package/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
  108. package/node_modules/emoji-regex/README.md +0 -73
  109. package/node_modules/emoji-regex/es2015/index.js +0 -6
  110. package/node_modules/emoji-regex/es2015/text.js +0 -6
  111. package/node_modules/emoji-regex/index.d.ts +0 -23
  112. package/node_modules/emoji-regex/index.js +0 -6
  113. package/node_modules/emoji-regex/package.json +0 -50
  114. package/node_modules/emoji-regex/text.js +0 -6
  115. package/node_modules/find-up/index.d.ts +0 -137
  116. package/node_modules/find-up/index.js +0 -89
  117. package/node_modules/find-up/license +0 -9
  118. package/node_modules/find-up/package.json +0 -53
  119. package/node_modules/find-up/readme.md +0 -156
  120. package/node_modules/get-caller-file/LICENSE.md +0 -6
  121. package/node_modules/get-caller-file/README.md +0 -41
  122. package/node_modules/get-caller-file/index.d.ts +0 -2
  123. package/node_modules/get-caller-file/index.js +0 -22
  124. package/node_modules/get-caller-file/index.js.map +0 -1
  125. package/node_modules/get-caller-file/package.json +0 -42
  126. package/node_modules/is-fullwidth-code-point/index.d.ts +0 -17
  127. package/node_modules/is-fullwidth-code-point/index.js +0 -50
  128. package/node_modules/is-fullwidth-code-point/license +0 -9
  129. package/node_modules/is-fullwidth-code-point/package.json +0 -42
  130. package/node_modules/is-fullwidth-code-point/readme.md +0 -39
  131. package/node_modules/locate-path/index.d.ts +0 -83
  132. package/node_modules/locate-path/index.js +0 -65
  133. package/node_modules/locate-path/license +0 -9
  134. package/node_modules/locate-path/package.json +0 -45
  135. package/node_modules/locate-path/readme.md +0 -122
  136. package/node_modules/p-limit/index.d.ts +0 -38
  137. package/node_modules/p-limit/index.js +0 -57
  138. package/node_modules/p-limit/license +0 -9
  139. package/node_modules/p-limit/package.json +0 -52
  140. package/node_modules/p-limit/readme.md +0 -101
  141. package/node_modules/p-locate/index.d.ts +0 -64
  142. package/node_modules/p-locate/index.js +0 -52
  143. package/node_modules/p-locate/license +0 -9
  144. package/node_modules/p-locate/package.json +0 -53
  145. package/node_modules/p-locate/readme.md +0 -90
  146. package/node_modules/p-try/index.d.ts +0 -39
  147. package/node_modules/p-try/index.js +0 -9
  148. package/node_modules/p-try/license +0 -9
  149. package/node_modules/p-try/package.json +0 -42
  150. package/node_modules/p-try/readme.md +0 -58
  151. package/node_modules/path-exists/index.d.ts +0 -28
  152. package/node_modules/path-exists/index.js +0 -23
  153. package/node_modules/path-exists/license +0 -9
  154. package/node_modules/path-exists/package.json +0 -39
  155. package/node_modules/path-exists/readme.md +0 -52
  156. package/node_modules/pngjs/.eslintignore +0 -2
  157. package/node_modules/pngjs/.eslintrc.json +0 -19
  158. package/node_modules/pngjs/.prettierignore +0 -3
  159. package/node_modules/pngjs/LICENSE +0 -20
  160. package/node_modules/pngjs/README.md +0 -429
  161. package/node_modules/pngjs/browser.js +0 -16096
  162. package/node_modules/pngjs/coverage/lcov-report/base.css +0 -354
  163. package/node_modules/pngjs/coverage/lcov-report/bitmapper.js.html +0 -881
  164. package/node_modules/pngjs/coverage/lcov-report/bitpacker.js.html +0 -554
  165. package/node_modules/pngjs/coverage/lcov-report/block-navigation.js +0 -77
  166. package/node_modules/pngjs/coverage/lcov-report/chunkstream.js.html +0 -647
  167. package/node_modules/pngjs/coverage/lcov-report/constants.js.html +0 -176
  168. package/node_modules/pngjs/coverage/lcov-report/crc.js.html +0 -200
  169. package/node_modules/pngjs/coverage/lcov-report/favicon.png +0 -0
  170. package/node_modules/pngjs/coverage/lcov-report/filter-pack.js.html +0 -593
  171. package/node_modules/pngjs/coverage/lcov-report/filter-parse-async.js.html +0 -152
  172. package/node_modules/pngjs/coverage/lcov-report/filter-parse-sync.js.html +0 -143
  173. package/node_modules/pngjs/coverage/lcov-report/filter-parse.js.html +0 -611
  174. package/node_modules/pngjs/coverage/lcov-report/format-normaliser.js.html +0 -359
  175. package/node_modules/pngjs/coverage/lcov-report/index.html +0 -426
  176. package/node_modules/pngjs/coverage/lcov-report/interlace.js.html +0 -365
  177. package/node_modules/pngjs/coverage/lcov-report/packer-async.js.html +0 -230
  178. package/node_modules/pngjs/coverage/lcov-report/packer-sync.js.html +0 -248
  179. package/node_modules/pngjs/coverage/lcov-report/packer.js.html +0 -467
  180. package/node_modules/pngjs/coverage/lcov-report/paeth-predictor.js.html +0 -128
  181. package/node_modules/pngjs/coverage/lcov-report/parser-async.js.html +0 -575
  182. package/node_modules/pngjs/coverage/lcov-report/parser-sync.js.html +0 -404
  183. package/node_modules/pngjs/coverage/lcov-report/parser.js.html +0 -950
  184. package/node_modules/pngjs/coverage/lcov-report/png-sync.js.html +0 -116
  185. package/node_modules/pngjs/coverage/lcov-report/png.js.html +0 -662
  186. package/node_modules/pngjs/coverage/lcov-report/prettify.css +0 -101
  187. package/node_modules/pngjs/coverage/lcov-report/prettify.js +0 -1007
  188. package/node_modules/pngjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  189. package/node_modules/pngjs/coverage/lcov-report/sorter.js +0 -169
  190. package/node_modules/pngjs/coverage/lcov-report/sync-inflate.js.html +0 -584
  191. package/node_modules/pngjs/coverage/lcov-report/sync-reader.js.html +0 -215
  192. package/node_modules/pngjs/coverage/lcov.info +0 -2177
  193. package/node_modules/pngjs/lib/bitmapper.js +0 -267
  194. package/node_modules/pngjs/lib/bitpacker.js +0 -158
  195. package/node_modules/pngjs/lib/chunkstream.js +0 -189
  196. package/node_modules/pngjs/lib/constants.js +0 -32
  197. package/node_modules/pngjs/lib/crc.js +0 -40
  198. package/node_modules/pngjs/lib/filter-pack.js +0 -171
  199. package/node_modules/pngjs/lib/filter-parse-async.js +0 -24
  200. package/node_modules/pngjs/lib/filter-parse-sync.js +0 -21
  201. package/node_modules/pngjs/lib/filter-parse.js +0 -177
  202. package/node_modules/pngjs/lib/format-normaliser.js +0 -93
  203. package/node_modules/pngjs/lib/interlace.js +0 -95
  204. package/node_modules/pngjs/lib/packer-async.js +0 -50
  205. package/node_modules/pngjs/lib/packer-sync.js +0 -56
  206. package/node_modules/pngjs/lib/packer.js +0 -129
  207. package/node_modules/pngjs/lib/paeth-predictor.js +0 -16
  208. package/node_modules/pngjs/lib/parser-async.js +0 -165
  209. package/node_modules/pngjs/lib/parser-sync.js +0 -108
  210. package/node_modules/pngjs/lib/parser.js +0 -290
  211. package/node_modules/pngjs/lib/png-sync.js +0 -12
  212. package/node_modules/pngjs/lib/png.js +0 -194
  213. package/node_modules/pngjs/lib/sync-inflate.js +0 -168
  214. package/node_modules/pngjs/lib/sync-reader.js +0 -45
  215. package/node_modules/pngjs/package.json +0 -73
  216. package/node_modules/qrcode/README.md +0 -770
  217. package/node_modules/qrcode/bin/qrcode +0 -159
  218. package/node_modules/qrcode/helper/to-sjis-browser.js +0 -2
  219. package/node_modules/qrcode/helper/to-sjis.js +0 -105
  220. package/node_modules/qrcode/lib/browser.js +0 -76
  221. package/node_modules/qrcode/lib/can-promise.js +0 -7
  222. package/node_modules/qrcode/lib/core/alignment-pattern.js +0 -83
  223. package/node_modules/qrcode/lib/core/alphanumeric-data.js +0 -59
  224. package/node_modules/qrcode/lib/core/bit-buffer.js +0 -37
  225. package/node_modules/qrcode/lib/core/bit-matrix.js +0 -65
  226. package/node_modules/qrcode/lib/core/byte-data.js +0 -30
  227. package/node_modules/qrcode/lib/core/error-correction-code.js +0 -135
  228. package/node_modules/qrcode/lib/core/error-correction-level.js +0 -50
  229. package/node_modules/qrcode/lib/core/finder-pattern.js +0 -22
  230. package/node_modules/qrcode/lib/core/format-info.js +0 -29
  231. package/node_modules/qrcode/lib/core/galois-field.js +0 -69
  232. package/node_modules/qrcode/lib/core/kanji-data.js +0 -54
  233. package/node_modules/qrcode/lib/core/mask-pattern.js +0 -234
  234. package/node_modules/qrcode/lib/core/mode.js +0 -167
  235. package/node_modules/qrcode/lib/core/numeric-data.js +0 -43
  236. package/node_modules/qrcode/lib/core/polynomial.js +0 -62
  237. package/node_modules/qrcode/lib/core/qrcode.js +0 -495
  238. package/node_modules/qrcode/lib/core/reed-solomon-encoder.js +0 -56
  239. package/node_modules/qrcode/lib/core/regex.js +0 -31
  240. package/node_modules/qrcode/lib/core/segments.js +0 -330
  241. package/node_modules/qrcode/lib/core/utils.js +0 -63
  242. package/node_modules/qrcode/lib/core/version-check.js +0 -9
  243. package/node_modules/qrcode/lib/core/version.js +0 -163
  244. package/node_modules/qrcode/lib/index.js +0 -12
  245. package/node_modules/qrcode/lib/renderer/canvas.js +0 -63
  246. package/node_modules/qrcode/lib/renderer/png.js +0 -78
  247. package/node_modules/qrcode/lib/renderer/svg-tag.js +0 -81
  248. package/node_modules/qrcode/lib/renderer/svg.js +0 -19
  249. package/node_modules/qrcode/lib/renderer/terminal/terminal-small.js +0 -85
  250. package/node_modules/qrcode/lib/renderer/terminal/terminal.js +0 -49
  251. package/node_modules/qrcode/lib/renderer/terminal.js +0 -9
  252. package/node_modules/qrcode/lib/renderer/utf8.js +0 -71
  253. package/node_modules/qrcode/lib/renderer/utils.js +0 -99
  254. package/node_modules/qrcode/lib/server.js +0 -138
  255. package/node_modules/qrcode/license +0 -10
  256. package/node_modules/qrcode/package.json +0 -77
  257. package/node_modules/require-directory/.jshintrc +0 -67
  258. package/node_modules/require-directory/.npmignore +0 -1
  259. package/node_modules/require-directory/.travis.yml +0 -3
  260. package/node_modules/require-directory/LICENSE +0 -22
  261. package/node_modules/require-directory/README.markdown +0 -184
  262. package/node_modules/require-directory/index.js +0 -86
  263. package/node_modules/require-directory/package.json +0 -40
  264. package/node_modules/require-main-filename/CHANGELOG.md +0 -26
  265. package/node_modules/require-main-filename/LICENSE.txt +0 -14
  266. package/node_modules/require-main-filename/README.md +0 -26
  267. package/node_modules/require-main-filename/index.js +0 -18
  268. package/node_modules/require-main-filename/package.json +0 -35
  269. package/node_modules/set-blocking/CHANGELOG.md +0 -26
  270. package/node_modules/set-blocking/LICENSE.txt +0 -14
  271. package/node_modules/set-blocking/README.md +0 -31
  272. package/node_modules/set-blocking/index.js +0 -7
  273. package/node_modules/set-blocking/package.json +0 -42
  274. package/node_modules/string-width/index.d.ts +0 -29
  275. package/node_modules/string-width/index.js +0 -47
  276. package/node_modules/string-width/license +0 -9
  277. package/node_modules/string-width/package.json +0 -56
  278. package/node_modules/string-width/readme.md +0 -50
  279. package/node_modules/strip-ansi/index.d.ts +0 -17
  280. package/node_modules/strip-ansi/index.js +0 -4
  281. package/node_modules/strip-ansi/license +0 -9
  282. package/node_modules/strip-ansi/package.json +0 -54
  283. package/node_modules/strip-ansi/readme.md +0 -46
  284. package/node_modules/which-module/LICENSE +0 -13
  285. package/node_modules/which-module/README.md +0 -58
  286. package/node_modules/which-module/index.js +0 -9
  287. package/node_modules/which-module/package.json +0 -41
  288. package/node_modules/wrap-ansi/index.js +0 -186
  289. package/node_modules/wrap-ansi/license +0 -9
  290. package/node_modules/wrap-ansi/package.json +0 -61
  291. package/node_modules/wrap-ansi/readme.md +0 -97
  292. package/node_modules/y18n/CHANGELOG.md +0 -35
  293. package/node_modules/y18n/LICENSE +0 -13
  294. package/node_modules/y18n/README.md +0 -109
  295. package/node_modules/y18n/index.js +0 -188
  296. package/node_modules/y18n/package.json +0 -39
  297. package/node_modules/yargs/CHANGELOG.md +0 -420
  298. package/node_modules/yargs/LICENSE +0 -21
  299. package/node_modules/yargs/README.md +0 -140
  300. package/node_modules/yargs/build/lib/apply-extends.d.ts +0 -2
  301. package/node_modules/yargs/build/lib/apply-extends.js +0 -65
  302. package/node_modules/yargs/build/lib/argsert.d.ts +0 -2
  303. package/node_modules/yargs/build/lib/argsert.js +0 -65
  304. package/node_modules/yargs/build/lib/command.d.ts +0 -64
  305. package/node_modules/yargs/build/lib/command.js +0 -416
  306. package/node_modules/yargs/build/lib/common-types.d.ts +0 -36
  307. package/node_modules/yargs/build/lib/common-types.js +0 -25
  308. package/node_modules/yargs/build/lib/completion-templates.d.ts +0 -2
  309. package/node_modules/yargs/build/lib/completion-templates.js +0 -50
  310. package/node_modules/yargs/build/lib/completion.d.ts +0 -21
  311. package/node_modules/yargs/build/lib/completion.js +0 -135
  312. package/node_modules/yargs/build/lib/is-promise.d.ts +0 -1
  313. package/node_modules/yargs/build/lib/is-promise.js +0 -9
  314. package/node_modules/yargs/build/lib/levenshtein.d.ts +0 -1
  315. package/node_modules/yargs/build/lib/levenshtein.js +0 -58
  316. package/node_modules/yargs/build/lib/middleware.d.ts +0 -10
  317. package/node_modules/yargs/build/lib/middleware.js +0 -57
  318. package/node_modules/yargs/build/lib/obj-filter.d.ts +0 -1
  319. package/node_modules/yargs/build/lib/obj-filter.js +0 -14
  320. package/node_modules/yargs/build/lib/parse-command.d.ts +0 -11
  321. package/node_modules/yargs/build/lib/parse-command.js +0 -36
  322. package/node_modules/yargs/build/lib/process-argv.d.ts +0 -2
  323. package/node_modules/yargs/build/lib/process-argv.js +0 -31
  324. package/node_modules/yargs/build/lib/usage.d.ts +0 -49
  325. package/node_modules/yargs/build/lib/usage.js +0 -540
  326. package/node_modules/yargs/build/lib/validation.d.ts +0 -34
  327. package/node_modules/yargs/build/lib/validation.js +0 -330
  328. package/node_modules/yargs/build/lib/yargs.d.ts +0 -274
  329. package/node_modules/yargs/build/lib/yargs.js +0 -1190
  330. package/node_modules/yargs/build/lib/yerror.d.ts +0 -4
  331. package/node_modules/yargs/build/lib/yerror.js +0 -11
  332. package/node_modules/yargs/index.js +0 -40
  333. package/node_modules/yargs/locales/be.json +0 -46
  334. package/node_modules/yargs/locales/de.json +0 -46
  335. package/node_modules/yargs/locales/en.json +0 -51
  336. package/node_modules/yargs/locales/es.json +0 -46
  337. package/node_modules/yargs/locales/fi.json +0 -49
  338. package/node_modules/yargs/locales/fr.json +0 -53
  339. package/node_modules/yargs/locales/hi.json +0 -49
  340. package/node_modules/yargs/locales/hu.json +0 -46
  341. package/node_modules/yargs/locales/id.json +0 -50
  342. package/node_modules/yargs/locales/it.json +0 -46
  343. package/node_modules/yargs/locales/ja.json +0 -51
  344. package/node_modules/yargs/locales/ko.json +0 -49
  345. package/node_modules/yargs/locales/nb.json +0 -44
  346. package/node_modules/yargs/locales/nl.json +0 -49
  347. package/node_modules/yargs/locales/nn.json +0 -44
  348. package/node_modules/yargs/locales/pirate.json +0 -13
  349. package/node_modules/yargs/locales/pl.json +0 -49
  350. package/node_modules/yargs/locales/pt.json +0 -45
  351. package/node_modules/yargs/locales/pt_BR.json +0 -48
  352. package/node_modules/yargs/locales/ru.json +0 -46
  353. package/node_modules/yargs/locales/th.json +0 -46
  354. package/node_modules/yargs/locales/tr.json +0 -48
  355. package/node_modules/yargs/locales/zh_CN.json +0 -48
  356. package/node_modules/yargs/locales/zh_TW.json +0 -47
  357. package/node_modules/yargs/package.json +0 -92
  358. package/node_modules/yargs/yargs.js +0 -14
  359. package/node_modules/yargs-parser/CHANGELOG.md +0 -601
  360. package/node_modules/yargs-parser/LICENSE.txt +0 -14
  361. package/node_modules/yargs-parser/README.md +0 -449
  362. package/node_modules/yargs-parser/index.js +0 -1032
  363. package/node_modules/yargs-parser/lib/tokenize-arg-string.js +0 -40
  364. package/node_modules/yargs-parser/package.json +0 -46
@@ -1,210 +0,0 @@
1
- // Runs only under an OS flock on a persistent inode. No lock-directory unlink/rename races.
2
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, rmSync, symlinkSync, realpathSync } from 'node:fs';
3
- import { dirname, isAbsolute, join, relative, sep } from 'node:path';
4
- import { randomUUID } from 'node:crypto';
5
-
6
- function read(file) { try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return null; } }
7
- function atomic(file, value) {
8
- mkdirSync(dirname(file), { recursive: true });
9
- const tmp = `${file}.${randomUUID()}.tmp`;
10
- try { writeFileSync(tmp, JSON.stringify(value) + '\n', { mode: 0o600 }); renameSync(tmp, file); }
11
- finally { if (existsSync(tmp)) rmSync(tmp); }
12
- }
13
- function identity(pid) {
14
- try { const text = readFileSync(`/proc/${pid}/stat`, 'utf8'); return { pid, start: text.slice(text.lastIndexOf(')') + 2).split(' ')[19] }; }
15
- catch { return { pid, start: null }; }
16
- }
17
- function killAlive(pid) {
18
- try { process.kill(pid, 0); return true; } catch(e) { return e.code === 'EPERM'; }
19
- }
20
- function alive(person) {
21
- if (!person?.pid || !Number.isInteger(person.pid)) return false;
22
- const current = identity(person.pid).start;
23
- // 无 /proc 平台:回退 kill(pid,0) 保守判活,与 processIdentityAlive 口径一致。
24
- if (current === null) return killAlive(person.pid);
25
- if (!person.start) return true;
26
- return String(person.start) === String(current);
27
- }
28
- function holderAlive(holder) {
29
- if (!holder) return false;
30
- const candidates = [holder.worker, holder.supervisor];
31
- // 旧 holder 兼容:只有顶层 pid/starttime。
32
- if (Number.isInteger(holder.pid)) candidates.push({ pid: holder.pid, start: holder.start });
33
- return candidates.some(alive);
34
- }
35
- function owns(holder, lease) { return !!lease?.generation && holder?.generation === lease.generation && holder.opId === lease.opId; }
36
- function fence(holder, lease) { if (!owns(holder, lease)) throw new Error('lease-lost'); }
37
- function terminal(phase) { return ['settled', 'rolled-back', 'failed'].includes(phase); }
38
-
39
- function execute(input) {
40
- const { lockPath, operation, lease, stateFile } = input;
41
- const holderFile = join(lockPath, 'holder.json');
42
- let holder = read(holderFile);
43
- const available = !holderAlive(holder);
44
- if (operation === 'acquire') {
45
- if (holder && owns(holder, lease)) return { ok: true, lease, holder, reentrant: true };
46
- // Missing publication is not evidence of owner death. Legacy half-locks require manual repair.
47
- if (existsSync(lockPath) && !existsSync(holderFile)) return { ok: false, error: 'lock-unpublished' };
48
- if (!available) return { ok: false, error: 'update-busy', holder };
49
- if (input.stateFile) {
50
- const tx = read(input.stateFile);
51
- // 安装/待生效/回滚未完成时,**任何**新操作都不得开始——即使锁已被误释放(holder 为空)。
52
- if (tx && ['installing','restart-pending','rolling-back'].includes(tx.phase) &&
53
- (!lease || tx.lease?.generation !== lease.generation)) {
54
- return { ok: false, error: 'recovery-required', holder, transaction: tx };
55
- }
56
- }
57
- holder = { opId: input.opId, generation: randomUUID(), worker: identity(input.pid), pid: input.pid, at: input.now };
58
- mkdirSync(lockPath, { recursive: true }); atomic(holderFile, holder);
59
- return { ok: true, holder, lease: { opId: holder.opId, generation: holder.generation } };
60
- }
61
- if (operation === 'release') {
62
- if (!owns(holder, lease)) return { ok: false, error: 'lease-lost' };
63
- const tx = input.stateFile ? read(input.stateFile) : null;
64
- if (tx && tx.lease?.generation === lease.generation && ['installing','restart-pending','rolling-back'].includes(tx.phase)) {
65
- return { ok: false, error: 'recovery-required' };
66
- }
67
- atomic(holderFile, null); return { ok: true };
68
- }
69
- if (operation === 'handover') {
70
- fence(holder, lease);
71
- holder = { ...holder, supervisor: identity(input.toPid), pid: input.toPid };
72
- atomic(holderFile, holder); return { ok: true, holder };
73
- }
74
- if (operation === 'assert') { fence(holder, lease); return { ok: true, holder }; }
75
- if (operation === 'state-write') {
76
- fence(holder, lease);
77
- if (input.tx.opId !== lease.opId) throw new Error('operation-mismatch');
78
- const old = read(stateFile);
79
- if (old?.lease && old.lease.generation !== lease.generation && !terminal(old.phase)) throw new Error('transaction-generation-mismatch');
80
- // 阶段 CAS:旧 worker 不能把"已被别人推进的阶段"改回去(如 failed → installing)。
81
- if (old && old.opId === input.tx.opId) {
82
- if (input.expectedPhases && !input.expectedPhases.includes(old.phase)) throw new Error('phase-cas-failed');
83
- if (terminal(old.phase) && !terminal(input.tx.phase)) throw new Error('terminal-regression');
84
- }
85
- const next = { ...input.tx, lease, id: lease.generation, updatedAt: new Date().toISOString() };
86
- atomic(stateFile, next);
87
- if (input.currentFile && input.currentFile !== stateFile) atomic(input.currentFile, next);
88
- return { ok: true, transaction: next };
89
- }
90
- if (operation === 'switch-profile') {
91
- fence(holder, lease);
92
- const file = join(input.profileDir, 'package.json'), doc = read(file);
93
- const key = input.key || 'dsh-mobile-remote';
94
- const previous = doc?.dependencies?.[key];
95
- if (typeof previous !== 'string') throw new Error('profile-dependency-missing');
96
- doc.dependencies[key] = input.specifier; atomic(file, doc);
97
- return { ok: true, previous, next: input.specifier };
98
- }
99
- if (operation === 'restore-profile') {
100
- fence(holder, lease);
101
- const file = join(input.profileDir, 'package.json');
102
- const doc = input.snapshot?.packageJson ? JSON.parse(input.snapshot.packageJson) : read(file);
103
- if (!doc?.dependencies) throw new Error('profile-dependencies-missing');
104
- const key = input.key || 'dsh-mobile-remote';
105
- if (input.preserveSpecifier === true) {
106
- if (typeof doc.dependencies[key] !== 'string' || doc.dependencies[key] === '') throw new Error('profile-dependency-missing');
107
- } else {
108
- doc.dependencies[key] = `file:${input.snapshotDir}`;
109
- }
110
- atomic(file, doc);
111
- const lockfile = join(input.profileDir, 'pnpm-lock.yaml');
112
- if (typeof input.snapshot?.pnpmLock === 'string') writeFileSync(lockfile, input.snapshot.pnpmLock, { mode: 0o600 });
113
- else if (input.snapshot?.pnpmLock === null && existsSync(lockfile)) rmSync(lockfile);
114
- return { ok: true };
115
- }
116
- if (operation === 'publish-snapshot-link') {
117
- fence(holder, lease);
118
- const modules = join(input.profileDir, 'node_modules'); mkdirSync(modules, { recursive: true });
119
- // Never traverse an unexpected node_modules symlink into another profile.
120
- if (realpathSync(modules) !== join(realpathSync(input.profileDir), 'node_modules')) throw new Error('profile-modules-outside-root');
121
- const key = input.key || 'dsh-mobile-remote';
122
- if (!/^(?:@[A-Za-z0-9._-]+\/)?[A-Za-z0-9._-]+$/.test(key)) throw new Error('dependency-key-invalid');
123
- const segments = key.split('/');
124
- const parent = join(modules, ...segments.slice(0, -1));
125
- mkdirSync(parent, { recursive: true });
126
- const relativeParent = relative(realpathSync(modules), realpathSync(parent));
127
- if (relativeParent === '..' || relativeParent.startsWith(`..${sep}`) || isAbsolute(relativeParent)) throw new Error('profile-package-scope-outside-root');
128
- const target = join(parent, segments.at(-1));
129
- const staged = `${target}.restore-${randomUUID()}`, previous = `${target}.previous-${randomUUID()}`;
130
- symlinkSync(realpathSync(input.snapshotDir), staged, 'dir');
131
- let moved = false;
132
- try {
133
- try { renameSync(target, previous); moved = true; } catch(e) { if (e.code !== 'ENOENT') throw e; }
134
- renameSync(staged, target);
135
- } catch(e) { if (moved && !existsSync(target)) renameSync(previous, target); throw e; }
136
- finally { if (existsSync(staged)) rmSync(staged); }
137
- // Retain the quarantined old link/tree; never delete active hardlinked module files in place.
138
- return { ok: true, installedRoot: target };
139
- }
140
- if (operation === 'claim-recovery') {
141
- fence(holder, lease);
142
- const tx = read(stateFile);
143
- if (!tx || tx.opId !== lease.opId || tx.lease?.generation !== lease.generation) throw new Error('operation-mismatch');
144
- if (tx.phase !== 'rolling-back') throw new Error('not-recovering');
145
- // 同代的两个监督器只能有一个执行恢复:先到者写 claim,后到者拿到 claimed。
146
- if (tx.recoveryClaim && tx.recoveryClaim.owner !== input.owner) return { ok: false, error: 'recovery-claimed', transaction: tx };
147
- const next = { ...tx, recoveryClaim: { owner: input.owner, at: input.now } };
148
- atomic(stateFile, next);
149
- if (input.currentFile && input.currentFile !== stateFile) atomic(input.currentFile, next);
150
- return { ok: true, transaction: next };
151
- }
152
- if (operation === 'finish-terminal') {
153
- fence(holder, lease);
154
- const tx = read(stateFile);
155
- if (!tx || tx.opId !== lease.opId || tx.lease?.generation !== lease.generation) throw new Error('operation-mismatch');
156
- if (input.expectedPhases && !input.expectedPhases.includes(tx.phase)) throw new Error('phase-cas-failed');
157
- if (!terminal(input.phase)) throw new Error('not-a-terminal-phase');
158
- const next = { ...tx, phase: input.phase, result: input.result, lease, id: lease.generation, updatedAt: new Date().toISOString() };
159
- atomic(stateFile, next);
160
- if (input.currentFile && input.currentFile !== stateFile) atomic(input.currentFile, next);
161
- // 发布终态与释放锁是一次仲裁:中间不存在"已终态但锁仍被旧代持有/已被释放"的空窗。
162
- atomic(holderFile, null);
163
- return { ok: true, transaction: next };
164
- }
165
- if (operation === 'converge') {
166
- const tx = read(stateFile);
167
- if (!tx) return { ok: true, action: 'none', transaction: null };
168
- if (terminal(tx.phase)) return { ok: true, action: 'terminal', transaction: tx };
169
- if (input.expectedLease && !owns(holder, input.expectedLease)) return { ok: true, action: 'superseded', transaction: tx };
170
- if (holderAlive(holder)) return { ok: true, action: 'active', transaction: tx };
171
- // holder.json 缺失:restart-pending 仍需按 stale 结算(不能因缺 holder 永久 recent);
172
- // 其他阶段维持保守 recent。
173
- if (existsSync(lockPath) && !existsSync(holderFile) && tx.phase !== 'restart-pending') {
174
- return { ok: true, action: 'recent', transaction: tx };
175
- }
176
- // issue #110 P1-C:restart-pending + holder 全死 + stale:
177
- // - 运行内容 == target → settled(保留 artifact/snapshot 元数据,不假称回滚成功);
178
- // - 内容不匹配 → failed(confirmation-lost),不无限 pending。
179
- if (tx.phase === 'restart-pending') {
180
- const startedAt = Date.parse(tx.startedAt ?? tx.updatedAt ?? '');
181
- // 缺时间戳视为 stale:restart-pending 不能因坏元数据永久 pending。
182
- const stale = Number.isFinite(startedAt) ? input.now - startedAt >= input.staleMs : true;
183
- if (!stale) return { ok: true, action: 'recent', transaction: tx };
184
- const target = String(tx.targetContentSha256 ?? '').toLowerCase();
185
- const local = String(input.localContentSha256 ?? '').toLowerCase();
186
- const matched = target !== '' && local === target;
187
- const next = {
188
- ...tx,
189
- phase: matched ? 'settled' : 'failed',
190
- result: matched
191
- ? { ok: true, matched: 'loaded-target-content-adopted' }
192
- : { ok: false, reason: 'confirmation-lost' },
193
- updatedAt: new Date(input.now).toISOString(),
194
- };
195
- atomic(stateFile, next);
196
- if (holder) atomic(holderFile, null);
197
- return { ok: true, action: matched ? 'settled' : 'converged', transaction: next };
198
- }
199
- // Never relabel a possibly damaged install as an ordinary terminal failure.
200
- if (['installing','rolling-back'].includes(tx.phase)) return { ok: true, action: 'recovery-required', transaction: tx };
201
- if (input.now - Date.parse(tx.startedAt) < input.staleMs) return { ok: true, action: 'recent', transaction: tx };
202
- if (tx.lease && holder && !owns(holder, tx.lease)) return { ok: true, action: 'superseded', transaction: tx };
203
- const next = { ...tx, phase: 'failed', result: { ok: false, reason: 'holder-gone' } };
204
- atomic(stateFile, next); if (holder) atomic(holderFile, null);
205
- return { ok: true, action: 'converged', transaction: next };
206
- }
207
- throw new Error('unknown-arbitration-operation');
208
- }
209
- try { console.log(JSON.stringify(execute(JSON.parse(readFileSync(0, 'utf8'))))); }
210
- catch(e) { console.log(JSON.stringify({ ok: false, error: e.message })); }
@@ -1,379 +0,0 @@
1
- #!/usr/bin/env node
2
- // 插件自更新的**外部监督器**(ADR 0019;评审 #32 note 1286 的 R1,二次复核的 F1/F2/F3/F4)。
3
- //
4
- // 为什么必须独立:回滚绝不能依赖新版插件能否加载。本脚本由**旧版插件**启动,
5
- // 启动前先把自身代码**冻结**到不可变目录(pnpm 可能清理原模块目录),并在 systemd 托管时
6
- // 用 transient unit **逃逸出宿主 cgroup**(否则停宿主时监督器会被一起杀掉)。
7
- //
8
- // 工作方式:
9
- // 1. `--arm`:写就绪回执 → 接管事务锁 → 等事务进入 `restart-pending`(或终态/超时);
10
- // 2. 进入后**先安排第一次重启**(旧宿主不会自己加载新代码),再等新实例健康;
11
- // 3. 健康判据是**正在运行的内容标识**(`plugin.contentSha256`),不是磁盘字节;
12
- // 4. 不健康 → 用**快照**恢复旧依赖并重装 → 再重启 → 确认旧内容回来;
13
- // 5. 全程只在终态释放锁,并把结果原子落盘供手机查询。
14
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
15
- import { dirname, join } from "node:path";
16
- import { spawn, spawnSync } from "node:child_process";
17
- import { appendOperationLog } from "./plugin-update-log.js";
18
- import {
19
- TRANSACTION_PHASE,
20
- acquireLock,
21
- assertUpdateLease,
22
- restoreOwnedProfile,
23
- publishOwnedSnapshotLink,
24
- finishOwnedTerminal,
25
- claimOwnedRecovery,
26
- defaultIsPidAlive,
27
- writeOwnedTransaction,
28
- switchOwnedDependency,
29
- handOverLock,
30
- readTransaction,
31
- releaseLock,
32
- snapshotReady,
33
- updateLockPath,
34
- writeTransaction,
35
- } from "./plugin-update-transaction.js";
36
- import { pluginContentDigest } from "./plugin-content-digest.js";
37
- import { verifyFrozenPackage } from "./runtime-dependency-snapshot.js";
38
- import { restartPlan, respawnCommandOf } from "./plugin-self-update.js";
39
- import { shellOptions } from "./tool-process.js";
40
-
41
- /** 等待宿主的默认超时:足够冷启动(含语料预热),又不至于让用户无限等。 */
42
- export const DEFAULT_WAIT_TIMEOUT_MS = 180_000;
43
- export const DEFAULT_POLL_MS = 2_000;
44
- /** 等事务进入 restart-pending 的上限(下载 + 安装可能很慢)。 */
45
- export const DEFAULT_ARM_TIMEOUT_MS = 15 * 60 * 1000;
46
-
47
- /** 解析命令行参数。 */
48
- export function parseArgs(argv) {
49
- const out = {};
50
- for (let i = 0; i < argv.length; i++) {
51
- const key = argv[i];
52
- if (!key.startsWith("--")) continue;
53
- const next = argv[i + 1];
54
- if (next === undefined || next.startsWith("--")) out[key.slice(2)] = "true";
55
- else {
56
- out[key.slice(2)] = next;
57
- i++;
58
- }
59
- }
60
- return out;
61
- }
62
-
63
- /** 轮询本机宿主,直到它报告出**期望的内容标识**(或期望版本)。 */
64
- export async function waitForHost({
65
- port,
66
- basePath = "/m",
67
- token = "",
68
- expectContentSha256 = "",
69
- expectVersion = "",
70
- timeoutMs = DEFAULT_WAIT_TIMEOUT_MS,
71
- pollMs = DEFAULT_POLL_MS,
72
- fetchImpl = fetch,
73
- now = () => Date.now(),
74
- sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
75
- } = {}) {
76
- const deadline = now() + timeoutMs;
77
- const url = `http://127.0.0.1:${port}${basePath}/api/bootstrap`;
78
- let lastError = "no-response";
79
- while (now() < deadline) {
80
- try {
81
- const res = await fetchImpl(url, {
82
- headers: token ? { "x-mobile-token": token } : {},
83
- signal: AbortSignal.timeout(Math.max(1000, pollMs)),
84
- });
85
- if (res?.ok) {
86
- const body = await res.json();
87
- const plugin = body?.plugin ?? {};
88
- const contentOk = expectContentSha256 !== "" && plugin.contentSha256 === expectContentSha256;
89
- const versionOk = expectContentSha256 === "" && expectVersion !== "" && plugin.version === expectVersion;
90
- const anyOk = expectContentSha256 === "" && expectVersion === "" && Boolean(body?.ok);
91
- if (contentOk || versionOk || anyOk) {
92
- return { ok: true, plugin, matched: contentOk ? "content" : versionOk ? "version" : "any" };
93
- }
94
- lastError = `content-mismatch:${plugin.contentSha256 ?? "none"}`;
95
- } else {
96
- lastError = `http-${res?.status ?? "?"}`;
97
- }
98
- } catch (e) {
99
- lastError = String(e?.message ?? e);
100
- }
101
- await sleep(pollMs);
102
- }
103
- return { ok: false, error: `host-wait-timeout: ${lastError}` };
104
- }
105
-
106
- /** 找出**当前**占用该端口的进程(F3:回滚不能杀更新前的旧 PID)。 */
107
- export function findPortOwnerPid(port, { run = spawnSync } = {}) {
108
- if (!Number.isFinite(port) || port <= 0) return null;
109
- try {
110
- const ss = run("ss", ["-ltnpH", `sport = :${port}`], { encoding: "utf8" });
111
- const m = /pid=(\d+)/.exec(ss?.stdout ?? "");
112
- if (m) return Number(m[1]);
113
- } catch {
114
- // 继续尝试 lsof
115
- }
116
- try {
117
- const lsof = run("lsof", ["-ti", `tcp:${port}`, "-sTCP:LISTEN"], { encoding: "utf8" });
118
- const first = (lsof?.stdout ?? "").trim().split("\n")[0];
119
- if (/^\d+$/.test(first)) return Number(first);
120
- } catch {
121
- // 没有可用工具
122
- }
123
- return null;
124
- }
125
-
126
- /** 生成"杀掉当前端口占用者"的 shell 片段(找不到就退回给定 pid)。 */
127
- export function portKillSnippet(port, fallbackPid = null) {
128
- const lines = [
129
- `P=$(ss -ltnpH "sport = :${port}" 2>/dev/null | grep -oP 'pid=\\K[0-9]+' | head -1)`,
130
- `[ -z "$P" ] && P=$(lsof -ti tcp:${port} -sTCP:LISTEN 2>/dev/null | head -1)`,
131
- ];
132
- if (fallbackPid) lines.push(`[ -z "$P" ] && P=${fallbackPid}`);
133
- lines.push('[ -n "$P" ] && kill -TERM "$P" 2>/dev/null');
134
- return lines.join("; ");
135
- }
136
-
137
- /**
138
- * 默认重启器:**按当前实例**(端口占用者)终止,而不是事务里记的旧 PID;
139
- * 前台形态自行重新拉起。**返回结果不再被忽略**(F3)。
140
- */
141
- /** 从 `/proc/<pid>/cmdline` 还原宿主原命令行(supervisor 的 argv 不是宿主 argv)。 */
142
- export function respawnCommandFromProc(pid) {
143
- if (!Number.isInteger(pid) || pid <= 0) return "";
144
- try {
145
- const parts = readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter((part) => part !== "");
146
- return respawnCommandOf(parts);
147
- } catch {
148
- return "";
149
- }
150
- }
151
-
152
- export function defaultRestart({
153
- restartForm,
154
- port,
155
- pid = null,
156
- hostPid = null,
157
- profile = "web",
158
- dshCommand = "dsh",
159
- respawnCommand = "",
160
- log = () => {},
161
- spawnSyncImpl = spawnSync,
162
- }) {
163
- // issue #110 P2:supervisor 的 process.argv 是 `update-supervisor.js --state`,
164
- // 不能拿它当宿主命令行;优先事务写入的 respawnCommand,其次 `/proc/<hostPid>/cmdline`。
165
- let originalCommand = respawnCommand;
166
- if (originalCommand === "" && Number.isInteger(hostPid)) originalCommand = respawnCommandFromProc(hostPid);
167
- if (originalCommand === "") originalCommand = respawnCommandOf(process.argv);
168
- const plan = restartPlan({ form: restartForm, pid: null, profile, dshCommand, respawnCommand: originalCommand });
169
- if (plan.mode === "unsupported") return { ok: false, error: "restart-unsupported" };
170
- const kill = portKillSnippet(port, pid);
171
- // 保留原始 argv(如 --port 3082 / --no-open),不能落回 `dsh web --profile web`。
172
- const respawn = plan.mode === "respawn"
173
- ? (plan.commands?.[plan.commands.length - 1] ?? "")
174
- : "";
175
- if (plan.mode === "respawn" && (respawn === "" || originalCommand === "")) {
176
- return { ok: false, error: "restart-command-missing" };
177
- }
178
- const script = plan.mode === "respawn"
179
- ? `sleep 1; ${kill}; sleep 2; nohup ${respawn} >/dev/null 2>&1 &`
180
- : `sleep 1; ${kill}`;
181
- const r = spawnSyncImpl("bash", ["-lc", script], { encoding: "utf8" });
182
- if (r.error) return { ok: false, error: r.error.message };
183
- if (r.status !== 0) return { ok: false, error: `restart-script-exit-${r.status}: ${(r.stderr || "").trim()}` };
184
- log(`supervisor: 已安排重启(${plan.mode},目标=当前端口占用者)`);
185
- return { ok: true, script };
186
- }
187
-
188
- /**
189
- * 默认恢复器(F4):把依赖指回**快照**(而不是可能已变的原 clone/tag/source),
190
- * 再重装;并检查安装结果。
191
- */
192
- export async function defaultRestore({ profileDir, snapshotDir: snapDir, expectedContentSha256, profileSnapshot, dependencyKey, preserveSpecifier = false, lockPath, lease }) {
193
- if (!snapDir || !snapshotReady(snapDir) || (expectedContentSha256 && pluginContentDigest(snapDir) !== expectedContentSha256)) {
194
- return { ok: false, error: "snapshot-unavailable" };
195
- }
196
- try {
197
- assertUpdateLease(lockPath, lease);
198
- // 一次受代际保护的仲裁里恢复 profile/lockfile(A 阻塞:不再有 assert→write 空窗)。
199
- const restoreKey = dependencyKey || profileSnapshot?.dependencyKey || 'dsh-mobile-remote';
200
- const restored = restoreOwnedProfile({ profileDir, snapshotDir: snapDir, snapshot: profileSnapshot, key: restoreKey,
201
- preserveSpecifier, lockPath, lease });
202
- if (!restored.ok) return { ok: false, error: restored.error };
203
- // 直接把**已验证自包含**的快照发布为安装目录:旧字节精确、离线可加载;
204
- // npm 事务保留原精确 registry spec,legacy 事务继续使用 file: 快照 spec。
205
- const published = publishOwnedSnapshotLink({ profileDir, snapshotDir: snapDir, key: restoreKey, lockPath, lease });
206
- if (!published.ok) return { ok: false, error: published.error };
207
- assertUpdateLease(lockPath, lease);
208
- const actualRoot = join(profileDir, "node_modules", ...restoreKey.split("/"));
209
- if (pluginContentDigest(actualRoot) !== expectedContentSha256) return { ok: false, error: "restored-content-mismatch" };
210
- const verified = verifyFrozenPackage(actualRoot);
211
- if (!verified.ok) return { ok: false, error: `restored-snapshot-invalid: ${verified.error}` };
212
- return { ok: true, restoredTo: snapDir, digest: verified.digest };
213
- } catch(e) { return { ok: false, error: e.message }; }
214
- }
215
-
216
- /** 默认安装器(监督器是独立进程,阻塞没关系)。 */
217
- export function defaultRunInstall(profileDir) {
218
- // Windows 上 pnpm 是 pnpm.cmd,必须经 shell 解析。
219
- const r = spawnSync("pnpm", ["install"], { cwd: profileDir, encoding: "utf8", ...shellOptions() });
220
- if (r.error) return { ok: false, error: r.error.message };
221
- if (r.status !== 0) return { ok: false, error: (r.stderr || `exit ${r.status}`).trim() };
222
- return { ok: true };
223
- }
224
-
225
- /**
226
- * 推进一次已进入 `restart-pending` 的事务。
227
- * **顺序**:先安排第一次重启(F1),再等新实例健康;不健康才走回滚。
228
- */
229
- export async function runTransaction({ stateFile, tx, timeoutMs = DEFAULT_WAIT_TIMEOUT_MS,
230
- pollMs = DEFAULT_POLL_MS, maxRollbacks = 1, waitForHost: waitImpl = waitForHost,
231
- restore = defaultRestore, restart = defaultRestart, runInstall = defaultRunInstall, log = () => {}, now = () => Date.now() } = {}) {
232
- const lockPath = tx.lockPath || join(dirname(stateFile), "plugin-update.lock.d");
233
- const lease = tx.lease;
234
- const phaseAt = () => tx.phase;
235
- const save = (patch, expectedPhases) => { tx = writeOwnedTransaction(stateFile, { ...tx, ...patch }, { lockPath, lease, currentFile: tx.currentFile, expectedPhases }); return tx; };
236
- // 终态与释放合一:不存在"已终态但锁还在/已被释放"的空窗(C3)。
237
- const finish = (phase, result, expectedPhases) => finishOwnedTerminal(stateFile, { phase, result, expectedPhases }, { lockPath, lease, currentFile: tx.currentFile });
238
- try {
239
- assertUpdateLease(lockPath, lease);
240
- let failure = tx.recoveryCause || tx.result?.reason;
241
- // 已经处于 rolling-back(安装失败/恢复重试):**直接续做恢复**,不重复"先重启再等待"。
242
- if (tx.phase !== TRANSACTION_PHASE.ROLLING_BACK) {
243
- const entryPhase = phaseAt();
244
- log("supervisor: restarting host to load candidate plugin");
245
- const result = await restart({ ...tx, pid: tx.hostPid, log });
246
- assertUpdateLease(lockPath, lease);
247
- if (!result?.ok) {
248
- log("supervisor: candidate restart failed");
249
- failure = `restart-failed: ${result?.error ?? "unknown"}`;
250
- } else {
251
- log("supervisor: waiting for candidate health confirmation");
252
- const healthy = await waitImpl({ ...tx, expectContentSha256: tx.targetContentSha256,
253
- expectVersion: tx.targetVersion, timeoutMs, pollMs });
254
- assertUpdateLease(lockPath, lease);
255
- if (healthy.ok) {
256
- log("supervisor: candidate plugin health confirmed");
257
- return finish(TRANSACTION_PHASE.SETTLED, { ok: true, matched: healthy.matched, at: new Date(now()).toISOString() }, [entryPhase]);
258
- }
259
- log("supervisor: candidate health check failed; rollback required");
260
- failure = healthy.error;
261
- }
262
- if (!tx.previousSnapshotDir) return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-target-missing", error: failure }, [entryPhase]);
263
- if ((tx.attempts ?? 0) >= maxRollbacks) return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-exhausted", error: failure }, [entryPhase]);
264
- // 正常失败与"续做恢复"共用同一入口;CAS 用**进入时的真实阶段**,不再硬编码。
265
- save({ phase: TRANSACTION_PHASE.ROLLING_BACK, attempts: (tx.attempts ?? 0) + 1, rolledBack: true,
266
- result: { ok: false, reason: "rolling-back", error: failure } }, [entryPhase]);
267
- }
268
- assertUpdateLease(lockPath, lease);
269
- if (!tx.previousSnapshotDir) return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-target-missing", error: failure }, ["rolling-back"]);
270
- if ((tx.attempts ?? 0) > maxRollbacks) return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-exhausted", error: failure }, ["rolling-back"]);
271
- // 同代唯一 claim:两个监督器同时重试时,只有一方真的执行恢复与重启。
272
- const owner = `${process.pid}-${Math.random().toString(36).slice(2)}`;
273
- const claimed = claimOwnedRecovery(stateFile, { owner }, { lockPath, lease, currentFile: tx.currentFile });
274
- if (!claimed.ok) return { ok: false, error: claimed.error, transaction: claimed.transaction };
275
- tx = claimed.transaction;
276
- log("supervisor: restoring previous plugin snapshot");
277
- const restored = await restore({ profileDir: tx.profileDir, snapshotDir: tx.previousSnapshotDir,
278
- expectedContentSha256: tx.previousContentSha256, profileSnapshot: tx.profileSnapshot,
279
- dependencyKey: tx.dependencyKey || tx.profileSnapshot?.dependencyKey,
280
- preserveSpecifier: Boolean(tx.npmCandidate), lockPath, lease, runInstall });
281
- assertUpdateLease(lockPath, lease);
282
- if (!restored?.ok) {
283
- log("supervisor: previous plugin snapshot restore failed");
284
- return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-restore-failed", error: restored?.error }, ["rolling-back"]);
285
- }
286
- log("supervisor: restarting host with previous plugin");
287
- const result = await restart({ ...tx, pid: null, log });
288
- assertUpdateLease(lockPath, lease);
289
- if (!result?.ok) {
290
- log("supervisor: rollback restart failed");
291
- return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "rollback-restart-failed", error: result?.error }, ["rolling-back"]);
292
- }
293
- log("supervisor: waiting for previous plugin health confirmation");
294
- const back = await waitImpl({ ...tx, expectContentSha256: tx.previousContentSha256,
295
- expectVersion: "", timeoutMs, pollMs });
296
- assertUpdateLease(lockPath, lease);
297
- log(back.ok ? "supervisor: previous plugin health confirmed" : "supervisor: previous plugin health not confirmed");
298
- return finish(back.ok ? TRANSACTION_PHASE.ROLLED_BACK : TRANSACTION_PHASE.FAILED,
299
- { ok: false, reason: back.ok ? "rolled-back" : "rollback-unconfirmed", error: back.ok ? failure : back.error }, ["rolling-back"]);
300
- } catch(e) {
301
- if (e.message === "lease-lost") return { ok: false, error: "lease-lost" };
302
- try { return finish(TRANSACTION_PHASE.FAILED, { ok: false, reason: "supervisor-error", error: e.message }, [tx.phase]); }
303
- catch { return { ok: false, error: e.message }; }
304
- }
305
- }
306
-
307
- export async function superviseUpdate(options = {}) {
308
- const tx = readTransaction(options.stateFile);
309
- if (!tx) return { ok: false, error: "no-transaction" };
310
- if (options.opId && (options.opId !== tx.opId || options.generation !== tx.lease?.generation)) return { ok: false, error: "operation-mismatch" };
311
- if (!["restart-pending", "rolling-back"].includes(tx.phase)) return { ok: false, error: `not-restart-pending:${tx.phase}` };
312
- return runTransaction({ ...options, tx });
313
- }
314
-
315
- export async function superviseArmed({ stateFile, readyFile, opId, generation,
316
- armTimeoutMs = DEFAULT_ARM_TIMEOUT_MS, pollMs = DEFAULT_POLL_MS,
317
- log = () => {}, sleep = ms => new Promise(r => setTimeout(r, ms)), now = () => Date.now(), ...rest } = {}) {
318
- const tx0 = readTransaction(stateFile);
319
- if (!tx0 || tx0.opId !== opId || tx0.lease?.generation !== generation) return { ok: false, error: "operation-mismatch" };
320
- const lockPath = tx0.lockPath, lease = tx0.lease;
321
- if (!handOverLock(lockPath, { lease, toPid: process.pid })) return { ok: false, error: "lease-lost" };
322
- let cgroup = "";
323
- try { cgroup = readFileSync("/proc/self/cgroup", "utf8").trim(); } catch { /* portable ready receipt */ }
324
- mkdirSync(dirname(readyFile), { recursive: true });
325
- writeFileSync(readyFile, JSON.stringify({ pid: process.pid, opId, generation, cgroup, at: new Date(now()).toISOString() }), { mode: 0o600 });
326
- const deadline = now() + armTimeoutMs;
327
- while (now() < deadline) {
328
- const tx = readTransaction(stateFile);
329
- if (!tx || tx.opId !== opId || tx.lease?.generation !== generation) return { ok: false, error: "operation-mismatch" };
330
- try { assertUpdateLease(lockPath, lease); } catch { return { ok: false, error: "lease-lost" }; }
331
- if (["restart-pending","rolling-back"].includes(tx.phase)) return runTransaction({ stateFile, tx, log, ...rest });
332
- if (["settled","rolled-back","failed"].includes(tx.phase)) return tx;
333
- if (!defaultIsPidAlive(tx.hostPid) && tx.phase === "installing") {
334
- const recovering = writeOwnedTransaction(stateFile, { ...tx, phase: "rolling-back", recoveryCause: "install-worker-gone", rolledBack: true }, { lockPath, lease, currentFile: tx.currentFile });
335
- return runTransaction({ stateFile, tx: recovering, log, ...rest });
336
- }
337
- await sleep(pollMs);
338
- }
339
- // Do not race a live installer. Keep its protected recovery metadata, rather than granting a new transaction.
340
- const current = readTransaction(stateFile);
341
- if (current.phase === "staging") {
342
- // 终态 + 释放同一次仲裁;不覆盖已推进到 installing 的事务(phase CAS)。
343
- try { finishOwnedTerminal(stateFile, { phase: "failed", result: { ok: false, reason: "arm-timeout" }, expectedPhases: ["staging"] }, { lockPath, lease, currentFile: current.currentFile }); }
344
- catch (e) { log(`supervisor: 保留受保护事务(${e.message})`); }
345
- }
346
- return { ok: false, error: "arm-timeout" };
347
- }
348
-
349
- async function main() {
350
- const args = parseArgs(process.argv.slice(2));
351
- const stateFile = args.state;
352
- if (!stateFile) {
353
- console.error("usage: node update-supervisor.js --state <transaction.json> [--arm --ready <file>] [--timeout 180]");
354
- process.exit(2);
355
- }
356
- const timeoutMs = Number(args.timeout ?? 0) > 0 ? Number(args.timeout) * 1000 : DEFAULT_WAIT_TIMEOUT_MS;
357
- const pollMs = Number(args.poll ?? 0) > 0 ? Number(args.poll) : DEFAULT_POLL_MS;
358
- const txAtStart = readTransaction(stateFile);
359
- const generation = txAtStart?.lease?.generation ?? args.generation;
360
- const currentFile = txAtStart?.currentFile ?? "";
361
- const logHome = currentFile ? dirname(dirname(dirname(currentFile))) : (process.env.HOME ?? "");
362
- const log = (message) => {
363
- if (logHome && generation) {
364
- try { appendOperationLog({ home: logHome, generation, stage: "supervisor", text: message, redactPaths: [logHome, txAtStart?.profileDir] }); } catch { /* progress logging must not block recovery */ }
365
- }
366
- console.log("supervisor: progress event recorded");
367
- };
368
- const finalState = args.arm
369
- ? await superviseArmed({ stateFile, readyFile: args.ready, opId: args.op, generation: args.generation, timeoutMs, pollMs, log })
370
- : await superviseUpdate({ stateFile, opId: args.op, generation: args.generation, timeoutMs, pollMs, log });
371
- console.log(`supervisor: 结束于 ${finalState?.phase ?? "unknown"}`);
372
- }
373
-
374
- if (process.argv[1] && process.argv[1].endsWith("update-supervisor.js")) {
375
- main().catch((e) => {
376
- console.error(`supervisor: 异常 ${e?.stack ?? e}`);
377
- process.exit(1);
378
- });
379
- }
@@ -1,37 +0,0 @@
1
- declare namespace ansiRegex {
2
- interface Options {
3
- /**
4
- Match only the first ANSI escape.
5
-
6
- @default false
7
- */
8
- onlyFirst: boolean;
9
- }
10
- }
11
-
12
- /**
13
- Regular expression for matching ANSI escape codes.
14
-
15
- @example
16
- ```
17
- import ansiRegex = require('ansi-regex');
18
-
19
- ansiRegex().test('\u001B[4mcake\u001B[0m');
20
- //=> true
21
-
22
- ansiRegex().test('cake');
23
- //=> false
24
-
25
- '\u001B[4mcake\u001B[0m'.match(ansiRegex());
26
- //=> ['\u001B[4m', '\u001B[0m']
27
-
28
- '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
29
- //=> ['\u001B[4m']
30
-
31
- '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
32
- //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
33
- ```
34
- */
35
- declare function ansiRegex(options?: ansiRegex.Options): RegExp;
36
-
37
- export = ansiRegex;
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = ({onlyFirst = false} = {}) => {
4
- const pattern = [
5
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
6
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
7
- ].join('|');
8
-
9
- return new RegExp(pattern, onlyFirst ? undefined : 'g');
10
- };
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.