From b40b2c736ff58af4cc68b57dc2ebe321dd61454d Mon Sep 17 00:00:00 2001 From: znetsixe Date: Fri, 29 May 2026 18:41:15 +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 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/commands/handlers.js b/src/commands/handlers.js index fe700c6..1eb1205 100644 --- a/src/commands/handlers.js +++ b/src/commands/handlers.js @@ -7,23 +7,33 @@ function _logger(source, ctx) { return ctx?.logger || source?.logger || null; } function _send(ctx, ports) { if (typeof ctx?.send === 'function') ctx.send(ports); } +// Resolve the command origin (control authority: parent | GUI | fysical). +// The shared commandRegistry stamps msg.origin (default 'parent'); legacy flows +// carried it as payload.source. Prefer the legacy field when present so existing +// flows keep working, otherwise use the registry-stamped msg.origin. +function _origin(msg) { + const p = msg && msg.payload; + if (p && typeof p === 'object' && typeof p.source === 'string' && p.source) return p.source; + return (typeof msg?.origin === 'string' && msg.origin) ? msg.origin : 'parent'; +} + exports.setMode = (source, msg) => { source.setMode(msg.payload); }; exports.startup = async (source, msg) => { const p = msg.payload || {}; - await source.handleInput(p.source ?? 'parent', 'execSequence', 'startup'); + await source.handleInput(_origin(msg), 'execSequence', 'startup'); }; exports.shutdown = async (source, msg) => { const p = msg.payload || {}; - await source.handleInput(p.source ?? 'parent', 'execSequence', 'shutdown'); + await source.handleInput(_origin(msg), 'execSequence', 'shutdown'); }; exports.estop = async (source, msg) => { const p = msg.payload || {}; - await source.handleInput(p.source ?? 'parent', p.action ?? 'emergencystop'); + await source.handleInput(_origin(msg), p.action ?? 'emergencystop'); }; // Legacy umbrella: payload.action selects the canonical verb. @@ -41,7 +51,7 @@ exports.execSequenceAlias = async (source, msg, ctx) => { exports.setPosition = async (source, msg) => { const p = msg.payload || {}; const action = p.action ?? 'execMovement'; - await source.handleInput(p.source ?? 'parent', action, Number(p.setpoint)); + await source.handleInput(_origin(msg), action, Number(p.setpoint)); }; exports.dataFlow = (source, msg) => {