Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Whitestone
339f7d6ef2 fix: [PORTAL] Add honest local Bannerlord readiness/status to the Nexus (closes #724)
Some checks failed
CI / test (pull_request) Failing after 9s
CI / validate (pull_request) Failing after 12s
Review Approval Gate / verify-review (pull_request) Failing after 3s
2026-04-10 20:17:11 -04:00
6 changed files with 223 additions and 123 deletions

79
app.js
View File

@@ -2429,6 +2429,15 @@ function activatePortal(portal) {
overlay.style.display = 'flex';
// Readiness detail for game-world portals
const readinessEl = document.getElementById('portal-readiness-detail');
if (portal.config.portal_type === 'game-world' && portal.config.readiness_steps) {
renderReadinessDetail(readinessEl, portal.config);
readinessEl.style.display = 'block';
} else {
readinessEl.style.display = 'none';
}
if (portal.config.destination && portal.config.destination.url) {
redirectBox.style.display = 'block';
errorBox.style.display = 'none';
@@ -2450,6 +2459,37 @@ function activatePortal(portal) {
}
}
// ═══ READINESS RENDERING ═══
function renderReadinessDetail(container, config) {
const steps = config.readiness_steps || {};
const stepKeys = ['downloaded', 'runtime_ready', 'launched', 'harness_bridged'];
let html = '<div class="portal-readiness-title">READINESS PIPELINE</div>';
let firstUndone = true;
stepKeys.forEach(key => {
const step = steps[key];
if (!step) return;
const cls = step.done ? 'done' : (firstUndone ? 'current' : '');
if (!step.done) firstUndone = false;
html += `<div class="portal-readiness-step ${cls}">
<span class="step-dot"></span>
<span>${step.label || key}</span>
</div>`;
});
if (config.blocked_reason) {
html += `<div class="portal-readiness-blocked">&#x26A0; ${config.blocked_reason}</div>`;
}
const doneCount = stepKeys.filter(k => steps[k]?.done).length;
const canEnter = doneCount === stepKeys.length && config.destination?.url;
if (!canEnter) {
html += `<div class="portal-readiness-hint">Cannot enter yet — ${stepKeys.length - doneCount} step${stepKeys.length - doneCount > 1 ? 's' : ''} remaining.</div>`;
}
container.innerHTML = html;
}
function closePortalOverlay() {
portalOverlayActive = false;
document.getElementById('portal-overlay').style.display = 'none';
@@ -2530,12 +2570,42 @@ function populateAtlas() {
const statusClass = `status-${config.status || 'online'}`;
// Build readiness section for game-world portals
let readinessHtml = '';
if (config.portal_type === 'game-world' && config.readiness_steps) {
const stepKeys = ['downloaded', 'runtime_ready', 'launched', 'harness_bridged'];
const steps = config.readiness_steps;
const doneCount = stepKeys.filter(k => steps[k]?.done).length;
const pct = Math.round((doneCount / stepKeys.length) * 100);
const barColor = config.color || '#ffd700';
readinessHtml = `<div class="atlas-card-readiness">
<div class="readiness-bar-track">
<div class="readiness-bar-fill" style="width:${pct}%;background:${barColor};"></div>
</div>
<div class="readiness-steps-mini">`;
let firstUndone = true;
stepKeys.forEach(key => {
const step = steps[key];
if (!step) return;
const cls = step.done ? 'done' : (firstUndone ? 'current' : '');
if (!step.done) firstUndone = false;
readinessHtml += `<span class="readiness-step ${cls}">${step.label || key}</span>`;
});
readinessHtml += '</div>';
if (config.blocked_reason) {
readinessHtml += `<div class="atlas-card-blocked">&#x26A0; ${config.blocked_reason}</div>`;
}
readinessHtml += '</div>';
}
card.innerHTML = `
<div class="atlas-card-header">
<div class="atlas-card-name">${config.name}</div>
<div class="atlas-card-status ${statusClass}">${config.status || 'ONLINE'}</div>
<div class="atlas-card-status ${statusClass}">${config.readiness_state || config.status || 'ONLINE'}</div>
</div>
<div class="atlas-card-desc">${config.description}</div>
${readinessHtml}
<div class="atlas-card-footer">
<div class="atlas-card-coord">X:${config.position.x} Z:${config.position.z}</div>
<div class="atlas-card-type">${config.destination?.type?.toUpperCase() || 'UNKNOWN'}</div>
@@ -2553,11 +2623,14 @@ function populateAtlas() {
document.getElementById('atlas-online-count').textContent = onlineCount;
document.getElementById('atlas-standby-count').textContent = standbyCount;
// Update Bannerlord HUD status
// Update Bannerlord HUD status with honest readiness state
const bannerlord = portals.find(p => p.config.id === 'bannerlord');
if (bannerlord) {
const statusEl = document.getElementById('bannerlord-status');
statusEl.className = 'hud-status-item ' + (bannerlord.config.status || 'offline');
const state = bannerlord.config.readiness_state || bannerlord.config.status || 'offline';
statusEl.className = 'hud-status-item ' + state;
const labelEl = statusEl.querySelector('.status-label');
if (labelEl) labelEl.textContent = state.toUpperCase().replace(/_/g, ' ');
}
}

View File

@@ -60,23 +60,6 @@ If the heartbeat is older than --stale-threshold seconds, the
mind is considered dead even if the process is still running
(e.g., hung on a blocking call).
KIMI HEARTBEAT
==============
The Kimi triage pipeline writes a cron heartbeat file after each run:
/var/run/bezalel/heartbeats/kimi-heartbeat.last
(fallback: ~/.bezalel/heartbeats/kimi-heartbeat.last)
{
"job": "kimi-heartbeat",
"timestamp": 1711843200.0,
"interval_seconds": 900,
"pid": 12345,
"status": "ok"
}
If the heartbeat is stale (>2x declared interval), the watchdog reports
a Kimi Heartbeat failure alongside the other checks.
ZERO DEPENDENCIES
=================
Pure stdlib. No pip installs. Same machine as the nexus.
@@ -121,10 +104,6 @@ DEFAULT_HEARTBEAT_PATH = Path.home() / ".nexus" / "heartbeat.json"
DEFAULT_STALE_THRESHOLD = 300 # 5 minutes without a heartbeat = dead
DEFAULT_INTERVAL = 60 # seconds between checks in watch mode
# Kimi Heartbeat — cron job heartbeat file written by the triage pipeline
KIMI_HEARTBEAT_JOB = "kimi-heartbeat"
KIMI_HEARTBEAT_STALE_MULTIPLIER = 2.0 # stale at 2x declared interval
GITEA_URL = os.environ.get("GITEA_URL", "https://forge.alexanderwhitestone.com")
GITEA_TOKEN = os.environ.get("GITEA_TOKEN", "")
GITEA_REPO = os.environ.get("NEXUS_REPO", "Timmy_Foundation/the-nexus")
@@ -366,93 +345,6 @@ def check_syntax_health() -> CheckResult:
)
def check_kimi_heartbeat(
job: str = KIMI_HEARTBEAT_JOB,
stale_multiplier: float = KIMI_HEARTBEAT_STALE_MULTIPLIER,
) -> CheckResult:
"""Check if the Kimi Heartbeat cron job is alive.
Reads the ``<job>.last`` file from the standard Bezalel heartbeat
directory (``/var/run/bezalel/heartbeats/`` or fallback
``~/.bezalel/heartbeats/``). The file is written atomically by the
cron_heartbeat module after each successful triage pipeline run.
A job is stale when:
``time.time() - timestamp > stale_multiplier * interval_seconds``
(same rule used by ``check_cron_heartbeats.py``).
"""
# Resolve heartbeat directory — same logic as cron_heartbeat._resolve
primary = Path("/var/run/bezalel/heartbeats")
fallback = Path.home() / ".bezalel" / "heartbeats"
env_dir = os.environ.get("BEZALEL_HEARTBEAT_DIR")
if env_dir:
hb_dir = Path(env_dir)
elif primary.exists():
hb_dir = primary
elif fallback.exists():
hb_dir = fallback
else:
return CheckResult(
name="Kimi Heartbeat",
healthy=False,
message="Heartbeat directory not found — no triage pipeline deployed yet",
details={"searched": [str(primary), str(fallback)]},
)
hb_file = hb_dir / f"{job}.last"
if not hb_file.exists():
return CheckResult(
name="Kimi Heartbeat",
healthy=False,
message=f"No heartbeat file at {hb_file} — Kimi triage pipeline has never reported",
details={"path": str(hb_file)},
)
try:
data = json.loads(hb_file.read_text())
except (json.JSONDecodeError, OSError) as e:
return CheckResult(
name="Kimi Heartbeat",
healthy=False,
message=f"Heartbeat file corrupt: {e}",
details={"path": str(hb_file), "error": str(e)},
)
timestamp = float(data.get("timestamp", 0))
interval = int(data.get("interval_seconds", 0))
raw_status = data.get("status", "unknown")
age = time.time() - timestamp
if interval <= 0:
# No declared interval — use raw timestamp age (30 min default)
interval = 1800
threshold = stale_multiplier * interval
is_stale = age > threshold
age_str = f"{int(age)}s" if age < 3600 else f"{int(age // 3600)}h {int((age % 3600) // 60)}m"
interval_str = f"{int(interval)}s" if interval < 3600 else f"{int(interval // 3600)}h {int((interval % 3600) // 60)}m"
if is_stale:
return CheckResult(
name="Kimi Heartbeat",
healthy=False,
message=(
f"Silent for {age_str} "
f"(threshold: {stale_multiplier}x {interval_str} = {int(threshold)}s). "
f"Status: {raw_status}"
),
details=data,
)
return CheckResult(
name="Kimi Heartbeat",
healthy=True,
message=f"Alive — last beat {age_str} ago (interval {interval_str}, status={raw_status})",
details=data,
)
# ── Gitea alerting ───────────────────────────────────────────────────
def _gitea_request(method: str, path: str, data: Optional[dict] = None) -> Any:
@@ -554,7 +446,6 @@ def run_health_checks(
check_mind_process(),
check_heartbeat(heartbeat_path, stale_threshold),
check_syntax_health(),
check_kimi_heartbeat(),
]
return HealthReport(timestamp=time.time(), checks=checks)
@@ -654,14 +545,6 @@ def main():
"--json", action="store_true", dest="output_json",
help="Output results as JSON (for integration with other tools)",
)
parser.add_argument(
"--kimi-job", default=KIMI_HEARTBEAT_JOB,
help=f"Kimi heartbeat job name (default: {KIMI_HEARTBEAT_JOB})",
)
parser.add_argument(
"--kimi-stale-multiplier", type=float, default=KIMI_HEARTBEAT_STALE_MULTIPLIER,
help=f"Kimi heartbeat staleness multiplier (default: {KIMI_HEARTBEAT_STALE_MULTIPLIER})",
)
args = parser.parse_args()

View File

@@ -196,6 +196,7 @@
</div>
<h2 id="portal-name-display">MORROWIND</h2>
<p id="portal-desc-display">The Vvardenfell harness. Ash storms and ancient mysteries.</p>
<div id="portal-readiness-detail" class="portal-readiness-detail" style="display:none;"></div>
<div class="portal-redirect-box" id="portal-redirect-box">
<div class="portal-redirect-label">REDIRECTING IN</div>
<div class="portal-redirect-timer" id="portal-timer">5</div>

View File

@@ -17,7 +17,7 @@
"id": "bannerlord",
"name": "Bannerlord",
"description": "Calradia battle harness. Massive armies, tactical command.",
"status": "active",
"status": "downloaded",
"color": "#ffd700",
"position": { "x": -15, "y": 0, "z": -10 },
"rotation": { "y": 0.5 },
@@ -25,13 +25,20 @@
"world_category": "strategy-rpg",
"environment": "production",
"access_mode": "operator",
"readiness_state": "active",
"readiness_state": "downloaded",
"readiness_steps": {
"downloaded": { "label": "Downloaded", "done": true },
"runtime_ready": { "label": "Runtime Ready", "done": false },
"launched": { "label": "Launched", "done": false },
"harness_bridged": { "label": "Harness Bridged", "done": false }
},
"blocked_reason": null,
"telemetry_source": "hermes-harness:bannerlord",
"owner": "Timmy",
"app_id": 261550,
"window_title": "Mount & Blade II: Bannerlord",
"destination": {
"url": "https://bannerlord.timmy.foundation",
"url": null,
"type": "harness",
"action_label": "Enter Calradia",
"params": { "world": "calradia" }

136
style.css
View File

@@ -367,6 +367,142 @@ canvas#nexus-canvas {
.status-online { background: rgba(74, 240, 192, 0.2); color: var(--color-primary); border: 1px solid var(--color-primary); }
.status-standby { background: rgba(255, 215, 0, 0.2); color: var(--color-gold); border: 1px solid var(--color-gold); }
.status-offline { background: rgba(255, 68, 102, 0.2); color: var(--color-danger); border: 1px solid var(--color-danger); }
.status-active { background: rgba(74, 240, 192, 0.2); color: var(--color-primary); border: 1px solid var(--color-primary); }
.status-blocked { background: rgba(255, 68, 102, 0.3); color: #ff4466; border: 1px solid #ff4466; }
.status-downloaded { background: rgba(100, 149, 237, 0.2); color: #6495ed; border: 1px solid #6495ed; }
.status-runtime_ready { background: rgba(255, 165, 0, 0.2); color: #ffa500; border: 1px solid #ffa500; }
.status-launched { background: rgba(255, 215, 0, 0.2); color: var(--color-gold); border: 1px solid var(--color-gold); }
.status-harness_bridged { background: rgba(74, 240, 192, 0.2); color: var(--color-primary); border: 1px solid var(--color-primary); }
/* Readiness Progress Bar (atlas card) */
.atlas-card-readiness {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(255,255,255,0.06);
}
.readiness-bar-track {
width: 100%;
height: 4px;
background: rgba(255,255,255,0.08);
border-radius: 2px;
overflow: hidden;
margin-bottom: 6px;
}
.readiness-bar-fill {
height: 100%;
border-radius: 2px;
transition: width 0.4s ease;
}
.readiness-steps-mini {
display: flex;
gap: 6px;
font-size: 9px;
font-family: var(--font-body);
letter-spacing: 0.05em;
color: var(--color-text-muted);
}
.readiness-step {
padding: 1px 5px;
border-radius: 2px;
background: rgba(255,255,255,0.04);
}
.readiness-step.done {
background: rgba(74, 240, 192, 0.15);
color: var(--color-primary);
}
.readiness-step.current {
background: rgba(255, 215, 0, 0.15);
color: var(--color-gold);
}
.atlas-card-blocked {
margin-top: 6px;
font-size: 10px;
color: #ff4466;
font-family: var(--font-body);
}
/* Readiness Detail (portal overlay) */
.portal-readiness-detail {
margin-top: 16px;
padding: 12px 16px;
background: rgba(0,0,0,0.3);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 4px;
}
.portal-readiness-title {
font-family: var(--font-display);
font-size: 10px;
letter-spacing: 0.15em;
color: var(--color-text-muted);
margin-bottom: 10px;
text-transform: uppercase;
}
.portal-readiness-step {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 0;
font-family: var(--font-body);
font-size: 11px;
color: rgba(255,255,255,0.4);
}
.portal-readiness-step .step-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: rgba(255,255,255,0.15);
flex-shrink: 0;
}
.portal-readiness-step.done .step-dot {
background: var(--color-primary);
box-shadow: 0 0 6px var(--color-primary);
}
.portal-readiness-step.done {
color: var(--color-primary);
}
.portal-readiness-step.current .step-dot {
background: var(--color-gold);
box-shadow: 0 0 6px var(--color-gold);
animation: pulse-dot 1.5s ease-in-out infinite;
}
.portal-readiness-step.current {
color: #fff;
}
@keyframes pulse-dot {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.portal-readiness-blocked {
margin-top: 8px;
padding: 6px 10px;
background: rgba(255, 68, 102, 0.1);
border: 1px solid rgba(255, 68, 102, 0.3);
border-radius: 3px;
font-size: 11px;
color: #ff4466;
font-family: var(--font-body);
}
.portal-readiness-hint {
margin-top: 8px;
font-size: 10px;
color: var(--color-text-muted);
font-family: var(--font-body);
font-style: italic;
}
/* HUD Status for readiness states */
.hud-status-item.downloaded .status-dot { background: #6495ed; box-shadow: 0 0 5px #6495ed; }
.hud-status-item.runtime_ready .status-dot { background: #ffa500; box-shadow: 0 0 5px #ffa500; }
.hud-status-item.launched .status-dot { background: var(--color-gold); box-shadow: 0 0 5px var(--color-gold); }
.hud-status-item.harness_bridged .status-dot { background: var(--color-primary); box-shadow: 0 0 5px var(--color-primary); }
.hud-status-item.blocked .status-dot { background: #ff4466; box-shadow: 0 0 5px #ff4466; }
.hud-status-item.downloaded .status-label,
.hud-status-item.runtime_ready .status-label,
.hud-status-item.launched .status-label,
.hud-status-item.harness_bridged .status-label,
.hud-status-item.blocked .status-label {
color: #fff;
}
.atlas-card-desc {
font-size: 12px;