8000 GitHub - hughguan/MetaMach: MetaMach is NOT an AI agent framework. It is a Bare-Metal, High-Availability Safety Harness & Execution Engine for Autonomous Agents in the Physical World. Β· GitHub
[go: up one dir, main page]

Skip to content
hughguanPublic

About

MetaMach is NOT an AI agent framework. It is a Bare-Metal, High-Availability Safety Harness & Execution Engine for Autonomous Agents in the Physical World.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

339 Commits

Folders and files

Repository files navigation

πŸ›‘οΈ MetaMach

CI License: MIT Herdr 0.7.3+ macOS & Linux Tests: 206 Version: 0.7.0-candidate

MetaMach is a durable AI Software Factory OS β€” a bare-metal safety harness and execution engine that orchestrates autonomous AI agents (Claude Code, Codex, Aider, etc.) inside survivable engineering workflows with checkpoints, Human-in-the-Loop (HITL) approval gates, and sandboxed execution.


Quick Start

1. Prerequisites

Dependency Requirement Purpose
Rust 1.88+ (Edition 2024) Required β€” compiles MetaMach binaries
PostgreSQL 16+ (host-native, no Docker) Required β€” durable state machine & task queue
tmux 3.3+ Required β€” isolated PTY session engine
Herdr 0.7.3+ Optional β€” terminal TUI dashboard (herdr-janus)

Note: MetaMach runs 100% standalone via janus CLI and Web Studio (janus studio). Herdr is an optional plugin host if you want a terminal overlay.

2. Installation & Bootstrap (30-second setup)

git clone https://github.com/hughguan/MetaMach.git
cd MetaMach
make bootstrap          # One command: checks prereqs, compiles binaries, initializes host PG

3. Initialize & Run Your First Project

cd my-project
janus init              # Scaffolds .janus/, auto-starts daemon, validates & registers
janus start             # Runs the workflow with checkpointing & safety gates

For quick single-command executions without a TOML workflow file:

janus start --inline "cargo test"       # Auto-generates a transient single-step workflow

Workflow Lifecycle

Every project managed by MetaMach follows a simple 7-verb lifecycle:

init β†’ plan β†’ dry-run β†’ start β†’ monitor β†’ harvest β†’ offboard

