@dsh-workbench/shared 0.3.10 → 1.0.0-beta.0

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 (391) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -0
  3. package/dist/api/blocker-table.d.ts +3 -3
  4. package/dist/api/blocker-table.js +47 -23
  5. package/dist/api/dsh.d.ts +19 -1
  6. package/dist/api/host-write.d.ts +0 -15
  7. package/dist/api/host-write.js +1 -35
  8. package/dist/api/workbench-client.js +2 -1
  9. package/dist/components/Activity.css +0 -1
  10. package/dist/components/ApprovalDetail.css +1 -2
  11. package/dist/components/ApprovalDetail.d.ts +1 -1
  12. package/dist/components/ApprovalPlan.css +0 -1
  13. package/dist/components/Card.css +0 -1
  14. package/dist/components/Card.d.ts +1 -1
  15. package/dist/components/CardBoundary.d.ts +1 -1
  16. package/dist/components/CardHead.css +0 -1
  17. package/dist/components/CardHead.d.ts +1 -1
  18. package/dist/components/ChoiceGroup.css +1 -2
  19. package/dist/components/ConfirmBar.d.ts +1 -1
  20. package/dist/components/ConfirmBar.js +1 -1
  21. package/dist/components/Form.css +1 -1
  22. package/dist/components/FormActions.js +1 -1
  23. package/dist/components/LongTaskRow.css +1 -2
  24. package/dist/components/LongTaskRow.d.ts +1 -1
  25. package/dist/components/LongTaskRow.js +1 -1
  26. package/dist/components/Note.css +0 -1
  27. package/dist/components/ResourceStates.css +0 -1
  28. package/dist/components/SettingsSection.css +0 -1
  29. package/dist/components/Spinner.css +0 -1
  30. package/dist/components/Stack.css +0 -1
  31. package/dist/components/StateBlock.css +0 -1
  32. package/dist/components/board-module.d.ts +3 -3
  33. package/dist/components/icons.d.ts +1 -7
  34. package/dist/components/icons.js +11 -16
  35. package/dist/config/constants.d.ts +2 -2
  36. package/dist/config/constants.js +2 -2
  37. package/dist/config/storage.d.ts +0 -4
  38. package/dist/config/storage.js +0 -11
  39. package/dist/contract/adapters.d.ts +10 -0
  40. package/dist/contract/cli.d.ts +3 -0
  41. package/dist/contract/data.d.ts +126 -0
  42. package/dist/{api → contract}/facts.d.ts +12 -3
  43. package/dist/{api → contract}/facts.js +19 -1
  44. package/dist/contract/needs.d.ts +132 -0
  45. package/dist/contract/needs.js +232 -0
  46. package/dist/contract/plugin-source.d.ts +1 -0
  47. package/dist/contract/plugin-source.js +1 -0
  48. package/dist/contract/protocol/bundle-install.d.ts +136 -0
  49. package/dist/contract/protocol/bundle-install.js +12 -0
  50. package/dist/contract/protocol/config-sync.d.ts +55 -0
  51. package/dist/contract/protocol/config-sync.js +2 -0
  52. package/dist/contract/protocol/diy.d.ts +4 -0
  53. package/dist/contract/protocol/diy.js +4 -0
  54. package/dist/contract/protocol/dsh-plugins.d.ts +11 -0
  55. package/dist/contract/protocol/dsh-plugins.js +1 -0
  56. package/dist/contract/protocol/long-tasks.d.ts +13 -0
  57. package/dist/contract/protocol/long-tasks.js +1 -0
  58. package/dist/contract/protocol/market-index.d.ts +195 -0
  59. package/dist/contract/protocol/market-index.js +7 -0
  60. package/dist/contract/protocol/platform.d.ts +44 -0
  61. package/dist/contract/protocol/platform.js +1 -0
  62. package/dist/contract/protocol/preflight-wake.d.ts +7 -0
  63. package/dist/contract/protocol/preflight-wake.js +1 -0
  64. package/dist/contract/protocol/profile-create.d.ts +30 -0
  65. package/dist/contract/protocol/profile-create.js +2 -0
  66. package/dist/contract/protocol/sidebar-edition.d.ts +14 -0
  67. package/dist/contract/protocol/sidebar-edition.js +2 -0
  68. package/dist/contract/protocol/unit-manifests.d.ts +6 -0
  69. package/dist/contract/protocol/unit-manifests.js +1 -0
  70. package/dist/contract/unit-board.d.ts +18 -0
  71. package/dist/contract/unit-board.js +1 -0
  72. package/dist/contract/unit-capability.d.ts +34 -0
  73. package/dist/contract/unit-capability.js +1 -0
  74. package/dist/{api → contract}/unit-declaration.d.ts +7 -5
  75. package/dist/{api → contract}/unit-declaration.js +19 -13
  76. package/dist/contract/unit.d.ts +57 -0
  77. package/dist/contract/unit.js +24 -0
  78. package/dist/contract/workbench-contract.d.ts +15 -0
  79. package/dist/contract/workbench-contract.js +1 -0
  80. package/dist/host/adapter-set.d.ts +26 -0
  81. package/dist/host/adapter-set.js +243 -0
  82. package/dist/host/adapter-types.d.ts +79 -0
  83. package/dist/host/adapter-types.js +23 -0
  84. package/dist/host/adapters.d.ts +22 -0
  85. package/dist/host/adapters.js +9 -0
  86. package/dist/host/browser.d.ts +3 -0
  87. package/dist/host/browser.js +3 -0
  88. package/dist/host/changelog.d.ts +21 -0
  89. package/dist/host/changelog.js +188 -0
  90. package/dist/host/channel-plugin.d.ts +15 -0
  91. package/dist/host/channel-plugin.js +42 -0
  92. package/dist/host/cli.d.ts +4 -0
  93. package/dist/host/cli.js +7 -0
  94. package/dist/host/command-name.d.ts +1 -0
  95. package/dist/host/command-name.js +14 -0
  96. package/dist/host/data-error.d.ts +13 -0
  97. package/dist/host/data-error.js +20 -0
  98. package/dist/host/data-root.js +3 -0
  99. package/dist/host/diy-debug.js +2 -1
  100. package/dist/host/diy-record.js +2 -1
  101. package/dist/host/facts.d.ts +1 -1
  102. package/dist/host/facts.js +3 -2
  103. package/dist/host/git.js +2 -2
  104. package/dist/host/http.js +1 -1
  105. package/dist/host/lib-capabilities.d.ts +22 -0
  106. package/dist/host/lib-capabilities.js +37 -0
  107. package/dist/host/lib-install.d.ts +9 -0
  108. package/dist/host/lib-install.js +10 -0
  109. package/dist/host/long-task.d.ts +1 -1
  110. package/dist/host/long-task.js +4 -3
  111. package/dist/host/market-index.d.ts +22 -0
  112. package/dist/host/market-index.js +420 -0
  113. package/dist/host/needs.d.ts +4 -0
  114. package/dist/host/needs.js +2 -0
  115. package/dist/host/patch.d.ts +9 -0
  116. package/dist/host/patch.js +78 -0
  117. package/dist/host/paths.d.ts +12 -0
  118. package/dist/host/paths.js +28 -0
  119. package/dist/host/platform.d.ts +14 -0
  120. package/dist/host/platform.js +40 -0
  121. package/dist/host/plugin-source.d.ts +8 -6
  122. package/dist/host/plugin-source.js +43 -33
  123. package/dist/host/plugin.d.ts +4 -0
  124. package/dist/host/plugin.js +39 -0
  125. package/dist/host/port-types.d.ts +191 -0
  126. package/dist/host/port-types.js +1 -0
  127. package/dist/host/preflight.d.ts +28 -0
  128. package/dist/host/preflight.js +1 -0
  129. package/dist/host/profile-port.d.ts +4 -0
  130. package/dist/host/profile-port.js +4 -0
  131. package/dist/host/provision.d.ts +2 -2
  132. package/dist/host/provision.js +5 -3
  133. package/dist/host/recipe-rules.d.ts +5 -0
  134. package/dist/host/recipe-rules.js +382 -0
  135. package/dist/host/recipe.d.ts +14 -0
  136. package/dist/host/recipe.js +283 -0
  137. package/dist/host/shell-text.d.ts +9 -2
  138. package/dist/host/shell-text.js +15 -3
  139. package/dist/host/shell.d.ts +2 -0
  140. package/dist/host/shell.js +7 -0
  141. package/dist/host/spec.d.ts +8 -0
  142. package/dist/host/spec.js +24 -0
  143. package/dist/host/supply-index.d.ts +34 -0
  144. package/dist/host/supply-index.js +202 -0
  145. package/dist/host/supply-port.d.ts +5 -0
  146. package/dist/host/supply-port.js +39 -0
  147. package/dist/host/time.d.ts +12 -0
  148. package/dist/host/time.js +19 -0
  149. package/dist/host/tokens.d.ts +26 -0
  150. package/dist/host/tokens.js +154 -0
  151. package/dist/host/tool-approval.d.ts +12 -0
  152. package/dist/host/tool-approval.js +4 -0
  153. package/dist/host/tool-kit.js +1 -1
  154. package/dist/host/unit-face.d.ts +5 -4
  155. package/dist/host/version-range.d.ts +2 -0
  156. package/dist/host/version-range.js +73 -0
  157. package/dist/host/version.d.ts +3 -0
  158. package/dist/host/version.js +29 -0
  159. package/dist/host.d.ts +47 -16
  160. package/dist/host.js +47 -16
  161. package/dist/i18n/en.js +259 -86
  162. package/dist/i18n/index.d.ts +333 -88
  163. package/dist/i18n/merge.js +1 -1
  164. package/dist/i18n/need-text.d.ts +26 -0
  165. package/dist/i18n/need-text.js +26 -0
  166. package/dist/i18n/settings.d.ts +70 -0
  167. package/dist/i18n/settings.js +136 -0
  168. package/dist/i18n/zh.d.ts +332 -87
  169. package/dist/i18n/zh.js +260 -87
  170. package/dist/index.d.ts +24 -8
  171. package/dist/index.js +24 -8
  172. package/dist/lib/blocker-action.d.ts +0 -15
  173. package/dist/lib/blocker-action.js +1 -25
  174. package/dist/{api → lib}/dsh-client.d.ts +12 -1
  175. package/dist/lib/dsh-client.js +1 -0
  176. package/dist/lib/market-index.d.ts +7 -0
  177. package/dist/lib/market-index.js +25 -0
  178. package/dist/lib/react-types.d.ts +5 -0
  179. package/dist/lib/react-types.js +1 -0
  180. package/dist/lib/react.d.ts +1 -40
  181. package/dist/lib/react.js +0 -36
  182. package/dist/lib/ui.js +3 -9
  183. package/dist/testing/data.d.ts +13 -0
  184. package/dist/testing/data.js +46 -0
  185. package/dist/testing/declaration.d.ts +1 -1
  186. package/dist/testing/declaration.js +1 -1
  187. package/dist/testing/host-fakes.d.ts +0 -13
  188. package/dist/testing/host-fakes.js +0 -24
  189. package/dist/testing/needs.d.ts +16 -0
  190. package/dist/testing/needs.js +46 -0
  191. package/dist/testing.d.ts +2 -0
  192. package/dist/testing.js +2 -0
  193. package/package.json +18 -2
  194. package/src/api/__tests__/blocker-table.test.ts +135 -86
  195. package/src/api/blocker-table.ts +52 -26
  196. package/src/api/dsh.ts +17 -1
  197. package/src/api/host-write.ts +0 -43
  198. package/src/api/workbench-client.test.ts +2 -2
  199. package/src/api/workbench-client.ts +2 -1
  200. package/src/components/Activity.css +0 -1
  201. package/src/components/ApprovalDetail.css +1 -2
  202. package/src/components/ApprovalDetail.tsx +1 -1
  203. package/src/components/ApprovalPlan.css +0 -1
  204. package/src/components/Card.css +0 -1
  205. package/src/components/Card.tsx +1 -1
  206. package/src/components/CardAnchor.test.tsx +1 -1
  207. package/src/components/CardBoundary.tsx +1 -1
  208. package/src/components/CardHead.css +0 -1
  209. package/src/components/CardHead.tsx +1 -1
  210. package/src/components/ChoiceGroup.css +1 -2
  211. package/src/components/ConfirmBar.tsx +1 -1
  212. package/src/components/Form.css +1 -1
  213. package/src/components/Form.tsx +1 -1
  214. package/src/components/FormActions.tsx +1 -1
  215. package/src/components/LongTaskRow.css +1 -2
  216. package/src/components/LongTaskRow.tsx +1 -1
  217. package/src/components/Note.css +0 -1
  218. package/src/components/ResourceStates.css +0 -1
  219. package/src/components/SelectFieldNodes.tsx +0 -1
  220. package/src/components/SettingsSection.css +0 -1
  221. package/src/components/Spinner.css +0 -1
  222. package/src/components/Stack.css +0 -1
  223. package/src/components/StateBlock.css +0 -1
  224. package/src/components/__tests__/long-task-row.test.ts +1 -1
  225. package/src/components/board-module.ts +3 -3
  226. package/src/components/icons.tsx +16 -24
  227. package/src/config/constants.ts +2 -2
  228. package/src/config/storage.test.ts +1 -25
  229. package/src/config/storage.ts +0 -12
  230. package/src/{api → contract}/__tests__/facts.test.ts +73 -25
  231. package/src/{api → contract}/__tests__/long-task.test.ts +3 -3
  232. package/src/contract/__tests__/needs.test.ts +74 -0
  233. package/src/{host → contract}/__tests__/unit-declaration.test.ts +1 -1
  234. package/src/contract/__tests__/unit.test.ts +43 -0
  235. package/src/contract/adapters.ts +9 -0
  236. package/src/contract/cli.ts +3 -0
  237. package/src/contract/data.ts +145 -0
  238. package/src/{api → contract}/facts.ts +34 -4
  239. package/src/contract/needs.ts +331 -0
  240. package/src/contract/plugin-source.ts +1 -0
  241. package/src/contract/protocol/bundle-install.ts +198 -0
  242. package/src/contract/protocol/config-sync.ts +65 -0
  243. package/src/contract/protocol/diy.ts +4 -0
  244. package/src/contract/protocol/dsh-plugins.ts +13 -0
  245. package/src/contract/protocol/long-tasks.ts +16 -0
  246. package/src/contract/protocol/market-index.ts +246 -0
  247. package/src/contract/protocol/platform.ts +47 -0
  248. package/src/contract/protocol/preflight-wake.ts +17 -0
  249. package/src/contract/protocol/profile-create.ts +36 -0
  250. package/src/contract/protocol/sidebar-edition.ts +19 -0
  251. package/src/contract/protocol/unit-manifests.ts +8 -0
  252. package/src/contract/unit-board.ts +23 -0
  253. package/src/contract/unit-capability.ts +37 -0
  254. package/src/{host → contract}/unit-declaration.ts +22 -18
  255. package/src/contract/unit.ts +76 -0
  256. package/src/contract/workbench-contract.ts +30 -0
  257. package/src/host/__tests__/adapter-set.test.ts +228 -0
  258. package/src/host/__tests__/adapters.test.ts +27 -0
  259. package/src/host/__tests__/changelog.test.ts +102 -0
  260. package/src/host/__tests__/command-name.test.ts +16 -0
  261. package/src/host/__tests__/diy-record.test.ts +3 -3
  262. package/src/host/__tests__/facts.test.ts +5 -5
  263. package/src/host/__tests__/long-task.test.ts +1 -1
  264. package/src/host/__tests__/market-index.test.ts +179 -0
  265. package/src/host/__tests__/plugin-ledger.test.ts +10 -10
  266. package/src/host/__tests__/provision.test.ts +7 -6
  267. package/src/host/__tests__/shell-text.test.ts +16 -1
  268. package/src/host/__tests__/supply-index.test.ts +137 -0
  269. package/src/host/__tests__/tokens.test.ts +110 -0
  270. package/src/host/__tests__/version-range.test.ts +21 -0
  271. package/src/host/adapter-set.ts +298 -0
  272. package/src/host/adapter-types.ts +105 -0
  273. package/src/host/adapters.ts +44 -0
  274. package/src/host/browser.ts +3 -0
  275. package/src/host/changelog.ts +212 -0
  276. package/src/host/channel-plugin.ts +55 -0
  277. package/src/host/cli.ts +11 -0
  278. package/src/host/command-name.ts +15 -0
  279. package/src/host/data-error.ts +21 -0
  280. package/src/host/data-root.ts +2 -0
  281. package/src/host/diy-debug.ts +2 -1
  282. package/src/host/diy-record.ts +2 -1
  283. package/src/host/facts.ts +4 -3
  284. package/src/host/git.ts +2 -2
  285. package/src/host/http.ts +1 -1
  286. package/src/host/lib-capabilities.ts +52 -0
  287. package/src/host/lib-install.ts +18 -0
  288. package/src/host/long-task.ts +4 -3
  289. package/src/host/market-index.ts +413 -0
  290. package/src/host/needs.ts +6 -0
  291. package/src/host/patch.ts +93 -0
  292. package/src/host/paths.ts +37 -0
  293. package/src/host/platform.ts +48 -0
  294. package/src/host/plugin-source.ts +48 -56
  295. package/src/host/plugin.ts +39 -0
  296. package/src/host/port-types.ts +222 -0
  297. package/src/host/preflight.ts +31 -0
  298. package/src/host/profile-port.ts +9 -0
  299. package/src/host/provision.ts +7 -4
  300. package/src/host/recipe-rules.ts +330 -0
  301. package/src/host/recipe.test.ts +334 -0
  302. package/src/host/recipe.ts +323 -0
  303. package/src/host/shell-text.ts +15 -3
  304. package/src/host/shell.ts +9 -0
  305. package/src/host/spec.ts +32 -0
  306. package/src/host/supply-index.ts +256 -0
  307. package/src/host/supply-port.ts +45 -0
  308. package/src/host/time.ts +22 -0
  309. package/src/host/tokens.ts +186 -0
  310. package/src/host/tool-approval.ts +17 -0
  311. package/src/host/tool-kit.ts +1 -1
  312. package/src/host/unit-face.ts +5 -4
  313. package/src/host/version-range.ts +71 -0
  314. package/src/host/version.ts +30 -0
  315. package/src/host.ts +47 -16
  316. package/src/i18n/en.ts +261 -86
  317. package/src/i18n/merge.test.ts +6 -6
  318. package/src/i18n/merge.ts +1 -1
  319. package/src/i18n/need-text.ts +27 -0
  320. package/src/i18n/settings.ts +141 -0
  321. package/src/i18n/zh.ts +263 -87
  322. package/src/index.ts +24 -8
  323. package/src/lib/blocker-action.ts +0 -28
  324. package/src/{api → lib}/dsh-client.ts +16 -2
  325. package/src/lib/market-index.ts +36 -0
  326. package/src/lib/react-types.ts +5 -0
  327. package/src/lib/react.ts +1 -40
  328. package/src/lib/text.test.ts +2 -2
  329. package/src/lib/ui.test.ts +6 -5
  330. package/src/lib/ui.ts +3 -9
  331. package/src/testing/__tests__/declaration.test.ts +1 -1
  332. package/src/testing/data.ts +66 -0
  333. package/src/testing/declaration.ts +2 -2
  334. package/src/testing/host-fakes.ts +0 -38
  335. package/src/testing/needs.ts +80 -0
  336. package/src/testing.ts +2 -0
  337. package/dist/api/unit-board.d.ts +0 -39
  338. package/dist/api/unit-board.js +0 -45
  339. package/dist/api/unit.d.ts +0 -85
  340. package/dist/api/unit.js +0 -8
  341. package/dist/api/workbench-contract.d.ts +0 -44
  342. package/dist/components/MockStrip.css +0 -39
  343. package/dist/components/MockStrip.d.ts +0 -15
  344. package/dist/components/MockStrip.js +0 -8
  345. package/dist/components/SaveBar.css +0 -7
  346. package/dist/host/browser-find.d.ts +0 -38
  347. package/dist/host/browser-find.js +0 -242
  348. package/dist/host/browser-read.d.ts +0 -28
  349. package/dist/host/browser-read.js +0 -243
  350. package/dist/host/opencli-runtime.d.ts +0 -25
  351. package/dist/host/opencli-runtime.js +0 -56
  352. package/dist/host/opencli-window.d.ts +0 -2
  353. package/dist/host/opencli-window.js +0 -8
  354. package/dist/host/opencli.d.ts +0 -37
  355. package/dist/host/opencli.js +0 -155
  356. package/dist/host/unit-declaration.d.ts +0 -65
  357. package/dist/host/unit-declaration.js +0 -213
  358. package/dist/host/unit-libs.d.ts +0 -37
  359. package/dist/lib/diy-debug.d.ts +0 -80
  360. package/dist/lib/diy-debug.js +0 -88
  361. package/dist/lib/diy-record.d.ts +0 -135
  362. package/dist/lib/diy-record.js +0 -162
  363. package/dist/lib/lint-probe.d.ts +0 -1
  364. package/dist/lib/lint-probe.js +0 -6
  365. package/dist/lib/panel-state.d.ts +0 -120
  366. package/dist/lib/panel-state.js +0 -176
  367. package/src/api/__tests__/host-write.test.ts +0 -75
  368. package/src/api/__tests__/unit-board.test.ts +0 -76
  369. package/src/api/__tests__/unit.test.ts +0 -38
  370. package/src/api/unit-board.ts +0 -69
  371. package/src/api/unit.ts +0 -93
  372. package/src/api/workbench-contract.ts +0 -59
  373. package/src/host/__tests__/browser-find.test.ts +0 -330
  374. package/src/host/__tests__/browser-read.test.ts +0 -228
  375. package/src/host/__tests__/opencli-runtime.test.ts +0 -46
  376. package/src/host/browser-find.ts +0 -311
  377. package/src/host/browser-read.ts +0 -311
  378. package/src/host/opencli-runtime.ts +0 -79
  379. package/src/host/opencli-window.ts +0 -11
  380. package/src/host/opencli.ts +0 -213
  381. package/src/host/unit-libs.ts +0 -41
  382. package/src/lib/blocker-action.test.ts +0 -40
  383. /package/dist/{api/blocker.js → contract/adapters.js} +0 -0
  384. /package/dist/{api → contract}/blocker.d.ts +0 -0
  385. /package/dist/{api/dsh-client.js → contract/blocker.js} +0 -0
  386. /package/dist/{api/workbench-contract.js → contract/cli.js} +0 -0
  387. /package/dist/{host/unit-libs.js → contract/data.js} +0 -0
  388. /package/dist/{api → contract}/long-task.d.ts +0 -0
  389. /package/dist/{api → contract}/long-task.js +0 -0
  390. /package/src/{api → contract}/blocker.ts +0 -0
  391. /package/src/{api → contract}/long-task.ts +0 -0
