GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — moat/CONTRIBUTING.md at main · majorcontext/moat

Expand file tree

/

CONTRIBUTING.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
172 lines (127 loc) · 5.65 KB
/

CONTRIBUTING.md

Copy path

File metadata and controls

172 lines (127 loc) · 5.65 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Contributing to Moat

Development Setup

git clone https://github.com/majorcontext/moat.git
cd moat
go build ./...

Running Tests

# Unit tests (includes race detector)
make test-unit

# Single test
make test-unit ARGS='-run TestName'

# E2E tests (requires container runtime)
go test -tags=e2e -v ./internal/e2e/

# With coverage (includes race detector)
make coverage

Linting

golangci-lint run

Architecture

cmd/moat/           CLI entry point (Cobra commands)
internal/
  audit/             Tamper-proof audit logging with cryptographic verification
  config/            moat.yaml parsing, mount string parsing
  container/         Container runtime abstraction (Docker and Apple containers)
  credential/        Secure credential storage (GitHub, Anthropic, AWS)
  image/             Runtime-based image selection (node/python/go → base image)
  log/               Structured logging (slog wrapper)
  proxy/             TLS-intercepting proxy for credential injection
  run/               Run lifecycle management (create/start/stop/destroy)
  storage/           Per-run storage for logs, traces, network requests

Key Flows

Credential Injection:

  1. moat grant github → token from gh CLI, env var, or PAT prompt → stored encrypted
  2. moat run --grant github → proxy started → container traffic routed through proxy
  3. Proxy intercepts HTTPS, injects Authorization headers for matching hosts

Image Selection:

  • moat.yaml dependencies field → image.Resolve() → node:X / python:X / golang:X / ubuntu:22.04

Observability:

  • Container stdout → storage.LogWriter → ~/.moat/runs/<id>/logs.jsonl
  • Proxy requests → storage.NetworkRequest → network.jsonl

Container Runtime Selection:

  • container.NewRuntime() auto-detects: Apple containers on macOS 15+ with Apple Silicon, otherwise Docker

Audit Logging:

  • Events → audit.Store.Append() → hash-chained entries in SQLite
  • moat audit <run-id> displays chain with verification
  • --export creates portable proof bundle

Proxy Security Model

The credential-injecting proxy binds to 0.0.0.0 on both Docker and Apple containers so container networks can reach it. Each run receives a cryptographically random 32-byte authentication token in HTTP_PROXY=http://moat:<token>@moat-proxy:<port>. The daemon uses the token to select that run's credentials and network policy; requests without a valid token are rejected.

The synthetic moat-proxy hostname resolves to the host gateway. Docker on Linux uses host-gateway mappings; Docker Desktop and Apple containers use addresses resolved during container initialization.

See proxy.go in the gatekeeper module for the full security model documentation.

Manual Testing

Claude Code credential injection

Credential injection for Claude Code requires manual verification:

# 1. Grant Anthropic credentials
moat grant anthropic

# 2. Start Claude Code in a test directory
moat claude ./examples/claude-code

# 3. Verify Claude Code starts and can make API calls
#    - Claude should authenticate successfully
#    - Try a simple prompt to confirm API access works

# 4. Check that the token was injected (not in environment)
#    In another terminal while Claude is running:
moat run --grant anthropic -- env | grep -i anthropic
#    Should show ANTHROPIC_API_KEY=moat-proxy-injected (placeholder, not real token)

# 5. Verify network trace shows API calls
moat trace --network
#    Should show requests to api.anthropic.com with 200 status

Codex credential injection

# 1. Grant OpenAI credentials
moat grant openai

# 2. Start Codex in a test directory
moat codex ./examples/agent-codex

# 3. Verify Codex starts and can make API calls
#    - Codex should authenticate successfully
#    - Try a simple prompt to confirm API access works

# 4. Check that the token was injected (not in environment)
moat run --grant openai -- env | grep -i openai
#    Should show OPENAI_API_KEY=moat-proxy-injected (placeholder, not real token)

# 5. Verify network trace shows API calls
moat trace --network
#    Should show requests to api.openai.com with 200 status

GitHub credential injection

# 1. Grant GitHub credentials
moat grant github

# 2. Test credential injection
moat run --grant github -- curl -s https://api.github.com/user
#    Should return your GitHub user info

# 3. Verify token is not in environment
moat run --grant github -- env | grep -i token
#    Should show GH_TOKEN=moat-proxy-injected (placeholder, not real token)

# 4. Verify network trace
moat trace --network
#    Should show GET https://api.github.com/user with 200 status

Code Style & Guidelines

For code style, error messages, documentation standards, and commit conventions, see CLAUDE.md.

Key points:

  • Follow standard Go conventions and go fmt
  • Use Conventional Commits format: type(scope): description
  • Error messages should be actionable—tell users exactly what to do
  • Documentation must match actual behavior

Data Directory Structure

~/.moat/
  config.yaml              # Global settings
  credentials/             # Encrypted tokens
  proxy/ca/                # Generated CA certificate
  runs/                    # Per-run data
    <run-id>/
      metadata.json        # Run configuration
      logs.jsonl           # Container output
      network.jsonl        # HTTP requests
      traces.jsonl         # OpenTelemetry spans
      secrets.jsonl        # Resolved secret names (not values)
      audit.db             # Tamper-proof audit database
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.