@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-rc.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 (344) hide show
  1. package/dist/components/Activity.css +69 -0
  2. package/dist/components/Activity.d.ts +56 -0
  3. package/dist/components/Activity.js +47 -0
  4. package/dist/components/ApprovalDetail.css +3 -0
  5. package/dist/components/ApprovalDetail.d.ts +42 -0
  6. package/dist/components/ApprovalDetail.js +53 -0
  7. package/dist/components/ApprovalPlan.css +39 -0
  8. package/dist/components/ApprovalPlan.d.ts +27 -0
  9. package/dist/components/ApprovalPlan.js +19 -0
  10. package/dist/components/Card.css +19 -0
  11. package/dist/components/Card.d.ts +26 -0
  12. package/dist/components/Card.js +18 -0
  13. package/dist/components/CardAnchor.d.ts +21 -0
  14. package/dist/components/CardAnchor.js +19 -0
  15. package/dist/components/CardAnchor.module.css +3 -0
  16. package/dist/components/CardBoundary.d.ts +42 -0
  17. package/dist/components/CardBoundary.js +58 -0
  18. package/dist/components/CardBoundary.module.css +5 -0
  19. package/dist/components/CardHead.css +87 -0
  20. package/dist/components/CardHead.d.ts +30 -0
  21. package/dist/components/CardHead.js +27 -0
  22. package/dist/components/ChoiceGroup.css +182 -0
  23. package/dist/components/ChoiceGroup.d.ts +54 -0
  24. package/dist/components/ChoiceGroup.js +63 -0
  25. package/dist/components/ConfirmBar.css +26 -0
  26. package/dist/components/ConfirmBar.d.ts +36 -0
  27. package/dist/components/ConfirmBar.js +26 -0
  28. package/dist/components/EmptyIllustration.d.ts +12 -0
  29. package/dist/components/EmptyIllustration.js +32 -0
  30. package/dist/components/Field.css +20 -0
  31. package/dist/components/Field.d.ts +18 -0
  32. package/dist/components/Field.js +15 -0
  33. package/dist/components/Form.css +6 -0
  34. package/dist/components/Form.d.ts +22 -0
  35. package/dist/components/Form.js +60 -0
  36. package/dist/components/FormActions.css +13 -0
  37. package/dist/components/FormActions.d.ts +29 -0
  38. package/dist/components/FormActions.js +43 -0
  39. package/dist/components/FormNodes.d.ts +107 -0
  40. package/dist/components/FormNodes.js +165 -0
  41. package/dist/components/FormRows.css +107 -0
  42. package/dist/components/FormRows.d.ts +36 -0
  43. package/dist/components/FormRows.js +26 -0
  44. package/dist/components/FormTypes.d.ts +84 -0
  45. package/dist/components/FormTypes.js +1 -0
  46. package/dist/components/Link.css +22 -0
  47. package/dist/components/Link.d.ts +22 -0
  48. package/dist/components/Link.js +17 -0
  49. package/dist/components/LongTaskRow.css +171 -0
  50. package/dist/components/LongTaskRow.d.ts +94 -0
  51. package/dist/components/LongTaskRow.js +103 -0
  52. package/dist/components/Note.css +13 -0
  53. package/dist/components/Note.d.ts +20 -0
  54. package/dist/components/Note.js +14 -0
  55. package/dist/components/ResourceStates.css +114 -0
  56. package/dist/components/ResourceStates.d.ts +44 -0
  57. package/dist/components/ResourceStates.js +41 -0
  58. package/dist/components/Rows.css +42 -0
  59. package/dist/components/Rows.d.ts +28 -0
  60. package/dist/components/Rows.js +21 -0
  61. package/dist/components/SaveBar.d.ts +24 -0
  62. package/dist/components/SaveBar.js +25 -0
  63. package/dist/components/SelectField.css +182 -0
  64. package/dist/components/SelectField.d.ts +89 -0
  65. package/dist/components/SelectField.js +260 -0
  66. package/dist/components/SelectFieldNodes.d.ts +49 -0
  67. package/dist/components/SelectFieldNodes.js +43 -0
  68. package/dist/components/SettingsSection.css +25 -0
  69. package/dist/components/SettingsSection.d.ts +20 -0
  70. package/dist/components/SettingsSection.js +17 -0
  71. package/dist/components/SetupShell.d.ts +93 -0
  72. package/dist/components/SetupShell.js +64 -0
  73. package/dist/components/SetupShell.module.css +81 -0
  74. package/dist/components/Spinner.css +5 -0
  75. package/dist/components/Spinner.d.ts +15 -0
  76. package/dist/components/Spinner.js +13 -0
  77. package/dist/components/Stack.css +6 -0
  78. package/dist/components/Stack.d.ts +14 -0
  79. package/dist/components/Stack.js +10 -0
  80. package/dist/components/StateBlock.css +38 -0
  81. package/dist/components/StateBlock.d.ts +24 -0
  82. package/dist/components/StateBlock.js +22 -0
  83. package/dist/components/TextField.css +32 -0
  84. package/dist/components/TextField.d.ts +14 -0
  85. package/dist/components/TextField.js +10 -0
  86. package/dist/components/board-module.d.ts +307 -0
  87. package/dist/components/board-module.js +1 -0
  88. package/dist/components/card-view-validate.d.ts +5 -0
  89. package/dist/components/card-view-validate.js +256 -0
  90. package/dist/components/icons.d.ts +63 -0
  91. package/dist/components/icons.js +107 -0
  92. package/dist/components/layout/icon-command.d.ts +8 -0
  93. package/dist/components/layout/icon-command.js +21 -0
  94. package/dist/contract/capture.d.ts +16 -0
  95. package/dist/contract/capture.js +1 -0
  96. package/dist/contract/diagnostics.d.ts +34 -0
  97. package/dist/contract/diagnostics.js +124 -0
  98. package/dist/contract/needs.d.ts +3 -1
  99. package/dist/contract/needs.js +4 -2
  100. package/dist/contract/protocol/bundle-install.d.ts +1 -1
  101. package/dist/contract/protocol/unit-manager.d.ts +50 -0
  102. package/dist/contract/protocol/unit-manager.js +2 -0
  103. package/dist/contract/unit.js +2 -1
  104. package/dist/host/adapter-contract.d.ts +3 -0
  105. package/dist/host/adapter-contract.js +95 -0
  106. package/dist/host/adapter-set.d.ts +27 -0
  107. package/dist/host/adapter-set.js +258 -0
  108. package/dist/host/adapter-types.d.ts +87 -0
  109. package/dist/host/adapter-types.js +23 -0
  110. package/dist/host/adapters/platform.d.ts +14 -0
  111. package/dist/host/adapters/platform.js +40 -0
  112. package/dist/host/adapters.d.ts +28 -0
  113. package/dist/host/adapters.js +9 -0
  114. package/dist/host/auth-loss.d.ts +33 -0
  115. package/dist/host/auth-loss.js +107 -0
  116. package/dist/host/board-fact.d.ts +8 -0
  117. package/dist/host/board-fact.js +16 -0
  118. package/dist/host/boot-record.d.ts +11 -0
  119. package/dist/host/boot-record.js +31 -0
  120. package/dist/host/browser.d.ts +3 -0
  121. package/dist/host/browser.js +3 -0
  122. package/dist/host/bundle-manager.d.ts +4 -0
  123. package/dist/host/bundle-manager.js +338 -0
  124. package/dist/host/changelog.d.ts +28 -0
  125. package/dist/host/changelog.js +201 -0
  126. package/dist/host/cli-error.d.ts +8 -0
  127. package/dist/host/cli-error.js +70 -0
  128. package/dist/host/cli.d.ts +4 -0
  129. package/dist/host/cli.js +9 -0
  130. package/dist/host/config-sync.d.ts +40 -0
  131. package/dist/host/config-sync.js +267 -0
  132. package/dist/host/context-ref.d.ts +13 -0
  133. package/dist/host/context-ref.js +41 -0
  134. package/dist/host/data-error.d.ts +15 -0
  135. package/dist/host/data-error.js +23 -0
  136. package/dist/host/data-plan-check.d.ts +10 -0
  137. package/dist/host/data-plan-check.js +315 -0
  138. package/dist/host/data-plan.d.ts +15 -0
  139. package/dist/host/data-plan.js +283 -0
  140. package/dist/host/data-root.d.ts +5 -0
  141. package/dist/host/data-root.js +23 -0
  142. package/dist/host/diy-debug.d.ts +80 -0
  143. package/dist/host/diy-debug.js +89 -0
  144. package/dist/host/diy-preset.d.ts +26 -0
  145. package/dist/host/diy-preset.js +115 -0
  146. package/dist/host/diy-record.d.ts +135 -0
  147. package/dist/host/diy-record.js +163 -0
  148. package/dist/host/dsh-compat.d.ts +27 -0
  149. package/dist/host/dsh-compat.js +75 -0
  150. package/dist/host/dsh-plugins.d.ts +5 -0
  151. package/dist/host/dsh-plugins.js +51 -0
  152. package/dist/host/env-policy.d.ts +82 -0
  153. package/dist/host/env-policy.js +181 -0
  154. package/dist/host/extension.d.ts +7 -0
  155. package/dist/host/extension.js +40 -0
  156. package/dist/host/facts.d.ts +31 -0
  157. package/dist/host/facts.js +58 -0
  158. package/dist/host/fs-write.d.ts +96 -0
  159. package/dist/host/fs-write.js +183 -0
  160. package/dist/host/git.d.ts +5 -0
  161. package/dist/host/git.js +1 -0
  162. package/dist/host/host-actions.d.ts +2 -0
  163. package/dist/host/host-actions.js +5 -0
  164. package/dist/host/host-kit.d.ts +37 -0
  165. package/dist/host/host-kit.js +27 -0
  166. package/dist/host/http.d.ts +47 -0
  167. package/dist/host/http.js +289 -0
  168. package/dist/host/install-failure.d.ts +50 -0
  169. package/dist/host/install-failure.js +184 -0
  170. package/dist/host/installed-module.d.ts +25 -0
  171. package/dist/host/installed-module.js +289 -0
  172. package/dist/host/installed-sources.d.ts +10 -0
  173. package/dist/host/installed-sources.js +63 -0
  174. package/dist/host/lease.d.ts +70 -0
  175. package/dist/host/lease.js +264 -0
  176. package/dist/host/lib-capabilities.d.ts +22 -0
  177. package/dist/host/lib-capabilities.js +37 -0
  178. package/dist/host/lib-install.d.ts +19 -0
  179. package/dist/host/lib-install.js +40 -0
  180. package/dist/host/lib-runners.d.ts +18 -0
  181. package/dist/host/lib-runners.js +46 -0
  182. package/dist/host/local-declaration.d.ts +7 -0
  183. package/dist/host/local-declaration.js +33 -0
  184. package/dist/host/long-task.d.ts +97 -0
  185. package/dist/host/long-task.js +297 -0
  186. package/dist/host/market-index-claim.d.ts +19 -0
  187. package/dist/host/market-index-claim.js +87 -0
  188. package/dist/host/market-index-doc.d.ts +12 -0
  189. package/dist/host/market-index-doc.js +1 -0
  190. package/dist/host/market-index-parse.d.ts +28 -0
  191. package/dist/host/market-index-parse.js +413 -0
  192. package/dist/host/market-index.d.ts +13 -0
  193. package/dist/host/market-index.js +105 -0
  194. package/dist/host/module-root.d.ts +1 -0
  195. package/dist/host/module-root.js +5 -0
  196. package/dist/host/needs.d.ts +4 -0
  197. package/dist/host/needs.js +2 -0
  198. package/dist/host/npm-registry.d.ts +10 -0
  199. package/dist/host/npm-registry.js +16 -0
  200. package/dist/host/package-content.d.ts +8 -0
  201. package/dist/host/package-content.js +90 -0
  202. package/dist/host/package-kind.d.ts +13 -0
  203. package/dist/host/package-kind.js +51 -0
  204. package/dist/host/package-route.d.ts +33 -0
  205. package/dist/host/package-route.js +68 -0
  206. package/dist/host/panel-state.d.ts +120 -0
  207. package/dist/host/panel-state.js +177 -0
  208. package/dist/host/patch-blocks.d.ts +13 -0
  209. package/dist/host/patch-blocks.js +52 -0
  210. package/dist/host/patch.d.ts +4 -0
  211. package/dist/host/patch.js +7 -0
  212. package/dist/host/paths.d.ts +12 -0
  213. package/dist/host/paths.js +20 -0
  214. package/dist/host/payload.d.ts +12 -0
  215. package/dist/host/payload.js +16 -0
  216. package/dist/host/plan-results.d.ts +5 -0
  217. package/dist/host/plan-results.js +71 -0
  218. package/dist/host/plan-run.d.ts +41 -0
  219. package/dist/host/plan-run.js +87 -0
  220. package/dist/host/platform.d.ts +14 -0
  221. package/dist/host/platform.js +40 -0
  222. package/dist/host/plugin-ledger.d.ts +32 -0
  223. package/dist/host/plugin-ledger.js +106 -0
  224. package/dist/host/plugin.d.ts +3 -0
  225. package/dist/host/plugin.js +38 -0
  226. package/dist/host/port-types.d.ts +233 -0
  227. package/dist/host/port-types.js +1 -0
  228. package/dist/host/preflight.d.ts +32 -0
  229. package/dist/host/preflight.js +1 -0
  230. package/dist/host/process-alive.d.ts +6 -0
  231. package/dist/host/process-alive.js +16 -0
  232. package/dist/host/profile-bundles.d.ts +20 -0
  233. package/dist/host/profile-bundles.js +48 -0
  234. package/dist/host/profile-create.d.ts +19 -0
  235. package/dist/host/profile-create.js +124 -0
  236. package/dist/host/profile-port.d.ts +4 -0
  237. package/dist/host/profile-port.js +4 -0
  238. package/dist/host/profile-registries.d.ts +10 -0
  239. package/dist/host/profile-registries.js +149 -0
  240. package/dist/host/provision.d.ts +32 -0
  241. package/dist/host/provision.js +105 -0
  242. package/dist/host/read-json.d.ts +1 -0
  243. package/dist/host/read-json.js +11 -0
  244. package/dist/host/recipe-rules.d.ts +5 -0
  245. package/dist/host/recipe-rules.js +412 -0
  246. package/dist/host/recipe.d.ts +14 -0
  247. package/dist/host/recipe.js +332 -0
  248. package/dist/host/registry-declaration.d.ts +21 -0
  249. package/dist/host/registry-declaration.js +42 -0
  250. package/dist/host/reinstall-record.d.ts +16 -0
  251. package/dist/host/reinstall-record.js +54 -0
  252. package/dist/host/release-age.d.ts +24 -0
  253. package/dist/host/release-age.js +92 -0
  254. package/dist/host/release-packages.generated.d.ts +1 -0
  255. package/dist/host/release-packages.generated.js +10 -0
  256. package/dist/host/release-probe.d.ts +37 -0
  257. package/dist/host/release-probe.js +156 -0
  258. package/dist/host/runtime/browser-argv.d.ts +1 -0
  259. package/dist/host/runtime/browser-argv.js +9 -0
  260. package/dist/host/runtime/dsh-compat.d.ts +4 -0
  261. package/dist/host/runtime/dsh-compat.js +32 -16
  262. package/dist/host/runtime/front-app.d.ts +6 -0
  263. package/dist/host/runtime/front-app.js +70 -0
  264. package/dist/host/runtime/verified-dsh.d.ts +5 -0
  265. package/dist/host/runtime/verified-dsh.js +20 -0
  266. package/dist/host/shell-render.d.ts +52 -0
  267. package/dist/host/shell-render.js +117 -0
  268. package/dist/host/shell-text.d.ts +30 -0
  269. package/dist/host/shell-text.js +40 -0
  270. package/dist/host/shell.d.ts +25 -0
  271. package/dist/host/shell.js +55 -0
  272. package/dist/host/site.d.ts +45 -0
  273. package/dist/host/site.js +182 -0
  274. package/dist/host/spec.d.ts +8 -0
  275. package/dist/host/spec.js +24 -0
  276. package/dist/host/submit-confirm.d.ts +19 -0
  277. package/dist/host/submit-confirm.js +45 -0
  278. package/dist/host/supply/builtin-catalog.d.ts +3 -0
  279. package/dist/host/supply/builtin-catalog.js +38 -0
  280. package/dist/host/supply/preflight.d.ts +14 -1
  281. package/dist/host/supply/supply-index.js +6 -0
  282. package/dist/host/supply-index.d.ts +38 -0
  283. package/dist/host/supply-index.js +209 -0
  284. package/dist/host/supply-port.d.ts +5 -0
  285. package/dist/host/supply-port.js +50 -0
  286. package/dist/host/time.d.ts +22 -0
  287. package/dist/host/time.js +33 -0
  288. package/dist/host/tokens.d.ts +26 -0
  289. package/dist/host/tokens.js +154 -0
  290. package/dist/host/tool-approval.d.ts +86 -0
  291. package/dist/host/tool-approval.js +118 -0
  292. package/dist/host/tool-kit.d.ts +8 -0
  293. package/dist/host/tool-kit.js +22 -0
  294. package/dist/host/toolbox-port.d.ts +16 -0
  295. package/dist/host/toolbox-port.js +1 -0
  296. package/dist/host/unit-config.d.ts +34 -0
  297. package/dist/host/unit-config.js +28 -0
  298. package/dist/host/unit-data.d.ts +3 -0
  299. package/dist/host/unit-data.js +127 -0
  300. package/dist/host/unit-face.d.ts +95 -0
  301. package/dist/host/unit-face.js +1 -0
  302. package/dist/host/unit-plugin.d.ts +24 -0
  303. package/dist/host/unit-plugin.js +25 -0
  304. package/dist/host/update-journal-manifest.d.ts +19 -0
  305. package/dist/host/update-journal-manifest.js +134 -0
  306. package/dist/host/update-journal-types.d.ts +33 -0
  307. package/dist/host/update-journal-types.js +2 -0
  308. package/dist/host/update-journal.d.ts +43 -0
  309. package/dist/host/update-journal.js +409 -0
  310. package/dist/host/value-handoff.d.ts +16 -0
  311. package/dist/host/value-handoff.js +22 -0
  312. package/dist/host/version-range.d.ts +2 -0
  313. package/dist/host/version-range.js +13 -0
  314. package/dist/host/version.d.ts +4 -0
  315. package/dist/host/version.js +32 -0
  316. package/dist/host/workspace-store.d.ts +19 -0
  317. package/dist/host/workspace-store.js +133 -0
  318. package/dist/host/write-result.d.ts +1 -0
  319. package/dist/host/write-result.js +18 -0
  320. package/dist/host.d.ts +2 -0
  321. package/dist/host.js +2 -0
  322. package/dist/i18n/en.js +14 -3
  323. package/dist/i18n/index.d.ts +15 -4
  324. package/dist/i18n/zh.d.ts +14 -3
  325. package/dist/i18n/zh.js +14 -3
  326. package/dist/lib/bundle-requirements.d.ts +1 -0
  327. package/dist/lib/bundle-requirements.js +9 -0
  328. package/package.json +1 -1
  329. package/src/contract/__tests__/unit.test.ts +7 -0
  330. package/src/contract/needs.ts +5 -3
  331. package/src/contract/protocol/bundle-install.ts +1 -0
  332. package/src/contract/unit.ts +2 -1
  333. package/src/host/runtime/__tests__/dsh-compat.test.ts +19 -1
  334. package/src/host/runtime/__tests__/verified-dsh.test.ts +55 -0
  335. package/src/host/runtime/dsh-compat.ts +36 -12
  336. package/src/host/runtime/verified-dsh.ts +22 -0
  337. package/src/host/supply/__tests__/builtin-catalog.test.ts +44 -0
  338. package/src/host/supply/builtin-catalog.ts +38 -0
  339. package/src/host/supply/preflight.ts +16 -1
  340. package/src/host/supply/supply-index.ts +3 -0
  341. package/src/host.ts +2 -0
  342. package/src/i18n/en.ts +17 -3
  343. package/src/i18n/zh.ts +16 -3
  344. package/src/lib/bundle-requirements.ts +11 -0
