@camstack/server 1.2.759 → 1.2.761

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 (96) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/agent/main.js +1 -0
  3. package/dist/api/trpc/generated-cap-mounts.js +1 -0
  4. package/dist/api/trpc/generated-cap-routers.js +27 -12
  5. package/dist/core/addon/addon-registry.service.js +1 -0
  6. package/package.json +16 -7
  7. package/system/dist/addon-runner.js +1 -0
  8. package/system/dist/addon-runner.mjs +1 -0
  9. package/system/dist/{agent-https-Bafgj4ni.mjs → agent-https-D1B_fvIx.mjs} +1 -1
  10. package/system/dist/{agent-https-DXDFMq90.js → agent-https-YFeT_9qF.js} +1 -1
  11. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  12. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  13. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  14. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  15. package/system/dist/builtins/alerts/alerts.addon.js +7 -1
  16. package/system/dist/builtins/alerts/alerts.addon.mjs +7 -1
  17. package/system/dist/builtins/autotrack/index.js +1 -1
  18. package/system/dist/builtins/autotrack/index.mjs +1 -1
  19. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  20. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  21. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  22. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  23. package/system/dist/builtins/camera-grid/index.js +1 -1
  24. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  25. package/system/dist/builtins/composer/composer.addon.js +3 -3
  26. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  27. package/system/dist/builtins/console-logging/index.js +1 -1
  28. package/system/dist/builtins/console-logging/index.mjs +1 -1
  29. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  30. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  31. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  32. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  33. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  34. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  35. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  36. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  37. package/system/dist/builtins/keychain/index.js +3 -3
  38. package/system/dist/builtins/keychain/index.mjs +3 -3
  39. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  40. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  41. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  42. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  43. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  44. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  45. package/system/dist/builtins/loki-logging/index.js +1 -1
  46. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  47. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  48. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  49. package/system/dist/builtins/platform-probe/index.js +1 -1
  50. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  51. package/system/dist/builtins/record-entries/index.js +1 -1
  52. package/system/dist/builtins/record-entries/index.mjs +1 -1
  53. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  54. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  55. package/system/dist/builtins/snapshot/index.js +1 -1
  56. package/system/dist/builtins/snapshot/index.mjs +1 -1
  57. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  58. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  59. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  60. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  61. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
  62. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
  63. package/system/dist/builtins/storage-orchestrator/location-store.d.ts +8 -0
  64. package/system/dist/builtins/storage-orchestrator/migrations/index.d.ts +10 -0
  65. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +22 -0
  66. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +260 -19
  67. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +260 -19
  68. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +54 -21
  69. package/system/dist/builtins/storage-orchestrator/storage-writability-monitor.d.ts +36 -0
  70. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  71. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  72. package/system/dist/builtins/winston-logging/index.js +1 -1
  73. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  74. package/system/dist/{capture-engine-WttiBMdu.mjs → capture-engine-C6myWpTr.mjs} +1 -1
  75. package/system/dist/{capture-engine-CInzGJAh.js → capture-engine-JrgzDAeI.js} +1 -1
  76. package/system/dist/{composition-sources-DQHH_g-A.js → composition-sources-53ryTB8m.js} +1 -1
  77. package/system/dist/{composition-sources-A4LM38lT.mjs → composition-sources-BJleLIBr.mjs} +1 -1
  78. package/system/dist/{constants-BAG_5cF6.mjs → constants-DW74hDp7.mjs} +1 -1
  79. package/system/dist/{constants-hAbcGGDs.js → constants-nY2QXQK5.js} +1 -1
  80. package/system/dist/{device-ca-CCIaKs70.mjs → device-ca-BUTX2AaQ.mjs} +1 -1
  81. package/system/dist/{device-ca-lLGjDsFP.js → device-ca-CzGQ4dJn.js} +1 -1
  82. package/system/dist/{dist-BIJD_nvZ.mjs → dist-Cu6VwGZZ.mjs} +50 -11
  83. package/system/dist/{dist-CiwLP3-C.js → dist-Cyida7ne.js} +50 -11
  84. package/system/dist/file-host-worker.js +1 -1
  85. package/system/dist/file-host-worker.mjs +1 -1
  86. package/system/dist/{hub-mdns-ciao-CLlDILdC.js → hub-mdns-ciao-CXAFrkV0.js} +2 -2
  87. package/system/dist/{hub-mdns-ciao-CXsUIWw_.mjs → hub-mdns-ciao-scMSbV7j.mjs} +2 -2
  88. package/system/dist/index.js +36 -7
  89. package/system/dist/index.mjs +36 -7
  90. package/system/dist/kernel/addon-loader.d.ts +13 -1
  91. package/system/dist/kernel/moleculer/addon-context-factory.d.ts +3 -1
  92. package/system/dist/{restore-archive-Dx9r-ndj.mjs → restore-archive-jWL53_V-.mjs} +1 -1
  93. package/system/dist/{restore-archive-CN1BA_o6.js → restore-archive-pn_Y6UG7.js} +1 -1
  94. package/system/dist/{wal-maintenance-B7wMSexc.mjs → wal-maintenance-By_dPC7l.mjs} +0 -0
  95. package/system/dist/{wal-maintenance-CecPWej8.js → wal-maintenance-CODI9DuS.js} +0 -0
  96. package/system/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { Fs as isSecretMarker, Ha as withLocationMode, Ho as REDACTED_SECRET, Hr as isLocationEnabled, Hs as normalizeNodeId, Or as gbToBytes, Qs as secretTreeFromPaths, Qt as StorageMigrationJobSchema, Ws as parseJsonObject, Xr as legacyModeOf, Xs as resolveSecretMarkers, Xt as StorageLocationModeSchema, Yt as StorageCleanupJobSchema, Zi as resolveLocationMode, Zt as StorageLocationTypeSchema, ba as storageCapability, dc as EventCategory, gr as evictionPolicyOfLocation, ic as transformSecretWrite, mi as modeMayWrite, oi as mayReadLocation, si as mayWriteToLocation, ua as settingsStoreCapability, us as collectSecretConfigKeys, wo as BaseAddon, xa as storageMigrationCapability, ys as defineRecordKinds, yt as LegacyStorageLocationDefaultSchema } from "../../dist-BIJD_nvZ.mjs";
