@camstack/server 1.2.896 → 1.2.898

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 (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +17 -23
  3. package/system/dist/addon-runner.js +103 -12
  4. package/system/dist/addon-runner.mjs +103 -12
  5. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/system/dist/builtins/autotrack/index.js +1 -1
  12. package/system/dist/builtins/autotrack/index.mjs +1 -1
  13. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  15. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  16. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  17. package/system/dist/builtins/camera-grid/index.js +1 -1
  18. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  19. package/system/dist/builtins/composer/composer.addon.js +14 -11
  20. package/system/dist/builtins/composer/composer.addon.mjs +11 -8
  21. package/system/dist/builtins/console-logging/index.js +1 -1
  22. package/system/dist/builtins/console-logging/index.mjs +1 -1
  23. package/system/dist/builtins/core-blocks/core-blocks.addon.js +170 -14
  24. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +169 -13
  25. package/system/dist/builtins/core-blocks/migrations/automation-confirmed-view.d.ts +23 -0
  26. package/system/dist/builtins/core-blocks/migrations/index.d.ts +1 -0
  27. package/system/dist/builtins/core-blocks/migrations/pump-cycle-split.d.ts +1 -0
  28. package/system/dist/builtins/device-history/device-history.addon.js +10 -9
  29. package/system/dist/builtins/device-history/device-history.addon.mjs +10 -9
  30. package/system/dist/builtins/device-manager/command-holds-wiring.d.ts +22 -0
  31. package/system/dist/builtins/device-manager/command-holds.d.ts +75 -0
  32. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
  33. package/system/dist/builtins/device-manager/device-manager.addon.js +383 -27
  34. package/system/dist/builtins/device-manager/device-manager.addon.mjs +380 -28
  35. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +35 -9
  36. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  37. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  38. package/system/dist/builtins/keychain/index.js +4 -4
  39. package/system/dist/builtins/keychain/index.mjs +4 -4
  40. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  41. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  42. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  43. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  44. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  45. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  46. package/system/dist/builtins/loki-logging/index.js +1 -1
  47. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  48. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  49. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  50. package/system/dist/builtins/platform-probe/index.js +1 -1
  51. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  52. package/system/dist/builtins/record-entries/index.js +1 -1
  53. package/system/dist/builtins/record-entries/index.mjs +1 -1
  54. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  55. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  56. package/system/dist/builtins/shared/device-state-changed.d.ts +8 -0
  57. package/system/dist/builtins/snapshot/index.js +1 -1
  58. package/system/dist/builtins/snapshot/index.mjs +1 -1
  59. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  60. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  61. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  62. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  63. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  64. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  65. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  66. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  67. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  68. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  69. package/system/dist/builtins/winston-logging/index.js +1 -1
  70. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  71. package/system/dist/{capture-engine-BgIjQWh6.js → capture-engine-BWS0KTbm.js} +48 -1
  72. package/system/dist/{capture-engine-DPn6JaPc.mjs → capture-engine-DBQDaDxJ.mjs} +37 -2
  73. package/system/dist/{composition-sources-Bec_hQMM.js → composition-sources-CDOW1dnY.js} +1 -32
  74. package/system/dist/{composition-sources-B0rdPm85.mjs → composition-sources-CGUWmf-T.mjs} +2 -21
  75. package/system/dist/{constants-DsQsO8PD.mjs → constants-BmrLkwZs.mjs} +1 -1
  76. package/system/dist/{constants-CsYMak6g.js → constants-BwrRoq-j.js} +1 -1
  77. package/system/dist/{device-ca-BuDqRFZd.mjs → device-ca-BGgZXEto.mjs} +1 -1
  78. package/system/dist/{device-ca-BeK8EI_7.js → device-ca-DiuwWyZY.js} +1 -1
  79. package/system/dist/{dist-CHC8tlB1.js → dist-CCd8IeIU.js} +705 -54
  80. package/system/dist/{dist-DiknL6UU.mjs → dist-D7t8wLTF.mjs} +694 -55
  81. package/system/dist/file-host-worker.js +1 -1
  82. package/system/dist/file-host-worker.mjs +1 -1
  83. package/system/dist/{hub-identity-Dt-mbtkY.mjs → hub-identity-BohJeqdO.mjs} +1 -1
  84. package/system/dist/{hub-identity-BM26oLpK.js → hub-identity-G_ZdyPpc.js} +1 -1
  85. package/system/dist/{hub-mdns-ciao-BDgSHCPM.js → hub-mdns-ciao-CKD4EgkG.js} +2 -2
  86. package/system/dist/{hub-mdns-ciao-CHq7b1FX.mjs → hub-mdns-ciao-D5RxSMrH.mjs} +2 -2
  87. package/system/dist/index.js +45 -13
  88. package/system/dist/index.mjs +46 -14
  89. package/system/dist/kernel/command-hold-overrides.d.ts +42 -0
  90. package/system/dist/kernel/moleculer/child-cap-descriptors.d.ts +3 -0
  91. package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +2 -1
  92. package/system/dist/kernel/transport/child-cap-protocol.d.ts +6 -1
  93. package/system/dist/{legacy-integration-rows-door-BYJa0xPI.js → legacy-integration-rows-door-BgCl68ek.js} +1 -1
  94. package/system/dist/{legacy-integration-rows-door-1WauJNCy.mjs → legacy-integration-rows-door-Rm9JmIsl.mjs} +1 -1
  95. package/system/dist/{rename-composition-block-fMaUic9d.js → rename-composition-block-2Z2ED7Og.js} +1 -1
  96. package/system/dist/{rename-composition-block-BOoAElGp.mjs → rename-composition-block-DNO3mNEO.mjs} +1 -1
  97. package/system/dist/{restore-archive-DNLe1z5A.mjs → restore-archive-2L5TymvF.mjs} +1 -1
  98. package/system/dist/{restore-archive-CeZV08vh.js → restore-archive-CZkQO8t3.js} +1 -1
  99. package/system/dist/{wal-maintenance-CekT_qH6.mjs → wal-maintenance-BMYe_n18.mjs} +0 -0
  100. package/system/dist/{wal-maintenance-CmCCUKZO.js → wal-maintenance-YjDJ73Qd.js} +0 -0
  101. package/system/package.json +1 -1
@@ -3,10 +3,10 @@ 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-CHC8tlB1.js");
6
+ const require_dist = require("../../dist-CCd8IeIU.js");
7
7
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
8
8
  const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
9
- const require_rename_composition_block = require("../../rename-composition-block-fMaUic9d.js");
9
+ const require_rename_composition_block = require("../../rename-composition-block-2Z2ED7Og.js");
10
10
  const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
11
11
  const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
12
12
  const require_retired_settings_keys = require("../../retired-settings-keys-C8nOOr5H.js");
@@ -7648,7 +7648,8 @@ async function loadMeta(pctx, input) {
7648
7648
  metadata,
7649
7649
  ...m.integrationId !== void 0 ? { integrationId: m.integrationId } : {},
7650
7650
  ...m.linkDeviceId !== void 0 ? { linkDeviceId: m.linkDeviceId } : {},
7651
- ...m.role !== void 0 ? { role: m.role } : {}
7651
+ ...m.role !== void 0 ? { role: m.role } : {},
7652
+ ...m.identifiers !== void 0 ? { identifiers: m.identifiers } : {}
7652
7653
  };
7653
7654
  }
