import { type WorkingStatus } from '../../constants.js';
import type { EventBusService } from '../event-bus/event-bus.service.js';
/**
 * Team Working Status File Structure
 * Tracks ONLY workingStatus (idle vs in_progress) based on terminal activity
 * agentStatus is now managed by AgentHeartbeatService via MCP calls
 */
export interface TeamWorkingStatusFile {
    /** Orchestrator working status */
    orchestrator: {
        sessionName: string;
        workingStatus: WorkingStatus;
        lastActivityCheck: string;
        updatedAt: string;
    };
    /** Team member working statuses indexed by sessionName */
    teamMembers: Record<string, {
        sessionName: string;
        teamMemberId: string;
        workingStatus: WorkingStatus;
        lastActivityCheck: string;
        updatedAt: string;
    }>;
    /** File metadata */
    metadata: {
        lastUpdated: string;
        version: string;
    };
}
/**
 * Activity Monitor Service - NEW ARCHITECTURE
 *
 * Responsibilities:
 * - Track ONLY workingStatus (idle vs in_progress) based on terminal activity
 * - Create and manage teamWorkingStatus.json file
 * - Integrate with AgentHeartbeatService for stale agent detection
 * - Remove ALL agentStatus management (now owned by AgentHeartbeatService)
 *
 * Key Changes:
 * - No more agentStatus updates to teams.json
 * - Simple activity detection: output changed = in_progress, else = idle
 * - Integration with stale detection (30-minute threshold)
 * - Separate teamWorkingStatus.json file for working statuses
 */
export declare class ActivityMonitorService {
    private static instance;
    private logger;
    private storageService;
    private _sessionBackend;
    private agentHeartbeatService;
    private intervalId;
    private readonly POLLING_INTERVAL;
    private lastTerminalOutputs;
    private readonly MAX_OUTPUT_SIZE;
    private readonly ACTIVITY_CHECK_TIMEOUT;
    private lastCleanup;
    private crewlyHome;
    private teamWorkingStatusFile;
    private eventBusService;
    /** Tracks when each session entered in_progress (epoch ms) */
    private busyTransitionTimestamps;
    /** Tracks which sessions have had their agent:busy event emitted */
    private busyEventEmitted;
    /** Tracks last recorded token counts per session to avoid duplicate recording */
    private lastRecordedTokens;
    /** Cached tokenTracking setting, refreshed periodically to avoid async reads in hot path */
    private tokenTrackingEnabled;
    private tokenTrackingLastCheck;
    private constructor();
    /**
     * Get the session backend, lazily initializing if needed.
     */
    private getBackend;
    static getInstance(): ActivityMonitorService;
    /**
     * Inject the EventBusService for direct event publishing on status transitions.
     *
     * @param service - The EventBusService instance
     */
    setEventBusService(service: EventBusService): void;
    /**
     * Build an AgentEvent for a working status transition.
     *
     * @param type - The event type ('agent:busy' or 'agent:idle')
     * @param timestamp - ISO timestamp for the event
     * @param identity - Agent identity fields (team/member/session)
     * @param previousValue - The previous working status
     * @param newValue - The new working status
     * @returns A fully-formed AgentEvent
     */
    private buildAgentEvent;
    /**
     * Handle duration-gated event emission for a session status transition.
     * Suppresses spurious idle→busy→idle cycles by requiring a minimum
     * busy duration (MIN_BUSY_DURATION_MS) before emitting events.
     *
     * @param key - Unique key for tracking (e.g. 'orchestrator' or session name)
     * @param newStatus - The new working status
     * @param previousStatus - The previous working status
     * @param statusChanged - Whether the status actually changed this poll
     * @param identity - Agent identity fields for building the event
     * @param now - ISO timestamp for the event
     */
    private handleDurationGatedEmission;
    startPolling(): void;
    stopPolling(): void;
    private performActivityCheck;
    /**
     * NEW ARCHITECTURE: Simplified activity checking
     *
     * This method now:
     * 1. Detects stale agents via AgentHeartbeatService (30-minute threshold)
     * 2. Checks terminal activity for working status (ONLY)
     * 3. Updates teamWorkingStatus.json (separate from teams.json)
     * 4. Removes ALL agentStatus logic (handled by AgentHeartbeatService)
     */
    private performActivityCheckInternal;
    /**
     * Load teamWorkingStatus.json file with proper initialization
     */
    private loadTeamWorkingStatusFile;
    /**
     * Save teamWorkingStatus.json file with atomic write
     */
    private saveTeamWorkingStatusFile;
    /**
     * Create default teamWorkingStatus.json structure
     */
    private createDefaultTeamWorkingStatusFile;
    /**
     * Cleanup old terminal outputs and perform garbage collection
     */
    private performPeriodicCleanup;
    /**
     * Attempt to parse and record token usage from PTY terminal output.
     *
     * Only records when token tracking is enabled in settings and when the
     * parsed token counts differ from the last recorded values (to avoid
     * duplicate recording from the same output being captured multiple times).
     *
     * @param sessionName - Agent session name
     * @param output - Captured terminal output
     * @param runtimeType - Runtime type hint for parser selection
     */
    private tryRecordPtyTokenUsage;
    /**
     * Get terminal output with size limits for activity detection
     */
    private getTerminalOutput;
    isRunning(): boolean;
    getPollingInterval(): number;
    /**
     * Get current team working status data
     * Useful for external services that need to check working statuses
     */
    getTeamWorkingStatus(): Promise<TeamWorkingStatusFile>;
    /**
     * Get working status for a specific session
     */
    getWorkingStatusForSession(sessionName: string): Promise<WorkingStatus | null>;
}
//# sourceMappingURL=activity-monitor.service.d.ts.map