diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-21 00:58:15 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-21 00:58:15 +0800 |
| commit | 7b29dbff7e43e87741476f47df17ad1582b16546 (patch) | |
| tree | 4c9d0832b4e4edd77e59e9cb0a88abf5e729a9f9 /src/SomhairlesDream.Cli | |
| parent | 47add3088d50f12c5f48591f26c53cdb59d8283b (diff) | |
| download | somhairles-dream-fsharp-7b29dbff7e43e87741476f47df17ad1582b16546.tar.gz | |
feat(pipeline): add runnable artifact pipeline increment
[Change Nature]
- This commit adds the first runnable increment of the F# artifact
pipeline: CLI, server, frontend bundle, stage fixture, and tests.
It is feature work, not a bug fix.
[New Capability]
- CLI `run` executes the three-step Blender fixture through the process
bridge and writes GLBs, step logs, events, and a manifest; `verify`
validates a manifest without Blender.
- Server exposes run start, run-scoped SSE, artifact manifest/file
routes, and serves the Fable frontend from its build output.
- Frontend starts runs, follows run-scoped SSE progress, and links the
artifact manifest on completion.
[Implementation]
- Shared layer holds domain, run state, replay, and artifact contracts;
Modeling holds the pipeline, 120s bridge timeout, and result-file
protocol; stage/blender/fixture.py owns geometry in Python (bpy owns
geometry, F# owns orchestration).
- Fable bundle is regenerated into public/ and copied by the server
project; solution includes all projects with warnings-as-errors.
- README documents build, Fable, server, interpreter/env, fixture
limitations, and current verification status.
[Impact]
- Verified: 40/40 solution tests pass; Release build 0 warnings/errors;
real CLI run with bpy 5.0.1 produced 3 GLBs, 3 logs, and a
verify-clean manifest; isolated-port server smoke flow succeeded.
- Not yet verified: browser end-to-end behavior and production
fidelity. Artifacts and caches are gitignored.
Diffstat (limited to 'src/SomhairlesDream.Cli')
| -rw-r--r-- | src/SomhairlesDream.Cli/Arguments.fs | 91 | ||||
| -rw-r--r-- | src/SomhairlesDream.Cli/Program.fs | 51 | ||||
| -rw-r--r-- | src/SomhairlesDream.Cli/SomhairlesDream.Cli.fsproj | 16 |
3 files changed, 158 insertions, 0 deletions
diff --git a/src/SomhairlesDream.Cli/Arguments.fs b/src/SomhairlesDream.Cli/Arguments.fs new file mode 100644 index 0000000..2de96be --- /dev/null +++ b/src/SomhairlesDream.Cli/Arguments.fs @@ -0,0 +1,91 @@ +namespace SomhairlesDream.Cli + +open System +open SomhairlesDream.Shared + +[<CLIMutable>] +type RunOptions = + { Ids: RunIds + OutputRoot: string + StageRoot: string + Python: string + Render: bool } + +type Command = + | Run of RunOptions + | Verify of string + | Help + +module Arguments = + let usage = + "usage: dotnet run --project src/SomhairlesDream.Cli -- run [options]\n" + + " dotnet run --project src/SomhairlesDream.Cli -- verify <manifest.json>" + + let private defaultPython () = + let configured = Environment.GetEnvironmentVariable("SOMHAIRLES_BPYTHON") + if String.IsNullOrWhiteSpace(configured) then "python3" else configured + + let private defaults () = + { Ids = + { ProjectId = "heritage-001" + RunId = "run-001" + BaseId = "base-000" + TargetId = "target-003" } + OutputRoot = ".artifacts" + StageRoot = "stage" + Python = defaultPython () + Render = false } + + let private requiredValue (args: string array) (index: int) (optionName: string) = + if index + 1 >= args.Length || String.IsNullOrWhiteSpace(args[index + 1]) then + Error $"{optionName} requires a value" + else + Ok args[index + 1] + + let private setValue optionName value (options: RunOptions) = + match optionName with + | "--project-id" -> Ok { options with Ids = { options.Ids with ProjectId = value } } + | "--run-id" -> Ok { options with Ids = { options.Ids with RunId = value } } + | "--base-id" -> Ok { options with Ids = { options.Ids with BaseId = value } } + | "--target-id" -> Ok { options with Ids = { options.Ids with TargetId = value } } + | "--output-root" -> Ok { options with OutputRoot = value } + | "--stage-root" -> Ok { options with StageRoot = value } + | "--python" -> Ok { options with Python = value } + | _ -> Error $"unknown option: {optionName}" + + let private validateRunOptions (options: RunOptions) = + [| options.Ids.ProjectId; options.Ids.RunId; options.Ids.BaseId; options.Ids.TargetId |] + |> Array.tryFind (Ids.validateResourceId >> Result.isError) + |> function + | Some value -> Error $"invalid resource id: {value}" + | None -> Ok(Run options) + + let private parseRun (args: string array) = + let rec loop (index: int) (options: RunOptions) = + if index >= args.Length then + validateRunOptions options + else + match args[index] with + | "--render" -> loop (index + 1) { options with Render = true } + | "--help" -> Ok Help + | optionName -> + match requiredValue args index optionName with + | Error message -> Error message + | Ok value -> + match setValue optionName value options with + | Error message -> Error message + | Ok updated -> loop (index + 2) updated + + loop 0 (defaults ()) + + let parse (args: string array) = + match args with + | [||] + | [| "--help" |] + | [| "help" |] -> Ok Help + | [| "verify" |] -> Error "verify requires a manifest path" + | [| "verify"; path |] when not (String.IsNullOrWhiteSpace(path)) -> Ok(Verify path) + | [| "verify"; _ |] -> Error "verify requires a manifest path" + | values when values.Length > 2 && values[0] = "verify" -> Error "verify accepts exactly one manifest path" + | values when values.Length > 0 && values[0] = "run" -> parseRun (values |> Array.skip 1) + | _ -> Error usage diff --git a/src/SomhairlesDream.Cli/Program.fs b/src/SomhairlesDream.Cli/Program.fs new file mode 100644 index 0000000..0d9ed1c --- /dev/null +++ b/src/SomhairlesDream.Cli/Program.fs @@ -0,0 +1,51 @@ +namespace SomhairlesDream.Cli + +open System +open System.IO +open SomhairlesDream.Modeling + +module Program = + let private bridgeFailure (message: string) = + message.StartsWith("blender bridge:", StringComparison.OrdinalIgnoreCase) + + let private run options = + let bridge = BlenderProcessBridge(options.Python, options.StageRoot) :> IArtifactBridge + + let pipelineOptions : PipelineOptions = + { ArtifactRoot = options.OutputRoot + Ids = options.Ids + Render = options.Render + Bridge = bridge + Clock = fun () -> DateTimeOffset.UtcNow + OnEvent = ignore } + + match Pipeline.run pipelineOptions with + | Ok _ -> + let manifestPath = Path.Combine(options.OutputRoot, options.Ids.ProjectId, options.Ids.RunId, "manifest.json") + printfn "%s" (Path.GetFullPath(manifestPath)) + 0 + | Error message -> + eprintfn "%s" message + if bridgeFailure message then 3 else 4 + + let private verify path = + match ArtifactVerifier.verify path with + | Ok _ -> + printfn "%s" (Path.GetFullPath(path)) + 0 + | Error message -> + eprintfn "%s" message + 4 + + [<EntryPoint>] + let main argv = + match Arguments.parse argv with + | Ok Help -> + printfn "%s" Arguments.usage + 0 + | Ok(Run options) -> run options + | Ok(Verify path) -> verify path + | Error message -> + eprintfn "%s" message + eprintfn "%s" Arguments.usage + 2 diff --git a/src/SomhairlesDream.Cli/SomhairlesDream.Cli.fsproj b/src/SomhairlesDream.Cli/SomhairlesDream.Cli.fsproj new file mode 100644 index 0000000..6c72658 --- /dev/null +++ b/src/SomhairlesDream.Cli/SomhairlesDream.Cli.fsproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>SomhairlesDream.Cli</RootNamespace> + <AssemblyName>SomhairlesDream.Cli</AssemblyName> + <OutputType>Exe</OutputType> + </PropertyGroup> + <ItemGroup> + <ProjectReference Include="../SomhairlesDream.Shared/SomhairlesDream.Shared.fsproj" /> + <ProjectReference Include="../SomhairlesDream.Modeling/SomhairlesDream.Modeling.fsproj" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Arguments.fs" /> + <Compile Include="Program.fs" /> + </ItemGroup> +</Project> |
