@dsh-workbench/shared 1.5.2-alpha.4 → 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 (310) 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/front-app.d.ts +6 -0
  257. package/dist/host/runtime/front-app.js +70 -0
  258. package/dist/host/shell-render.d.ts +52 -0
  259. package/dist/host/shell-render.js +117 -0
  260. package/dist/host/shell-text.d.ts +30 -0
  261. package/dist/host/shell-text.js +40 -0
  262. package/dist/host/shell.d.ts +25 -0
  263. package/dist/host/shell.js +55 -0
  264. package/dist/host/site.d.ts +45 -0
  265. package/dist/host/site.js +182 -0
  266. package/dist/host/spec.d.ts +8 -0
  267. package/dist/host/spec.js +24 -0
  268. package/dist/host/submit-confirm.d.ts +19 -0
  269. package/dist/host/submit-confirm.js +45 -0
  270. package/dist/host/supply-index.d.ts +38 -0
  271. package/dist/host/supply-index.js +209 -0
  272. package/dist/host/supply-port.d.ts +5 -0
  273. package/dist/host/supply-port.js +50 -0
  274. package/dist/host/time.d.ts +22 -0
  275. package/dist/host/time.js +33 -0
  276. package/dist/host/tokens.d.ts +26 -0
  277. package/dist/host/tokens.js +154 -0
  278. package/dist/host/tool-approval.d.ts +86 -0
  279. package/dist/host/tool-approval.js +118 -0
  280. package/dist/host/tool-kit.d.ts +8 -0
  281. package/dist/host/tool-kit.js +22 -0
  282. package/dist/host/toolbox-port.d.ts +16 -0
  283. package/dist/host/toolbox-port.js +1 -0
  284. package/dist/host/unit-config.d.ts +34 -0
  285. package/dist/host/unit-config.js +28 -0
  286. package/dist/host/unit-data.d.ts +3 -0
  287. package/dist/host/unit-data.js +127 -0
  288. package/dist/host/unit-face.d.ts +95 -0
  289. package/dist/host/unit-face.js +1 -0
  290. package/dist/host/unit-plugin.d.ts +24 -0
  291. package/dist/host/unit-plugin.js +25 -0
  292. package/dist/host/update-journal-manifest.d.ts +19 -0
  293. package/dist/host/update-journal-manifest.js +134 -0
  294. package/dist/host/update-journal-types.d.ts +33 -0
  295. package/dist/host/update-journal-types.js +2 -0
  296. package/dist/host/update-journal.d.ts +43 -0
  297. package/dist/host/update-journal.js +409 -0
  298. package/dist/host/value-handoff.d.ts +16 -0
  299. package/dist/host/value-handoff.js +22 -0
  300. package/dist/host/version-range.d.ts +2 -0
  301. package/dist/host/version-range.js +13 -0
  302. package/dist/host/version.d.ts +4 -0
  303. package/dist/host/version.js +32 -0
  304. package/dist/host/workspace-store.d.ts +19 -0
  305. package/dist/host/workspace-store.js +133 -0
  306. package/dist/host/write-result.d.ts +1 -0
  307. package/dist/host/write-result.js +18 -0
  308. package/dist/lib/dsh-client.d.ts +1 -1
  309. package/package.json +51 -47
  310. package/src/lib/dsh-client.ts +2 -1