7654
7655
  /**
@@ -12096,6 +12097,201 @@ var MirrorRowWriter = class MirrorRowWriter {
12096
12097
  }
12097
12098
  };
12098
12099
  //#endregion
12100
+ //#region src/builtins/device-manager/command-holds.ts
12101
+ function same(a, b) {
12102
+ return Object.is(a, b);
12103
+ }
12104
+ /** Does `reading` confirm `held`: equal, or a number within its tolerance? */
12105
+ function confirms(reading, held, tolerance) {
12106
+ if (same(reading, held)) return true;
12107
+ if (typeof reading !== "number" || typeof held !== "number" || tolerance <= 0) return false;
12108
+ return Math.abs(reading - held) <= tolerance + 1e-9;
12109
+ }
12110
+ function judge(reading, held) {
12111
+ if (confirms(reading, held.value, held.tolerance)) return "confirmed";
12112
+ if (held.stale.some((v) => same(v, reading))) return "stale";
12113
+ return "device-answered";
12114
+ }
12115
+ var CommandHolds = class {
12116
+ deps;
12117
+ /** device → cap → field → held value. */
12118
+ held = /* @__PURE__ */ new Map();
12119
+ armings = /* @__PURE__ */ new Map();
12120
+ seq = 0;
12121
+ constructor(deps) {
12122
+ this.deps = deps;
12123
+ }
12124
+ /**
12125
+ * Hold what a command leads to. A field the slice already holds is not held
12126
+ * (and a standing hold on it is dropped: the newer command wins). Returns the
12127
+ * token that `release` takes, or `null` when nothing is held.
12128
+ */
12129
+ arm(request) {
12130
+ const base = this.deps.baseSlice(request.deviceId, request.capName);
12131
+ if (base === null) {
12132
+ this.deps.logger.debug("command hold: the cap has no slice yet — nothing held", {
12133
+ tags: { deviceId: request.deviceId },
12134
+ meta: {
12135
+ cap: request.capName,
12136
+ method: request.method
12137
+ }
12138
+ });
12139
+ return null;
12140
+ }
12141
+ this.seq += 1;
12142
+ const token = this.seq;
12143
+ const fields = this.fieldsOf(request.deviceId, request.capName);
12144
+ let changed = false;
12145
+ let holding = false;
12146
+ for (const effect of request.effects) {
12147
+ const standing = fields.get(effect.field);
12148
+ const tolerance = effect.tolerance ?? 0;
12149
+ const reported = Object.hasOwn(base, effect.field) ? base[effect.field] : void 0;
12150
+ if (Object.hasOwn(base, effect.field) && confirms(reported, effect.value, tolerance)) {
12151
+ if (standing !== void 0) {
12152
+ fields.delete(effect.field);
12153
+ changed = true;
12154
+ }
12155
+ continue;
12156
+ }
12157
+ if (standing === void 0 || !same(standing.value, effect.value)) changed = true;
12158
+ const stale = standing === void 0 ? [reported] : [...standing.stale, standing.value];
12159
+ fields.set(effect.field, {
12160
+ value: effect.value,
12161
+ tolerance,
12162
+ stale,
12163
+ token
12164
+ });
12165
+ holding = true;
12166
+ }
12167
+ this.dropEmpty(request.deviceId, request.capName);
12168
+ this.forgetStaleArmings();
12169
+ if (holding) {
12170
+ const timer = setTimeout(() => this.release(token, "unconfirmed"), request.holdMs);
12171
+ timer.unref?.();
12172
+ this.armings.set(token, {
12173
+ token,
12174
+ deviceId: request.deviceId,
12175
+ capName: request.capName,
12176
+ method: request.method,
12177
+ holdMs: request.holdMs,
12178
+ timer
12179
+ });
12180
+ }
12181
+ if (changed) this.deps.reemit(request.deviceId, request.capName);
12182
+ return holding ? token : null;
12183
+ }
12184
+ /** End what `token` still holds — refused at once, or unconfirmed at the limit. */
12185
+ release(token, reason) {
12186
+ const arming = this.armings.get(token);
12187
+ if (arming === void 0) return;
12188
+ this.armings.delete(token);
12189
+ clearTimeout(arming.timer);
12190
+ const fields = this.held.get(arming.deviceId)?.get(arming.capName);
12191
+ if (fields === void 0) return;
12192
+ const dropped = [];
12193
+ for (const [field, held] of fields) {
12194
+ if (held.token !== token) continue;
12195
+ fields.delete(field);
12196
+ dropped.push(field);
12197
+ }
12198
+ if (dropped.length === 0) return;
12199
+ this.dropEmpty(arming.deviceId, arming.capName);
12200
+ const tags = { deviceId: arming.deviceId };
12201
+ const meta = {
12202
+ cap: arming.capName,
12203
+ method: arming.method,
12204
+ fields: dropped
12205
+ };
12206
+ if (reason === "unconfirmed" && arming.holdMs <= 1e4) this.deps.logger.debug("one-shot command hold ended", {
12207
+ tags,
12208
+ meta
12209
+ });
12210
+ else if (reason === "unconfirmed") this.deps.logger.warn("command hold reverted: the device did not confirm in time", {
12211
+ tags,
12212
+ meta
12213
+ });
12214
+ else this.deps.logger.info("command hold rolled back: the command was refused", {
12215
+ tags,
12216
+ meta
12217
+ });
12218
+ this.deps.reemit(arming.deviceId, arming.capName);
12219
+ }
12220
+ /**
12221
+ * The slice under the hold moved: keep each held field it still reports
12222
+ * stale, drop the ones it confirms or answers otherwise.
12223
+ */
12224
+ settle(deviceId, capName, base) {
12225
+ const fields = this.held.get(deviceId)?.get(capName);
12226
+ if (fields === void 0) return;
12227
+ for (const [field, held] of fields) {
12228
+ if (!Object.hasOwn(base, field)) continue;
12229
+ const reading = judge(base[field], held);
12230
+ if (reading === "stale") continue;
12231
+ fields.delete(field);
12232
+ if (reading === "device-answered") this.deps.logger.debug("command hold released: the device answered otherwise", {
12233
+ tags: { deviceId },
12234
+ meta: {
12235
+ cap: capName,
12236
+ field,
12237
+ reason: reading
12238
+ }
12239
+ });
12240
+ }
12241
+ this.dropEmpty(deviceId, capName);
12242
+ this.forgetStaleArmings();
12243
+ }
12244
+ /** `base` with the held values over it; `base` itself when nothing is held. */
12245
+ overlay(deviceId, capName, base) {
12246
+ const fields = this.held.get(deviceId)?.get(capName);
12247
+ if (fields === void 0 || fields.size === 0) return base;
12248
+ const out = { ...base };
12249
+ for (const [field, held] of fields) out[field] = held.value;
12250
+ return out;
12251
+ }
12252
+ /** Is any field of the cap held? */
12253
+ isHolding(deviceId, capName) {
12254
+ return (this.held.get(deviceId)?.get(capName)?.size ?? 0) > 0;
12255
+ }
12256
+ /** Forget a removed device's holds. */
12257
+ clearDevice(deviceId) {
12258
+ this.held.delete(deviceId);
12259
+ for (const [token, arming] of this.armings) {
12260
+ if (arming.deviceId !== deviceId) continue;
12261
+ clearTimeout(arming.timer);
12262
+ this.armings.delete(token);
12263
+ }
12264
+ }
12265
+ /** Stop every timer (shutdown). */
12266
+ dispose() {
12267
+ for (const arming of this.armings.values()) clearTimeout(arming.timer);
12268
+ this.armings.clear();
12269
+ this.held.clear();
12270
+ }
12271
+ fieldsOf(deviceId, capName) {
12272
+ const perCap = this.held.get(deviceId) ?? /* @__PURE__ */ new Map();
12273
+ this.held.set(deviceId, perCap);
12274
+ const fields = perCap.get(capName) ?? /* @__PURE__ */ new Map();
12275
+ perCap.set(capName, fields);
12276
+ return fields;
12277
+ }
12278
+ dropEmpty(deviceId, capName) {
12279
+ const perCap = this.held.get(deviceId);
12280
+ if (perCap === void 0) return;
12281
+ if ((perCap.get(capName)?.size ?? 0) === 0) perCap.delete(capName);
12282
+ if (perCap.size === 0) this.held.delete(deviceId);
12283
+ }
12284
+ /** An arming whose fields were all confirmed or replaced holds nothing: stop its timer. */
12285
+ forgetStaleArmings() {
12286
+ for (const [token, arming] of this.armings) {
12287
+ const fields = this.held.get(arming.deviceId)?.get(arming.capName);
12288
+ if (fields !== void 0 && [...fields.values()].some((f) => f.token === token)) continue;
12289
+ clearTimeout(arming.timer);
12290
+ this.armings.delete(token);
12291
+ }
12292
+ }
12293
+ };
12294
+ //#endregion
12099
12295
  //#region src/builtins/device-manager/device-state-mirror.ts
