Skip to content

feat(queen): Queen Self-Improving Container β€” Backend API + Docker + CI/CDΒ #476

@gHashTag

Description

@gHashTag

🎯 Objective

Deploy Queen as a self-improving container service with HTTP/JSON API,
WebSocket realtime updates, and autonomous improvement loop via .tri + .t27 pipeline.

πŸ“‹ Context

Queen UI (SwiftUI) = native macOS only. For cloud deployment and autonomous
self-improvement, we need containerized Queen-as-a-Service.

Existing code to build upon:

  • src/tri/queen/self_learning.zig β€” Self-learning engine (Phase 5)
  • src/tri/queen/episodes.zig β€” Episode management
  • src/tri/queen/experience.zig β€” Experience recall
  • src/tri/queen/lotus_cycle.zig β€” Lotus Cycle (Phase 4)
  • src/tri/queen/tri27_bridge.zig β€” TRI-27 integration (15/15 tests)
  • src/tri/queen/github_comment.zig β€” GitHub commenting

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ Railway Container ────────────────┐
β”‚  Queen Backend (Zig) β†’ HTTP/JSON + WebSocket      β”‚
β”‚  Self-Improvement Loop β†’ .tri spec β†’ .t27 exec    β”‚
β”‚  Frontend (React+Vite) β†’ Three Kingdoms Dashboard β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Checklist (tri CLI flow)

Phase 1: Backend API (Week 1)

  • src/tri/queen/backend_server.zig β€” HTTP/JSON + WebSocket
    • GET /api/status β€” system state + sacred constants
    • GET /api/episodes β€” recent episodes from .trinity/experience/
    • POST /api/improve β€” trigger self-improvement cycle
    • GET /api/pipeline β€” pipeline status
    • GET /health β€” Railway health check
    • WS /ws β€” realtime updates
  • src/tri/queen/auto_improve.zig β€” self-improvement orchestration
    • Load recent episodes β†’ analyze patterns via TVC
    • Generate .tri spec β†’ run .t27 algorithms
    • Apply via VIBEE codegen β†’ validate β†’ deploy
  • src/tri/queen/episode_to_tri.zig β€” episode β†’ .tri spec converter
  • Modify build.zig β€” add queen-backend build target
  • Modify src/tri/main.zig β€” add tri queen-backend command

Phase 2: Frontend (Week 2)

  • apps/queen-web/ β€” React + Vite app
    • ThreeKingdoms.tsx (Brain, Body, Spirit tabs)
    • StatusDashboard.tsx (realtime metrics)
    • EpisodeViewer.tsx (experience log)
    • ImprovementPanel.tsx (self-improvement controls)
  • WebSocket client for realtime updates

Phase 3: Docker + Deploy (Week 3)

  • deploy/Dockerfile.queen β€” multi-stage build
    • Stage 1: Frontend build (node:20-alpine)
    • Stage 2: Zig backend (ubuntu:22.04 + Zig 0.15)
    • Stage 3: Runtime image (minimal)
  • .github/workflows/queen-deploy.yml β€” CI/CD to Railway
  • deploy/fly.toml.queen β€” Fly.io alternative config

Phase 4: Self-Improvement Integration (Week 4)

  • specs/tri/queen/self_improvement.tri β€” pipeline spec
  • Wire auto_improve.zig ↔ self_learning.zig ↔ tri27_bridge.zig
  • Episode β†’ Pattern Detection β†’ .tri Spec β†’ .t27 Execution β†’ VIBEE Codegen
  • Update .trinity/queen/tri27_config.json β€” auto-adapt settings

Phase 5: Validation (Week 5)

  • zig build queen-backend && ./zig-out/bin/queen-backend --test
  • docker build -f deploy/Dockerfile.queen -t queen:test .
  • curl http://localhost:8080/health β†’ 200 OK
  • curl -X POST http://localhost:8080/api/improve β†’ triggers loop
  • Documentation in docs/queen/CONTAINER.md

πŸ”§ Agent Instructions

tri dev scan          β†’ read this issue + .trinity/experience/similar_tasks.json
tri dev pick --smart  β†’ Phase 1 first (backend_server.zig is critical path)
tri issue comment 476 β†’ πŸ” [RESEARCH] Step 1/10
tri spec create       β†’ reuse specs/tri/queen/self_improvement.tri template
tri gen               β†’ .tri β†’ .zig + tri issue comment "βš™οΈ [CODEGEN]"
tri test              β†’ IF FAIL β†’ save to .trinity/mistakes/
tri verdict --toxic   β†’ compare with past verdicts
tri experience save   β†’ save episode + learnings + mistakes
tri git commit        β†’ tri issue comment "βœ… [DONE]"
tri loop decide       β†’ continue to next phase or stop

⚠️ Constraints

  • Do NOT touch apps/queen/ (SwiftUI β€” leave as-is)
  • Reuse existing src/tri/queen/*.zig β€” DO NOT rewrite
  • Railway preferred over Fly.io (MCP already integrated)
  • Max container memory: 512MB (Railway free tier)
  • All endpoints must return JSON with φ²+φ⁻²=3 validation header

πŸ”— Dependencies

πŸ“Š Success Criteria

  • queen-backend binary builds clean
  • 5 HTTP endpoints respond correctly
  • WebSocket streams episode updates
  • Docker image < 200MB
  • Self-improvement loop executes at least 1 cycle
  • Railway deployment accessible via public URL

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions