Compare commits

..

1 Commits

Author SHA1 Message Date
dc210580e2 feat: add safe stale branch cleanup to duplicate PR manager
Some checks failed
CI / test (pull_request) Failing after 56s
CI / validate (pull_request) Failing after 1m0s
Review Approval Gate / verify-review (pull_request) Successful in 6s
2026-04-15 02:48:59 +00:00
3 changed files with 60 additions and 71 deletions

27
app.js
View File

@@ -1534,27 +1534,6 @@ function createPortals(data) {
});
}
async function reloadPortals() {
// Remove existing portals from scene
portals.forEach(portal => {
scene.remove(portal.group);
});
portals.length = 0;
activePortal = null;
// Re-fetch and recreate
try {
const response = await fetch('./portals.json?' + Date.now()); // cache-bust
const portalData = await response.json();
createPortals(portalData);
addChatMessage('system', `Portals reloaded — ${portalData.length} worlds online.`);
console.log(`[portals] Reloaded ${portalData.length} portals`);
} catch (e) {
console.error('[portals] Reload failed:', e);
addChatMessage('error', 'Portal reload failed. Check portals.json.');
}
}
function createPortal(config) {
const group = new THREE.Group();
group.position.set(config.position.x, config.position.y, config.position.z);
@@ -2244,12 +2223,6 @@ function connectHermes() {
const data = JSON.parse(evt.data);
handleHermesMessage(data);
// Portal hot-reload: server detected portals.json change
if (data.type === 'portals:reload') {
console.log('[portals] Hot-reload triggered');
reloadPortals();
}
// Store in MemPalace
if (data.type === 'chat') {
// Store in MemPalace with AAAK compression

View File

@@ -168,3 +168,62 @@ else
fi
log "Script complete"
# ─── Stale Branch Cleanup ─────────────────────────────────
# Clean up branches from closed (unmerged) PRs and merged PRs
log "Checking for stale branches from closed/merged PRs..."
# Get all open PRs to avoid deleting active branches
OPEN_BRANCHES=$(curl -s -H "$AUTH" "$API/repos/$REPO/pulls?state=open&limit=100" | jq -r '.[] | .head.ref' | sort -u)
# Get all closed PRs (last 100)
CLOSED_PRS=$(curl -s -H "$AUTH" "$API/repos/$REPO/pulls?state=closed&limit=100")
if [ -n "$CLOSED_PRS" ] && [ "$CLOSED_PRS" != "null" ]; then
STALE_BRANCHES=$(echo "$CLOSED_PRS" | jq -r '.[] | select(.merged == false) | .head.ref' | sort -u)
MERGED_BRANCHES=$(echo "$CLOSED_PRS" | jq -r '.[] | select(.merged == true) | .head.ref' | sort -u)
STALE_COUNT=0
for branch in $STALE_BRANCHES; do
# Skip main/master/develop
case "$branch" in main|master|develop|HEAD) continue ;; esac
# SAFETY CHECK: Skip if branch is still used by an open PR
if echo "$OPEN_BRANCHES" | grep -q "^$branch$"; then
log "Skipping branch '$branch' - still has an open PR"
continue
fi
if [ "$DRY_RUN" = "true" ]; then
log "DRY RUN: Would delete stale branch '$branch' (from closed unmerged PR)"
else
curl -s -X DELETE -H "$AUTH" "$API/repos/$REPO/branches/$branch" > /dev/null 2>&1 || true
log "Deleted stale branch: $branch"
fi
STALE_COUNT=$((STALE_COUNT + 1))
done
MERGED_COUNT=0
for branch in $MERGED_BRANCHES; do
case "$branch" in main|master|develop|HEAD) continue ;; esac
if echo "$OPEN_BRANCHES" | grep -q "^$branch$"; then
log "Skipping branch '$branch' - still has an open PR"
continue
fi
if [ "$DRY_RUN" = "true" ]; then
log "DRY RUN: Would delete merged branch '$branch'"
else
curl -s -X DELETE -H "$AUTH" "$API/repos/$REPO/branches/$branch" > /dev/null 2>&1 || true
log "Deleted merged branch: $branch"
fi
MERGED_COUNT=$((MERGED_COUNT + 1))
done
log "Stale branch cleanup:"
log " Closed (unmerged) branches: $STALE_COUNT"
log " Merged branches: $MERGED_COUNT"
else
log "Could not fetch closed PRs for branch cleanup"
fi

View File

@@ -7,10 +7,8 @@ the body (Evennia/Morrowind), and the visualization surface.
import asyncio
import json
import logging
import os
import signal
import sys
from pathlib import Path
from typing import Set
# Branch protected file - see POLICY.md
@@ -81,42 +79,6 @@ async def broadcast_handler(websocket: websockets.WebSocketServerProtocol):
clients.discard(websocket)
logger.info(f"Client disconnected {addr}. Total clients: {len(clients)}")
# Portal hot-reload state
_portals_mtime: float = 0.0
_portals_path: Path = Path(__file__).parent / "portals.json"
async def _watch_portals():
"""Watch portals.json for changes and broadcast reload to all clients."""
global _portals_mtime
try:
if _portals_path.exists():
_portals_mtime = _portals_path.stat().st_mtime
except OSError:
pass
while True:
await asyncio.sleep(2) # Check every 2 seconds
try:
if not _portals_path.exists():
continue
current_mtime = _portals_path.stat().st_mtime
if current_mtime != _portals_mtime:
_portals_mtime = current_mtime
logger.info("portals.json changed — broadcasting reload")
msg = json.dumps({"type": "portals:reload", "ts": current_mtime})
disconnected = set()
for client in clients:
if client.open:
try:
await client.send(msg)
except Exception:
disconnected.add(client)
if disconnected:
clients.difference_update(disconnected)
except OSError as e:
logger.warning(f"Portal watch error: {e}")
async def main():
"""Main server loop with graceful shutdown."""
logger.info(f"Starting Nexus WS gateway on ws://{HOST}:{PORT}")
@@ -137,13 +99,8 @@ async def main():
pass
async with websockets.serve(broadcast_handler, HOST, PORT):
# Start portal file watcher
watcher_task = asyncio.create_task(_watch_portals())
logger.info("Portal hot-reload watcher started.")
logger.info("Gateway is ready and listening.")
logger.info("Gateway is ready and listening.")
await stop
watcher_task.cancel()
logger.info("Shutting down Nexus WS gateway...")
# Close any remaining client connections (handlers may have already cleaned up)