@dsh-workbench/shared 1.5.2-alpha.0 → 1.5.2-alpha.2

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 (322) hide show
  1. package/dist/contract/protocol/bundle-install.d.ts +7 -1
  2. package/dist/contract/protocol/bundle-install.js +1 -0
  3. package/dist/host/runtime/dsh-compat.js +20 -6
  4. package/dist/i18n/en.js +2 -0
  5. package/dist/i18n/index.d.ts +3 -1
  6. package/dist/i18n/zh.d.ts +2 -0
  7. package/dist/i18n/zh.js +2 -0
  8. package/dist/lib/dsh-client.d.ts +1 -1
  9. package/package.json +47 -51
  10. package/src/contract/protocol/bundle-install.ts +9 -1
  11. package/src/host/runtime/__tests__/dsh-compat.test.ts +23 -0
  12. package/src/host/runtime/dsh-compat.ts +18 -5
  13. package/src/i18n/en.ts +2 -0
  14. package/src/i18n/zh.ts +2 -0
  15. package/src/lib/dsh-client.ts +1 -2
  16. package/dist/components/Activity.css +0 -69
  17. package/dist/components/Activity.d.ts +0 -56
  18. package/dist/components/Activity.js +0 -47
  19. package/dist/components/ApprovalDetail.css +0 -3
  20. package/dist/components/ApprovalDetail.d.ts +0 -42
  21. package/dist/components/ApprovalDetail.js +0 -53
  22. package/dist/components/ApprovalPlan.css +0 -39
  23. package/dist/components/ApprovalPlan.d.ts +0 -27
  24. package/dist/components/ApprovalPlan.js +0 -19
  25. package/dist/components/Card.css +0 -19
  26. package/dist/components/Card.d.ts +0 -26
  27. package/dist/components/Card.js +0 -18
  28. package/dist/components/CardAnchor.d.ts +0 -21
  29. package/dist/components/CardAnchor.js +0 -19
  30. package/dist/components/CardAnchor.module.css +0 -3
  31. package/dist/components/CardBoundary.d.ts +0 -42
  32. package/dist/components/CardBoundary.js +0 -58
  33. package/dist/components/CardBoundary.module.css +0 -5
  34. package/dist/components/CardHead.css +0 -87
  35. package/dist/components/CardHead.d.ts +0 -30
  36. package/dist/components/CardHead.js +0 -27
  37. package/dist/components/ChoiceGroup.css +0 -182
  38. package/dist/components/ChoiceGroup.d.ts +0 -54
  39. package/dist/components/ChoiceGroup.js +0 -63
  40. package/dist/components/ConfirmBar.css +0 -26
  41. package/dist/components/ConfirmBar.d.ts +0 -36
  42. package/dist/components/ConfirmBar.js +0 -26
  43. package/dist/components/EmptyIllustration.d.ts +0 -12
  44. package/dist/components/EmptyIllustration.js +0 -32
  45. package/dist/components/Field.css +0 -20
  46. package/dist/components/Field.d.ts +0 -18
  47. package/dist/components/Field.js +0 -15
  48. package/dist/components/Form.css +0 -6
  49. package/dist/components/Form.d.ts +0 -22
  50. package/dist/components/Form.js +0 -60
  51. package/dist/components/FormActions.css +0 -13
  52. package/dist/components/FormActions.d.ts +0 -29
  53. package/dist/components/FormActions.js +0 -43
  54. package/dist/components/FormNodes.d.ts +0 -107
  55. package/dist/components/FormNodes.js +0 -165
  56. package/dist/components/FormRows.css +0 -107
  57. package/dist/components/FormRows.d.ts +0 -36
  58. package/dist/components/FormRows.js +0 -26
  59. package/dist/components/FormTypes.d.ts +0 -84
  60. package/dist/components/FormTypes.js +0 -1
  61. package/dist/components/Link.css +0 -22
  62. package/dist/components/Link.d.ts +0 -22
  63. package/dist/components/Link.js +0 -17
  64. package/dist/components/LongTaskRow.css +0 -171
  65. package/dist/components/LongTaskRow.d.ts +0 -94
  66. package/dist/components/LongTaskRow.js +0 -103
  67. package/dist/components/Note.css +0 -13
  68. package/dist/components/Note.d.ts +0 -20
  69. package/dist/components/Note.js +0 -14
  70. package/dist/components/ResourceStates.css +0 -114
  71. package/dist/components/ResourceStates.d.ts +0 -44
  72. package/dist/components/ResourceStates.js +0 -41
  73. package/dist/components/Rows.css +0 -42
  74. package/dist/components/Rows.d.ts +0 -28
  75. package/dist/components/Rows.js +0 -21
  76. package/dist/components/SaveBar.d.ts +0 -24
  77. package/dist/components/SaveBar.js +0 -25
  78. package/dist/components/SelectField.css +0 -182
  79. package/dist/components/SelectField.d.ts +0 -89
  80. package/dist/components/SelectField.js +0 -260
  81. package/dist/components/SelectFieldNodes.d.ts +0 -49
  82. package/dist/components/SelectFieldNodes.js +0 -43
  83. package/dist/components/SettingsSection.css +0 -25
  84. package/dist/components/SettingsSection.d.ts +0 -20
  85. package/dist/components/SettingsSection.js +0 -17
  86. package/dist/components/SetupShell.d.ts +0 -93
  87. package/dist/components/SetupShell.js +0 -64
  88. package/dist/components/SetupShell.module.css +0 -81
  89. package/dist/components/Spinner.css +0 -5
  90. package/dist/components/Spinner.d.ts +0 -15
  91. package/dist/components/Spinner.js +0 -13
  92. package/dist/components/Stack.css +0 -6
  93. package/dist/components/Stack.d.ts +0 -14
  94. package/dist/components/Stack.js +0 -10
  95. package/dist/components/StateBlock.css +0 -38
  96. package/dist/components/StateBlock.d.ts +0 -24
  97. package/dist/components/StateBlock.js +0 -22
  98. package/dist/components/TextField.css +0 -32
  99. package/dist/components/TextField.d.ts +0 -14
  100. package/dist/components/TextField.js +0 -10
  101. package/dist/components/board-module.d.ts +0 -307
  102. package/dist/components/board-module.js +0 -1
  103. package/dist/components/card-view-validate.d.ts +0 -5
  104. package/dist/components/card-view-validate.js +0 -256
  105. package/dist/components/icons.d.ts +0 -63
  106. package/dist/components/icons.js +0 -107
  107. package/dist/components/layout/icon-command.d.ts +0 -8
  108. package/dist/components/layout/icon-command.js +0 -21
  109. package/dist/contract/capture.d.ts +0 -16
  110. package/dist/contract/capture.js +0 -1
  111. package/dist/contract/diagnostics.d.ts +0 -34
  112. package/dist/contract/diagnostics.js +0 -124
  113. package/dist/contract/protocol/unit-manager.d.ts +0 -50
  114. package/dist/contract/protocol/unit-manager.js +0 -2
  115. package/dist/host/adapter-contract.d.ts +0 -3
  116. package/dist/host/adapter-contract.js +0 -95
  117. package/dist/host/adapter-set.d.ts +0 -27
  118. package/dist/host/adapter-set.js +0 -258
  119. package/dist/host/adapter-types.d.ts +0 -87
  120. package/dist/host/adapter-types.js +0 -23
  121. package/dist/host/adapters/platform.d.ts +0 -14
  122. package/dist/host/adapters/platform.js +0 -40
  123. package/dist/host/adapters.d.ts +0 -28
  124. package/dist/host/adapters.js +0 -9
  125. package/dist/host/auth-loss.d.ts +0 -33
  126. package/dist/host/auth-loss.js +0 -107
  127. package/dist/host/board-fact.d.ts +0 -8
  128. package/dist/host/board-fact.js +0 -16
  129. package/dist/host/boot-record.d.ts +0 -11
  130. package/dist/host/boot-record.js +0 -31
  131. package/dist/host/browser.d.ts +0 -3
  132. package/dist/host/browser.js +0 -3
  133. package/dist/host/bundle-manager.d.ts +0 -4
  134. package/dist/host/bundle-manager.js +0 -338
  135. package/dist/host/changelog.d.ts +0 -28
  136. package/dist/host/changelog.js +0 -201
  137. package/dist/host/cli-error.d.ts +0 -8
  138. package/dist/host/cli-error.js +0 -70
  139. package/dist/host/cli.d.ts +0 -4
  140. package/dist/host/cli.js +0 -9
  141. package/dist/host/config-sync.d.ts +0 -40
  142. package/dist/host/config-sync.js +0 -267
  143. package/dist/host/context-ref.d.ts +0 -13
  144. package/dist/host/context-ref.js +0 -41
  145. package/dist/host/data-error.d.ts +0 -15
  146. package/dist/host/data-error.js +0 -23
  147. package/dist/host/data-plan-check.d.ts +0 -10
  148. package/dist/host/data-plan-check.js +0 -315
  149. package/dist/host/data-plan.d.ts +0 -15
  150. package/dist/host/data-plan.js +0 -283
  151. package/dist/host/data-root.d.ts +0 -5
  152. package/dist/host/data-root.js +0 -23
  153. package/dist/host/diy-debug.d.ts +0 -80
  154. package/dist/host/diy-debug.js +0 -89
  155. package/dist/host/diy-preset.d.ts +0 -26
  156. package/dist/host/diy-preset.js +0 -115
  157. package/dist/host/diy-record.d.ts +0 -135
  158. package/dist/host/diy-record.js +0 -163
  159. package/dist/host/dsh-compat.d.ts +0 -27
  160. package/dist/host/dsh-compat.js +0 -75
  161. package/dist/host/dsh-plugins.d.ts +0 -5
  162. package/dist/host/dsh-plugins.js +0 -51
  163. package/dist/host/env-policy.d.ts +0 -82
  164. package/dist/host/env-policy.js +0 -181
  165. package/dist/host/extension.d.ts +0 -7
  166. package/dist/host/extension.js +0 -40
  167. package/dist/host/facts.d.ts +0 -31
  168. package/dist/host/facts.js +0 -58
  169. package/dist/host/fs-write.d.ts +0 -96
  170. package/dist/host/fs-write.js +0 -183
  171. package/dist/host/git.d.ts +0 -5
  172. package/dist/host/git.js +0 -1
  173. package/dist/host/host-actions.d.ts +0 -2
  174. package/dist/host/host-actions.js +0 -5
  175. package/dist/host/host-kit.d.ts +0 -37
  176. package/dist/host/host-kit.js +0 -27
  177. package/dist/host/http.d.ts +0 -47
  178. package/dist/host/http.js +0 -289
  179. package/dist/host/install-failure.d.ts +0 -50
  180. package/dist/host/install-failure.js +0 -184
  181. package/dist/host/installed-module.d.ts +0 -25
  182. package/dist/host/installed-module.js +0 -289
  183. package/dist/host/installed-sources.d.ts +0 -10
  184. package/dist/host/installed-sources.js +0 -63
  185. package/dist/host/lease.d.ts +0 -70
  186. package/dist/host/lease.js +0 -264
  187. package/dist/host/lib-capabilities.d.ts +0 -22
  188. package/dist/host/lib-capabilities.js +0 -37
  189. package/dist/host/lib-install.d.ts +0 -19
  190. package/dist/host/lib-install.js +0 -40
  191. package/dist/host/lib-runners.d.ts +0 -18
  192. package/dist/host/lib-runners.js +0 -46
  193. package/dist/host/local-declaration.d.ts +0 -7
  194. package/dist/host/local-declaration.js +0 -33
  195. package/dist/host/long-task.d.ts +0 -97
  196. package/dist/host/long-task.js +0 -297
  197. package/dist/host/market-index-claim.d.ts +0 -19
  198. package/dist/host/market-index-claim.js +0 -87
  199. package/dist/host/market-index-doc.d.ts +0 -12
  200. package/dist/host/market-index-doc.js +0 -1
  201. package/dist/host/market-index-parse.d.ts +0 -28
  202. package/dist/host/market-index-parse.js +0 -413
  203. package/dist/host/market-index.d.ts +0 -13
  204. package/dist/host/market-index.js +0 -105
  205. package/dist/host/module-root.d.ts +0 -1
  206. package/dist/host/module-root.js +0 -5
  207. package/dist/host/needs.d.ts +0 -4
  208. package/dist/host/needs.js +0 -2
  209. package/dist/host/npm-registry.d.ts +0 -10
  210. package/dist/host/npm-registry.js +0 -16
  211. package/dist/host/package-content.d.ts +0 -8
  212. package/dist/host/package-content.js +0 -90
  213. package/dist/host/package-kind.d.ts +0 -13
  214. package/dist/host/package-kind.js +0 -51
  215. package/dist/host/package-route.d.ts +0 -33
  216. package/dist/host/package-route.js +0 -68
  217. package/dist/host/panel-state.d.ts +0 -120
  218. package/dist/host/panel-state.js +0 -177
  219. package/dist/host/patch-blocks.d.ts +0 -13
  220. package/dist/host/patch-blocks.js +0 -52
  221. package/dist/host/patch.d.ts +0 -4
  222. package/dist/host/patch.js +0 -7
  223. package/dist/host/paths.d.ts +0 -12
  224. package/dist/host/paths.js +0 -20
  225. package/dist/host/payload.d.ts +0 -12
  226. package/dist/host/payload.js +0 -16
  227. package/dist/host/plan-results.d.ts +0 -5
  228. package/dist/host/plan-results.js +0 -71
  229. package/dist/host/plan-run.d.ts +0 -41
  230. package/dist/host/plan-run.js +0 -87
  231. package/dist/host/platform.d.ts +0 -14
  232. package/dist/host/platform.js +0 -40
  233. package/dist/host/plugin-ledger.d.ts +0 -32
  234. package/dist/host/plugin-ledger.js +0 -106
  235. package/dist/host/plugin.d.ts +0 -3
  236. package/dist/host/plugin.js +0 -38
  237. package/dist/host/port-types.d.ts +0 -233
  238. package/dist/host/port-types.js +0 -1
  239. package/dist/host/preflight.d.ts +0 -32
  240. package/dist/host/preflight.js +0 -1
  241. package/dist/host/process-alive.d.ts +0 -6
  242. package/dist/host/process-alive.js +0 -16
  243. package/dist/host/profile-bundles.d.ts +0 -20
  244. package/dist/host/profile-bundles.js +0 -48
  245. package/dist/host/profile-create.d.ts +0 -19
  246. package/dist/host/profile-create.js +0 -124
  247. package/dist/host/profile-port.d.ts +0 -4
  248. package/dist/host/profile-port.js +0 -4
  249. package/dist/host/profile-registries.d.ts +0 -10
  250. package/dist/host/profile-registries.js +0 -149
  251. package/dist/host/provision.d.ts +0 -32
  252. package/dist/host/provision.js +0 -105
  253. package/dist/host/read-json.d.ts +0 -1
  254. package/dist/host/read-json.js +0 -11
  255. package/dist/host/recipe-rules.d.ts +0 -5
  256. package/dist/host/recipe-rules.js +0 -412
  257. package/dist/host/recipe.d.ts +0 -14
  258. package/dist/host/recipe.js +0 -332
  259. package/dist/host/registry-declaration.d.ts +0 -21
  260. package/dist/host/registry-declaration.js +0 -42
  261. package/dist/host/reinstall-record.d.ts +0 -16
  262. package/dist/host/reinstall-record.js +0 -54
  263. package/dist/host/release-age.d.ts +0 -24
  264. package/dist/host/release-age.js +0 -92
  265. package/dist/host/release-packages.generated.d.ts +0 -1
  266. package/dist/host/release-packages.generated.js +0 -10
  267. package/dist/host/release-probe.d.ts +0 -37
  268. package/dist/host/release-probe.js +0 -156
  269. package/dist/host/runtime/browser-argv.d.ts +0 -1
  270. package/dist/host/runtime/browser-argv.js +0 -9
  271. package/dist/host/runtime/front-app.d.ts +0 -6
  272. package/dist/host/runtime/front-app.js +0 -70
  273. package/dist/host/shell-render.d.ts +0 -52
  274. package/dist/host/shell-render.js +0 -117
  275. package/dist/host/shell-text.d.ts +0 -30
  276. package/dist/host/shell-text.js +0 -40
  277. package/dist/host/shell.d.ts +0 -25
  278. package/dist/host/shell.js +0 -55
  279. package/dist/host/site.d.ts +0 -45
  280. package/dist/host/site.js +0 -182
  281. package/dist/host/spec.d.ts +0 -8
  282. package/dist/host/spec.js +0 -24
  283. package/dist/host/submit-confirm.d.ts +0 -19
  284. package/dist/host/submit-confirm.js +0 -45
  285. package/dist/host/supply-index.d.ts +0 -38
  286. package/dist/host/supply-index.js +0 -209
  287. package/dist/host/supply-port.d.ts +0 -5
  288. package/dist/host/supply-port.js +0 -50
  289. package/dist/host/time.d.ts +0 -22
  290. package/dist/host/time.js +0 -33
  291. package/dist/host/tokens.d.ts +0 -26
  292. package/dist/host/tokens.js +0 -154
  293. package/dist/host/tool-approval.d.ts +0 -86
  294. package/dist/host/tool-approval.js +0 -118
  295. package/dist/host/tool-kit.d.ts +0 -8
  296. package/dist/host/tool-kit.js +0 -22
  297. package/dist/host/toolbox-port.d.ts +0 -16
  298. package/dist/host/toolbox-port.js +0 -1
  299. package/dist/host/unit-config.d.ts +0 -34
  300. package/dist/host/unit-config.js +0 -28
  301. package/dist/host/unit-data.d.ts +0 -3
  302. package/dist/host/unit-data.js +0 -127
  303. package/dist/host/unit-face.d.ts +0 -95
  304. package/dist/host/unit-face.js +0 -1
  305. package/dist/host/unit-plugin.d.ts +0 -24
  306. package/dist/host/unit-plugin.js +0 -25
  307. package/dist/host/update-journal-manifest.d.ts +0 -19
  308. package/dist/host/update-journal-manifest.js +0 -134
  309. package/dist/host/update-journal-types.d.ts +0 -33
  310. package/dist/host/update-journal-types.js +0 -2
  311. package/dist/host/update-journal.d.ts +0 -43
  312. package/dist/host/update-journal.js +0 -409
  313. package/dist/host/value-handoff.d.ts +0 -16
  314. package/dist/host/value-handoff.js +0 -22
  315. package/dist/host/version-range.d.ts +0 -2
  316. package/dist/host/version-range.js +0 -13
  317. package/dist/host/version.d.ts +0 -4
  318. package/dist/host/version.js +0 -32
  319. package/dist/host/workspace-store.d.ts +0 -19
  320. package/dist/host/workspace-store.js +0 -133
  321. package/dist/host/write-result.d.ts +0 -1
  322. package/dist/host/write-result.js +0 -18
@@ -1,95 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
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;
@@ -1,25 +0,0 @@
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
- }
@@ -1,19 +0,0 @@
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
- };
@@ -1,134 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export const UPDATE_JOURNAL_STATES = ['prepared', 'carrying', 'flipping', 'manifest', 'committed'];
2
- export const UPDATE_JOURNAL_LINK_KINDS = ['symlink', 'dir', 'missing', 'other'];
@@ -1,43 +0,0 @@
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;