tg-bot-dev
Use this skill when you need to change the Telegram bot under tg_bot/ (commands, queue/control plane, keyboards, state, delivery, systemd behaviour).
Key principles
- •Control plane vs work plane: “control plane” actions must work even while Codex is busy; Codex-triggering work stays serialized via the queue.
- •KISS / modularity: keep
router.pyfocused on semantics,keyboards.pyon callback_data + markup,app.pyon runtime wiring (poll/worker),state.pyon persistence. - •Tests-first during implementation: for every new callback/command/state field, add or extend unit tests under
tg_bot/tests/while you code. - •Lazy refactor: if you touch a function/file that’s getting too complex and the refactor is small, do it immediately. If it’s non-trivial/risky, write a refactor plan as a separate tech note under
notes/technical/(what/why/how, scope boundaries). - •Callback data hygiene:
callback_datamust stay<= 64 bytes; keep prefixes short and add tests for encoding/limits.
Workflow
- •Orient on current behaviour
- •Read
tg_bot/README.mdfor the contract (commands, env vars, safety rules). - •For queue-related changes, locate existing plan/notes in
notes/technical/.
- •Implement in the right layer
- •
tg_bot/router.py: parse/route commands and callbacks; keep behaviour deterministic. - •
tg_bot/keyboards.py: defineCB_*constants and keyboard builders (no business logic). - •
tg_bot/app.py: poller/worker wiring, queue/spool, bypass rules (control plane). - •
tg_bot/state.py: persistent state only (add load/save + defaults + tests).
- •Add tests while coding
- •Prefer small unit tests (no network; no Telegram calls) under
tg_bot/tests/. - •Use the existing
python-testsskill for exact commands and TMPDIR handling when running tests.
- •Validate quickly
- •Syntax smoke:
python3 -m py_compile tg_bot/app.py tg_bot/router.py tg_bot/keyboards.py tg_bot/state.py - •Unit tests:
TMPDIR="$PWD/.tmp/pytests" python3 -m unittest discover -s tg_bot/tests -v
- •Commit and push frequently
- •Keep commits small and conventional (
feat(tg-bot): ...,fix(tg-bot): ...,test(tg-bot): ...). - •Push after each logically complete slice (so deploy/restart is easy to validate).