feat: owner review 2 phase 5a: workspace and projects with a local home (#14)
CI / Build and test (push) Successful in 9m43s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 27s
CI / PostgreSQL 16 integration (push) Failing after 8m41s
CI / PostgreSQL 17 integration (push) Successful in 12m37s
CI / Docker image (push) Successful in 56s
Release / Build, test and publish (push) Successful in 14m59s
Release / Server image (push) Successful in 1m51s

Edit opens a sequence as a project of a workspace folder outside the library. Projects have linear version histories kept as sidecars in .chronos/projects/, Main mirrors the sequence's settings, and sync merges setting by setting. Migration 0009, JobKind.WorkspaceCopy = 20, Settings › Workspace, and 241 new strings in 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 09:22:08 +01:00
1 parent efa87f68ce
commit 9b24cf74fc
370 files changed
+29237 -287

No files matched your search

@@ -0,0 +1,179 @@
using System.Text.Json.Serialization;
using Chronos.Core.Imaging;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Data.Processing;
using Chronos.Data.Projects;
namespace Chronos.Data.Workspaces;
/// <summary>
/// One frame of a workspace's media (<c>media/media.json</c>): the frame's record at its home (what analyses and the
/// editor read) and the file the workspace holds for it, with its SHA-256 and size as copied.
/// </summary>
/// <param name="File">The file relative to the media folder ("proxies/&lt;frame id&gt;.jpg"); null when the workspace holds none.</param>
public sealed record WorkspaceFrame(
Guid Id,
int Index,
string FileName,
string? OriginalFileName,
long Size,
string? Sha256,
DateTime? CapturedAt,
int? UtcOffsetMinutes,
TimestampSource TimestampSource,
double? ExposureTime,
double? FNumber,
int? Iso,
double? FocalLength,
double? ExposureBias,
int? WhiteBalance,
int Orientation,
int Width,
int Height,
ImageFileFormat Format,
int PreviewWidth,
int PreviewHeight,
double? MeanLogLuminance,
double? ClipLow,
double? ClipHigh,
FrameFlags Flags,
string? File,
string? FileSha256,
long FileBytes)
{
/// <summary>The record of a home's frame, with the file the workspace holds for it.</summary>
public static WorkspaceFrame Of(Frame frame, string? file, string? fileSha256, long fileBytes)
{
ArgumentNullException.ThrowIfNull(frame);
return new WorkspaceFrame(frame.Id, frame.Index, frame.FileName, frame.OriginalFileName, frame.Size, frame.Sha256, frame.CapturedAt, frame.UtcOffsetMinutes,
frame.TimestampSource, frame.ExposureTime, frame.FNumber, frame.Iso, frame.FocalLength, frame.ExposureBias, frame.WhiteBalance, frame.Orientation,
frame.Width, frame.Height, frame.Format, frame.PreviewWidth, frame.PreviewHeight, frame.MeanLogLuminance, frame.ClipLow, frame.ClipHigh, frame.Flags,
file, fileSha256, fileBytes);
}
/// <summary>The frame as the processing engine reads it; flagged missing while the workspace holds no file for it.</summary>
public Frame ToFrame(Guid sequenceId) => new()
{
Id = Id,
SequenceId = sequenceId,
Index = Index,
RelativePath = File ?? FileName,
FileName = FileName,
OriginalFileName = OriginalFileName,
Size = Size,
Sha256 = Sha256,
CapturedAt = CapturedAt,
UtcOffsetMinutes = UtcOffsetMinutes,
TimestampSource = TimestampSource,
ExposureTime = ExposureTime,
FNumber = FNumber,
Iso = Iso,
FocalLength = FocalLength,
ExposureBias = ExposureBias,
WhiteBalance = WhiteBalance,
Orientation = Orientation,
Width = Width,
Height = Height,
Format = Format,
PreviewWidth = PreviewWidth,
PreviewHeight = PreviewHeight,
MeanLogLuminance = MeanLogLuminance,
ClipLow = ClipLow,
ClipHigh = ClipHigh,
Flags = File is null ? Flags | FrameFlags.Missing : Flags,
};
}
/// <summary>
/// What a workspace project holds of its sequence's photos (<c>media/media.json</c>, owner review 2, R8): the kind
/// (<see cref="BundleMedia.Proxies"/>; originals in phase 5c), the sequence and its frames version at the home when they
/// were copied, and every frame in index order. Written last by a copy, so a copy cut short leaves the previous index.
/// </summary>
/// <param name="Aliases">The encodings of the sequence's photos a conversion joined at the home (R7, its tombstones of reason
/// "replaced") when the media were copied: a version parked on a photo before its file was converted still finds its frame.</param>
public sealed record WorkspaceMedia(string Format, int FormatVersion, string Kind, Guid SequenceId, int FramesVersion, IReadOnlyList<WorkspaceFrame> Frames,
DateTimeOffset Copied, string? AnalysisSha256 = null, IReadOnlyList<PhotoAlias>? Aliases = null)
{
public const string FormatName = "chronos-workspace-media";
public const int CurrentFormatVersion = 1;
/// <summary>The frames' photos in index order, as project positions name them, with the encodings conversions joined.</summary>
[JsonIgnore]
public FramePhotos Photos => new(Frames.Select(f => (f.Index, new FramePhoto(f.Sha256, f.Size, f.CapturedAt))), Aliases);
/// <summary>The frames held, as the processing engine reads them.</summary>
public IReadOnlyList<Frame> ToFrames() => [.. Frames.Select(f => f.ToFrame(SequenceId))];
/// <summary>
/// These media with their photos named as <paramref name="home"/> names them now (owner review 2, R8): a frame copied
/// before the home hashed its photo (a folder adopted, verified since) takes the SHA-256 the home's frame of that id has
/// for the same photo (the same size and capture time; a conversion that gave the frame another file is not the same
/// photo), and the encodings the home's conversions joined since the copy are added to <see cref="Aliases"/>. Versions
/// the home made since name those photos so; named alike here, one photo merges as one. The frames, their files and the
/// frames version stay as they are. This instance when there is nothing to learn.
/// </summary>
public WorkspaceMedia NamedAsAt(HomeFrames home)
{
ArgumentNullException.ThrowIfNull(home);
var there = new Dictionary<Guid, Frame>(home.Frames.Count);
foreach (var frame in home.Frames) there[frame.Id] = frame;
var learned = false;
var frames = new List<WorkspaceFrame>(Frames.Count);
foreach (var frame in Frames)
{
if (string.IsNullOrEmpty(frame.Sha256) && there.TryGetValue(frame.Id, out var held) && !string.IsNullOrEmpty(held.Sha256)
&& held.Size == frame.Size && Millisecond(held.CapturedAt) == Millisecond(frame.CapturedAt))
{
frames.Add(frame with { Sha256 = held.Sha256.ToLowerInvariant() });
learned = true;
}
else
{
frames.Add(frame);
}
}
var known = Aliases ?? [];
var links = known.Select(Link).ToHashSet();
var added = home.Photos.Aliases.Where(a => links.Add(Link(a))).ToList();
if (!learned && added.Count == 0) return this;
return this with { Frames = learned ? frames : Frames, Aliases = added.Count > 0 ? [.. known, .. added] : Aliases };
static long? Millisecond(DateTime? time) => time is { } at ? at.Ticks / TimeSpan.TicksPerMillisecond : null;
// A media index read back may hold a damaged link: compared as it is, and left out of the classes like any other.
static (string?, string?) Link(PhotoAlias alias) => (alias.Sha256?.ToLowerInvariant(), alias.Replacement?.ToLowerInvariant());
}
}
/// <summary>
/// A workspace project's sequence opened for editing (like a server sequence opened with proxies): the home's sequence
/// row, the frames as the workspace holds them and the absolute path of each frame's file (null, and the frame flagged
/// missing, when it holds none).
/// </summary>
public sealed class WorkspaceSequence
{
public WorkspaceSequence(Sequence sequence, IReadOnlyList<Frame> frames, IReadOnlyList<string?> files)
{
if (files.Count != frames.Count) throw new ArgumentException("One file entry per frame is required.", nameof(files));
Sequence = sequence;
Frames = frames;
Files = files;
}
public Sequence Sequence { get; }
public IReadOnlyList<Frame> Frames { get; }
public IReadOnlyList<string?> Files { get; }
/// <summary>
/// The editor's frame source over the workspace's files, through the same read-ahead window as archive renders; it also
/// implements <see cref="Core.Analysis.Deep.IFrameSource"/> and <see cref="IAsyncDisposable"/> (dispose it when done).
/// </summary>
public IRenderFrameSource OpenFrames(ImageDecoder decoder, FrameWindowOptions? window = null)
{
var frames = new SequenceFrames(Sequence, Frames, Files);
return new SequenceFrameSource(frames, frames.LightFrames(), decoder, window);
}
}