SPB Git

Repository Public

Agent.swift 12.6 KB 285 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/Agent.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/// Which agent CLI an instance runs (`CR_AGENT` on the server).91public enum AgentID: OpenStringEnum {92    case claude, codex93    case unknown(String)94    public static var known: [(AgentID, String)] { [(.claude, "claude"), (.codex, "codex")] }95    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }96}9798public enum McpTransport: OpenStringEnum {99    case stdio, http, sse100    case unknown(String)101    public static var known: [(McpTransport, String)] { [(.stdio, "stdio"), (.http, "http"), (.sse, "sse")] }102    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }103}104105public enum SkillKind: OpenStringEnum {106    case skill, command, agent107    case unknown(String)108    public static var known: [(SkillKind, String)] { [(.skill, "skill"), (.command, "command"), (.agent, "agent")] }109    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }110}111112/// What the agent CLI of an instance can do (mirrors `AgentCapabilities` in `agent.ts`).113public struct AgentCapabilities: Hashable, Sendable {114    public var promptSubmitHook: Bool115    public var attentionHook: Bool116    public var projectMcpScope: Bool117    public var mcpLiveStatus: Bool118    public var mcpHeaders: Bool119    public var mcpTransports: [McpTransport]120    public var skillKinds: [SkillKind]121}122123/// Public branding returned by `GET /auth/status` (readable before login).124public struct Branding: Codable, Hashable, Sendable {125    public var agent: AgentID126    public var productName: String127    public var agentName: String128129    public init(agent: AgentID, productName: String, agentName: String) {130        self.agent = agent131        self.productName = productName132        self.agentName = agentName133    }134}135136/// An sRGB colour as `0xRRGGBB` plus alpha, kept Foundation-only so that models stay UI-free.137public struct HexColor: Hashable, Sendable, Codable {138    public var rgb: UInt32139    public var alpha: Double140141    public init(_ rgb: UInt32, alpha: Double = 1) {142        self.rgb = rgb & 0xFFFFFF143        self.alpha = alpha144    }145146    public var red: Double { Double((rgb >> 16) & 0xFF) / 255 }147    public var green: Double { Double((rgb >> 8) & 0xFF) / 255 }148    public var blue: Double { Double(rgb & 0xFF) / 255 }149    public var hexString: String { String(format: "#%06X", rgb) }150151    /// WCAG relative luminance.152    public var luminance: Double {153        func lin(_ c: Double) -> Double { c <= 0.03928 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4) }154        return 0.2126 * lin(red) + 0.7152 * lin(green) + 0.0722 * lin(blue)155    }156157    public func contrast(with other: HexColor) -> Double {158        let a = max(luminance, other.luminance), b = min(luminance, other.luminance)159        return (a + 0.05) / (b + 0.05)160    }161}162163/// A colour with its light and dark variants.164public struct AdaptiveHex: Hashable, Sendable {165    public var light: HexColor166    public var dark: HexColor167    public init(light: UInt32, dark: UInt32) {168        self.light = HexColor(light)169        self.dark = HexColor(dark)170    }171}172173/// Accent family of a product. Values are the web application's design tokens174/// (`apps/web/src/app/globals.css`): `--color-accent`, `--color-accent-2`, `--color-accent-fg`,175/// the brand gradient stops, `--color-ink`, and (Claude) the coral / coral-ink warm pair.176public struct AgentAccent: Hashable, Sendable {177    /// Interactive accent, text-capable (WCAG AA on the app surfaces).178    public var primary: AdaptiveHex179    public var secondary: AdaptiveHex180    /// Text / glyph colour on a `primary` fill.181    public var onPrimary: AdaptiveHex182    /// Warm companion: fill (`warm`) and its text-capable ink (`warmInk`).183    public var warm: AdaptiveHex184    public var warmInk: AdaptiveHex185    /// Brand gradient stops (mark, hero, primary call to action).186    public var gradient: [HexColor]187    /// Deep ink behind hero banners (white text on it in both themes).188    public var ink: HexColor189}190191/// One of the two products served by the same code base. Everything a native app needs to know192/// statically about its instance: where it is, what it is called, and how it looks.193public struct AgentProfile: Hashable, Sendable, Identifiable {194    public var id: AgentID195    /// Name of the CLI product ("Claude Code", "Codex").196    public var agentName: String197    /// Short name used in sentences and session titles ("Claude", "Codex").198    public var shortName: String199    /// Name of the application ("Claude Remote", "Codex Remote").200    public var productName: String201    public var slug: String202    /// What to type in a shell session to authenticate the CLI.203    public var loginCommand: String204    /// Public origin of the production instance; also the WebAuthn relying party.205    public var baseURL: URL206    /// Custom URL scheme (`clauderemote`, `codexremote`).207    public var urlScheme: String208    /// Bundle identifier shared by the macOS and the iOS app (Debug builds add `.dev`).209    public var bundleIdentifier: String210    public var capabilities: AgentCapabilities211    public var accent: AgentAccent212    /// SF Symbol standing for the agent in lists and status items.213    public var symbolName: String214215    /// WebAuthn relying party identifier = host of the public origin.216    public var relyingPartyID: String { baseURL.host() ?? "" }217    /// Associated domain entries the app target must declare.218    public var associatedDomains: [String] { ["webcredentials:\(relyingPartyID)", "applinks:\(relyingPartyID)"] }219    public var branding: Branding { Branding(agent: id, productName: productName, agentName: agentName) }220    /// APNs topic for a build configuration.221    public func pushTopic(debug: Bool) -> String { debug ? bundleIdentifier + ".dev" : bundleIdentifier }222223    /// Same profile pointed at another origin (dev stack through an SSH tunnel, tests).224    public func with(baseURL: URL) -> AgentProfile {225        var copy = self226        copy.baseURL = baseURL227        return copy228    }229230    public static let appleTeamID = "3YM54G49SN"231232    public static let claude = AgentProfile(233        id: .claude, agentName: "Claude Code", shortName: "Claude", productName: "Claude Remote",234        slug: "claude-remote", loginCommand: "claude auth login",235        baseURL: URL(string: "https://claude.spboucher.ai")!, urlScheme: "clauderemote",236        bundleIdentifier: "ai.spboucher.clauderemote",237        capabilities: AgentCapabilities(238            promptSubmitHook: true, attentionHook: true, projectMcpScope: true, mcpLiveStatus: true,239            mcpHeaders: true, mcpTransports: [.stdio, .http, .sse], skillKinds: [.skill, .command, .agent]),240        accent: AgentAccent(241            primary: AdaptiveHex(light: 0x5151E8, dark: 0x8F8FFF),242            secondary: AdaptiveHex(light: 0x8B5CF6, dark: 0xB08CFF),243            onPrimary: AdaptiveHex(light: 0xFFFFFF, dark: 0x0A0A1F),244            warm: AdaptiveHex(light: 0xFF7A59, dark: 0xFF8F73),245            warmInk: AdaptiveHex(light: 0xB03E1C, dark: 0xFF9D85),246            gradient: [HexColor(0x5B5BF0), HexColor(0x8B5CF6), HexColor(0xFF7A59)],247            ink: HexColor(0x11122B)),248        symbolName: "sparkles")249250    public static let codex = AgentProfile(251        id: .codex, agentName: "Codex", shortName: "Codex", productName: "Codex Remote",252        slug: "codex-remote", loginCommand: "codex login",253        baseURL: URL(string: "https://codex.spboucher.ai")!, urlScheme: "codexremote",254        bundleIdentifier: "ai.spboucher.codexremote",255        capabilities: AgentCapabilities(256            promptSubmitHook: false, attentionHook: false, projectMcpScope: false, mcpLiveStatus: false,257            mcpHeaders: false, mcpTransports: [.stdio, .http], skillKinds: [.skill, .agent]),258        accent: AgentAccent(259            primary: AdaptiveHex(light: 0x0B7268, dark: 0x2DD4BF),260            secondary: AdaptiveHex(light: 0x0891B2, dark: 0x22D3EE),261            onPrimary: AdaptiveHex(light: 0xFFFFFF, dark: 0x04201C),262            warm: AdaptiveHex(light: 0x0D9488, dark: 0x2DD4BF),263            warmInk: AdaptiveHex(light: 0x0A6B60, dark: 0x5EEAD4),264            gradient: [HexColor(0x047857), HexColor(0x0D9488), HexColor(0x0891B2)],265            ink: HexColor(0x04211D)),266        symbolName: "chevron.left.forwardslash.chevron.right")267268    public static let all: [AgentProfile] = [.claude, .codex]269270    public static func profile(for id: AgentID) -> AgentProfile { id == .codex ? .codex : .claude }271272    /// Profile owning a URL (custom scheme, or the host of a web link).273    public static func profile(owning url: URL) -> AgentProfile? {274        all.first { $0.urlScheme == url.scheme?.lowercased() || ($0.relyingPartyID == url.host() && url.scheme == "https") }275    }276277    /// Conversation ids accepted after `--resume` (Claude) / `resume` (Codex); never option-like.278    public func isConversationID(_ id: String) -> Bool {279        let pattern = self.id == .codex280            ? #"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"#281            : #"^[A-Za-z0-9][A-Za-z0-9-]{7,63}$"#282        return id.range(of: pattern, options: .regularExpression) != nil283    }284}285
Files main
Menu

Theme