iobroker.eos-admin 9.0.36 → 9.0.38

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 (173) hide show
  1. package/NEXOWATT_EOS_BUILD_INFO.json +10 -10
  2. package/README.md +15 -3
  3. package/adminWww/.vite/manifest.json +114 -114
  4. package/adminWww/NEXOWATT_EOS_FRONTEND_MANIFEST.json +13759 -13759
  5. package/adminWww/assets/{AdapterUpdateDialog-D2nDWE_N.js → AdapterUpdateDialog-D4gUYZep.js} +1 -1
  6. package/adminWww/assets/{Adapters-D0sVqNBU.js → Adapters-DLxiJc3y.js} +1 -1
  7. package/adminWww/assets/{ConfigManager-Zm7UoaaN.js → ConfigManager-D_YTKUdP.js} +1 -1
  8. package/adminWww/assets/{Enums-BGL7pR-O.js → Enums-D79rON6b.js} +1 -1
  9. package/adminWww/assets/{Fields-A8J3u1yq.js → Fields-CTOv49EU.js} +1 -1
  10. package/adminWww/assets/{Files-CQPjCvW6.js → Files-DNLzjEG5.js} +1 -1
  11. package/adminWww/assets/{Hosts-CxzkkNBj.js → Hosts-DHNboUMq.js} +1 -1
  12. package/adminWww/assets/{Instances-eEbEukDh.js → Instances-BJxYNJAC.js} +1 -1
  13. package/adminWww/assets/{Intro-I_Tknp0E.js → Intro-8R-Q7CR_.js} +1 -1
  14. package/adminWww/assets/{Logs-C3GPz61Q.js → Logs-CjAPhWuK.js} +1 -1
  15. package/adminWww/assets/{Objects-DDnisxNB.js → Objects-cvdqooGe.js} +1 -1
  16. package/adminWww/assets/{Overview-BpZFdEmp.js → Overview-JPfBOuKv.js} +1 -1
  17. package/adminWww/assets/{State-DY6Nw0SB.js → State-CGnvMceJ.js} +1 -1
  18. package/adminWww/assets/{UsedResources-CtUpdP2b.js → UsedResources-FBd9jThR.js} +1 -1
  19. package/adminWww/assets/{Users-DcqlSfc5.js → Users-BbUu3hZj.js} +1 -1
  20. package/adminWww/assets/{bootstrap-Didkuj-F.js → bootstrap-Df_WTIJg.js} +3 -3
  21. package/adminWww/assets/{hostInit-Chrs-wsg.js → hostInit-BQCRqFay.js} +1 -1
  22. package/adminWww/assets/{icons-material-SqwOQW6y.js → icons-material-DS82xOs8.js} +1 -1
  23. package/adminWww/assets/{index-CpDo61Mz.js → index-BlBZd8r8.js} +2 -2
  24. package/adminWww/assets/{installSVGRenderer-DZMZ3pJw.js → installSVGRenderer-BtlXF9y3.js} +1 -1
  25. package/adminWww/assets/{mf-entry-bootstrap-0-b0c4981a.js → mf-entry-bootstrap-0-8bb11ea2.js} +2 -2
  26. package/adminWww/index.html +23 -23
  27. package/adminWww/mf-manifest.json +1 -1
  28. package/adminWww/mf-stats.json +1 -1
  29. package/adminWww/{remoteEntry-eos-9.0.36.js → remoteEntry-eos-9.0.38.js} +1 -1
  30. package/adminWww/remoteEntry.js +1 -1
  31. package/build/lib/eosLegacyMigration.js +351 -60
  32. package/build/lib/eosLegacyMigration.js.map +1 -1
  33. package/build/lib/eosLegacySource.js +172 -0
  34. package/build/lib/eosLegacySource.js.map +1 -0
  35. package/build/lib/eosModuleHost.js +38 -1
  36. package/build/lib/eosModuleHost.js.map +1 -1
  37. package/build/lib/eosModuleHttp.js +55 -8
  38. package/build/lib/eosModuleHttp.js.map +1 -1
  39. package/build/lib/eosRuntimeControl.js +3 -1
  40. package/build/lib/eosRuntimeControl.js.map +1 -1
  41. package/build/main.js +1 -1
  42. package/build/main.js.map +1 -1
  43. package/docs/README.md +2 -0
  44. package/docs/reports/unified-9.0.37/PRUEFBERICHT.md +59 -0
  45. package/docs/reports/unified-9.0.37/PRUEFERGEBNISSE.json +112 -0
  46. package/docs/reports/unified-9.0.37/raw/INDEX.json +232 -0
  47. package/docs/reports/unified-9.0.37/raw/backend.log +5 -0
  48. package/docs/reports/unified-9.0.37/raw/core-final-node22.log +1439 -0
  49. package/docs/reports/unified-9.0.37/raw/core-final-node24.log +1381 -0
  50. package/docs/reports/unified-9.0.37/raw/dashboard-935-screenshot.json +15 -0
  51. package/docs/reports/unified-9.0.37/raw/dashboard-de-en-nl.json +1059 -0
  52. package/docs/reports/unified-9.0.37/raw/ems-ui-nvp-integration.json +245 -0
  53. package/docs/reports/unified-9.0.37/raw/farm-and-dashboard-935.json +11 -0
  54. package/docs/reports/unified-9.0.37/raw/farm-tracking-source-tests.log +80 -0
  55. package/docs/reports/unified-9.0.37/raw/fixtures-verification.log +39 -0
  56. package/docs/reports/unified-9.0.37/raw/frontend.log +160 -0
  57. package/docs/reports/unified-9.0.37/raw/installer.log +26 -0
  58. package/docs/reports/unified-9.0.37/raw/lint.log +45 -0
  59. package/docs/reports/unified-9.0.37/raw/measure-storage-display.cjs +47 -0
  60. package/docs/reports/unified-9.0.37/raw/modules.log +5 -0
  61. package/docs/reports/unified-9.0.37/raw/node22-isolated-start-deadlines.log +28 -0
  62. package/docs/reports/unified-9.0.37/raw/node22-migration.log +1329 -0
  63. package/docs/reports/unified-9.0.37/raw/node22-mira.log +222 -0
  64. package/docs/reports/unified-9.0.37/raw/node22-parallel-initial.log +13278 -0
  65. package/docs/reports/unified-9.0.37/raw/node22-startzeiten.json +21 -0
  66. package/docs/reports/unified-9.0.37/raw/node22-system-status.log +639 -0
  67. package/docs/reports/unified-9.0.37/raw/node22-tests-final.log +18494 -0
  68. package/docs/reports/unified-9.0.37/raw/node22-version.log +1 -0
  69. package/docs/reports/unified-9.0.37/raw/node24-migration.log +1301 -0
  70. package/docs/reports/unified-9.0.37/raw/node24-mira.log +41 -0
  71. package/docs/reports/unified-9.0.37/raw/node24-system-status.log +111 -0
  72. package/docs/reports/unified-9.0.37/raw/node24-tests-final.log +3080 -0
  73. package/docs/reports/unified-9.0.37/raw/node24-version.log +1 -0
  74. package/docs/reports/unified-9.0.37/raw/npm-runtime-audit.json +77 -0
  75. package/docs/reports/unified-9.0.37/raw/platform-acl-node22.log +98 -0
  76. package/docs/reports/unified-9.0.37/raw/platform-acl-node24.log +22 -0
  77. package/docs/reports/unified-9.0.37/raw/platform-nginx-node22.json +21 -0
  78. package/docs/reports/unified-9.0.37/raw/platform-nginx-node24.json +21 -0
  79. package/docs/reports/unified-9.0.37/raw/qa-source-check.log +2 -0
  80. package/docs/reports/unified-9.0.37/raw/release-metadata.log +13 -0
  81. package/docs/reports/unified-9.0.37/raw/sbom.log +8 -0
  82. package/docs/reports/unified-9.0.37/raw/speicher-warnschwelle-integration.json +172 -0
  83. package/docs/reports/unified-9.0.37/raw/sse-backpressure-9.0.35.log +1 -0
  84. package/docs/reports/unified-9.0.37/raw/sse-backpressure-9.0.37.log +1 -0
  85. package/docs/reports/unified-9.0.37/raw/storage-display-memory-node22.json +19 -0
  86. package/docs/reports/unified-9.0.37/raw/storage-display-memory-node24.json +19 -0
  87. package/docs/reports/unified-9.0.37/raw/typecheck.log +5 -0
  88. package/docs/reports/unified-9.0.37/raw/ui-runtime.log +7 -0
  89. package/docs/reports/unified-9.0.38/PRUEFBERICHT.md +51 -0
  90. package/docs/reports/unified-9.0.38/PRUEFERGEBNISSE.json +112 -0
  91. package/docs/reports/unified-9.0.38/raw/INDEX.json +272 -0
  92. package/docs/reports/unified-9.0.38/raw/backend.log +5 -0
  93. package/docs/reports/unified-9.0.38/raw/core-final-node22.log +1439 -0
  94. package/docs/reports/unified-9.0.38/raw/core-final-node24.log +1381 -0
  95. package/docs/reports/unified-9.0.38/raw/dashboard-de-en-nl.json +1044 -0
  96. package/docs/reports/unified-9.0.38/raw/field-upgrade-936-node22.log +21 -0
  97. package/docs/reports/unified-9.0.38/raw/field-upgrade-936-node24.log +10 -0
  98. package/docs/reports/unified-9.0.38/raw/fixtures-verification.log +39 -0
  99. package/docs/reports/unified-9.0.38/raw/frontend.log +152 -0
  100. package/docs/reports/unified-9.0.38/raw/installer.log +26 -0
  101. package/docs/reports/unified-9.0.38/raw/legacy-historian-provenance.json +44 -0
  102. package/docs/reports/unified-9.0.38/raw/legacy-history-built-influx.log +10 -0
  103. package/docs/reports/unified-9.0.38/raw/legacy-history-misbinding-937.log +1 -0
  104. package/docs/reports/unified-9.0.38/raw/legacy-history-providers-node22.log +326 -0
  105. package/docs/reports/unified-9.0.38/raw/legacy-history-providers-node24.log +58 -0
  106. package/docs/reports/unified-9.0.38/raw/legacy-history-real-influx.log +10 -0
  107. package/docs/reports/unified-9.0.38/raw/legacy-history-source-comparison.json +12 -0
  108. package/docs/reports/unified-9.0.38/raw/legacy-template-interfaces.json +21 -0
  109. package/docs/reports/unified-9.0.38/raw/lint.log +45 -0
  110. package/docs/reports/unified-9.0.38/raw/migration-admin-browser-node22.log +86 -0
  111. package/docs/reports/unified-9.0.38/raw/migration-admin-browser-node24.log +84 -0
  112. package/docs/reports/unified-9.0.38/raw/migration-live-children-node22.log +20 -0
  113. package/docs/reports/unified-9.0.38/raw/migration-live-children-node24.log +9 -0
  114. package/docs/reports/unified-9.0.38/raw/migration-process-admin-node22.log +831 -0
  115. package/docs/reports/unified-9.0.38/raw/migration-process-admin-node24.log +144 -0
  116. package/docs/reports/unified-9.0.38/raw/modules.log +5 -0
  117. package/docs/reports/unified-9.0.38/raw/node22-initial-destination-channel.log +13298 -0
  118. package/docs/reports/unified-9.0.38/raw/node22-migration.log +1443 -0
  119. package/docs/reports/unified-9.0.38/raw/node22-mira.log +222 -0
  120. package/docs/reports/unified-9.0.38/raw/node22-system-status.log +639 -0
  121. package/docs/reports/unified-9.0.38/raw/node22-tests-final.log +18620 -0
  122. package/docs/reports/unified-9.0.38/raw/node22-version.log +1 -0
  123. package/docs/reports/unified-9.0.38/raw/node24-migration.log +1411 -0
  124. package/docs/reports/unified-9.0.38/raw/node24-mira.log +41 -0
  125. package/docs/reports/unified-9.0.38/raw/node24-system-status.log +111 -0
  126. package/docs/reports/unified-9.0.38/raw/node24-tests-final.log +3102 -0
  127. package/docs/reports/unified-9.0.38/raw/node24-version.log +1 -0
  128. package/docs/reports/unified-9.0.38/raw/npm-runtime-audit.json +77 -0
  129. package/docs/reports/unified-9.0.38/raw/platform-acl-node22.log +98 -0
  130. package/docs/reports/unified-9.0.38/raw/platform-acl-node24.log +22 -0
  131. package/docs/reports/unified-9.0.38/raw/platform-nginx-node22.json +21 -0
  132. package/docs/reports/unified-9.0.38/raw/platform-nginx-node24.json +21 -0
  133. package/docs/reports/unified-9.0.38/raw/qa-source-check.log +2 -0
  134. package/docs/reports/unified-9.0.38/raw/release-metadata.log +13 -0
  135. package/docs/reports/unified-9.0.38/raw/sbom.log +8 -0
  136. package/docs/reports/unified-9.0.38/raw/source-shape-node22.log +438 -0
  137. package/docs/reports/unified-9.0.38/raw/source-shape-node24.log +78 -0
  138. package/docs/reports/unified-9.0.38/raw/target-owner-bootstrap-node22.log +509 -0
  139. package/docs/reports/unified-9.0.38/raw/target-owner-bootstrap-node24.log +92 -0
  140. package/docs/reports/unified-9.0.38/raw/typecheck.log +5 -0
  141. package/docs/reports/unified-9.0.38/raw/ui-runtime.log +7 -0
  142. package/docs/start/START_HIER_9.0.37.md +38 -0
  143. package/docs/start/START_HIER_9.0.38.md +21 -0
  144. package/docs/unified/BESTANDSUEBERNAHME_9_0_7.md +2 -0
  145. package/docs/unified/DEVELOPMENT_FINDINGS.md +3 -1
  146. package/docs/unified/SECURITY_CRA.md +6 -0
  147. package/io-package.json +12 -12
  148. package/package.json +8 -4
  149. package/public/eos-migration/index.html +11 -4
  150. package/public/eos-migration/index.js +156 -18
  151. package/release-manifests/unified/build-environment.cdx.json +6 -6
  152. package/release-manifests/unified/files.json +229 -117
  153. package/release-manifests/unified/frontend.cdx.json +6 -6
  154. package/release-manifests/unified/installer.cdx.json +6 -6
  155. package/release-manifests/unified/obsolete-admin-assets.json +166 -0
  156. package/release-manifests/unified/runtime.cdx.json +26 -26
  157. package/release-manifests/unified/validation.json +15 -15
  158. package/tools/eos-release-manifest.cjs +1 -1
  159. package/ui/ems/modules/para14a.js +8 -3
  160. package/ui/ems/modules/storage-control.js +10 -5
  161. package/ui/io-package.json +9 -1
  162. package/ui/lib/notification-mail.js +95 -8
  163. package/ui/main.js +339 -21
  164. package/ui/package.json +1 -1
  165. package/ui/www/app.js +48 -18
  166. package/ui/www/i18n/en.json +15 -0
  167. package/ui/www/i18n/nl.json +15 -0
  168. package/ui/www/licenses/smarthome-markdown-components.json +156 -156
  169. package/ui/www/live-display.js +145 -27
  170. package/ui/www/manifest.webmanifest +2 -2
  171. package/ui/www/storagefarm-dispatch.js +59 -8
  172. package/ui/www/storagefarm-summary.css +3 -1
  173. package/ui/www/storagefarm.html +2 -0
