# laude-institute/headlong architecture

> Architecture diagram of the GitHub repository laude-institute/headlong, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/laude-institute/headlong
- Repository: https://github.com/laude-institute/headlong

## Overview

#### Purpose and entry points
Headlong is a Bash-first persistent-agent harness. An identity maintains one append-only thought trajectory; background thinkers continue LLM-driven work while chat inputs become observations in that same stream. Installation and lifecycle begin at `install.sh`, `status.sh`, and `uninstall.sh`. Primary runtime commands are Bash executables in `bin/`, while host-side orchestration lives in `tools/`.

#### Agent execution core
`shellm` is the recursive LLM execution loop: render context, call an LLM, execute generated Bash, record results, and repeat. `llm` abstracts Anthropic, OpenAI, Gemini, and OpenRouter; `shellm-docker` constrains model-generated commands when Docker is available. Core paths: `bin/shellm`, `bin/llm`, `bin/shellm-docker`. The host-only Docker policy boundary is `tools/shellm-docker-broker`.

#### Durable trajectory and context
The system records work as append-only JSONL trajectory DAGs, supporting fork/merge rather than mutable session state. Context is a derived, tiered projection: recent events stay detailed while older history is progressively summarized and remains retrievable. This separates durable history from prompt construction. Core paths: `bin/traj`, `bin/context`, `bin/recap`. Memory and reusable procedures are filesystem-backed extensions: `bin/mem`, `bin/skills`.

#### Persistent thinker control plane
Thinkers implement the continuously running “mind”: a dispatcher invokes specialized thought processes, reacts to new observations, and applies inactivity/backoff behavior. The monolith is the general reasoning loop; responder handles conversational replies; retrieval builds/searches supporting indexes. Paths: `thinkers/monolith/step`, `thinkers/responder/step`, `thinkers/retrieval/step`. Shared shell behavior is centralized in `thinkers/_lib/common.sh`; subscriptions define which trajectory events wake each thinker.

#### Identity and human interaction boundary
Identities package persona, trajectory, memories, activation, and named user commands. Human messages and goals are written into the trajectory through the core CLIs; host utilities create/manage identities and expose named personas. Paths: `bin/chat`, `bin/focus`, `tools/identity`, `tools/persona`, `tools/headlong-init`. Skills provide agent-visible operational integrations, including Slack, Telegram, Google Workspace, and web research: `skills/slack/SKILL.md`, `skills/telegram/SKILL.md`, `skills/web-research/SKILL.md`.

#### External channels and dashboard
Slack and Telegram are separate Python bridge services that translate platform events into the shared trajectory and render agent-selected outbound responses. Paths: `slack/src/headlong_slack/inbound.py`, `slack/src/headlong_slack/outbound.py`, `telegram/src/headlong_telegram/inbound.py`, `telegram/src/headlong_telegram/outbound.py`. The dashboard is a Python API/server with a Bun/React viewer, covering trajectory, chat, thinker control, health, memories, and usage: `web/src/headlong_web/server.py`, `web/src/headlong_web/chat.py`, `web/viewer/app/routes/timeline.tsx`.

#### Deployment and operational runtime
A local install can run directly or sandbox generated commands with Docker; the long-lived deployment model uses systemd services for thinkers, web, and message bridges. Paths: `deploy/thinkers-service.sh`, `deploy/headlong-web.service`, `deploy/headlong-slack-bridge.service`. Terraform provisions dedicated AWS-based deployments and Slack alerting: `deploy/terraform/main.tf`, `deploy/terraform-slack/main.tf`, `deploy/terraform-slack/lambda/slack_alert.py`. Material dependencies are Bash, git, curl, jq, LLM provider APIs, Docker for recommended isolation, Python/uv for services, and Bun/Node for the web viewer.

