# leighklotz/answer architecture

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

- Interactive diagram: https://gitdiagram.com/leighklotz/answer
- Repository: https://github.com/leighklotz/answer
- Video tour (about a minute): https://gitdiagram.com/leighklotz/answer/video

## Overview

#### Project purpose

Answer is a Bash-based Linux/macOS code-assistant toolchain. It treats LLM requests and responses as Unix pipeline data, supporting interactive terminal use, machine-readable conversation streams, multi-turn chaining, context ingestion, and controlled code extraction.

#### Core components

- **Conversation entry and response rendering — `bin/ask`**  
  Public `ask`, `help`, and `answer` commands construct prompts, accept standard input, preserve conversation history in pipeline mode, and render the final assistant response. Interactive use is documented as producing plain text, while piped use emits structured JSON intended for downstream commands.

- **Context and command adapters — `bin/lx`**  
  `lx` ingests one or more files as markdown-formatted context. `bx` captures shell-command output for inclusion in an LLM request. These adapters let external shell commands and files become prompt inputs without taking ownership of the caller’s workspace.

- **Execution and extraction boundary — `bin/unfence`**  
  `unfence` extracts targeted code blocks from model output and provides a review/confirmation step before output is passed to an interpreter such as Bash or Python. The interpreter is application- or user-supplied, not part of this repository.

- **Workspace, session, and model management — `bin/commands/hx.sh`**  
  The `hx` management interface enables or disables shell integration, configures model settings, controls cache behavior, and exposes recent interaction information. `bin/commands/hx-bootstrap.sh` supports installing the shell integration into a Bash session.

- **Caching and provenance — `bin/commands/cache.sh`**  
  The documented runtime state includes JSON inference cache entries under a discovered project `.hallux` workspace, with a fallback under `~/.config/hallux/.cache/`. Cache commands manage retention and session caching. Provenance commands under `bin/commands/provenance.sh` record selected interactions as Git notes under `provenance/hallux`; this is separate from inference caching and Bash history.

- **Shared shell and optional integrations — `bin/functions.sh`**  
  Common shell behavior is organized in shared functions and command scripts. `bin/tools` provides an optional bridge to the external `toolex` project for native LLM tool calls; it is not the primary request path.

#### External interfaces

The main interfaces are Bash commands, standard input/output/error, environment variables, local filesystem state, and a configured LLM API or self-hosted endpoint. Users may pipe results into ordinary Unix utilities or into external interpreters. Git is an external owner of provenance notes, and Bash owns the underlying command history files.

#### Relationships

A user or shell command supplies prompts, files, or command output to `ask`/`help`, optionally through `lx` or `bx`. Those commands create conversation data for the configured LLM path; `answer` terminates a structured pipeline by producing plain text. A downstream `ask` or `help` can consume the structured history and append another turn. `unfence` forms a separate safety boundary between generated text and user-selected interpreters. `hx` manages the session, workspace discovery, model settings, cache controls, and provenance operations around these command-line interactions.

