/** * mailbox-tool — Tool that exposes the inter-agent mailbox to agents. * * Sub-commands: check, send, ack, query, status, online, unread * * Uses the project-level GlobalMailbox for cross-session communication. * Agents are auto-registered on first use with heartbeat tracking. * Read receipts track who read each message and when. * * @module mailbox-tool */ import type { EventBus } from '../kernel/events.js'; import type { Context } from '../core/context.js'; import type { Tool } from '../types/tool.js'; import { type Mailbox, type MailboxAudience } from './mailbox-types.js'; export type MailboxResolver = (ctx: Context) => Mailbox; export interface MailboxToolOptions { /** * How to obtain a Mailbox instance given the execution Context. * Default: derives project dir from ctx and creates a GlobalMailbox. */ resolveMailbox?: MailboxResolver | undefined; /** * Agent id of the caller — used as default "from" on send. * Default: 'leader' for the main agent, or derived from ctx.meta. */ agentId?: string | undefined; /** Session id for cross-session communication. Default: derived from ctx. */ sessionId?: string | undefined; /** * Project directory where the mailbox is stored. * Default: derived from ctx.projectRoot (may differ from wpaths.projectDir). * For correct cross-session sharing, pass `wpaths.projectDir` from the caller. */ projectDir?: string | undefined; /** * EventBus for emitting mailbox.agent_registered and mailbox.agent_heartbeat * events so the TUI/WebUI can update the online agent count in the status bar. * When omitted, events are not emitted and the status bar count stays at 0. */ events?: EventBus | undefined; } export declare function defaultResolveProjectDir(ctx: Context): string; /** * Compact, deterministic tag for a session id — 8 hex chars of its sha256. * Session ids are date-sharded paths ("2026-06-11/sess_"); * the tag keeps mailbox identities short, filesystem-safe, and stable for * the lifetime of the session (including across process restarts/resumes). */ export declare function mailboxSessionTag(sessionId: string): string; /** * Resolve the caller's mailbox identity from the execution Context. * * Shared by the `mailbox` power-tool, the thin `mail_send`/`mail_inbox` * tools, the agent-loop checker, and the /mailbox slash command so every * surface agrees on who is talking: * - base id: ctx.meta.agentId → ctx.agentId field (subagents) → fallback * - unique id: `@` — SESSION-bound, not pid-bound. Every * session has its own id, so two leader sessions on the same project * never collide (pids can be recycled by the OS), and a resumed session * keeps its identity: read state survives a restart instead of * re-flooding old broadcasts. Derived LIVE from ctx.session.id so an * in-process session swap (resume / session.new / project switch) moves * the identity with it. `ctx.meta.globalAgentId` remains an explicit * override for hosts that manage identity themselves. */ export declare function resolveMailboxIdentity(ctx: Context, fallbackBase?: string): { baseId: string; callerId: string; name: string; role?: string | undefined; sessionId: string; }; /** * Apply sender-specific delivery restrictions before a message is persisted. * Chimera workers report only to main agents; enforcing that here keeps the * invariant intact even if a model requests a peer or project broadcast. */ export declare function applyMailboxSendPolicy(ctx: Context, identity: Pick, 'baseId' | 'name'>, requestedTo: string, requestedAudience?: MailboxAudience): { to: string; audience?: MailboxAudience; }; export declare function makeMailboxTool(opts?: MailboxToolOptions): Tool; //# sourceMappingURL=mailbox-tool.d.ts.map