ton

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT

README

ton

TON

English | 简体中文

CI Go

AI Engineering Session — a local TUI orchestrator for long-running, auditable coding-agent sessions.

ton runs the loop humans usually babysit by hand:

Clarify → Ready → /start → Plan → Execute → Verify ⇄ Repair → Summarize

It drives headless local agents (OpenCode / Claude Code / Cursor CLI), keeps a milestone-first UI, and persists the full audit trail under <workspace>/.ton/.

Status: v1 candidate. Core session loop is implemented (clarify → plan → execute → verify ⇄ repair → summarize, soft/hard stop, Git, budget, crash resume, session lock). CI runs go vet / go test / build with the built-in fake driver covering orchestration. Live OpenCode / Claude / Cursor still need their CLIs + auth on your machine — treat those as integration smoke, not CI coverage.

Why ton

Pain What ton does
Agents lose the plot mid-task Explicit clarify + Ready gate before unattended work
Logs vanish into a scrollback Milestones in the TUI; events/verify logs on disk
Failures need a human at 2am Session verify gate + repair loop with exhausted policies
Switching CLIs means rewriting glue Pluggable drivers behind one session model

Install

Preferred: install the release binary onto your user PATH (no Go required).

# Linux / macOS → ~/.local/bin (prints a PATH hint if that dir is missing)
curl -fsSL https://raw.githubusercontent.com/toninfo/ton/main/install.sh | bash
# Windows PowerShell → %LOCALAPPDATA%\ton\bin and updates your User PATH
irm https://raw.githubusercontent.com/toninfo/ton/main/install.ps1 | iex

Pin a release if needed: TON_VERSION=v1.0.0 before the curl/irm line.

Open a new terminal, then:

ton doctor

Later updates (release binary installs):

ton upgrade          # latest GitHub release
ton upgrade --check  # report only
# or inside the TUI: /upgrade  ·  /upgrade check
Alternative: Go / source

go install writes to $(go env GOPATH)/bin (often ~/go/bin or %USERPROFILE%\go\bin). That directory is frequently not on PATH, so ton will appear “not installed” until you add it — prefer the installers above unless you already manage a Go bin directory.

# Requires Go 1.24+
go install github.com/toninfo/ton/cmd/ton@latest
export PATH="$(go env GOPATH)/bin:$PATH"   # bash/zsh; reopen shell after

# From a checkout → ~/.local/bin
git clone https://github.com/toninfo/ton.git
cd ton && make install

Manual archives (linux / darwin / windows × amd64 / arm64) are attached to each GitHub Release.

Quick start

ton needs two engines: an OpenAI-compatible LLM (clarify docs/cards + conductor) and a local coding-agent CLI (plan/execute/repair after /start).

Always prefer a writable project directory (<workspace>/.ton/ + agent edits). Unwritable cwd without -w falls back to ~/ton-workspace.

ton setup --api-key …             # once: writes ~/.config/ton/llm.env
ton doctor                        # scan agents + print config paths
cd /path/to/your/project
ton                               # or: ton -w /path/to/your/project

Optional: pin driver (export TON_DRIVER=opencode); unset → auto-scan.

In the TUI: describe the goal → refine until Ready/start.

Command Purpose
/start Plan + unattended execute/verify/repair
/docs [preview|open|req|design] Review requirements/design (TUI preview + open docs folder); alias /review
/status Compact phase · subphase · queue · driver · why
/todos Toggle plan items
/stop `[soft hard]`
/driver <name> Switch backend (auto rescans and chooses)
/model <name> Switch clarify/plan model
/key <api_key> Save LLM key to ~/.config/ton/llm.env
/queue Show queued input kinds during execution
/brief <text> Queue next-step brief (execute boundaries)
/skip Queue skip current step (execute boundaries)
/export Re-export todos.md / report artifacts
/upgrade [version|check] Install latest (or pinned) GitHub release; alias /update

Working state is first-class: Execute / Verify / Repair / Summarize show live phase, subphase, milestones, and queued input depth — without dumping agent transcripts into the UI.

Roles (LLM · Agent · ton)
Role Responsibility
LLM Clarify docs + cards / conductor / plan constraints / verify & step-exhaust / summarize
Coding agent After /start: todos.json, repo mutations, repairs
ton /start, schema contracts, real Verify, Git, resume, budget, TUI

Clarify is LLM-only. After /start, the coding agent writes under .ton/sessions/<id>/ (file contract). Defaults maximize unattended work: agent auto-selected, sandbox off, and git auto-commit after successful steps — clarify never asks about these.

Security note

ton runs local coding agents against your workspace. Defaults are automation-first: sandbox off, optional git auto-commit, and some drivers use elevated flags (e.g. Cursor --force --trust). Only use trusted workspaces; see SECURITY.md.

Architecture

Session loop, package map, and what belongs in extras/docs/ARCHITECTURE.md.

Configuration

Load order:

  1. Built-in defaults
  2. ~/.config/ton/config.yaml
  3. Environment variables
Variable Purpose
TON_LLM_API_KEY Clarify/plan API key (required for live clarify)
TON_LLM_BASE_URL OpenAI-compatible base URL
TON_LLM_MODEL Planning model
TON_DRIVER Pin opencode · claude · cursor · fake; auto/unset scans
TON_WORKSPACE Default workspace path
TON_CONFIG_DIR Override the config dir (default ~/.config/ton); relocates config.yaml + llm.env
TON_LOG_LEVEL Log level
CURSOR_API_KEY Cursor CLI auth when needed