1
+ import { Fs as isSecretMarker, Ha as withLocationMode, Ho as REDACTED_SECRET, Hr as isLocationEnabled, Hs as normalizeNodeId, Or as gbToBytes, Qs as secretTreeFromPaths, Qt as StorageMigrationJobSchema, Ws as parseJsonObject, Xr as legacyModeOf, Xs as resolveSecretMarkers, Xt as StorageLocationModeSchema, Yt as StorageCleanupJobSchema, Zi as resolveLocationMode, Zt as StorageLocationTypeSchema, ba as storageCapability, dc as EventCategory, gr as evictionPolicyOfLocation, gs as defineAddonMigrations, ic as transformSecretWrite, mi as modeMayWrite, oi as mayReadLocation, si as mayWriteToLocation, ua as settingsStoreCapability, us as collectSecretConfigKeys, wo as BaseAddon, xa as storageMigrationCapability, ys as defineRecordKinds, yt as LegacyStorageLocationDefaultSchema } from "../../dist-Cu6VwGZZ.mjs";
2
2
  import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
3
3
  import { z } from "zod";
4
4
  import { randomUUID } from "node:crypto";
@@ -212,6 +212,11 @@ var SqliteLocationStore = class {
212
212
  data: { seededAt: Date.now() }
213
213
  });
214
214
  }
215
+ async unmarkTypeSeeded(type) {
216
+ const kind = this.seedMarkersKind;
217
+ if (kind === null) return;
218
+ await kind.delete(type);
219
+ }
215
220
  static recordStoresOf(records) {
216
221
  return records.kind(storageOrchestratorRecordKinds.locations);
217
222
  }
@@ -1251,6 +1256,29 @@ function buildStorageLocationRegistry(perAddon) {
1251
1256
  }
1252
1257
  };
1253
1258
  }
1259
+ /** The `storage-orchestrator` catalogue (D987): offered to the engine once the seed state is known. */
1260
+ var ADDON_MIGRATIONS = [{
1261
+ meta: {
1262
+ id: "storage-orchestrator/2026-11-04-reseed-pruned-defaults",
1263
+ owner: "storage-orchestrator",
1264
+ level: "addon-state",
1265
+ seq: 1,
1266
+ dependsOn: [],
1267
+ store: "settings",
1268
+ scope: "cluster",
1269
+ onFailure: "tolerate",
1270
+ bodyKind: "procedure",
1271
+ description: "Re-create the default storage location of a declared type whose seed marker survived the 2026-11-01 prune with no rows left",
1272
+ fixtureMark: "a type that still has its row and its seed marker, which the repair must not touch"
1273
+ },
1274
+ procedure: async (ports) => {
1275
+ const types = ports.reseed();
1276
+ return {
1277
+ outcome: types.length > 0 ? "done" : "already-done",
1278
+ summary: { types: [...types] }
1279
+ };
1280
+ }
1281
+ }];
1254
1282
  //#endregion
1255
1283
  //#region src/builtins/storage-orchestrator/location-occupancy.ts
1256
1284
  /**
@@ -2798,6 +2826,25 @@ var StorageOrchestratorService = class {
2798
2826
  } });
2799
2827
  });
2800
2828
  }
2829
+ forgetSeeded(type) {
2830
+ const seeded = this.seededTypes;
2831
+ const store = this.locationStore;
2832
+ if (seeded === null || !seeded.delete(type) || !store?.unmarkTypeSeeded) return;
2833
+ store.unmarkTypeSeeded(type).catch((err) => {
2834
+ this.logger.error("storage-orchestrator: forgetting the seed memory failed", { meta: {
2835
+ type,
2836
+ error: err instanceof Error ? err.message : String(err)
2837
+ } });
2838
+ });
2839
+ }
2840
+ /**
2841
+ * Do the rows this service holds answer "which locations exist"? False while
2842
+ * a store that must answer has not (not wired, adoption pending, read
2843
+ * failed): an empty map then means NOT YET KNOWN, never "none" (D315).
2844
+ */
2845
+ locationsAuthoritative() {
2846
+ return !(this.storeRequiredForSeed && this.locationStore === null);
2847
+ }
2801
2848
  /** True once a persistence store is wired (constructor or {@link attachStore}). */
2802
2849
  hasStore() {
2803
2850
  return this.locationStore !== null;
@@ -3242,39 +3289,71 @@ var StorageOrchestratorService = class {
3242
3289
  }
3243
3290
  }
