Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX OS Automation9// File : Packages/ORIXFeatureWorkflow/Sources/orix-preview-workflow/main.swift10// Description : Renders the Workflow Studio screens to PNG files on a11// throwaway data folder: `swift run orix-preview-workflow12// --shot <dir>`.13// Module : orix-preview-workflow14// Repository : https://git.spboucher.ai/orix-automation15// Created : 2026-11-2116// Last Modified : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : Proprietary, all rights reserved (see license file)83// License File : LICENSE84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import AppKit92import ORIXAppUI93import ORIXFeatureWorkflow94import SwiftUI9596_ = NSApplication.shared9798let arguments = CommandLine.arguments99guard let flag = arguments.firstIndex(of: "--shot"), arguments.count > flag + 1 else {100 FileHandle.standardError.write(Data("usage: orix-preview-workflow --shot <dir>\n".utf8))101 exit(2)102}103let directory = URL(fileURLWithPath: arguments[flag + 1], isDirectory: true)104105@MainActor106func shoot<V: View>(_ name: String, _ view: V, model: AppModel, size: CGSize, settle: Double = 1.4) async throws {107 for dark in [true, false] {108 let url = directory.appendingPathComponent("\(name)-\(dark ? "dark" : "light").png")109 try await ShotRenderer.render(view.environment(model), size: size, dark: dark, settle: settle, to: url)110 print("SHOT \(url.path)")111 }112}113114@MainActor115func run() async throws {116 let model = try await PreviewEnvironment.make()117 model.section = .workflows118 model.selectedWorkflowID = "system-health-report"119 let vm = WorkflowStudioModel(app: model)120 await vm.reload(selected: model.selectedWorkflowID)121 let compact = CGSize(width: 1100, height: 700), large = CGSize(width: 1600, height: 1000)122123 try await shoot("library-canvas", vm.studioView(), model: model, size: large)124 try await shoot("library-canvas-compact", vm.studioView(), model: model, size: compact)125126 vm.selectNodes(["write"])127 try await shoot("inspector-tool", vm.studioView(), model: model, size: large)128 vm.selectNodes(["lowDisk"])129 try await shoot("inspector-condition", vm.studioView(), model: model, size: compact)130 vm.selectNodes([])131132 try await shoot("template-gallery", vm.templateGalleryView(), model: model, size: CGSize(width: 1100, height: 760))133 try await shoot("permission-review", vm.permissionReviewView(), model: model, size: CGSize(width: 620, height: 600))134 try await shoot("add-palette", vm.paletteView(), model: model, size: CGSize(width: 420, height: 520))135 try await shoot("version-history", vm.historyView(), model: model, size: CGSize(width: 611, height: 420))136 try await shoot("create-from-description", vm.generateView(), model: model, size: CGSize(width: 720, height: 640))137138 // A real dry run of the template, started paused so the canvas can be captured while it is going.139 try await model.services.workflows.acceptPermissions(workflowID: "system-health-report")140 var request = WorkflowRunRequest(workflowID: "system-health-report")141 request.dryRun = true142 request.startPaused = true143 let runID = try await model.services.workflows.startRun(request)144 await vm.follow(runID: runID)145 for _ in 0..<3 { vm.debuggerStepOver(); try await Task.sleep(nanoseconds: 250_000_000) }146 vm.fitWhenShown()147 try await shoot("dry-run-during", vm.studioView(), model: model, size: large)148 vm.debuggerResume()149 let deadline = Date().addingTimeInterval(60)150 while vm.selectedRunIsLive, Date() < deadline { try await Task.sleep(nanoseconds: 200_000_000) }151 print("DRY RUN status=\(vm.selectedRunStatus?.rawValue ?? "?") steps=\(vm.stepStatuses.sorted { $0.key < $1.key }.map { "\($0.key):\($0.value.rawValue)" }.joined(separator: " "))")152 vm.selectNodes(["write"])153 try await shoot("dry-run-after", vm.studioView(), model: model, size: large)154 try await shoot("dry-run-after-compact", vm.studioView(), model: model, size: compact)155 vm.showRunPanel(false)156157 // A generated 40-step graph, zoomed to fit.158 guard await vm.install(WorkflowStudioSamples.layered(count: 40)) else { print("INSTALL FAILED: \(model.banner?.text ?? "?")"); throw CocoaError(.fileWriteUnknown) }159 vm.fitWhenShown(exactly: true)160 try await shoot("graph-40-nodes", vm.studioView(), model: model, size: large)161162 await model.services.shutdown()163}164165Task { @MainActor in166 do { try await run(); exit(0) } catch {167 FileHandle.standardError.write(Data("preview failed: \(error)\n".utf8))168 exit(1)169 }170}171RunLoop.main.run()172