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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/dist/components/Activity.css +69 -0
  2. package/dist/components/Activity.d.ts +56 -0
  3. package/dist/components/Activity.js +47 -0
  4. package/dist/components/ApprovalDetail.css +3 -0
  5. package/dist/components/ApprovalDetail.d.ts +42 -0
  6. package/dist/components/ApprovalDetail.js +53 -0
  7. package/dist/components/ApprovalPlan.css +39 -0
  8. package/dist/components/ApprovalPlan.d.ts +27 -0
  9. package/dist/components/ApprovalPlan.js +19 -0
  10. package/dist/components/Card.css +19 -0
  11. package/dist/components/Card.d.ts +26 -0
  12. package/dist/components/Card.js +18 -0
  13. package/dist/components/CardAnchor.d.ts +21 -0
  14. package/dist/components/CardAnchor.js +19 -0
  15. package/dist/components/CardAnchor.module.css +3 -0
  16. package/dist/components/CardBoundary.d.ts +42 -0
  17. package/dist/components/CardBoundary.js +58 -0
  18. package/dist/components/CardBoundary.module.css +5 -0
  19. package/dist/components/CardHead.css +87 -0
  20. package/dist/components/CardHead.d.ts +30 -0
  21. package/dist/components/CardHead.js +27 -0
  22. package/dist/components/ChoiceGroup.css +182 -0
  23. package/dist/components/ChoiceGroup.d.ts +54 -0
  24. package/dist/components/ChoiceGroup.js +63 -0
  25. package/dist/components/ConfirmBar.css +26 -0
  26. package/dist/components/ConfirmBar.d.ts +36 -0
  27. package/dist/components/ConfirmBar.js +26 -0
  28. package/dist/components/EmptyIllustration.d.ts +12 -0
  29. package/dist/components/EmptyIllustration.js +32 -0
  30. package/dist/components/Field.css +20 -0
  31. package/dist/components/Field.d.ts +18 -0
  32. package/dist/components/Field.js +15 -0
  33. package/dist/components/Form.css +6 -0
  34. package/dist/components/Form.d.ts +22 -0
  35. package/dist/components/Form.js +60 -0
  36. package/dist/components/FormActions.css +13 -0
  37. package/dist/components/FormActions.d.ts +29 -0
  38. package/dist/components/FormActions.js +43 -0
  39. package/dist/components/FormNodes.d.ts +107 -0
  40. package/dist/components/FormNodes.js +165 -0
  41. package/dist/components/FormRows.css +107 -0
  42. package/dist/components/FormRows.d.ts +36 -0
  43. package/dist/components/FormRows.js +26 -0
  44. package/dist/components/FormTypes.d.ts +84 -0
  45. package/dist/components/FormTypes.js +1 -0
  46. package/dist/components/Link.css +22 -0
  47. package/dist/components/Link.d.ts +22 -0
  48. package/dist/components/Link.js +17 -0
  49. package/dist/components/LongTaskRow.css +171 -0
  50. package/dist/components/LongTaskRow.d.ts +94 -0
  51. package/dist/components/LongTaskRow.js +103 -0
  52. package/dist/components/Note.css +13 -0
  53. package/dist/components/Note.d.ts +20 -0
  54. package/dist/components/Note.js +14 -0
  55. package/dist/components/ResourceStates.css +114 -0
  56. package/dist/components/ResourceStates.d.ts +44 -0
  57. package/dist/components/ResourceStates.js +41 -0
  58. package/dist/components/Rows.css +42 -0
  59. package/dist/components/Rows.d.ts +28 -0
  60. package/dist/components/Rows.js +21 -0
  61. package/dist/components/SaveBar.d.ts +24 -0
  62. package/dist/components/SaveBar.js +25 -0
  63. package/dist/components/SelectField.css +182 -0
  64. package/dist/components/SelectField.d.ts +89 -0
  65. package/dist/components/SelectField.js +260 -0
  66. package/dist/components/SelectFieldNodes.d.ts +49 -0
  67. package/dist/components/SelectFieldNodes.js +43 -0
  68. package/dist/components/SettingsSection.css +25 -0
  69. package/dist/components/SettingsSection.d.ts +20 -0
  70. package/dist/components/SettingsSection.js +17 -0
  71. package/dist/components/SetupShell.d.ts +93 -0
  72. package/dist/components/SetupShell.js +64 -0
  73. package/dist/components/SetupShell.module.css +81 -0
  74. package/dist/components/Spinner.css +5 -0
  75. package/dist/components/Spinner.d.ts +15 -0
  76. package/dist/components/Spinner.js +13 -0
  77. package/dist/components/Stack.css +6 -0
  78. package/dist/components/Stack.d.ts +14 -0
  79. package/dist/components/Stack.js +10 -0
  80. package/dist/components/StateBlock.css +38 -0
  81. package/dist/components/StateBlock.d.ts +24 -0
  82. package/dist/components/StateBlock.js +22 -0
  83. package/dist/components/TextField.css +32 -0
  84. package/dist/components/TextField.d.ts +14 -0
  85. package/dist/components/TextField.js +10 -0
  86. package/dist/components/board-module.d.ts +307 -0
  87. package/dist/components/board-module.js +1 -0
  88. package/dist/components/card-view-validate.d.ts +5 -0
  89. package/dist/components/card-view-validate.js +256 -0
  90. package/dist/components/icons.d.ts +63 -0
  91. package/dist/components/icons.js +107 -0
  92. package/dist/components/layout/icon-command.d.ts +8 -0
  93. package/dist/components/layout/icon-command.js +21 -0
  94. package/dist/contract/capture.d.ts +16 -0
  95. package/dist/contract/capture.js +1 -0
  96. package/dist/contract/diagnostics.d.ts +34 -0
  97. package/dist/contract/diagnostics.js +124 -0
  98. package/dist/contract/protocol/unit-manager.d.ts +50 -0
  99. package/dist/contract/protocol/unit-manager.js +2 -0
  100. package/dist/host/adapter-contract.d.ts +3 -0
  101. package/dist/host/adapter-contract.js +95 -0
  102. package/dist/host/adapter-set.d.ts +27 -0
  103. package/dist/host/adapter-set.js +258 -0
  104. package/dist/host/adapter-types.d.ts +87 -0
  105. package/dist/host/adapter-types.js +23 -0
  106. package/dist/host/adapters/platform.d.ts +14 -0
  107. package/dist/host/adapters/platform.js +40 -0
  108. package/dist/host/adapters.d.ts +28 -0
  109. package/dist/host/adapters.js +9 -0
  110. package/dist/host/auth-loss.d.ts +33 -0
  111. package/dist/host/auth-loss.js +107 -0
  112. package/dist/host/board-fact.d.ts +8 -0
  113. package/dist/host/board-fact.js +16 -0
  114. package/dist/host/boot-record.d.ts +11 -0
  115. package/dist/host/boot-record.js +31 -0
  116. package/dist/host/browser.d.ts +3 -0
  117. package/dist/host/browser.js +3 -0
  118. package/dist/host/bundle-manager.d.ts +4 -0
  119. package/dist/host/bundle-manager.js +338 -0
  120. package/dist/host/changelog.d.ts +28 -0
  121. package/dist/host/changelog.js +201 -0
  122. package/dist/host/cli-error.d.ts +8 -0
  123. package/dist/host/cli-error.js +70 -0
  124. package/dist/host/cli.d.ts +4 -0
  125. package/dist/host/cli.js +9 -0
  126. package/dist/host/config-sync.d.ts +40 -0
  127. package/dist/host/config-sync.js +267 -0
  128. package/dist/host/context-ref.d.ts +13 -0
  129. package/dist/host/context-ref.js +41 -0
  130. package/dist/host/data-error.d.ts +15 -0
  131. package/dist/host/data-error.js +23 -0
  132. package/dist/host/data-plan-check.d.ts +10 -0
  133. package/dist/host/data-plan-check.js +315 -0
  134. package/dist/host/data-plan.d.ts +15 -0
  135. package/dist/host/data-plan.js +283 -0
  136. package/dist/host/data-root.d.ts +5 -0
  137. package/dist/host/data-root.js +23 -0
  138. package/dist/host/diy-debug.d.ts +80 -0
  139. package/dist/host/diy-debug.js +89 -0
  140. package/dist/host/diy-preset.d.ts +26 -0
  141. package/dist/host/diy-preset.js +115 -0
  142. package/dist/host/diy-record.d.ts +135 -0
  143. package/dist/host/diy-record.js +163 -0
  144. package/dist/host/dsh-compat.d.ts +27 -0
  145. package/dist/host/dsh-compat.js +75 -0
  146. package/dist/host/dsh-plugins.d.ts +5 -0
  147. package/dist/host/dsh-plugins.js +51 -0
  148. package/dist/host/env-policy.d.ts +82 -0
  149. package/dist/host/env-policy.js +181 -0
  150. package/dist/host/extension.d.ts +7 -0
  151. package/dist/host/extension.js +40 -0
  152. package/dist/host/facts.d.ts +31 -0
  153. package/dist/host/facts.js +58 -0
  154. package/dist/host/fs-write.d.ts +96 -0
  155. package/dist/host/fs-write.js +183 -0
  156. package/dist/host/git.d.ts +5 -0
  157. package/dist/host/git.js +1 -0
  158. package/dist/host/host-actions.d.ts +2 -0
  159. package/dist/host/host-actions.js +5 -0
  160. package/dist/host/host-kit.d.ts +37 -0
  161. package/dist/host/host-kit.js +27 -0
  162. package/dist/host/http.d.ts +47 -0
  163. package/dist/host/http.js +289 -0
  164. package/dist/host/install-failure.d.ts +50 -0
  165. package/dist/host/install-failure.js +184 -0
  166. package/dist/host/installed-module.d.ts +25 -0
  167. package/dist/host/installed-module.js +289 -0
  168. package/dist/host/installed-sources.d.ts +10 -0
  169. package/dist/host/installed-sources.js +63 -0
  170. package/dist/host/lease.d.ts +70 -0
  171. package/dist/host/lease.js +264 -0
  172. package/dist/host/lib-capabilities.d.ts +22 -0
  173. package/dist/host/lib-capabilities.js +37 -0
  174. package/dist/host/lib-install.d.ts +19 -0
  175. package/dist/host/lib-install.js +40 -0
  176. package/dist/host/lib-runners.d.ts +18 -0
  177. package/dist/host/lib-runners.js +46 -0
  178. package/dist/host/local-declaration.d.ts +7 -0
  179. package/dist/host/local-declaration.js +33 -0
  180. package/dist/host/long-task.d.ts +97 -0
  181. package/dist/host/long-task.js +297 -0
  182. package/dist/host/market-index-claim.d.ts +19 -0
  183. package/dist/host/market-index-claim.js +87 -0
  184. package/dist/host/market-index-doc.d.ts +12 -0
  185. package/dist/host/market-index-doc.js +1 -0
  186. package/dist/host/market-index-parse.d.ts +28 -0
  187. package/dist/host/market-index-parse.js +413 -0
  188. package/dist/host/market-index.d.ts +13 -0
  189. package/dist/host/market-index.js +105 -0
  190. package/dist/host/module-root.d.ts +1 -0
  191. package/dist/host/module-root.js +5 -0
  192. package/dist/host/needs.d.ts +4 -0
  193. package/dist/host/needs.js +2 -0
  194. package/dist/host/npm-registry.d.ts +10 -0
  195. package/dist/host/npm-registry.js +16 -0
  196. package/dist/host/package-content.d.ts +8 -0
  197. package/dist/host/package-content.js +90 -0
  198. package/dist/host/package-kind.d.ts +13 -0
  199. package/dist/host/package-kind.js +51 -0
  200. package/dist/host/package-route.d.ts +33 -0
  201. package/dist/host/package-route.js +68 -0
  202. package/dist/host/panel-state.d.ts +120 -0
  203. package/dist/host/panel-state.js +177 -0
  204. package/dist/host/patch-blocks.d.ts +13 -0
  205. package/dist/host/patch-blocks.js +52 -0
  206. package/dist/host/patch.d.ts +4 -0
  207. package/dist/host/patch.js +7 -0
  208. package/dist/host/paths.d.ts +12 -0
  209. package/dist/host/paths.js +20 -0
  210. package/dist/host/payload.d.ts +12 -0
  211. package/dist/host/payload.js +16 -0
  212. package/dist/host/plan-results.d.ts +5 -0
  213. package/dist/host/plan-results.js +71 -0
  214. package/dist/host/plan-run.d.ts +41 -0
  215. package/dist/host/plan-run.js +87 -0
  216. package/dist/host/platform.d.ts +14 -0
  217. package/dist/host/platform.js +40 -0
  218. package/dist/host/plugin-ledger.d.ts +32 -0
  219. package/dist/host/plugin-ledger.js +106 -0
  220. package/dist/host/plugin.d.ts +3 -0
  221. package/dist/host/plugin.js +38 -0
  222. package/dist/host/port-types.d.ts +233 -0
  223. package/dist/host/port-types.js +1 -0
  224. package/dist/host/preflight.d.ts +32 -0
  225. package/dist/host/preflight.js +1 -0
  226. package/dist/host/process-alive.d.ts +6 -0
  227. package/dist/host/process-alive.js +16 -0
  228. package/dist/host/profile-bundles.d.ts +20 -0
  229. package/dist/host/profile-bundles.js +48 -0
  230. package/dist/host/profile-create.d.ts +19 -0
  231. package/dist/host/profile-create.js +124 -0
  232. package/dist/host/profile-port.d.ts +4 -0
  233. package/dist/host/profile-port.js +4 -0
  234. package/dist/host/profile-registries.d.ts +10 -0
  235. package/dist/host/profile-registries.js +149 -0
  236. package/dist/host/provision.d.ts +32 -0
  237. package/dist/host/provision.js +105 -0
  238. package/dist/host/read-json.d.ts +1 -0
  239. package/dist/host/read-json.js +11 -0
  240. package/dist/host/recipe-rules.d.ts +5 -0
  241. package/dist/host/recipe-rules.js +412 -0
  242. package/dist/host/recipe.d.ts +14 -0
  243. package/dist/host/recipe.js +332 -0
  244. package/dist/host/registry-declaration.d.ts +21 -0
  245. package/dist/host/registry-declaration.js +42 -0
  246. package/dist/host/reinstall-record.d.ts +16 -0
  247. package/dist/host/reinstall-record.js +54 -0
  248. package/dist/host/release-age.d.ts +24 -0
  249. package/dist/host/release-age.js +92 -0
  250. package/dist/host/release-packages.generated.d.ts +1 -0
  251. package/dist/host/release-packages.generated.js +10 -0
  252. package/dist/host/release-probe.d.ts +37 -0
  253. package/dist/host/release-probe.js +156 -0
  254. package/dist/host/runtime/browser-argv.d.ts +1 -0
  255. package/dist/host/runtime/browser-argv.js +9 -0
  256. package/dist/host/runtime/dsh-compat.d.ts +1 -1
  257. package/dist/host/runtime/dsh-compat.js +4 -1
  258. package/dist/host/runtime/front-app.d.ts +6 -0
  259. package/dist/host/runtime/front-app.js +70 -0
  260. package/dist/host/shell-render.d.ts +52 -0
  261. package/dist/host/shell-render.js +117 -0
  262. package/dist/host/shell-text.d.ts +30 -0
  263. package/dist/host/shell-text.js +40 -0
  264. package/dist/host/shell.d.ts +25 -0
  265. package/dist/host/shell.js +55 -0
  266. package/dist/host/site.d.ts +45 -0
  267. package/dist/host/site.js +182 -0
  268. package/dist/host/spec.d.ts +8 -0
  269. package/dist/host/spec.js +24 -0
  270. package/dist/host/submit-confirm.d.ts +19 -0
  271. package/dist/host/submit-confirm.js +45 -0
  272. package/dist/host/supply-index.d.ts +38 -0
  273. package/dist/host/supply-index.js +209 -0
  274. package/dist/host/supply-port.d.ts +5 -0
  275. package/dist/host/supply-port.js +50 -0
  276. package/dist/host/time.d.ts +22 -0
  277. package/dist/host/time.js +33 -0
  278. package/dist/host/tokens.d.ts +26 -0
  279. package/dist/host/tokens.js +154 -0
  280. package/dist/host/tool-approval.d.ts +86 -0
  281. package/dist/host/tool-approval.js +118 -0
  282. package/dist/host/tool-kit.d.ts +8 -0
  283. package/dist/host/tool-kit.js +22 -0
  284. package/dist/host/toolbox-port.d.ts +16 -0
  285. package/dist/host/toolbox-port.js +1 -0
  286. package/dist/host/unit-config.d.ts +34 -0
  287. package/dist/host/unit-config.js +28 -0
  288. package/dist/host/unit-data.d.ts +3 -0
  289. package/dist/host/unit-data.js +127 -0
  290. package/dist/host/unit-face.d.ts +95 -0
  291. package/dist/host/unit-face.js +1 -0
  292. package/dist/host/unit-plugin.d.ts +24 -0
  293. package/dist/host/unit-plugin.js +25 -0
  294. package/dist/host/update-journal-manifest.d.ts +19 -0
  295. package/dist/host/update-journal-manifest.js +134 -0
  296. package/dist/host/update-journal-types.d.ts +33 -0
  297. package/dist/host/update-journal-types.js +2 -0
  298. package/dist/host/update-journal.d.ts +43 -0
  299. package/dist/host/update-journal.js +409 -0
  300. package/dist/host/value-handoff.d.ts +16 -0
  301. package/dist/host/value-handoff.js +22 -0
  302. package/dist/host/version-range.d.ts +2 -0
  303. package/dist/host/version-range.js +13 -0
  304. package/dist/host/version.d.ts +4 -0
  305. package/dist/host/version.js +32 -0
  306. package/dist/host/workspace-store.d.ts +19 -0
  307. package/dist/host/workspace-store.js +133 -0
  308. package/dist/host/write-result.d.ts +1 -0
  309. package/dist/host/write-result.js +18 -0
  310. package/dist/lib/dsh-client.d.ts +1 -1
  311. package/package.json +51 -47
  312. package/src/host/runtime/__tests__/dsh-compat.test.ts +10 -2
  313. package/src/host/runtime/dsh-compat.ts +4 -2
  314. package/src/lib/dsh-client.ts +2 -1