3244
3291
  /**
3245
- * Remove seed-shaped locations (`<type>:default`) whose type is no longer
3246
- * declared by any addon (stale defaults from a removed location type).
3292
+ * Remove seed-shaped locations (`<type>:default`) whose type no INSTALLED
3293
+ * package declares any more (stale defaults from a removed location type).
3247
3294
  * Operator-added locations of an undeclared type are KEPT but warned.
3248
3295
  *
3296
+ * "Undeclared" means undeclared by every installed package, not by every
3297
+ * LOADED addon. The registry is built from the addons that loaded; an addon
3298
+ * whose load failed (`Cannot find module` after a bad deploy) declares the
3299
+ * same types it always did, and "not known right now" is not "removed"
3300
+ * (D49, D315). `unloaded` is that other half — every installed declarer
3301
+ * that is not loaded. A type one of them declares is kept, by name in the
3302
+ * log; a package that could not even be read has unknown declarations, so
3303
+ * the whole pass is skipped (a read that would DESTROY needs an answer).
3304
+ *
3305
+ * A pruned type also forgets that it was seeded: were it declared again, it
3306
+ * seeds again, while an operator's own delete (which never reaches here)
3307
+ * keeps sticking.
3308
+ *
3249
3309
  * FAIL-SAFE: if the registry is EMPTY (no addon declared any location), we
3250
3310
  * refuse to prune anything. An empty registry almost always means
3251
3311
  * declarations failed to load (boot ordering, a stale install) — pruning
3252
3312
  * "everything undeclared" in that state would wipe every seeded location
3253
3313
  * (data/logs/recordings/…). Better to keep stale rows than destroy live ones.
3254
3314
  */