12100
12296
  /**
12101
12297
  * Hub-side runtime-state mirror for the device-manager addon.
@@ -12144,6 +12340,8 @@ var DeviceStateMirror = class {
12144
12340
  stateMirror = /* @__PURE__ */ new Map();
12145
12341
  /** The claims and the merged view of every claimed cap (D663). */
12146
12342
  claims;
12343
+ /** Commanded values shown before the device confirms them (D1061). Memory only. */
12344
+ holds;
12147
12345
  /**
12148
12346
  * Devices whose CLAIMS are known: the row was read, or a loaded claims index
12149
12347
  * vouched that it names none (D447). This is a READ-path fact — what a
@@ -12174,6 +12372,14 @@ var DeviceStateMirror = class {
12174
12372
  schemaFor,
12175
12373
  emitSlice: (deviceId, capName, slice) => this.emitStateChanged(deviceId, capName, slice)
12176
12374
  });
12375
+ this.holds = new CommandHolds({
12376
+ logger: ctx.logger,
12377
+ baseSlice: (deviceId, capName) => this.baseSlice(deviceId, capName),
12378
+ reemit: (deviceId, capName) => {
12379
+ const base = this.baseSlice(deviceId, capName);
12380
+ if (base !== null) this.emitStateChanged(deviceId, capName, { ...base });
12381
+ }
12382
+ });
12177
12383
  this.writer = new MirrorRowWriter({
12178
12384
  logger: ctx.logger,
12179
12385
  policyFor,
@@ -12186,6 +12392,22 @@ var DeviceStateMirror = class {
12186
12392
  setTransitionTap(tap) {
12187
12393
  this.transitionTap = tap;
12188
12394
  }
12395
+ /**
12396
+ * Hold what a command leads to: the effective slice shows it at once (and
12397
+ * `DeviceStateChanged` carries it), the stored, persisted and recorded slice
12398
+ * does not change. Returns the token {@link releaseCommand} takes, or `null`.
12399
+ */
12400
+ holdCommand(request) {
12401
+ return this.holds.arm(request);
12402
+ }
12403
+ /** End a command's hold: refused (rolled back at once) or unconfirmed (at the limit). */
12404
+ releaseCommand(token, reason) {
12405
+ this.holds.release(token, reason);
12406
+ }
12407
+ /** Stop the hold timers (shutdown). */
12408
+ disposeHolds() {
12409
+ this.holds.dispose();
12410
+ }
12189
12411
  /** The native slice the mirror holds for `capName`, as a read-only view. */