Main entry points: [`bin/ask`](https://github.com/leighklotz/answer/blob/main/bin/ask) (ask / help / answer), [`bin/commands/hx.sh`](https://github.com/leighklotz/answer/blob/main/bin/commands/hx.sh) (hx management), [`bin/lx`](https://github.com/leighklotz/answer/blob/main/bin/lx) (lx / bx), [`bin/unfence`](https://github.com/leighklotz/answer/blob/main/bin/unfence) (unfence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["Command interfaces"]
  node_ask["ask / help / answer<br/>conversation CLI"]
  node_adapters["lx / bx<br/>context adapters"]
  node_unfence["unfence<br/>code extraction boundary"]
  node_tools["toolex bridge<br/>optional integration"]
end

subgraph group_management["Session and state"]
  node_hx["hx management<br/>session manager<br/>[hx.sh]"]
  node_workspace[("Project .hallux workspace<br/>runtime state")]
  node_cache["Inference cache<br/>cache manager<br/>[cache.sh]"]
  node_provenance["Provenance<br/>[provenance.sh]"]
end

node_shell(("User / shell command<br/>external caller"))
node_interpreter(("Bash / Python interpreter<br/>external interpreter"))
node_llm(("Configured LLM endpoint<br/>external model service"))
node_git[("Git<br/>external provenance store")]
node_toolex(("toolex<br/>external tool system"))

node_shell -->|"supplies prompts"| node_ask
node_shell -->|"supplies files/output"| node_adapters
node_adapters -->|"provides context"| node_ask
node_ask -->|"sends requests"| node_llm
node_llm -->|"returns responses"| node_ask
node_ask -->|"emits conversation data"| node_shell
node_shell -->|"selects generated code"| node_unfence
node_unfence -->|"passes reviewed code"| node_interpreter
node_hx -->|"discovers workspace"| node_workspace
node_hx -->|"controls caching"| node_cache
node_cache -->|"stores cache entries"| node_workspace
node_hx -->|"exposes operations"| node_provenance
node_provenance -->|"records notes"| node_git
node_ask -.->|"optionally bridges tools"| node_tools
node_tools -.->|"calls tool system"| node_toolex

click node_ask "https://github.com/leighklotz/answer/blob/main/bin/ask"
click node_adapters "https://github.com/leighklotz/answer/blob/main/bin/lx"
click node_unfence "https://github.com/leighklotz/answer/blob/main/bin/unfence"
click node_hx "https://github.com/leighklotz/answer/blob/main/bin/commands/hx.sh"
click node_cache "https://github.com/leighklotz/answer/blob/main/bin/commands/cache.sh"
click node_provenance "https://github.com/leighklotz/answer/blob/main/bin/commands/provenance.sh"
click node_tools "https://github.com/leighklotz/answer/blob/main/bin/tools"

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_ask,node_adapters,node_unfence,node_tools toneBlue
class node_hx,node_workspace,node_cache,node_provenance toneAmber
class node_shell,node_interpreter,node_llm,node_git,node_toolex toneNeutral
```

## Components

### Command interfaces

Bash commands for prompts, context, and code extraction.

- [ask / help / answer](https://github.com/leighklotz/answer/blob/main/bin/ask): conversation CLI · Builds prompts, preserves pipeline history, and renders responses. · `bin/ask`
- [lx / bx](https://github.com/leighklotz/answer/blob/main/bin/lx): context adapters · Turns files and shell output into prompt context. · `bin/lx`
- [unfence](https://github.com/leighklotz/answer/blob/main/bin/unfence): code extraction boundary · Reviews selected generated code before execution. · `bin/unfence`
- [toolex bridge](https://github.com/leighklotz/answer/blob/main/bin/tools): optional integration · Optional bridge for native LLM tool calls. · `bin/tools`

### Session and state

Workspace, cache, and provenance management.

- [hx management](https://github.com/leighklotz/answer/blob/main/bin/commands/hx.sh): session manager · Controls shell integration, models, cache behavior, and interaction information. · `bin/commands/hx.sh`
- **Project .hallux workspace**: runtime state · Discovered workspace for JSON inference cache entries.
- [Inference cache](https://github.com/leighklotz/answer/blob/main/bin/commands/cache.sh): cache manager · Manages retention and session caching, with a user fallback cache. · `bin/commands/cache.sh`
- [Provenance](https://github.com/leighklotz/answer/blob/main/bin/commands/provenance.sh): provenance manager · Records selected interactions as Git notes. · `bin/commands/provenance.sh`

### Other components

- **User / shell command**: external caller
- **Bash / Python interpreter**: external interpreter
- **Configured LLM endpoint**: external model service
- **Git**: external provenance store
- **toolex**: external tool system

## Connections

- User / shell command → ask / help / answer: supplies prompts
- User / shell command → lx / bx: supplies files/output
- lx / bx → ask / help / answer: provides context
- ask / help / answer → Configured LLM endpoint: sends requests
- Configured LLM endpoint → ask / help / answer: returns responses
- ask / help / answer → User / shell command: emits conversation data
- User / shell command → unfence: selects generated code
- unfence → Bash / Python interpreter: passes reviewed code
- hx management → Project .hallux workspace: discovers workspace
- hx management → Inference cache: controls caching
- Inference cache → Project .hallux workspace: stores cache entries
- hx management → Provenance: exposes operations
- Provenance → Git: records notes
- ask / help / answer → toolex bridge: optionally bridges tools
- toolex bridge → toolex: calls tool system