Main entry points: [`bin/traj`](https://github.com/laude-institute/headlong/blob/main/bin/traj) (Trajectory DAG), [`bin/shellm`](https://github.com/laude-institute/headlong/blob/main/bin/shellm) (Recursive execution loop), [`thinkers/_lib/common.sh`](https://github.com/laude-institute/headlong/blob/main/thinkers/_lib/common.sh) (Thinker dispatcher), [`deploy/thinkers-service.sh`](https://github.com/laude-institute/headlong/blob/main/deploy/thinkers-service.sh) (Long-lived services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Agent Core"]
  node_shellm{{"Recursive execution loop<br/>Bash agent loop"}}
  node_llm["LLM provider adapter<br/>Bash CLI"]
  node_docker_runner["Sandboxed command runner<br/>Bash CLI"]
  node_docker_broker["Docker policy broker<br/>host policy boundary"]
end

subgraph group_state["Durable State"]
  node_trajectory[("Trajectory DAG<br/>append-only JSONL")]
  node_context["Tiered context projection<br/>derived prompt state"]
  node_recap["History recap<br/>summarizer"]
  node_memory_skills["Memory &amp; skills<br/>filesystem extensions"]
end

subgraph group_thinkers["Thinker Control Plane"]
  node_dispatcher{{"Thinker dispatcher<br/>persistent control plane<br/>[common.sh]"}}
  node_monolith["General reasoning thinker<br/>thought process"]
  node_responder["Conversation responder<br/>thought process"]
  node_retrieval["Retrieval thinker<br/>indexing process"]
end

subgraph group_interfaces["Human &amp; Channel Interfaces"]
  node_identity["Identity management<br/>host utility"]
  node_chat_focus["Chat &amp; goals<br/>Bash CLI"]
  node_bridges["Slack &amp; Telegram bridges<br/>Python services<br/>[inbound.py]"]
  node_dashboard_api["Dashboard API<br/>Python server<br/>[server.py]"]
  node_timeline["Timeline viewer<br/>Bun/React client<br/>[timeline.tsx]"]
end

subgraph group_operations["Deployment &amp; Operations"]
  node_lifecycle["Install &amp; lifecycle<br/>Bash lifecycle<br/>[install.sh]"]
  node_systemd["Long-lived services<br/>systemd deployment"]
  node_terraform["AWS deployment &amp; alerts<br/>Terraform<br/>[main.tf]"]
end

node_lifecycle -->|"initializes"| node_identity
node_identity -->|"owns"| node_trajectory
node_chat_focus -->|"appends observations"| node_trajectory
node_trajectory -->|"projects"| node_context
node_recap -->|"summarizes history"| node_trajectory
node_context -->|"renders prompt context"| node_shellm
node_shellm -->|"calls"| node_llm
node_shellm -.->|"uses when sandboxed"| node_docker_runner
node_docker_runner -->|"enforces policy through"| node_docker_broker
node_shellm -->|"records execution"| node_trajectory
node_memory_skills -->|"extends operations"| node_shellm
node_trajectory -->|"event subscriptions"| node_dispatcher
node_dispatcher -->|"invokes"| node_monolith
node_dispatcher -->|"invokes"| node_responder
node_dispatcher -->|"invokes"| node_retrieval
node_monolith -->|"drives reasoning work"| node_shellm
node_responder -->|"writes replies"| node_trajectory
node_retrieval -->|"builds/searches support"| node_memory_skills
node_bridges -->|"translates inbound events"| node_trajectory
node_trajectory -->|"selected outbound responses"| node_bridges
node_dashboard_api -->|"reads and writes"| node_trajectory
node_timeline -->|"uses"| node_dashboard_api
node_systemd -->|"runs"| node_dispatcher
node_systemd -->|"runs"| node_dashboard_api
node_systemd -->|"runs"| node_bridges
node_terraform -->|"provisions deployment"| node_systemd

click node_lifecycle "https://github.com/laude-institute/headlong/blob/main/install.sh"
click node_identity "https://github.com/laude-institute/headlong/blob/main/tools/identity"
click node_chat_focus "https://github.com/laude-institute/headlong/blob/main/bin/chat"
click node_shellm "https://github.com/laude-institute/headlong/blob/main/bin/shellm"
click node_llm "https://github.com/laude-institute/headlong/blob/main/bin/llm"
click node_docker_runner "https://github.com/laude-institute/headlong/blob/main/bin/shellm-docker"
click node_docker_broker "https://github.com/laude-institute/headlong/blob/main/tools/shellm-docker-broker"
click node_trajectory "https://github.com/laude-institute/headlong/blob/main/bin/traj"
click node_context "https://github.com/laude-institute/headlong/blob/main/bin/context"
click node_recap "https://github.com/laude-institute/headlong/blob/main/bin/recap"
click node_memory_skills "https://github.com/laude-institute/headlong/blob/main/bin/mem"
click node_dispatcher "https://github.com/laude-institute/headlong/blob/main/thinkers/_lib/common.sh"
click node_monolith "https://github.com/laude-institute/headlong/blob/main/thinkers/monolith/step"
click node_responder "https://github.com/laude-institute/headlong/blob/main/thinkers/responder/step"
click node_retrieval "https://github.com/laude-institute/headlong/blob/main/thinkers/retrieval/step"
click node_bridges "https://github.com/laude-institute/headlong/blob/main/slack/src/headlong_slack/inbound.py"
click node_dashboard_api "https://github.com/laude-institute/headlong/blob/main/web/src/headlong_web/server.py"
click node_timeline "https://github.com/laude-institute/headlong/blob/main/web/viewer/app/routes/timeline.tsx"
click node_systemd "https://github.com/laude-institute/headlong/blob/main/deploy/thinkers-service.sh"
click node_terraform "https://github.com/laude-institute/headlong/blob/main/deploy/terraform/main.tf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shellm,node_llm,node_docker_runner,node_docker_broker toneBlue
class node_trajectory,node_context,node_recap,node_memory_skills toneAmber
class node_dispatcher,node_monolith,node_responder,node_retrieval toneMint
class node_identity,node_chat_focus,node_bridges,node_dashboard_api,node_timeline toneRose
class node_lifecycle,node_systemd,node_terraform toneIndigo
```

## Components

### Agent Core

- [Recursive execution loop](https://github.com/laude-institute/headlong/blob/main/bin/shellm): Bash agent loop · Renders context, invokes a model, executes Bash, and records results. · `bin/shellm`
- [LLM provider adapter](https://github.com/laude-institute/headlong/blob/main/bin/llm): Bash CLI · Abstracts Anthropic, OpenAI, Gemini, and OpenRouter. · `bin/llm`
- [Sandboxed command runner](https://github.com/laude-institute/headlong/blob/main/bin/shellm-docker): Bash CLI · `bin/shellm-docker`
- [Docker policy broker](https://github.com/laude-institute/headlong/blob/main/tools/shellm-docker-broker): host policy boundary · Host-only boundary for constrained generated commands. · `tools/shellm-docker-broker`

### Durable State

- [Trajectory DAG](https://github.com/laude-institute/headlong/blob/main/bin/traj): append-only JSONL · Durable forkable and mergeable event history. · `bin/traj`
- [Tiered context projection](https://github.com/laude-institute/headlong/blob/main/bin/context): derived prompt state · Keeps recent events detailed and summarizes older history. · `bin/context`
- [History recap](https://github.com/laude-institute/headlong/blob/main/bin/recap): summarizer · `bin/recap`
- [Memory & skills](https://github.com/laude-institute/headlong/blob/main/bin/mem): filesystem extensions · Reusable procedures and agent-visible integrations. · `bin/mem`

### Thinker Control Plane

- [Thinker dispatcher](https://github.com/laude-institute/headlong/blob/main/thinkers/_lib/common.sh): persistent control plane · Subscriptions wake specialized processes on trajectory events. · `thinkers/_lib/common.sh`
- [General reasoning thinker](https://github.com/laude-institute/headlong/blob/main/thinkers/monolith/step): thought process · `thinkers/monolith/step`
- [Conversation responder](https://github.com/laude-institute/headlong/blob/main/thinkers/responder/step): thought process · `thinkers/responder/step`
- [Retrieval thinker](https://github.com/laude-institute/headlong/blob/main/thinkers/retrieval/step): indexing process · Builds and searches supporting indexes. · `thinkers/retrieval/step`

### Human & Channel Interfaces

- [Identity management](https://github.com/laude-institute/headlong/blob/main/tools/identity): host utility · Creates and manages personas, activation, and identity state. · `tools/identity`
- [Chat & goals](https://github.com/laude-institute/headlong/blob/main/bin/chat): Bash CLI · Writes human messages and goals as trajectory observations. · `bin/chat`
- [Slack & Telegram bridges](https://github.com/laude-institute/headlong/blob/main/slack/src/headlong_slack/inbound.py): Python services · Translate channel events to trajectory observations and outbound replies. · `slack/src/headlong_slack/inbound.py`
- [Dashboard API](https://github.com/laude-institute/headlong/blob/main/web/src/headlong_web/server.py): Python server · Provides trajectory, chat, thinker, health, memory, and usage operations. · `web/src/headlong_web/server.py`
- [Timeline viewer](https://github.com/laude-institute/headlong/blob/main/web/viewer/app/routes/timeline.tsx): Bun/React client · `web/viewer/app/routes/timeline.tsx`

### Deployment & Operations

- [Install & lifecycle](https://github.com/laude-institute/headlong/blob/main/install.sh): Bash lifecycle · `install.sh`
- [Long-lived services](https://github.com/laude-institute/headlong/blob/main/deploy/thinkers-service.sh): systemd deployment · Runs thinkers, web, and message bridges. · `deploy/thinkers-service.sh`
- [AWS deployment & alerts](https://github.com/laude-institute/headlong/blob/main/deploy/terraform/main.tf): Terraform · Provisions dedicated deployments and Slack alerting. · `deploy/terraform/main.tf`

## Connections

- Install & lifecycle → Identity management: initializes
- Identity management → Trajectory DAG: owns
- Chat & goals → Trajectory DAG: appends observations
- Trajectory DAG → Tiered context projection: projects
- History recap → Trajectory DAG: summarizes history
- Tiered context projection → Recursive execution loop: renders prompt context
- Recursive execution loop → LLM provider adapter: calls
- Recursive execution loop → Sandboxed command runner: uses when sandboxed
- Sandboxed command runner → Docker policy broker: enforces policy through
- Recursive execution loop → Trajectory DAG: records execution
- Memory & skills → Recursive execution loop: extends operations
- Trajectory DAG → Thinker dispatcher: event subscriptions
- Thinker dispatcher → General reasoning thinker: invokes
- Thinker dispatcher → Conversation responder: invokes
- Thinker dispatcher → Retrieval thinker: invokes
- General reasoning thinker → Recursive execution loop: drives reasoning work
- Conversation responder → Trajectory DAG: writes replies
- Retrieval thinker → Memory & skills: builds/searches support
- Slack & Telegram bridges → Trajectory DAG: translates inbound events
- Trajectory DAG → Slack & Telegram bridges: selected outbound responses
- Dashboard API → Trajectory DAG: reads and writes
- Timeline viewer → Dashboard API: uses
- Long-lived services → Thinker dispatcher: runs
- Long-lived services → Dashboard API: runs
- Long-lived services → Slack & Telegram bridges: runs
- AWS deployment & alerts → Long-lived services: provisions deployment
