/** * Tool registration functions, delegation module factory, and shared helpers. * * This module owns the "plumbing" layer that sits between the composition * root (`plugin.ts`) and the individual tool/hook implementations: * * - **Tool registration** — `registerDelegationTools`, `registerSessionTools`, * `registerHivemindTools`, `registerConfigTools` build tool maps from deps. * - **Delegation wiring** — `setupDelegationModules` constructs the full v2 * delegation sub-system (state-machine, coordinator, monitor, etc.). * - **Helpers** — session-id extraction, TUI notification predicates, the * in-tree session manager fallback, and pending-notification persistence. * * @module plugin-registration */ import { tool } from "@opencode-ai/plugin/tool"; import { CompletionDetector } from "./coordination/completion/detector.js"; import { DelegationCoordinator } from "./coordination/delegation/coordinator.js"; import { DelegationLifecycle } from "./coordination/delegation/lifecycle.js"; import { DelegationManager } from "./coordination/delegation/manager.js"; import { DelegationMonitor } from "./coordination/delegation/monitor.js"; import { NotificationRouter } from "./coordination/delegation/notification-router.js"; import { PeriodicNotifier } from "./coordination/delegation/periodic-notifier.js"; import { SlotManager } from "./coordination/delegation/slot-manager.js"; import type { Delegation, DelegationNotificationType } from "./coordination/delegation/types.js"; import { type OpenCodeClient } from "./shared/session-api.js"; import { createPtyManagerIfSupported } from "./features/background-command/pty/pty-runtime.js"; import { createTmuxIntegrationIfSupported } from "./features/tmux/integration.js"; import type { ForkSessionManager } from "./features/tmux/observers.js"; import { SessionTracker } from "./features/session-tracker/index.js"; import type { HivemindConfigs } from "./schema-kernel/hivemind-configs.schema.js"; import type { RuntimePolicy } from "./shared/types.js"; /** Timeout for session lifecycle polling (30 minutes). */ export declare const WATCH_TIMEOUT_MS = 1800000; export interface DelegationToolDeps { delegationManager: DelegationManager; hivemindConfig: HivemindConfigs; ptyManager: ReturnType extends Promise ? T : never; tmuxIntegration?: Awaited>; client: OpenCodeClient; monitor: { getEscalationLevel: (id: string) => string | null; }; projectDirectory: string; } export interface SessionToolDeps { client: OpenCodeClient; sessionTracker: SessionTracker; projectDirectory: string; } export interface HivemindToolDeps { projectDirectory: string; } export interface ConfigToolDeps { projectDirectory: string; } /** * Register delegation-domain tools: delegate-task, delegation-status, run-background-command. * * @param deps - Delegation-specific dependencies. * @returns Record of 3 delegation tools. */ export declare function registerDelegationTools(deps: DelegationToolDeps): Record>; /** * Register session-domain tools: execute-slash-command, session-patch, session-journal-export, * session-tracker, session-hierarchy, session-context, create-governance-session. * * @param deps - Session-specific dependencies. * @returns Record of 7 session tools. */ export declare function registerSessionTools(deps: SessionToolDeps): Record>; /** * Register hivemind-domain tools: hivemind-doc, hivemind-trajectory, hivemind-pressure, * hivemind-sdk-supervisor, hivemind-command-engine, hivemind-session-view, * hivemind-agent-work-create, hivemind-agent-work-export. * * @param deps - Hivemind-specific dependencies. * @returns Record of 8 hivemind tools. */ export declare function registerHivemindTools(deps: HivemindToolDeps): Record>; /** * Register config-domain tools: configure-primitive, validate-restart, * bootstrap-init, bootstrap-recover, prompt-skim, prompt-analyze. * * @param deps - Config-specific dependencies. * @returns Record of 6 config tools. */ export declare function registerConfigTools(deps: ConfigToolDeps): Record>; /** Return true only for notification types that should append to the parent TUI. */ export declare function shouldAppendParentTuiNotification(type: DelegationNotificationType): boolean; /** * Build an in-tree ForkSessionManager for builds where the in-tree tmux * integration is not available (e.g. running outside a tmux session, or * the tmux binary is not installed). The observer enriches `session.created` * events with delegation metadata and dispatches them here; in this case * we discard the enriched event. Production builds (with tmux available) * construct a real `SessionManager` inside `createTmuxIntegrationIfSupported` * and publish the adapter via `setSessionManagerAdapter`; the plugin * entry then passes `tmuxIntegration.adapter` to the observer. * * Phase 43 (REQ-05): runtime-injection boundary. * * Phase 51 (REQ-51-06): the "no-op" path is now reached when the factory * returns `null` (silent fallback per D-04), not when the fork package is * absent. Same runtime shape, different trigger. */ export declare function buildInTreeSessionManager(): ForkSessionManager; /** * Extract the session ID from a hook input object, checking multiple * known paths (`sessionID`, `sessionId`, nested `message.sessionID`). */ export declare function extractHookSessionId(input: unknown): string | undefined; /** Extract a short assistant-content excerpt from a chat-message hook payload. */ export declare function extractAssistantExcerpt(input: unknown, output: unknown): string | undefined; /** * Wire the module-level sendPrompt and getSessionMessages functions for * tmux-copilot take-over and peek actions. * * Two modes for sendPrompt: * - steer (noReply:true): sync prompt for immediate context injection * - respond (noReply:false): async prompt with reactivation * * @param client - OpenCode SDK client (must have session.prompt). */ export declare function wireTmuxPromptAndMessages(client: OpenCodeClient): void; /** * Emit a TUI-visible status banner for the tmux subsystem. * * @param client - OpenCode SDK client for TUI logging. * @param tmuxIntegration - The tmux integration result (null if unavailable). * @param projectDirectory - Absolute path to the project root. */ export declare function emitTmuxStatusBanner(client: OpenCodeClient, tmuxIntegration: Awaited> | null, projectDirectory: string): void; /** * Create an event observer that writes journal entries for session lifecycle * events: session.created, tool.execute, and delegation events. * * Journal entries are written to `.hivemind/journal//journal.jsonl` * with idempotency guards to prevent duplicate entries. * * @param projectDirectory - Absolute path to the project root. * @returns Observer function compatible with eventObservers array. */ export declare function createJournalObserver(projectDirectory: string): (input: { event?: unknown; }) => Promise; /** * Group raw delegation notifications by parent session and persist them into * the session continuity store. Used by `NotificationRouter` during delegation * lifecycle transitions. */ export declare function persistPendingDelegationNotifications(records: Array<{ notification: { delegationId: string; message: string; timestamp: number; type: string; }; parentSessionId: string; }>): void; export interface DelegationModuleSetupOptions { client: OpenCodeClient; enableRuntimeAdapter?: boolean; persistDelegations?: (delegations: Delegation[]) => void; projectDirectory: string; ptyManager?: Awaited>; runtimePolicy?: RuntimePolicy; onChildSessionCreated?: (childSessionId: string, parentSessionId: string) => void; /** * P58.8 S1 (REQ-58-07): optional tmux integration result. When supplied, * the session manager reference is wired into DelegationManager so * `dispatch()` can start the capture-pane polling loop after spawning * a child session. */ tmuxIntegration?: Awaited>; } export interface DelegationModuleSetup { coordinator: DelegationCoordinator; delegationManager: DelegationManager; detector: CompletionDetector; lifecycle: DelegationLifecycle; notificationRouter: NotificationRouter; periodicNotifier: PeriodicNotifier; slotManager: SlotManager; monitor: DelegationMonitor; } /** * Build a `Logger` (the shape expected by `createTmuxIntegrationIfSupported`'s * `options.log` parameter) that forwards every call into the OpenCode TUI * `client.app.log` envelope. This makes the integration's silent-null * factory (`f4dd77ac` B3 fix) actually visible to the user — the factory's * `skip(reason)` calls now show up in the TUI log instead of being swallowed. * * The `info` and `warn` levels surface at "info" in the TUI; `debug` is * forwarded at "debug" (typically hidden by default in the OpenCode TUI * but visible in verbose mode). `error` is forwarded at "error". * * The returned logger is purely additive — if `client.app.log` is * unavailable (older OpenCode builds, or partial SDK), every call is a * safe no-op, preserving the factory's existing D-04 silent-fallback * contract. */ export declare function buildTuiTmuxLogger(client: OpenCodeClient | undefined): { debug: (msg: string, data?: unknown) => void; info: (msg: string, data?: unknown) => void; warn: (msg: string, data?: unknown) => void; error: (msg: string, data?: unknown) => void; }; /** * Wires delegate-task v2 modules for the OpenCode plugin composition root. * * @param options - Plugin runtime dependencies and project root. * @returns Delegation modules shared by tools, plugin setup, and integration tests. */ export declare function setupDelegationModules(options: DelegationModuleSetupOptions): DelegationModuleSetup; //# sourceMappingURL=plugin-registration.d.ts.map