@@ -0,0 +1,95 @@
1
+ import type { HostContext } from '../contract/module-context.js';
2
+ import type { UnitManifest } from '../contract/unit.js';
3
+ import type { RouteTable } from '../host/http.js';
4
+ import type { LongTaskBase, LongTaskHost, LongTaskRegistry } from '../host/long-task.js';
5
+ import type { ProvisionHandler } from './provision.js';
6
+ import type { UnitCapability } from '../contract/unit-capability.js';
7
+ import type { ApprovalCall, ApprovalFacts, ApprovalPolicy } from '../host/tool-approval.js';
8
+ import type { ValueHandoff } from '../host/value-handoff.js';
9
+ import type { WorkspaceStore } from '../host/workspace-store.js';
10
+ import type { DataReader } from '../contract/data.js';
11
+ import type { LibReader } from '../contract/lib.js';
12
+ import type { GitReader } from '../contract/git.js';
13
+ import type { CommandReader } from '../contract/command.js';
14
+ import type { HostKit } from './host-kit.js';
15
+ export interface ToolScopeContext {
16
+ readonly workspace: string | null;
17
+ readonly preset: string | null;
18
+ readonly session: string | null;
19
+ readonly scope?: unknown;
20
+ }
21
+ export interface UnitMountDeps extends HostKit {
22
+ readonly manifest: UnitManifest;
23
+ readonly ctx: HostContext;
24
+ readonly logger?: {
25
+ info?(message: string): void;
26
+ warn?(message: string): void;
27
+ } | undefined;
28
+ readonly manifests: () => readonly UnitManifest[];
29
+ readonly ownedUnits: () => readonly string[];
30
+ readonly installable?: (() => readonly string[]) | undefined;
31
+ readonly data: DataReader;
32
+ readonly env?: Readonly<Record<string, string | undefined>> | undefined;
33
+ readonly libs?: LibReader | undefined;
34
+ readonly git?: GitReader | undefined;
35
+ readonly commands?: CommandReader | undefined;
36
+ readonly store: WorkspaceStore;
37
+ readonly values?: ValueHandoff | undefined;
38
+ readonly probe?: (unit: string, options?: {
39
+ readonly force?: boolean;
40
+ }) => Promise<UnitCapability | undefined>;
41
+ readonly longTasks?: LongTaskHost | undefined;
42
+ readonly longTaskRuns?: (() => ReadonlyMap<string, LongTaskRegistry<LongTaskBase>>) | undefined;
43
+ }
44
+ export type ContextRenderer = (ref: {
45
+ readonly kind: string;
46
+ readonly parts: readonly string[];
47
+ }) => Promise<string> | string;
48
+ export type UnitWarmRead = readonly string[];
49
+ export interface UnitCall {
50
+ readonly source: string;
51
+ readonly args: Readonly<Record<string, unknown>>;
52
+ readonly result: unknown;
53
+ }
54
+ /**
55
+ * 挂载结果:路由表 + 工具注册。
56
+ * `registerTools()` 是**调用时才注册**,返回一组清理函数(卸载 / 热换时外壳逐个调);
57
+ * 工具名必须与清单 `dsh.workbench.tools` 一字不差,没有工具就 `() => []`。
58
+ */
59
+ export interface UnitMountResult {
60
+ readonly routes: RouteTable;
61
+ registerTools(): Array<() => void>;
62
+ readonly factsOf?: ((call: UnitCall) => readonly string[] | undefined) | undefined;
63
+ readonly gate?: {
64
+ deniedTools(context: ToolScopeContext): readonly string[];
65
+ denyReason?(name: string, context: ToolScopeContext): string | undefined;
66
+ subscribe(listener: () => void): () => void;
67
+ };
68
+ readonly context?: {
69
+ readonly kinds: readonly string[];
70
+ render(ref: {
71
+ readonly kind: string;
72
+ readonly parts: readonly string[];
73
+ }): Promise<string> | string;
74
+ };
75
+ readonly warmReads?: (() => readonly UnitWarmRead[]) | undefined;
76
+ readonly prefs?: {
77
+ readonly resource: string;
78
+ handle(payload: unknown): unknown;
79
+ };
80
+ readonly actions?: readonly {
81
+ readonly resource: string;
82
+ handle(payload: unknown): unknown;
83
+ }[];
84
+ readonly provision?: ProvisionHandler;
85
+ readonly longTasks?: LongTaskRegistry<LongTaskBase> | undefined;
86
+ readonly approvalDetail?: ((call: ApprovalCall) => ApprovalFacts | undefined | Promise<ApprovalFacts | undefined>) | undefined;
87
+ readonly needsApproval?: ApprovalPolicy | undefined;
88
+ }
89
+ export interface UnitModuleFace {
90
+ readonly unit: string;
91
+ mount(deps: UnitMountDeps): UnitMountResult;
92
+ }
93
+ export interface UnitOwnedFace extends UnitModuleFace {
94
+ readonly manifest: UnitManifest;
95
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { HostContext } from '../contract/module-context.js';
2
+ import type { UnitModuleFace } from './unit-face.js';
3
+ /**
4
+ * 一个宿主插件导出的三件:`name` / `inject` / `apply`。
5
+ */
6
+ export interface UnitHostPlugin {
7
+ readonly name: string;
8
+ readonly inject: readonly string[];
9
+ apply(ctx: HostContext): void;
10
+ }
11
+ /**
12
+ * 把「宿主面注册进外壳」这段在每个模块里都一样的接线收成一份。
13
+ * 用法:先 `const plugin = defineUnitHostPlugin({ … })`,再逐个导出 `name` / `inject` / `apply`
14
+ * (逐名 `export const` 才过 arch 的导出对账;解构导出它认不出)。
15
+ * @param options.name 插件名(包名)。
16
+ * @param options.unit 单元 id。
17
+ * @param options.face 这个单元的宿主面。
18
+ * @returns `{ name, inject, apply }`;`apply` 里取 `workbenchUnits`、缺了就 warn 一声。
19
+ */
20
+ export declare function defineUnitHostPlugin(options: {
21
+ readonly name: string;
22
+ readonly unit: string;
23
+ readonly face: UnitModuleFace;
24
+ }): UnitHostPlugin;
@@ -0,0 +1,25 @@
1
+ import { UNITS_SERVICE } from '../config/constants.js';
2
+ /**
3
+ * 把「宿主面注册进外壳」这段在每个模块里都一样的接线收成一份。
4
+ * 用法:先 `const plugin = defineUnitHostPlugin({ … })`,再逐个导出 `name` / `inject` / `apply`
5
+ * (逐名 `export const` 才过 arch 的导出对账;解构导出它认不出)。
6
+ * @param options.name 插件名(包名)。
7
+ * @param options.unit 单元 id。
8
+ * @param options.face 这个单元的宿主面。
9
+ * @returns `{ name, inject, apply }`;`apply` 里取 `workbenchUnits`、缺了就 warn 一声。
10
+ */
11
+ export function defineUnitHostPlugin(options) {
12
+ const { name, unit, face } = options;
13
+ return {
14
+ name,
15
+ inject: [UNITS_SERVICE],
16
+ apply(ctx) {
17
+ const units = ctx.get(UNITS_SERVICE);
18
+ if (units === undefined) {
19
+ ctx.logger?.warn?.(`[${unit}] 外壳没有提供 workbenchUnits 服务:这个模块装不进来`);
20
+ return;
21
+ }
22
+ ctx.effect(() => units.register(face), `${name}: 注册 ${unit}`);
23
+ },
24
+ };
25
+ }
@@ -0,0 +1,19 @@
1
+ import type { UpdateJournalRecord } from './update-journal-types.js';
2
+ /** 用 Pick 绑定日志结构,字段增删会变成编译错误而不是静默漂移。 */
3
+ export type ManifestRecord = Pick<UpdateJournalRecord, 'from' | 'to' | 'profileDir' | 'versionDir' | 'manifestPath' | 'manifestText' | 'manifestDeps' | 'links' | 'carry'>;
4
+ /**
5
+ * 回滚清单:新日志只回写被接管的几条依赖,避免把等待期间用户/插件新增的依赖整份吞掉。
6
+ * 旧日志没有逐条快照,只能退回整份原文。
7
+ */
8
+ export declare function restoreManifest(record: ManifestRecord): void;
9
+ export type LinkFn = (target: string, path: string) => void;
10
+ /**
11
+ * 新版已经启动过时按日志前滚:把链接与清单都补成新版,而不是留半截现场。
12
+ *
13
+ * 先整体校验(新版本目录里的包都在、类型可接),再逐条换链;中途失败会尽力把
14
+ * 已经换过的链接按快照退回去,避免留下“一半新版、一半旧版”的现场。
15
+ */
16
+ export declare function rollForward(record: ManifestRecord, link?: LinkFn): {
17
+ readonly ok: boolean;
18
+ readonly detail: string;
19
+ };
@@ -0,0 +1,134 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, relative, resolve, sep } from 'node:path';
3
+ import { copyDirInto, linkDir, removePath, writeJsonFile, writeTextFile } from './fs-write.js';
4
+ import { readJsonObject } from './read-json.js';
5
+ /**
6
+ * 回滚清单:新日志只回写被接管的几条依赖,避免把等待期间用户/插件新增的依赖整份吞掉。
7
+ * 旧日志没有逐条快照,只能退回整份原文。
8
+ */
9
+ export function restoreManifest(record) {
10
+ const deps = record.manifestDeps;
11
+ if (deps === undefined) {
12
+ writeTextFile(record.manifestPath, record.manifestText, { fsync: true });
13
+ return;
14
+ }
15
+ const current = readManifestObject(record);
16
+ const dependencies = { ...(dependenciesOf(current) ?? {}) };
17
+ for (const [pkg, spec] of Object.entries(deps)) {
18
+ if (spec === null)
19
+ delete dependencies[pkg];
20
+ else
21
+ dependencies[pkg] = spec;
22
+ }
23
+ writeJsonFile(record.manifestPath, { ...current, dependencies }, { fsync: true });
24
+ }
25
+ /**
26
+ * 新版已经启动过时按日志前滚:把链接与清单都补成新版,而不是留半截现场。
27
+ *
28
+ * 先整体校验(新版本目录里的包都在、类型可接),再逐条换链;中途失败会尽力把
29
+ * 已经换过的链接按快照退回去,避免留下“一半新版、一半旧版”的现场。
30
+ */
31
+ export function rollForward(record, link = linkDir) {
32
+ const failures = [];
33
+ const planned = [];
34
+ for (const link of record.links) {
35
+ if (link.kind === 'other') {
36
+ failures.push(`${link.pkg}:现场那条既不是链接也不是目录`);
37
+ continue;
38
+ }
39
+ const target = join(record.versionDir, 'node_modules', link.pkg);
40
+ if (!existsSync(target)) {
41
+ failures.push(`${link.pkg}:新版本目录里找不到`);
42
+ continue;
43
+ }
44
+ planned.push({ link, target });
45
+ }
46
+ if (failures.length > 0)
47
+ return { ok: false, detail: `换新版的链接没补齐(${failures.join(';')})` };
48
+ const changed = [];
49
+ const specs = {};
50
+ for (const item of planned) {
51
+ changed.push(item);
52
+ try {
53
+ link(item.target, item.link.path);
54
+ specs[item.link.pkg] = linkSpecOf(record.profileDir, item.target);
55
+ }
56
+ catch (error) {
57
+ failures.push(`${item.link.pkg}:${messageOf(error)}`);
58
+ break;
59
+ }
60
+ }
61
+ if (failures.length > 0) {
62
+ for (const item of changed.reverse())
63
+ revertLink(record, item.link, link);
64
+ return { ok: false, detail: `换新版的链接没补齐(${failures.join(';')})` };
65
+ }
66
+ try {
67
+ const current = readJsonObject(record.manifestPath);
68
+ if (current === undefined)
69
+ throw new Error('清单读不出来');
70
+ const dependencies = { ...(dependenciesOf(current) ?? {}) };
71
+ for (const [pkg, spec] of Object.entries(specs))
72
+ dependencies[pkg] = spec;
73
+ writeJsonFile(record.manifestPath, { ...current, dependencies }, { fsync: true });
74
+ }
75
+ catch (error) {
76
+ for (const item of changed.reverse())
77
+ revertLink(record, item.link, link);
78
+ return { ok: false, detail: `换新版的清单没写成(${messageOf(error)})` };
79
+ }
80
+ return { ok: true, detail: `已经按 ${record.to} 补好链接与清单` };
81
+ }
82
+ function revertLink(record, link, apply) {
83
+ try {
84
+ if (link.kind === 'symlink' && link.target !== undefined) {
85
+ apply(resolve(dirname(link.path), link.target), link.path);
86
+ return;
87
+ }
88
+ if (link.kind === 'missing') {
89
+ removePath(link.path);
90
+ return;
91
+ }
92
+ if (link.kind !== 'dir')
93
+ return;
94
+ const carried = record.carry.find((item) => item.from === link.path);
95
+ if (carried !== undefined && existsSync(carried.to)) {
96
+ copyDirInto(carried.to, link.path);
97
+ return;
98
+ }
99
+ if (record.to === record.from) {
100
+ const target = join(record.versionDir, 'node_modules', link.pkg);
101
+ if (existsSync(target))
102
+ apply(target, link.path);
103
+ }
104
+ }
105
+ catch {
106
+ // 尽力而为:退不回去就保留日志,下次启动还会再试
107
+ }
108
+ }
109
+ function linkSpecOf(profileDir, target) {
110
+ return `link:${relative(profileDir, target).split(sep).join('/')}`;
111
+ }
112
+ function readManifestObject(record) {
113
+ const current = readJsonObject(record.manifestPath);
114
+ if (current !== undefined)
115
+ return current;
116
+ try {
117
+ const parsed = JSON.parse(record.manifestText);
118
+ if (typeof parsed === 'object' && parsed !== null)
119
+ return parsed;
120
+ }
121
+ catch {
122
+ // 落到下面统一报错
123
+ }
124
+ throw new Error('清单读不出来');
125
+ }
126
+ function dependenciesOf(manifest) {
127
+ const table = manifest['dependencies'];
128
+ if (typeof table !== 'object' || table === null || Array.isArray(table))
129
+ return undefined;
130
+ return { ...table };
131
+ }
132
+ function messageOf(error) {
133
+ return error instanceof Error ? error.message : String(error);
134
+ }
@@ -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;