SPB Git

Repository Public

WorkDTO.swift 15.8 KB 415 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/WorkDTO.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: Projects9192public struct Project: Codable, Hashable, Sendable, Identifiable {93    public var id: String94    public var name: String95    public var description: String96    /// Label of the workspace root, e.g. "workspace".97    public var rootLabel: String98    /// Relative to that root.99    public var path: String100    public var gitRemote: String?101    public var gitBranch: String?102    public var gitDirty: Bool?103    public var tags: [String]104    public var pinned: Bool105    public var settings: [String: JSONValue]106    public var activeSessions: Int107    public var lastActivityAt: Date?108    public var createdAt: Date109110    /// `<rootLabel>/<path>` as shown by the web application.111    public var displayPath: String { path.isEmpty ? rootLabel : "\(rootLabel)/\(path)" }112}113114public enum ProjectMode: String, Codable, Sendable, CaseIterable {115    case create, existing, clone116}117118public struct CreateProject: Codable, Hashable, Sendable {119    public var name: String120    public var description: String121    public var mode: ProjectMode122    public var rootLabel: String?123    public var path: String?124    /// Required when `mode == .clone` (`https://`, `ssh://`, `git@host:path` or `gitsrv:`).125    public var gitUrl: String?126    public var tags: [String]127128    public init(name: String, description: String = "", mode: ProjectMode, rootLabel: String? = nil, path: String? = nil,129                gitUrl: String? = nil, tags: [String] = []) {130        self.name = name; self.description = description; self.mode = mode; self.rootLabel = rootLabel131        self.path = path; self.gitUrl = gitUrl; self.tags = tags132    }133}134135/// Partial update: only non-nil members are sent.136public struct UpdateProject: Codable, Hashable, Sendable {137    public var name: String?138    public var description: String?139    public var tags: [String]?140    public var pinned: Bool?141    public var settings: [String: JSONValue]?142143    public init(name: String? = nil, description: String? = nil, tags: [String]? = nil, pinned: Bool? = nil, settings: [String: JSONValue]? = nil) {144        self.name = name; self.description = description; self.tags = tags; self.pinned = pinned; self.settings = settings145    }146}147148public struct WorkspaceRoot: Codable, Hashable, Sendable, Identifiable {149    public var label: String150    public var id: String { label }151}152153// MARK: Terminal sessions154155/// `agent` (wire value `claude`, a historical name) = the instance's agent CLI: Claude Code on a156/// Claude instance, Codex on a Codex instance. `shell` = a login shell.157public enum SessionKind: OpenStringEnum {158    case agent, shell159    case unknown(String)160    public static var known: [(SessionKind, String)] { [(.agent, "claude"), (.shell, "shell")] }161    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }162}163164public struct TerminalSession: Codable, Hashable, Sendable, Identifiable {165    public var id: String166    public var projectId: String?167    public var projectName: String?168    public var kind: SessionKind169    public var title: String170    public var state: SessionState171    /// Relative to the project root ("" = root).172    public var cwd: String173    public var pid: Int?174    /// Conversation id of the agent CLI, when known (historical key).175    public var claudeConversationId: String?176    public var pinned: Bool177    public var archived: Bool178    public var attachedClients: Int179    public var exitCode: Int?180    public var createdAt: Date181    public var lastActivityAt: Date?182    public var endedAt: Date?183    /// Short hook message; never terminal content.184    public var waitingReason: String?185186    public var conversationId: String? { claudeConversationId }187}188189public struct CreateSession: Codable, Hashable, Sendable {190    public var projectId: String?191    public var kind: SessionKind192    public var title: String?193    public var cwd: String194    /// `claude --resume <id>` / `codex resume <id>`; agent sessions only, exclusive with `continueLast`.195    public var resumeConversationId: String?196    public var continueLast: Bool?197    public var cols: Int198    public var rows: Int199200    public init(projectId: String? = nil, kind: SessionKind = .agent, title: String? = nil, cwd: String = "",201                resumeConversationId: String? = nil, continueLast: Bool? = nil, cols: Int = 120, rows: Int = 32) {202        self.projectId = projectId; self.kind = kind; self.title = title; self.cwd = cwd203        self.resumeConversationId = resumeConversationId; self.continueLast = continueLast204        self.cols = min(max(cols, 20), 500); self.rows = min(max(rows, 5), 200)205    }206207    public func encode(to encoder: Encoder) throws {208        var c = encoder.container(keyedBy: CodingKeys.self)209        try c.encode(projectId, forKey: .projectId) // explicit null is part of the schema210        try c.encode(kind, forKey: .kind)211        try c.encodeIfPresent(title, forKey: .title)212        try c.encode(cwd, forKey: .cwd)213        try c.encodeIfPresent(resumeConversationId, forKey: .resumeConversationId)214        try c.encodeIfPresent(continueLast, forKey: .continueLast)215        try c.encode(cols, forKey: .cols)216        try c.encode(rows, forKey: .rows)217    }218}219220public struct UpdateSession: Codable, Hashable, Sendable {221    public var title: String?222    public var pinned: Bool?223    /// Only a session that is not live can be archived (409 `session_live`).224    public var archived: Bool?225    public init(title: String? = nil, pinned: Bool? = nil, archived: Bool? = nil) {226        self.title = title; self.pinned = pinned; self.archived = archived227    }228}229230/// A recorded conversation of the agent CLI for a project directory (metadata only).231public struct AgentConversation: Codable, Hashable, Sendable, Identifiable {232    public var id: String233    /// First user prompt, truncated to 160 characters.234    public var summary: String235    public var updatedAt: Date236    public var messageCount: Int237}238239/// `GET /sessions/:id/snapshot`: last screen lines, for an explicit user-requested preview only.240public struct SessionSnapshot: Codable, Hashable, Sendable {241    public var text: String242}243244// MARK: Files245246public enum FileEntryType: OpenStringEnum {247    case file, dir, symlink, other248    case unknown(String)249    public static var known: [(FileEntryType, String)] { [(.file, "file"), (.dir, "dir"), (.symlink, "symlink"), (.other, "other")] }250    public var unknownRawValue: String? { if case .unknown(let r) = self { r } else { nil } }251}252253public struct FileEntry: Codable, Hashable, Sendable, Identifiable {254    public var name: String255    /// Project-relative.256    public var path: String257    public var type: FileEntryType258    public var size: Int64259    public var mtimeMs: Double260    public var binary: Bool?261262    public var id: String { path }263    public var modifiedAt: Date { Date(timeIntervalSince1970: mtimeMs / 1000) }264    public var isDirectory: Bool { type == .dir }265}266267public struct FileContent: Codable, Hashable, Sendable {268    public var path: String269    public var size: Int64270    public var mtimeMs: Double271    /// Pass back as `baseSha256` when saving, for optimistic concurrency.272    public var sha256: String273    public var encoding: String274    public var content: String275    public var modifiedAt: Date { Date(timeIntervalSince1970: mtimeMs / 1000) }276}277278public struct WriteFile: Codable, Hashable, Sendable {279    public var path: String280    public var content: String281    /// sha256 of the content the editor loaded; omitted when creating. Mismatch → 409 `conflict`.282    public var baseSha256: String?283    public var create: Bool?284    public init(path: String, content: String, baseSha256: String? = nil, create: Bool? = nil) {285        self.path = path; self.content = content; self.baseSha256 = baseSha256; self.create = create286    }287}288289public enum FsOp: Hashable, Sendable, Encodable {290    case mkdir(path: String)291    case rename(from: String, to: String)292    /// Destructive: gate it behind `AuthService.reauthenticate(reason:)` in the UI.293    case delete(path: String)294295    private enum Keys: String, CodingKey { case op, path, from, to, confirm }296    public func encode(to encoder: Encoder) throws {297        var c = encoder.container(keyedBy: Keys.self)298        switch self {299        case .mkdir(let path):300            try c.encode("mkdir", forKey: .op); try c.encode(path, forKey: .path)301        case .rename(let from, let to):302            try c.encode("rename", forKey: .op); try c.encode(from, forKey: .from); try c.encode(to, forKey: .to)303        case .delete(let path):304            try c.encode("delete", forKey: .op); try c.encode(path, forKey: .path); try c.encode(true, forKey: .confirm)305        }306    }307}308309public enum SearchMode: String, Codable, Sendable, CaseIterable {310    case name, content311}312313public struct SearchHit: Codable, Hashable, Sendable {314    public var path: String315    public var line: Int?316    public var preview: String?317}318319public struct GitStatus: Codable, Hashable, Sendable {320    public struct File: Codable, Hashable, Sendable, Identifiable {321        public var path: String322        /// Porcelain status letters of the index and of the work tree (" ", "M", "A", "D", "?", …).323        public var index: String324        public var worktree: String325        public var id: String { path }326    }327    public var isRepo: Bool328    public var branch: String?329    public var ahead: Int330    public var behind: Int331    public var files: [File]332}333334public struct GitDiff: Codable, Hashable, Sendable {335    public var diff: String336    public var truncated: Bool337}338339// MARK: Tasks340341public struct AgentTask: Codable, Hashable, Sendable, Identifiable {342    public struct Artifact: Codable, Hashable, Sendable, Identifiable {343        public var id: String344        public var name: String345        public var size: Int64346        public var createdAt: Date347    }348    public var id: String349    public var projectId: String?350    public var title: String351    public var command: String352    /// "local" or an allow-listed node alias.353    public var host: String354    public var cwd: String355    public var state: TaskState356    public var exitCode: Int?357    public var timeoutSec: Double?358    public var retryOf: String?359    /// Retry is only offered when true.360    public var idempotent: Bool361    public var createdAt: Date362    public var startedAt: Date?363    public var endedAt: Date?364    public var logBytes: Int64365    public var cpuSec: Double?366    public var maxRssMb: Double?367    public var artifacts: [Artifact]368369    public var canRetry: Bool { idempotent && state.isFinished }370}371372public struct CreateTask: Codable, Hashable, Sendable {373    public var projectId: String?374    public var title: String375    public var command: String376    public var host: String377    public var cwd: String378    public var timeoutSec: Int?379    public var idempotent: Bool380    public var artifactGlobs: [String]381382    public init(projectId: String? = nil, title: String, command: String, host: String = "local", cwd: String = "",383                timeoutSec: Int? = nil, idempotent: Bool = false, artifactGlobs: [String] = []) {384        self.projectId = projectId; self.title = title; self.command = command; self.host = host; self.cwd = cwd385        self.timeoutSec = timeoutSec; self.idempotent = idempotent; self.artifactGlobs = artifactGlobs386    }387388    public func encode(to encoder: Encoder) throws {389        var c = encoder.container(keyedBy: CodingKeys.self)390        try c.encode(projectId, forKey: .projectId)391        try c.encode(title, forKey: .title)392        try c.encode(command, forKey: .command)393        try c.encode(host, forKey: .host)394        try c.encode(cwd, forKey: .cwd)395        try c.encode(timeoutSec, forKey: .timeoutSec)396        try c.encode(idempotent, forKey: .idempotent)397        try c.encode(artifactGlobs, forKey: .artifactGlobs)398    }399}400401/// A slice of a task log (`GET /tasks/:id/log?offset=&limit=`).402public struct TaskLogChunk: Hashable, Sendable {403    public var offset: Int64404    public var data: Data405    /// Total size of the log on the server (`X-Log-Size`), when reported.406    public var totalSize: Int64?407    public var nextOffset: Int64 { offset + Int64(data.count) }408    public var isAtEnd: Bool { totalSize.map { nextOffset >= $0 } ?? data.isEmpty }409    public var text: String { String(decoding: data, as: UTF8.self) }410411    public init(offset: Int64, data: Data, totalSize: Int64?) {412        self.offset = offset; self.data = data; self.totalSize = totalSize413    }414}415
Files main
Menu

Theme