feat(projects): workspace projects with linear versions, the local archive as their home

Owner review 2, phase 5a (R8): editing moves out of the library into a workspace on a fast disk, and a
sequence gets several projects, each with a linear version history pushed and pulled like git.

- Core: ProjectSettings keeps members a newer Chronos wrote (Extra) and reads a newer settings format
  read-only; ProjectContent is the portable form of a version (every frame position parked by photo,
  canonical text, SHA-256 content hash); ProjectBundle format 2 adds the workspace section, and a file
  without it is still written as format 1. JobKind.WorkspaceCopy = 20 (19 kept for Convert).
- Data: migration 0009 (projects, project_versions, the render's project columns); ProjectService on
  ArchiveService.Projects keeps projects as sidecars first (.chronos/projects/<id>/), then the index,
  under the sequence lease: create, rename, delete into the projects' trash, history, push with
  fast-forward, idempotent repeat, divergence and hash checks. Main is made from the sequence's settings
  and mirrored both ways, so every older code path keeps working; outside writes become "external"
  versions, a mirror a crash cut short is completed or merged. Full scans and rebuilds take the projects
  back from their sidecars.
- ProjectMerge moves from the App to Data/Projects, merges pending frames photo by photo and replays
  unpushed commits on a moved head.
- Workspaces: WorkspaceStore, WorkspaceSync (checkout, save, commit, push, pull with replay and merge,
  conflicts settled by keep mine / take server / save both, restore, status) and the WorkspaceCopy job
  (proxies copied hash-verified and resumable; originals refused until phase 5c).
- Renders of a project version place its positions on the frames and record the project and version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c4c1802884e403db8759ed0501f770a67a047f20)
This commit is contained in:
Alby96 committed 2026-10-27 22:51:32 +01:00
1 parent e3cbe30b29
commit 03d32f18d3
51 files changed
+4917 -108

No files matched your search

