import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; import type { AgentSessionSummary } from "./broker/types.js"; import type { PinetReadOptions, PinetReadResult } from "@pinet/pinet-core/pinet-read-formatting"; import { type InboxMessage, type PinetControlCommand, type PinetRemoteControlRequestResult, type SlackBridgeSettings } from "./helpers.js"; export interface SubtreeBrokerPaths { rootDir: string; socketPath: string; dbPath: string; lockPath: string; } export interface SubtreeWorkerRecord { launchId: string; sessionName: string; repoPath: string; role: string; laneId: string | null; agentId: string | null; startedAt: string; monitorCommand: string; } export interface SubtreeBrokerStatus { active: boolean; selfAgentId: string | null; startedAt: string | null; paths: SubtreeBrokerPaths | null; childLaunchEnv: Record; childLaunchHint: string | null; childCount: number; spawnedWorkers: SubtreeWorkerRecord[]; } export interface SubtreeAgentRecord { emoji: string; name: string; id: string; pid?: number; stableId?: string | null; session?: AgentSessionSummary | null; status: "working" | "idle"; metadata: Record | null; lastHeartbeat: string; lastSeen?: string; disconnectedAt?: string | null; resumableUntil?: string | null; outboundCount?: number; pendingInboxCount?: number; parentAgentId?: string | null; rootAgentId?: string | null; treeDepth?: number; supervisionState?: string; subtreeRole?: string | null; laneId?: string | null; } export interface SubtreeSpawnInput { task: string; repo: string; role?: string; laneId?: string; waitForRegistrationMs?: number; } export interface SubtreeSpawnResult { status: "started"; launchId: string; sessionName: string; repoPath: string; role: string; laneId: string | null; agentId: string; agentName: string; messageId: number; threadId: string; monitorCommand: string; socketPath: string; dbPath: string; childLaunchEnv: Record; } export interface SubtreeBrokerRuntimeDeps { cwd: string; getSettings: () => SlackBridgeSettings; getAgentStableId: () => string; getCentralAgentId: () => string | null; getAgentIdentity: () => { name: string; emoji: string; }; getAgentMetadata: (role: "broker" | "worker") => Promise>; getMeshRoleFromMetadata: (metadata: Record | undefined, fallback?: "broker" | "worker") => "broker" | "worker"; pushInboxMessages: (messages: InboxMessage[]) => void; updateBadge: () => void; maybeDrainInboxIfIdle: (ctx: ExtensionContext) => boolean; requestRemoteControl: (command: PinetControlCommand, ctx: ExtensionContext) => PinetRemoteControlRequestResult; runRemoteControl: (command: PinetControlCommand, ctx: ExtensionContext) => void; formatError: (error: unknown) => string; } export interface SubtreeBrokerRuntime { start: (ctx: ExtensionContext) => Promise; stop: (options?: { releaseIdentity?: boolean; stopChildren?: boolean; }) => Promise; getStatus: () => SubtreeBrokerStatus; readInbox: (options?: PinetReadOptions) => PinetReadResult | null; sendMessage: (target: string, body: string, metadata?: Record) => Promise<{ messageId: number; target: string; threadId: string; } | null>; listAgents: (includeGhosts?: boolean) => SubtreeAgentRecord[] | null; spawnWorker: (ctx: ExtensionContext, input: SubtreeSpawnInput) => Promise; isActive: () => boolean; } export declare function buildSubtreeBrokerPaths(stableId: string): SubtreeBrokerPaths; export declare function createSubtreeBrokerRuntime(deps: SubtreeBrokerRuntimeDeps): SubtreeBrokerRuntime;