feat(workspace): clean-up of media, size limit and workspace trash

Phase 5c P4. The workspace no longer grows without bound: a daily
workspace-cleanup system schedule (04:30, catch-up) removes the media of
projects in step with their home that were not opened for Clean after,
and the size limit removes the least recently used after each copy.
Each project kept is logged with its reason (open in Edit, not in step,
home offline, jobs pending, renders not sent, unreadable, just copied).

- WorkspaceCleaner: cleans under the project's lease, re-checking every
  condition; the originals the home no longer holds go to the workspace
  trash, never away. The media index is marked Cleaned, so the project
  reads as MediaRemoved and opening it copies the media again.
- WorkspaceTrash: lists entries with a fingerprint, and empties only the
  plan the user confirmed (refused when the trash changed since).
- Trash dialog view model and view: Erase is enabled only after the user
  types the number of entries.
- Removing a copy counts the unsent renders and the last originals. Send
  first queues the renders' sending and refuses the removal until they
  are sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 15:41:48 +01:00
1 parent 2e1c67f531
commit f86630c77a
19 files changed
+1595 -44

No files matched your search

+15 -2
View File
@@ -20,8 +20,8 @@ namespace Chronos.App.Jobs;
/// wrote into its archive.json, as the rescans before it did, and counts as none while it is offline (an unplugged
/// drive). The system schedules stand for the timers the desktop used to run out of sight: the archive scan (its interval
/// carried over from the former Settings › Archive › Rescan every, <see cref="AppSettings.ScanIntervalMinutes"/>, once:
/// a row that exists keeps the user's edits), the daily index backup, and the housekeeping clean-up at 04:00 (job history,
/// cache trim). Scans give what they find a deep analysis as Settings › Analysis › After a scan says at each run
/// a row that exists keeps the user's edits), the daily index backup, the housekeeping clean-up at 04:00 (job history,
/// cache trim), and the workspace's clean-up at 04:30 (phase 5c: its media, a report of its trash). Scans give what they find a deep analysis as Settings › Analysis › After a scan says at each run
/// (<see cref="DeepAnalysisAfterScan"/>), like the scans started by hand. Thread-safe: the scheduler calls it from its loop.
/// </summary>
public sealed class DesktopScheduleHost(AppSettings settings, Func<ChronosDatabase?> database, Func<ArchiveService?> archives) : IScheduleHost
@@ -41,6 +41,16 @@ public sealed class DesktopScheduleHost(AppSettings settings, Func<ChronosDataba
/// <summary>When the housekeeping runs.</summary>
public static readonly TimeOnly HousekeepingTime = new(4, 0);
/// <summary>
/// Clean-up of the workspace (phase 5c), daily at 04:30, with catch-up: the media of projects past Settings › Workspace ›
/// Clean after or Size limit (<see cref="WorkspaceCleanStep"/>), and a report of its trash (<see cref="WorkspaceTrashStep"/>),
/// which it never empties. It runs whether an archive is open or not.
/// </summary>
public const string WorkspaceCleanup = "workspace-cleanup";
/// <summary>When the workspace clean-up runs: after the housekeeping.</summary>
public static readonly TimeOnly WorkspaceCleanupTime = new(4, 30);
/// <summary>The PC's zone; tests set another.</summary>
public TimeZoneInfo TimeZone { get; init; } = TimeZoneInfo.Local;
@@ -54,6 +64,9 @@ public sealed class DesktopScheduleHost(AppSettings settings, Func<ChronosDataba
new(Housekeeping, "Housekeeping", ScheduleActions.Cleanup, ScheduleRecurrence.DailyAt(HousekeepingTime),
new ScheduleParametersDto(Steps: [Chronos.Data.Housekeeping.CleanupSteps.JobHistory, CacheTrimStep.StepName],
OlderThanDays: Chronos.Data.Housekeeping.CleanupSteps.DefaultHistoryDays)),
// The ages and the limit are Settings › Workspace's, read at each run: the schedule holds no days of its own.
new(WorkspaceCleanup, "Workspace clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.DailyAt(WorkspaceCleanupTime),
new ScheduleParametersDto(Steps: [WorkspaceCleanStep.StepName, WorkspaceTrashStep.StepName], OlderThanDays: 0)),
];
public IReadOnlyList<string> CleanupSteps => archives()?.CleanupSteps.Select(s => s.Name).ToList() ?? [];
+3
View File
@@ -166,6 +166,7 @@ public static class ScheduleText
DesktopScheduleHost.ArchiveScan => "Jobs.Schedule.System.ArchiveScan",
DesktopScheduleHost.IndexBackup => "Jobs.Schedule.System.IndexBackup",
DesktopScheduleHost.Housekeeping => "Jobs.Schedule.System.Housekeeping",
DesktopScheduleHost.WorkspaceCleanup => "Jobs.Schedule.System.WorkspaceCleanup",
_ => null,
};
@@ -175,6 +176,8 @@ public static class ScheduleText
CleanupSteps.Audit => "Audit",
CleanupSteps.TrashReport => "TrashReport",
CacheTrimStep.StepName => "CacheTrim",
WorkspaceCleanStep.StepName => "WorkspaceClean",
WorkspaceTrashStep.StepName => "WorkspaceTrash",
_ => null,
};
@@ -0,0 +1,63 @@
using Chronos.App.Infrastructure;
using Chronos.App.Workspace;
using Chronos.Core.Localization;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Housekeeping;
using Chronos.Data.Workspaces;
namespace Chronos.App.Jobs;
/// <summary>
/// The desktop's clean-up step <c>workspace-clean</c> (phase 5c): removes the media of workspace projects in step with their
/// home, those not opened for Settings › Workspace › Clean after, then the least recently used while the projects take more
/// than Size limit (<see cref="WorkspaceHost.CleanAsync"/>). Each project kept is logged with why. It needs no archive: the
/// <c>workspace-cleanup</c> schedule runs it whether one is open or not. The trash is never emptied here.
/// </summary>
public sealed class WorkspaceCleanStep(Func<WorkspaceHost?> workspace) : ICleanupStep
{
public const string StepName = "workspace-clean";
public string Name => StepName;
public async Task<string> RunAsync(CleanupContext context, CleanupParameters parameters)
{
ArgumentNullException.ThrowIfNull(context);
if (workspace() is not { } host || await host.CleanAsync(cleanAfter: true, cancellationToken: context.Cancellation).ConfigureAwait(false) is not { } report)
return Loc.L("Jobs.Log.WorkspaceUnavailable");
foreach (var kept in report.Kept)
context.Job.Log(Loc.L("Jobs.Log.WorkspaceKept", Named(kept.SequenceTitle, kept.Name, kept.IsMain), Reason(kept.Reason)));
if (report.Cleaned.Count == 0 && report.Kept.Count == 0) return Loc.L("Jobs.Log.WorkspaceNothing", Formatting.Bytes(report.UsedBefore));
foreach (var cleaned in report.Cleaned.Where(c => c.Trashed > 0))
context.Job.Log(Loc.L("Archive.Log.WorkspaceOriginalsTrashed", Named(cleaned.SequenceTitle, cleaned.Name, cleaned.IsMain), Formatting.Count(cleaned.Trashed)));
return Loc.L("Jobs.Log.WorkspaceCleaned", Formatting.Count(report.Cleaned.Count), Formatting.Bytes(report.Freed), Formatting.Count(report.Kept.Count));
}
/// <summary>"open in Edit", "renders not sent", …: why a project was kept, for the job log.</summary>
public static string Reason(WorkspaceKeep reason) => Loc.L("Jobs.Log.WorkspaceSkip." + reason);
/// <summary>"Harbour sunset · Main": a project as the job log names it (its sequence, then its name).</summary>
public static string Named(string sequenceTitle, string name, bool isMain)
{
var project = WorkspaceText.ProjectName(name, isMain);
return sequenceTitle is { Length: > 0 } title ? title + Loc.Separator + project : project;
}
}
/// <summary>
/// The desktop's clean-up step <c>workspace-trash</c> (phase 5c): reports what the workspace's trash holds (entries and
/// size); it never deletes, emptying it stays the user's Settings › Workspace › Trash › Empty….
/// </summary>
public sealed class WorkspaceTrashStep(Func<WorkspaceHost?> workspace) : ICleanupStep
{
public const string StepName = "workspace-trash";
public string Name => StepName;
public async Task<string> RunAsync(CleanupContext context, CleanupParameters parameters)
{
ArgumentNullException.ThrowIfNull(context);
if (workspace() is not { IsEnabled: true } host) return Loc.L("Jobs.Log.WorkspaceUnavailable");
var plan = await host.PlanTrashAsync(context.Cancellation).ConfigureAwait(false);
return Loc.L("Jobs.Log.WorkspaceTrash", Formatting.Count(plan.Items.Count), Formatting.Bytes(plan.Bytes));
}
}