+129
View File
@@ -0,0 +1,129 @@
using Chronos.Core.Archiving;
using Chronos.Core.Model;
using Chronos.Core.Project;
namespace Chronos.Data.Projects;
/// <summary>A project's home cannot be reached now (its archive offline or busy, its server out of reach): try again later.</summary>
public sealed class HomeUnavailableException(string message, Exception? inner = null) : IOException(message, inner);
/// <summary>The sequence a home keeps projects for, as a workspace's project file names it.</summary>
public sealed record HomeSequence(BundleArchive Archive, BundleSequence Sequence, BundleHome Home);
/// <summary>
/// Where a sequence's projects live (owner review 2, R8): the side a workspace pushes to and pulls from, "like git". This
/// PC's archive is one (<see cref="ArchiveProjectHome"/>); a server is the other (phase 5b). Every call may throw
/// <see cref="HomeUnavailableException"/> when the home cannot be reached, and <see cref="ProjectException"/> when it refuses.
/// </summary>
public interface IProjectHome
{
/// <summary>The sequence and where it is.</summary>
Task<HomeSequence> SequenceAsync(CancellationToken cancellationToken);
/// <summary>The sequence's live projects, Main first (made when the sequence had none).</summary>
Task<IReadOnlyList<SequenceProject>> ListAsync(CancellationToken cancellationToken);
/// <summary>A new project named <paramref name="name"/> from <paramref name="fromVersionId"/> (a version of any project of the sequence), or from Main's head.</summary>
Task<SequenceProject> CreateAsync(string name, Guid? fromVersionId, string? author, CancellationToken cancellationToken);
/// <summary>The project's newest version.</summary>
Task<ProjectVersion> HeadAsync(Guid projectId, CancellationToken cancellationToken);
/// <summary>A version of the project by id; null when the home has none.</summary>
Task<ProjectVersion?> GetVersionAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken);
/// <summary>The versions numbered above <paramref name="afterNumber"/>, oldest first, at most <paramref name="limit"/>.</summary>
Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken);
/// <summary>One page of the history, newest first: the versions numbered below <paramref name="beforeNumber"/> (from the head when null).</summary>
Task<IReadOnlyList<ProjectVersion>> HistoryAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken);
/// <summary>Stores a version made from the head (<see cref="ProjectService.PushAsync"/>).</summary>
Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken);
/// <summary>The sequence's frames as the home holds them now.</summary>
Task<HomeFrames> FramesAsync(CancellationToken cancellationToken);
}
/// <summary>A sequence of this PC's archive as its projects' home: the archive's <see cref="ProjectService"/>.</summary>
public sealed class ArchiveProjectHome(ChronosDatabase db, ProjectService projects, Guid sequenceId) : IProjectHome
{
public Guid SequenceId => sequenceId;
public async Task<HomeSequence> SequenceAsync(CancellationToken cancellationToken)
{
var sequence = await db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false)
?? throw new ProjectException(ProjectError.SequenceNotFound, $"Sequence {sequenceId} is not in the index.");
var archive = await db.Archives.GetAsync(sequence.ArchiveId, cancellationToken).ConfigureAwait(false);
return new HomeSequence(new BundleArchive(sequence.ArchiveId, archive?.Name ?? string.Empty, archive?.RootPath),
new BundleSequence(sequence.Id, sequence.Folder, sequence.DisplayTitle, sequence.FrameCount),
new BundleHome(BundleHome.ArchiveKind, sequence.Id, sequence.ArchiveId));
}
public Task<IReadOnlyList<SequenceProject>> ListAsync(CancellationToken cancellationToken) =>
Reach(async () =>
{
// Made at once when the sequence has none, so every list has a Main.
await projects.MainAsync(sequenceId, cancellationToken).ConfigureAwait(false);
return await projects.ListAsync(sequenceId, cancellationToken).ConfigureAwait(false);
});
public Task<SequenceProject> CreateAsync(string name, Guid? fromVersionId, string? author, CancellationToken cancellationToken) =>
Reach(() => projects.CreateAsync(sequenceId, name, fromVersionId, author, cancellationToken));
public Task<ProjectVersion> HeadAsync(Guid projectId, CancellationToken cancellationToken) =>
Reach(async () =>
{
await Own(projectId, cancellationToken).ConfigureAwait(false);
return await projects.HeadAsync(projectId, cancellationToken).ConfigureAwait(false);
});
public async Task<ProjectVersion?> GetVersionAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken) =>
await projects.GetVersionAsync(versionId, cancellationToken).ConfigureAwait(false) is { } version && version.ProjectId == projectId ? version : null;
public Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken) =>
Reach(async () =>
{
await Own(projectId, cancellationToken).ConfigureAwait(false);
return await projects.VersionsAfterAsync(projectId, afterNumber, limit, cancellationToken).ConfigureAwait(false);
});
public Task<IReadOnlyList<ProjectVersion>> HistoryAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken) =>
Reach(async () =>
{
await Own(projectId, cancellationToken).ConfigureAwait(false);
return await projects.HistoryAsync(projectId, beforeNumber, limit, cancellationToken).ConfigureAwait(false);
});
public Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken) =>
Reach(async () =>
{
await Own(projectId, cancellationToken).ConfigureAwait(false);
return await projects.PushAsync(projectId, version, cancellationToken).ConfigureAwait(false);
});
public Task<HomeFrames> FramesAsync(CancellationToken cancellationToken) => projects.FramesAsync(sequenceId, cancellationToken);
/// <summary>The project is one of this sequence's.</summary>
private async Task<SequenceProject> Own(Guid projectId, CancellationToken cancellationToken) =>
await projects.GetAsync(projectId, cancellationToken).ConfigureAwait(false) is { } project && project.SequenceId == sequenceId
? project
: throw new ProjectException(ProjectError.NotFound, $"Project {projectId} is not a project of sequence {sequenceId}.");
/// <summary>An archive offline, read-only or busy is a home out of reach for now.</summary>
private static async Task<T> Reach<T>(Func<Task<T>> call)
{
try
{
return await call().ConfigureAwait(false);
}
catch (ArchiveOfflineException ex)
{
throw new HomeUnavailableException(ex.Message, ex);
}
catch (LeaseUnavailableException ex)
{
throw new HomeUnavailableException(ex.Message, ex);
}
}
}