@@ -0,0 +1,45 @@
1
+ import type { DataErrorCode, RequestPlan, RequestRecipe, ResolvedRequestPlan, ResolvedRequestRecipe } from '../contract/data.js';
2
+ import type { SiteEnvelope, UnitSite } from '../contract/unit.js';
3
+ export type UnitSites = Readonly<Record<string, UnitSite>>;
4
+ export interface SiteProblem {
5
+ readonly code: DataErrorCode;
6
+ readonly message: string;
7
+ readonly pageCode: string;
8
+ }
9
+ export type SiteResolution<T> = {
10
+ readonly ok: true;
11
+ readonly value: T;
12
+ } | {
13
+ readonly ok: false;
14
+ readonly problem: SiteProblem;
15
+ };
16
+ export interface PlanEnvelopeOptions {
17
+ readonly envelope?: SiteEnvelope | false | undefined;
18
+ }
19
+ export type EnvelopePath = {
20
+ readonly ok: true;
21
+ readonly path: string | undefined;
22
+ } | {
23
+ readonly ok: false;
24
+ readonly problem: string;
25
+ };
26
+ /**
27
+ * 把一条只写 `site`(或同时写 `origin`)的配方解析成带 `origin` 的直白形状。
28
+ * 显式字段优先于站点默认值;`origin` 显式写时只覆盖站点的 origin。
29
+ */
30
+ export declare function resolveRecipeOf(recipe: RequestRecipe, sites: UnitSites | undefined): SiteResolution<ResolvedRequestRecipe>;
31
+ /**
32
+ * 把一份只写 `site`(或同时写 `origin`)的读取计划解析成带 `origin` 的直白形状。
33
+ * 显式字段优先于站点默认值。
34
+ */
35
+ export declare function resolvePlanOf(plan: RequestPlan, sites: UnitSites | undefined): SiteResolution<ResolvedRequestPlan>;
36
+ /**
37
+ * 把相对信封 `dataPath` 的路径展开成绝对路径;`envelope: false` 表示从根取、不展开。
38
+ * 多段 `dataPath`(如 `data.list`)不猜语义,要求调用方写全。
39
+ */
40
+ export declare function envelopePathOf(path: string | undefined, envelope: SiteEnvelope | false | undefined): EnvelopePath;
41
+ /**
42
+ * 手写计划的信封展开:吃一份计划与站点,返回 `response.path` / `while.path` 已展开的计划。
43
+ * 运行时不认识信封;要用这份 helper 在代码里显式展开。
44
+ */
45
+ export declare function expandPlanPathsOf(plan: RequestPlan, site: UnitSite, options?: PlanEnvelopeOptions): RequestPlan;
@@ -0,0 +1,182 @@
1
+ import { isRecord } from '../contract/guards.js';
2
+ function siteUndeclaredOf(site, sites) {
3
+ return {
4
+ code: 'invalid-request',
5
+ message: sites === undefined
6
+ ? `模块清单没有站点表(host.sites),这条配方引用了站点 ${site}`
7
+ : `站点 ${site} 没在清单 host.sites 里声明`,
8
+ pageCode: 'site-undeclared',
9
+ };
10
+ }
11
+ function siteOf(site, sites) {
12
+ if (site === undefined)
13
+ return { ok: true, value: undefined };
14
+ if (!isRecord(sites) || !Object.hasOwn(sites, site))
15
+ return { ok: false, problem: siteUndeclaredOf(site, sites) };
16
+ const found = sites[site];
17
+ if (!isRecord(found) || typeof found.origin !== 'string' || found.origin.trim() === '') {
18
+ return {
19
+ ok: false,
20
+ problem: {
21
+ code: 'invalid-request',
22
+ message: `站点 ${site} 没有 origin —— 清单 host.sites.${site} 至少要写一个 http(s) origin`,
23
+ pageCode: 'site-undeclared',
24
+ },
25
+ };
26
+ }
27
+ return { ok: true, value: found };
28
+ }
29
+ function emptyProblemOf(label) {
30
+ return {
31
+ code: 'invalid-request',
32
+ message: `${label}要有 origin 或 site 至少一个`,
33
+ pageCode: 'site-undeclared',
34
+ };
35
+ }
36
+ /**
37
+ * 把一条只写 `site`(或同时写 `origin`)的配方解析成带 `origin` 的直白形状。
38
+ * 显式字段优先于站点默认值;`origin` 显式写时只覆盖站点的 origin。
39
+ */
40
+ export function resolveRecipeOf(recipe, sites) {
41
+ if (typeof recipe !== 'object' || recipe === null || Array.isArray(recipe)) {
42
+ return { ok: false, problem: emptyProblemOf('配方') };
43
+ }
44
+ const originText = typeof recipe.origin === 'string' ? recipe.origin.trim() : '';
45
+ const siteText = typeof recipe.site === 'string' ? recipe.site.trim() : '';
46
+ const siteName = siteText === '' ? undefined : siteText;
47
+ if (originText === '' && siteName === undefined)
48
+ return { ok: false, problem: emptyProblemOf('配方') };
49
+ const picked = siteOf(siteName, sites);
50
+ if (!picked.ok)
51
+ return picked;
52
+ const site = picked.value;
53
+ if (originText === '' && site === undefined)
54
+ return { ok: false, problem: emptyProblemOf('配方') };
55
+ const origin = originText === '' ? site.origin : originText;
56
+ return {
57
+ ok: true,
58
+ value: {
59
+ ...recipe,
60
+ origin,
61
+ ...(recipe.loginUrl === undefined && site?.loginUrl !== undefined ? { loginUrl: site.loginUrl } : {}),
62
+ ...(recipe.session === undefined && site?.session !== undefined ? { session: site.session } : {}),
63
+ ...(recipe.timeoutMs === undefined && site?.timeoutMs !== undefined ? { timeoutMs: site.timeoutMs } : {}),
64
+ ...(recipe.authLoss === undefined && site?.authLoss !== undefined ? { authLoss: site.authLoss } : {}),
65
+ },
66
+ };
67
+ }
68
+ /**
69
+ * 把一份只写 `site`(或同时写 `origin`)的读取计划解析成带 `origin` 的直白形状。
70
+ * 显式字段优先于站点默认值。
71
+ */
72
+ export function resolvePlanOf(plan, sites) {
73
+ if (typeof plan !== 'object' || plan === null || Array.isArray(plan)) {
74
+ return { ok: false, problem: emptyProblemOf('计划') };
75
+ }
76
+ const originText = typeof plan.origin === 'string' ? plan.origin.trim() : '';
77
+ const siteText = typeof plan.site === 'string' ? plan.site.trim() : '';
78
+ const siteName = siteText === '' ? undefined : siteText;
79
+ if (originText === '' && siteName === undefined)
80
+ return { ok: false, problem: emptyProblemOf('计划') };
81
+ const picked = siteOf(siteName, sites);
82
+ if (!picked.ok)
83
+ return picked;
84
+ const site = picked.value;
85
+ if (originText === '' && site === undefined)
86
+ return { ok: false, problem: emptyProblemOf('计划') };
87
+ const origin = originText === '' ? site.origin : originText;
88
+ return {
89
+ ok: true,
90
+ value: {
91
+ ...plan,
92
+ origin,
93
+ ...(plan.loginUrl === undefined && site?.loginUrl !== undefined ? { loginUrl: site.loginUrl } : {}),
94
+ ...(plan.session === undefined && site?.session !== undefined ? { session: site.session } : {}),
95
+ ...(plan.timeoutMs === undefined && site?.timeoutMs !== undefined ? { timeoutMs: site.timeoutMs } : {}),
96
+ ...(plan.authLoss === undefined && site?.authLoss !== undefined ? { authLoss: site.authLoss } : {}),
97
+ },
98
+ };
99
+ }
100
+ /**
101
+ * 把相对信封 `dataPath` 的路径展开成绝对路径;`envelope: false` 表示从根取、不展开。
102
+ * 多段 `dataPath`(如 `data.list`)不猜语义,要求调用方写全。
103
+ */
104
+ export function envelopePathOf(path, envelope) {
105
+ if (path !== undefined && typeof path !== 'string') {
106
+ return { ok: false, problem: 'response.path 要是字符串' };
107
+ }
108
+ const rawPath = path?.trim() ?? '';
109
+ const normalizedPath = rawPath === '' ? undefined : rawPath;
110
+ if (rawPath !== '' && rawPath.split('.').some((segment) => segment.trim() === '')) {
111
+ return { ok: false, problem: 'response.path 里不许有空段' };
112
+ }
113
+ if (envelope === undefined || envelope === false)
114
+ return { ok: true, path: normalizedPath };
115
+ if (typeof envelope !== 'object' || envelope === null || Array.isArray(envelope)) {
116
+ return { ok: false, problem: '信封要是对象或 false' };
117
+ }
118
+ if (envelope.dataPath !== undefined && typeof envelope.dataPath !== 'string') {
119
+ return { ok: false, problem: '信封的 dataPath 要是字符串' };
120
+ }
121
+ const dataPath = envelope.dataPath?.trim();
122
+ if (dataPath !== undefined && dataPath.split('.').some((segment) => segment.trim() === '')) {
123
+ return { ok: false, problem: '信封的 dataPath 里不许有空段' };
124
+ }
125
+ if (dataPath === undefined || dataPath === '')
126
+ return { ok: true, path: normalizedPath };
127
+ const current = rawPath;
128
+ if (current === '')
129
+ return { ok: true, path: dataPath };
130
+ const under = current === dataPath || current.startsWith(`${dataPath}.`);
131
+ if (!under && dataPath.includes('.')) {
132
+ return {
133
+ ok: false,
134
+ problem: `站点信封的 dataPath 有多段(${dataPath}),配方路径要写全(以 ${dataPath} 开头)`,
135
+ };
136
+ }
137
+ const next = under ? current : `${dataPath}.${current}`;
138
+ const doubled = `${dataPath}.${dataPath}`;
139
+ if (next === doubled || next.startsWith(`${doubled}.`)) {
140
+ return { ok: false, problem: `路径出现重复前缀 ${doubled}` };
141
+ }
142
+ return { ok: true, path: next };
143
+ }
144
+ function expandedStepOf(step, envelope) {
145
+ if (typeof step !== 'object' || step === null || Array.isArray(step))
146
+ throw new Error('计划里的步骤要是对象');
147
+ const next = { ...step };
148
+ if (step.response === undefined || step.response === null) {
149
+ delete next.response;
150
+ }
151
+ else if ((step.response.kind ?? 'json') === 'json') {
152
+ const got = envelopePathOf(step.response.path, envelope);
153
+ if (!got.ok)
154
+ throw new Error(got.problem);
155
+ next.response = { ...step.response, ...(got.path === undefined ? {} : { path: got.path }) };
156
+ }
157
+ if (step.while === undefined || step.while === null) {
158
+ delete next.while;
159
+ }
160
+ else {
161
+ const got = envelopePathOf(step.while.path, envelope);
162
+ if (!got.ok)
163
+ throw new Error(got.problem);
164
+ next.while = { ...step.while, path: got.path ?? step.while.path };
165
+ }
166
+ return next;
167
+ }
168
+ /**
169
+ * 手写计划的信封展开:吃一份计划与站点,返回 `response.path` / `while.path` 已展开的计划。
170
+ * 运行时不认识信封;要用这份 helper 在代码里显式展开。
171
+ */
172
+ export function expandPlanPathsOf(plan, site, options = {}) {
173
+ if (typeof plan !== 'object' || plan === null || !Array.isArray(plan.steps)) {
174
+ throw new Error('计划要是对象且带 steps');
175
+ }
176
+ if (typeof site !== 'object' || site === null)
177
+ throw new Error('站点要是对象');
178
+ const envelope = options.envelope === undefined ? site.envelope : options.envelope;
179
+ if (envelope === undefined || envelope === false)
180
+ return plan;
181
+ return { ...plan, steps: plan.steps.map((step) => expandedStepOf(step, envelope)) };
182
+ }
@@ -0,0 +1,8 @@
1
+ export interface NpmRef {
2
+ readonly name: string;
3
+ readonly version?: string;
4
+ }
5
+ export declare function isPackageName(value: string): boolean;
6
+ export declare function splitNpmSpec(spec: string): NpmRef | undefined;
7
+ export declare function localDirOf(spec: string): string | undefined;
8
+ export declare function refusalReason(): string;
@@ -0,0 +1,24 @@
1
+ import path from 'node:path';
2
+ const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
3
+ const VERSION = /^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/;
4
+ export function isPackageName(value) {
5
+ return value.length <= 214 && PACKAGE_NAME.test(value);
6
+ }
7
+ export function splitNpmSpec(spec) {
8
+ const value = spec.trim();
9
+ const at = value.lastIndexOf('@');
10
+ const name = at > 0 ? value.slice(0, at) : value;
11
+ const version = at > 0 ? value.slice(at + 1) : '';
12
+ if (!isPackageName(name))
13
+ return undefined;
14
+ if (version !== '' && !VERSION.test(version))
15
+ return undefined;
16
+ return { name, ...(version === '' ? {} : { version }) };
17
+ }
18
+ export function localDirOf(spec) {
19
+ const dir = spec.trim().replace(/^(?:file|link):/, '');
20
+ return path.isAbsolute(dir) ? dir : undefined;
21
+ }
22
+ export function refusalReason() {
23
+ return '这个包既不是工作台的模块,也不是运行时的插件,装了也用不上';
24
+ }
@@ -0,0 +1,19 @@
1
+ import type { PlanStep } from '../contract/data.js';
2
+ import type { LongTaskStep } from '../contract/long-task.js';
3
+ /**
4
+ * 长任务里逐步骤确认写计划的桥:`confirm` 发一条人工干预,`answer` 把用户回执翻成 yes / no。
5
+ */
6
+ export interface SubmitPlanConfirmer {
7
+ confirm(step: PlanStep, index: number): Promise<boolean>;
8
+ answer(values: Readonly<Record<string, string>>): boolean;
9
+ }
10
+ /**
11
+ * 建一个逐步骤确认桥。把 `emit` 接到长任务 `run({ onStep })`,把 `answer` 接到
12
+ * `longTasks.create({ answer })`;用户回执不是 `yes` 就返回 false,写计划会停在当前步。
13
+ * @param options `emit` 是长任务步骤出口;`signal` 停止时自动按 false 收口。
14
+ * @returns `confirm` / `answer` 两个回调。
15
+ */
16
+ export declare function createSubmitPlanConfirmer(options: {
17
+ readonly emit: (step: LongTaskStep) => void;
18
+ readonly signal?: AbortSignal | undefined;
19
+ }): SubmitPlanConfirmer;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 建一个逐步骤确认桥。把 `emit` 接到长任务 `run({ onStep })`,把 `answer` 接到
3
+ * `longTasks.create({ answer })`;用户回执不是 `yes` 就返回 false,写计划会停在当前步。
4
+ * @param options `emit` 是长任务步骤出口;`signal` 停止时自动按 false 收口。
5
+ * @returns `confirm` / `answer` 两个回调。
6
+ */
7
+ export function createSubmitPlanConfirmer(options) {
8
+ let pending;
9
+ const onAbort = () => {
10
+ finish(false);
11
+ };
12
+ const finish = (value) => {
13
+ const resolve = pending;
14
+ pending = undefined;
15
+ if (resolve === undefined)
16
+ return false;
17
+ options.signal?.removeEventListener('abort', onAbort);
18
+ resolve(value);
19
+ return true;
20
+ };
21
+ options.signal?.addEventListener('abort', onAbort, { once: true });
22
+ return {
23
+ confirm(step, index) {
24
+ if (options.signal?.aborted === true)
25
+ return Promise.resolve(false);
26
+ finish(false);
27
+ return new Promise((resolve) => {
28
+ pending = resolve;
29
+ options.emit({
30
+ kind: 'info',
31
+ text: `确认第 ${String(index + 1)} 步:${step.name}`,
32
+ intervention: {
33
+ title: `确认写入:${step.name}`,
34
+ hint: `第 ${String(index + 1)} 步;输入 yes 才写`,
35
+ fields: [{ key: 'confirm', label: '写这一步?输入 yes', placeholder: 'yes', required: true }],
36
+ submitLabel: '确认',
37
+ },
38
+ });
39
+ });
40
+ },
41
+ answer(values) {
42
+ return finish(String(values['confirm'] ?? '').trim().toLowerCase() === 'yes');
43
+ },
44
+ };
45
+ }
@@ -0,0 +1,3 @@
1
+ import type { Need } from '../../contract/needs.js';
2
+ export declare function builtinCommandsOf(file: string): ReadonlyMap<string, readonly string[]>;
3
+ export declare function builtinMissingOf(needs: readonly Need[] | undefined, catalog: ReadonlyMap<string, readonly string[]>): readonly string[];
@@ -0,0 +1,38 @@
1
+ import { readJsonObject } from '../runtime/read-json.js';
2
+ export function builtinCommandsOf(file) {
3
+ const parsed = readJsonObject(file);
4
+ if (!Array.isArray(parsed))
5
+ return new Map();
6
+ const bySite = new Map();
7
+ for (const one of parsed) {
8
+ if (typeof one !== 'object' || one === null)
9
+ continue;
10
+ const row = one;
11
+ const site = typeof row['site'] === 'string' ? row['site'] : '';
12
+ const name = typeof row['name'] === 'string' ? row['name'] : '';
13
+ if (site === '' || name === '')
14
+ continue;
15
+ const list = bySite.get(site) ?? [];
16
+ list.push(name);
17
+ for (const alias of Array.isArray(row['aliases']) ? row['aliases'] : []) {
18
+ if (typeof alias === 'string' && alias !== '')
19
+ list.push(alias);
20
+ }
21
+ bySite.set(site, list);
22
+ }
23
+ return bySite;
24
+ }
25
+ export function builtinMissingOf(needs, catalog) {
26
+ return (needs ?? [])
27
+ .filter((need) => need.kind === 'extension' || need.kind === 'lib')
28
+ .filter((need) => (need.sources ?? []).some((source) => source.kind === 'builtin'))
29
+ .filter((need) => {
30
+ const commands = catalog.get(need.name);
31
+ if (commands === undefined)
32
+ return true;
33
+ if (need.kind !== 'extension')
34
+ return false;
35
+ return (need.commands ?? []).some((name) => !commands.includes(name));
36
+ })
37
+ .map((need) => need.name);
38
+ }
@@ -1,4 +1,4 @@
1
- export type PreflightStepId = 'toolchain' | 'cli' | 'bridge' | 'runtime' | 'diy' | 'warm';
1
+ export type PreflightStepId = 'toolchain' | 'cli' | 'bridge' | 'runtime' | 'host' | 'diy' | 'warm';
2
2
  export type PreflightStepStatus = 'pending' | 'running' | 'ok' | 'warn' | 'failed';
