@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,13 @@
1
+ export { splitNpmSpec } from './spec.js';
2
+ export type { NpmRef } from './spec.js';
3
+ export type PackageKind = 'runtime-plugin' | 'dsh-bundle' | 'both' | 'neither';
4
+ export interface PackageVerdict {
5
+ readonly kind: PackageKind;
6
+ readonly pkg?: string;
7
+ readonly pluginName?: string;
8
+ }
9
+ export declare function isCommandFile(name: string): boolean;
10
+ export declare function pluginManifestOf(dir: string, manifestFile: string): Readonly<Record<string, unknown>> | undefined;
11
+ export declare function hasCommandFile(dir: string): boolean;
12
+ export declare function dshMarkersOf(raw: unknown): boolean;
13
+ export declare function verdictOf(dir: string, manifestFile: string): PackageVerdict | undefined;
@@ -0,0 +1,51 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export { splitNpmSpec } from './spec.js';
4
+ import { dshRecordOf, packageManifestOf, packageNameOf } from './local-declaration.js';
5
+ import { pluginAt } from './plugin.js';
6
+ function asRecord(value) {
7
+ return typeof value === 'object' && value !== null ? value : undefined;
8
+ }
9
+ export function isCommandFile(name) {
10
+ if (name.endsWith('.d.ts') || name.endsWith('.test.ts'))
11
+ return false;
12
+ if (name.endsWith('.d.js'))
13
+ return false;
14
+ return name.endsWith('.ts') || name.endsWith('.js');
15
+ }
16
+ export function pluginManifestOf(dir, manifestFile) {
17
+ try {
18
+ const parsed = JSON.parse(fs.readFileSync(path.join(dir, manifestFile), 'utf8'));
19
+ if (Array.isArray(parsed))
20
+ return undefined;
21
+ return asRecord(parsed);
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }
27
+ export function hasCommandFile(dir) {
28
+ try {
29
+ return fs.readdirSync(dir).some(isCommandFile);
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ export function dshMarkersOf(raw) {
36
+ const record = asRecord(raw);
37
+ return record !== undefined && ('bundle' in record || 'workbench' in record);
38
+ }
39
+ export function verdictOf(dir, manifestFile) {
40
+ const plugin = pluginAt(dir, manifestFile);
41
+ if (packageManifestOf(dir) === undefined && plugin === undefined)
42
+ return undefined;
43
+ const dsh = dshMarkersOf(dshRecordOf(dir));
44
+ const kind = plugin !== undefined && dsh ? 'both' : plugin !== undefined ? 'runtime-plugin' : dsh ? 'dsh-bundle' : 'neither';
45
+ const pkg = packageNameOf(dir);
46
+ return {
47
+ kind,
48
+ ...(pkg === undefined ? {} : { pkg }),
49
+ ...(plugin?.name === undefined ? {} : { pluginName: plugin.name }),
50
+ };
51
+ }
@@ -0,0 +1,33 @@
1
+ import type { Seam } from './seam/run.js';
2
+ export type PackageRouteKind = 'runtime-plugin' | 'dsh-bundle' | 'neither';
3
+ export interface PackageRoute {
4
+ readonly kind: PackageRouteKind;
5
+ readonly pkg?: string;
6
+ readonly pluginName?: string;
7
+ }
8
+ export interface PackageRouter {
9
+ packageRouteOf(options: RouteOptions): Promise<PackageRoute | undefined>;
10
+ reset(): void;
11
+ }
12
+ interface RouteOptions {
13
+ readonly spec: string;
14
+ readonly seam?: Seam | undefined;
15
+ readonly registry?: string | undefined;
16
+ readonly force?: boolean;
17
+ }
18
+ export type ScratchRootSource = string | ((seam: Seam) => string | undefined);
19
+ export interface PackageRouterOptions {
20
+ readonly manifestFile: string;
21
+ readonly cacheDir?: string | undefined;
22
+ readonly scratchRoot?: ScratchRootSource | undefined;
23
+ readonly dshLookup?: ((options: {
24
+ seam: Seam;
25
+ name: string;
26
+ registry: string;
27
+ }) => Promise<{
28
+ readable: boolean;
29
+ raw: unknown;
30
+ }>) | undefined;
31
+ }
32
+ export declare function createPackageRouter(options: PackageRouterOptions): PackageRouter;
33
+ export {};
@@ -0,0 +1,68 @@
1
+ import { now } from './time.js';
2
+ import { VERSION_CHECK_TTL_MS } from '../config/constants.js';
3
+ import { dshMarkersOf, splitNpmSpec, verdictOf } from './package-kind.js';
4
+ import { withPackageDir } from './package-content.js';
5
+ import { localDirOf } from './local-declaration.js';
6
+ function routeOfVerdict(verdict, fallback) {
7
+ const pkg = verdict.pkg ?? fallback;
8
+ if (verdict.kind === 'neither')
9
+ return { kind: 'neither', ...(pkg === undefined ? {} : { pkg }) };
10
+ if (verdict.kind === 'dsh-bundle' || verdict.kind === 'both')
11
+ return { kind: 'dsh-bundle' };
12
+ return {
13
+ kind: 'runtime-plugin',
14
+ ...(pkg === undefined ? {} : { pkg }),
15
+ ...(verdict.pluginName === undefined ? {} : { pluginName: verdict.pluginName }),
16
+ };
17
+ }
18
+ function scratchRootOf(source, seam) {
19
+ return typeof source === 'function' ? source(seam) : source;
20
+ }
21
+ export function createPackageRouter(options) {
22
+ const cache = new Map();
23
+ return {
24
+ packageRouteOf: (routeOptions) => routeOf(cache, options, routeOptions),
25
+ reset: () => {
26
+ cache.clear();
27
+ },
28
+ };
29
+ }
30
+ async function routeOf(cache, options, routeOptions) {
31
+ const local = localDirOf(routeOptions.spec);
32
+ if (local !== undefined) {
33
+ const verdict = verdictOf(local, options.manifestFile);
34
+ return verdict === undefined ? undefined : routeOfVerdict(verdict, splitNpmSpec(routeOptions.spec)?.name);
35
+ }
36
+ const ref = splitNpmSpec(routeOptions.spec);
37
+ if (ref === undefined)
38
+ return undefined;
39
+ const seam = routeOptions.seam;
40
+ const registry = routeOptions.registry;
41
+ if (seam === undefined || registry === undefined)
42
+ return undefined;
43
+ const key = `${registry}|${routeOptions.spec}`;
44
+ const hit = cache.get(key);
45
+ if (routeOptions.force !== true && hit !== undefined && now() - hit.at < VERSION_CHECK_TTL_MS) {
46
+ return hit.route ?? undefined;
47
+ }
48
+ const found = options.dshLookup === undefined
49
+ ? { readable: false, raw: undefined }
50
+ : await options.dshLookup({ seam, name: routeOptions.spec, registry });
51
+ let route;
52
+ if (found.readable && dshMarkersOf(found.raw)) {
53
+ route = { kind: 'dsh-bundle' };
54
+ }
55
+ else {
56
+ const scratchRoot = scratchRootOf(options.scratchRoot, seam);
57
+ const verdict = await withPackageDir({
58
+ seam,
59
+ spec: routeOptions.spec,
60
+ registry,
61
+ ...(options.cacheDir === undefined ? {} : { cacheDir: options.cacheDir }),
62
+ ...(scratchRoot === undefined ? {} : { scratchRoot }),
63
+ }, (dir) => verdictOf(dir, options.manifestFile));
64
+ route = verdict === undefined ? undefined : routeOfVerdict(verdict, ref.name);
65
+ }
66
+ cache.set(key, { at: now(), route: route ?? null });
67
+ return route;
68
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * 一张面板卡片取数走到哪一步:`idle` 还没取、`loading` 取着、`ready` 拿到了、`error` 失败了。
3
+ */
4
+ export type PanelCardPhase = 'idle' | 'loading' | 'ready' | 'error';
5
+ /**
6
+ * 一次取数失败:机器码 + 给人看的一句话。
7
+ */
8
+ export interface PanelCardError {
9
+ readonly code: string;
10
+ readonly message: string;
11
+ }
12
+ /**
13
+ * 一张卡片最近一次取数的读数:哪个单元、哪条路由、什么相位、什么时候、失败原因。
14
+ */
15
+ export interface PanelCardRead {
16
+ readonly unit: string;
17
+ readonly route: string;
18
+ readonly phase: PanelCardPhase;
19
+ readonly at: number;
20
+ readonly error?: PanelCardError;
21
+ }
22
+ /**
23
+ * 一张卡片崩了的读数:单元、原因、时间,以及同一原因连着崩了几次(窗口见 `PANEL_STATE_CRASH_WINDOW_MS`)。
24
+ */
25
+ export interface PanelCardCrash {
26
+ readonly unit: string;
27
+ readonly reason: string;
28
+ readonly at: number;
29
+ readonly count: number;
30
+ }
31
+ /**
32
+ * 一个单元此刻的读数:它的卡片、最近一次读成的时间(`okAt`,没成过给 `null`),以及崩了的那一条。
33
+ */
34
+ export interface PanelUnitReport {
35
+ readonly unit: string;
36
+ readonly at: number;
37
+ readonly okAt: number | null;
38
+ readonly cards: readonly PanelCardRead[];
39
+ readonly crash?: PanelCardCrash;
40
+ }
41
+ /**
42
+ * 一个工作区此刻的全量读数(面板按工作区存):所有单元的读数 + 整块最近动过的时间。
43
+ */
44
+ export interface PanelWorkspaceReport {
45
+ readonly workspace: string | null;
46
+ readonly at: number;
47
+ readonly units: readonly PanelUnitReport[];
48
+ }
49
+ /**
50
+ * 客户端往上报的一批卡片读数(`POST` 请求体的形状)。
51
+ */
52
+ export interface PanelCardsReport {
53
+ readonly workspace: string;
54
+ readonly cards: readonly PanelCardRead[];
55
+ }
56
+ /**
57
+ * 客户端往上报的一次卡片崩溃(`POST` 请求体的形状)。
58
+ */
59
+ export interface PanelCrashReport {
60
+ readonly workspace: string;
61
+ readonly unit: string;
62
+ readonly reason: string;
63
+ readonly at: number;
64
+ }
65
+ /**
66
+ * 面板运行态的留存口(宿主持有一份):收卡片读数与崩溃,按工作区取快照。
67
+ */
68
+ export interface PanelStateStore {
69
+ cards(report: PanelCardsReport): void;
70
+ crash(report: PanelCrashReport): void;
71
+ snapshot(workspace: string | null): PanelWorkspaceReport;
72
+ }
73
+ /**
74
+ * 留存的工作区上限(LRU,满 64 个丢最旧的)。
75
+ */
76
+ export declare const PANEL_STATE_MAX_UNITS = 64;
77
+ /**
78
+ * 每个单元留存的卡片上限(按路由 LRU,满 12 张丢最旧的)。
79
+ */
80
+ export declare const PANEL_STATE_MAX_CARDS = 12;
81
+ /**
82
+ * 一次上报最多读入的卡片条数(32 条之后的丢掉)。
83
+ */
84
+ export declare const PANEL_STATE_MAX_REPORTS = 32;
85
+ /**
86
+ * 同一原因的连续崩溃算进同一次计数的窗口(10 分钟,毫秒)。
87
+ */
88
+ export declare const PANEL_STATE_CRASH_WINDOW_MS = 600000;
89
+ /**
90
+ * 上报文本字段的截断长度(2000 字符;workspace / reason / message 共用)。
91
+ */
92
+ export declare const PANEL_STATE_MAX_TEXT = 2000;
93
+ /**
94
+ * 上报解析的结果:`ok: true` 带收好的值,`ok: false` 带一句中文原因(直接回给上报方)。
95
+ */
96
+ export type PanelParse<T> = {
97
+ readonly ok: true;
98
+ readonly value: T;
99
+ } | {
100
+ readonly ok: false;
101
+ readonly message: string;
102
+ };
103
+ /**
104
+ * 收一批卡片读数上报。
105
+ * @param payload - `POST` 的请求体。
106
+ * @returns 至少收到一条能认的卡片才 `ok: true`;请求体不是对象、`workspace` 为空、`cards` 不是数组,
107
+ * 或一条都认不出(`unit` / `route` / `phase` / `at` 缺一)时 `ok: false` + 中文原因;认不出的单条静默跳过。
108
+ */
109
+ export declare function parseCardsReport(payload: unknown): PanelParse<PanelCardsReport>;
110
+ /**
111
+ * 收一次卡片崩溃上报。
112
+ * @param payload - `POST` 的请求体。
113
+ * @returns `workspace` / `unit` / `reason` 都不能空,缺一给 `ok: false` + 中文原因;`at` 缺省或不合法时取当前时间。
114
+ */
115
+ export declare function parseCrashReport(payload: unknown): PanelParse<PanelCrashReport>;
116
+ /**
117
+ * 造一份面板运行态的留存(进程内存、按工作区分桶,带上面那几条上限的 LRU)。
118
+ * @returns 留存口:`cards` / `crash` 收上报,`snapshot(workspace)` 取全量;没存过的工作区(含 `null`)给一份空的。
119
+ */
120
+ export declare function createPanelStateStore(): PanelStateStore;
@@ -0,0 +1,177 @@
1
+ import { now } from './time.js';
2
+ /**
3
+ * 留存的工作区上限(LRU,满 64 个丢最旧的)。
4
+ */
5
+ export const PANEL_STATE_MAX_UNITS = 64;
6
+ /**
7
+ * 每个单元留存的卡片上限(按路由 LRU,满 12 张丢最旧的)。
8
+ */
9
+ export const PANEL_STATE_MAX_CARDS = 12;
10
+ /**
11
+ * 一次上报最多读入的卡片条数(32 条之后的丢掉)。
12
+ */
13
+ export const PANEL_STATE_MAX_REPORTS = 32;
14
+ /**
15
+ * 同一原因的连续崩溃算进同一次计数的窗口(10 分钟,毫秒)。
16
+ */
17
+ export const PANEL_STATE_CRASH_WINDOW_MS = 600000;
18
+ /**
19
+ * 上报文本字段的截断长度(2000 字符;workspace / reason / message 共用)。
20
+ */
21
+ export const PANEL_STATE_MAX_TEXT = 2000;
22
+ const PHASES = ['idle', 'loading', 'ready', 'error'];
23
+ function asRecord(value) {
24
+ return typeof value === 'object' && value !== null ? value : undefined;
25
+ }
26
+ function textOf(value, max) {
27
+ if (typeof value !== 'string')
28
+ return '';
29
+ const trimmed = value.trim();
30
+ return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
31
+ }
32
+ function atOf(value) {
33
+ if (typeof value !== 'number' || !Number.isFinite(value))
34
+ return null;
35
+ if (value < 0)
36
+ return null;
37
+ return Math.trunc(value);
38
+ }
39
+ function errorOf(raw) {
40
+ const record = asRecord(raw);
41
+ if (record === undefined)
42
+ return undefined;
43
+ const code = textOf(record['code'], 120);
44
+ const message = textOf(record['message'], PANEL_STATE_MAX_TEXT);
45
+ if (code === '' && message === '')
46
+ return undefined;
47
+ return { code: code === '' ? 'unknown' : code, message };
48
+ }
49
+ /**
50
+ * 收一批卡片读数上报。
51
+ * @param payload - `POST` 的请求体。
52
+ * @returns 至少收到一条能认的卡片才 `ok: true`;请求体不是对象、`workspace` 为空、`cards` 不是数组,
53
+ * 或一条都认不出(`unit` / `route` / `phase` / `at` 缺一)时 `ok: false` + 中文原因;认不出的单条静默跳过。
54
+ */
55
+ export function parseCardsReport(payload) {
56
+ const record = asRecord(payload);
57
+ if (record === undefined)
58
+ return { ok: false, message: '请求体要是一个对象' };
59
+ const workspace = textOf(record['workspace'], PANEL_STATE_MAX_TEXT);
60
+ if (workspace === '')
61
+ return { ok: false, message: 'workspace 不能是空的 —— 面板按工作区存' };
62
+ const raw = record['cards'];
63
+ if (!Array.isArray(raw))
64
+ return { ok: false, message: 'cards 要是一个数组' };
65
+ const cards = [];
66
+ for (const item of raw.slice(0, PANEL_STATE_MAX_REPORTS)) {
67
+ const card = asRecord(item);
68
+ if (card === undefined)
69
+ continue;
70
+ const unit = textOf(card['unit'], 200);
71
+ const route = textOf(card['route'], 400);
72
+ const phase = textOf(card['phase'], 20);
73
+ const at = atOf(card['at']);
74
+ if (unit === '' || route === '' || at === null || !PHASES.includes(phase))
75
+ continue;
76
+ const error = errorOf(card['error']);
77
+ cards.push({ unit, route, phase, at, ...(error === undefined ? {} : { error }) });
78
+ }
79
+ if (cards.length === 0)
80
+ return { ok: false, message: 'cards 里没有一条能认的(unit / route / phase / at 都要有)' };
81
+ return { ok: true, value: { workspace, cards } };
82
+ }
83
+ /**
84
+ * 收一次卡片崩溃上报。
85
+ * @param payload - `POST` 的请求体。
86
+ * @returns `workspace` / `unit` / `reason` 都不能空,缺一给 `ok: false` + 中文原因;`at` 缺省或不合法时取当前时间。
87
+ */
88
+ export function parseCrashReport(payload) {
89
+ const record = asRecord(payload);
90
+ if (record === undefined)
91
+ return { ok: false, message: '请求体要是一个对象' };
92
+ const workspace = textOf(record['workspace'], PANEL_STATE_MAX_TEXT);
93
+ const unit = textOf(record['unit'], 200);
94
+ const reason = textOf(record['reason'], PANEL_STATE_MAX_TEXT);
95
+ if (workspace === '')
96
+ return { ok: false, message: 'workspace 不能是空的' };
97
+ if (unit === '')
98
+ return { ok: false, message: 'unit 不能是空的' };
99
+ if (reason === '')
100
+ return { ok: false, message: 'reason 不能是空的(没有原因的崩溃没法查)' };
101
+ return { ok: true, value: { workspace, unit, reason, at: atOf(record['at']) ?? now() } };
102
+ }
103
+ /**
104
+ * 造一份面板运行态的留存(进程内存、按工作区分桶,带上面那几条上限的 LRU)。
105
+ * @returns 留存口:`cards` / `crash` 收上报,`snapshot(workspace)` 取全量;没存过的工作区(含 `null`)给一份空的。
106
+ */
107
+ export function createPanelStateStore() {
108
+ const workspaces = new Map();
109
+ function trim(entry, max) {
110
+ while (entry.size > max) {
111
+ const oldest = entry.keys().next();
112
+ if (oldest.done === true)
113
+ return;
114
+ entry.delete(oldest.value);
115
+ }
116
+ }
117
+ function workspaceEntryOf(workspace) {
118
+ const existing = workspaces.get(workspace);
119
+ if (existing !== undefined)
120
+ return existing;
121
+ const created = { at: 0, units: new Map() };
122
+ workspaces.set(workspace, created);
123
+ trim(workspaces, PANEL_STATE_MAX_UNITS);
124
+ return created;
125
+ }
126
+ function unitEntryOf(entry, unit) {
127
+ const existing = entry.units.get(unit);
128
+ if (existing !== undefined)
129
+ return existing;
130
+ const created = { at: 0, cards: new Map() };
131
+ entry.units.set(unit, created);
132
+ return created;
133
+ }
134
+ return {
135
+ cards(report) {
136
+ const entry = workspaceEntryOf(report.workspace);
137
+ for (const card of report.cards) {
138
+ const unit = unitEntryOf(entry, card.unit);
139
+ unit.cards.delete(card.route);
140
+ unit.cards.set(card.route, card);
141
+ trim(unit.cards, PANEL_STATE_MAX_CARDS);
142
+ if (card.at > unit.at)
143
+ unit.at = card.at;
144
+ if (card.at > entry.at)
145
+ entry.at = card.at;
146
+ }
147
+ },
148
+ crash(report) {
149
+ const entry = workspaceEntryOf(report.workspace);
150
+ const unit = unitEntryOf(entry, report.unit);
151
+ const previous = unit.crash;
152
+ const counted = previous !== undefined &&
153
+ previous.reason === report.reason &&
154
+ report.at >= previous.at &&
155
+ report.at - previous.at <= PANEL_STATE_CRASH_WINDOW_MS;
156
+ unit.crash = { unit: report.unit, reason: report.reason, at: report.at, count: counted ? previous.count + 1 : 1 };
157
+ if (report.at > unit.at)
158
+ unit.at = report.at;
159
+ if (report.at > entry.at)
160
+ entry.at = report.at;
161
+ },
162
+ snapshot(workspace) {
163
+ if (workspace === null)
164
+ return { workspace: null, at: 0, units: [] };
165
+ const entry = workspaces.get(workspace);
166
+ if (entry === undefined)
167
+ return { workspace, at: 0, units: [] };
168
+ const units = [...entry.units.entries()].map(([unit, one]) => {
169
+ const cards = [...one.cards.values()].sort((a, b) => a.route.localeCompare(b.route));
170
+ const okAt = cards.reduce((best, card) => (card.phase === 'ready' && (best === null || card.at > best) ? card.at : best), null);
171
+ return { unit, at: one.at, okAt, cards, ...(one.crash === undefined ? {} : { crash: one.crash }) };
172
+ });
173
+ units.sort((a, b) => b.at - a.at || a.unit.localeCompare(b.unit));
174
+ return { workspace, at: entry.at, units };
175
+ },
176
+ };
177
+ }
@@ -0,0 +1,13 @@
1
+ export interface PatchBlock {
2
+ readonly key: string;
3
+ readonly id: string;
4
+ readonly insert: boolean;
5
+ readonly body: string;
6
+ readonly names: readonly string[];
7
+ }
8
+ export interface SpannedBlock extends PatchBlock {
9
+ readonly from: number;
10
+ readonly to: number;
11
+ }
12
+ export declare function spannedBlocks(text: string): SpannedBlock[];
13
+ export declare function patchBlocks(text: string): PatchBlock[];
@@ -0,0 +1,52 @@
1
+ const ID_LINE = /^- id:[ \t]*"?([^"\s#]+)/;
2
+ const INSERT_LINE = /^- insert:[ \t]*$/;
3
+ const NESTED_ID = /^[ \t]+-[ \t]*id:[ \t]*"?([^"\s#]+)/;
4
+ const NAME_LINE = /^[ \t]*-?[ \t]*name:[ \t]*['"]?([^'"\s#]+)/;
5
+ function trimmedTail(lines) {
6
+ let end = lines.length;
7
+ while (end > 0 && (lines[end - 1] ?? '').trim() === '')
8
+ end -= 1;
9
+ return lines.slice(0, end);
10
+ }
11
+ function matched(text, pattern) {
12
+ const found = pattern.exec(text);
13
+ return found === null ? undefined : found[1];
14
+ }
15
+ function blockOf(body, index) {
16
+ const lines = body.split('\n');
17
+ const first = lines[0] ?? '';
18
+ const id = matched(first, ID_LINE);
19
+ const nested = lines.flatMap((line) => {
20
+ const one = matched(line, NESTED_ID);
21
+ return one === undefined ? [] : [one];
22
+ });
23
+ const insert = id === undefined && INSERT_LINE.test(first);
24
+ const label = id ?? nested.join(', ');
25
+ const key = id !== undefined ? `id:${id}` : insert ? `insert:${nested.join(', ')}` : `block:${String(index)}`;
26
+ const names = lines.flatMap((line) => {
27
+ const one = matched(line, NAME_LINE);
28
+ return one === undefined ? [] : [one];
29
+ });
30
+ return { key, id: label === '' ? key : label, insert, body, names };
31
+ }
32
+ export function spannedBlocks(text) {
33
+ const lines = text.split(/\r?\n/);
34
+ const starts = [];
35
+ lines.forEach((line, index) => {
36
+ if (/^- /.test(line) || line === '-')
37
+ starts.push(index);
38
+ });
39
+ const blocks = [];
40
+ for (let i = 0; i < starts.length; i += 1) {
41
+ const from = starts[i] ?? 0;
42
+ const to = i + 1 < starts.length ? (starts[i + 1] ?? lines.length) : lines.length;
43
+ const body = trimmedTail(lines.slice(from, to)).join('\n');
44
+ if (body.trim() === '')
45
+ continue;
46
+ blocks.push({ ...blockOf(body, blocks.length), from, to });
47
+ }
48
+ return blocks;
49
+ }
50
+ export function patchBlocks(text) {
51
+ return spannedBlocks(text).map(({ from: _from, to: _to, ...block }) => block);
52
+ }
@@ -0,0 +1,4 @@
1
+ import { patchBlocks, type PatchBlock } from './patch-blocks.js';
2
+ export { patchBlocks, type PatchBlock };
3
+ /** 把 patch 文本写回原文件:原子写,保留已有权限位(新文件 0644)。 */
4
+ export declare function writePatchFile(path: string, text: string): void;
@@ -0,0 +1,7 @@
1
+ import { writeTextFile } from './fs-write.js';
2
+ import { patchBlocks } from './patch-blocks.js';
3
+ export { patchBlocks };
4
+ /** 把 patch 文本写回原文件:原子写,保留已有权限位(新文件 0644)。 */
5
+ export function writePatchFile(path, text) {
6
+ writeTextFile(path, text, { mode: 'keep' });
7
+ }
@@ -0,0 +1,12 @@
1
+ export interface RuntimeLayout {
2
+ readonly root: string;
3
+ readonly home: string;
4
+ readonly vendorPrefix: string;
5
+ readonly vendorPluginsDir: string;
6
+ readonly libsPrefix: string;
7
+ readonly libsBinDir: string;
8
+ readonly npmCacheDir: string;
9
+ readonly pnpmStoreDir: string;
10
+ }
11
+ export declare function runtimeRootOf(id: string): string;
12
+ export declare function runtimeLayoutOf(id: string): RuntimeLayout;
@@ -0,0 +1,20 @@
1
+ import { join } from 'node:path';
2
+ import { workbenchRoot } from './data-root.js';
3
+ export function runtimeRootOf(id) {
4
+ return join(workbenchRoot(), id);
5
+ }
6
+ export function runtimeLayoutOf(id) {
7
+ const root = runtimeRootOf(id);
8
+ const vendorPrefix = join(root, 'plugins-npm');
9
+ const libsPrefix = join(root, 'libs');
10
+ return {
11
+ root,
12
+ home: join(root, 'home'),
13
+ vendorPrefix,
14
+ vendorPluginsDir: join(vendorPrefix, 'node_modules'),
15
+ libsPrefix,
16
+ libsBinDir: join(libsPrefix, 'node_modules', '.bin'),
17
+ npmCacheDir: join(root, 'npm-cache'),
18
+ pnpmStoreDir: join(root, 'pnpm-store'),
19
+ };
20
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 把任意 payload 当对象看;不是对象就回空对象。
3
+ * @param value 任意入参。
4
+ * @returns 可按下标取值的安全对象。
5
+ */
6
+ export declare function recordOf(value: unknown): Record<string, unknown>;
7
+ /**
8
+ * 把任意 payload 当一段文字看:字符串就 trim,别的都算空串。
9
+ * @param value 任意入参。
10
+ * @returns 去掉首尾空白的字符串;不是字符串时是空串。
11
+ */
12
+ export declare function textOf(value: unknown): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 把任意 payload 当对象看;不是对象就回空对象。
3
+ * @param value 任意入参。
4
+ * @returns 可按下标取值的安全对象。
5
+ */
6
+ export function recordOf(value) {
7
+ return typeof value === 'object' && value !== null ? value : {};
8
+ }
9
+ /**
10
+ * 把任意 payload 当一段文字看:字符串就 trim,别的都算空串。
11
+ * @param value 任意入参。
12
+ * @returns 去掉首尾空白的字符串;不是字符串时是空串。
13
+ */
14
+ export function textOf(value) {
15
+ return typeof value === 'string' ? value.trim() : '';
16
+ }
@@ -0,0 +1,5 @@
1
+ import type { DataError, PlanResults, RequestPlan } from '../contract/data.js';
2
+ export declare function planResultsOf(value: unknown, names?: readonly string[], options?: {
3
+ readonly loginUrl?: string | undefined;
4
+ }): PlanResults;
5
+ export declare function allSame(plan: RequestPlan, error: DataError): PlanResults;