ductor
CLAUDE.md457 starsChanged 9 months agoMITView on GitHub
This file gives coding agents a current map of the repository. ductor is a multi-transport chat orchestrator for the official provider CLIs (claude, codex, gemini, agy, grok). It runs Telegram, Matrix and/or Slack, can expose an optional direct WebSocket API, keeps state under ~/.ductor, and supervises the main agent plus optional sub-agents in one asyncio process. Background and async delivery:
- Reads credentials
- Installs packages
The file
We split this CLAUDE.md into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 106
All run as in-process asyncio tasks:
- Distinctive: line 120
update observer (upgradeable installs)
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
This file gives coding agents a current map of the repository.
Project Overview
ductor is a multi-transport chat orchestrator for the official provider CLIs (claude, codex, gemini, agy, grok).
It runs Telegram, Matrix and/or Slack, can expose an optional direct WebSocket API, keeps state under ~/.ductor, and supervises the main agent plus optional sub-agents in one asyncio process.
Stack:
- Python 3.11+
- aiogram 3.x (Telegram)
- matrix-nio (Matrix, optional extra)
- slack-bolt (Slack, optional extra)
- aiohttp (webhook server, internal API, optional direct API)
- Pydantic 2.x
- asyncio
Development Commands
# Setup
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Run
ductor
ductor -v
# Tests
pytest
pytest -k "pattern"
# Quality
ruff format .
ruff check .
mypy ductor_botRuntime Flow
Telegram:
Update -> AuthMiddleware -> SequentialMiddleware -> TelegramBot
-> Orchestrator -> CLIService -> provider subprocess -> Telegram delivery
Matrix:
sync event -> MatrixBot auth/room checks -> Orchestrator
-> CLIService -> provider subprocess -> Matrix delivery
API (optional):
/ws auth (token + e2e_pk + optional chat_id/channel_id)
-> encrypted frames -> Orchestrator streaming -> encrypted result eventsBackground and async delivery:
Observer / TaskHub / InterAgentBus callback
-> bus.adapters -> Envelope -> MessageBus
-> optional shared lock + optional session injection
-> registered transport adapters (TelegramTransport / MatrixTransport)Module Map
| Module | Purpose |
cli_commands/ | CLI command implementations (service, docker, api, agents, lifecycle, install, status) |
messenger/ | transport protocol, capabilities, notifications, registry, multi-transport adapter |
messenger/telegram/ | Telegram transport: middleware, handlers, startup, callback routing, file/media UX |
messenger/matrix/ | Matrix transport: sync loop, auth, segment streaming, reaction buttons, media |
messenger/slack/ | Slack transport: Socket Mode bot, native streaming, ID mapping, sender/media |
orchestrator/ | command routing, directives/hooks, flows, provider/session/task wiring, lifecycle split |
bus/ | unified Envelope, MessageBus, shared LockPool, delivery adapters |
cli/ | provider wrappers, stream parsing, auth detection, model caches, process registry |
session/ | SessionKey(transport, chat_id, topic_id), provider-isolated session buckets, named sessions |
tasks/ | delegated background task runtime (TaskHub) and persistent registry |
background/ | named background session execution for /session |
multiagent/ | supervisor, inter-agent bus, internal localhost API bridge, shared knowledge sync |
api/ | optional direct WebSocket API and authenticated file endpoints |
cron/, webhook/, heartbeat/, cleanup/ | in-process automation observers |
workspace/ | ~/.ductor path model, seeding, rule deployment/sync, skill sync |
infra/ | PID lock, service backends, Docker manager, restart/update/recovery helpers |
files/ | shared file/path safety, MIME detection, image processing (image_processor.py: resize/convert incoming images) |
security/, text/ | prompt safety, formatting helpers |
Key Runtime Patterns
DuctorPathsinworkspace/paths.pyis the single source of truth for runtime paths.- Session identity is
SessionKey(transport, chat_id, topic_id)across Telegram chats/topics, Matrix rooms (mapped int), and API channel isolation. /newresets the configured default-provider bucket for the active session key./resetresets the currently active provider bucket for the active session key.MessageBusis the single async delivery path for observers, task callbacks, webhook wake results, and async inter-agent responses. Delivery is transport-aware: UNICAST envelopes route to the matching transport only, with cascading fallback when the target transport is unavailable.- Telegram ingress and
MessageBusshare oneLockPool;ApiServercurrently uses its own lock pool. - Workspace init is zone-based:
- Zone 2 overwrite:
CLAUDE.md,AGENTS.md,GEMINI.md, framework-managed tool scripts - Zone 3 seed-once: user-owned files
- Zone 2 overwrite:
- Rule sync is mtime-based for sibling
CLAUDE.md/AGENTS.md/GEMINI.md; cron task folders additionally get missing rule backfill.AGENTS.mdserves Codex and Grok — like Codex, Grok loads project rules fromAGENTS.md(RulesSelectordeploys it when either is authenticated). - Skill sync spans
~/.ductor/workspace/skills,~/.claude/skills,~/.codex/skills,~/.gemini/skills,~/.grok/skills:- normal mode: links/junctions
- Docker mode: managed copies (
.ductor_managed)
ductor agents addis a Telegram-focused scaffold; Matrix sub-agents are supported throughagents.jsonor the bundled agent tool scripts.
Background Systems
All run as in-process asyncio tasks:
BackgroundObserver(named sessions)CronObserver(results route UNICAST when job haschat_id, BROADCAST otherwise)WebhookObserverHeartbeatObserver(supportsgroup_targetswith per-target overrides)CleanupObserverCodexCacheObserverGeminiCacheObserverAntigravityCacheObserverGrokCacheObserver- config reloader
- rule sync watcher
- skill sync watcher
- update observer (upgradeable installs)
The four model-cache observers start only for provider CLIs found by startup auth detection (installed_providers), not by a plain PATH lookup.
Service Backends
Platform dispatch lives in infra/service.py:
- Linux: systemd user service (
infra/service_linux.py) - macOS: launchd Launch Agent (
infra/service_macos.py) - Windows: Task Scheduler (
infra/service_windows.py)
Operational notes:
- onboarding offers service install when a backend is available
stop_bot()stops the installed service first so it does not immediately respawn the processductor service logsbehavior:- Linux:
journalctl --user -u ductor -f - macOS/Windows: recent lines from
~/.ductor/logs/agent.log(fallback newest*.log)
- Linux:
CLI Surface
Core:
ductor,ductor onboarding,ductor resetductor status,ductor stop,ductor restart,ductor upgrade,ductor uninstall
Groups:
ductor service <install|status|start|stop|logs|uninstall>ductor docker <rebuild|enable|disable|mount|unmount|mounts|extras|extras-add|extras-remove>ductor api <enable|disable>ductor agents <list|add|remove>ductor install <matrix|slack|api>
Nuances:
ductor agents addinteractively scaffolds Telegram sub-agents only- Matrix sub-agents are still first-class at runtime; define them in
agents.jsonor via the bundled agent tools
Key Data Files (~/.ductor)
config/config.json.envsessions.jsonnamed_sessions.jsontasks.jsoncron_jobs.jsonwebhooks.jsonagents.jsonstartup_state.jsoninflight_turns.jsonchat_activity.jsonSHAREDMEMORY.mdlogs/agent.logworkspace/
Conventions
asyncio_mode = "auto"in tests- line length 100
- mypy strict mode
- ruff strict lint profile
- config deep-merge adds new defaults without dropping user keys
- supervisor restart code is
42
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

