SPB Git

Repository Public

SystemDTO.swift 19.3 KB 442 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Claude Remote / Codex Remote9// File             : Packages/ClaudeRemoteKit/Sources/ClaudeRemoteModels/SystemDTO.swift10// Module           : ClaudeRemoteModels11// Repository       : https://git.spboucher.ai/claude-remote-apple12// Project Website  : https://claude.spboucher.ai13// Created          : 2026-11-2914// Last Modified    : 2026-11-2915//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author           : Simon-Pierre Boucher21// Position         : Professor of Finance22// Institution      : Université du Québec en Outaouais (UQO)23// Department       : Département des sciences administratives24// Organization     : SP Boucher25//26// Website          : https://spboucher.ai27// Git              : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General          : info@spboucher.ai34// Professional     : contact@spboucher.ai35// Direct           : simon@spboucher.ai36// Research         : research@spboucher.ai37// Development      : dev@spboucher.ai38// Support          : support@spboucher.ai39// Security/Admin   : admin@spboucher.ai40// Notifications    : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification   : Public67// Distribution     : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License          : None specified (no license file in this repository)81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation8990// MARK: Skills / MCP9192public enum SkillSource: OpenStringEnum {93    case user, project, plugin, registry94    case unknown(String)95    public static var known: [(SkillSource, String)] { [(.user, "user"), (.project, "project"), (.plugin, "plugin"), (.registry, "registry")] }96    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }97}9899public struct SkillInfo: Codable, Hashable, Sendable, Identifiable {100    public var name: String101    public var description: String102    public var source: SkillSource103    public var kind: SkillKind104    public var version: String?105    /// Display label like "~/.claude/skills/foo".106    public var location: String107    public var enabled: Bool108    /// Nil = registry not connected.109    public var updateAvailable: Bool?110    public var id: String { "\(source.rawValue)/\(kind.rawValue)/\(name)" }111}112113public enum SkillScope: String, Codable, Sendable, CaseIterable {114    case user, project115}116117/// Body of `POST /skills/op`. Nothing is fetched from the network and no skill code runs.118public enum SkillOp: Hashable, Sendable, Encodable {119    /// Copies a directory inside a project into the user's skills.120    case install(projectId: String, path: String, replace: Bool = false)121    case remove(name: String, kind: SkillKind, scope: SkillScope = .user, projectId: String? = nil)122    case enable(name: String, kind: SkillKind, scope: SkillScope = .user, projectId: String? = nil)123    case disable(name: String, kind: SkillKind, scope: SkillScope = .user, projectId: String? = nil)124    /// Answers 501 `not_implemented` on current servers.125    case installFromRegistry(name: String)126127    private enum Keys: String, CodingKey { case op, projectId, path, replace, name, kind, scope }128    public func encode(to encoder: Encoder) throws {129        var c = encoder.container(keyedBy: Keys.self)130        func named(_ op: String, _ name: String, _ kind: SkillKind, _ scope: SkillScope, _ projectId: String?) throws {131            try c.encode(op, forKey: .op); try c.encode(name, forKey: .name); try c.encode(kind, forKey: .kind)132            try c.encode(scope, forKey: .scope); try c.encodeIfPresent(projectId, forKey: .projectId)133        }134        switch self {135        case .install(let projectId, let path, let replace):136            try c.encode("install", forKey: .op); try c.encode(projectId, forKey: .projectId)137            try c.encode(path, forKey: .path); try c.encode(replace, forKey: .replace)138        case .remove(let n, let k, let s, let p): try named("remove", n, k, s, p)139        case .enable(let n, let k, let s, let p): try named("enable", n, k, s, p)140        case .disable(let n, let k, let s, let p): try named("disable", n, k, s, p)141        case .installFromRegistry(let name):142            try c.encode("install-registry", forKey: .op); try c.encode(name, forKey: .name)143        }144    }145}146147/// `GET /skills/registry/search`: `connected == false` until the registry exposes an API.148public struct SkillRegistrySearch: Codable, Hashable, Sendable {149    public var connected: Bool150    public var results: [JSONValue]151}152153public enum McpScope: OpenStringEnum {154    case user, project, local155    case unknown(String)156    public static var known: [(McpScope, String)] { [(.user, "user"), (.project, "project"), (.local, "local")] }157    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }158}159160public enum McpStatus: OpenStringEnum {161    case connected, failed, needsAuth, notChecked162    case unknown(String)163    public static var known: [(McpStatus, String)] {164        [(.connected, "connected"), (.failed, "failed"), (.needsAuth, "needs_auth"), (.notChecked, "unknown")]165    }166    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }167}168169public struct McpServerInfo: Codable, Hashable, Sendable, Identifiable {170    public var name: String171    public var scope: McpScope172    public var transport: McpTransport173    /// Command or URL. Secret values (headers, env) are never returned by the server.174    public var target: String175    /// Names only.176    public var envKeys: [String]177    public var status: McpStatus178    public var lastError: String?179    public var checkedAt: Date?180    public var id: String { "\(scope.rawValue)/\(name)" }181}182183public struct AddMcpServer: Codable, Hashable, Sendable {184    public var name: String185    public var transport: McpTransport186    public var target: String187    public var args: [String]188    /// Write-only: never echoed back.189    public var env: [String: String]190    /// Write-only.191    public var headers: [String: String]192    public var scope: SkillScope193    public var projectId: String?194195    public init(name: String, transport: McpTransport, target: String, args: [String] = [], env: [String: String] = [:],196                headers: [String: String] = [:], scope: SkillScope = .user, projectId: String? = nil) {197        self.name = name; self.transport = transport; self.target = target; self.args = args; self.env = env198        self.headers = headers; self.scope = scope; self.projectId = projectId199    }200201    /// Same rule as the server: a leading "-" would be read as an option by the CLI.202    public static func isValidName(_ name: String) -> Bool {203        name.range(of: #"^[A-Za-z0-9_][A-Za-z0-9_-]{0,39}$"#, options: .regularExpression) != nil204    }205}206207// MARK: System208209public struct ComponentHealth: Codable, Hashable, Sendable, Identifiable {210    public var component: String211    public var health: Health212    public var detail: String?213    public var checkedAt: Date214    public var id: String { component }215}216217public struct SystemStatus: Codable, Hashable, Sendable {218    public struct Host: Codable, Hashable, Sendable {219        public var name: String220        public var cpuPct: Double?221        public var load: [Double]222        public var memUsedMb: Double?223        public var memTotalMb: Double?224        public var diskFreeGb: Double?225        public var diskTotalGb: Double?226        public var uptimeSec: Double?227    }228    public struct Counts: Codable, Hashable, Sendable {229        public var liveSessions: Int230        public var wsClients: Int231        public var runningTasks: Int232        public var queuedTasks: Int233    }234    /// The instance's agent CLI (wire key `claude`, historical).235    public struct AgentCLI: Codable, Hashable, Sendable {236        public var version: String?237        public var authenticated: Bool?238        /// Sent by a Codex instance only; absent ⇒ claude.239        public var agent: AgentID?240        public var agentName: String?241    }242    public var collectedAt: Date243    public var version: String244    public var components: [ComponentHealth]245    public var host: Host246    public var counts: Counts247    public var agentCLI: AgentCLI248249    private enum CodingKeys: String, CodingKey {250        case collectedAt, version, components, host, counts251        case agentCLI = "claude"252    }253}254255/// `GET /health` (public).256public struct ServerHealth: Codable, Hashable, Sendable {257    public var ok: Bool258    public var version: String259    public var agent: AgentID?260}261262public struct AuditEvent: Codable, Hashable, Sendable, Identifiable {263    /// Numeric string; pass the last one as `before` to paginate.264    public var id: String265    public var at: Date266    public var actor: String267    public var action: String268    public var target: String?269    public var ip: String?270    public var ok: Bool271    public var detail: [String: JSONValue]272}273274// MARK: Notifications275276public enum NotificationKind: OpenStringEnum {277    case sessionWaiting, sessionExited, taskSucceeded, taskFailed, nodeOffline, storageLow, system278    case unknown(String)279    public static var known: [(NotificationKind, String)] {280        [(.sessionWaiting, "session.waiting"), (.sessionExited, "session.exited"), (.taskSucceeded, "task.succeeded"),281         (.taskFailed, "task.failed"), (.nodeOffline, "node.offline"), (.storageLow, "storage.low"), (.system, "system")]282    }283    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }284}285286/// A server notification. Named `ServerNotification` to stay clear of `Foundation.Notification`.287public struct ServerNotification: Codable, Hashable, Sendable, Identifiable {288    public var id: String289    public var kind: NotificationKind290    public var title: String291    /// Generic by default; the detail level is a user setting. Never terminal content.292    public var body: String293    /// Web path such as `/terminal/?s=<id>`; map it with `DeepLinkRouter`.294    public var link: String?295    public var readAt: Date?296    public var createdAt: Date297    public var isUnread: Bool { readAt == nil }298299    public init(id: String, kind: NotificationKind, title: String, body: String, link: String?, readAt: Date?, createdAt: Date) {300        self.id = id; self.kind = kind; self.title = title; self.body = body; self.link = link; self.readAt = readAt; self.createdAt = createdAt301    }302}303304public struct NotificationsReadResult: Codable, Hashable, Sendable {305    public var ok: Bool306    public var updated: Int307}308309// MARK: Settings310311public enum ThemePreference: OpenStringEnum {312    case light, dark, system313    case unknown(String)314    public static var known: [(ThemePreference, String)] { [(.light, "light"), (.dark, "dark"), (.system, "system")] }315    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }316}317318public enum TerminalThemePreference: OpenStringEnum {319    /// Follows the app theme.320    case auto321    case light, dark322    case unknown(String)323    public static var known: [(TerminalThemePreference, String)] { [(.auto, "auto"), (.light, "light"), (.dark, "dark")] }324    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }325}326327public enum WorkspaceLayout: OpenStringEnum {328    case terminal, terminalFiles, terminalEditor, terminalMonitoring, research329    case unknown(String)330    public static var known: [(WorkspaceLayout, String)] {331        [(.terminal, "terminal"), (.terminalFiles, "terminal+files"), (.terminalEditor, "terminal+editor"),332         (.terminalMonitoring, "terminal+monitoring"), (.research, "research")]333    }334    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }335}336337public enum NotificationDetail: OpenStringEnum {338    case generic, titles339    case unknown(String)340    public static var known: [(NotificationDetail, String)] { [(.generic, "generic"), (.titles, "titles")] }341    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }342}343344/// User settings, shared with the web application (`GET/PUT /settings`). Decoding applies the345/// server's defaults to any missing member; unknown members of `notifications` are preserved.346public struct UserSettings: Codable, Hashable, Sendable {347    public struct Notifications: Codable, Hashable, Sendable {348        public var inApp: Bool349        public var webPush: Bool350        public var detail: NotificationDetail351        /// Native push (contract §3); default true.352        public var push: Bool353354        public init(inApp: Bool = true, webPush: Bool = false, detail: NotificationDetail = .generic, push: Bool = true) {355            self.inApp = inApp; self.webPush = webPush; self.detail = detail; self.push = push356        }357        public init(from decoder: Decoder) throws {358            let c = try decoder.container(keyedBy: CodingKeys.self)359            inApp = try c.decodeIfPresent(Bool.self, forKey: .inApp) ?? true360            webPush = try c.decodeIfPresent(Bool.self, forKey: .webPush) ?? false361            detail = try c.decodeIfPresent(NotificationDetail.self, forKey: .detail) ?? .generic362            push = try c.decodeIfPresent(Bool.self, forKey: .push) ?? true363        }364    }365366    public var theme: ThemePreference367    public var terminalTheme: TerminalThemePreference368    public var terminalFont: String369    public var terminalFontSize: Double370    public var mobileFontSize: Double371    public var scrollback: Int372    public var defaultProjectId: String?373    public var defaultLayout: WorkspaceLayout374    public var notifications: Notifications375    public var sessionRetentionDays: Int376    /// Key ids of the mobile key row (`TerminalKey` ids in ClaudeRemoteTerminal).377    public var mobileToolbar: [String]378    public var autosave: Bool379    /// Persisted panel sizes etc. of the web app; round-tripped untouched.380    public var layout: [String: JSONValue]381382    public static let defaultMobileToolbar = ["esc", "tab", "ctrl", "alt", "shift", "up", "down", "left", "right", "enter", "/", "|", "~", "-"]383384    private enum CodingKeys: String, CodingKey {385        case theme, terminalTheme, terminalFont, terminalFontSize, mobileFontSize, scrollback, defaultProjectId, defaultLayout386        case notifications, sessionRetentionDays, mobileToolbar, autosave, layout387    }388389    public init() {390        theme = .light; terminalTheme = .auto; terminalFont = "JetBrains Mono"; terminalFontSize = 13; mobileFontSize = 12391        scrollback = 5000; defaultProjectId = nil; defaultLayout = .terminalFiles; notifications = Notifications()392        sessionRetentionDays = 90; mobileToolbar = Self.defaultMobileToolbar; autosave = false; layout = [:]393    }394395    public init(from decoder: Decoder) throws {396        let d = UserSettings()397        let c = try decoder.container(keyedBy: CodingKeys.self)398        theme = try c.decodeIfPresent(ThemePreference.self, forKey: .theme) ?? d.theme399        terminalTheme = try c.decodeIfPresent(TerminalThemePreference.self, forKey: .terminalTheme) ?? d.terminalTheme400        terminalFont = try c.decodeIfPresent(String.self, forKey: .terminalFont) ?? d.terminalFont401        terminalFontSize = try c.decodeIfPresent(Double.self, forKey: .terminalFontSize) ?? d.terminalFontSize402        mobileFontSize = try c.decodeIfPresent(Double.self, forKey: .mobileFontSize) ?? d.mobileFontSize403        scrollback = try c.decodeIfPresent(Int.self, forKey: .scrollback) ?? d.scrollback404        defaultProjectId = try c.decodeIfPresent(String.self, forKey: .defaultProjectId)405        defaultLayout = try c.decodeIfPresent(WorkspaceLayout.self, forKey: .defaultLayout) ?? d.defaultLayout406        notifications = try c.decodeIfPresent(Notifications.self, forKey: .notifications) ?? d.notifications407        sessionRetentionDays = try c.decodeIfPresent(Int.self, forKey: .sessionRetentionDays) ?? d.sessionRetentionDays408        mobileToolbar = try c.decodeIfPresent([String].self, forKey: .mobileToolbar) ?? d.mobileToolbar409        autosave = try c.decodeIfPresent(Bool.self, forKey: .autosave) ?? d.autosave410        layout = try c.decodeIfPresent([String: JSONValue].self, forKey: .layout) ?? [:]411    }412413    public func encode(to encoder: Encoder) throws {414        var c = encoder.container(keyedBy: CodingKeys.self)415        try c.encode(theme, forKey: .theme)416        try c.encode(terminalTheme, forKey: .terminalTheme)417        try c.encode(terminalFont, forKey: .terminalFont)418        try c.encode(min(max(terminalFontSize, 8), 28), forKey: .terminalFontSize)419        try c.encode(min(max(mobileFontSize, 8), 28), forKey: .mobileFontSize)420        try c.encode(min(max(scrollback, 500), 50000), forKey: .scrollback)421        try c.encode(defaultProjectId, forKey: .defaultProjectId)422        try c.encode(defaultLayout, forKey: .defaultLayout)423        try c.encode(notifications, forKey: .notifications)424        try c.encode(min(max(sessionRetentionDays, 1), 3650), forKey: .sessionRetentionDays)425        try c.encode(mobileToolbar, forKey: .mobileToolbar)426        try c.encode(autosave, forKey: .autosave)427        try c.encode(layout, forKey: .layout)428    }429}430431// MARK: Errors432433/// The server's error envelope `{error:{code,message,details}}`.434public struct APIErrorBody: Codable, Hashable, Sendable {435    public struct Payload: Codable, Hashable, Sendable {436        public var code: String437        public var message: String438        public var details: JSONValue?439    }440    public var error: Payload441}442
Files main
Menu

Theme