Step Command Description
init janus init Scaffold .janus/, validate blueprint, register project database with daemon
plan janus plan --description "..." Generate or edit a workflow definition (.janus/workflows/*.toml)
dry-run janus start --dry-run Preview execution plan & DAG topology without running commands
start janus start Execute workflow with automatic step checkpointing & tool reconciliation
monitor janus status / stop / continue Check real-time progress, pause, or resume interrupted workflows
harvest janus harvest list / apply Inspect and apply outputs from sandboxed execution tasks
offboard janus offboard --blueprint <name> Archive audit log, generate production report, purge transient runtime data

LLM-Assisted Planning: Generate a workflow directly from natural language:
janus plan --blueprint my-project --description "Build Rust binary, run test suite, deploy"


Workflow DSL & Safety Rail Examples

MetaMach uses a unified Workflow DSL (.janus/workflows/<name>.toml) supporting both linear sequential steps and multi-node DAG workflows.

1. Linear Workflow (Sequential Steps)

# .janus/workflows/ci.toml
[workflow]
name = "ci"
description = "Build and test suite"

[[steps]]
name = "build"
agent = "builder"
command = "cargo build --release"

[[steps]]
name = "test"
agent = "tester"
command = "cargo test"
max_correction_attempts = 3      # re-dispatches with error context on failure

2. Minimal DAG Workflow (Parallel Execution)

# .janus/workflows/parallel_ci.toml
[workflow]
name = "parallel_ci"
description = "Run linter and tests concurrently after build"

[[nodes]]
id = "build"
workflow = "wf_build"

[[nodes]]
id = "lint"
needs = ["build"]
steps = [{ name = "clippy", command = "cargo clippy" }]

[[nodes]]
id = "test"
needs = ["build"]
steps = [{ name = "cargo_test", command = "cargo test" }]

3. Advanced DAG Workflow (Dual-Track Isolation & Path Whitelisting)

Nodes can declare sandbox isolation (runs in an isolated Git worktree) and allowed write paths:

# .janus/workflows/fullstack_iot.toml
[workflow]
name = "fullstack_iot"
description = "Parallel web build and firmware flashing"

[[nodes]]
id = "build_web_ui"
isolation = "sandbox"            # runs in an isolated Git worktree & sandbox tmux
writes = ["apps/web/dist/"]      # whitelist: post-execution guard flags writes outside this directory
steps = [{ name = "install", command = "bun install && bun run build" }]

[[nodes]]
id = "flash_esp32"
isolation = "bare_metal"         # host-native, janush-protected physical execution
needs = ["build_web_ui"]
steps = [{ name = "flash", command = "esptool.py write_flash 0x0 target/firmware.bin" }]

Monitoring, Web Studio & Harvest

CLI Monitoring & Task Control

janus status                             # Snapshot active task status
janus status --json                      # Machine-readable output
janus stop --blueprint my-project        # Pause active tasks for a project
janus continue --blueprint my-project    # Resume paused or interrupted tasks from last checkpoint

MetaMach Studio (Visual Canvas & Web Observer)

Launch the interactive web observer sidecar:

janus studio                             # Starts Web Studio at http://127.0.0.1:8444
janus studio -d                          # Launch detached in the background
  • 🎨 Visual DAG Canvas: Drag-and-drop workflow editor and execution plan graph.
  • πŸ“‘ Real-Time Stream: Live WebSocket observer streaming step state transitions.
  • πŸ›‘οΈ HITL Web Interlocks: One-click human-in-the-loop approval center for high-risk operations.

Sandbox Harvest Pipeline

Review and apply outputs from sandboxed steps without risking main workspace contamination:

janus harvest list                                       # List all harvested sandbox refs
janus harvest apply --ref-name refs/sandbox/<id>-<step>   # Apply approved sandbox output to working directory

Architecture & Project Structure

System Architecture

                         ═══════════════════════════════════════════
                          CLI Agent (Claude Code / Codex / Pi / ...)
                         ═══════════════════════════════════════════
                                        β”‚
                                        β”‚ spawns on user command
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  janush  (Proxy Shell)       β”‚
                         β”‚  β€’ Tool Guard reconciliation β”‚
                         β”‚  β€’ 30s fail-closed timeout   β”‚
                         β”‚  β€’ 16KB streaming truncation β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚ UDS (Unix Domain Socket)
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚        janus-daemon  (MM-CORE)           β”‚
                         β”‚  β€’ Master state machine & UDS router     β”‚
                         β”‚  β€’ Workflow engine & durable checkpoints β”‚
                         β”‚  β€’ DAG engine (topological sort)         β”‚
                         β”‚  β€’ HITL Gateway & Webhooks               β”‚
                         β”‚  β€’ Cold-start resume & self-healing      β”‚
                         β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚             β”‚             β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚             └──────────┐
                   β–Ό                      β–Ό                        β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚  janus::tmux         β”‚  β”‚  PostgreSQL       β”‚  β”‚  janus::gateway       β”‚
     β”‚  β€’ tmux -L mm-tmux   β”‚  β”‚  β€’ catalog DB     β”‚  β”‚  β€’ HITL dispatch      β”‚
     β”‚  β€’ remain-on-exit    β”‚  β”‚  β€’ per-blueprint DBβ”‚  β”‚  β€’ Webhook ingress    β”‚
     β”‚  β€’ SSH reverse tunnelβ”‚  β”‚  β€’ SQLite fallback β”‚  β”‚  β€’ HMAC verification  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β–²                                           β–²
                   β”‚ (reattach view)                           β”‚ UDS proxying
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚  herdr-janus (TUI)    β”‚                  β”‚  janus-studio (Web Observer) β”‚
     β”‚  β€’ Terminal dashboardβ”‚                  β”‚  β€’ Visual DAG Canvas Editor  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚  β€’ Real-Time WS Streamer     β”‚
                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

TL;DR: janus-daemon owns all state in PostgreSQL while janush interceptively checks every agent command before bare-metal execution. Decoupled Web Studio sidecar runs on http://127.0.0.1:8444.

MetaMach Workspace Layout

metamach/
β”œβ”€β”€ docs/                        # Technical specifications & ADR index
β”œβ”€β”€ janus/                       # Core Rust workspace (~14,100 LOC)
β”‚   β”œβ”€β”€ src/bin/                 #   5 Binaries: janus, janus-daemon, herdr-janus, janush, janus-studio
β”‚   β”œβ”€β”€ src/                     #   Engine modules (absurd, tmux, tool_guard, gateway, cognitive, workflow)
β”‚   └── tests/                   #   Integration test suite (9 files, 206 tests)
β”œβ”€β”€ templates/                   # Default templates for `janus init`
β”‚   β”œβ”€β”€ blueprint.toml           #   Default blueprint recipe
β”‚   β”œβ”€β”€ agents/                  #   architecture.toml, builder.toml, tester.toml
β”‚   └── workflows/               #   15 workflow templates (linear + DAG)
└── Makefile                     # Bootstrap, database setup, health check

Per-Project Layout (after janus init)

my-project/
β”œβ”€β”€ .janus/                      # Project-specific MetaMach configuration
β”‚   β”œβ”€β”€ blueprint.toml           #   Project recipe & default workflow selection
β”‚   β”œβ”€β”€ agents/                  #   Agent role overrides (architect, builder, tester)
β”‚   β”‚   β”œβ”€β”€ architecture.toml
β”‚   β”‚   β”œβ”€β”€ builder.toml
β”‚   β”‚   └── tester.toml
β”‚   β”œβ”€β”€ workflows/               #   Project workflows (linear + DAG)
β”‚   β”‚   β”œβ”€β”€ wf_architect_design.toml
β”‚   β”‚   β”œβ”€β”€ wf_builder_implement.toml
β”‚   β”‚   β”œβ”€β”€ req2spec.toml
β”‚   β”‚   └── spec2software.toml
β”‚   └── openwiki/                #   RAG knowledge scope & production reports
└── src/                         # Your project source code

Core Principles

  • πŸ›‘οΈ Safety First: Fail-closed 30s timeouts, post-execution file write whitelisting, sandboxed Git worktree isolation, and human approval gates for high-risk operations.
  • βš™οΈ Uncompromising Stability: Daemon-owned state machine, transactional PostgreSQL checkpoints with SQLite fallback, and automatic cold-start task recovery.
  • πŸ”Œ Pure Decoupling: Agent-agnostic integration with any CLI tool, decoupled Web Studio sidecar, and host-native execution without container overhead.

πŸ“š Specifications & Documentation

The authoritative technical specifications live under docs/:

  • PRD.md β€” Product Requirements & Persona Specifications
  • ARCH.md β€” High-Level Architecture & Component Topology
  • ADR.md β€” Architecture Decision Records Index (36 Decision Records)
  • SPEC.md β€” Technical Contracts, Test Catalog & Deployment Matrix
  • PLAN.md β€” Execution Roadmap & Milestone History

Troubleshooting & FAQ

Daemon not reachable (janus-daemon)

If janus commands report janus-daemon not reachable, start the resident background daemon:

janus daemon                            # Launch daemon in foreground (Ctrl+C to stop)
make health                             # Verify daemon socket & PG connection
PostgreSQL database connection issues

MetaMach uses a host-native PostgreSQL instance (no Docker). If the database is down or uninitialized:

make db-init                           # Initialize PG cluster at ~/.metamach/db/ & run catalog migrations
Is MetaMach a replacement for Docker or CI runners?

No. MetaMach is an AI Software Factory OS designed to safely host autonomous AI coding agents on local or remote dev machines with hardware access, strong checkpoints, and human approval gates.


CI & Testing

  • 206 Workspace Tests: 100% passing (140 unit tests + 66 integration tests across 9 files).
  • CI Gates: Every commit passes cargo fmt, cargo clippy -D warnings, and cargo test --workspace.
  • Pre-Push Hook: ./scripts/pre-push auto-provisions local PostgreSQL and validates E2E workflow dispatches.

License

MIT β€” see LICENSE.

About

MetaMach is NOT an AI agent framework. It is a Bare-Metal, High-Availability Safety Harness & Execution Engine for Autonomous Agents in the Physical World.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0