@@ -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;
@@ -0,0 +1,133 @@
1
+ import { createHash } from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { workspacesRoot } from '../host/data-root.js';
5
+ import { writeJsonFile } from './fs-write.js';
6
+ function slug(raw, max = 40) {
7
+ const cleaned = raw
8
+ .replace(/[^A-Za-z0-9._-]+/g, '-')
9
+ .replace(/^[-.]+|[-.]+$/g, '')
10
+ .slice(0, max);
11
+ return cleaned === '' ? 'workspace' : cleaned;
12
+ }
13
+ export function workspaceKey(workspace) {
14
+ const abs = path.resolve(workspace);
15
+ return `${slug(path.basename(abs))}-${createHash('sha1').update(abs).digest('hex').slice(0, 8)}`;
16
+ }
17
+ function safeName(name) {
18
+ const trimmed = name.trim();
19
+ if (trimmed === '' || trimmed === '.' || trimmed === '..') {
20
+ throw new Error(`模块文件夹里只接受相对文件名,收到的是「${name}」`);
21
+ }
22
+ if (trimmed.includes('\0') || path.isAbsolute(trimmed) || /^[A-Za-z]:[\\/]/.test(trimmed)) {
23
+ throw new Error(`模块只能写自己的文件夹:不接受绝对路径「${name}」`);
24
+ }
25
+ if (trimmed.replace(/\\/g, '/').split('/').includes('..')) {
26
+ throw new Error(`模块只能写自己的文件夹:路径越界「${name}」`);
27
+ }
28
+ return trimmed;
29
+ }
30
+ function inside(dir, name) {
31
+ const full = path.resolve(dir, safeName(name));
32
+ if (full !== dir && !full.startsWith(dir + path.sep)) {
33
+ throw new Error(`模块只能写自己的文件夹:路径越界「${name}」`);
34
+ }
35
+ return full;
36
+ }
37
+ function memoryStore(dir) {
38
+ const files = new Map();
39
+ return {
40
+ dir,
41
+ read: (name) => {
42
+ safeName(name);
43
+ return files.get(name) ?? null;
44
+ },
45
+ write: (name, value) => {
46
+ safeName(name);
47
+ files.set(name, value);
48
+ },
49
+ remove: (name) => {
50
+ safeName(name);
51
+ files.delete(name);
52
+ },
53
+ list: () => [...files.keys()].sort(),
54
+ };
55
+ }
56
+ function fileStore(dir) {
57
+ return {
58
+ dir,
59
+ read: (name) => {
60
+ const file = inside(dir, name);
61
+ try {
62
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ },
68
+ write: (name, value) => {
69
+ writeJsonFile(inside(dir, name), value);
70
+ },
71
+ remove: (name) => {
72
+ const file = inside(dir, name);
73
+ try {
74
+ fs.unlinkSync(file);
75
+ }
76
+ catch {
77
+ }
78
+ },
79
+ list: () => {
80
+ try {
81
+ return fs
82
+ .readdirSync(dir, { withFileTypes: true })
83
+ .filter((entry) => entry.isFile())
84
+ .map((entry) => entry.name)
85
+ .sort();
86
+ }
87
+ catch {
88
+ return [];
89
+ }
90
+ },
91
+ };
92
+ }
93
+ export function createWorkspaceStore(options) {
94
+ const root = options.root === null ? null : options.root ?? workspacesRoot();
95
+ let warned = false;
96
+ const memory = new Map();
97
+ const fallback = (dir) => {
98
+ if (!warned) {
99
+ warned = true;
100
+ options.logger?.warn?.('[dsh-workbench] 没有可写的数据根:模块配置只在本进程内生效(见 shared/api/host/data-root.ts)');
101
+ }
102
+ const hit = memory.get(dir);
103
+ if (hit !== undefined)
104
+ return hit;
105
+ const created = memoryStore(dir);
106
+ memory.set(dir, created);
107
+ return created;
108
+ };
109
+ const open = (parts) => root === null
110
+ ? fallback(path.join('/_memory', ...parts))
111
+ : fileStore(path.join(root, ...parts.map((part) => slug(part))));
112
+ return {
113
+ for: (unitId, workspace) => workspace === null || workspace.trim() === ''
114
+ ? fallback(path.join('/_memory', slug(unitId)))
115
+ : open([workspaceKey(workspace), unitId]),
116
+ machine: (unitId) => open(['_machine', unitId]),
117
+ scan: (unitId) => {
118
+ if (root === null)
119
+ return [];
120
+ let entries;
121
+ try {
122
+ entries = fs.readdirSync(root, { withFileTypes: true })
123
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('_'))
124
+ .map((entry) => entry.name)
125
+ .sort();
126
+ }
127
+ catch {
128
+ return [];
129
+ }
130
+ return entries.map((key) => fileStore(path.join(root, key, slug(unitId))));
131
+ },
132
+ };
133
+ }
@@ -0,0 +1 @@
1
+ export declare function writeResultForClient(value: unknown, code: string): unknown;
@@ -0,0 +1,18 @@
1
+ export function writeResultForClient(value, code) {
2
+ if (typeof value !== 'object' || value === null)
3
+ return value;
4
+ const box = value;
5
+ const existing = box['error'];
6
+ if (box['ok'] !== false || (typeof existing === 'object' && existing !== null))
7
+ return value;
8
+ const text = box['text'];
9
+ const detail = box['detail'];
10
+ return {
11
+ ok: false,
12
+ error: {
13
+ code,
14
+ message: typeof text === 'string' && text.trim() !== '' ? text : '这一步没有成功,也没说为什么',
15
+ ...(typeof detail === 'string' ? { detail } : {}),
16
+ },
17
+ };
18
+ }
@@ -1,7 +1,7 @@
1
1
  import type { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client';
2
2
  import type { PropsRenderSlots, SlotLabel } from '@deepseek-ai/dsh-client-ui-slots';
3
3
  import type { SessionInput as OfficialSessionInput } from '@deepseek-ai/dsh-client-ui-conversation/client';
4
- import type { SessionStatus as OfficialSessionStatus } from '@deepseek-ai/dsh-client-ui-session/client';
4
+ import type { SessionStatus as OfficialSessionStatus } from '@deepseek-ai/dsh-client-ui-session-status/client';
5
5
  import type { SessionSummary as OfficialSessionSummary } from '@deepseek-ai/dsh-api-session-controller/client';
6
6
  import type { WorkspaceSnapshot as OfficialWorkspaceSnapshot, WorkspaceView as OfficialWorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/client';
7
7
  import type { SubagentCatalogEntry as OfficialSubagentCatalogEntry } from '@deepseek-ai/dsh-subagent';