import Foundation /// The app-owned adapter between the native feature layer and T3's WebSocket/Core runtime. /// Implementations are main-actor isolated so UI state never depends on locking. @MainActor public protocol FeatureClient: AnyObject { func initialSnapshot() async throws -> FeatureSnapshot func events() -> AsyncStream func pair(endpoint: String, token: String?) async throws func activateEnvironment(id: String) async throws func removeEnvironment(id: String) async throws func disconnect() async func addProject(path: String) async throws func createThread(projectID: String, title: String?, selection: FeatureSelection?) async throws -> FeatureThread func renameThread(id: String, title: String) async throws func setThreadArchived(id: String, archived: Bool) async throws func setThreadSettled(id: String, settled: Bool) async throws func setThreadSnoozed(id: String, until: Date?) async throws func setRuntimeMode(id: String, mode: FeatureRuntimeMode) async throws func setInteractionMode(id: String, mode: FeatureInteractionMode) async throws func deleteThread(id: String) async throws func loadThread(id: String) async throws -> FeatureThreadDetail func sendMessage(threadID: String, text: String, selection: FeatureSelection?) async throws func cancelTurn(threadID: String) async throws func resolveApproval(id: String, decision: FeatureApprovalDecision) async throws func resolveUserInput(id: String, answers: [String: String]) async throws func saveSettings(_ settings: FeatureSettings) async throws func listFiles(threadID: String, path: String?) async throws -> [FeatureFileEntry] func readFile(threadID: String, path: String) async throws -> FeatureFileContent func loadReview(threadID: String) async throws -> FeatureReview func sourceControlStatus(threadID: String) async throws -> FeatureSourceControlStatus func performSourceControlAction( threadID: String, action: FeatureSourceControlAction, message: String? ) async throws -> FeatureSourceControlStatus func terminalSnapshot(threadID: String) async throws -> FeatureTerminalSnapshot func terminalEvents(threadID: String) -> AsyncStream func openTerminal(threadID: String, columns: Int, rows: Int) async throws func writeTerminal(threadID: String, data: String) async throws func resizeTerminal(threadID: String, columns: Int, rows: Int) async throws func closeTerminal(threadID: String) async throws } public extension FeatureClient { func events() -> AsyncStream { AsyncStream { continuation in continuation.finish() } } func activateEnvironment(id: String) async throws {} func removeEnvironment(id: String) async throws {} func disconnect() async {} func addProject(path: String) async throws {} func resolveUserInput(id: String, answers: [String: String]) async throws {} func setThreadSettled(id: String, settled: Bool) async throws {} func setThreadSnoozed(id: String, until: Date?) async throws {} func setRuntimeMode(id: String, mode: FeatureRuntimeMode) async throws {} func setInteractionMode(id: String, mode: FeatureInteractionMode) async throws {} func listFiles(threadID: String, path: String?) async throws -> [FeatureFileEntry] { throw FeatureCapabilityUnavailable("Files") } func readFile(threadID: String, path: String) async throws -> FeatureFileContent { throw FeatureCapabilityUnavailable("File preview") } func loadReview(threadID: String) async throws -> FeatureReview { throw FeatureCapabilityUnavailable("Review") } func sourceControlStatus(threadID: String) async throws -> FeatureSourceControlStatus { throw FeatureCapabilityUnavailable("Source control") } func performSourceControlAction( threadID: String, action: FeatureSourceControlAction, message: String? ) async throws -> FeatureSourceControlStatus { throw FeatureCapabilityUnavailable("Source control actions") } func terminalSnapshot(threadID: String) async throws -> FeatureTerminalSnapshot { throw FeatureCapabilityUnavailable("Terminal") } func terminalEvents(threadID: String) -> AsyncStream { AsyncStream { $0.finish() } } func openTerminal(threadID: String, columns: Int, rows: Int) async throws { throw FeatureCapabilityUnavailable("Terminal") } func writeTerminal(threadID: String, data: String) async throws { throw FeatureCapabilityUnavailable("Terminal") } func resizeTerminal(threadID: String, columns: Int, rows: Int) async throws { throw FeatureCapabilityUnavailable("Terminal") } func closeTerminal(threadID: String) async throws { throw FeatureCapabilityUnavailable("Terminal") } }