3
3
  export type PreflightFailure = 'permission' | 'network' | 'missing' | 'host' | 'unknown';
4
4
  export type PreflightGuidance = 'install' | 'path' | 'shell' | 'host';
@@ -17,6 +17,18 @@ export interface PreflightDiyGap {
17
17
  readonly detail: string;
18
18
  readonly command: string;
19
19
  }
20
+ export type PreflightHostTier = 'newer' | 'older';
21
+ export type PreflightHostStanding = {
22
+ readonly tier: 'ok';
23
+ readonly log?: readonly string[];
24
+ } | PreflightHostGap;
25
+ export interface PreflightHostGap {
26
+ readonly tier: PreflightHostTier;
27
+ readonly runtime: string;
28
+ readonly verified: string;
29
+ readonly command?: string;
30
+ readonly log?: readonly string[];
31
+ }
20
32
  export interface PreflightSnapshot {
21
33
  readonly phase: 'idle' | 'checking' | 'installing' | 'ready' | 'failed';
22
34
  readonly steps: readonly PreflightStep[];
@@ -25,6 +37,7 @@ export interface PreflightSnapshot {
25
37
  readonly failure?: PreflightFailure;
26
38
  readonly guidance?: PreflightGuidance;
27
39
  readonly bridgeIssues?: readonly PreflightBridgeIssue[];
40
+ readonly hostGap?: PreflightHostGap;
28
41
  readonly diyGap?: PreflightDiyGap;
29
42
  readonly canWakeBrowser?: boolean;
30
43
  readonly extensionDir?: string;
@@ -13,6 +13,8 @@ function nativeSourcePackage(source) {
13
13
  return text(source.package);
14
14
  if (source.kind === 'git')
15
15
  return `git:${text(source.url)}`;
16
+ if (source.kind === 'builtin')
17
+ return 'builtin';
16
18
  return `local:${text(source.env) || text(source.path)}`;
17
19
  }
18
20
  function packageOf(need, prefix) {
@@ -52,6 +54,8 @@ function sourceCompatible(left, right, env) {
52
54
  if (left.kind === 'local' && right.kind === 'local') {
53
55
  return text(left.env) === text(right.env) && text(left.path) === text(right.path);
54
56
  }
57
+ if (left.kind === 'builtin' && right.kind === 'builtin')
58
+ return true;
55
59
  return false;
56
60
  }
57
61
  function sourcesCompatible(left, right, env) {
@@ -96,6 +100,8 @@ function sourceText(source) {
96
100
  }
97
101
  if (source.kind === 'git')
98
102
  return `git:${source.url}`;
103
+ if (source.kind === 'builtin')
104
+ return '运行时自带';
99
105
  return `local:${source.env ?? source.path ?? ''}`;
100
106
  }
101
107
  function addDeclarer(entry, unit, commands) {
@@ -0,0 +1,38 @@
1
+ import type { Need, SupplySource } from '../contract/needs.js';
2
+ export interface SupplyDeclaration {
3
+ readonly id: string;
4
+ readonly needs?: readonly Need[];
5
+ }
6
+ export interface SupplyIndexOptions {
7
+ readonly env?: Readonly<Record<string, string | undefined>>;
8
+ readonly packagePrefix?: string | undefined;
9
+ }
10
+ export interface SupplyEntry {
11
+ readonly key: string;
12
+ readonly kind: 'extension' | 'lib';
13
+ readonly names: readonly string[];
14
+ readonly package: string;
15
+ readonly runtime?: string;
16
+ readonly sources: readonly SupplySource[];
17
+ readonly declarers: readonly string[];
18
+ readonly commands: readonly string[];
19
+ readonly conflicted: boolean;
20
+ }
21
+ export interface SupplyConflict {
22
+ readonly kind: 'source-mismatch' | 'name-mismatch';
23
+ readonly key: string;
24
+ readonly names: readonly string[];
25
+ readonly declarers: readonly string[];
26
+ readonly detail: string;
27
+ }
28
+ export interface SupplyIndex {
29
+ readonly entries: ReadonlyMap<string, SupplyEntry>;
30
+ readonly conflicts: readonly SupplyConflict[];
31
+ readonly problems: readonly string[];
32
+ readonly entryOf: (kind: 'extension' | 'lib', name: string) => SupplyEntry | undefined;
33
+ readonly sourcesOf: (kind: 'extension' | 'lib', name: string) => readonly SupplySource[];
34
+ }
35
+ export declare function npmSourceOf(sources: readonly SupplySource[] | undefined): Extract<SupplySource, {
36
+ kind: 'npm';
37
+ }> | undefined;
38
+ export declare function buildSupplyIndex(declarations: readonly SupplyDeclaration[], options?: SupplyIndexOptions): SupplyIndex;