12190
12412
  currentSlice(deviceId, capName) {
12191
12413
  return this.stateMirror.get(deviceId)?.get(capName);
@@ -12398,6 +12620,7 @@ var DeviceStateMirror = class {
12398
12620
  await this.seeding.get(deviceId)?.catch(() => void 0);
12399
12621
  await this.writer.forget(deviceId);
12400
12622
  this.stateMirror.delete(deviceId);
12623
+ this.holds.clearDevice(deviceId);
12401
12624
  this.workloadTransitions.forget(deviceId);
12402
12625
  this.claims.clearDevice(deviceId);
12403
12626
  this.seeded.delete(deviceId);
@@ -12689,25 +12912,33 @@ var DeviceStateMirror = class {
12689
12912
  if (!raw) return true;
12690
12913
  return (typeof raw.lastProbedAt === "number" ? raw.lastProbedAt : 0) > 0;
12691
12914
  }
12692
- /** The EFFECTIVE slices of a device: native for an unclaimed cap, the merge
12693
- * for a claimed one (a held cap is not reported). */
12694
- snapshotForDevice(deviceId) {
12915
+ /** The slices of a device: native for an unclaimed cap, the merge for a
12916
+ * claimed one (a held cap is not reported) — and, in the `effective` view,
12917
+ * a commanded value over either (D1061). */
12918
+ snapshotForDevice(deviceId, view = "effective") {
12695
12919
  const out = {};
12696
12920
  for (const [k, v] of this.stateMirror.get(deviceId) ?? []) {
12697
12921
  if (this.claims.isClaimed(deviceId, k)) continue;
12698
- out[k] = { ...v };
12922
+ out[k] = this.viewOf(deviceId, k, v, view);
12699
12923
  }
12700
- for (const [k, v] of this.claims.visibleCaps(deviceId)) out[k] = { ...v };
12924
+ for (const [k, v] of this.claims.visibleCaps(deviceId)) out[k] = this.viewOf(deviceId, k, v, view);
12701
12925
  return out;
12702
12926
  }
12703
- /** One cap's EFFECTIVE slice, cloned. Null when the device has never written
12927
+ /** One cap's slice in `view`, cloned. Null when the device has never written
12704
12928
  * it — callers read that as "the cap has no state", never as an empty slice —
12705
12929
  * and null while a claim holds it. */
12706
- capSlice(deviceId, cap) {
12930
+ capSlice(deviceId, cap, view = "effective") {
12931
+ const base = this.baseSlice(deviceId, cap);
12932
+ return base === null ? null : this.viewOf(deviceId, cap, base, view);
12933
+ }
12934
+ /** What the device reported for the cap, or the claim's merge — never a hold. Not cloned. */
12935
+ baseSlice(deviceId, cap) {
12707
12936
  const visible = this.claims.visible(deviceId, cap);
12708
- if (visible !== void 0) return visible ? { ...visible } : null;
12709
- const raw = this.stateMirror.get(deviceId)?.get(cap);
12710
- return raw ? { ...raw } : null;
12937
+ if (visible !== void 0) return visible ? visible : null;
12938
+ return this.stateMirror.get(deviceId)?.get(cap) ?? null;
12939
+ }
12940
+ viewOf(deviceId, cap, base, view) {
12941
+ return view === "confirmed" ? { ...base } : { ...this.holds.overlay(deviceId, cap, base) };
12711
12942
  }
12712
12943
  /** The device's NATIVE slices — what the row stores under the cap names. */
12713
12944
  nativeSnapshotForDevice(deviceId) {
@@ -12719,10 +12950,10 @@ var DeviceStateMirror = class {
12719
12950
  }
12720
12951
  /** Whole-system mirror dump. Backs `deviceState.getAllSnapshots` — one
12721
12952
  * round-trip for a warm boot instead of N per-device calls. */
12722
- allSnapshots() {
12953
+ allSnapshots(view = "effective") {
12723
12954
  const out = {};
12724
12955
  const deviceIds = new Set([...this.stateMirror.keys(), ...this.claims.deviceIds()]);
12725
- for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId);
12956
+ for (const deviceId of deviceIds) out[String(deviceId)] = this.snapshotForDevice(deviceId, view);
12726
12957
  return out;
12727
12958
  }
12728
12959
  /**
@@ -12751,17 +12982,21 @@ var DeviceStateMirror = class {
12751
12982
  }
12752
12983
  /** Remember a restored running bit so the first public merge does not emit a flip. */
12753
12984
  seedRunningFlip(deviceId) {
12754
- const slice = this.capSlice(deviceId, RUNNING_STATE_CAP);
12985
+ const slice = this.capSlice(deviceId, RUNNING_STATE_CAP, "confirmed");
12755
12986
  if (slice === null) return;
12756
12987
  const running = slice["running"];
12757
12988
  this.runningFlip.seed(deviceId, running === true || running === false ? running : null);
12758
12989
  }
12759
12990
  /**
12760
- * The PUBLIC event: exactly `{ deviceId, capName, slice }` for every device,
12761
- * claimed or not. The native shadow never rides here (D224) — see
12762
- * `emitNativeShadow`.
12991
+ * The PUBLIC event: `{ deviceId, capName, slice }` for every device, claimed
12992
+ * or not; `slice` is the EFFECTIVE slice. While a command hold changes it
12993
+ * (D1061), `confirmed` carries the slice without the hold — what history,
12994
+ * automations and the edge detectors below read. The native shadow of a
12995
+ * claim never rides here (D224) — see `emitNativeShadow`.
12763
12996
  */
12764
12997
  emitStateChanged(deviceId, capName, slice) {
12998
+ this.holds.settle(deviceId, capName, slice);
12999
+ const effective = this.holds.overlay(deviceId, capName, slice);
12765
13000
  if (capName === RUNNING_STATE_CAP) {
12766
13001
  const flip = this.runningFlip.note(deviceId, slice);
12767
13002
  if (flip !== null) this.ctx.eventBus.emit({
@@ -12788,10 +13023,15 @@ var DeviceStateMirror = class {
12788
13023
  id: deviceId
12789
13024
  },
12790
13025
  category: require_dist.EventCategory.DeviceStateChanged,
12791
- data: {
13026
+ data: effective === slice ? {
12792
13027
  deviceId,
12793
13028
  capName,
12794
13029
  slice
13030
+ } : {
13031
+ deviceId,
13032
+ capName,
13033
+ slice: { ...effective },
13034
+ confirmed: slice
12795
13035
  }
12796
13036
  });
12797
13037
  }
@@ -12892,15 +13132,15 @@ var CommandObserverRegistry = class {
12892
13132
  } catch {}
12893
13133
  }
12894
13134
  };
12895
- var registry;
13135
+ var registry$1;
12896
13136
  /** The process-wide registry. */
12897
13137
  function getCommandObserverRegistry() {
12898
- registry ??= new CommandObserverRegistry();
12899
- return registry;
13138
+ registry$1 ??= new CommandObserverRegistry();
13139
+ return registry$1;
12900
13140
  }
12901
13141
  /** Test seam: forget every subscriber. */
12902
13142
  function __resetCommandObserverRegistryForTests() {
12903
- registry = void 0;
13143
+ registry$1 = void 0;
12904
13144
  }
12905
13145
  function isRecord(value) {
12906
13146
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -13080,6 +13320,110 @@ function runObservedCommand(sink, facts, call) {
13080
13320
  throw err;
13081
13321
  }
13082
13322
  }
13323
+ //#endregion
13324
+ //#region src/kernel/command-hold-overrides.ts
13325
+ /** The source key of an in-process registration. */
13326
+ var IN_PROCESS_HOLD_SOURCE = "in-process";
13327
+ /** The source key of a forked child's registrations. */
13328
+ function childHoldSource(childId) {
13329
+ return `child:${childId}`;
13330
+ }
13331
+ /** The options a child's cap descriptors carry, one entry per device cap. */
13332
+ function childCommandHoldEntries(caps) {
13333
+ const out = [];
13334
+ for (const cap of caps) {
13335
+ if (cap.deviceId === void 0 || cap.commandHolds === void 0) continue;
13336
+ out.push({
13337
+ deviceId: cap.deviceId,
13338
+ capName: cap.capName,
13339
+ commands: cap.commandHolds
13340
+ });
13341
+ }
13342
+ return out;
13343
+ }
13344
+ function keyOf$1(deviceId, capName) {
13345
+ return `${deviceId}|${capName}`;
13346
+ }
13347
+ var CommandHoldOverrideRegistry = class {
13348
+ bySource = /* @__PURE__ */ new Map();
13349
+ /** Record (or replace) one device cap's options from `source`. */
13350
+ set(source, entry) {
13351
+ const perSource = this.bySource.get(source) ?? /* @__PURE__ */ new Map();
13352
+ perSource.set(keyOf$1(entry.deviceId, entry.capName), entry.commands);
13353
+ this.bySource.set(source, perSource);
13354
+ }
13355
+ /** Forget one device cap's options from `source`. */
13356
+ delete(source, deviceId, capName) {
13357
+ const perSource = this.bySource.get(source);
13358
+ if (perSource === void 0) return;
13359
+ perSource.delete(keyOf$1(deviceId, capName));
13360
+ if (perSource.size === 0) this.bySource.delete(source);
13361
+ }
13362
+ /** Replace everything `source` reported with `entries` (an empty list forgets the source). */
13363
+ replaceSource(source, entries) {
13364
+ if (entries.length === 0) {
13365
+ this.bySource.delete(source);
13366
+ return;
13367
+ }
13368
+ this.bySource.set(source, new Map(entries.map((e) => [keyOf$1(e.deviceId, e.capName), e.commands])));
13369
+ }
13370
+ /** The options for a device cap, from whichever source registered it; `undefined` = default. */
13371
+ get(deviceId, capName) {
13372
+ const key = keyOf$1(deviceId, capName);
13373
+ for (const perSource of this.bySource.values()) {
13374
+ const found = perSource.get(key);
13375
+ if (found !== void 0) return found;
13376
+ }
13377
+ }
13378
+ };
13379
+ var registry;
13380
+ /** The process-wide registry. */
13381
+ function getCommandHoldOverrideRegistry() {
13382
+ registry ??= new CommandHoldOverrideRegistry();
13383
+ return registry;
13384
+ }
13385
+ //#endregion
13386
+ //#region src/builtins/device-manager/command-holds-wiring.ts
13387
+ /**
13388
+ * Arms the command hold (D1061) from the D1022 command seams.
13389
+ *
13390
+ * Every device command the hub sees — its tRPC mount, the UDS parent for a
13391
+ * forked addon's `ctx.api`, an in-process addon's `ctx.api` — reaches the
13392
+ * process-wide observer registry BEFORE the call runs. Here each one resolves
13393
+ * what it leads to (the vocabulary's effects under the provider's option) on
13394
+ * the slice the device last reported, and the mirror holds it; a refused call
13395
+ * rolls the hold back at once.
13396
+ *
13397
+ * Telemetry in, never a gate (D8): a throw here costs the hold, never the call.
13398
+ */
13399
+ /** Subscribe the hold to the command observations; returns the unsubscribe. */
13400
+ function startCommandHolds(deps) {
13401
+ const optionsFor = deps.optionsFor ?? ((deviceId, capName) => getCommandHoldOverrideRegistry().get(deviceId, capName));
13402
+ const unsubscribe = getCommandObserverRegistry().subscribe((obs) => {
13403
+ try {
13404
+ const current = deps.mirror.capSlice(obs.deviceId, obs.capName, "confirmed") ?? void 0;
13405
+ const shown = deps.mirror.capSlice(obs.deviceId, obs.capName) ?? void 0;
13406
+ const option = optionsFor(obs.deviceId, obs.capName)?.[obs.method];
13407
+ const hold = require_dist.resolveCommandHold(obs.capName, obs.method, obs.args, current, option, shown);
13408
+ if (hold === null) return;
13409
+ const token = deps.mirror.holdCommand({
13410
+ deviceId: obs.deviceId,
13411
+ capName: obs.capName,
13412
+ method: obs.method,
13413
+ effects: hold.effects,
13414
+ holdMs: hold.holdMs
13415
+ });
13416
+ if (token === null) return;
13417
+ obs.outcome?.catch(() => deps.mirror.releaseCommand(token, "refused"));
13418
+ } catch (err) {
13419
+ deps.logger.error(`command hold: arming ${obs.capName}.${obs.method} failed: ${err instanceof Error ? err.message : String(err)}`, { tags: { deviceId: obs.deviceId } });
13420
+ }
13421
+ });
13422
+ return () => {
13423
+ unsubscribe();
13424
+ deps.mirror.disposeHolds();
13425
+ };
13426
+ }
13083
13427
  var REDACTED = "***";
13084
13428
  var ROUTING_KEYS = new Set([
13085
13429
  "deviceId",
@@ -13998,6 +14342,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
13998
14342
  stateMirrorImpl = null;
13999
14343
  /** The transition audit (D1022): command + mirror correlation, shipped to device-history. */
14000
14344
  transitions = null;
14345
+ /** Unsubscribes the command hold (D1061). */
14346
+ stopCommandHolds = null;
14001
14347
  /**
14002
14348
  * Removes the claimed-status overlay this addon installed on the capability
14003
14349
  * registry (D663, S3): `getStatus` of a claimed cap answers the mirror for
@@ -14344,6 +14690,10 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
14344
14690
  const metaStore = new DeviceMetaStore(settings, registry, deviceRows, this.addonStoreWriteLock);
14345
14691
  this.stateMirrorImpl = new DeviceStateMirror(this.ctx);
14346
14692
  const stateMirror = this.stateMirrorImpl;
14693
+ this.stopCommandHolds = startCommandHolds({
14694
+ mirror: stateMirror,
14695
+ logger: this.ctx.logger.child("command-holds")
14696
+ });
14347
14697
  this.transitions = startDeviceTransitions({
14348
14698
  mirror: stateMirror,
14349
14699
  logger: this.ctx.logger.child("transitions"),
@@ -14638,13 +14988,13 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
14638
14988
  return stateMirror.snapshotForDevice(input.deviceId);
14639
14989
  },
14640
14990
  getCapSlice: async (input) => {
14641
- return stateMirror.capSlice(input.deviceId, input.capName);
14991
+ return stateMirror.capSlice(input.deviceId, input.capName, input.confirmed === true ? "confirmed" : "effective");
14642
14992
  },
14643
14993
  getNativeCapSlice: async (input) => {
14644
14994
  return stateMirror.nativeSlice(input.deviceId, input.capName);
14645
14995
  },
14646
- getAllSnapshots: async () => {
14647
- return stateMirror.allSnapshots();
14996
+ getAllSnapshots: async (input) => {
14997
+ return stateMirror.allSnapshots(input?.confirmed === true ? "confirmed" : "effective");
14648
14998
  },
14649
14999
  setCapSlice: async (input) => {
14650
15000
  const { deviceId, capName, slice } = input;
@@ -14742,6 +15092,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
14742
15092
  this.templateActions = null;
14743
15093
  await this.transitions?.stop();
14744
15094
  this.transitions = null;
15095
+ this.stopCommandHolds?.();
15096
+ this.stopCommandHolds = null;
14745
15097
  this.removalCleanupImpl?.dispose();
14746
15098
  this.removalCleanupImpl = null;
14747
15099
  this.removalHooksCleanupImpl?.dispose();
@@ -14759,11 +15111,15 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
14759
15111
  exports.CommandObserverRegistry = CommandObserverRegistry;
14760
15112
  exports.DeviceManagerAddon = DeviceManagerAddon;
14761
15113
  exports.default = DeviceManagerAddon;
15114
+ exports.IN_PROCESS_HOLD_SOURCE = IN_PROCESS_HOLD_SOURCE;
14762
15115
  exports.__resetCommandObserverRegistryForTests = __resetCommandObserverRegistryForTests;
14763
15116
  exports.addonCommandActor = addonCommandActor;
15117
+ exports.childCommandHoldEntries = childCommandHoldEntries;
15118
+ exports.childHoldSource = childHoldSource;
14764
15119
  exports.commandActorFromContext = commandActorFromContext;
14765
15120
  exports.commandObserverLink = commandObserverLink;
14766
15121
  exports.createDeviceSettingsStore = createDeviceSettingsStore;
15122
+ exports.getCommandHoldOverrideRegistry = getCommandHoldOverrideRegistry;
14767
15123
  exports.getCommandObserverRegistry = getCommandObserverRegistry;
14768
15124
  exports.mergeAggregates = mergeAggregates;
14769
15125
  exports.observable = observable;