Routines, bots and goals
Routines, bots, services and goals sit next to tasks.
Paths in crates/axe-core/src/, crates/axe-telegram/src/, crates/axe-node/src/, crates/axe-server/src/ or crates/axe/src/ (a file is in one) unless noted.
These sit next to tasks with their own tables, API and CLI namespace; task code gains no branches for them.
- Routines (
axe routine,routine.rs) create ordinary pending tasks on a five-field cron in an IANA timezone. After downtime only the latest missed occurrence is created; manual triggers take a retry key. A template can set the created task's owner, repos and labels likeaxe task add(routine::Template). Each task keeps a snapshot of the template it came from. Cost controls on the template (pre_check,model,effort,skills) are read from that snapshot by the node (dispatch/pre_check.rs, skills/axe/references/routines.md). - Bots (
axe bot,bot.rs,dispatch/bots.rs) are persistent identities with one agent session resumed on every wake. Wakes come from the bot itself, named cron schedules (schedule.rs), task-event subscriptions (subscription.rs) and the Telegram gateway (telegram.rs,board.rs). A voice message reaches the bot as a local transcript marked[voice message, auto-transcribed, may contain errors]: the node runs SenseVoice-Small (sherpa-onnx) in a child process before the run, with no API or key, and keeps the audio as the message's attachment (transcribe.rs; off with[defaults] transcribe_voice = false). The server replies "Transcribing…" to the voice message at once and edits that reply into the transcript, or a failure line, when the node stores it (telegram.rsvoice_acks). Design: docs/design/bots.md. - Services (
axe service,service.rs,dispatch/services.rs) are long-running processes a bot declares: name, shell command, cwd (default the bot's run folder), env and restart policy (always,on-failure,never).axe service set <name> --command <cmd> [--cwd D] [--env K=V] [--restart P],list,start,stop,log [-n N]andrm, with--botdefaulting to$AXE_BOT. The server stores the declarations; a long-runningaxe noderuns every enabled one as its own child process group (sh -c, withAXE_BOT,AXE_SERVICE,AXE_SERVERand the bot's sealed values), its output in<log_dir>/services/<bot>/<name>.log(rotated past[services] log_bytes, one old file kept). An exit is restarted by the policy with a delay that doubles per quick crash; a crash loop wakes the bot, and one still goingescalate_after_secondslater messages the owner too. Stopping the node sends SIGTERM to every service and SIGKILL afterstop_grace_seconds(keep it under the unit's stop timeout); starting it starts every enabled service again. A drain (SIGUSR1) first wakes each owning bot ("Services stop in N s") and keeps the services running forstop_warn_seconds. No systemd unit or container per service: they live and die with the node.[services]inconfig.rslists every knob and default. A scheduled service (--cron "<5 fields>" [--timezone TZ] [--timeout 10m] [--no-catch-up], stored inservices.schedule) is the node's crontab: the node runs it at each cron time, one run at a time (a run time during a run is skipped), stops a run past its timeout (SIGTERM, then SIGKILL) and reports its last exit, end and next run; a timeout or a non-zero exit is afailedservice event. Run times missed while the node was down are not replayed: at most one catch-up run when it starts (dispatch/services.rs). Routines stay server-side and create tasks. Bot/status,axe bot showand the dashboard's Services page (per node, with recent logs) show each service's kind, state (crash-looping included), restarts and uptime, or for a scheduled one its last run, exit and next run (Service::summary,web/lib/services.ts). - Goals (
axe goal,goal.rs,goal_board.rs) are durable outcomes bots share, with weekly budgets and an append-only trajectory. Design: docs/design/goals.md.
Delivery statistics (axe stats, flow.rs) and run cost (usage.rs) are
computed from the event log and run usage; the only recorded classifications
are an escalation's class (axe task escalate --class) and a task's workload.
Run usage comes from the run log. A run's cost is the tool's own figure
first, else axe's price table (usage::PRICES), keyed provider/model with
time windows such as DeepSeek's peak hours: each run's new tokens are priced
at the window its run started in. A Claude run's cost is the costUSD that
Claude Code reports when it priced the model from its list
(costBasis: "list"); a figure it made up for a model it does not know
counts as none. A run on a provider's login (Claude Code on DeepSeek) records
its models as provider/model, without Claude Code's [1m] suffix. A Codex
run's tokens come from the running total in codex exec --json. Its model
comes from the Codex session transcript in the runtime's login directory. Its
cost is estimated from the table's OpenAI Standard API prices
(usage::openai_price). Neither Claude's nor Codex's figure is what a
subscription plan bills. A model with no figure and no table row keeps its
tokens at $0; a Codex run whose transcript is gone does so under the model
codex. axe usage backfill reads Codex transcripts from the node's
runtimes. An OpenCode run's tokens and cost are the sum of its
step_finish lines in opencode run --format json (its own model calls
only; the server adds the session's previous run, Parsed::per_run), its
output tokens include its reasoning, and its model is the one the node ran
it with (provider/model: the rule's, else the runtime's default), since
the log does not name it (usage::parse_opencode, Parsed::with_model).
A Pi run's are the sum of its assistant message_end lines in
pi --mode json (also its own model calls only, Parsed::per_run), each
naming its provider and model (provider/model) and carrying the cost Pi
priced; its output tokens include its reasoning (usage::parse_pi).
Cost covers the whole install by default: the dashboard's Cost view and a
bot's Telegram /cost (last 7 days) total every bot run and task run. Their
split by bot counts each run once, under one bot: a bot's own runs plus the
runs of tasks it owns (--owner bot:<name>), everything else under no bot
(usage::owner_bot). Telegram /cost is short: one headline line (total,
runs, how many have unknown usage) and a bar per day. Its Bot, Project, Model
and Runtime buttons edit the reply in place to that one breakdown (the top 5
and the rest as one "others" line), and ‹ Total goes back; the server answers
the presses, with no bot wake. It has no web link or button. Runs with
unknown usage are counted, never shown as $0.
/cost <bot> is that bot's own runs only, with the same buttons but Bot.
GET /api/views/cost?arg=... renders the same text; by=owner|project|model|agent
in arg picks a breakdown.
The Cost view's "Per run and per task" charts plot, per day (per week past
31 days), the cost per run and the cost per finished task, each as an "All"
line and one line per model or per runtime. Cost per run is the known cost of
the runs that ended that day divided by those runs; a run counts once, at its
whole cost, under the model that cost the most in it. Cost per task is the
known cost of all runs of the tasks finished that day (last moved to done),
whenever those runs ended, divided by those tasks; a task counts under the model
or runtime that cost the most across its runs. Runs with unknown usage are left
out of both ratios and counted separately: a task whose runs are all unknown is
not in the count, and periods with unknown runs are shaded. The series buckets
of GET /api/stats/cost carry the figures as per_run and per_task
(usage::cost_stats).
Every dashboard chart with a time axis (Cost, Stats, a bot's Stats tab, Node)
labels and buckets time in the viewer's browser time zone: a day runs from
local midnight to local midnight, and custom From/To dates are local dates.
GET /api/stats/cost takes tz=<IANA zone> (for example tz=Asia/Taipei)
for that: its step_days series and its day and week breakdowns then
follow calendar days in that zone; without tz they are UTC, and an unknown
zone is a 400.