From 19720bd67f8c6fffc1705f53c63a4a04538845d4 Mon Sep 17 00:00:00 2001 From: znetsixe Date: Fri, 29 May 2026 18:41:17 +0200 Subject: [PATCH] =?UTF-8?q?feat(commands):=20adopt=20unified=20command=20e?= =?UTF-8?q?nvelope=20=E2=80=94=20msg.origin=20provenance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve command origin via msg.origin (registry-stamped, default parent) with a legacy fallback to the previous payload.source/msg.source field. Feeds the existing mode/allowedSources arbitration unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/commands/handlers.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commands/handlers.js b/src/commands/handlers.js index 46d1797..9253ad7 100644 --- a/src/commands/handlers.js +++ b/src/commands/handlers.js @@ -23,12 +23,20 @@ function _gate(source, action, msg) { if (!source.isValidActionForMode(action, source.mode)) return false; } if (typeof source?.isValidSourceForMode === 'function') { - const src = (typeof msg?.source === 'string' && msg.source) ? msg.source : 'parent'; - if (!source.isValidSourceForMode(src, source.mode)) return false; + if (!source.isValidSourceForMode(_origin(msg), source.mode)) return false; } return true; } +// Resolve the command origin (control authority: parent | GUI | fysical). +// The shared commandRegistry stamps msg.origin (default 'parent'); legacy flows +// carried it as msg.source. Prefer the legacy field when present so existing +// flows keep working, otherwise use the registry-stamped msg.origin. +function _origin(msg) { + if (typeof msg?.source === 'string' && msg.source) return msg.source; + return (typeof msg?.origin === 'string' && msg.origin) ? msg.origin : 'parent'; +} + exports.setMode = (source, msg) => { // set.mode is a status-level operation — allowed in every mode by the // default schema (incl. maintenance). The gate still fires so an