@@ -1,13 +1,13 @@
1
1
  /* Copyright (c) 2026 NexoWatt. Confidential and proprietary. */
2
2
  'use strict';
3
- const { createHash } = require('node:crypto');
3
+ const { createHash, randomUUID } = require('node:crypto');
4
4
  const { join } = require('node:path');
5
5
  const { setTimeout: delay } = require('node:timers/promises');
6
6
  const { performance } = require('node:perf_hooks');
7
- const { isDeepStrictEqual } = require('node:util');
8
7
  const { EosModuleConfigStore } = require('./eosModuleConfigStore');
9
8
  const SOURCES = Object.freeze({ ui: 'nexowatt-ui', devices: 'nexowatt-devices', eebus: 'eebus', backup: 'nexowatt-backup', ocpp: 'ocpp21' });
10
9
  const VERSIONS = Object.freeze({ ui: ['1.0.35', '1.0.36', '1.0.37', '1.0.38'], devices: ['0.5.176'], eebus: ['0.3.0'], backup: ['1.0.10'], ocpp: ['0.4.2', '0.4.3'] });
10
+ const { ownPlaceholder, containsCustomerSettings, cleanVersion, sourceMetadata, sourceIdentity, schemaDriven, validJournalSource, uiShape, devicesShape } = require('./eosLegacySource');
11
11
  const ACL = { owner: 'system.user.admin', ownerGroup: 'system.group.administrator', object: 0x600, state: 0x600 };
