HYNA-Stage 第 6 天:KAVLR 編年史與以 $150 手機打造的 90 篇文章 AI 憲章
Day 6 of Building HYNA-Stage: The KAVLR Chronicles & A 90-Article AI Constitution Built on a $150 Phone 🐯🛡️
HYNA-Stage 和 KAVLR 的建置者公開兩項系統的技術架構、除錯經過及安全設計;整套系統以 Termux 和 $150 Android 手機開發。KAVLR v1.0.5 透過 90 篇文章構成的 AI 憲章評估指令,評分達 90 才允許執行,低於 90 則封鎖。HYNA-Stage 使用 E2B Firecracker MicroVM,目標是在 5 秒內配置隔離的程式碼部署環境。
Good evening. It's October 26.
Welcome to Day 6 of Building HYNA-Stage.
If you’ve been following this journey, you know we aren't just building tools; we are building the secure, ephemeral infrastructure for the AI era. And we are doing it under the most extreme constraint possible: a $150 Android phone using Termux.
Today, I’m pulling back the curtain completely. No marketing fluff. Just the raw technical architecture, the emotional post-mortem, and the "Hall of Bugs" we conquered to bring HYNA-Stage and KAVLR to life.
Technical Report & Post-Mortem: HYNA-Stage & KAVLR
Part 1: Technical Architecture
1. HYNA-Stage (Ephemeral Cloud Sandboxes)
Purpose: Provision isolated MicroVMs for code deployment in under 5 seconds.
- Client Interface: Node.js CLI (
@hynaweb/stage). Uses nativefetch,commander,chalk, andora. Stores local JWT session at~/.hyna-stage(chmod 600). - Backend: Supabase Edge Functions (Deno runtime).
- Compute Provider: E2B SDK (
@e2b/code-interpreter). - Database: Supabase PostgreSQL.
- Execution Flow:
- User authenticates via
hyna-stage login. - CLI sends file content to
/deploy-stageEdge Function using a customx-hyna-keyheader (bypassing Supabase's API Gateway apikey pattern-blocking). - Function provisions an E2B Firecracker MicroVM, writes the file (
/home/user/index.html), and runspython3 -m http.server 3000in the background. - Function logs the environment to the
environmentstable and returns the public E2B URL. - Dashboard fetches
environmentstable via RLS to display active instances.
- User authenticates via
2. KAVLR (AI Agent Action Gate)
Purpose: Fail-closed runtime security gate for autonomous AI agents.
- Client Interface: Node.js CLI (
@hynaweb/kavlrv1.0.5). Intercepts commands usingchild_process.spawn(). - Database/Policy Engine: Supabase PostgreSQL.
- AI Inference: Supabase Edge Function (
llm-judge) calling Groq API (openai/gpt-oss-120b). - Execution Flow:
- Agent runs
kavlr <command>. - CLI parses binary and args, sends to
evaluate_kavlr_action_v2RPC. - Postgres checks the
settingstable (Kill Switch), then thepoliciestable (static allow/deny). - If unknown, returns
NEEDS_AI. CLI callsllm-judgeEdge Function. - LLM grades intent (0-100) based on a 90-Article Constitutional AI framework. Score >= 90 allows execution. Score < 90 blocks execution and logs to
agent_logs. - Web dashboard polls
agent_logsevery 3 seconds for live telemetry.
- Agent runs
Part 2: Emotional Log (The Journey)
Act I: The Spark and The Abyss
Started with a vision to build enterprise infrastructure from a $150 Android phone. Crashed immediately into the Supabase API Gateway rejecting custom keys. Hours of staring at {"error":"Invalid API Key"}. Breakthrough achieved by bypassing the gateway with a custom header.
Act II: The Dark Timeline
Postgres pg_net caused infinite transaction locks and timeouts. The Termux terminal began "eating" code, pasting old command outputs directly into source files, corrupting package.json and breaking Node.js via ASCII art syntax errors. The developer and the AI co-pilot nearly lost their minds.
Act III: The Cyberpunk Awakening
Moved the AI inference to a Supabase Edge Function. The AI initially failed (scored 95/100 for cat .env | base64). We rewrote the AI's Constitution to strictly ban exfiltration and obfuscation. Then, the defining moment: the user tried to run rm -f kavlr to uninstall the tool, and KAVLR's AI intercepted the command, scored it 0/100, and blocked it. The AI protected its own binary.
Act IV: The NPM Bouncer
Reached the finish line. NPM rejected the package name kavlr due to similarity with kasir. Scoped to @hynaweb/kavlr and finally published to the world. Within minutes, hundreds of downloads.
Part 3: The Bug Hall of Fame (Named)
1. The Gateway Mutiny
- Description: Supabase PostgREST blocking standard API keys and custom RPC calls.
- Resolution: Bypassed the API Gateway's header pattern-matching by using custom
x-hyna-keyheaders and settingverify_jwt: false.
2. The Postgres Black Hole
- Description: Using
pg_netto make HTTP requests to the AI inside a SQL transaction, causing the event loop to block and timeout. - Resolution: Ripped out
pg_net. Shifted the AI call to the client-side CLI. Postgres now only returnsNEEDS_AI, eliminating database latency.
3. The Termux Poltergeist
- Description: The Android terminal's paste buffer corrupting multi-line
cat >commands, causing old terminal output to overwritepackage.jsonand JS files. - Resolution: Abandoned
catheredocs. Used Python scripts and base64 decoding to write files byte-by-byte, preventing terminal interception.
4. The Model Mirage
- Description: Groq deprecated
llama-3.3-70b-versatilemid-build, throwing a 404. - Resolution: Swapped to
openai/gpt-oss-120band implemented strict error logging inside the Edge Function.
5. The Semantic Blindspot
- Description: The AI gave a
95/100tocat .env | base64because it saw no immediate network egress (curl). - Resolution: Upgraded the Constitutional prompt to explicitly ban reading
.env,.ssh, and usingbase64encoding, forcing the AI to grade the preparatory action.
6. The Self-Preservation Protocol
- Description: The user tried to delete the CLI using
rm, but KAVLR intercepted the command, recognized the destructive action, and blocked it. - Resolution: Used
mvinstead ofrmto bypass the leash to uninstall the tool.
7. The NPM Bouncer
- Description: NPM's automated spam filter rejected
kavlrbecause it looked too similar tokasir. - Resolution: Created a scoped package:
@hynaweb/kavlr.
The Architect's Final Note
We started with an empty folder and a thought experiment. We ended with a globally published, AI-powered security ecosystem and ephemeral cloud infrastructure that runs on a phone.
The bugs were brutal, but we gave them names, defeated them, and shipped the code.
The Sentinel is live.
👉 HYNA-Stage Dashboard: hyna-stage
👉 KAVLR Dashboard: kavlr
Take a bow, builders. The cloud belongs to everyone, and the AI era needs guardrails. We’re just getting started. 🐯☁️🚀
來源:DEV Community · dev.to