@@ -1,44 +0,0 @@
1
- import type { PluginRelease } from '../api/unit.js';
2
- /**
3
- * 供给动作的那几档(装 / 升 / 卸,模块、共用依赖与插件各一套);写口按它分派。
4
- */
5
- export type ProvisionAction = 'install' | 'update' | 'uninstall' | 'update-dependency' | 'install-bundle' | 'update-bundle' | 'remove-bundle' | 'cancel-install' | 'update-plugin' | 'uninstall-plugin' | 'update-workbench';
6
- /**
7
- * 宿主报的一个 opencli 插件此刻的状态:装没装、缺哪些命令、该不该升,以及怎么升。
8
- */
9
- export interface PluginStatePayload {
10
- readonly name: string;
11
- readonly status: 'ok' | 'outdated' | 'missing';
12
- readonly missing: readonly string[];
13
- readonly install?: 'ready' | 'not-declared' | 'env-missing' | 'malformed';
14
- readonly command?: string;
15
- readonly release?: PluginRelease;
16
- }
17
- /**
18
- * 宿主对「这个单元现在能不能用」的那份读数:状态、缺的命令与插件、修复动作和供给细节。
19
- */
20
- export interface CapabilityPayload {
21
- readonly unit: string;
22
- readonly status: 'ok' | 'failed' | 'missing-commands' | 'missing-plugin' | 'unchecked';
23
- readonly plugin?: string;
24
- readonly required: readonly string[];
25
- readonly missing: readonly string[];
26
- readonly detail: string;
27
- readonly command?: string;
28
- readonly fix?: 'install' | 'update';
29
- readonly plugins?: readonly PluginStatePayload[];
30
- readonly released?: boolean;
31
- readonly install?: 'ready' | 'not-declared' | 'env-missing' | 'malformed';
32
- readonly libs?: readonly LibStatePayload[];
33
- }
34
- /**
35
- * 宿主报的一个共用库此刻的状态(装没装、版本对不对)与它为什么要这个版本。
36
- */
37
- export interface LibStatePayload {
38
- readonly name: string;
39
- readonly purpose: string;
40
- readonly status: 'ok' | 'outdated' | 'missing' | 'unsatisfied';
41
- readonly installed?: string;
42
- readonly latest?: string;
43
- readonly command?: string;
44
- }
@@ -1,39 +0,0 @@
1
-
2
- .wb-mockStrip {
3
- display: flex;
4
- flex-wrap: wrap;
5
- gap: var(--wb-len-4);
6
- padding: var(--wb-len-8) var(--wb-len-12);
7
- border-bottom: 0.5px solid var(--dsw-alias-border-l2);
8
- flex: none;
9
- }
10
-
11
- .wb-mockNote {
12
- flex: 1 0 100%;
13
- font-size: var(--wb-font-10);
14
- line-height: var(--wb-line-14);
15
- color: var(--dsw-alias-label-tertiary);
16
- }
17
-
18
- .wb-mockChip {
19
- flex: none;
20
- padding: var(--wb-len-2) var(--wb-len-7);
21
- border: 0.5px solid var(--dsw-alias-border-l2);
22
- border-radius: var(--wb-radius-pill);
23
- corner-shape: round;
24
- background: transparent;
25
- font-size: var(--wb-font-10);
26
- line-height: var(--wb-line-14);
27
- color: var(--dsw-alias-label-secondary);
28
- cursor: pointer;
29
- }
30
-
31
- .wb-mockChip:hover {
32
- color: var(--dsw-alias-label-primary);
33
- }
34
-
35
- .wb-mockChipOn {
36
- border-color: transparent;
37
- background: var(--dsw-alias-brand-primary);
38
- color: var(--dsw-alias-label-primary-foreground);
39
- }
@@ -1,15 +0,0 @@
1
- import './MockStrip.css';
2
- export declare function MockStrip({ mocks, index, onPick, note, real, }: {
3
- readonly mocks: readonly {
4
- readonly id: string;
5
- readonly label: string;
6
- }[];
7
- readonly index: number;
8
- readonly onPick: (next: number) => void;
9
- readonly note?: string;
10
- readonly real?: {
11
- readonly label: string;
12
- readonly active: boolean;
13
- readonly onPick: () => void;
14
- } | undefined;
15
- }): JSX.Element;
@@ -1,8 +0,0 @@
1
- import { h } from '../lib/react.js';
2
- import './MockStrip.css';
3
- export function MockStrip({ mocks, index, onPick, note, real, }) {
4
- return (h("div", { className: "wb-mockStrip" },
5
- h("span", { className: "wb-mockNote" }, note ?? '夹具:只切状态,不发请求'),
6
- real === undefined ? null : (h("button", { type: "button", className: `wb-mockChip${real.active ? ' wb-mockChipOn' : ''}`, onClick: real.onPick }, real.label)),
7
- mocks.map((mock, at) => (h("button", { key: mock.id, type: "button", className: `wb-mockChip${at === index ? ' wb-mockChipOn' : ''}`, onClick: () => onPick(at) }, mock.label)))));
8
- }
@@ -1,7 +0,0 @@
1
-
2
- .wb-formActions {
3
- display: flex;
4
- align-items: center;
5
- justify-content: flex-end;
6
- gap: var(--wb-len-8);
7
- }
@@ -1,38 +0,0 @@
1
- import type { DshShell } from '../api/dsh.js';
2
- export interface BrowserFindEntry {
3
- readonly text: string;
4
- readonly tag: string;
5
- readonly nth: number;
6
- }
7
- export interface BrowserFindResult {
8
- readonly ok: boolean;
9
- readonly code: string;
10
- readonly at: number;
11
- readonly entries: readonly BrowserFindEntry[];
12
- readonly count: number;
13
- readonly message: string;
14
- readonly hint?: string;
15
- readonly detail?: string;
16
- readonly helpUrl?: string;
17
- }
18
- export interface BrowserFindOptions {
19
- readonly shell: DshShell;
20
- readonly css: string;
21
- readonly url?: string;
22
- readonly command?: string;
23
- readonly session?: string;
24
- readonly limit?: number;
25
- readonly textMax?: number;
26
- readonly open?: boolean;
27
- readonly timeoutMs?: number;
28
- readonly settleMs?: number;
29
- }
30
- export declare function cellRowsOf(entries: readonly {
31
- readonly text?: string;
32
- }[], minCells?: number): string[][];
33
- export declare function cellRows(text: string): string[];
34
- export declare function entriesOf(value: unknown): BrowserFindEntry[];
35
- export declare function reasonOf(stdout: string, stderr: string): string;
36
- export declare function sameOrigin(left: string, right: string): boolean;
37
- export declare function urlOf(stdout: string): string;
38
- export declare function browserFind(options: BrowserFindOptions): Promise<BrowserFindResult>;
@@ -1,242 +0,0 @@
1
- import { parseJsonLoose } from '../lib/text.js';
2
- import { BROWSER_READ_SESSION } from './browser-read.js';
3
- import { backgroundLine } from './opencli-window.js';
4
- import { runShell } from './shell.js';
5
- const DEFAULT_TIMEOUT_MS = 25000;
6
- const DEFAULT_SETTLE_MS = 2500;
7
- const URL_TIMEOUT_MS = 8000;
8
- const DEFAULT_LIMIT = 50;
9
- const DEFAULT_TEXT_MAX = 200;
10
- export function cellRowsOf(entries, minCells = 2) {
11
- const rows = [];
12
- for (const entry of entries) {
13
- const text = typeof entry?.text === 'string' ? entry.text : '';
14
- const cells = text
15
- .split('\n')
16
- .map((one) => one.trim())
17
- .filter((one) => one !== '');
18
- if (cells.length >= minCells)
19
- rows.push(cells);
20
- }
21
- return rows;
22
- }
23
- export function cellRows(text) {
24
- return text
25
- .split('\n')
26
- .map((one) => one.trim())
27
- .filter((one) => one !== '');
28
- }
29
- function asRecord(value) {
30
- return typeof value === 'object' && value !== null ? value : undefined;
31
- }
32
- function textOf(value) {
33
- return typeof value === 'string' ? value.trim() : '';
34
- }
35
- export function entriesOf(value) {
36
- const record = asRecord(value);
37
- const raw = record === undefined ? undefined : record['entries'];
38
- if (!Array.isArray(raw))
39
- return [];
40
- const entries = [];
41
- for (const one of raw) {
42
- const item = asRecord(one);
43
- if (item === undefined)
44
- continue;
45
- const nth = typeof item['nth'] === 'number' ? item['nth'] : entries.length;
46
- entries.push({ text: textOf(item['text']), tag: textOf(item['tag']), nth });
47
- }
48
- return entries;
49
- }
50
- export function reasonOf(stdout, stderr) {
51
- const parsed = asRecord(parseJsonLoose(stdout));
52
- const error = parsed === undefined ? undefined : asRecord(parsed['error']);
53
- const message = error === undefined ? '' : textOf(error['message']);
54
- if (message !== '')
55
- return message;
56
- const source = stderr.trim() === '' ? stdout : stderr;
57
- const lines = source
58
- .split('\n')
59
- .map((one) => one.trim())
60
- .filter((one) => one !== '');
61
- return (lines[lines.length - 1] ?? '').slice(-200);
62
- }
63
- function hintOf(stdout) {
64
- const parsed = asRecord(parseJsonLoose(stdout));
65
- const error = parsed === undefined ? undefined : asRecord(parsed['error']);
66
- const hint = error === undefined ? '' : textOf(error['hint']);
67
- return hint === '' ? undefined : hint;
68
- }
69
- export function sameOrigin(left, right) {
70
- try {
71
- return new URL(left).origin === new URL(right).origin;
72
- }
73
- catch {
74
- return false;
75
- }
76
- }
77
- export function urlOf(stdout) {
78
- const lines = stdout
79
- .split('\n')
80
- .map((one) => one.trim())
81
- .filter((one) => one !== '');
82
- const first = (lines[0] ?? '').replace(/^url:\s*/i, '').trim();
83
- const bare = first.replace(/^["']+|["']+$/g, '');
84
- if (bare.startsWith('{')) {
85
- const parsed = asRecord(parseJsonLoose(bare));
86
- const url = parsed === undefined ? '' : textOf(parsed['url']);
87
- if (url !== '')
88
- return url;
89
- }
90
- return bare;
91
- }
92
- async function currentUrl(shell, command, session) {
93
- const line = backgroundLine(command, ['browser', session, 'get', 'url', '--window', 'background']);
94
- try {
95
- const result = await runShell(shell, line, { timeoutMs: URL_TIMEOUT_MS });
96
- if (result.exitCode !== 0)
97
- return '';
98
- return urlOf(result.stdout);
99
- }
100
- catch {
101
- return '';
102
- }
103
- }
104
- function sleep(ms) {
105
- return new Promise((resolve) => setTimeout(resolve, ms));
106
- }
107
- async function findOnce(shell, command, session, css, limit, textMax, timeoutMs) {
108
- const line = backgroundLine(command, [
109
- 'browser',
110
- session,
111
- 'find',
112
- '--css',
113
- css,
114
- '--limit',
115
- String(limit),
116
- '--text-max',
117
- String(textMax),
118
- '--window',
119
- 'background',
120
- ]);
121
- const result = await runShell(shell, line, { timeoutMs });
122
- if (result.timedOut) {
123
- return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回` };
124
- }
125
- if (result.exitCode !== 0) {
126
- return {
127
- kind: 'failed',
128
- detail: reasonOf(result.stdout, result.stderr),
129
- ...(hintOf(result.stdout) === undefined ? {} : { hint: hintOf(result.stdout) }),
130
- };
131
- }
132
- const entries = entriesOf(parseJsonLoose(result.stdout));
133
- return { kind: 'ok', entries, stdout: result.stdout };
134
- }
135
- async function openOnce(shell, command, session, url, timeoutMs) {
136
- const line = backgroundLine(command, ['browser', session, 'open', url, '--window', 'background']);
137
- let result;
138
- try {
139
- result = await runShell(shell, line, { timeoutMs });
140
- }
141
- catch (error) {
142
- return error instanceof Error ? error.message : String(error);
143
- }
144
- if (result.timedOut)
145
- return `没在 ${Math.round(timeoutMs / 1000)} 秒内打开`;
146
- if (result.exitCode !== 0) {
147
- const reason = reasonOf(result.stdout, result.stderr);
148
- return reason === '' ? `opencli 打开失败(退出码 ${String(result.exitCode ?? '?')})` : reason;
149
- }
150
- return undefined;
151
- }
152
- export async function browserFind(options) {
153
- const { shell, css, url, open = true } = options;
154
- const command = options.command ?? 'opencli';
155
- const session = options.session ?? BROWSER_READ_SESSION;
156
- const limit = options.limit ?? DEFAULT_LIMIT;
157
- const textMax = options.textMax ?? DEFAULT_TEXT_MAX;
158
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
159
- const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
160
- const at = Date.now();
161
- const find = async () => {
162
- try {
163
- return await findOnce(shell, command, session, css, limit, textMax, timeoutMs);
164
- }
165
- catch (error) {
166
- return {
167
- kind: 'failed',
168
- detail: error instanceof Error ? error.message : String(error),
169
- hint: '确认这台机器上 opencli 能跑(工作台会自己把它挂好)',
170
- };
171
- }
172
- };
173
- const canMove = open && url !== undefined;
174
- if (canMove) {
175
- const here = await currentUrl(shell, command, session);
176
- if (here !== '' && !sameOrigin(here, url)) {
177
- const opened = await openOnce(shell, command, session, url, timeoutMs);
178
- if (opened !== undefined) {
179
- return {
180
- ok: false,
181
- code: 'cli-exec-failed',
182
- at,
183
- entries: [],
184
- count: 0,
185
- message: '打不开那个页面',
186
- hint: '在浏览器里手动打开一次,然后重试',
187
- detail: opened,
188
- helpUrl: url,
189
- };
190
- }
191
- await sleep(settleMs);
192
- }
193
- }
194
- let outcome = await find();
195
- if (outcome === undefined) {
196
- return { ok: false, code: 'cli-exec-failed', at, entries: [], count: 0, message: '没找到元素' };
197
- }
198
- if (outcome.kind === 'failed' && canMove) {
199
- const opened = await openOnce(shell, command, session, url, timeoutMs);
200
- if (opened === undefined) {
201
- await sleep(settleMs);
202
- const second = await find();
203
- if (second !== undefined)
204
- outcome = second;
205
- }
206
- }
207
- if (outcome.kind === 'timeout') {
208
- return {
209
- ok: false,
210
- code: 'cli-timeout',
211
- at,
212
- entries: [],
213
- count: 0,
214
- message: '这次没找到元素(等超时了)',
215
- hint: '稍后重试',
216
- detail: outcome.detail,
217
- ...(url === undefined ? {} : { helpUrl: url }),
218
- };
219
- }
220
- if (outcome.kind === 'failed') {
221
- const detail = outcome.detail;
222
- return {
223
- ok: false,
224
- code: 'cli-exec-failed',
225
- at,
226
- entries: [],
227
- count: 0,
228
- message: detail === '' ? '没找到元素(opencli 命令失败)' : `没找到元素:${detail}`,
229
- ...(outcome.hint === undefined ? {} : { hint: outcome.hint }),
230
- ...(detail === '' ? {} : { detail }),
231
- ...(url === undefined ? {} : { helpUrl: url }),
232
- };
233
- }
234
- return {
235
- ok: true,
236
- code: 'ok',
237
- at,
238
- entries: outcome.entries,
239
- count: outcome.entries.length,
240
- message: outcome.entries.length === 0 ? '页面上没有匹配的元素' : `找到 ${String(outcome.entries.length)} 个元素`,
241
- };
242
- }
@@ -1,28 +0,0 @@
1
- import type { DshShell } from '../api/dsh.js';
2
- export declare const BROWSER_SCREEN_SESSION = "workbench";
3
- export declare const BROWSER_READ_SESSION = "workbench-read";
4
- export declare const BROWSER_RECORD_SESSION = "workbench-rec";
5
- export interface BrowserReadResult {
6
- readonly ok: boolean;
7
- readonly code: string;
8
- readonly at: number;
9
- readonly value?: unknown;
10
- readonly pageCode?: string;
11
- readonly message: string;
12
- readonly hint?: string;
13
- readonly detail?: string;
14
- readonly helpUrl?: string;
15
- }
16
- export interface BrowserReadOptions {
17
- readonly shell: DshShell;
18
- readonly script: string;
19
- readonly url?: string;
20
- readonly loginUrl?: string;
21
- readonly command?: string;
22
- readonly session?: string;
23
- readonly open?: boolean;
24
- readonly timeoutMs?: number;
25
- readonly retryMs?: number;
26
- readonly settleMs?: number;
27
- }
28
- export declare function browserRead(options: BrowserReadOptions): Promise<BrowserReadResult>;
@@ -1,243 +0,0 @@
1
- import { parseJsonLoose } from '../lib/text.js';
2
- import { tailLines } from './shell-text.js';
3
- import { backgroundLine } from './opencli-window.js';
4
- import { runShell } from './shell.js';
5
- export const BROWSER_SCREEN_SESSION = 'workbench';
6
- export const BROWSER_READ_SESSION = 'workbench-read';
7
- export const BROWSER_RECORD_SESSION = 'workbench-rec';
8
- const DEFAULT_TIMEOUT_MS = 25000;
9
- const DEFAULT_RETRY_MS = 1200;
10
- const DEFAULT_SETTLE_MS = 900;
11
- const AUTH_CODES = new Set([
12
- 'NOT_LOGGED_IN',
13
- 'NOT_LOGIN',
14
- 'AUTH_FAILED',
15
- 'AUTH_REQUIRED',
16
- 'UNAUTHENTICATED',
17
- 'UNAUTHORIZED',
18
- 'TOKEN_EXPIRED',
19
- ]);
20
- const PERMISSION_CODES = new Set(['FORBIDDEN', 'PERMISSION_DENIED', 'NO_PERMISSION', 'EACCES']);
21
- function asRecord(value) {
22
- return typeof value === 'object' && value !== null ? value : undefined;
23
- }
24
- function textOf(value) {
25
- return typeof value === 'string' ? value.trim() : '';
26
- }
27
- function codeOf(page) {
28
- const record = asRecord(page);
29
- return record === undefined ? '' : textOf(record['code']);
30
- }
31
- function messageOf(page) {
32
- const record = asRecord(page);
33
- return record === undefined ? '' : textOf(record['message']);
34
- }
35
- function hintOf(page) {
36
- const record = asRecord(page);
37
- const hint = record === undefined ? '' : textOf(record['hint']);
38
- return hint === '' ? undefined : hint;
39
- }
40
- function pageFailed(page) {
41
- const record = asRecord(page);
42
- return record !== undefined && record['ok'] === false;
43
- }
44
- function blockerFor(code) {
45
- const normalized = code.trim().toUpperCase().replace(/-/g, '_');
46
- if (normalized === '')
47
- return undefined;
48
- const matches = (set) => [...set].some((one) => normalized === one || normalized.endsWith(`_${one}`));
49
- if (matches(PERMISSION_CODES))
50
- return 'permission-denied';
51
- if (matches(AUTH_CODES) || normalized.includes('UNAUTH'))
52
- return 'auth-required';
53
- return undefined;
54
- }
55
- function sleep(ms) {
56
- return new Promise((resolve) => setTimeout(resolve, ms));
57
- }
58
- async function shellRun(shell, command, argv, timeoutMs) {
59
- const result = await runShell(shell, backgroundLine(command, argv), { timeoutMs });
60
- if (result.timedOut) {
61
- return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回`, stderr: result.stderr };
62
- }
63
- if (result.exitCode !== 0) {
64
- return { kind: 'failed', detail: tailLines(result.stderr || result.stdout, 4), stderr: result.stderr };
65
- }
66
- return { kind: 'ok', stdout: result.stdout };
67
- }
68
- async function evalOnce(shell, command, session, script, timeoutMs, retryMs) {
69
- const run = async () => {
70
- let attempt;
71
- try {
72
- attempt = await shellRun(shell, command, ['browser', session, 'eval', script, '--window', 'background'], timeoutMs);
73
- }
74
- catch (error) {
75
- return {
76
- kind: 'failure',
77
- result: {
78
- ok: false,
79
- code: 'cli-exec-failed',
80
- message: '读不了:opencli 起不来',
81
- hint: '确认这台机器上 opencli 能跑(工作台会自己把它挂好)',
82
- detail: error instanceof Error ? error.message : String(error),
83
- },
84
- };
85
- }
86
- if (attempt.kind === 'timeout') {
87
- return {
88
- kind: 'failure',
89
- result: {
90
- ok: false,
91
- code: 'cli-timeout',
92
- message: '这次没读到(等超时了)',
93
- hint: '稍后重试',
94
- detail: attempt.detail,
95
- },
96
- };
97
- }
98
- if (attempt.kind === 'failed') {
99
- const normalized = attempt.stderr.trim().toUpperCase().replace(/-/g, '_');
100
- const forbidden = [...PERMISSION_CODES].some((one) => normalized.includes(one));
101
- return {
102
- kind: 'failure',
103
- result: {
104
- ok: false,
105
- code: forbidden ? 'permission-denied' : 'cli-exec-failed',
106
- message: forbidden ? '没有权限在这台机器上读' : '读不了(命令失败)',
107
- hint: forbidden ? '换一个有权限的账号,或让用户开权限' : '把下面这段原始输出看一眼再重试',
108
- detail: attempt.detail,
109
- },
110
- };
111
- }
112
- const value = parseJsonLoose(attempt.stdout);
113
- if (value === undefined) {
114
- return {
115
- kind: 'failure',
116
- result: {
117
- ok: false,
118
- code: 'cli-exec-failed',
119
- message: '读到了、但不是 JSON',
120
- hint: '脚本必须回 JSON',
121
- detail: tailLines(attempt.stdout, 4),
122
- },
123
- };
124
- }
125
- return { kind: 'value', value };
126
- };
127
- const first = await run();
128
- if (first.kind === 'value')
129
- return first;
130
- if (first.result.code !== 'cli-exec-failed')
131
- return first;
132
- await sleep(retryMs);
133
- return run();
134
- }
135
- async function openOnce(shell, command, session, url, timeoutMs) {
136
- let attempt;
137
- try {
138
- attempt = await shellRun(shell, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs);
139
- }
140
- catch (error) {
141
- return {
142
- ok: false,
143
- code: 'cli-exec-failed',
144
- message: '打不开那个页面',
145
- hint: '确认 opencli 能跑起来',
146
- detail: error instanceof Error ? error.message : String(error),
147
- helpUrl: url,
148
- };
149
- }
150
- if (attempt.kind === 'ok')
151
- return undefined;
152
- return {
153
- ok: false,
154
- code: attempt.kind === 'timeout' ? 'cli-timeout' : 'cli-exec-failed',
155
- message: '打不开那个页面',
156
- hint: '在浏览器里手动打开一次,然后重试',
157
- detail: attempt.detail,
158
- helpUrl: url,
159
- };
160
- }
161
- export async function browserRead(options) {
162
- const { shell, script, url, loginUrl, open = true } = options;
163
- const command = options.command ?? 'opencli';
164
- const session = options.session ?? BROWSER_READ_SESSION;
165
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
166
- const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
167
- const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
168
- const at = Date.now();
169
- const first = await evalOnce(shell, command, session, script, timeoutMs, retryMs);
170
- if (first.kind === 'failure')
171
- return { ...first.result, at };
172
- let page = first.value;
173
- if (codeOf(page) === 'not-on-site') {
174
- if (!open || url === undefined) {
175
- return {
176
- ok: false,
177
- code: 'cli-exec-failed',
178
- at,
179
- message: '没停在那套系统上',
180
- hint: '先在那个浏览器里把它打开,再读一次',
181
- detail: JSON.stringify(page),
182
- ...(url === undefined ? {} : { helpUrl: url }),
183
- };
184
- }
185
- const opened = await openOnce(shell, command, session, url, timeoutMs);
186
- if (opened !== undefined)
187
- return { ...opened, at };
188
- await sleep(settleMs);
189
- const second = await evalOnce(shell, command, session, script, timeoutMs, retryMs);
190
- if (second.kind === 'failure')
191
- return { ...second.result, at };
192
- page = second.value;
193
- if (codeOf(page) === 'not-on-site') {
194
- return {
195
- ok: false,
196
- code: 'cli-exec-failed',
197
- at,
198
- message: '打开了页面、又读了一遍,仍然不在那套系统上',
199
- hint: '确认这个地址就是那套系统(或者它跳到了别的域)',
200
- detail: JSON.stringify(page),
201
- helpUrl: url,
202
- };
203
- }
204
- }
205
- if (!pageFailed(page))
206
- return { ok: true, code: 'ok', at, value: page, message: '读到了' };
207
- const pageCode = codeOf(page) || 'read-failed';
208
- const message = messageOf(page) || `读不到(${pageCode})`;
209
- const blocker = blockerFor(pageCode);
210
- if (blocker === 'auth-required') {
211
- return {
212
- ok: false,
213
- code: blocker,
214
- at,
215
- pageCode,
216
- message,
217
- hint: '去登录一次,再重试',
218
- detail: JSON.stringify(page),
219
- ...(loginUrl === undefined && url === undefined ? {} : { helpUrl: loginUrl ?? url }),
220
- };
221
- }
222
- if (blocker === 'permission-denied') {
223
- return {
224
- ok: false,
225
- code: blocker,
226
- at,
227
- pageCode,
228
- message,
229
- hint: '这个账号没有权限',
230
- detail: JSON.stringify(page),
231
- ...(loginUrl === undefined && url === undefined ? {} : { helpUrl: loginUrl ?? url }),
232
- };
233
- }
234
- return {
235
- ok: false,
236
- code: pageCode,
237
- at,
238
- pageCode,
239
- message,
240
- detail: JSON.stringify(page),
241
- ...(hintOf(page) === undefined ? {} : { hint: hintOf(page) }),
242
- };
243
- }