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

+127 -19
View File
@@ -5,6 +5,7 @@ using Chronos.Core.Project;
using Chronos.Core.Video;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Processing;
using Chronos.Data.Projects;
namespace Chronos.App.Editor;
@@ -45,7 +46,8 @@ public sealed class EditorSession : IAsyncDisposable
Source = source;
_codecs = codecs ?? [];
_basis = content.Project;
History = new ProjectHistory(content.Project);
// Undo steps take outside changes as the source merges them (a workspace project: positions photo by photo).
History = new ProjectHistory(content.Project, merge: (basis, ours, theirs) => source.Merge(basis, ours, theirs).Merged);
History.Changed += OnProjectChanged;
_saver = new ProjectSaver(SaveAsync, saveDelay ?? DefaultSaveDelay);
_saver.Failed += OnSaveFailed;
@@ -67,6 +69,12 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>A save met settings changed on the server too (<see cref="Conflict"/> was null): the user picks a side.</summary>
public event Action<ProjectConflictException>? ConflictFound;
/// <summary>
/// An edit not stored yet met a newer Chronos's settings stored meanwhile, which this one never merges with: the edit
/// was kept aside at the path given (<see cref="ISequenceSource.SetAsideAsync"/>) and the newer settings shown read-only.
/// </summary>
public event Action<string>? EditSetAside;
public ISequenceSource Source { get; }
/// <summary>A server sequence edited with proxies: saved, analysed and rendered on the server.</summary>
@@ -165,11 +173,15 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>
/// The jobs that render <paramref name="export"/> and its batch: one job on this PC (the sequence is prepared once),
/// one per preset on a server, where a render node uploads one file per job (BRIEF §14.7).
/// one per preset on a server, where a render node uploads one file per job (BRIEF §14.7), and for a workspace project
/// one per preset at its home with the project's portable settings (<see cref="IProjectRenders"/>, owner review 2, R8).
/// </summary>
public IReadOnlyList<ArchiveJobRequest> RenderRequests(ExportSettings export) => IsRemote
? ProcessingJobs.RenderEach(Content.Sequence, export, Content.SourceWidth, Content.SourceHeight, Project with { Export = export })
: [RenderRequest(export)];
public IReadOnlyList<ArchiveJobRequest> RenderRequests(ExportSettings export) => Source switch
{
IProjectRenders renders => renders.RenderRequests(Content.Sequence, Project, export, Content.SourceWidth, Content.SourceHeight),
_ when IsRemote => ProcessingJobs.RenderEach(Content.Sequence, export, Content.SourceWidth, Content.SourceHeight, Project with { Export = export }),
_ => [RenderRequest(export)],
};
/// <summary>
/// Makes a "Save both" copy of this PC's settings the project, as one undoable step; null when it stores the same values.
@@ -185,10 +197,11 @@ public sealed class EditorSession : IAsyncDisposable
}
/// <summary>
/// Settles <see cref="Conflict"/> against the server's settings as the last save read them. Both choices first take
/// in what only the server changed (like any merge, without an undo step). <paramref name="keepMine"/> then saves
/// the editor's values of the settings both changed; otherwise the server's values become the project as one
/// undoable step, so Ctrl+Z brings the editor's back (and saves them).
/// Settles <see cref="Conflict"/> against the settings stored meanwhile (the server's, a workspace's working state a sync
/// wrote) as the last save read them. Both choices first take in what only the other side changed (like any merge,
/// without an undo step). <paramref name="keepMine"/> then saves the editor's values of the settings both changed;
/// otherwise the other side's values become the project as one undoable step, so Ctrl+Z brings the editor's back (and
/// saves them).
/// </summary>
/// <returns>False when there is no conflict to settle (a later save already went through).</returns>
public bool ResolveConflict(bool keepMine)
@@ -197,8 +210,17 @@ public sealed class EditorSession : IAsyncDisposable
Conflict = null;
var basis = _basis;
_basis = theirs;
History.Replace(ProjectMerge.Merge(basis, Project, theirs));
if (!keepMine) History.Apply(ProjectMerge.Merge(basis, theirs, Project));
try
{
History.Replace(Source.Merge(basis, Project, theirs).Merged);
if (!keepMine) History.Apply(Source.Merge(basis, theirs, Project).Merged);
}
catch (NewerSettingsException ex)
{
// Never merged with a newer Chronos's settings: the edit is kept aside, those settings shown read-only.
_ = TakeNewerAsync(theirs, ex, CancellationToken.None);
return true;
}
// The change waiting for its retry goes now, on top of the server's settings.
_ = _saver.FlushAsync();
return true;
@@ -230,7 +252,9 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>
/// Reads the sequence again (an analysis finished): new reports and advice, the frames with the project's positions
/// following them (<see cref="Follow"/>), the stored project merged into the open one. Saves wait until it is taken,
/// and a read waits for the one under way, so each follows the frames the one before it took.
/// and a read waits for the one under way, so each follows the frames the one before it took. A stored project of a
/// newer Chronos met with an edit not stored yet is never merged: the edit is kept aside and the newer settings shown
/// read-only (<see cref="EditSetAside"/>).
/// </summary>
public async Task ReloadAsync(CancellationToken cancellationToken = default)
{
@@ -240,13 +264,21 @@ public sealed class EditorSession : IAsyncDisposable
{
var content = await Source.LoadAsync(cancellationToken);
Follow(content);
// A server's settings that conflict with the editor's waiting change are not merged over it: that change's
// retry meets them and asks (Conflict).
if (Conflict is null && (!IsRemote || ProjectMerge.Conflicts(_basis, Project, content.Project).Count == 0))
// Settings a server or a sync stored that conflict with the editor's waiting change are not merged over it: that
// change's retry meets them and asks (Conflict).
ProjectMergeResult? merge = null;
try
{
merge = Conflict is null ? Source.Merge(_basis, Project, content.Project) : null;
}
catch (NewerSettingsException ex)
{
await TakeNewerAsync(content.Project, ex, cancellationToken);
}
if (merge is not null && (!Source.AsksConflicts || !merge.HasConflicts))
{
var merged = ProjectMerge.Merge(_basis, Project, content.Project);
_basis = content.Project;
History.Replace(merged);
History.Replace(merge.Merged);
}
}
finally
@@ -256,6 +288,46 @@ public sealed class EditorSession : IAsyncDisposable
ContentChanged?.Invoke();
}
/// <summary>
/// Reads the project again after the user took the other side's values of the settings both changed (a workspace
/// project's "Take the library's", settled by its sync): what only the other side changed comes in as any merge does,
/// without an undo step (<paramref name="kept"/>: the stored project as keeping the editor's values would have left
/// it), then the values taken become the project as one undoable step, so Ctrl+Z brings the editor's back (and saves
/// them), as <see cref="ResolveConflict"/> does for a server's.
/// </summary>
/// <returns>That step, which a toast's Undo can take back while it is the last change; null when it changed nothing.</returns>
public async Task<ProjectRestore?> TakeOverAsync(ProjectSettings kept, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(kept);
await _saver.FlushAsync();
var taken = await BeginReadAsync();
ProjectRestore? step = null;
try
{
var content = await Source.LoadAsync(cancellationToken);
Follow(content);
var basis = _basis;
_basis = content.Project;
try
{
History.Replace(Source.Merge(basis, Project, kept).Merged);
var before = Project;
if (!IsReadOnly && History.Apply(Source.Merge(kept, Project, content.Project).Merged)) step = new ProjectRestore(this, before, Project);
}
catch (NewerSettingsException ex)
{
_basis = basis;
await TakeNewerAsync(content.Project, ex, cancellationToken);
}
}
finally
{
taken.SetResult();
}
ContentChanged?.Invoke();
return step;
}
/// <summary>Stores pending changes now; false when the save failed (the change stays pending and is retried).</summary>
public Task<bool> FlushAsync() => _saver.FlushAsync();
@@ -304,6 +376,40 @@ public sealed class EditorSession : IAsyncDisposable
NamesFrames(project) && ProjectSettings.FollowFrames(project.ToJson(), before, after) is { } moved ? ProjectSettings.FromJson(moved) : project;
}
/// <summary>
/// The stored project is a newer Chronos's (<paramref name="newer"/>) while the editor holds an edit not stored yet,
/// which this Chronos can neither merge with it nor store over it (<see cref="NewerSettingsException"/>): the edit is
/// kept aside by the source (<see cref="ISequenceSource.SetAsideAsync"/>, said by <see cref="EditSetAside"/>), never
/// dropped silently, and only then are the newer settings taken, read-only, the pending save dropped with it. A source
/// that keeps nothing aside, or a set-aside that fails, leaves the editor as it is (logged): the next read tries again.
/// Never throws.
/// </summary>
private async Task TakeNewerAsync(ProjectSettings newer, NewerSettingsException cause, CancellationToken cancellationToken)
{
var unsaved = Project;
string? kept;
try
{
kept = await Source.SetAsideAsync(unsaved, cancellationToken);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Log.Warning("editor", $"The edit of {Content.Sequence.DisplayTitle} not stored yet could not be kept aside; it stays in the editor", ex);
return;
}
if (kept is null)
{
Log.Warning("editor", $"The edit of {Content.Sequence.DisplayTitle} not stored yet meets newer settings and stays in the editor: {cause.Message}");
return;
}
Log.Info("editor", $"The edit of {Content.Sequence.DisplayTitle} not stored yet was kept in {kept}: the stored project is a newer Chronos's ({cause.Message})");
_saver.Drop();
Conflict = null;
_basis = newer;
History.Replace(newer);
EditSetAside?.Invoke(kept);
}
/// <summary>
/// Waits for the read under way (two jobs that end together read the sequence one after the other), then marks a new
/// one under way until the returned source is completed.
@@ -352,7 +458,9 @@ public sealed class EditorSession : IAsyncDisposable
private void OnProjectChanged()
{
_saver.Schedule(Project);
// A read-only project takes what is read again (a workspace pull of a newer Chronos's settings) without a save that
// could never be stored and would be retried for ever.
if (!IsReadOnly) _saver.Schedule(Project);
ProjectChanged?.Invoke();
}
@@ -405,7 +513,7 @@ public sealed class EditorSession : IAsyncDisposable
Conflict = null;
_basis = stored;
// Someone else's change was merged in: show it without an undo step (edits made since the save are kept).
if (!ProjectMerge.SameValues(stored, project)) History.Replace(ProjectMerge.Merge(project, Project, stored));
if (!ProjectMerge.SameValues(stored, project)) History.Replace(Source.Merge(project, Project, stored).Merged);
}
}