SPB Git

Repository Public

States.swift 7.0 KB 168 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/States.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/// Terminal session lifecycle (`packages/shared/src/states.ts`). `waitingForInput` is only ever91/// set by the server from an agent hook, never from terminal output.92public enum SessionState: OpenStringEnum {93    case created, starting, running, detached, waitingForInput, stopping, stopped, failed, recoverable94    case unknown(String)9596    public static var known: [(SessionState, String)] {97        [(.created, "CREATED"), (.starting, "STARTING"), (.running, "RUNNING"), (.detached, "DETACHED"),98         (.waitingForInput, "WAITING_FOR_INPUT"), (.stopping, "STOPPING"), (.stopped, "STOPPED"),99         (.failed, "FAILED"), (.recoverable, "RECOVERABLE")]100    }101    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }102103    /// A process exists (LIVE_SESSION_STATES on the server).104    public var isLive: Bool {105        switch self {106        case .starting, .running, .detached, .waitingForInput, .stopping: true107        default: false108        }109    }110    /// The terminal stream can be attached (live and not stopping: the server answers 410 otherwise).111    public var isAttachable: Bool { isLive && self != .stopping }112    public var isTerminal: Bool { self == .stopped || self == .failed }113114    /// Allowed transitions, mirrored from the server for optimistic UI checks.115    public func canTransition(to next: SessionState) -> Bool {116        if self == next { return true }117        let table: [SessionState: [SessionState]] = [118            .created: [.starting, .failed, .stopped],119            .starting: [.running, .detached, .failed, .stopped],120            .running: [.detached, .waitingForInput, .stopping, .stopped, .failed, .recoverable],121            .detached: [.running, .waitingForInput, .stopping, .stopped, .failed, .recoverable],122            .waitingForInput: [.running, .detached, .stopping, .stopped, .failed, .recoverable],123            .stopping: [.stopped, .failed],124            .recoverable: [.starting, .stopped],125        ]126        return table[self]?.contains(next) ?? false127    }128}129130public enum TaskState: OpenStringEnum {131    case queued, running, succeeded, failed, cancelling, cancelled, timedOut, lost132    case unknown(String)133134    public static var known: [(TaskState, String)] {135        [(.queued, "QUEUED"), (.running, "RUNNING"), (.succeeded, "SUCCEEDED"), (.failed, "FAILED"),136         (.cancelling, "CANCELLING"), (.cancelled, "CANCELLED"), (.timedOut, "TIMED_OUT"), (.lost, "LOST")]137    }138    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }139140    /// Finished for good (no further transition).141    public var isFinished: Bool {142        switch self {143        case .succeeded, .failed, .cancelled, .timedOut, .lost: true144        default: false145        }146    }147    public var isActive: Bool {148        switch self {149        case .queued, .running, .cancelling: true150        default: false151        }152    }153    public var canCancel: Bool { self == .queued || self == .running }154}155156/// Health vocabulary of every dashboard. Stale data is `unknown`, never `online`.157public enum Health: OpenStringEnum {158    case online, offline, degraded159    case unknown(String)160161    /// The server's explicit "UNKNOWN" value.162    public static var unknownHealth: Health { .unknown("UNKNOWN") }163    public static var known: [(Health, String)] {164        [(.online, "ONLINE"), (.offline, "OFFLINE"), (.degraded, "DEGRADED")]165    }166    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }167}168
Files main
Menu

Theme