@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,33 @@
1
+ export declare const UPDATE_JOURNAL_STATES: readonly ["prepared", "carrying", "flipping", "manifest", "committed"];
2
+ export type UpdateJournalState = (typeof UPDATE_JOURNAL_STATES)[number];
3
+ export declare const UPDATE_JOURNAL_LINK_KINDS: readonly ["symlink", "dir", "missing", "other"];
4
+ export type UpdateJournalLinkKind = (typeof UPDATE_JOURNAL_LINK_KINDS)[number];
5
+ export interface UpdateJournalLink {
6
+ readonly pkg: string;
7
+ readonly path: string;
8
+ readonly kind: UpdateJournalLinkKind;
9
+ readonly target?: string | undefined;
10
+ }
11
+ export interface UpdateJournalCarry {
12
+ readonly pkg: string;
13
+ readonly from: string;
14
+ readonly to: string;
15
+ }
16
+ export interface UpdateJournalRecord {
17
+ readonly schema: 1;
18
+ readonly state: UpdateJournalState;
19
+ readonly from: string;
20
+ readonly to: string;
21
+ readonly profileDir: string;
22
+ readonly versionsDir: string;
23
+ readonly versionDir: string;
24
+ readonly manifestPath: string;
25
+ readonly manifestText: string;
26
+ readonly manifestDeps?: Readonly<Record<string, string | null>> | undefined;
27
+ readonly links: readonly UpdateJournalLink[];
28
+ readonly carry: readonly UpdateJournalCarry[];
29
+ readonly cursor: number;
30
+ readonly carried: number;
31
+ readonly at: string;
32
+ readonly updatedAt?: string | undefined;
33
+ }
@@ -0,0 +1,2 @@
1
+ export const UPDATE_JOURNAL_STATES = ['prepared', 'carrying', 'flipping', 'manifest', 'committed'];
2
+ export const UPDATE_JOURNAL_LINK_KINDS = ['symlink', 'dir', 'missing', 'other'];
@@ -0,0 +1,43 @@
1
+ import { type UpdateJournalRecord } from './update-journal-types.js';
2
+ export declare function updateJournalFile(root: string): string;
3
+ export declare function writeUpdateJournal(file: string, record: UpdateJournalRecord): void;
4
+ export declare function clearUpdateJournal(file: string): void;
5
+ export declare function readUpdateJournal(file: string): UpdateJournalRecord | undefined;
6
+ export interface UpdateJournalRestoreInput {
7
+ readonly record: UpdateJournalRecord;
8
+ readonly file: string;
9
+ readonly log?: ((message: string) => void) | undefined;
10
+ }
11
+ export interface UpdateJournalRestoreResult {
12
+ readonly ok: boolean;
13
+ readonly detail: string;
14
+ }
15
+ export declare function restoreUpdateJournal(input: UpdateJournalRestoreInput): UpdateJournalRestoreResult;
16
+ export type UpdateJournalRecovery = {
17
+ readonly kind: 'none';
18
+ } | {
19
+ readonly kind: 'cleared';
20
+ readonly from: string;
21
+ readonly to: string;
22
+ readonly dirty?: true;
23
+ } | {
24
+ readonly kind: 'restored';
25
+ readonly from: string;
26
+ readonly to: string;
27
+ readonly detail: string;
28
+ } | {
29
+ readonly kind: 'kept';
30
+ readonly from: string;
31
+ readonly to: string;
32
+ readonly detail: string;
33
+ };
34
+ export interface UpdateJournalRecoveryInput {
35
+ readonly file: string;
36
+ readonly bootFile?: string | undefined;
37
+ readonly upFile?: string | undefined;
38
+ readonly markerPath?: string | undefined;
39
+ readonly at?: string | undefined;
40
+ readonly ignoreLease?: boolean | undefined;
41
+ readonly log?: ((message: string) => void) | undefined;
42
+ }
43
+ export declare function recoverUpdateJournal(input: UpdateJournalRecoveryInput): UpdateJournalRecovery;
@@ -0,0 +1,409 @@
1
+ import { existsSync, lstatSync, unlinkSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import dayjs from 'dayjs';
4
+ import { readBootRecord } from './boot-record.js';
5
+ import { ensureDir, linkDir, moveDir, removePath, writeJsonFile } from './fs-write.js';
6
+ import { acquireUpdateLease, updateLeaseActive } from './lease.js';
7
+ import { readJsonObject } from './read-json.js';
8
+ import { clearReinstallRecord, readReinstallRecord, reinstallRecordFile } from './reinstall-record.js';
9
+ import { restoreManifest, rollForward } from './update-journal-manifest.js';
10
+ import { UPDATE_JOURNAL_LINK_KINDS, UPDATE_JOURNAL_STATES, } from './update-journal-types.js';
11
+ export function updateJournalFile(root) {
12
+ return join(root, 'self-update-journal.json');
13
+ }
14
+ export function writeUpdateJournal(file, record) {
15
+ writeJsonFile(file, record, { fsync: true });
16
+ }
17
+ export function clearUpdateJournal(file) {
18
+ try {
19
+ unlinkSync(file);
20
+ }
21
+ catch (error) {
22
+ if (error.code !== 'ENOENT')
23
+ throw error;
24
+ }
25
+ }
26
+ export function readUpdateJournal(file) {
27
+ const raw = readJsonObject(file);
28
+ if (raw === undefined)
29
+ return undefined;
30
+ return recordOf(raw);
31
+ }
32
+ function textOf(value) {
33
+ return typeof value === 'string' && value !== '' ? value : undefined;
34
+ }
35
+ function countOf(value) {
36
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : undefined;
37
+ }
38
+ function linkOf(value) {
39
+ if (typeof value !== 'object' || value === null)
40
+ return undefined;
41
+ const record = value;
42
+ const pkg = textOf(record['pkg']);
43
+ const path = textOf(record['path']);
44
+ const kind = textOf(record['kind']);
45
+ if (pkg === undefined || path === undefined)
46
+ return undefined;
47
+ if (kind === undefined || !UPDATE_JOURNAL_LINK_KINDS.includes(kind))
48
+ return undefined;
49
+ const target = textOf(record['target']);
50
+ return { pkg, path, kind: kind, ...(target === undefined ? {} : { target }) };
51
+ }
52
+ function carryOf(value) {
53
+ if (typeof value !== 'object' || value === null)
54
+ return undefined;
55
+ const record = value;
56
+ const pkg = textOf(record['pkg']);
57
+ const from = textOf(record['from']);
58
+ const to = textOf(record['to']);
59
+ if (pkg === undefined || from === undefined || to === undefined)
60
+ return undefined;
61
+ return { pkg, from, to };
62
+ }
63
+ function manifestDepsOf(value) {
64
+ if (value === undefined)
65
+ return undefined;
66
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
67
+ return undefined;
68
+ const deps = {};
69
+ for (const [pkg, spec] of Object.entries(value)) {
70
+ if (typeof spec === 'string')
71
+ deps[pkg] = spec;
72
+ else if (spec === null)
73
+ deps[pkg] = null;
74
+ else
75
+ return undefined;
76
+ }
77
+ return deps;
78
+ }
79
+ function recordOf(raw) {
80
+ if (typeof raw !== 'object' || raw === null)
81
+ return undefined;
82
+ const record = raw;
83
+ if (record['schema'] !== 1)
84
+ return undefined;
85
+ const state = textOf(record['state']);
86
+ const from = textOf(record['from']);
87
+ const to = textOf(record['to']);
88
+ const profileDir = textOf(record['profileDir']);
89
+ const versionsDir = textOf(record['versionsDir']);
90
+ const versionDir = textOf(record['versionDir']);
91
+ const manifestPath = textOf(record['manifestPath']);
92
+ const at = textOf(record['at']);
93
+ const cursor = countOf(record['cursor']);
94
+ const carried = countOf(record['carried']);
95
+ if (state === undefined || !UPDATE_JOURNAL_STATES.includes(state))
96
+ return undefined;
97
+ if (from === undefined || to === undefined)
98
+ return undefined;
99
+ if (profileDir === undefined || versionsDir === undefined || versionDir === undefined)
100
+ return undefined;
101
+ if (manifestPath === undefined || at === undefined)
102
+ return undefined;
103
+ if (typeof record['manifestText'] !== 'string')
104
+ return undefined;
105
+ if (cursor === undefined || carried === undefined)
106
+ return undefined;
107
+ if (!Array.isArray(record['links']) || !Array.isArray(record['carry']))
108
+ return undefined;
109
+ const links = record['links'].map(linkOf);
110
+ const carry = record['carry'].map(carryOf);
111
+ if (links.some((item) => item === undefined) || carry.some((item) => item === undefined))
112
+ return undefined;
113
+ const manifestDeps = manifestDepsOf(record['manifestDeps']);
114
+ if (record['manifestDeps'] !== undefined && manifestDeps === undefined)
115
+ return undefined;
116
+ const updatedAt = textOf(record['updatedAt']);
117
+ return {
118
+ schema: 1,
119
+ state: state,
120
+ from,
121
+ to,
122
+ profileDir,
123
+ versionsDir,
124
+ versionDir,
125
+ manifestPath,
126
+ manifestText: record['manifestText'],
127
+ ...(manifestDeps === undefined ? {} : { manifestDeps }),
128
+ links: links,
129
+ carry: carry,
130
+ cursor,
131
+ carried,
132
+ at,
133
+ ...(updatedAt === undefined ? {} : { updatedAt }),
134
+ };
135
+ }
136
+ export function restoreUpdateJournal(input) {
137
+ const errors = [];
138
+ for (const link of [...input.record.links].reverse()) {
139
+ try {
140
+ restoreLink(link, input.record);
141
+ }
142
+ catch (error) {
143
+ errors.push(`${link.pkg}:${messageOf(error)}`);
144
+ }
145
+ }
146
+ for (const item of [...input.record.carry].reverse()) {
147
+ if (existsSync(item.from) && realDirOf(item.from))
148
+ continue;
149
+ try {
150
+ restoreCarry(item);
151
+ }
152
+ catch (error) {
153
+ errors.push(`${item.pkg}:${messageOf(error)}`);
154
+ }
155
+ }
156
+ if (input.record.state === 'manifest') {
157
+ try {
158
+ restoreManifest(input.record);
159
+ }
160
+ catch (error) {
161
+ errors.push(`清单:${messageOf(error)}`);
162
+ }
163
+ }
164
+ if (errors.length > 0) {
165
+ const detail = `恢复没完成(${errors.join(';')}),换版现场留着`;
166
+ input.log?.(detail);
167
+ return { ok: false, detail };
168
+ }
169
+ try {
170
+ clearUpdateJournal(input.file);
171
+ }
172
+ catch (error) {
173
+ return { ok: false, detail: `配置恢复了,但换版日志没清掉:${messageOf(error)}` };
174
+ }
175
+ const detail = `已经回到 ${input.record.from},链接与清单一致`;
176
+ input.log?.(detail);
177
+ return { ok: true, detail };
178
+ }
179
+ function restoreLink(link, record) {
180
+ if (link.kind === 'symlink') {
181
+ if (link.target === undefined)
182
+ throw new Error('快照里没有原来指向哪');
183
+ linkDir(resolve(dirname(link.path), link.target), link.path);
184
+ return;
185
+ }
186
+ if (link.kind === 'dir') {
187
+ if (realDirOf(link.path))
188
+ return;
189
+ removePath(link.path);
190
+ if (record.to === record.from) {
191
+ const target = join(record.versionDir, 'node_modules', link.pkg);
192
+ if (existsSync(target))
193
+ linkDir(target, link.path);
194
+ }
195
+ return;
196
+ }
197
+ if (link.kind === 'missing') {
198
+ removePath(link.path);
199
+ return;
200
+ }
201
+ throw new Error('现场那条既不是链接也不是目录');
202
+ }
203
+ function restoreCarry(item) {
204
+ if (!existsSync(item.to))
205
+ throw new Error('搬走的目录找不到了');
206
+ if (existsSync(item.from) && realDirOf(item.from))
207
+ return;
208
+ removePath(item.from);
209
+ ensureDir(dirname(item.from));
210
+ moveDir(item.to, item.from);
211
+ }
212
+ function realDirOf(path) {
213
+ try {
214
+ const info = lstatSync(path);
215
+ return info.isSymbolicLink() ? false : info.isDirectory();
216
+ }
217
+ catch {
218
+ return false;
219
+ }
220
+ }
221
+ export function recoverUpdateJournal(input) {
222
+ if (!existsSync(input.file))
223
+ return { kind: 'none' };
224
+ const root = dirname(input.file);
225
+ let lease;
226
+ if (input.ignoreLease !== true) {
227
+ if (updateLeaseActive(root))
228
+ return { kind: 'none' };
229
+ try {
230
+ lease = acquireUpdateLease({ root, pid: process.pid });
231
+ }
232
+ catch (error) {
233
+ input.log?.(`恢复锁没写上,这次先不动现场:${messageOf(error)}`);
234
+ return { kind: 'none' };
235
+ }
236
+ if (lease === undefined)
237
+ return { kind: 'none' };
238
+ }
239
+ try {
240
+ return recoverLocked(input);
241
+ }
242
+ finally {
243
+ if (lease !== undefined) {
244
+ try {
245
+ lease.release();
246
+ }
247
+ catch {
248
+ // 释放失败最多堵一轮,下一轮按陈旧锁接管
249
+ }
250
+ }
251
+ }
252
+ }
253
+ function recoverLocked(input) {
254
+ const record = readUpdateJournal(input.file);
255
+ if (record === undefined)
256
+ return { kind: 'none' };
257
+ if (record.state === 'committed') {
258
+ try {
259
+ clearUpdateJournal(input.file);
260
+ }
261
+ catch (error) {
262
+ input.log?.(`换版日志没清掉:${messageOf(error)}`);
263
+ markCommitted(input, record);
264
+ return { kind: 'cleared', from: record.from, to: record.to, dirty: true };
265
+ }
266
+ markCommitted(input, record);
267
+ return { kind: 'cleared', from: record.from, to: record.to };
268
+ }
269
+ if (targetStarted(record, input)) {
270
+ const rolled = rollForward(record);
271
+ if (!rolled.ok) {
272
+ const detail = `新版已经启动过,但${rolled.detail}`;
273
+ markFailed(input, record);
274
+ input.log?.(detail);
275
+ return { kind: 'kept', from: record.from, to: record.to, detail };
276
+ }
277
+ try {
278
+ clearUpdateJournal(input.file);
279
+ }
280
+ catch (error) {
281
+ input.log?.(`新版已经在跑,但换版日志没清掉:${messageOf(error)}`);
282
+ markCommitted(input, record);
283
+ return { kind: 'cleared', from: record.from, to: record.to, dirty: true };
284
+ }
285
+ markCommitted(input, record);
286
+ input.log?.(rolled.detail);
287
+ return { kind: 'cleared', from: record.from, to: record.to };
288
+ }
289
+ if (!snapshotIntact(record)) {
290
+ const detail = '快照里的旧目录已经不在了,不敢按日志恢复';
291
+ markFailed(input, record);
292
+ input.log?.(detail);
293
+ return { kind: 'kept', from: record.from, to: record.to, detail };
294
+ }
295
+ const restored = restoreUpdateJournal({
296
+ record,
297
+ file: input.file,
298
+ ...(input.log === undefined ? {} : { log: input.log }),
299
+ });
300
+ if (restored.ok)
301
+ clearRolledBackReinstall(dirname(input.file), record);
302
+ markFailed(input, record);
303
+ return restored.ok
304
+ ? { kind: 'restored', from: record.from, to: record.to, detail: restored.detail }
305
+ : { kind: 'kept', from: record.from, to: record.to, detail: restored.detail };
306
+ }
307
+ function clearRolledBackReinstall(root, record) {
308
+ if (record.to === record.from)
309
+ return;
310
+ try {
311
+ const file = reinstallRecordFile(root);
312
+ const pending = readReinstallRecord(file);
313
+ if (pending !== undefined && pending.version !== record.to)
314
+ return;
315
+ clearReinstallRecord(file);
316
+ }
317
+ catch {
318
+ // 记录没清掉最多多跑一次 install,不影响配置
319
+ }
320
+ }
321
+ function targetStarted(record, input) {
322
+ if (record.to === record.from)
323
+ return false;
324
+ if (record.state !== 'flipping' && record.state !== 'manifest')
325
+ return false;
326
+ const since = dayjs(record.at).valueOf();
327
+ for (const file of [input.bootFile, input.upFile]) {
328
+ if (file === undefined)
329
+ continue;
330
+ const boot = readBootRecord(file);
331
+ if (boot === undefined || boot.version !== record.to)
332
+ continue;
333
+ const at = dayjs(boot.at).valueOf();
334
+ if (!Number.isFinite(at) || !Number.isFinite(since) || at >= since)
335
+ return true;
336
+ }
337
+ return false;
338
+ }
339
+ function snapshotIntact(record) {
340
+ for (const link of record.links) {
341
+ if (link.kind === 'symlink') {
342
+ if (link.target === undefined || !existsSync(resolve(dirname(link.path), link.target)))
343
+ return false;
344
+ continue;
345
+ }
346
+ if (link.kind === 'other')
347
+ return false;
348
+ if (link.kind !== 'dir')
349
+ continue;
350
+ if (realDirOf(link.path))
351
+ continue;
352
+ const item = record.carry.find((entry) => entry.from === link.path);
353
+ if (item === undefined) {
354
+ if (record.to === record.from && existsSync(join(record.versionDir, 'node_modules', link.pkg)))
355
+ continue;
356
+ return false;
357
+ }
358
+ if (!existsSync(item.from) && !existsSync(item.to))
359
+ return false;
360
+ }
361
+ return true;
362
+ }
363
+ function markCommitted(input, record) {
364
+ if (markerIsOk(input, record.to))
365
+ return;
366
+ writeMarker(input, {
367
+ state: 'pending-restart',
368
+ version: record.to,
369
+ at: input.at ?? new Date().toISOString(),
370
+ phase: 'committed',
371
+ committed: true,
372
+ });
373
+ }
374
+ function markFailed(input, record) {
375
+ if (markerIsOk(input, record.to))
376
+ return;
377
+ const current = readMarker(input);
378
+ if (current?.['state'] === 'failed' && current['version'] === record.from)
379
+ return;
380
+ writeMarker(input, {
381
+ state: 'failed',
382
+ version: record.from,
383
+ reason: 'incomplete',
384
+ at: input.at ?? new Date().toISOString(),
385
+ });
386
+ }
387
+ function markerIsOk(input, version) {
388
+ const current = readMarker(input);
389
+ return current?.['state'] === 'ok' && current['version'] === version;
390
+ }
391
+ function readMarker(input) {
392
+ if (input.markerPath === undefined)
393
+ return undefined;
394
+ return readJsonObject(input.markerPath);
395
+ }
396
+ function writeMarker(input, patch) {
397
+ if (input.markerPath === undefined)
398
+ return;
399
+ const base = readJsonObject(input.markerPath) ?? {};
400
+ try {
401
+ writeJsonFile(input.markerPath, { ...base, ...patch });
402
+ }
403
+ catch {
404
+ return;
405
+ }
406
+ }
407
+ function messageOf(error) {
408
+ return error instanceof Error ? error.message : String(error);
409
+ }
@@ -0,0 +1,16 @@
1
+ export interface HandoffEntry {
2
+ readonly fact: string;
3
+ readonly key: string;
4
+ }
5
+ export interface HandoffValue {
6
+ readonly value: unknown;
7
+ readonly at: number;
8
+ }
9
+ export interface ValueHandoff {
10
+ hand(entry: HandoffEntry, value: unknown, now?: number): void;
11
+ take(entry: HandoffEntry, now?: number): HandoffValue | undefined;
12
+ }
13
+ export declare function handoffId(entry: HandoffEntry): string;
14
+ export declare function createValueHandoff(options?: {
15
+ ttlMs?: number;
16
+ }): ValueHandoff;
@@ -0,0 +1,22 @@
1
+ import { now as clockNow } from './time.js';
2
+ import { HANDOFF_TTL_MS } from '../config/constants.js';
3
+ export function handoffId(entry) {
4
+ return `${String(entry.fact.length)}:${entry.fact}${entry.key}`;
5
+ }
6
+ export function createValueHandoff(options = {}) {
7
+ const ttlMs = options.ttlMs ?? HANDOFF_TTL_MS;
8
+ const held = new Map();
9
+ return {
10
+ hand(entry, value, now = clockNow()) {
11
+ held.set(handoffId(entry), { value, at: now });
12
+ },
13
+ take(entry, now = clockNow()) {
14
+ const id = handoffId(entry);
15
+ const hit = held.get(id);
16
+ if (hit === undefined)
17
+ return undefined;
18
+ held.delete(id);
19
+ return now - hit.at >= ttlMs ? undefined : hit;
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ export type VersionVerdict = 'satisfied' | 'unsatisfied' | 'malformed';
2
+ export declare function checkVersionRange(contract: string | undefined, version: string): VersionVerdict;
@@ -0,0 +1,13 @@
1
+ import semver from 'semver';
2
+ export function checkVersionRange(contract, version) {
3
+ const spec = contract?.trim() ?? '';
4
+ if (spec === '')
5
+ return 'satisfied';
6
+ const range = semver.validRange(spec);
7
+ if (range === null)
8
+ return 'malformed';
9
+ const parsed = semver.coerce(version);
10
+ if (parsed === null)
11
+ return 'malformed';
12
+ return semver.satisfies(parsed, range) ? 'satisfied' : 'unsatisfied';
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare function compareVersions(left: string, right: string): number | undefined;
2
+ export declare function isValidVersion(value: string): boolean;
3
+ export declare function isNewerVersion(latest: string, installed: string): boolean;
4
+ export declare function runningVersionOf(moduleUrl: string): string | undefined;
@@ -0,0 +1,32 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import semver from 'semver';
3
+ export function compareVersions(left, right) {
4
+ const a = semver.valid(left.trim());
5
+ const b = semver.valid(right.trim());
6
+ if (a === null || b === null)
7
+ return undefined;
8
+ return semver.compare(a, b);
9
+ }
10
+ export function isValidVersion(value) {
11
+ return semver.valid(value.trim()) !== null;
12
+ }
13
+ export function isNewerVersion(latest, installed) {
14
+ if (latest === installed)
15
+ return false;
16
+ const compared = compareVersions(latest, installed);
17
+ return compared === undefined ? true : compared > 0;
18
+ }
19
+ export function runningVersionOf(moduleUrl) {
20
+ for (const depth of ['../../package.json', '../package.json']) {
21
+ try {
22
+ const read = JSON.parse(readFileSync(new URL(depth, moduleUrl), 'utf8'));
23
+ if (typeof read.name !== 'string' || !read.name.startsWith('@dsh-workbench/'))
24
+ continue;
25
+ return typeof read.version === 'string' && read.version !== '' ? read.version : undefined;
26
+ }
27
+ catch {
28
+ continue;
29
+ }
30
+ }
31
+ return undefined;
32
+ }
@@ -0,0 +1,19 @@
1
+ export interface ModuleStore {
2
+ readonly dir: string;
3
+ read(name: string): unknown | null;
4
+ write(name: string, value: unknown): void;
5
+ remove(name: string): void;
6
+ list(): string[];
7
+ }
8
+ export interface WorkspaceStore {
9
+ for(unitId: string, workspace: string | null): ModuleStore;
10
+ machine(unitId: string): ModuleStore;
11
+ scan(unitId: string): ModuleStore[];
12
+ }
13
+ export declare function workspaceKey(workspace: string): string;
14
+ export declare function createWorkspaceStore(options: {
15
+ readonly root?: string | null | undefined;
16
+ readonly logger?: {
17
+ warn?(message: string): void;
18
+ } | undefined;
19
+ }): WorkspaceStore;