← All source files

V12 / ea1357ad1734

ProjectCommands.cs

Lilith/Core/Projects/ProjectCommands.cs

Changed in this version
CS
using Lilith.Core.Commands;

namespace Lilith.Core.Projects;

public static class ProjectCommands
{
    public static void Register(ChatCommandRegistry commands, Func<ProviderClient> provider)
    {
        commands.Register("projects", "List private project drafts; no execution.", c => { c.RequireNoArguments(); return ProjectJson.Serialize(new ProjectDraftStore(provider().Workspace ?? throw new InvalidOperationException("Workspace unavailable.")).List()); });
        commands.Register("project-review", "Inspect source, frozen tests and evidence for one draft.", c => ProjectJson.Serialize(new ProjectDraftStore(provider().Workspace ?? throw new InvalidOperationException("Workspace unavailable.")).Load(c.Arguments)));
        commands.RegisterAsync("project-test", "Approve execution of one project and up to ten bounded test/repair rounds in visible Chrome or the console runner.", async c => new(true, await provider().ApproveProjectTestingAsync(c.Arguments, c.CancellationToken)));
        commands.RegisterAsync("project-publish", "Prepare one exact publication proposal for a successfully tested draft; does not approve workspace changes.", async c => new(true, await provider().PrepareProjectPublicationAsync(c.Arguments, c.CancellationToken)));
        string Pending(string state)
        {
            var store = new ProjectDraftStore(provider().Workspace ?? throw new InvalidOperationException("Workspace unavailable."));
            var ids = store.List().Select(d => System.Text.Json.JsonSerializer.SerializeToElement(d)).Where(d => d.GetProperty("State").GetString() == state).Select(d => d.GetProperty("Id").GetString()!).ToArray();
            return ids.Length == 1 ? ids[0] : throw new InvalidOperationException("Expected exactly one " + state + " draft. Use an explicit project ID.");
        }
        commands.RegisterAsync("project-test-pending", "Explicitly approve execution for the single pending draft; fails if there is more than one.", async c => { c.RequireNoArguments(); return new(true, await provider().ApproveProjectTestingAsync(Pending("awaiting_test_approval"), c.CancellationToken)); });
        commands.RegisterAsync("project-publish-pending", "Prepare publication for the single qualified draft; workspace approval remains separate.", async c => { c.RequireNoArguments(); return new(true, await provider().PrepareProjectPublicationAsync(Pending("ready_to_publish"), c.CancellationToken)); });
    }
}