# helsome/tinycode architecture

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

- Interactive diagram: https://gitdiagram.com/helsome/tinycode
- Repository: https://github.com/helsome/tinycode

## Overview

TinyCode is a TypeScript coding-agent harness. The principal workflow runs from a user prompt through the CLI and bootstrap into a streaming agent loop, where model responses can invoke registered tools under permission checks; results and conversation state are managed, then presented in the TUI. Separate capabilities cover context compaction, sessions, skills, MCP, and supervised read-only sub-agents. Edges follow the excerpts and README; some subsystem wiring is documented rather than shown in sampled implementation, so those links cite the README.

Main entry points: [`src/bootstrap.ts`](https://github.com/helsome/tinycode/blob/main/src/bootstrap.ts) (Runtime bootstrap), [`src/agent/runtime.ts`](https://github.com/helsome/tinycode/blob/main/src/agent/runtime.ts) (Agent loop), [`src/tui/app.ts`](https://github.com/helsome/tinycode/blob/main/src/tui/app.ts) (Terminal UI), [`src/tools/registry.ts`](https://github.com/helsome/tinycode/blob/main/src/tools/registry.ts) (Tool registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and setup"]
  node_cli["CLI<br/>[index.ts]"]
  node_cli_commands["CLI commands<br/>[commands.ts]"]
  node_cli_args["CLI arguments<br/>[args.ts]"]
  node_config["Configuration<br/>[loader.ts]"]
  node_bootstrap["Runtime bootstrap<br/>[bootstrap.ts]"]
end

subgraph group_agent["Agent and policy"]
  node_model["Model registry<br/>[registry.ts]"]
  node_prompt["System prompt<br/>[prompt.ts]"]
  node_runtime["Agent loop<br/>[runtime.ts]"]
  node_permissions["Permission gate<br/>[manager.ts]"]
  node_rules["Permission rules<br/>[rules.ts]"]
  node_classifier["Risk classifier<br/>[classifier.ts]"]
  node_subagents["Sub-agent manager<br/>[manager.ts]"]
  node_workers["Read-only workers<br/>[worker.ts]"]
end

subgraph group_tools["Tools and integrations"]
  node_tool_registry["Tool registry<br/>[registry.ts]"]
  node_builtin_tools["Built-in tools"]
  node_tool_paths["Workspace path guard<br/>[paths.ts]"]
  node_tool_walk["File walker<br/>[walk.ts]"]
  node_skills["Skills registry<br/>[registry.ts]"]
  node_mcp["MCP manager<br/>[manager.ts]"]
  node_mcp_client["MCP client<br/>[client.ts]"]
  node_mcp_adapter["MCP adapter<br/>[adapter.ts]"]
end

subgraph group_state["Conversation state"]
  node_context["Context manager<br/>[manager.ts]"]
  node_compaction["Context compaction<br/>[compact.ts]"]
  node_tool_results["Tool result artifacts<br/>[tool-results.ts]"]
  node_sessions["Session manager<br/>[manager.ts]"]
  node_session_storage[("JSONL storage<br/>[storage.ts]")]
end

subgraph group_interface["User interface"]
  node_tui["Terminal UI<br/>[app.ts]"]
  node_permission_dialog["Approval dialog"]
  node_transcript["Transcript view<br/>[transcript.ts]"]
  node_slash["Slash commands<br/>[slash.ts]"]
end

node_user(("User"))

node_user -->|"starts task"| node_cli
node_cli -->|"parses flags"| node_cli_args
node_cli -->|"dispatches"| node_cli_commands
node_cli_commands -->|"starts harness"| node_bootstrap
node_bootstrap -->|"loads settings"| node_config
node_bootstrap -->|"selects model"| node_model
node_bootstrap -->|"builds prompt"| node_prompt
node_bootstrap -->|"creates runtime"| node_runtime
node_bootstrap -->|"registers tools"| node_tool_registry
node_bootstrap -->|"configures policy"| node_permissions
node_bootstrap -->|"configures context"| node_context
node_bootstrap -->|"creates session"| node_sessions
node_runtime -->|"loads tools"| node_tool_registry
node_runtime -->|"checks calls"| node_permissions
node_runtime -->|"transforms context"| node_context
node_runtime -->|"records messages"| node_sessions
node_permissions -->|"evaluates rules"| node_rules
node_rules -->|"classifies risk"| node_classifier
node_tool_registry -->|"registers suite"| node_builtin_tools
node_builtin_tools -->|"guards paths"| node_tool_paths
node_builtin_tools -->|"walks files"| node_tool_walk
node_bootstrap -->|"discovers skills"| node_skills
node_skills -->|"adds skill tool"| node_tool_registry
node_bootstrap -->|"starts servers"| node_mcp
node_mcp -->|"connects clients"| node_mcp_client
node_bootstrap -->|"adapts tools"| node_mcp_adapter
node_mcp_adapter -->|"adds MCP tools"| node_tool_registry
node_bootstrap -->|"creates workers"| node_subagents
node_subagents -->|"spawns workers"| node_workers
node_context -->|"compacts turns"| node_compaction
node_context -->|"truncates results"| node_tool_results
node_sessions -->|"persists history"| node_session_storage
node_cli -->|"launches interface"| node_tui
node_tui -->|"prompts agent"| node_runtime
node_tui -->|"prompts approval"| node_permission_dialog
node_tui -->|"renders events"| node_transcript
node_tui -->|"dispatches commands"| node_slash
node_user -->|"enters prompts"| node_tui

click node_cli "https://github.com/helsome/tinycode/blob/main/src/cli/index.ts"
click node_cli_commands "https://github.com/helsome/tinycode/blob/main/src/cli/commands.ts"
click node_cli_args "https://github.com/helsome/tinycode/blob/main/src/cli/args.ts"
click node_config "https://github.com/helsome/tinycode/blob/main/src/config/loader.ts"
click node_bootstrap "https://github.com/helsome/tinycode/blob/main/src/bootstrap.ts"
click node_model "https://github.com/helsome/tinycode/blob/main/src/model/registry.ts"
click node_prompt "https://github.com/helsome/tinycode/blob/main/src/agent/prompt.ts"
click node_runtime "https://github.com/helsome/tinycode/blob/main/src/agent/runtime.ts"
click node_permissions "https://github.com/helsome/tinycode/blob/main/src/permissions/manager.ts"
click node_rules "https://github.com/helsome/tinycode/blob/main/src/permissions/rules.ts"
click node_classifier "https://github.com/helsome/tinycode/blob/main/src/permissions/classifier.ts"
click node_tool_registry "https://github.com/helsome/tinycode/blob/main/src/tools/registry.ts"
click node_builtin_tools "https://github.com/helsome/tinycode/tree/main/src/tools"
click node_tool_paths "https://github.com/helsome/tinycode/blob/main/src/tools/paths.ts"
click node_tool_walk "https://github.com/helsome/tinycode/blob/main/src/tools/walk.ts"
click node_skills "https://github.com/helsome/tinycode/blob/main/src/skills/registry.ts"
click node_mcp "https://github.com/helsome/tinycode/blob/main/src/mcp/manager.ts"
click node_mcp_client "https://github.com/helsome/tinycode/blob/main/src/mcp/client.ts"
click node_mcp_adapter "https://github.com/helsome/tinycode/blob/main/src/mcp/adapter.ts"
click node_subagents "https://github.com/helsome/tinycode/blob/main/src/agents/manager.ts"
click node_workers "https://github.com/helsome/tinycode/blob/main/src/agents/worker.ts"
click node_context "https://github.com/helsome/tinycode/blob/main/src/context/manager.ts"
click node_compaction "https://github.com/helsome/tinycode/blob/main/src/context/compact.ts"
click node_tool_results "https://github.com/helsome/tinycode/blob/main/src/context/tool-results.ts"
click node_sessions "https://github.com/helsome/tinycode/blob/main/src/session/manager.ts"
click node_session_storage "https://github.com/helsome/tinycode/blob/main/src/session/storage.ts"
click node_tui "https://github.com/helsome/tinycode/blob/main/src/tui/app.ts"
click node_permission_dialog "https://github.com/helsome/tinycode/blob/main/src/tui/permission-dialog.ts"
click node_transcript "https://github.com/helsome/tinycode/blob/main/src/tui/transcript.ts"
click node_slash "https://github.com/helsome/tinycode/blob/main/src/tui/slash.ts"

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_cli,node_cli_commands,node_cli_args,node_config,node_bootstrap,node_user toneBlue
class node_model,node_prompt,node_runtime,node_permissions,node_rules,node_classifier,node_subagents,node_workers toneAmber
class node_tool_registry,node_builtin_tools,node_tool_paths,node_tool_walk,node_skills,node_mcp,node_mcp_client,node_mcp_adapter toneMint
class node_context,node_compaction,node_tool_results,node_sessions,node_session_storage toneRose
class node_tui,node_permission_dialog,node_transcript,node_slash toneIndigo
```

## Components

### Entry and setup

- [CLI](https://github.com/helsome/tinycode/blob/main/src/cli/index.ts): `src/cli/index.ts`
- [CLI commands](https://github.com/helsome/tinycode/blob/main/src/cli/commands.ts): `src/cli/commands.ts`
- [CLI arguments](https://github.com/helsome/tinycode/blob/main/src/cli/args.ts): `src/cli/args.ts`
- [Configuration](https://github.com/helsome/tinycode/blob/main/src/config/loader.ts): `src/config/loader.ts`
- [Runtime bootstrap](https://github.com/helsome/tinycode/blob/main/src/bootstrap.ts): `src/bootstrap.ts`

### Agent and policy

- [Model registry](https://github.com/helsome/tinycode/blob/main/src/model/registry.ts): `src/model/registry.ts`
- [System prompt](https://github.com/helsome/tinycode/blob/main/src/agent/prompt.ts): `src/agent/prompt.ts`
- [Agent loop](https://github.com/helsome/tinycode/blob/main/src/agent/runtime.ts): `src/agent/runtime.ts`
- [Permission gate](https://github.com/helsome/tinycode/blob/main/src/permissions/manager.ts): `src/permissions/manager.ts`
- [Permission rules](https://github.com/helsome/tinycode/blob/main/src/permissions/rules.ts): `src/permissions/rules.ts`
- [Risk classifier](https://github.com/helsome/tinycode/blob/main/src/permissions/classifier.ts): `src/permissions/classifier.ts`
- [Sub-agent manager](https://github.com/helsome/tinycode/blob/main/src/agents/manager.ts): `src/agents/manager.ts`
- [Read-only workers](https://github.com/helsome/tinycode/blob/main/src/agents/worker.ts): `src/agents/worker.ts`

### Tools and integrations

- [Tool registry](https://github.com/helsome/tinycode/blob/main/src/tools/registry.ts): `src/tools/registry.ts`
- [Built-in tools](https://github.com/helsome/tinycode/tree/main/src/tools): `src/tools`
- [Workspace path guard](https://github.com/helsome/tinycode/blob/main/src/tools/paths.ts): `src/tools/paths.ts`
- [File walker](https://github.com/helsome/tinycode/blob/main/src/tools/walk.ts): `src/tools/walk.ts`
- [Skills registry](https://github.com/helsome/tinycode/blob/main/src/skills/registry.ts): `src/skills/registry.ts`
- [MCP manager](https://github.com/helsome/tinycode/blob/main/src/mcp/manager.ts): `src/mcp/manager.ts`
- [MCP client](https://github.com/helsome/tinycode/blob/main/src/mcp/client.ts): `src/mcp/client.ts`
- [MCP adapter](https://github.com/helsome/tinycode/blob/main/src/mcp/adapter.ts): `src/mcp/adapter.ts`

### Conversation state

- [Context manager](https://github.com/helsome/tinycode/blob/main/src/context/manager.ts): `src/context/manager.ts`
- [Context compaction](https://github.com/helsome/tinycode/blob/main/src/context/compact.ts): `src/context/compact.ts`
- [Tool result artifacts](https://github.com/helsome/tinycode/blob/main/src/context/tool-results.ts): `src/context/tool-results.ts`
- [Session manager](https://github.com/helsome/tinycode/blob/main/src/session/manager.ts): `src/session/manager.ts`
- [JSONL storage](https://github.com/helsome/tinycode/blob/main/src/session/storage.ts): `src/session/storage.ts`

### User interface

- [Terminal UI](https://github.com/helsome/tinycode/blob/main/src/tui/app.ts): `src/tui/app.ts`
- [Approval dialog](https://github.com/helsome/tinycode/blob/main/src/tui/permission-dialog.ts): `src/tui/permission-dialog.ts`
- [Transcript view](https://github.com/helsome/tinycode/blob/main/src/tui/transcript.ts): `src/tui/transcript.ts`
- [Slash commands](https://github.com/helsome/tinycode/blob/main/src/tui/slash.ts): `src/tui/slash.ts`

### Other components

- **User**

## Connections

- User → CLI: starts task (evidence: `README.md`)
- CLI → CLI arguments: parses flags (evidence: `src/cli/index.ts`)
- CLI → CLI commands: dispatches (evidence: `src/cli/index.ts`)
- CLI commands → Runtime bootstrap: starts harness (evidence: `src/cli/commands.ts`)
- Runtime bootstrap → Configuration: loads settings (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Model registry: selects model (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → System prompt: builds prompt (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Agent loop: creates runtime (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Tool registry: registers tools (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Permission gate: configures policy (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Context manager: configures context (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → Session manager: creates session (evidence: `src/bootstrap.ts`)
- Agent loop → Tool registry: loads tools (evidence: `src/agent/runtime.ts`)
- Agent loop → Permission gate: checks calls (evidence: `src/agent/runtime.ts`)
- Agent loop → Context manager: transforms context (evidence: `src/agent/runtime.ts`)
- Agent loop → Session manager: records messages (evidence: `src/agent/runtime.ts`)
- Permission gate → Permission rules: evaluates rules (evidence: `src/permissions/manager.ts`)
- Permission rules → Risk classifier: classifies risk (evidence: `src/permissions/rules.ts`)
- Tool registry → Built-in tools: registers suite (evidence: `src/tools/index.ts`)
- Built-in tools → Workspace path guard: guards paths (evidence: `src/tools/read.ts`)
- Built-in tools → File walker: walks files (evidence: `src/tools/find.ts`)
- Runtime bootstrap → Skills registry: discovers skills (evidence: `src/bootstrap.ts`)
- Skills registry → Tool registry: adds skill tool (evidence: `src/bootstrap.ts`)
- Runtime bootstrap → MCP manager: starts servers (evidence: `src/bootstrap.ts`)
- MCP manager → MCP client: connects clients (evidence: `src/mcp/manager.ts`)
- Runtime bootstrap → MCP adapter: adapts tools (evidence: `src/bootstrap.ts`)
- MCP adapter → Tool registry: adds MCP tools (evidence: `src/mcp/adapter.ts`)
- Runtime bootstrap → Sub-agent manager: creates workers (evidence: `src/bootstrap.ts`)
- Sub-agent manager → Read-only workers: spawns workers (evidence: `src/agents/manager.ts`)
- Context manager → Context compaction: compacts turns (evidence: `src/context/manager.ts`)
- Context manager → Tool result artifacts: truncates results (evidence: `src/context/manager.ts`)
- Session manager → JSONL storage: persists history (evidence: `src/session/manager.ts`)
- CLI → Terminal UI: launches interface (evidence: `src/cli/index.ts`)
- Terminal UI → Agent loop: prompts agent (evidence: `src/tui/app.ts`)
- Terminal UI → Approval dialog: prompts approval (evidence: `src/tui/app.ts`)
- Terminal UI → Transcript view: renders events (evidence: `src/tui/app.ts`)
- Terminal UI → Slash commands: dispatches commands (evidence: `src/tui/app.ts`)
- User → Terminal UI: enters prompts (evidence: `README.md`)
