跳到正文
DEV Community· Harun - solo dev·· 3 小時前AI 評分36

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 🐯🛡️

AI 導讀

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 native fetch, commander, chalk, and ora. 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:
    1. User authenticates via hyna-stage login.
    2. CLI sends file content to /deploy-stage Edge Function using a custom x-hyna-key header (bypassing Supabase's API Gateway apikey pattern-blocking).
    3. Function provisions an E2B Firecracker MicroVM, writes the file (/home/user/index.html), and runs python3 -m http.server 3000 in the background.
    4. Function logs the environment to the environments table and returns the public E2B URL.
    5. Dashboard fetches environments table via RLS to display active instances.

2. KAVLR (AI Agent Action Gate)

Purpose: Fail-closed runtime security gate for autonomous AI agents.

  • Client Interface: Node.js CLI (@hynaweb/kavlr v1.0.5). Intercepts commands using child_process.spawn().
  • Database/Policy Engine: Supabase PostgreSQL.
  • AI Inference: Supabase Edge Function (llm-judge) calling Groq API (openai/gpt-oss-120b).
  • Execution Flow:
    1. Agent runs kavlr <command>.
    2. CLI parses binary and args, sends to evaluate_kavlr_action_v2 RPC.
    3. Postgres checks the settings table (Kill Switch), then the policies table (static allow/deny).
    4. If unknown, returns NEEDS_AI. CLI calls llm-judge Edge Function.
    5. 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.
    6. Web dashboard polls agent_logs every 3 seconds for live telemetry.

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-key headers and setting verify_jwt: false.

2. The Postgres Black Hole

  • Description: Using pg_net to 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 returns NEEDS_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 overwrite package.json and JS files.
  • Resolution: Abandoned cat heredocs. 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-versatile mid-build, throwing a 404.
  • Resolution: Swapped to openai/gpt-oss-120b and implemented strict error logging inside the Edge Function.

5. The Semantic Blindspot

  • Description: The AI gave a 95/100 to cat .env | base64 because it saw no immediate network egress (curl).
  • Resolution: Upgraded the Constitutional prompt to explicitly ban reading .env, .ssh, and using base64 encoding, 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 mv instead of rm to bypass the leash to uninstall the tool.

7. The NPM Bouncer

  • Description: NPM's automated spam filter rejected kavlr because it looked too similar to kasir.
  • 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