12
12
  const HOST_MAX_AGE_MS = 60000;
13
13
  const STARTUP_WINDOW_MS = 45000;
@@ -37,6 +37,7 @@ function copy(value) {
37
37
  }
38
38
  const fingerprint = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
39
39
  const nativeHash = object => fingerprint(object.native);
40
+ const reviewStamp = object => fingerprint([object.common?.enabled, object.common?.host, object.common?.version, record(object.native) ? nativeHash(object) : null]);
40
41
  /**
41
42
  * A later config/metadata edit can postdate a long-disabled UI. For a local
42
43
  * noncompact daemon, js-controller resets sigKill before launch, records its PID,
@@ -115,6 +116,12 @@ class EosLegacyMigration {
115
116
  this.recovery = null;
116
117
  this.commitPromise = null;
117
118
  this.blockedSources = null;
119
+ this.manualRevision = randomUUID();
120
+ this.operation = { state: 'idle', code: '' };
121
+ this.manualPending = null;
122
+ this.manualScopes = null;
123
+ this.manuallyAllowed = null;
124
+ this.uiSaves = 0;
118
125
  }
119
126
  read(operation) {
120
127
  let timer;
@@ -128,6 +135,8 @@ class EosLegacyMigration {
128
135
  const id = scope === 'ems' ? 'ui' : scope;
129
136
  if (id !== undefined && !Object.hasOwn(SOURCES, id))
130
137
  return false;
138
+ if (this.manualScopes)
139
+ return id !== undefined && !this.manualScopes.has(id) && this.manuallyAllowed.has(id);
131
140
  if (this.phase === 'BLOCKED' && this.blockedSources && id !== undefined)
132
141
  return !this.blockedSources.has(id);
133
142
  return ['DISABLED', 'NOT_NEEDED', 'TRANSFERRED', 'COMMITTED'].includes(this.phase);
@@ -155,6 +164,8 @@ class EosLegacyMigration {
155
164
  }
156
165
  }
157
166
  async persist(phase) {
167
+ if (this.manualPending && this.stopped)
168
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
158
169
  this.phase = phase;
159
170
  this.journal = { ...this.journal, v: 1, owner: this.owner.namespace, phase, updatedAt: Date.now() };
160
171
  await this.store.save('migration', this.envelope(this.journal));
@@ -177,11 +188,12 @@ class EosLegacyMigration {
177
188
  try {
178
189
  const license = this.owner.eosLicenseService?.statusView?.();
179
190
  if (license?.valid === true && license.coreEnabled === true)
180
- code = 'EOS_MIGRATION_RESTART_REQUIRED';
191
+ code = this.owner.eosRuntimeControl ? 'EOS_MIGRATION_REVIEW_READY' : 'EOS_MIGRATION_RESTART_REQUIRED';
181
192
  }
182
193
  catch { /* Diagnostic reads never grant permission or expose license internals. */ }
183
194
  }
184
- return { phase: this.phase, code, sources: (this.journal?.sources || []).map(row => ({ id: row.id, source: row.source, namespacePreserved: ['TRANSFERRED', 'COMMITTED'].includes(this.phase) })), updatedAt: this.journal?.updatedAt || null,
195
+ return { phase: this.phase, code, sources: (this.journal?.sources || []).map(row => ({ id: row.id, source: row.source,
196
+ ...Object.fromEntries(['sourceVersion', 'instanceVersion', 'adapterVersion', 'versionCode', 'enabled', 'targetEnabled'].filter(field => Object.hasOwn(row, field)).map(field => [field, row[field]])), namespacePreserved: ['TRANSFERRED', 'COMMITTED'].includes(this.phase) })), updatedAt: this.journal?.updatedAt || null,
185
197
  ...(this.phase === 'BLOCKED' && this.blockedSources && this.journal?.issues?.length ? { issues: this.journal.issues.map(row => ({ id: row.id, source: row.source, code: row.code })) } : {}) };
186
198
  }