3255
- pruneUndeclaredSystemLocations() {
3315
+ pruneUndeclaredSystemLocations(unloaded = []) {
3256
3316
  if (!this.registry) return;
3257
3317
  if (this.registry.list().length === 0) {
3258
3318
  this.logger.warn("storage-orchestrator: skipping prune — no location declarations loaded (fail-safe)");
3259
3319
  return;
3260
3320
  }
3321
+ const unreadable = unloaded.filter((d) => d.addonId === null);
3322
+ if (unreadable.length > 0) {
3323
+ this.logger.warn("storage-orchestrator: skipping prune — an installed package could not be read, so what it declares is unknown", { meta: { packages: unreadable.map((d) => d.packageName) } });
3324
+ return;
3325
+ }
3261
3326
  for (const [id, loc] of Array.from(this.locations)) {
3262
3327
  if (this.registry.cardinalityOf(loc.type) !== null) continue;
3263
- if (loc.id === `${loc.type}:default`) {
3264
- this.locations.delete(id);
3265
- if (this.locationStore) this.locationStore.delete(id).catch((err) => {
3266
- this.logger.error("storage-orchestrator: prune persistence failed", { meta: {
3267
- id,
3268
- error: err instanceof Error ? err.message : String(err)
3269
- } });
3270
- });
3271
- this.logger.info("storage-orchestrator: pruned stale seeded location", { meta: {
3328
+ if (!(loc.id === `${loc.type}:default`)) {
3329
+ this.logger.warn("storage-orchestrator: location of undeclared type kept (operator-owned)", { meta: {
3272
3330
  id,
3273
3331
  type: loc.type
3274
3332
  } });
3275
- } else this.logger.warn("storage-orchestrator: location of undeclared type kept (operator-owned)", { meta: {
3333
+ continue;
3334
+ }
3335
+ const holders = unloaded.filter((d) => d.declarations.some((x) => x.id === loc.type));
3336
+ if (holders.length > 0) {
3337
+ this.logger.info("storage-orchestrator: prune skipped — type declared by an installed addon that is not loaded", { meta: {
3338
+ id,
3339
+ type: loc.type,
3340
+ addons: holders.map((d) => d.addonId),
3341
+ reason: "declaring-addon-unloaded"
3342
+ } });
3343
+ continue;
3344
+ }
3345
+ this.locations.delete(id);
3346
+ this.forgetSeeded(loc.type);
3347
+ if (this.locationStore) this.locationStore.delete(id).catch((err) => {
3348
+ this.logger.error("storage-orchestrator: prune persistence failed", { meta: {
3349
+ id,
3350
+ error: err instanceof Error ? err.message : String(err)
3351
+ } });
3352
+ });
3353
+ this.logger.info("storage-orchestrator: pruned stale seeded location", { meta: {
3276
3354
  id,
3277
- type: loc.type
3355
+ type: loc.type,
3356
+ reason: "no-installed-package-declares-type"
3278
3357
  } });
3279
3358
  }
3280
3359
  }
@@ -3475,6 +3554,32 @@ var StorageOrchestratorService = class {
3475
3554
  } : { added };
3476
3555
  }
3477
3556
  /**
3557
+ * Re-create the default of a type whose seed marker survived the loss of every
3558
+ * row (the 2026-11-01 prune: it deleted the rows and, until D1006, left the
3559
+ * marker). That state cannot be an operator action — the service refuses to
3560
+ * delete or disable the LAST enabled location of a type — so it is repaired
3561
+ * with the normal seed rules (media/backup roots, `defaultsTo`), each one
3562
+ * logged with its reason. Returns the types that got their default back.
3563
+ *
3564
+ * The caller states that every declaring addon is loaded and the store has
3565
+ * answered: this never guesses (D49, D315).
3566
+ */
3567
+ reseedPrunedDefaults(input) {
3568
+ const seeded = this.seededTypes;
3569
+ if (seeded === null) return [];
3570
+ const candidates = input.declarations.filter((d) => seeded.has(d.id) && !this.hasAnyLocationOfType(d.id));
3571
+ if (candidates.length === 0) return [];
3572
+ for (const d of candidates) seeded.delete(d.id);
3573
+ this.seedDefaults(input);
3574
+ const restored = candidates.filter((d) => this.hasAnyLocationOfType(d.id)).map((d) => d.id);
3575
+ for (const d of candidates) if (restored.includes(d.id)) this.logger.info("storage-orchestrator: re-seeded a default that a prune had removed", { meta: {
3576
+ type: d.id,
3577
+ reason: "seed-marker-without-rows"
3578
+ } });
3579
+ else this.rememberSeeded(d.id);
3580
+ return restored;
3581
+ }
3582
+ /**
3478
3583
  * The same-type physical-root refusal (D389).
3479
3584
  *
3480
3585
  * An unresolvable root — another node's disk, a remote provider, a path that
@@ -3842,6 +3947,67 @@ var StoragePressureManager = class {
3842
3947
  }
3843
3948
  };
3844
3949
  //#endregion
3950
+ //#region src/builtins/storage-orchestrator/storage-writability-monitor.ts
3951
+ var WRITABILITY_FINDING_PREFIX = "storage:no-writable-location:";
3952
+ var STORAGE_PAGE = "/system/storage";
3953
+ /** What stops working when the type has nowhere to write. */
3954
+ var IMPACT_BY_TYPE = {
3955
+ eventMedia: "no thumbnails or track photos are saved",
3956
+ recordings: "no recordings are written",
3957
+ recordingsLow: "no low-resolution recordings are written",
3958
+ artifacts: "no analysis artifacts are saved",
3959
+ backups: "no backups can be written"
3960
+ };
3961
+ var GENERIC_IMPACT = "everything that writes to it is refused";
3962
+ var StorageWritabilityMonitor = class {
3963
+ deps;
3964
+ failing = /* @__PURE__ */ new Set();
3965
+ evaluated = false;
3966
+ constructor(deps) {
3967
+ this.deps = deps;
3968
+ }
3969
+ evaluate(input) {
3970
+ if (!input.authoritative) return;
3971
+ if (input.declarers.some((d) => d.addonId === null)) return;
3972
+ const first = !this.evaluated;
3973
+ this.evaluated = true;
3974
+ const loaded = input.declarers.filter((d) => d.loaded);
3975
+ const types = /* @__PURE__ */ new Map();
3976
+ for (const declarer of loaded) for (const d of declarer.declarations) {
3977
+ const entry = types.get(d.id) ?? {
3978
+ displayName: d.displayName,
3979
+ addons: []
3980
+ };
3981
+ if (declarer.addonId !== null && !entry.addons.includes(declarer.addonId)) entry.addons.push(declarer.addonId);
3982
+ types.set(d.id, entry);
3983
+ }
3984
+ for (const [type, info] of types) {
3985
+ const findingId = `${WRITABILITY_FINDING_PREFIX}${type}`;
3986
+ if (!input.locations.some((l) => l.type === type && mayWriteToLocation(l))) {
3987
+ this.failing.add(type);
3988
+ this.deps.logger.warn("storage-orchestrator: declared type has no writable location", { meta: {
3989
+ type,
3990
+ addons: info.addons
3991
+ } });
3992
+ this.deps.emit({
3993
+ category: EventCategory.SystemLivenessFailed,
3994
+ data: {
3995
+ findingId,
3996
+ severity: "error",
3997
+ title: `No writable ${info.displayName.toLowerCase()} location`,
3998
+ message: `${info.displayName} (${type}) is needed by ${info.addons.join(", ")} but has no location that accepts writes: ${IMPACT_BY_TYPE[type] ?? GENERIC_IMPACT}. Add or re-enable a location on the Storage page.`,
3999
+ href: STORAGE_PAGE,
4000
+ actionLabel: "Open Storage"
4001
+ }
4002
+ });
4003
+ } else if (this.failing.delete(type) || first) this.deps.emit({
4004
+ category: EventCategory.SystemLivenessRecovered,
4005
+ data: { findingId }
4006
+ });
4007
+ }
4008
+ }
4009
+ };
4010
+ //#endregion
3845
4011
  //#region src/builtins/storage-orchestrator/storage-location-band-monitor.ts
3846
4012
  var DEFAULT_STORAGE_LOCATION_BAND_CONFIG = {
3847
4013
  lowPercent: 15,
@@ -4913,6 +5079,7 @@ var StorageOrchestratorAddon = class extends BaseAddon {
4913
5079
  * failed upsert.
4914
5080
  */
4915
5081
  announceLocationsChanged(locationId, locationType, reason) {
5082
+ this.evaluateWritability();
4916
5083
  try {
4917
5084
  this.ctx.eventBus.emit({
4918
5085
  id: randomUUID(),
@@ -5177,6 +5344,35 @@ var StorageOrchestratorAddon = class extends BaseAddon {
5177
5344
  async locationVolumeTotalBytes(locationId) {
5178
5345
  return volumeTotalBytesOf(await this.volumeCapacityOf(locationId));
5179
5346
  }
5347
+ declarersSeen = null;
5348
+ seedAnswered = false;
5349
+ reseedRepairDone = false;
5350
+ reseedRepairRunning = false;
5351
+ writabilityMonitor = null;
5352
+ /** Built on first use: `this.ctx` does not exist in a field initializer. */
5353
+ get writability() {
5354
+ this.writabilityMonitor ??= new StorageWritabilityMonitor({
5355
+ logger: this.ctx.logger,
5356
+ emit: (event) => this.emitWritabilityEvent(event)
5357
+ });
5358
+ return this.writabilityMonitor;
5359
+ }
5360
+ emitWritabilityEvent(event) {
5361
+ try {
5362
+ this.ctx.eventBus.emit({
5363
+ id: randomUUID(),
5364
+ timestamp: /* @__PURE__ */ new Date(),
5365
+ source: {
5366
+ type: "addon",
5367
+ id: this.ctx.id
5368
+ },
5369
+ category: event.category,
5370
+ data: { ...event.data }
5371
+ });
5372
+ } catch (err) {
5373
+ this.ctx.logger.warn("storage-orchestrator: could not emit the writability finding", { meta: { error: err instanceof Error ? err.message : String(err) } });
5374
+ }
5375
+ }
5180
5376
  /**
5181
5377
  * Seed default storage locations from the addon-declared
5182
5378
  * `storageLocations`, aggregated by the kernel into a
@@ -5193,19 +5389,64 @@ var StorageOrchestratorAddon = class extends BaseAddon {
5193
5389
  async seedFromDeclarations() {
5194
5390
  if (!this.service) return;
5195
5391
  await this.refreshNodeLocalCache();
5196
- const registry = buildStorageLocationRegistry(this.ctx.kernel.listStorageLocationDeclarations?.() ?? []);
5392
+ const declarers = this.ctx.kernel.listStorageLocationDeclarers?.();
5393
+ const perAddon = declarers !== void 0 ? declarers.filter((d) => d.loaded).map((d) => d.declarations) : this.ctx.kernel.listStorageLocationDeclarations?.() ?? [];
5394
+ const unloaded = declarers?.filter((d) => !d.loaded) ?? [];
5395
+ const registry = buildStorageLocationRegistry(perAddon);
5197
5396
  this.service.setRegistry(registry);
5198
- this.service.pruneUndeclaredSystemLocations();
5397
+ this.service.pruneUndeclaredSystemLocations(unloaded);
5199
5398
  const mediaRoot = process.env.CAMSTACK_MEDIA_ROOT?.trim();
5200
5399
  const backupRoot = process.env.CAMSTACK_BACKUP_ROOT?.trim();
5201
- this.service.seedDefaults({
5400
+ const seedInput = {
5202
5401
  providerId: "filesystem-storage",
5203
5402
  basePath: this.ctx.nodeDataDir,
5204
5403
  mediaBasePath: mediaRoot && mediaRoot.length > 0 ? mediaRoot : void 0,
5205
5404
  backupBasePath: backupRoot && backupRoot.length > 0 ? backupRoot : void 0,
5206
5405
  declarations: registry.list()
5207
- });
5406
+ };
5407
+ const seedOutcome = this.service.seedDefaults(seedInput);
5208
5408
  await this.service.backfillNodeIds(HUB_NODE_ID);
5409
+ this.declarersSeen = declarers ?? null;
5410
+ this.seedAnswered = seedOutcome.deferred === void 0;
5411
+ await this.repairPrunedDefaults(seedInput, declarers);
5412
+ this.evaluateWritability();
5413
+ }
5414
+ /**
5415
+ * One-shot ledger migration (D987): re-create the default of a declared type whose
5416
+ * seed marker survived the 2026-11-01 prune with no rows left. It is offered ONLY
5417
+ * when the whole picture is known: the kernel listed its declarers, every one of them
5418
+ * is loaded and readable, and the seed pass answered. Otherwise it is not offered and
5419
+ * the next seed pass tries again; it never guesses (D49/D315).
5420
+ */
5421
+ async repairPrunedDefaults(seedInput, declarers) {
5422
+ const service = this.service;
5423
+ if (!service || this.reseedRepairDone || this.reseedRepairRunning) return;
5424
+ if (declarers === void 0 || declarers.some((d) => !d.loaded || d.addonId === null)) return;
5425
+ if (!this.seedAnswered || !service.locationsAuthoritative()) return;
5426
+ this.reseedRepairRunning = true;
5427
+ try {
5428
+ await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, { reseed: () => service.reseedPrunedDefaults(seedInput) }));
5429
+ this.reseedRepairDone = true;
5430
+ } catch (err) {
5431
+ this.ctx.logger.warn("storage-orchestrator: the pruned-default repair did not run", { meta: { error: err instanceof Error ? err.message : String(err) } });
5432
+ } finally {
5433
+ this.reseedRepairRunning = false;
5434
+ }
5435
+ }
5436
+ /**
5437
+ * Alert when a declared type has nowhere to write. Runs after every seed pass
5438
+ * and every change to the set of locations; a no-op until a pass has an
5439
+ * answered state AND the kernel could list its declarers (D315).
5440
+ */
5441
+ evaluateWritability() {
5442
+ const service = this.service;
5443
+ const declarers = this.declarersSeen;
5444
+ if (!service || declarers === null) return;
5445
+ this.writability.evaluate({
5446
+ authoritative: this.seedAnswered && service.locationsAuthoritative(),
5447
+ declarers,
5448
+ locations: service.listLocations()
5449
+ });
5209
5450
  }
5210
5451
  /**
5211
5452
  * Rebuild the `providerId → nodeLocal` cache from every registered
@@ -1,4 +1,4 @@
1
- import type { IScopedLogger, IStorageProviderImpl, StorageAccess, StorageLocation, StorageLocationDeclaration, StorageLocationRef } from "@camstack/types";
1
+ import type { IScopedLogger, IStorageProviderImpl, StorageAccess, StorageLocation, StorageLocationDeclaration, StorageLocationDeclarer, StorageLocationRef } from "@camstack/types";
2
2
  import type { ResolveRoot } from "./location-root-collision.js";
3
3
  import type { ILocationStore } from "./location-store.js";
4
4
  export interface ListLocationsFilter {
@@ -76,6 +76,23 @@ export interface StorageDispatchTarget {
76
76
  /** The two chunked-I/O session families the orchestrator tracks. */
77
77
  export type StorageSessionKind = "upload" | "download";
78
78
  /** What a {@link StorageOrchestratorService.seedDefaults} pass did. */
79
+ export interface SeedDefaultsInput {
80
+ readonly providerId: string;
81
+ readonly basePath: string;
82
+ /**
83
+ * Root for declarations marked `defaultRoot: 'media'` (the dedicated media
84
+ * volume, `CAMSTACK_MEDIA_ROOT`). Absent → media declarations fall back to
85
+ * `basePath` like everything else.
86
+ */
87
+ readonly mediaBasePath?: string;
88
+ /**
89
+ * Root for declarations marked `defaultRoot: 'backup'` (the dedicated
90
+ * backup volume, `CAMSTACK_BACKUP_ROOT`, default `/backups`). Absent →
91
+ * backup declarations fall back to `basePath`.
92
+ */
93
+ readonly backupBasePath?: string;
94
+ readonly declarations: readonly StorageLocationDeclaration[];
95
+ }
79
96
  export type SeedOutcome = {
80
97
  readonly added: number;
81
98
  readonly deferred?: "store-not-answered" | "provider-unclassified";
@@ -161,6 +178,13 @@ export declare class StorageOrchestratorService {
161
178
  private installPredatesSeedMemory;
162
179
  private loadSeedMemory;
163
180
  private rememberSeeded;
181
+ private forgetSeeded;
182
+ /**
183
+ * Do the rows this service holds answer "which locations exist"? False while
184
+ * a store that must answer has not (not wired, adoption pending, read
185
+ * failed): an empty map then means NOT YET KNOWN, never "none" (D315).
186
+ */
187
+ locationsAuthoritative(): boolean;
164
188
  /** True once a persistence store is wired (constructor or {@link attachStore}). */
165
189
  hasStore(): boolean;
166
190
  /**
@@ -356,17 +380,30 @@ export declare class StorageOrchestratorService {
356
380
  */
357
381
  private probeOccupancy;
358
382
  /**
359
- * Remove seed-shaped locations (`<type>:default`) whose type is no longer
360
- * declared by any addon (stale defaults from a removed location type).
383
+ * Remove seed-shaped locations (`<type>:default`) whose type no INSTALLED
384
+ * package declares any more (stale defaults from a removed location type).
361
385
  * Operator-added locations of an undeclared type are KEPT but warned.
362
386
  *
387
+ * "Undeclared" means undeclared by every installed package, not by every
388
+ * LOADED addon. The registry is built from the addons that loaded; an addon
389
+ * whose load failed (`Cannot find module` after a bad deploy) declares the
390
+ * same types it always did, and "not known right now" is not "removed"
391
+ * (D49, D315). `unloaded` is that other half — every installed declarer
392
+ * that is not loaded. A type one of them declares is kept, by name in the
393
+ * log; a package that could not even be read has unknown declarations, so
394
+ * the whole pass is skipped (a read that would DESTROY needs an answer).
395
+ *
396
+ * A pruned type also forgets that it was seeded: were it declared again, it
397
+ * seeds again, while an operator's own delete (which never reaches here)
398
+ * keeps sticking.
399
+ *
363
400
  * FAIL-SAFE: if the registry is EMPTY (no addon declared any location), we
364
401
  * refuse to prune anything. An empty registry almost always means
365
402
  * declarations failed to load (boot ordering, a stale install) — pruning
366
403
  * "everything undeclared" in that state would wipe every seeded location
367
404
  * (data/logs/recordings/…). Better to keep stale rows than destroy live ones.
368
405
  */
369
- pruneUndeclaredSystemLocations(): void;
406
+ pruneUndeclaredSystemLocations(unloaded?: readonly StorageLocationDeclarer[]): void;
370
407
  /**
371
408
  * Resolve a `StorageLocationRef` to a concrete `StorageLocation`.
372
409
  * - bare type (e.g. `'backups'`) → default location of that type
@@ -439,23 +476,19 @@ export declare class StorageOrchestratorService {
439
476
  * the referenced location's default instance (sharing the same root
440
477
  * directory for derivative slots like `recordingsLow` → `recordings`).
441
478
  */
442
- seedDefaults(input: {
443
- readonly providerId: string;
444
- readonly basePath: string;
445
- /**
446
- * Root for declarations marked `defaultRoot: 'media'` (the dedicated media
447
- * volume, `CAMSTACK_MEDIA_ROOT`). Absent → media declarations fall back to
448
- * `basePath` like everything else.
449
- */
450
- readonly mediaBasePath?: string;
451
- /**
452
- * Root for declarations marked `defaultRoot: 'backup'` (the dedicated
453
- * backup volume, `CAMSTACK_BACKUP_ROOT`, default `/backups`). Absent →
454
- * backup declarations fall back to `basePath`.
455
- */
456
- readonly backupBasePath?: string;
457
- readonly declarations: readonly StorageLocationDeclaration[];
458
- }): SeedOutcome;
479
+ seedDefaults(input: SeedDefaultsInput): SeedOutcome;
480
+ /**
481
+ * Re-create the default of a type whose seed marker survived the loss of every
482
+ * row (the 2026-11-01 prune: it deleted the rows and, until D1006, left the
483
+ * marker). That state cannot be an operator action — the service refuses to
484
+ * delete or disable the LAST enabled location of a type — so it is repaired
485
+ * with the normal seed rules (media/backup roots, `defaultsTo`), each one
486
+ * logged with its reason. Returns the types that got their default back.
487
+ *
488
+ * The caller states that every declaring addon is loaded and the store has
489
+ * answered: this never guesses (D49, D315).
490
+ */
491
+ reseedPrunedDefaults(input: SeedDefaultsInput): readonly string[];
459
492
  /**
460
493
  * The same-type physical-root refusal (D389).
461
494
  *
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Is every DECLARED storage type writable? A type an installed addon declares
3
+ * but that has no location in a writing mode refuses every write ("no writable
4
+ * eventMedia storage location") and the operator learns of it from a 404
5
+ * thumbnail days later. This turns that state into an alert through the
6
+ * existing alert centre: a liveness finding under a stable id, which the centre
7
+ * opens as one card and dismisses on the matching recovery.
8
+ *
9
+ * Only an ANSWERED state raises (D49, D315): a store that has not answered, a
10
+ * declarer that did not load, a package that could not be read are all
11
+ * "unknown", never "no writable location".
12
+ */
13
+ import type { IScopedLogger, StorageLocation, StorageLocationDeclarer } from "@camstack/types";
14
+ import { EventCategory } from "@camstack/types";
15
+ export declare const WRITABILITY_FINDING_PREFIX = "storage:no-writable-location:";
16
+ export interface WritabilityEmission {
17
+ readonly category: EventCategory.SystemLivenessFailed | EventCategory.SystemLivenessRecovered;
18
+ readonly data: Readonly<Record<string, unknown>>;
19
+ }
20
+ export interface WritabilityInput {
21
+ /** False until the location store answered: then nothing can be said. */
22
+ readonly authoritative: boolean;
23
+ readonly declarers: readonly StorageLocationDeclarer[];
24
+ readonly locations: readonly StorageLocation[];
25
+ }
26
+ export interface WritabilityMonitorDeps {
27
+ readonly emit: (event: WritabilityEmission) => void;
28
+ readonly logger: IScopedLogger;
29
+ }
30
+ export declare class StorageWritabilityMonitor {
31
+ private readonly deps;
32
+ private readonly failing;
33
+ private evaluated;
34
+ constructor(deps: WritabilityMonitorDeps);
35
+ evaluate(input: WritabilityInput): void;
36
+ }
@@ -3,11 +3,11 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CiwLP3-C.js");
6
+ const require_dist = require("../../dist-Cyida7ne.js");
7
7
  const require_safe_buffer$1 = require("../../safe-buffer-D3aoa-7X.js");
8
8
  const require_x509_es = require("../../x509.es-WtnRNyYS.js");
9
- const require_agent_https = require("../../agent-https-DXDFMq90.js");
10
- const require_constants$8 = require("../../constants-hAbcGGDs.js");
9
+ const require_agent_https = require("../../agent-https-YFeT_9qF.js");
10
+ const require_constants$8 = require("../../constants-nY2QXQK5.js");
11
11
  const require_src$1 = require("../../src-CnAqG6EF.js");
12
12
  let zod = require("zod");
13
13
  let node_crypto = require("node:crypto");
@@ -1,9 +1,9 @@
1
1
  import { a as __toCommonJS, i as __require, n as __esmMin, o as __toESM, r as __exportAll, t as __commonJSMin } from "../../chunk-CNf5ZN-e.mjs";
2
- import { Ds as hydrateSchema, _s as defineCustomActions, hs as customAction, ma as shortHostname, qt as ServerNameSchema, uc as errMsg, wo as BaseAddon } from "../../dist-BIJD_nvZ.mjs";
2
+ import { Ds as hydrateSchema, _s as defineCustomActions, hs as customAction, ma as shortHostname, qt as ServerNameSchema, uc as errMsg, wo as BaseAddon } from "../../dist-Cu6VwGZZ.mjs";
3
3
  import { t as require_safe_buffer } from "../../safe-buffer-B1OjL1I9.mjs";
4
4
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, a as KeyUsageFlags, c as Pkcs10CertificateRequest, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, l as Pkcs10CertificateRequestGenerator, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension } from "../../x509.es-BRiJgOvu.mjs";
5
- import { B as setProcessAgentHttpsNames, I as AGENT_HTTPS_NAMES_COLLECTION, L as AGENT_HTTPS_NAMES_COLUMNS, M as isLocalOnlyHostname, R as AgentHttpsNames, V as systemConfigRecordKinds, u as isPrivateAddress, z as getProcessAgentHttpsNames } from "../../agent-https-Bafgj4ni.mjs";
6
- import { a as MESH_CA_KEY_REF, c as SERVER_AUTH_OID, i as MESH_CA_FIELD, n as DEFAULT_HUB_TLS_TCP_PORT, o as MESH_CA_SETTINGS_KEY, r as MESH_CA_COMMON_NAME, s as MESH_CA_VALIDITY_DAYS, t as CLIENT_AUTH_OID } from "../../constants-BAG_5cF6.mjs";
5
+ import { B as setProcessAgentHttpsNames, I as AGENT_HTTPS_NAMES_COLLECTION, L as AGENT_HTTPS_NAMES_COLUMNS, M as isLocalOnlyHostname, R as AgentHttpsNames, V as systemConfigRecordKinds, u as isPrivateAddress, z as getProcessAgentHttpsNames } from "../../agent-https-D1B_fvIx.mjs";
6
+ import { a as MESH_CA_KEY_REF, c as SERVER_AUTH_OID, i as MESH_CA_FIELD, n as DEFAULT_HUB_TLS_TCP_PORT, o as MESH_CA_SETTINGS_KEY, r as MESH_CA_COMMON_NAME, s as MESH_CA_VALIDITY_DAYS, t as CLIENT_AUTH_OID } from "../../constants-DW74hDp7.mjs";
7
7
  import { t as require_src } from "../../src-hG4grMU4.mjs";
8
8
  import { z } from "zod";
9
9
  import { X509Certificate, createHash, createPrivateKey, randomBytes, randomInt, sign, timingSafeEqual, verify, webcrypto } from "node:crypto";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CiwLP3-C.js");
6
+ const require_dist = require("../../dist-Cyida7ne.js");
7
7
  const require_formatter = require("../../formatter-xbxeV4GD.js");
8
8
  const require_log_file_read_protocol = require("../../log-file-read-protocol-D0WcLbIV.js");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { ri as logDestinationCapability, wo as BaseAddon } from "../../dist-BIJD_nvZ.mjs";
1
+ import { ri as logDestinationCapability, wo as BaseAddon } from "../../dist-Cu6VwGZZ.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-DkYZ4LXp.mjs";
3
3
  import { a as LogFileIndexStore, i as serveRead, n as isFromReader, t as CancelBook } from "../../log-file-read-protocol-B7M3X3bT.mjs";
4
4
  import { createRequire } from "node:module";
@@ -1,4 +1,4 @@
1
- import { No as HISTORY_DEFAULT_MIN_INTERVAL_MS, Ts as historyItemFieldPath, lc as DeviceType } from "./dist-BIJD_nvZ.mjs";
1
+ import { No as HISTORY_DEFAULT_MIN_INTERVAL_MS, Ts as historyItemFieldPath, lc as DeviceType } from "./dist-Cu6VwGZZ.mjs";
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CiwLP3-C.js");
1
+ const require_dist = require("./dist-Cyida7ne.js");
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CiwLP3-C.js");
1
+ const require_dist = require("./dist-Cyida7ne.js");
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { oo as compositionSourceKey, uc as errMsg } from "./dist-BIJD_nvZ.mjs";
1
+ import { oo as compositionSourceKey, uc as errMsg } from "./dist-Cu6VwGZZ.mjs";
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { ls as buildSecretRef } from "./dist-BIJD_nvZ.mjs";
1
+ import { ls as buildSecretRef } from "./dist-Cu6VwGZZ.mjs";
2
2
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
3
3
  var MESH_CA_KEY_REF = buildSecretRef({
4
4
  owner: "system",
@@ -1,5 +1,5 @@
1
1
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
2
- var MESH_CA_KEY_REF = require("./dist-CiwLP3-C.js").buildSecretRef({
2
+ var MESH_CA_KEY_REF = require("./dist-Cyida7ne.js").buildSecretRef({
3
3
  owner: "system",
4
4
  scope: { kind: "global" },
5
5
  fieldPath: "meshCaKey"
@@ -1,4 +1,4 @@
1
- import { H as DEVICE_SAN_CREDENTIAL_PREFIX, U as DEVICE_SAN_USER_PREFIX, ls as buildSecretRef } from "./dist-BIJD_nvZ.mjs";
1
+ import { H as DEVICE_SAN_CREDENTIAL_PREFIX, U as DEVICE_SAN_USER_PREFIX, ls as buildSecretRef } from "./dist-Cu6VwGZZ.mjs";
2
2
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, a as KeyUsageFlags, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension } from "./x509.es-BRiJgOvu.mjs";
3
3
  import { X509Certificate, createPublicKey, randomBytes, verify, webcrypto } from "node:crypto";
4
4
  //#region src/auth/jwt-signing-key.ts
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CiwLP3-C.js");
1
+ const require_dist = require("./dist-Cyida7ne.js");
2
2
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
3
3
  let node_crypto = require("node:crypto");
4
4
  //#region src/auth/jwt-signing-key.ts