|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/09/2026 |
| 5 | +PromotionGatePanel.js |
| 6 | +*/ |
| 7 | + |
| 8 | +import { drawPanel } from '../DebugPanel.js'; |
| 9 | + |
| 10 | +function asObject(value) { |
| 11 | + return value && typeof value === 'object' && !Array.isArray(value) ? value : {}; |
| 12 | +} |
| 13 | + |
| 14 | +function resolvePromotionStatus(source) { |
| 15 | + const snapshot = asObject(source); |
| 16 | + const evaluation = asObject(snapshot.lastEvaluation); |
| 17 | + const status = asObject(snapshot.status); |
| 18 | + const handoff = asObject(status.handoff).toMode ? status.handoff : asObject(evaluation.handoff); |
| 19 | + const abort = asObject(status.abort).decisionPath ? status.abort : asObject(evaluation.abort); |
| 20 | + const mode = typeof status.mode === 'string' && status.mode |
| 21 | + ? status.mode |
| 22 | + : (typeof evaluation.mode === 'string' && evaluation.mode ? evaluation.mode : 'passive'); |
| 23 | + return { |
| 24 | + mode, |
| 25 | + handoff, |
| 26 | + abort, |
| 27 | + reason: String(snapshot.lastReason || evaluation.reason || ''), |
| 28 | + stability: asObject(evaluation.stability) |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +export function getPromotionGatePanelLines(promotionState) { |
| 33 | + const status = resolvePromotionStatus(promotionState); |
| 34 | + const handoffLabel = status.handoff.toMode |
| 35 | + ? `${String(status.handoff.fromMode || 'passive')} -> ${String(status.handoff.toMode)}` |
| 36 | + : 'n/a'; |
| 37 | + const abortVisible = status.abort.rollbackTriggered === true || status.abort.aborted === true; |
| 38 | + const abortLabel = abortVisible |
| 39 | + ? `${status.abort.aborted === true ? 'ABORTED' : 'VISIBLE'} (${String(status.abort.reason || 'rollback')})` |
| 40 | + : 'no'; |
| 41 | + |
| 42 | + return [ |
| 43 | + `Mode: ${status.mode}`, |
| 44 | + `Handoff: ${handoffLabel}`, |
| 45 | + `Abort: ${abortLabel}`, |
| 46 | + `Stable: ${Number(status.stability.currentFrames || 0)}/${Number(status.stability.requiredFrames || 0)}`, |
| 47 | + `Reason: ${status.reason || 'n/a'}` |
| 48 | + ]; |
| 49 | +} |
| 50 | + |
| 51 | +export function drawPromotionGatePanel(renderer, promotionState, { |
| 52 | + x = 620, |
| 53 | + y = 184, |
| 54 | + width = 300, |
| 55 | + height = 146, |
| 56 | + title = 'Promotion Gate' |
| 57 | +} = {}) { |
| 58 | + drawPanel(renderer, x, y, width, height, title, getPromotionGatePanelLines(promotionState)); |
| 59 | +} |
0 commit comments