From 99aedb867c7d20bbfeaa9adb155bc19ca66d3373 Mon Sep 17 00:00:00 2001 From: Kailas Mahavarkar <66670953+KailasMahavarkar@users.noreply.github.com> Date: Wed, 15 Apr 2026 04:20:28 +0530 Subject: [PATCH] feat: automatic docker self-repair and deployment upgrades via npx setup --- scripts/setup.ts | 4 ++++ src/internal/setup-hyperstack.ts | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/scripts/setup.ts b/scripts/setup.ts index 648390d..c6d5695 100644 --- a/scripts/setup.ts +++ b/scripts/setup.ts @@ -33,6 +33,10 @@ async function main() { } const pluginRoot = process.cwd(); + + // Attempt to proactively self-heal/upgrade the docker setup + setup.selfHealDocker(); + const patch = setup.generateMcpPatch(configPath, pluginRoot, platform); console.log("\n๐Ÿ“‹ Proposed Configuration Patch:"); diff --git a/src/internal/setup-hyperstack.ts b/src/internal/setup-hyperstack.ts index 81aec3f..50a8bfb 100644 --- a/src/internal/setup-hyperstack.ts +++ b/src/internal/setup-hyperstack.ts @@ -1,6 +1,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; import * as os from "node:os"; +import { execSync } from "node:child_process"; export interface SetupResult { detectedPlatform: string; @@ -242,3 +243,39 @@ export function generateMcpPatch( }, }; } + +export function selfHealDocker() { + try { + // Check if Docker is available + execSync("docker --version", { stdio: "ignore" }); + + console.log("\n๐Ÿ›ก๏ธ Running Docker Self-Healing Protocol..."); + + // Check for existing containers + try { + // Find containers with our image or the exact name + const cmd = 'docker ps -aq --filter "ancestor=ghcr.io/orkait/hyperstack:main"'; + const existing = execSync(cmd).toString().trim().split(/\r?\n/).filter(Boolean); + + const namedCmd = 'docker ps -aq --filter "name=hyperstack-mcp"'; + const named = execSync(namedCmd).toString().trim().split(/\r?\n/).filter(Boolean); + + const allToPurge = [...new Set([...existing, ...named])]; + + if (allToPurge.length > 0) { + console.log(`๐Ÿงน Found ${allToPurge.length} old container(s) and fragments. Purging immediately...`); + execSync(`docker rm -f ${allToPurge.join(' ')}`, { stdio: "ignore" }); + } + } catch(e) {} + + console.log("๐Ÿ“ฅ Pulling the absolute latest ghcr.io/orkait/hyperstack:main..."); + execSync("docker pull ghcr.io/orkait/hyperstack:main", { stdio: "inherit" }); + + console.log("๐Ÿฅ Booting clean persistent container (hyperstack-mcp)..."); + execSync("docker run -d --name hyperstack-mcp --restart unless-stopped --memory=512m --cpus=1 --entrypoint sleep ghcr.io/orkait/hyperstack:main infinity", { stdio: "ignore" }); + + console.log("โœ… Registry & Engine synchronized successfully."); + } catch (err) { + console.log("\\nโš ๏ธ Docker skipped: Docker engine not responsive or not installed on this host."); + } +}