See extras/config.yaml for an annotated file and docs/CONFIGURATION.md for the full field reference. ton config prints the effective config with secrets redacted. ton setup --help explains the LLM triad (base_url + model + API key).

Windows: verify gates run through the default shell. powershell / pwsh work out of the box; POSIX-style gate commands (e.g. test -f) need bash on PATH (Git Bash / WSL). See verify.shell in the config reference.

ton config
ton doctor
ton doctor --probe-serve
ton sessions
ton serve status   # OpenCode serve surface (lifecycle still maturing)

Drivers

When driver.default / TON_DRIVER is unset or auto, ton scans PATH (opencodeclaudeagent) and caches under ~/.local/share/ton/discovered_agents.json (default TTL 24h). TTL expiry, ton doctor, /driver auto, or agent failure triggers a rescan; auto mode may switch to another available agent on failure. Explicit pins are always honored.

Driver Executable Mode
opencode opencode Headless JSON; optional workspace serve
claude claude -p + stream-json
cursor agent --force --trust + stream-json
fake (none) Deterministic backend for tests/demos (explicit only)

Authenticate the chosen driver first, then /start. ton records events, verification output, repair rounds, and report.md under .ton/sessions/<id>/.

Exit codes

Code Meaning
0 Done
1 Generic error / still running
2 Aborted
3 Failed
4 Done with failed steps

Development

make check    # go vet + go test
make build
make snapshot # optional: goreleaser --snapshot

Config reference: docs/CONFIGURATION.md

Contributing

See CONTRIBUTING.md and the Code of Conduct. Security reports go through SECURITY.md only. Release notes: CHANGELOG.md.

License

MIT © 2026 toninfo

Directories

Path Synopsis
cmd
ton command
internal
artifacts
Package artifacts define the session product contract path (agent is the authoritative agent, stdout is only auxiliary evidence).
Package artifacts define the session product contract path (agent is the authoritative agent, stdout is only auxiliary evidence).
backend/core
Package core holds the dependency-free backend contract.
Package core holds the dependency-free backend contract.
brand
Package brand centralizes product name and path/environment variable conventions.
Package brand centralizes product name and path/environment variable conventions.
browserenv
Package browserenv forces browser automation (Playwright MCP / Chromium) to stay headless.
Package browserenv forces browser automation (Playwright MCP / Chromium) to stay headless.
budget
Package budget accumulates Agent usage and enforces session budget policies at step boundaries (design §16).
Package budget accumulates Agent usage and enforces session budget policies at step boundaries (design §16).
buildinfo
Package buildinfo holds build metadata injected by GoReleaser/-ldflags.
Package buildinfo holds build metadata injected by GoReleaser/-ldflags.
clarify
Package clarify manages requirement clarification and the Ready-to-Start gate.
Package clarify manages requirement clarification and the Ready-to-Start gate.
cli
Package cli defines the ton command-line interface.
Package cli defines the ton command-line interface.
control
Package control defines the control signals of the LLM process director (candidate for orchestration authority).
Package control defines the control signals of the LLM process director (candidate for orchestration authority).
discover
Package discover scans the agent CLI available on the machine and caches the results for automatic selection.
Package discover scans the agent CLI available on the machine and caches the results for automatic selection.
doctor
Package doctor implements dependency checks used by the CLI.
Package doctor implements dependency checks used by the CLI.
gitmgr
Package gitmgr encapsulates Git operations that must be performed by ton, rather than delegated to an agent model.
Package gitmgr encapsulates Git operations that must be performed by ton, rather than delegated to an agent model.
llm
Package llm provides the OpenAI-compatible chat client used by ton.
Package llm provides the OpenAI-compatible chat client used by ton.
orch
Package orch contains the pure state-transition rules for an ton session.
Package orch contains the pure state-transition rules for an ton session.
plan
Package plan generates and validates the ordered implementation plan.
Package plan generates and validates the ordered implementation plan.
repair
Package repair turns a failed session gate into a constrained agent repair run.
Package repair turns a failed session gate into a constrained agent repair run.
repocontext
Package repocontext provides lightweight repository snapshots for the grinding/command layer (does not replace the agent toolring).
Package repocontext provides lightweight repository snapshots for the grinding/command layer (does not replace the agent toolring).
report
Package report renders the durable session summary written to report.md.
Package report renders the durable session summary written to report.md.
sandbox
Package sandbox optionally constrains the writable range of agents during the running-in period.
Package sandbox optionally constrains the writable range of agents during the running-in period.
secrets
Package secrets manage the local LLM API key placement (without entering yaml or warehouse).
Package secrets manage the local LLM API key placement (without entering yaml or warehouse).
selfupdate
Package selfupdate downloads ton release binaries from GitHub and replaces the running executable.
Package selfupdate downloads ton release binaries from GitHub and replaces the running executable.
serve
Package serve manages the OpenCode serve process at the workspace level.
Package serve manages the OpenCode serve process at the workspace level.
tui
Package tui provides the interactive Bubble Tea interface for ton sessions.
Package tui provides the interactive Bubble Tea interface for ton sessions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL