Supervisor
The core orchestrator that manages sessions, tasks, and Discord communication.
Overview
The Supervisor class is Tars’ central orchestrator. It manages the GeminiEngine, routes Discord messages, and coordinates background operations through the Heartbeat Service (maintenance) and the Cron Service (scheduled tasks).
Key Responsibilities
- Session Lifecycle — Coordinating with
GeminiEngineto maintain and persist sessions. - Message Routing — Processing Discord prompts and streaming responses back.
- Task Execution — Running background operations via
executeTask()triggered by the Heartbeat and Cron services. - Memory Mutation Detection — Detecting when tools like
memory_store_factare used and invalidating the session to pick up new facts.
Core Methods
run(prompt, callback)
The primary method for interactive prompts from Discord. It:
- Acquires a processing lock (
isProcessingflag) to prevent concurrent access. - Passes the prompt and optional attachments to the
GeminiEngine. - Streams events back to the callback (text chunks, tool calls, errors, done signals).
- Persists the
sessionIdif it was newly generated by the engine. - Invalidate the session if memory-mutating tools were detected.
await supervisor.run('Check deployment status', async (event) => {
if (event.type === 'text') console.log(event.value);
if (event.type === 'done') console.log('Complete');
});
executeTask(prompt)
Used by the Heartbeat and Cron services for background execution. This uses GeminiEngine.runSync() which collects the full response in an ephemeral session — preventing background tasks from bloating the user’s conversation history.
Startup Flow
When the supervisor initializes (via main.ts), it runs several bootstrap operations:
syncAgents: Deploys system-generated agents to~/.tars/.gemini/agents/.syncBuiltInSkills: Syncs built-in skills while preserving user-defined ones.installExtensions: Integrates MCP extensions by copying them to the Gemini environment and configuring safety overrides.GeminiEngine.initialize(): Discovers extensions, performs authentication, and warms up the Native Core.
Concurrency Control
The Supervisor uses an isProcessing lock to prevent multiple prompts from being processed simultaneously by the same instance, ensuring deterministic response patterns.