A personal assistant in a single Go binary. One long-lived daemon owns sessions,
jobs and channels; the terminal UI, pig run and the messaging bots are thin
clients over a Unix socket.
CLI (Bubble Tea) ─┐
pig run ├── Unix socket, JSON-RPC 2.0 ──► daemon ──► provider chain
Telegram │ ├── SQLite
QQ official bot ───┘ ├── job workers
└── skill tool servers
- One binary, one daemon.
pig daemon startdetaches itself; the TUI andpig runreconnect. - Provider failover. Ordered chains per role with failure classification,
cooldown, sticky success, prompt-cache-friendly requests and usage/cost
accounting. Wire adapters:
anthropic,openai-chat,openai-responses,mock. - Tool loop with safe boundaries. Steering, queueing, auto-fork of long turns into background jobs, subagents with their own sessions, built-in convergence control (repeat/stall detection, wrap-up notice).
- Context maintenance. snapcompact archives old turns as glyph-rendered PNG
frames,
shakeelides oversized tool output, plus LLM summaries and an idle scheduler. - Tools.
read,write,edit,bash,todo,task,job,browser,search(web and filesystem),send(files),memory(durable facts),agenda(personal tasks and one-time reminders). - Bash output compression (RTK) with a rule table and a savings ledger.
- Skills.
SKILL.mddiscovery plus stdio JSON-RPC tool servers. - Channels. Telegram long polling and the QQ official bot v2 gateway, with pairing codes, slash commands and job notifications.
- Read-only config.
config.tomlis0444and only changes throughpig config; secrets live inauth.env(0600) viapig auth.
./pig doctor # config, providers, db quick_check, artifacts, disk, daemon
./pig doctor --strict # non-zero when a check fails
docker build -t pig . # reproducible image, non-root, HEALTHCHECK on `pig daemon status`CI runs gofmt, go vet, go test -race and the e2e script on every push.
Deleting a session also deletes its artifacts (rows and blob files), so disk does
not grow with abandoned chats.
go build -o pig ./cmd/pig
export PIG_HOME=~/.pig
./pig config init --provider anthropic --model claude-sonnet-4-5 \
--context-window 200000 --max-output 64000 --input text,image
./pig auth set ANTHROPIC_API_KEY # prompts without echo
./pig daemon start
./pig run "summarize this repo" # one shot
./pig tui # terminal UI (default command)Channels are optional:
./pig auth set PIG_TELEGRAM_TOKEN
./pig config set channel.telegram.enabled true
./pig serve # foreground daemon, requires a channelpig help lists every command; pig docs prints the embedded documentation.
In a paired chat, ask «提醒我 10 分钟后去拿快递» or «把买茶加入待办». Pig uses
agenda for these requests; todo remains the agent's work checklist. Items
belong to the chat, not the session, so /new does not lose them.
The local CLI needs no model call:
pig agenda add 'Buy tea'
pig agenda add --due 10m 'Collect parcel' # or 2030-05-02T08:00:00+08:00
pig agenda # open items, IDs and delivery state
pig agenda done <id> # or: pig agenda cancel <id>
pig agenda list --all --json # includes closed itemsChat reminders go to the original paired chat; terminal reminders appear as
due in the local inbox, not as desktop notifications. An overdue chat item
is picked up when the daemon returns. A send without a confirmed receipt is
unknown and is not retried automatically. Delivery never completes a task.
See daemon operations for upgrades and status values.
| Path | Contents |
|---|---|
cmd/pig |
entry point |
cmd/genfont |
rasterises the snapcompact glyph table |
internal/config |
TOML schema, validation, atomic writes, auth.env |
internal/store |
SQLite: sessions, entries, compactions, jobs, facts |
internal/provider |
wire adapters, failover runner, usage accounting |
internal/agent |
run loop, boundaries, convergence, subagents |
internal/compact |
projection, snapcompact, shake, LLM summaries |
internal/job |
priority queue, workers, crash recovery |
internal/tool |
registry and the built-in tools |
internal/rtk |
bash output compression |
internal/skill |
skill discovery and tool servers |
internal/channel |
channel contract, pairing, rendering |
internal/i18n |
reply catalogs: en, zh, zh-Hant |
internal/daemon |
runtime, IPC methods, channels, scheduler |
internal/tui |
Bubble Tea client |
internal/ipc |
JSON-RPC framing over a Unix socket |
bench |
agent benchmark harness (hermesbench 61-task adapter) |
docs |
embedded docs: config, architecture, daemon, skill authoring |
test |
e2e.sh |
go build ./... && go vet ./...
go test -race ./...
./test/e2e.sh # daemon lifecycle, tools, jobs, config, rtk, snapcompactbench/run_hermesbench.py runs the deterministic 61-task suite from
am423/hermes-bench-tool-call
against Pig (or any harness with a JSON event stream), scores it with the
suite's own verifiers and reports pass@1, tokens, cost at published unit prices
and wall-clock time. bench/README.md documents the tool mapping, the
deviations and the measured results.
macOS and Linux. Windows is not supported: flock, Setsid and Unix sockets
are used directly.
No credentials are stored in this repository. auth.env, config.toml, the
database, artifacts and benchmark worktrees are git-ignored.