Skip to content

Latest commit

 

History

History
118 lines (91 loc) · 11.4 KB

File metadata and controls

118 lines (91 loc) · 11.4 KB

bird hawk Architecture

AI Coding Agent for Your Terminal

Go Port Protocol


target Overview

hawk is an AI-powered coding agent for the terminal. It reads codebases, writes and edits files, runs tests, and manages git — all through natural language. Zero CGO, single static binary for linux/darwin/windows on amd64/arm64.


blocks Layered Architecture

hawk/
├── api/openapi.yaml           <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/file-text.svg" width="16" height="16" alt="file-text" /> Daemon REST API contract (OpenAPI 3.1)
├── cmd/                       <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/terminal.svg" width="16" height="16" alt="terminal" /> Cobra CLI commands (200+ files)
│   ├── hawk/main.go           <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/zap.svg" width="16" height="16" alt="zap" /> Entry point — calls cmd.Execute()
│   ├── root.go                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/settings.svg" width="16" height="16" alt="settings" /> Root command, flag definitions
│   ├── daemon.go              <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/server.svg" width="16" height="16" alt="server" /> Daemon start/stop/status
│   ├── chat.go                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/message-square.svg" width="16" height="16" alt="message-square" /> Interactive TUI chat
│   └── ...
├── internal/
│   ├── api/                   <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/globe.svg" width="16" height="16" alt="globe" /> HTTP server (:4590) — 8 REST endpoints
│   ├── daemon/                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/server.svg" width="16" height="16" alt="server" /> Daemon lifecycle (PID file, socket)
│   ├── engine/                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/brain.svg" width="16" height="16" alt="brain" /> Agent execution loop
│   │   ├── session.go         <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/refresh-cw.svg" width="16" height="16" alt="refresh-cw" /> Core agent loop (Stream, agentLoop)
│   │   ├── ctxmgr/            <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/package.svg" width="16" height="16" alt="package" /> Context packing and visualization
│   │   ├── token/             <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/coins.svg" width="16" height="16" alt="coins" /> Budget allocation and prediction
│   │   ├── streaming/         <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/radio.svg" width="16" height="16" alt="radio" /> Response cache and stream optimizer
│   │   ├── planning/          <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/target.svg" width="16" height="16" alt="target" /> Goals and task decomposition
│   │   └── workflow/          <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/wrench.svg" width="16" height="16" alt="wrench" /> JSON-defined automation pipelines
│   ├── tool/                  <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/hammer.svg" width="16" height="16" alt="hammer" /> 40+ built-in tools
│   ├── config/                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/settings.svg" width="16" height="16" alt="settings" /> Settings, env manager, migration
│   ├── session/               <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/database.svg" width="16" height="16" alt="database" /> SQLite persistence, search, export
│   ├── permissions/           <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/shield.svg" width="16" height="16" alt="shield" /> Guardian, rules DSL, boundary checker
│   ├── sandbox/               <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/box.svg" width="16" height="16" alt="box" /> Landlock + seccomp isolation
│   ├── intelligence/          <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/git-branch.svg" width="16" height="16" alt="git-branch" /> Repo map, AST analysis, deps
│   ├── multiagent/            <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/users.svg" width="16" height="16" alt="users" /> Personas, inter-agent messaging
│   ├── mcp/                   <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/plug.svg" width="16" height="16" alt="plug" /> MCP client and server
│   ├── bridge/                <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/link.svg" width="16" height="16" alt="link" /> Bridges to ecosystem services
│   └── resilience/            <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/refresh-cw.svg" width="16" height="16" alt="refresh-cw" /> Circuit breaker, retry, rate limit
├── shared/types/              <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/share-2.svg" width="16" height="16" alt="share-2" /> Cross-repo exported types
├── docs/                      <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/book-open.svg" width="16" height="16" alt="book-open" /> Architecture docs
└── external/                  <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/link.svg" width="16" height="16" alt="link" /> Local go.work checkouts

globe Daemon HTTP API (:4590)

Contract api/openapi.yaml
Port :4590 (default). Override: HAWK_DAEMON_PORT
Auth Bearer token or X-API-Key. Set via HAWK_DAEMON_API_KEY
radio Endpoint Summary
Method Path Description
GET /v1/health heart Health check
GET /v1/version tag Version info
POST /v1/chat message-square Send message (JSON or SSE)
GET /v1/sessions list List sessions
GET /v1/sessions/{id} search Get session
GET /v1/sessions/{id}/messages message-square Get messages
DELETE /v1/sessions/{id} trash-2 Delete session
GET /v1/stats bar-chart Usage statistics

link Ecosystem Integration

Service Role Connection
bird eyrie LLM provider runtime :8080 — all LLM calls routed here
brain yaad Persistent memory :3456 — session context, recall
eye sight Code review Library — diff-based review
search inspect Security audit Library — website scanning
scissors tok Token optimization Library — compression, secrets
camera trace Session capture CLI hook — git-native capture

lightbulb hawk never talks to LLM APIs directly — all calls go through eyrie.


shield Tool Safety Layer

Every tool call passes through the permission system before execution:

Tool Call → <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/shield.svg" width="16" height="16" alt="shield" /> Guardian (rules DSL) → <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/blocks.svg" width="16" height="16" alt="blocks" /> Boundary Checker → <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/user.svg" width="16" height="16" alt="user" /> User Approval → <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/box.svg" width="16" height="16" alt="box" /> Sandbox (landlock/seccomp) → <img src="https://cdn.jsdelivr.net/gh/lucide-icons/lucide@latest/icons/check-circle.svg" width="16" height="16" alt="check-circle" /> Execute

ruler Key Design Decisions

Decision Rationale
cmd/hawk/main.go entry point Standard Go layout — goreleaser builds with main: ./cmd/hawk producing hawk binary
cmd/ is CLI library Not a binary sub-directory — holds 200+ cobra command files
Zero CGO Pure Go, cross-compilable. Tree-sitter is optional
internal/ is private Other repos import shared/types/ only
external/ go.work symlinks for local dev — not committed