@dsh-workbench/shared 1.5.2-alpha.3 → 1.5.2-alpha.5

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 (314) 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/protocol/unit-manager.d.ts +50 -0
  99. package/dist/contract/protocol/unit-manager.js +2 -0
  100. package/dist/host/adapter-contract.d.ts +3 -0
  101. package/dist/host/adapter-contract.js +95 -0
  102. package/dist/host/adapter-set.d.ts +27 -0
  103. package/dist/host/adapter-set.js +258 -0
  104. package/dist/host/adapter-types.d.ts +87 -0
  105. package/dist/host/adapter-types.js +23 -0
  106. package/dist/host/adapters/platform.d.ts +14 -0
  107. package/dist/host/adapters/platform.js +40 -0
  108. package/dist/host/adapters.d.ts +28 -0
  109. package/dist/host/adapters.js +9 -0
  110. package/dist/host/auth-loss.d.ts +33 -0
  111. package/dist/host/auth-loss.js +107 -0
  112. package/dist/host/board-fact.d.ts +8 -0
  113. package/dist/host/board-fact.js +16 -0
  114. package/dist/host/boot-record.d.ts +11 -0
  115. package/dist/host/boot-record.js +31 -0
  116. package/dist/host/browser.d.ts +3 -0
  117. package/dist/host/browser.js +3 -0
  118. package/dist/host/bundle-manager.d.ts +4 -0
  119. package/dist/host/bundle-manager.js +338 -0
  120. package/dist/host/changelog.d.ts +28 -0
  121. package/dist/host/changelog.js +201 -0
  122. package/dist/host/cli-error.d.ts +8 -0
  123. package/dist/host/cli-error.js +70 -0
  124. package/dist/host/cli.d.ts +4 -0
  125. package/dist/host/cli.js +9 -0
  126. package/dist/host/config-sync.d.ts +40 -0
  127. package/dist/host/config-sync.js +267 -0
  128. package/dist/host/context-ref.d.ts +13 -0
  129. package/dist/host/context-ref.js +41 -0
  130. package/dist/host/data-error.d.ts +15 -0
  131. package/dist/host/data-error.js +23 -0
  132. package/dist/host/data-plan-check.d.ts +10 -0
  133. package/dist/host/data-plan-check.js +315 -0
  134. package/dist/host/data-plan.d.ts +15 -0
  135. package/dist/host/data-plan.js +283 -0
  136. package/dist/host/data-root.d.ts +5 -0
  137. package/dist/host/data-root.js +23 -0
  138. package/dist/host/diy-debug.d.ts +80 -0
  139. package/dist/host/diy-debug.js +89 -0
  140. package/dist/host/diy-preset.d.ts +26 -0
  141. package/dist/host/diy-preset.js +115 -0
  142. package/dist/host/diy-record.d.ts +135 -0
  143. package/dist/host/diy-record.js +163 -0
  144. package/dist/host/dsh-compat.d.ts +27 -0
  145. package/dist/host/dsh-compat.js +75 -0
  146. package/dist/host/dsh-plugins.d.ts +5 -0
  147. package/dist/host/dsh-plugins.js +51 -0
  148. package/dist/host/env-policy.d.ts +82 -0
  149. package/dist/host/env-policy.js +181 -0
  150. package/dist/host/extension.d.ts +7 -0
  151. package/dist/host/extension.js +40 -0
  152. package/dist/host/facts.d.ts +31 -0
  153. package/dist/host/facts.js +58 -0
  154. package/dist/host/fs-write.d.ts +96 -0
  155. package/dist/host/fs-write.js +183 -0
  156. package/dist/host/git.d.ts +5 -0
  157. package/dist/host/git.js +1 -0
  158. package/dist/host/host-actions.d.ts +2 -0
  159. package/dist/host/host-actions.js +5 -0
  160. package/dist/host/host-kit.d.ts +37 -0
  161. package/dist/host/host-kit.js +27 -0
  162. package/dist/host/http.d.ts +47 -0
  163. package/dist/host/http.js +289 -0
  164. package/dist/host/install-failure.d.ts +50 -0
  165. package/dist/host/install-failure.js +184 -0
  166. package/dist/host/installed-module.d.ts +25 -0
  167. package/dist/host/installed-module.js +289 -0
  168. package/dist/host/installed-sources.d.ts +10 -0
  169. package/dist/host/installed-sources.js +63 -0
  170. package/dist/host/lease.d.ts +70 -0
  171. package/dist/host/lease.js +264 -0
  172. package/dist/host/lib-capabilities.d.ts +22 -0
  173. package/dist/host/lib-capabilities.js +37 -0
  174. package/dist/host/lib-install.d.ts +19 -0
  175. package/dist/host/lib-install.js +40 -0
  176. package/dist/host/lib-runners.d.ts +18 -0
  177. package/dist/host/lib-runners.js +46 -0
  178. package/dist/host/local-declaration.d.ts +7 -0
  179. package/dist/host/local-declaration.js +33 -0
  180. package/dist/host/long-task.d.ts +97 -0
  181. package/dist/host/long-task.js +297 -0
  182. package/dist/host/market-index-claim.d.ts +19 -0
  183. package/dist/host/market-index-claim.js +87 -0
  184. package/dist/host/market-index-doc.d.ts +12 -0
  185. package/dist/host/market-index-doc.js +1 -0
  186. package/dist/host/market-index-parse.d.ts +28 -0
  187. package/dist/host/market-index-parse.js +413 -0
  188. package/dist/host/market-index.d.ts +13 -0
  189. package/dist/host/market-index.js +105 -0
  190. package/dist/host/module-root.d.ts +1 -0
  191. package/dist/host/module-root.js +5 -0
  192. package/dist/host/needs.d.ts +4 -0
  193. package/dist/host/needs.js +2 -0
  194. package/dist/host/npm-registry.d.ts +10 -0
  195. package/dist/host/npm-registry.js +16 -0
  196. package/dist/host/package-content.d.ts +8 -0
  197. package/dist/host/package-content.js +90 -0
  198. package/dist/host/package-kind.d.ts +13 -0
  199. package/dist/host/package-kind.js +51 -0
  200. package/dist/host/package-route.d.ts +33 -0
  201. package/dist/host/package-route.js +68 -0
  202. package/dist/host/panel-state.d.ts +120 -0
  203. package/dist/host/panel-state.js +177 -0
  204. package/dist/host/patch-blocks.d.ts +13 -0
  205. package/dist/host/patch-blocks.js +52 -0
  206. package/dist/host/patch.d.ts +4 -0
  207. package/dist/host/patch.js +7 -0
  208. package/dist/host/paths.d.ts +12 -0
  209. package/dist/host/paths.js +20 -0
  210. package/dist/host/payload.d.ts +12 -0
  211. package/dist/host/payload.js +16 -0
  212. package/dist/host/plan-results.d.ts +5 -0
  213. package/dist/host/plan-results.js +71 -0
  214. package/dist/host/plan-run.d.ts +41 -0
  215. package/dist/host/plan-run.js +87 -0
  216. package/dist/host/platform.d.ts +14 -0
  217. package/dist/host/platform.js +40 -0
  218. package/dist/host/plugin-ledger.d.ts +32 -0
  219. package/dist/host/plugin-ledger.js +106 -0
  220. package/dist/host/plugin.d.ts +3 -0
  221. package/dist/host/plugin.js +38 -0
  222. package/dist/host/port-types.d.ts +233 -0
  223. package/dist/host/port-types.js +1 -0
  224. package/dist/host/preflight.d.ts +32 -0
  225. package/dist/host/preflight.js +1 -0
  226. package/dist/host/process-alive.d.ts +6 -0
  227. package/dist/host/process-alive.js +16 -0
  228. package/dist/host/profile-bundles.d.ts +20 -0
  229. package/dist/host/profile-bundles.js +48 -0
  230. package/dist/host/profile-create.d.ts +19 -0
  231. package/dist/host/profile-create.js +124 -0
  232. package/dist/host/profile-port.d.ts +4 -0
  233. package/dist/host/profile-port.js +4 -0
  234. package/dist/host/profile-registries.d.ts +10 -0
  235. package/dist/host/profile-registries.js +149 -0
  236. package/dist/host/provision.d.ts +32 -0
  237. package/dist/host/provision.js +105 -0
  238. package/dist/host/read-json.d.ts +1 -0
  239. package/dist/host/read-json.js +11 -0
  240. package/dist/host/recipe-rules.d.ts +5 -0
  241. package/dist/host/recipe-rules.js +412 -0
  242. package/dist/host/recipe.d.ts +14 -0
  243. package/dist/host/recipe.js +332 -0
  244. package/dist/host/registry-declaration.d.ts +21 -0
  245. package/dist/host/registry-declaration.js +42 -0
  246. package/dist/host/reinstall-record.d.ts +16 -0
  247. package/dist/host/reinstall-record.js +54 -0
  248. package/dist/host/release-age.d.ts +24 -0
  249. package/dist/host/release-age.js +92 -0
  250. package/dist/host/release-packages.generated.d.ts +1 -0
  251. package/dist/host/release-packages.generated.js +10 -0
  252. package/dist/host/release-probe.d.ts +37 -0
  253. package/dist/host/release-probe.js +156 -0
  254. package/dist/host/runtime/browser-argv.d.ts +1 -0
  255. package/dist/host/runtime/browser-argv.js +9 -0
  256. package/dist/host/runtime/dsh-compat.d.ts +1 -1
  257. package/dist/host/runtime/dsh-compat.js +4 -1
  258. package/dist/host/runtime/front-app.d.ts +6 -0
  259. package/dist/host/runtime/front-app.js +70 -0
  260. package/dist/host/shell-render.d.ts +52 -0
  261. package/dist/host/shell-render.js +117 -0
  262. package/dist/host/shell-text.d.ts +30 -0
  263. package/dist/host/shell-text.js +40 -0
  264. package/dist/host/shell.d.ts +25 -0
  265. package/dist/host/shell.js +55 -0
  266. package/dist/host/site.d.ts +45 -0
  267. package/dist/host/site.js +182 -0
  268. package/dist/host/spec.d.ts +8 -0
  269. package/dist/host/spec.js +24 -0
  270. package/dist/host/submit-confirm.d.ts +19 -0
  271. package/dist/host/submit-confirm.js +45 -0
  272. package/dist/host/supply-index.d.ts +38 -0
  273. package/dist/host/supply-index.js +209 -0
  274. package/dist/host/supply-port.d.ts +5 -0
  275. package/dist/host/supply-port.js +50 -0
  276. package/dist/host/time.d.ts +22 -0
  277. package/dist/host/time.js +33 -0
  278. package/dist/host/tokens.d.ts +26 -0
  279. package/dist/host/tokens.js +154 -0
  280. package/dist/host/tool-approval.d.ts +86 -0
  281. package/dist/host/tool-approval.js +118 -0
  282. package/dist/host/tool-kit.d.ts +8 -0
  283. package/dist/host/tool-kit.js +22 -0
  284. package/dist/host/toolbox-port.d.ts +16 -0
  285. package/dist/host/toolbox-port.js +1 -0
  286. package/dist/host/unit-config.d.ts +34 -0
  287. package/dist/host/unit-config.js +28 -0
  288. package/dist/host/unit-data.d.ts +3 -0
  289. package/dist/host/unit-data.js +127 -0
  290. package/dist/host/unit-face.d.ts +95 -0
  291. package/dist/host/unit-face.js +1 -0
  292. package/dist/host/unit-plugin.d.ts +24 -0
  293. package/dist/host/unit-plugin.js +25 -0
  294. package/dist/host/update-journal-manifest.d.ts +19 -0
  295. package/dist/host/update-journal-manifest.js +134 -0
  296. package/dist/host/update-journal-types.d.ts +33 -0
  297. package/dist/host/update-journal-types.js +2 -0
  298. package/dist/host/update-journal.d.ts +43 -0
  299. package/dist/host/update-journal.js +409 -0
  300. package/dist/host/value-handoff.d.ts +16 -0
  301. package/dist/host/value-handoff.js +22 -0
  302. package/dist/host/version-range.d.ts +2 -0
  303. package/dist/host/version-range.js +13 -0
  304. package/dist/host/version.d.ts +4 -0
  305. package/dist/host/version.js +32 -0
  306. package/dist/host/workspace-store.d.ts +19 -0
  307. package/dist/host/workspace-store.js +133 -0
  308. package/dist/host/write-result.d.ts +1 -0
  309. package/dist/host/write-result.js +18 -0
  310. package/dist/lib/dsh-client.d.ts +1 -1
  311. package/package.json +51 -47
  312. package/src/host/runtime/__tests__/dsh-compat.test.ts +10 -2
  313. package/src/host/runtime/dsh-compat.ts +4 -2
  314. package/src/lib/dsh-client.ts +2 -1