187
199
  async loadDestinations() {
@@ -216,6 +228,17 @@ class EosLegacyMigration {
216
228
  }
217
229
  }
218
230
  async saveUi(value) {
231
+ if (this.manualPending && this.phase !== 'TRANSFERRED')
232
+ throw fail('EOS_MIGRATION_BUSY');
233
+ this.uiSaves++;
234
+ try {
235
+ await this.persistUi(value);
236
+ }
237
+ finally {
238
+ this.uiSaves--;
239
+ }
240
+ }
241
+ async persistUi(value) {
219
242
  const config = copy(value);
220
243
  // Host TLS, authentication and licensing are never restored from an old UI.
221
244
  for (const key of ['licenseKey', 'auth', 'port', 'secure', 'certPublic', 'certPrivate', 'certChained', 'bind'])
@@ -234,12 +257,83 @@ class EosLegacyMigration {
234
257
  const alive = await this.reader.getForeignStateAsync(`system.adapter.${source}.alive`);
235
258
  return await hasConfirmedLegacyStop(this.reader, object, alive) && await this.hostFresh(object.common.host);
236
259
  }
237
- matchesSource(object, row) {
238
- return object?.type === 'instance' && object._id === `system.adapter.${row.source}` && record(object.native) && nativeHash(object) === row.nativeHash && object.common?.host === row.host && object.common?.version === row.sourceVersion;
260
+ async checkUiDestination() {
261
+ const defaults = require(join(this.options.baseDir, 'io-package.json')).native.eosUi || {};
262
+ if (containsCustomerSettings(this.owner.config.eosUi || {}, defaults))
263
+ throw fail('EOS_MIGRATION_DESTINATION_CONFIGURED');
264
+ const namespace = this.owner.namespace;
265
+ const state = await this.reader.getForeignStateAsync(namespace + '.installer.configJson');
266
+ if (state && state.val != null && state.val !== '') {
267
+ if (typeof state.val !== 'string' || Buffer.byteLength(state.val) > 512 * 1024)
268
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
269
+ let patch;
270
+ try {
271
+ patch = copy(JSON.parse(state.val));
272
+ }
273
+ catch {
274
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
275
+ }
276
+ if (!record(patch) || containsCustomerSettings(patch, defaults))
277
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
278
+ }
279
+ for (const channel of ['smarthome', 'ems', 'chargepoints', 'energyFlow', 'historie']) {
280
+ const id = namespace + '.' + channel;
281
+ const object = await this.reader.getForeignObjectAsync(id);
282
+ // Historic state objects may be restored without a parent folder.
283
+ if (!object && channel !== 'historie')
284
+ continue;
285
+ if (object && !ownPlaceholder(namespace, channel, object))
286
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
287
+ const prefix = id + '.';
288
+ const result = await this.reader.getObjectViewAsync('system', 'state', { startkey: prefix, endkey: prefix + '\u9999', limit: 513 });
289
+ if (!Array.isArray(result?.rows) || result.rows.length > 512)
290
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
291
+ for (const entry of result.rows) {
292
+ const leaf = entry.value;
293
+ if (leaf?.type !== 'state' || !leaf._id?.startsWith(prefix))
294
+ continue;
295
+ if (channel !== 'historie' || Object.entries(leaf.common?.custom || {}).some(([provider, cfg]) => /^(?:influxdb|sql|history|postgresql)\.\d+$/.test(provider) && record(cfg) &&
296
+ (cfg.enabled === true || typeof cfg.aliasId === 'string' && cfg.aliasId.trim())))
297
+ throw fail('EOS_MIGRATION_DESTINATION_STATES');
298
+ }
299
+ }
300
+ }
301
+ async readUiSource(source, requiredStates) {
302
+ const { readPreservedUiStates } = require(join(this.options.baseDir, 'ui/lib/preserved-ui-config'));
303
+ const states = await readPreservedUiStates(this.reader, source, requiredStates);
304
+ const patch = states.values['installer.configJson'];
305
+ if (patch)
306
+ uiShape(patch, {}, true);
307
+ return states;
308
+ }
309
+ async readSourceMetadata(id, object) {
310
+ const name = SOURCES[id];
311
+ sourceIdentity(name, object, true);
312
+ const metadata = await this.reader.getForeignObjectAsync('system.adapter.' + name);
313
+ if (metadata)
314
+ sourceIdentity(name, metadata, false);
315
+ return sourceMetadata(object, metadata);
239
316
  }
240
- async candidate(id, object) {
241
- if (!VERSIONS[id]?.includes(object.common?.version))
242
- throw fail('EOS_MIGRATION_SOURCE_VERSION');
317
+ async matchesSource(object, row) {
318
+ if (object?.type !== 'instance' || object._id !== 'system.adapter.' + row.source || !record(object.native) ||
319
+ nativeHash(object) !== row.nativeHash || object.common?.host !== row.host)
320
+ return false;
321
+ if (row.schemaVerified !== true)
322
+ return object.common.version === row.sourceVersion;
323
+ if ((object.common.name !== undefined && object.common.name !== SOURCES[row.id]) ||
324
+ cleanVersion(object.common.version) !== row.instanceVersion)
325
+ return false;
326
+ // Only a handover which used the adapter object's version depends on it.
327
+ // Never use a newly installed local version as a witness for the old source.
328
+ if (row.instanceVersion !== null || row.adapterVersion === null)
329
+ return true;
330
+ const metadata = await this.readSourceMetadata(row.id, object);
331
+ return metadata.adapterVersion === row.adapterVersion;
332
+ }
333
+ async candidate(id, object, activateDevices = false, metadata) {
334
+ metadata ??= await this.readSourceMetadata(id, object);
335
+ if (!schemaDriven(id) && !VERSIONS[id]?.includes(metadata.instanceVersion))
336
+ throw fail('EOS_MIGRATION_MODULE_FORMAT_UNVERIFIED');
243
337
  if (!record(object.native) || typeof object.common.enabled !== 'boolean')
244
338
  throw fail('EOS_MIGRATION_SOURCE_UNAVAILABLE');
245
339
  const source = object._id.slice('system.adapter.'.length);
@@ -255,46 +349,44 @@ class EosLegacyMigration {
255
349
  const existing = await this.read(this.store.load(id));
256
350
  if (existing)
257
351
  throw fail('EOS_MIGRATION_DESTINATION_CONFIGURED');
258
- if (id === 'ui') {
259
- const defaults = require(join(this.options.baseDir, 'io-package.json')).native.eosUi || {};
260
- if (!isDeepStrictEqual(this.owner.config.eosUi || {}, defaults))
261
- throw fail('EOS_MIGRATION_DESTINATION_CONFIGURED');
262
- for (const channel of ['smarthome', 'ems', 'chargepoints', 'energyFlow']) {
263
- if (await this.reader.getForeignObjectAsync(`${this.owner.namespace}.${channel}`))
264
- throw fail('EOS_MIGRATION_DESTINATION_STATES');
265
- }
266
- }
352
+ if (id === 'ui')
353
+ await this.checkUiDestination();
267
354
  const config = decryptNative(this.owner, object);
268
355
  let prepared;
356
+ const targetEnabled = object.common.enabled || (id === 'devices' && activateDevices === true);
269
357
  if (id === 'ui') {
270
- const { readPreservedUiStates } = require(join(this.options.baseDir, 'ui/lib/preserved-ui-config'));
271
- const states = await readPreservedUiStates(this.reader, source);
358
+ const uiDefaults = require(join(this.options.baseDir, 'ui/io-package.json')).native;
359
+ uiShape(config, uiDefaults);
360
+ const states = await this.readUiSource(source);
272
361
  prepared = { config: { ...config }, requiredStates: states.requiredStates };
273
362
  for (const key of ['licenseKey', 'auth', 'port', 'secure', 'certPublic', 'certPrivate', 'certChained', 'bind'])
274
363
  delete prepared.config[key];
275
364
  }
276
365
  else {
366
+ if (id === 'devices')
367
+ devicesShape(config);
277
368
  const factory = this.options.factories?.[id] || require(join(this.options.baseDir, 'modules', id, 'index.js'));
278
369
  if (typeof factory.preflightLegacyConfig === 'function')
279
370
  prepared = await factory.preflightLegacyConfig(config, {
280
- owner: this.reader, source, sourceVersion: object.common.version, sourceEnabled: object.common.enabled,
371
+ owner: this.reader, source, sourceVersion: metadata.sourceVersion, sourceEnabled: object.common.enabled,
281
372
  dataDir: join(this.options.dataDir, 'modules', id), eosDataDir: this.options.dataDir, installationDir: this.options.installationDir,
282
373
  });
283
374
  else if (id === 'devices')
284
375
  prepared = { config: factory.validateConfig({ ...config, enabled: object.common.enabled === true }) };
285
376
  else
286
377
  throw fail('EOS_MIGRATION_PREFLIGHT_UNAVAILABLE');
287
- prepared.config.enabled = object.common.enabled === true;
378
+ prepared.config.enabled = targetEnabled;
288
379
  prepared.config = factory.validateConfig(prepared.config);
289
380
  }
290
381
  if (!record(prepared?.config))
291
382
  throw fail('EOS_MIGRATION_CONFIG_INVALID');
292
- const migration = { source, sourceVersion: object.common.version, preserveNamespace: true,
383
+ const migration = { source, sourceVersion: metadata.sourceVersion, preserveNamespace: true,
293
384
  importedAt: new Date().toISOString(), statesCopied: false, mappingsRewritten: false,
294
385
  ...(id === 'ui' ? { requiredStates: prepared.requiredStates } : {}),
295
386
  identityImported: prepared.identityImported === true, omittedFields: id === 'ui' ? ['host transport/authentication/license fields'] : [] };
296
387
  return { id, source, enabled: object.common.enabled === true, nativeHash: nativeHash(object),
297
- host: object.common.host, sourceVersion: object.common.version, envelope: this.envelope(prepared.config, migration),
388
+ host: object.common.host, ...metadata, ...(schemaDriven(id) ? { schemaVerified: true } : {}),
389
+ ...(id === 'devices' && targetEnabled !== object.common.enabled ? { targetEnabled } : {}), envelope: this.envelope(prepared.config, migration),
298
390
  prepareFiles: prepared.prepareFiles };
299
391
  }
300
392
  async rollback(code, stopConfirmed = false) {
@@ -305,7 +397,7 @@ class EosLegacyMigration {
305
397
  // Called before any new runtime exists or after confirmed complete shutdown.
306
398
  for (const row of this.journal.sources || []) {
307
399
  const current = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
308
- if (!this.matchesSource(current, row)) {
400
+ if (!(await this.matchesSource(current, row))) {
309
401
  await this.persist('ROLLBACK_REQUIRED');
310
402
  throw fail('EOS_MIGRATION_SOURCE_CHANGED');
311
403
  }
@@ -315,7 +407,7 @@ class EosLegacyMigration {
315
407
  // Recheck the exact source immediately before each re-enable. The
316
408
  // controller API is not a compare-and-swap transaction; never reuse
317
409
  // a previous loop's source/version/host decision.
318
- if (!this.matchesSource(current, row)) {
410
+ if (!(await this.matchesSource(current, row))) {
319
411
  await this.persist('ROLLBACK_REQUIRED');
320
412
  throw fail('EOS_MIGRATION_SOURCE_CHANGED');
321
413
  }
@@ -331,7 +423,7 @@ class EosLegacyMigration {
331
423
  const checks = await Promise.all((this.journal.sources || []).filter(row => row.enabled).map(async (row) => {
332
424
  const object = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
333
425
  const alive = await this.reader.getForeignStateAsync(`system.adapter.${row.source}.alive`);
334
- return this.matchesSource(object, row) && object.common.enabled === true && alive?.val === true && alive.ack === true && alive.ts >= object.ts && await this.hostFresh(row.host);
426
+ return await this.matchesSource(object, row) && object.common.enabled === true && alive?.val === true && alive.ack === true && alive.ts >= object.ts && await this.hostFresh(row.host);
335
427
  }));
336
428
  if (checks.every(Boolean))
337
429
  break;
@@ -363,6 +455,169 @@ class EosLegacyMigration {
363
455
  throw error;
364
456
  }
365
457
  }
458
+ async readInventory(inspectVersions = false) {
459
+ const observed = [], issues = [], proof = [];
460
+ // Inventory every participating family before releasing any independent scope.
461
+ // OCPP has an explicit manual import and a separate live ownership check.
462
+ for (const [id, name] of Object.entries(SOURCES)) {
463
+ if (id === 'ocpp')
464
+ continue;
465
+ const found = await this.reader.getObjectViewAsync('system', 'instance', { startkey: `system.adapter.${name}.`, endkey: `system.adapter.${name}.\u9999` });
466
+ if (!Array.isArray(found?.rows) || found.rows.length > 64)
467
+ throw fail('EOS_MIGRATION_INVENTORY');
468
+ const seen = new Set();
469
+ for (const row of found.rows) {
470
+ const sourceId = row.value?._id;
471
+ if (row.value?.type !== 'instance' || !new RegExp(`^system\\.adapter\\.${name}\\.\\d+$`).test(sourceId || '') || seen.has(sourceId))
472
+ throw fail('EOS_MIGRATION_INVENTORY');
473
+ seen.add(sourceId);
474
+ proof.push([sourceId, reviewStamp(row.value)]);
475
+ const source = sourceId.slice('system.adapter.'.length);
476
+ let metadata = sourceMetadata(row.value, null);
477
+ if (inspectVersions) {
478
+ try {
479
+ metadata = await this.readSourceMetadata(id, row.value);
480
+ }
481
+ catch (error) {
482
+ issues.push({ id, source, code: safeCode(error) });
483
+ }
484
+ }
485
+ observed.push({ id, source, ...metadata });
486
+ if (found.rows.length > 1)
487
+ issues.push({ id, source, code: 'EOS_MIGRATION_AMBIGUOUS' });
488
+ }
489
+ }
490
+ proof.sort((a, b) => a[0].localeCompare(b[0]));
491
+ return { observed, issues, stamps: new Map(proof), signature: fingerprint(proof) };
492
+ }
493
+ async manualReview() {
494
+ const view = this.manualView();
495
+ if (!view.canStart)
496
+ return this.status();
497
+ if (this.reviewPending)
498
+ return this.reviewPending;
499
+ this.reviewPending = this.readInventory(true).then(inventory => {
500
+ if (this.manualPending || this.stopped || !this.manualView().canStart)
501
+ return this.status();
502
+ if (this.review?.signature !== inventory.signature)
503
+ this.manualRevision = randomUUID();
504
+ this.review = inventory;
505
+ const status = this.status();
506
+ const sources = inventory.observed.map(row => ({ ...row, namespacePreserved: false }));
507
+ const issues = [...inventory.issues];
508
+ for (const prior of status.issues || []) {
509
+ if (sources.some(row => row.source === prior.source) && !issues.some(row => row.source === prior.source && row.code === prior.code))
510
+ issues.push(prior);
511
+ }
512
+ return { ...status, sources, issues };
513
+ }).finally(() => { this.reviewPending = null; });
514
+ return this.reviewPending;
515
+ }
516
+ manualView() {
517
+ const license = this.owner.eosLicenseService?.statusView?.();
518
+ const selectable = !this.stopped && !this.startupBlocked && !this.manualPending &&
519
+ ['BLOCKED', 'NOT_NEEDED', 'DISABLED', 'LICENSE_REQUIRED'].includes(this.phase);
520
+ const canStart = selectable && license?.valid === true && license.coreEnabled === true;
521
+ return { canStart, canActivateDevices: canStart && (this.review?.observed || []).some(row => row.id === 'devices' && row.enabled === false),
522
+ revision: this.manualRevision, operation: { ...this.operation } };
523
+ }
524
+ requestManual(activateDevices, revision, confirmAuthority) {
525
+ const view = this.manualView();
526
+ if (this.manualPending || this.owner.eosRuntimeControl?.pending || this.owner.eosModuleHost?.configurationSavePromise || this.owner.eosModuleHost?.mutation || this.uiSaves) {
527
+ throw fail('EOS_MIGRATION_BUSY');
528
+ }
529
+ if (!view.canStart || !this.owner.eosRuntimeControl || !this.owner.eosModuleHost || !this.owner.eosHostedRuntime)
530
+ throw fail('EOS_MIGRATION_ACTION_UNAVAILABLE');
531
+ if (!this.review || typeof revision !== 'string' || revision !== this.manualRevision)
532
+ throw fail('EOS_MIGRATION_REVISION_CONFLICT');
533
+ if (typeof activateDevices !== 'boolean' || (activateDevices && !view.canActivateDevices))
534
+ throw fail('EOS_MIGRATION_REQUEST_INVALID');
535
+ this.manualRevision = randomUUID();
536
+ this.operation = { state: 'running', code: '' };
537
+ this.manualPending = Promise.resolve().then(async () => {
538
+ await this.prepare({ activateDevices, signature: this.review.signature, confirmAuthority });
539
+ if (this.phase === 'TRANSFERRED') {
540
+ await this.releaseLiveTargets(true);
541
+ await this.verifyRuntime();
542
+ }
543
+ else if (this.manualScopes)
544
+ await this.releaseLiveTargets(false);
545
+ if (this.stopped)
546
+ return;
547
+ const ok = ['COMMITTED', 'NOT_NEEDED'].includes(this.phase);
548
+ this.operation = { state: ok ? 'complete' : 'failed', code: ok ? '' : this.status().code || 'EOS_MIGRATION_FAILED' };
549
+ }).catch(async (error) => {
550
+ const code = safeCode(error);
551
+ if (this.phase === 'TRANSFERRED')
552
+ await this.failStartup(code);
553
+ // A failed drain must not restore write authority. Before any journal was
554
+ // created, all old sources are still intact; the affected targets stay gated.
555
+ if (this.manualScopes) {
556
+ const heldIds = [...this.manualScopes].filter(id => id !== 'ui');
557
+ this.blockedSources = new Set(this.manualScopes);
558
+ if (!this.journal?.phase && !this.stopped) {
559
+ this.phase = 'BLOCKED';
560
+ this.journal = { sources: this.journal?.sources || [], code };
561
+ }
562
+ this.manualScopes = null;
563
+ this.manuallyAllowed = null;
564
+ await this.owner.eosModuleHost?.releaseMigrationModules(heldIds, false).catch(() => { });
565
+ }
566
+ if (code === 'EOS_MIGRATION_JOURNAL_PRESENT')
567
+ this.block(code);
568
+ this.operation = { state: 'failed', code };
569
+ this.owner.log.warn(`EOS_MIGRATION_MANUAL_FAILED: ${code}`);
570
+ if (!this.stopped)
571
+ await this.publish();
572
+ }).finally(() => { this.manualPending = null; this.review = null; });
573
+ }
574
+ async confirmManualAuthority(manual, candidates) {
575
+ const permitted = await Promise.resolve().then(() => manual.confirmAuthority()).catch(() => false);
576
+ if (permitted !== true || this.stopped)
577
+ throw fail('EOS_MIGRATION_AUTHORIZATION_CHANGED');
578
+ const license = this.owner.eosLicenseService?.statusView?.();
579
+ if (license?.valid !== true || license.coreEnabled !== true)
580
+ throw fail('EOS_MIGRATION_LICENSE_REQUIRED');
581
+ if (candidates.some(row => row.id !== 'ui' && this.owner.eosLicenseService.allowsEmbeddedModule?.(row.id) !== true)) {
582
+ throw fail('EOS_MIGRATION_MODULE_LICENSE_REQUIRED');
583
+ }
584
+ }
585
+ async holdLiveTargets(candidates) {
586
+ const owner = this.owner;
587
+ const ids = candidates.map(row => row.id);
588
+ if (owner.eosRuntimeControl.pending || owner.eosModuleHost.configurationSavePromise || owner.eosModuleHost.mutation || this.uiSaves || this.stopped)
589
+ throw fail('EOS_MIGRATION_BUSY');
590
+ this.manuallyAllowed = new Set(Object.keys(SOURCES).filter(id => this.allowsStartup(id)));
591
+ this.manualScopes = new Set(ids);
592
+ const tasks = [owner.eosModuleHost.holdMigrationModules(ids.filter(id => id !== 'ui'))];
593
+ if (this.manualScopes.has('ui'))
594
+ tasks.push(owner.eosHostedRuntime.pause(), owner.eosHostedRuntime.pauseEms());
595
+ const settled = await Promise.allSettled(tasks);
596
+ if (settled.some(result => result.status === 'rejected') || this.stopped)
597
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
598
+ }
599
+ async releaseLiveTargets(transferred) {
600
+ if (!this.manualScopes || this.stopped)
601
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
602
+ const owner = this.owner;
603
+ const ids = [...this.manualScopes];
604
+ await owner.eosModuleHost.releaseMigrationModules(ids.filter(id => id !== 'ui'), transferred);
605
+ this.manualScopes = null;
606
+ this.manuallyAllowed = null;
607
+ if (!transferred)
608
+ return;
609
+ await owner.eosOwnership.refresh();
610
+ if (ids.includes('ui')) {
611
+ const jobs = [];
612
+ if (owner.eosRuntimeControl.isEnabled('ui'))
613
+ jobs.push(owner.eosHostedRuntime.resume());
614
+ if (owner.eosRuntimeControl.isEnabled('ems'))
615
+ jobs.push(owner.eosHostedRuntime.resumeEms());
616
+ await Promise.all(jobs);
617
+ }
618
+ await owner.eosModuleHost.start();
619
+ await owner.eosModuleHost.reconcile();
620
+ }
366
621
  async checkLegacyRpc(candidates) {
367
622
  const sources = new Set(candidates.map(row => row.source));
368
623
  const inventory = await this.reader.getObjectViewAsync('system', 'instance', { startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' });
@@ -402,14 +657,18 @@ class EosLegacyMigration {
402
657
  }
403
658
  return referenced;
404
659
  }
405
- async prepare() {
406
- await this.loadDestinations();
660
+ async prepare(manual = null) {
661
+ if (!manual)
662
+ await this.loadDestinations();
407
663
  const prior = await this.read(this.store.load('migration'));
408
664
  if (prior) {
665
+ // Only adapter startup may recover a journal that predates this process.
666
+ if (manual)
667
+ throw fail('EOS_MIGRATION_JOURNAL_PRESENT');
409
668
  const journal = this.decode(prior);
410
669
  if (journal.v !== 1 || journal.owner !== this.owner.namespace || !['PREPARED', 'STOPPING', 'TRANSFERRED', 'COMMITTED', 'ROLLING_BACK', 'ROLLBACK_REQUIRED', 'ROLLED_BACK'].includes(journal.phase) ||
411
670
  (journal.runtimeStopConfirmed !== undefined && typeof journal.runtimeStopConfirmed !== 'boolean') ||
412
- !Array.isArray(journal.sources) || journal.sources.length > Object.keys(SOURCES).length || new Set(journal.sources.map(row => row.id)).size !== journal.sources.length || journal.sources.some(row => !SOURCES[row.id] || !new RegExp(`^${SOURCES[row.id]}\\.\\d+$`).test(row.source) || !/^[a-f0-9]{64}$/.test(row.nativeHash) || typeof row.enabled !== 'boolean' || typeof row.host !== 'string' || !row.host || row.host.length > 255 || !VERSIONS[row.id].includes(row.sourceVersion)))
671
+ !Array.isArray(journal.sources) || journal.sources.length > Object.keys(SOURCES).length || new Set(journal.sources.map(row => row?.id)).size !== journal.sources.length || journal.sources.some(row => !validJournalSource(row, SOURCES, VERSIONS)))
413
672
  throw fail('EOS_MIGRATION_JOURNAL_INVALID');
414
673
  this.journal = journal;
415
674
  this.phase = journal.phase;
@@ -431,7 +690,7 @@ class EosLegacyMigration {
431
690
  await this.publish();
432
691
  return;
433
692
  }
434
- if (this.owner.config.eosAutoMigrate === false) {
693
+ if (!manual && this.owner.config.eosAutoMigrate === false) {
435
694
  this.phase = 'DISABLED';
436
695
  return;
437
696
  }
@@ -449,27 +708,14 @@ class EosLegacyMigration {
449
708
  const observed = [];
450
709
  const issues = [];
451
710
  try {
452
- // Inventory every participating family before releasing any independent scope.
453
- // OCPP has an explicit manual import and a separate live ownership check.
454
- for (const [id, name] of Object.entries(SOURCES)) {
455
- if (id === 'ocpp')
456
- continue;
457
- const found = await this.reader.getObjectViewAsync('system', 'instance', { startkey: `system.adapter.${name}.`, endkey: `system.adapter.${name}.\u9999` });
458
- if (!Array.isArray(found?.rows) || found.rows.length > 64)
459
- throw fail('EOS_MIGRATION_INVENTORY');
460
- const seen = new Set();
461
- for (const row of found.rows) {
462
- const sourceId = row.value?._id;
463
- if (row.value?.type !== 'instance' || !new RegExp(`^system\\.adapter\\.${name}\\.\\d+$`).test(sourceId || '') || seen.has(sourceId))
464
- throw fail('EOS_MIGRATION_INVENTORY');
465
- seen.add(sourceId);
466
- const source = sourceId.slice('system.adapter.'.length);
467
- observed.push({ id, source });
468
- if (found.rows.length > 1)
469
- issues.push({ id, source, code: 'EOS_MIGRATION_AMBIGUOUS' });
470
- }
471
- }
711
+ const inventory = await this.readInventory();
712
+ observed.push(...inventory.observed);
713
+ issues.push(...inventory.issues);
714
+ if (manual && inventory.signature !== manual.signature)
715
+ throw fail('EOS_MIGRATION_INVENTORY_CHANGED');
472
716
  if (!observed.length) {
717
+ this.journal = null;
718
+ this.blockedSources = null;
473
719
  this.phase = 'NOT_NEEDED';
474
720
  await this.publish();
475
721
  return;
@@ -488,9 +734,14 @@ class EosLegacyMigration {
488
734
  const object = await this.reader.getForeignObjectAsync(sourceId);
489
735
  if (object?.type !== 'instance' || object._id !== sourceId)
490
736
  throw fail('EOS_MIGRATION_SOURCE_UNAVAILABLE');
491
- candidates.push(await this.candidate(row.id, object));
737
+ if (manual && inventory.stamps.get(sourceId) !== reviewStamp(object))
738
+ throw fail('EOS_MIGRATION_INVENTORY_CHANGED');
739
+ Object.assign(row, await this.readSourceMetadata(row.id, object));
740
+ candidates.push(await this.candidate(row.id, object, manual?.activateDevices === true, row));
492
741
  }
493
742
  catch (error) {
743
+ if (manual && error?.code === 'EOS_MIGRATION_INVENTORY_CHANGED')
744
+ throw error;
494
745
  issues.push({ ...row, code: safeCode(error) });
495
746
  }
496
747
  }
@@ -506,20 +757,49 @@ class EosLegacyMigration {
506
757
  }
507
758
  }
508
759
  catch (error) {
760
+ if (manual && error?.code === 'EOS_MIGRATION_INVENTORY_CHANGED')
761
+ throw error;
762
+ this.blockedSources = null;
509
763
  this.phase = 'BLOCKED';
510
764
  this.journal = { sources: observed, code: safeCode(error) };
511
765
  this.owner.log.warn(`EOS_MIGRATION_BLOCKED: ${safeCode(error)}; existing adapters remain unchanged`);
512
766
  await this.publish();
513
767
  return;
514
768
  }
515
- this.journal = { sources: candidates.map(({ id, source, enabled, nativeHash: hash, sourceVersion, host }) => ({ id, source, enabled, nativeHash: hash, sourceVersion, host })) };
769
+ if (manual) {
770
+ await this.confirmManualAuthority(manual, candidates);
771
+ await this.holdLiveTargets(candidates);
772
+ // Prove all candidates again after fencing the new processes. A slow
773
+ // clicked form or a finishing config save cannot bless a replaced source.
774
+ for (const row of candidates) {
775
+ if (manual && this.stopped)
776
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
777
+ const current = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
778
+ if (!(await this.matchesSource(current, row)) || current.common.enabled !== row.enabled)
779
+ throw fail('EOS_MIGRATION_SOURCE_CHANGED');
780
+ if (await this.read(this.store.load(row.id)))
781
+ throw fail('EOS_MIGRATION_DESTINATION_CONFIGURED');
782
+ if (row.id === 'ui')
783
+ await this.checkUiDestination();
784
+ }
785
+ await this.confirmManualAuthority(manual, candidates);
786
+ }
787
+ this.journal = { sources: candidates.map(({ envelope: _envelope, prepareFiles: _files, ...binding }) => binding) };
516
788
  await this.persist('PREPARED');
517
789
  try {
518
790
  await this.persist('STOPPING');
519
791
  for (const row of candidates) {
792
+ if (manual && this.stopped)
793
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
520
794
  const current = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
521
- if (!this.matchesSource(current, row) || current.common.enabled !== row.enabled)
795
+ if (!(await this.matchesSource(current, row)) || current.common.enabled !== row.enabled)
522
796
  throw fail('EOS_MIGRATION_SOURCE_CHANGED');
797
+ if (manual && this.stopped)
798
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
799
+ if (row.id === 'ui') {
800
+ await this.checkUiDestination();
801
+ await this.readUiSource(row.source, row.envelope.migration.requiredStates);
802
+ }
523
803
  if (row.enabled)
524
804
  await this.owner.extendForeignObjectAsync(current._id, { common: { enabled: false } });
525
805
  }
@@ -530,24 +810,32 @@ class EosLegacyMigration {
530
810
  await delay(100);
531
811
  }
532
812
  for (const row of candidates) {
813
+ if (manual && this.stopped)
814
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
533
815
  const current = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
534
- if (!this.matchesSource(current, row) || current.common.enabled !== false)
816
+ if (!(await this.matchesSource(current, row)) || current.common.enabled !== false)
535
817
  throw fail('EOS_MIGRATION_SOURCE_CHANGED');
536
818
  if (row.id === 'ui') {
819
+ await this.checkUiDestination();
537
820
  // Recheck after confirmed stop: an in-flight old save may have
538
821
  // changed the JSON after preflight. Never activate partial data.
539
- const { readPreservedUiStates } = require(join(this.options.baseDir, 'ui/lib/preserved-ui-config'));
540
- const states = await readPreservedUiStates(this.reader, row.source, row.envelope.migration.requiredStates);
822
+ const states = await this.readUiSource(row.source, row.envelope.migration.requiredStates);
541
823
  row.envelope.migration.requiredStates = states.requiredStates;
542
824
  }
825
+ if (manual && this.stopped)
826
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
543
827
  await row.prepareFiles?.();
828
+ if (manual && this.stopped)
829
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
544
830
  await this.store.save(row.id, row.envelope);
545
831
  }
546
832
  // Recheck after file and asynchronous state reads, before granting write
547
833
  // authority to the new runtimes. No disabled source gets enabled here.
548
834
  for (const row of candidates) {
835
+ if (manual && this.stopped)
836
+ throw fail('EOS_MIGRATION_STOP_UNCONFIRMED');
549
837
  const current = await this.reader.getForeignObjectAsync(`system.adapter.${row.source}`);
550
- if (!this.matchesSource(current, row) || !(await this.stoppedSource(row.source)))
838
+ if (!(await this.matchesSource(current, row)) || !(await this.stoppedSource(row.source)))
551
839
  throw fail('EOS_MIGRATION_SOURCE_CHANGED');
552
840
  }
553
841
  await this.persist('TRANSFERRED');
@@ -555,6 +843,8 @@ class EosLegacyMigration {
555
843
  this.owner.log.info('EOS_MIGRATION_TRANSFERRED: existing namespaces and settings retained; startup verification pending');
556
844
  }
557
845
  catch (error) {
846
+ if (manual && this.stopped)
847
+ throw error; // journal recovery belongs to the next owner
558
848
  // prepare() has not allowed the caller to construct/start any new
559
849
  // runtime yet; only configuration transfer has been attempted.
560
850
  await this.rollback(safeCode(error), true);
@@ -623,7 +913,7 @@ class EosLegacyMigration {
623
913
  }
624
914
  }
625
915
  async readiness(rows, deadline) {
626
- const modules = await this.startupRead(Promise.all(rows.filter(row => row.id !== 'ui' && row.enabled)
916
+ const modules = await this.startupRead(Promise.all(rows.filter(row => row.id !== 'ui' && (row.targetEnabled ?? row.enabled))
627
917
  .map(row => this.owner.eosModuleHost?.status(row.id))), deadline);
628
918
  // Read these live values only after the asynchronous module snapshot.
629
919
  const ui = this.owner.eosHostedRuntime?.status?.();
@@ -672,7 +962,7 @@ class EosLegacyMigration {
672
962
  ? Math.min(configuredWindow, STARTUP_WINDOW_MS) : STARTUP_WINDOW_MS;
673
963
  const startedAt = performance.now();
674
964
  let deadline = startedAt + startupWindow;
675
- const hasDevices = this.journal.sources.some(row => row.id === 'devices' && row.enabled);
965
+ const hasDevices = this.journal.sources.some(row => row.id === 'devices' && (row.targetEnabled ?? row.enabled));
676
966
  const absoluteDeadline = deadline + (hasDevices ? DEVICES_PROGRESS_ALLOWANCE_MS : 0);
677
967
  let completedObjects = 0;
678
968
  while (!this.stopped && !this.startupBlocked && performance.now() < deadline) {
@@ -720,6 +1010,7 @@ class EosLegacyMigration {
720
1010
  return this.monitor;
721
1011
  }
722
1012
  stop() { this.stopped = true; }
1013
+ async whenManualIdle() { await this.manualPending; }
723
1014
  }
724
1015
  function safeCode(error) { return typeof error?.code === 'string' && /^[A-Z0-9_]{1,80}$/.test(error.code) ? error.code : 'EOS_MIGRATION_FAILED'; }
725
1016
  module.exports = { EosLegacyMigration, decryptNative, hasConfirmedLegacyStop };