@@ -0,0 +1,33 @@
1
+ import type { AuthLoss } from '../contract/data.js';
2
+ /**
3
+ * 一条登录丢失结论:给模块先判断,再决定是否自己解析响应。
4
+ */
5
+ export interface AuthLossNotice {
6
+ readonly message: string;
7
+ readonly loginUrl?: string;
8
+ }
9
+ export interface AuthLossProblem {
10
+ readonly path: string;
11
+ readonly problem: string;
12
+ }
13
+ /**
14
+ * 认常见的登录丢失形状:401、`status:false` + 登录/超时文案、跳 `/login`(403 是没权限,不算登录丢失)。
15
+ * `status:false` 单独出现不算,避免把业务错误误判成登录。
16
+ * @param value 已解析的响应体。
17
+ * @returns 命中时给消息与可选的登录地址;不命中 undefined。
18
+ */
19
+ export declare function authLossOf(value: unknown): AuthLossNotice | undefined;
20
+ /**
21
+ * 查一条自定义登录丢失形状:配方与读取计划共用同一套规则。
22
+ * @param at 报错时用的字段路径。
23
+ * @param value 待查的形状。
24
+ * @returns 每个问题带字段路径;空数组表示合法。
25
+ */
26
+ export declare function authLossProblemsOf(at: string, value: unknown): readonly AuthLossProblem[];
27
+ /**
28
+ * 生成页面脚本里的登录丢失判定片段:依赖脚本里已有的 `pick`。
29
+ * 不写 `authLoss` 时也生成一个恒返回 null 的函数,调用点不用分支。
30
+ * @param authLoss 站点或计划上的形状。
31
+ * @returns 可直接拼进脚本的行。
32
+ */
33
+ export declare function authLossScriptLines(authLoss: AuthLoss | undefined): string[];
@@ -0,0 +1,107 @@
1
+ import { pathSegmentsProblem } from '../contract/guards.js';
2
+ const AUTH_WORDS = /登录|登陆|超时|会话|未授权|请重新|login|log in|session|expired|unauthorized|auth/i;
3
+ function textOf(value) {
4
+ return typeof value === 'string' ? value.trim() : '';
5
+ }
6
+ function primitiveValue(value) {
7
+ return value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
8
+ }
9
+ /**
10
+ * 认常见的登录丢失形状:401、`status:false` + 登录/超时文案、跳 `/login`(403 是没权限,不算登录丢失)。
11
+ * `status:false` 单独出现不算,避免把业务错误误判成登录。
12
+ * @param value 已解析的响应体。
13
+ * @returns 命中时给消息与可选的登录地址;不命中 undefined。
14
+ */
15
+ export function authLossOf(value) {
16
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
17
+ return undefined;
18
+ const record = value;
19
+ const status = record['status'] ?? record['statusCode'];
20
+ const numeric = typeof status === 'string' && status.trim() !== '' ? Number(status) : status;
21
+ const message = textOf(record['message'] ?? record['msg'] ?? record['error'] ?? record['errorMessage'] ?? record['detail']);
22
+ const url = textOf(record['loginUrl'] ?? record['loginURL'] ?? record['url'] ?? record['redirect']);
23
+ const loginUrl = /\/login(?:[?#]|$)/i.test(url) ? url : undefined;
24
+ const needsLogin = record['status'] === false ||
25
+ record['success'] === false ||
26
+ record['loggedIn'] === false ||
27
+ record['authenticated'] === false;
28
+ if (numeric === 401) {
29
+ return {
30
+ message: message === '' ? `HTTP ${String(numeric)}` : message,
31
+ ...(loginUrl === undefined ? {} : { loginUrl }),
32
+ };
33
+ }
34
+ if (!needsLogin || !AUTH_WORDS.test(message))
35
+ return undefined;
36
+ return { message, ...(loginUrl === undefined ? {} : { loginUrl }) };
37
+ }
38
+ /**
39
+ * 查一条自定义登录丢失形状:配方与读取计划共用同一套规则。
40
+ * @param at 报错时用的字段路径。
41
+ * @param value 待查的形状。
42
+ * @returns 每个问题带字段路径;空数组表示合法。
43
+ */
44
+ export function authLossProblemsOf(at, value) {
45
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
46
+ return [{ path: at, problem: `${at} 要是对象` }];
47
+ }
48
+ const record = value;
49
+ const problems = [];
50
+ const unknown = Object.keys(record).filter((key) => !['path', 'equals', 'in', 'messagePath'].includes(key));
51
+ if (unknown.length > 0) {
52
+ problems.push({ path: at, problem: `${at} 里有不认的键 ${unknown.map((key) => JSON.stringify(key)).join(' / ')}` });
53
+ }
54
+ if (textOf(record['path']) === '')
55
+ problems.push({ path: `${at}.path`, problem: 'authLoss.path 不能为空' });
56
+ const pathProblem = pathSegmentsProblem(record['path'], `${at}.path`);
57
+ if (pathProblem !== undefined)
58
+ problems.push({ path: `${at}.path`, problem: pathProblem });
59
+ const hasEquals = record['equals'] !== undefined;
60
+ if (hasEquals && !primitiveValue(record['equals'])) {
61
+ problems.push({ path: `${at}.equals`, problem: 'authLoss.equals 只支持字符串 / 数字 / 布尔 / null' });
62
+ }
63
+ if (record['in'] !== undefined && !Array.isArray(record['in'])) {
64
+ problems.push({ path: `${at}.in`, problem: 'authLoss.in 要是数组' });
65
+ }
66
+ if (Array.isArray(record['in']) && record['in'].some((one) => !primitiveValue(one))) {
67
+ problems.push({ path: `${at}.in`, problem: 'authLoss.in 的元素只支持字符串 / 数字 / 布尔 / null' });
68
+ }
69
+ const hasIn = Array.isArray(record['in']) && record['in'].length > 0;
70
+ if (!hasEquals && !hasIn)
71
+ problems.push({ path: at, problem: 'equals 或 in 至少给一个' });
72
+ if (hasEquals && hasIn)
73
+ problems.push({ path: at, problem: 'equals 与 in 只给一个' });
74
+ if (record['messagePath'] !== undefined && textOf(record['messagePath']) === '') {
75
+ problems.push({ path: `${at}.messagePath`, problem: 'authLoss.messagePath 不能为空' });
76
+ }
77
+ const messageProblem = pathSegmentsProblem(record['messagePath'], `${at}.messagePath`);
78
+ if (messageProblem !== undefined)
79
+ problems.push({ path: `${at}.messagePath`, problem: messageProblem });
80
+ return problems;
81
+ }
82
+ /**
83
+ * 生成页面脚本里的登录丢失判定片段:依赖脚本里已有的 `pick`。
84
+ * 不写 `authLoss` 时也生成一个恒返回 null 的函数,调用点不用分支。
85
+ * @param authLoss 站点或计划上的形状。
86
+ * @returns 可直接拼进脚本的行。
87
+ */
88
+ export function authLossScriptLines(authLoss) {
89
+ const normalized = authLoss === undefined
90
+ ? undefined
91
+ : {
92
+ ...authLoss,
93
+ path: authLoss.path.trim(),
94
+ ...(authLoss.messagePath === undefined ? {} : { messagePath: authLoss.messagePath.trim() }),
95
+ };
96
+ return [
97
+ ` const authLoss = ${normalized === undefined ? 'null' : JSON.stringify(normalized)};`,
98
+ ' const authLostOf = (value) => {',
99
+ ' if (authLoss === null) return null;',
100
+ ' const got = pick(value, authLoss.path);',
101
+ ' const hit = Array.isArray(authLoss.in) && authLoss.in.length > 0 ? authLoss.in.indexOf(got) >= 0 : got === authLoss.equals;',
102
+ ' if (!hit) return null;',
103
+ ' const message = authLoss.messagePath === undefined ? null : pick(value, authLoss.messagePath);',
104
+ ' return typeof message === "string" && message !== "" ? message : "需要登录";',
105
+ ' };',
106
+ ];
107
+ }
@@ -0,0 +1,8 @@
1
+ import { type BoardFactState, type BoardProbe } from '../lib/board-fact.js';
2
+ /**
3
+ * 把一次探针读数归成椅面归属。
4
+ * @param probe - 探针读数。
5
+ * @param workshop - 当前工作区根路径;`null` 表示还不知道当前是哪个工作区。
6
+ * @returns 外壳不在、或板路径与工作区缺一 → `unknown`;右栏没开或没画出来 → `hidden`;板在本工作区 → `workshop`,否则 `other`。
7
+ */
8
+ export declare function boardFactOf(probe: BoardProbe, workshop: string | null): BoardFactState;
@@ -0,0 +1,16 @@
1
+ import { insideWorkshop } from '../lib/board-fact.js';
2
+ /**
3
+ * 把一次探针读数归成椅面归属。
4
+ * @param probe - 探针读数。
5
+ * @param workshop - 当前工作区根路径;`null` 表示还不知道当前是哪个工作区。
6
+ * @returns 外壳不在、或板路径与工作区缺一 → `unknown`;右栏没开或没画出来 → `hidden`;板在本工作区 → `workshop`,否则 `other`。
7
+ */
8
+ export function boardFactOf(probe, workshop) {
9
+ if (!probe.workbench)
10
+ return 'unknown';
11
+ if (!probe.bar || !probe.open || !probe.drawn)
12
+ return 'hidden';
13
+ if (probe.board === '' || workshop === null)
14
+ return 'unknown';
15
+ return insideWorkshop(workshop, probe.board) ? 'workshop' : 'other';
16
+ }
@@ -0,0 +1,11 @@
1
+ export interface BootRecord {
2
+ readonly version: string;
3
+ readonly at: string;
4
+ readonly pid?: number | undefined;
5
+ }
6
+ export declare function bootFileIn(dir: string): string;
7
+ export declare function upFileIn(dir: string): string;
8
+ export declare function workbenchBootFile(): string;
9
+ export declare function workbenchUpFile(): string;
10
+ export declare function readBootRecord(file: string): BootRecord | undefined;
11
+ export declare function writeBootRecord(record: BootRecord, file: string): void;
@@ -0,0 +1,31 @@
1
+ import { join } from 'node:path';
2
+ import { workbenchRoot } from './data-root.js';
3
+ import { writeJsonFile } from './fs-write.js';
4
+ import { readJsonObject } from './read-json.js';
5
+ export function bootFileIn(dir) {
6
+ return join(dir, 'self-update-boot.json');
7
+ }
8
+ export function upFileIn(dir) {
9
+ return join(dir, 'self-update-up.json');
10
+ }
11
+ export function workbenchBootFile() {
12
+ return bootFileIn(workbenchRoot());
13
+ }
14
+ export function workbenchUpFile() {
15
+ return upFileIn(workbenchRoot());
16
+ }
17
+ export function readBootRecord(file) {
18
+ const record = readJsonObject(file);
19
+ if (record === undefined)
20
+ return undefined;
21
+ if (typeof record.version !== 'string' || typeof record.at !== 'string')
22
+ return undefined;
23
+ return {
24
+ version: record.version,
25
+ at: record.at,
26
+ ...(typeof record.pid === 'number' ? { pid: record.pid } : {}),
27
+ };
28
+ }
29
+ export function writeBootRecord(record, file) {
30
+ writeJsonFile(file, record);
31
+ }
@@ -0,0 +1,3 @@
1
+ export declare const BROWSER_SCREEN_SESSION = "workbench";
2
+ export declare const BROWSER_READ_SESSION = "workbench-read";
3
+ export declare const BROWSER_RECORD_SESSION = "workbench-rec";
@@ -0,0 +1,3 @@
1
+ export const BROWSER_SCREEN_SESSION = 'workbench';
2
+ export const BROWSER_READ_SESSION = 'workbench-read';
3
+ export const BROWSER_RECORD_SESSION = 'workbench-rec';
@@ -0,0 +1,4 @@
1
+ import type { DshHostContext } from '../api/dsh.js';
2
+ import type { BundleManager } from './adapter-types.js';
3
+ export declare const PLUGIN_MANAGER_SERVICE = "pluginManager";
4
+ export declare function readBundleManager(ctx: DshHostContext): BundleManager | undefined;
@@ -0,0 +1,338 @@
1
+ import { RESTART_REASONS } from '../contract/protocol/bundle-install.js';
2
+ export const PLUGIN_MANAGER_SERVICE = 'pluginManager';
3
+ const APPLICATIONS = ['applied', 'restart-required', 'overridden', 'failed', 'cancelled'];
4
+ const STAGES = ['install', 'enable', 'remove'];
5
+ const PROBLEMS = [
6
+ 'invalid-spec',
7
+ 'already-installed',
8
+ 'not-found',
9
+ 'not-a-package',
10
+ 'not-a-bundle',
11
+ 'not-a-workbench-module',
12
+ 'network',
13
+ 'unknown',
14
+ ];
15
+ const SPEC_KINDS = ['registry', 'path', 'git', 'tarball'];
16
+ const FAILURE_KINDS = [
17
+ 'pnpm-missing',
18
+ 'timeout',
19
+ 'not-found',
20
+ 'no-matching-version',
21
+ 'network',
22
+ 'disk-full',
23
+ 'permission',
24
+ 'build-blocked',
25
+ 'integrity',
26
+ 'unknown',
27
+ ];
28
+ const CANCELLATIONS = ['cancelled', 'too-late', 'not-running'];
29
+ function asRecord(value) {
30
+ return typeof value === 'object' && value !== null ? value : undefined;
31
+ }
32
+ function asText(value) {
33
+ return typeof value === 'string' ? value : '';
34
+ }
35
+ function pick(allowed, value) {
36
+ return typeof value === 'string' && allowed.includes(value) ? value : undefined;
37
+ }
38
+ function asRegistry(value) {
39
+ if (value === null)
40
+ return null;
41
+ return typeof value === 'string' ? value : undefined;
42
+ }
43
+ function asTextArray(value) {
44
+ return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
45
+ }
46
+ function asRegistries(raw) {
47
+ const record = asRecord(raw);
48
+ if (record === undefined)
49
+ return null;
50
+ const registry = asRegistry(record.registry);
51
+ if (registry === undefined)
52
+ return null;
53
+ return {
54
+ registry,
55
+ fallbackRegistries: asTextArray(record.fallbackRegistries),
56
+ resolved: typeof record.resolved === 'string' ? record.resolved : null,
57
+ };
58
+ }
59
+ function asPackageResult(raw) {
60
+ const record = asRecord(raw);
61
+ if (record === undefined)
62
+ return undefined;
63
+ const kind = pick(FAILURE_KINDS, record.kind);
64
+ return {
65
+ exitCode: typeof record.exitCode === 'number' ? record.exitCode : -1,
66
+ output: asText(record.output),
67
+ truncated: record.truncated === true,
68
+ logPath: asText(record.logPath),
69
+ ...(kind === undefined ? {} : { kind }),
70
+ };
71
+ }
72
+ function asChange(raw) {
73
+ const record = asRecord(raw);
74
+ if (record === undefined)
75
+ return null;
76
+ const application = pick(APPLICATIONS, record.application);
77
+ const stage = pick(STAGES, record.stage);
78
+ if (application === undefined || stage === undefined)
79
+ return null;
80
+ const error = asRecord(record.error);
81
+ const packageResult = asPackageResult(record.packageResult);
82
+ const pendingBuilds = asTextArray(record.pendingBuilds);
83
+ const restartReason = pick(RESTART_REASONS, record.restartReason);
84
+ const failedAt = pick(['registry', 'spec-host'], record.failedAt);
85
+ const bundle = asText(record.bundle);
86
+ const version = asText(record.version);
87
+ const errorCode = error === undefined ? '' : asText(error.code);
88
+ const errorDetail = error === undefined ? '' : asText(error.diagnostic);
89
+ const incompatible = asIncompatibleList(error?.incompatible);
90
+ return {
91
+ application,
92
+ stage,
93
+ changed: record.changed === true,
94
+ target: asText(record.target),
95
+ ...(bundle === '' ? {} : { bundle }),
96
+ ...(version === '' ? {} : { version }),
97
+ ...(errorCode === '' ? {} : { errorCode }),
98
+ ...(errorDetail === '' ? {} : { errorDetail }),
99
+ ...(incompatible.length === 0 ? {} : { incompatible }),
100
+ ...(packageResult === undefined ? {} : { packageResult }),
101
+ ...(pendingBuilds.length === 0 ? {} : { pendingBuilds }),
102
+ ...(restartReason === undefined ? {} : { restartReason }),
103
+ ...(failedAt === undefined ? {} : { failedAt }),
104
+ };
105
+ }
106
+ function asInspection(raw) {
107
+ const record = asRecord(raw);
108
+ if (record === undefined)
109
+ return null;
110
+ const status = asText(record.status);
111
+ if (status === 'refused') {
112
+ const problem = pick(PROBLEMS, record.problem) ?? 'unknown';
113
+ const registries = Array.isArray(record.registries)
114
+ ? record.registries.map(asRegistry).filter((item) => item !== undefined)
115
+ : [];
116
+ return {
117
+ status: 'refused',
118
+ problem,
119
+ reason: asText(record.reason),
120
+ ...(registries.length === 0 ? {} : { registries }),
121
+ };
122
+ }
123
+ if (status !== 'accepted')
124
+ return null;
125
+ const kind = pick(SPEC_KINDS, record.kind);
126
+ const registry = asRegistry(record.registry);
127
+ if (kind === undefined || registry === undefined)
128
+ return null;
129
+ const name = asText(record.name);
130
+ const version = asText(record.version);
131
+ const description = asText(record.description);
132
+ const host = asText(record.host);
133
+ return {
134
+ status: 'accepted',
135
+ kind,
136
+ bundle: typeof record.bundle === 'boolean' ? record.bundle : null,
137
+ registry,
138
+ ...(name === '' ? {} : { name }),
139
+ ...(version === '' ? {} : { version }),
140
+ ...(description === '' ? {} : { description }),
141
+ ...(host === '' ? {} : { host }),
142
+ };
143
+ }
144
+ const VERSION_PROBLEMS = ['not-updatable', 'not-found', 'network', 'unknown'];
145
+ const UPDATE_STEPS = ['check', 'remove', 'install'];
146
+ function asRequirementMap(value) {
147
+ const record = asRecord(value);
148
+ if (record === undefined)
149
+ return {};
150
+ const entries = [];
151
+ for (const [key, raw] of Object.entries(record)) {
152
+ if (typeof raw === 'string')
153
+ entries.push([key, raw]);
154
+ }
155
+ return Object.fromEntries(entries);
156
+ }
157
+ function asIncompatible(raw) {
158
+ const record = asRecord(raw);
159
+ if (record === undefined)
160
+ return undefined;
161
+ const name = asText(record.name);
162
+ const version = asText(record.version);
163
+ const runtimeVersion = asText(record.runtimeVersion);
164
+ if (name === '' || version === '' || runtimeVersion === '')
165
+ return undefined;
166
+ return { name, version, runtimeVersion, requirements: asRequirementMap(record.requirements) };
167
+ }
168
+ function asIncompatibleList(raw) {
169
+ if (!Array.isArray(raw))
170
+ return [];
171
+ const rows = [];
172
+ for (const item of raw) {
173
+ const entry = asIncompatible(item);
174
+ if (entry !== undefined)
175
+ rows.push(entry);
176
+ }
177
+ return rows;
178
+ }
179
+ function asRegistryAttempt(raw) {
180
+ const record = asRecord(raw);
181
+ if (record === undefined)
182
+ return undefined;
183
+ const registry = asRegistry(record.registry);
184
+ if (registry === undefined)
185
+ return undefined;
186
+ const problem = pick(VERSION_PROBLEMS, record.problem);
187
+ const reason = asText(record.reason);
188
+ return {
189
+ registry,
190
+ ...(problem === undefined ? {} : { problem }),
191
+ ...(reason === '' ? {} : { reason }),
192
+ };
193
+ }
194
+ function asRegistryAttempts(raw) {
195
+ if (!Array.isArray(raw))
196
+ return [];
197
+ const rows = [];
198
+ for (const item of raw) {
199
+ const attempt = asRegistryAttempt(item);
200
+ if (attempt !== undefined)
201
+ rows.push(attempt);
202
+ }
203
+ return rows;
204
+ }
205
+ function asVersionEntry(raw) {
206
+ const record = asRecord(raw);
207
+ if (record === undefined)
208
+ return null;
209
+ const version = asText(record.version);
210
+ if (version === '')
211
+ return null;
212
+ const publishedAt = asText(record.publishedAt);
213
+ const deprecated = asText(record.deprecated);
214
+ const incompatible = asIncompatible(record.incompatible);
215
+ return {
216
+ version,
217
+ tags: asTextArray(record.tags),
218
+ prerelease: record.prerelease === true,
219
+ bundle: record.bundle === true,
220
+ ...(publishedAt === '' ? {} : { publishedAt }),
221
+ ...(deprecated === '' ? {} : { deprecated }),
222
+ ...(incompatible === undefined ? {} : { incompatible }),
223
+ };
224
+ }
225
+ function asVersionList(raw) {
226
+ const record = asRecord(raw);
227
+ if (record === undefined)
228
+ return null;
229
+ const status = asText(record.status);
230
+ const attempts = asRegistryAttempts(record.attempts);
231
+ if (status === 'refused') {
232
+ return {
233
+ status: 'refused',
234
+ problem: pick(VERSION_PROBLEMS, record.problem) ?? 'unknown',
235
+ reason: asText(record.reason),
236
+ attempts,
237
+ };
238
+ }
239
+ if (status !== 'listed')
240
+ return null;
241
+ const registry = asRegistry(record.registry);
242
+ const versions = [];
243
+ if (Array.isArray(record.versions)) {
244
+ for (const item of record.versions) {
245
+ const entry = asVersionEntry(item);
246
+ if (entry !== null)
247
+ versions.push(entry);
248
+ }
249
+ }
250
+ return {
251
+ status: 'listed',
252
+ installed: asText(record.installed),
253
+ registry: registry ?? null,
254
+ attempts,
255
+ versions,
256
+ omitted: typeof record.omitted === 'number' ? record.omitted : 0,
257
+ };
258
+ }
259
+ function asUpdateOutcome(raw) {
260
+ const record = asRecord(raw);
261
+ if (record === undefined)
262
+ return null;
263
+ const step = pick(UPDATE_STEPS, record.step);
264
+ const change = asChange(record.result);
265
+ if (step === undefined || change === null)
266
+ return null;
267
+ const restore = record.restore === undefined ? null : asChange(record.restore);
268
+ return {
269
+ from: asText(record.from),
270
+ to: asText(record.to),
271
+ step,
272
+ change,
273
+ ...(restore === null ? {} : { restore }),
274
+ };
275
+ }
276
+ export function readBundleManager(ctx) {
277
+ const face = ctx.get(PLUGIN_MANAGER_SERVICE);
278
+ if (face === undefined)
279
+ return undefined;
280
+ if (typeof face.installBundle !== 'function' || typeof face.removeBundle !== 'function')
281
+ return undefined;
282
+ return {
283
+ async registries() {
284
+ if (typeof face.registries !== 'function')
285
+ return null;
286
+ return asRegistries(await face.registries());
287
+ },
288
+ async inspect(spec, registry) {
289
+ if (typeof face.inspect !== 'function')
290
+ return null;
291
+ return asInspection(await face.inspect(spec, registry === undefined ? undefined : { registry }));
292
+ },
293
+ async install(request) {
294
+ const options = {
295
+ ...(request.registry === undefined ? {} : { registry: request.registry }),
296
+ ...(request.requestId === undefined
297
+ ? {}
298
+ : { requestId: request.requestId }),
299
+ ...(request.approvedBuilds === undefined ? {} : { approvedBuilds: [...request.approvedBuilds] }),
300
+ };
301
+ return asChange(await face.installBundle?.(request.spec, options));
302
+ },
303
+ async remove(name) {
304
+ return asChange(await face.removeBundle?.(name));
305
+ },
306
+ async setEnabled(name, enabled) {
307
+ if (typeof face.setBundleEnabled !== 'function')
308
+ return null;
309
+ return asChange(await face.setBundleEnabled(name, enabled));
310
+ },
311
+ async cancel(requestId) {
312
+ if (typeof face.cancelInstall !== 'function')
313
+ return null;
314
+ return pick(CANCELLATIONS, (asRecord(await face.cancelInstall(requestId)) ?? {}).status) ?? null;
315
+ },
316
+ async listVersions(name, registry) {
317
+ if (typeof face.listVersions !== 'function')
318
+ return null;
319
+ return asVersionList(await face.listVersions(name, registry === undefined ? undefined : { registry }));
320
+ },
321
+ async updateBundle(name, version, request = {}) {
322
+ if (typeof face.updateBundle !== 'function')
323
+ return null;
324
+ const options = {
325
+ ...(request.registry === undefined ? {} : { registry: request.registry }),
326
+ ...(request.requestId === undefined
327
+ ? {}
328
+ : { requestId: request.requestId }),
329
+ };
330
+ return asUpdateOutcome(await face.updateBundle(name, version, options));
331
+ },
332
+ async waitForInstall(requestId) {
333
+ if (typeof face.waitForInstall !== 'function')
334
+ return null;
335
+ return asChange(await face.waitForInstall(requestId));
336
+ },
337
+ };
338
+ }
@@ -0,0 +1,28 @@
1
+ export declare const CHANGELOG_FILE = "CHANGELOG.md";
2
+ export declare const CHANGELOG_KINDS: readonly ["added", "changed", "fixed", "removed", "security", "deprecated"];
3
+ export type ChangelogKind = (typeof CHANGELOG_KINDS)[number];
4
+ export interface ChangelogSection {
5
+ readonly version: string;
6
+ readonly body: string;
7
+ }
8
+ export interface ChangelogEntryOptions {
9
+ readonly version: string;
10
+ readonly kind?: ChangelogKind | undefined;
11
+ readonly note: string;
12
+ readonly date?: string | undefined;
13
+ }
14
+ export declare function changelogVersion(value: string): string;
15
+ export declare function changelogDate(now?: Date): string;
16
+ export declare function normalizeChangelogText(text: string): string;
17
+ export declare function changelogSkeleton(): string;
18
+ export declare function parseChangelog(text: string): readonly ChangelogSection[];
19
+ export declare function changelogSectionOf(text: string, version: string): string | undefined;
20
+ export declare function changelogHasEntry(text: string, version: string): boolean;
21
+ export declare function appendChangelogEntry(text: string, options: ChangelogEntryOptions): string;
22
+ export interface ChangelogPlan {
23
+ readonly action: 'kept' | 'written';
24
+ readonly version: string;
25
+ readonly text: string;
26
+ readonly section: string;
27
+ }
28
+ export declare function planChangelog(text: string, options: ChangelogEntryOptions): ChangelogPlan | undefined;