From 119dafa505cd31767828a58406aa247ac4382e76 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 21 Nov 2026 11:05:05 +0100 Subject: [PATCH] Remove the research page, its MCP write tools and token write permission Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 + Directory.Packages.props | 1 - src/Flypaper.Storage/Entities/IdeaEntity.cs | 41 --- .../Entities/LabEntryEntity.cs | 33 --- .../Entities/McpTokenEntity.cs | 2 - src/Flypaper.Storage/FlypaperDbContext.cs | 22 -- .../FlypaperStorageExtensions.cs | 2 - .../20261121100100_RemoveResearch.Designer.cs | 151 +++++++++++ .../20261121100100_RemoveResearch.cs | 82 ++++++ .../FlypaperDbContextModelSnapshot.cs | 97 ------- src/Flypaper.Storage/Research/LabLimits.cs | 10 - .../Research/ResearchStore.cs | 247 ------------------ .../Settings/McpTokenStore.cs | 10 +- .../Components/Layout/MainLayout.razor | 1 - .../Components/Pages/Research/IdeaTable.razor | 58 ---- .../Pages/Research/ResearchPage.razor | 139 ---------- .../Pages/Settings/McpSection.razor | 26 +- .../Pages/Settings/McpTokenModel.cs | 2 - .../Components/Shared/MarkdownRenderer.cs | 57 ---- src/Flypaper.Web/Flypaper.Web.csproj | 1 - src/Flypaper.Web/Mcp/McpExtensions.cs | 43 +-- src/Flypaper.Web/Mcp/McpResults.cs | 27 -- .../Mcp/McpTokenAuthenticationHandler.cs | 9 +- src/Flypaper.Web/Mcp/McpTokenService.cs | 20 +- src/Flypaper.Web/Mcp/ResearchTools.cs | 188 ------------- src/Flypaper.Web/wwwroot/app.css | 93 ------- test/Flypaper.Tests/Mcp/McpEndpointTests.cs | 43 +-- .../Mcp/McpTokenServiceTests.cs | 31 +-- .../Storage/ResearchStoreTests.cs | 79 ------ .../Web/MarkdownRendererTests.cs | 50 ---- 30 files changed, 264 insertions(+), 1310 deletions(-) delete mode 100644 src/Flypaper.Storage/Entities/IdeaEntity.cs delete mode 100644 src/Flypaper.Storage/Entities/LabEntryEntity.cs create mode 100644 src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.Designer.cs create mode 100644 src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.cs delete mode 100644 src/Flypaper.Storage/Research/LabLimits.cs delete mode 100644 src/Flypaper.Storage/Research/ResearchStore.cs delete mode 100644 src/Flypaper.Web/Components/Pages/Research/IdeaTable.razor delete mode 100644 src/Flypaper.Web/Components/Pages/Research/ResearchPage.razor delete mode 100644 src/Flypaper.Web/Components/Shared/MarkdownRenderer.cs delete mode 100644 src/Flypaper.Web/Mcp/ResearchTools.cs delete mode 100644 test/Flypaper.Tests/Storage/ResearchStoreTests.cs delete mode 100644 test/Flypaper.Tests/Web/MarkdownRendererTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5afc4..b045a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ All notable changes to Flypaper are documented in this file. The format follows ## [Unreleased] +### Removed + +- Page „Erkenntnisse“ (`/erkenntnisse`) with lab notebook and idea table, including its navigation entry and + all stored entries and ideas (tables `LabEntries` and `Ideas` are dropped by a migration, without backup). +- MCP: tools `list_entries`, `list_ideas`, `create_entry`, `update_entry`, `create_idea`, `update_idea` and + `set_idea_status`. All MCP tools are read-only again. +- MCP tokens: write permission (switch on the settings page, column „Zugriff“, database column `CanWrite`). +- Markdown rendering (Markdig). + ## [0.5.2] - 2026-11-17 ### Changed diff --git a/Directory.Packages.props b/Directory.Packages.props index 7c5c78a..2c10719 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,7 +10,6 @@ - diff --git a/src/Flypaper.Storage/Entities/IdeaEntity.cs b/src/Flypaper.Storage/Entities/IdeaEntity.cs deleted file mode 100644 index f6579c0..0000000 --- a/src/Flypaper.Storage/Entities/IdeaEntity.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Flypaper.Storage.Entities; - -public enum IdeaLevel -{ - Low = 1, - Medium = 2, - High = 3 -} - -public enum IdeaStatus -{ - Open, - InProgress, - Done, - Dropped -} - -public sealed class IdeaEntity -{ - public int Id { get; set; } - - public required string Title { get; set; } - - public IdeaLevel Effort { get; set; } - - public IdeaLevel Efficiency { get; set; } - - public required string Rationale { get; set; } - - public IdeaStatus Status { get; set; } - - public DateTime? ImplementedOn { get; set; } - - public string? Commit { get; set; } - - public DateTime CreatedAt { get; set; } - - public DateTime UpdatedAt { get; set; } - - public bool IsClosed => Status is IdeaStatus.Done or IdeaStatus.Dropped; -} diff --git a/src/Flypaper.Storage/Entities/LabEntryEntity.cs b/src/Flypaper.Storage/Entities/LabEntryEntity.cs deleted file mode 100644 index 1b5699b..0000000 --- a/src/Flypaper.Storage/Entities/LabEntryEntity.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Flypaper.Storage.Entities; - -public enum LabEntryKind -{ - Experiment, - Observation, - Hypothesis, - Method -} - -public sealed class LabEntryEntity -{ - public int Id { get; set; } - - public DateTime Date { get; set; } - - public required string Title { get; set; } - - public LabEntryKind Kind { get; set; } - - public required string Text { get; set; } - - public string? Commit { get; set; } - - public string? Strategies { get; set; } - - public DateTime CreatedAt { get; set; } - - public DateTime UpdatedAt { get; set; } - - public IReadOnlyList StrategyList => - (Strategies ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); -} diff --git a/src/Flypaper.Storage/Entities/McpTokenEntity.cs b/src/Flypaper.Storage/Entities/McpTokenEntity.cs index a066945..c2143f4 100644 --- a/src/Flypaper.Storage/Entities/McpTokenEntity.cs +++ b/src/Flypaper.Storage/Entities/McpTokenEntity.cs @@ -11,6 +11,4 @@ public sealed class McpTokenEntity public DateTime CreatedAt { get; set; } public DateTime? LastUsedAt { get; set; } - - public bool CanWrite { get; set; } } diff --git a/src/Flypaper.Storage/FlypaperDbContext.cs b/src/Flypaper.Storage/FlypaperDbContext.cs index e008652..7a1739b 100644 --- a/src/Flypaper.Storage/FlypaperDbContext.cs +++ b/src/Flypaper.Storage/FlypaperDbContext.cs @@ -14,10 +14,6 @@ public sealed class FlypaperDbContext(DbContextOptions option public DbSet McpTokens => Set(); - public DbSet LabEntries => Set(); - - public DbSet Ideas => Set(); - protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) => configurationBuilder.Properties().HaveConversion(); @@ -47,23 +43,5 @@ public sealed class FlypaperDbContext(DbContextOptions option mcpToken.Property(e => e.Name).HasMaxLength(100); mcpToken.Property(e => e.TokenHash).HasMaxLength(64); mcpToken.HasIndex(e => e.TokenHash).IsUnique(); - - var labEntry = modelBuilder.Entity(); - labEntry.Property(e => e.Title).HasMaxLength(LabLimits.TitleLength); - labEntry.Property(e => e.Kind).HasConversion().HasMaxLength(16); - labEntry.Property(e => e.Text).HasMaxLength(LabLimits.TextLength); - labEntry.Property(e => e.Commit).HasMaxLength(LabLimits.CommitLength); - labEntry.Property(e => e.Strategies).HasMaxLength(LabLimits.StrategiesLength); - labEntry.Ignore(e => e.StrategyList); - labEntry.HasIndex(e => e.Date); - - var idea = modelBuilder.Entity(); - idea.Property(e => e.Title).HasMaxLength(LabLimits.TitleLength); - idea.Property(e => e.Effort).HasConversion().HasMaxLength(16); - idea.Property(e => e.Efficiency).HasConversion().HasMaxLength(16); - idea.Property(e => e.Rationale).HasMaxLength(LabLimits.TextLength); - idea.Property(e => e.Status).HasConversion().HasMaxLength(16); - idea.Property(e => e.Commit).HasMaxLength(LabLimits.CommitLength); - idea.Ignore(e => e.IsClosed); } } diff --git a/src/Flypaper.Storage/FlypaperStorageExtensions.cs b/src/Flypaper.Storage/FlypaperStorageExtensions.cs index 1a2e6c9..ec66fe4 100644 --- a/src/Flypaper.Storage/FlypaperStorageExtensions.cs +++ b/src/Flypaper.Storage/FlypaperStorageExtensions.cs @@ -3,7 +3,6 @@ using Flypaper.Storage.Dashboard; using Flypaper.Storage.Events; using Flypaper.Storage.Maintenance; using Flypaper.Storage.Queries; -using Flypaper.Storage.Research; using Flypaper.Storage.Settings; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -24,7 +23,6 @@ public static class FlypaperStorageExtensions builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); builder.Services.Configure(builder.Configuration.GetSection(RetentionOptions.SectionName)); builder.Services.AddFlypaperStorage(connectionString); diff --git a/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.Designer.cs b/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.Designer.cs new file mode 100644 index 0000000..1e8093d --- /dev/null +++ b/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.Designer.cs @@ -0,0 +1,151 @@ +// +using System; +using Flypaper.Storage; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Flypaper.Storage.Migrations +{ + [DbContext(typeof(FlypaperDbContext))] + [Migration("20261121100100_RemoveResearch")] + partial class RemoveResearch + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.15"); + + modelBuilder.Entity("Flypaper.Storage.Entities.McpTokenEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("LastUsedAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("TokenHash") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TokenHash") + .IsUnique(); + + b.ToTable("McpTokens"); + }); + + modelBuilder.Entity("Flypaper.Storage.Entities.SettingEntity", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Value") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("Settings"); + }); + + modelBuilder.Entity("Flypaper.Storage.Entities.TrapEventEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Asn") + .HasColumnType("INTEGER"); + + b.Property("BytesSent") + .HasColumnType("INTEGER"); + + b.Property("City") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ClientInfo") + .HasMaxLength(2048) + .HasColumnType("TEXT"); + + b.Property("Country") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("CountryCode") + .HasMaxLength(2) + .HasColumnType("TEXT"); + + b.Property("DurationMs") + .HasColumnType("INTEGER"); + + b.Property("EndedAt") + .HasColumnType("TEXT"); + + b.Property("Outcome") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("TEXT"); + + b.Property("Protocol") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("TEXT"); + + b.Property("Provider") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("RemoteIp") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.Property("SessionId") + .HasColumnType("TEXT"); + + b.Property("StartedAt") + .HasColumnType("TEXT"); + + b.Property("Strategy") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.Property("Target") + .HasMaxLength(2048) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Asn"); + + b.HasIndex("CountryCode"); + + b.HasIndex("RemoteIp"); + + b.HasIndex("StartedAt"); + + b.ToTable("TrapEvents"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.cs b/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.cs new file mode 100644 index 0000000..cd11c13 --- /dev/null +++ b/src/Flypaper.Storage/Migrations/20261121100100_RemoveResearch.cs @@ -0,0 +1,82 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Flypaper.Storage.Migrations +{ + /// + public partial class RemoveResearch : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Ideas"); + + migrationBuilder.DropTable( + name: "LabEntries"); + + migrationBuilder.DropColumn( + name: "CanWrite", + table: "McpTokens"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CanWrite", + table: "McpTokens", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.CreateTable( + name: "Ideas", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Commit = table.Column(type: "TEXT", maxLength: 64, nullable: true), + CreatedAt = table.Column(type: "TEXT", nullable: false), + Efficiency = table.Column(type: "TEXT", maxLength: 16, nullable: false), + Effort = table.Column(type: "TEXT", maxLength: 16, nullable: false), + ImplementedOn = table.Column(type: "TEXT", nullable: true), + Rationale = table.Column(type: "TEXT", maxLength: 20000, nullable: false), + Status = table.Column(type: "TEXT", maxLength: 16, nullable: false), + Title = table.Column(type: "TEXT", maxLength: 200, nullable: false), + UpdatedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Ideas", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LabEntries", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Commit = table.Column(type: "TEXT", maxLength: 64, nullable: true), + CreatedAt = table.Column(type: "TEXT", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + Kind = table.Column(type: "TEXT", maxLength: 16, nullable: false), + Strategies = table.Column(type: "TEXT", maxLength: 512, nullable: true), + Text = table.Column(type: "TEXT", maxLength: 20000, nullable: false), + Title = table.Column(type: "TEXT", maxLength: 200, nullable: false), + UpdatedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LabEntries", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_LabEntries_Date", + table: "LabEntries", + column: "Date"); + } + } +} diff --git a/src/Flypaper.Storage/Migrations/FlypaperDbContextModelSnapshot.cs b/src/Flypaper.Storage/Migrations/FlypaperDbContextModelSnapshot.cs index 4ca173a..e02f387 100644 --- a/src/Flypaper.Storage/Migrations/FlypaperDbContextModelSnapshot.cs +++ b/src/Flypaper.Storage/Migrations/FlypaperDbContextModelSnapshot.cs @@ -17,109 +17,12 @@ namespace Flypaper.Storage.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "10.0.15"); - modelBuilder.Entity("Flypaper.Storage.Entities.IdeaEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Commit") - .HasMaxLength(64) - .HasColumnType("TEXT"); - - b.Property("CreatedAt") - .HasColumnType("TEXT"); - - b.Property("Efficiency") - .IsRequired() - .HasMaxLength(16) - .HasColumnType("TEXT"); - - b.Property("Effort") - .IsRequired() - .HasMaxLength(16) - .HasColumnType("TEXT"); - - b.Property("ImplementedOn") - .HasColumnType("TEXT"); - - b.Property("Rationale") - .IsRequired() - .HasMaxLength(20000) - .HasColumnType("TEXT"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(16) - .HasColumnType("TEXT"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("TEXT"); - - b.Property("UpdatedAt") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Ideas"); - }); - - modelBuilder.Entity("Flypaper.Storage.Entities.LabEntryEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Commit") - .HasMaxLength(64) - .HasColumnType("TEXT"); - - b.Property("CreatedAt") - .HasColumnType("TEXT"); - - b.Property("Date") - .HasColumnType("TEXT"); - - b.Property("Kind") - .IsRequired() - .HasMaxLength(16) - .HasColumnType("TEXT"); - - b.Property("Strategies") - .HasMaxLength(512) - .HasColumnType("TEXT"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(20000) - .HasColumnType("TEXT"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("TEXT"); - - b.Property("UpdatedAt") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Date"); - - b.ToTable("LabEntries"); - }); - modelBuilder.Entity("Flypaper.Storage.Entities.McpTokenEntity", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); - b.Property("CanWrite") - .HasColumnType("INTEGER"); - b.Property("CreatedAt") .HasColumnType("TEXT"); diff --git a/src/Flypaper.Storage/Research/LabLimits.cs b/src/Flypaper.Storage/Research/LabLimits.cs deleted file mode 100644 index 8c254d6..0000000 --- a/src/Flypaper.Storage/Research/LabLimits.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Flypaper.Storage; - -public static class LabLimits -{ - public const int TitleLength = 200; - public const int TextLength = 20_000; - public const int CommitLength = 64; - public const int StrategiesLength = 512; - public const int StrategyNameLength = 64; -} diff --git a/src/Flypaper.Storage/Research/ResearchStore.cs b/src/Flypaper.Storage/Research/ResearchStore.cs deleted file mode 100644 index 7570ba5..0000000 --- a/src/Flypaper.Storage/Research/ResearchStore.cs +++ /dev/null @@ -1,247 +0,0 @@ -using System.Text.RegularExpressions; -using Flypaper.Storage.Entities; -using Microsoft.EntityFrameworkCore; - -namespace Flypaper.Storage.Research; - -public sealed record LabEntryInput( - string? Title = null, - LabEntryKind? Kind = null, - string? Text = null, - DateTime? Date = null, - string? Commit = null, - IReadOnlyList? Strategies = null); - -public sealed record IdeaInput( - string? Title = null, - IdeaLevel? Effort = null, - IdeaLevel? Efficiency = null, - string? Rationale = null, - IdeaStatus? Status = null, - DateTime? ImplementedOn = null, - string? Commit = null); - -public sealed partial class ResearchStore(IDbContextFactory dbContextFactory, TimeProvider timeProvider) -{ - public const int MaxLimit = 500; - - [GeneratedRegex("^[0-9a-f]{4,64}$")] - private static partial Regex CommitPattern(); - - [GeneratedRegex("^[a-z0-9][a-z0-9._-]*$")] - private static partial Regex StrategyPattern(); - - public async Task> ListEntriesAsync( - LabEntryKind? kind = null, - string? strategy = null, - int limit = MaxLimit, - CancellationToken ct = default) - { - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - var entries = db.LabEntries.AsNoTracking(); - if (kind is { } wanted) - { - entries = entries.Where(e => e.Kind == wanted); - } - - var rows = await entries.OrderByDescending(e => e.Date).ThenByDescending(e => e.Id).ToListAsync(ct); - if (!string.IsNullOrWhiteSpace(strategy)) - { - var name = strategy.Trim().ToLowerInvariant(); - rows = rows.Where(e => e.StrategyList.Contains(name, StringComparer.Ordinal)).ToList(); - } - - return rows.Take(Math.Clamp(limit, 1, MaxLimit)).ToList(); - } - - public async Task CreateEntryAsync(LabEntryInput input, CancellationToken ct = default) - { - var now = timeProvider.GetUtcNow().UtcDateTime; - var entry = new LabEntryEntity - { - Title = RequireText(input.Title, "title", LabLimits.TitleLength), - Kind = input.Kind ?? throw new ArgumentException("kind is required."), - Text = RequireText(input.Text, "text", LabLimits.TextLength), - Date = (input.Date ?? now).Date, - Commit = ParseCommit(input.Commit), - Strategies = JoinStrategies(input.Strategies), - CreatedAt = now, - UpdatedAt = now - }; - - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - db.LabEntries.Add(entry); - await db.SaveChangesAsync(ct); - return entry; - } - - public async Task UpdateEntryAsync(int id, LabEntryInput input, CancellationToken ct = default) - { - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - var entry = await db.LabEntries.SingleOrDefaultAsync(e => e.Id == id, ct); - if (entry is null) - { - return null; - } - - if (input.Title is not null) - { - entry.Title = RequireText(input.Title, "title", LabLimits.TitleLength); - } - - if (input.Kind is { } kind) - { - entry.Kind = kind; - } - - if (input.Text is not null) - { - entry.Text = RequireText(input.Text, "text", LabLimits.TextLength); - } - - if (input.Date is { } date) - { - entry.Date = date.Date; - } - - if (input.Commit is not null) - { - entry.Commit = ParseCommit(input.Commit); - } - - if (input.Strategies is not null) - { - entry.Strategies = JoinStrategies(input.Strategies); - } - - entry.UpdatedAt = timeProvider.GetUtcNow().UtcDateTime; - await db.SaveChangesAsync(ct); - return entry; - } - - public async Task> ListIdeasAsync(IdeaStatus? status = null, CancellationToken ct = default) - { - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - var ideas = db.Ideas.AsNoTracking(); - if (status is { } wanted) - { - ideas = ideas.Where(i => i.Status == wanted); - } - - var rows = await ideas.ToListAsync(ct); - return rows - .OrderBy(i => i.Effort) - .ThenByDescending(i => i.Efficiency) - .ThenBy(i => i.Id) - .ToList(); - } - - public async Task CreateIdeaAsync(IdeaInput input, CancellationToken ct = default) - { - var now = timeProvider.GetUtcNow().UtcDateTime; - var status = input.Status ?? IdeaStatus.Open; - var idea = new IdeaEntity - { - Title = RequireText(input.Title, "title", LabLimits.TitleLength), - Effort = input.Effort ?? throw new ArgumentException("effort is required."), - Efficiency = input.Efficiency ?? throw new ArgumentException("efficiency is required."), - Rationale = RequireText(input.Rationale, "rationale", LabLimits.TextLength), - Status = status, - Commit = ParseCommit(input.Commit), - CreatedAt = now, - UpdatedAt = now - }; - idea.ImplementedOn = ImplementedOn(status, input.ImplementedOn, null, now); - - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - db.Ideas.Add(idea); - await db.SaveChangesAsync(ct); - return idea; - } - - public async Task UpdateIdeaAsync(int id, IdeaInput input, CancellationToken ct = default) - { - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - var idea = await db.Ideas.SingleOrDefaultAsync(i => i.Id == id, ct); - if (idea is null) - { - return null; - } - - var now = timeProvider.GetUtcNow().UtcDateTime; - if (input.Title is not null) - { - idea.Title = RequireText(input.Title, "title", LabLimits.TitleLength); - } - - if (input.Effort is { } effort) - { - idea.Effort = effort; - } - - if (input.Efficiency is { } efficiency) - { - idea.Efficiency = efficiency; - } - - if (input.Rationale is not null) - { - idea.Rationale = RequireText(input.Rationale, "rationale", LabLimits.TextLength); - } - - if (input.Commit is not null) - { - idea.Commit = ParseCommit(input.Commit); - } - - var status = input.Status ?? idea.Status; - idea.Status = status; - idea.ImplementedOn = ImplementedOn(status, input.ImplementedOn, idea.ImplementedOn, now); - idea.UpdatedAt = now; - await db.SaveChangesAsync(ct); - return idea; - } - - private static DateTime? ImplementedOn(IdeaStatus status, DateTime? given, DateTime? current, DateTime now) => - status == IdeaStatus.Done ? (given ?? current ?? now).Date : null; - - private static string RequireText(string? value, string name, int maxLength) - { - var text = value?.Trim(); - if (string.IsNullOrEmpty(text)) - { - throw new ArgumentException($"{name} must not be empty."); - } - - return text.Length <= maxLength ? text : throw new ArgumentException($"{name} is too long (at most {maxLength} characters)."); - } - - private static string? ParseCommit(string? value) - { - var commit = value?.Trim().ToLowerInvariant(); - if (string.IsNullOrEmpty(commit)) - { - return null; - } - - return CommitPattern().IsMatch(commit) ? commit : throw new ArgumentException("commit must be a hexadecimal hash of 4 to 64 characters."); - } - - private static string? JoinStrategies(IReadOnlyList? strategies) - { - var names = (strategies ?? []) - .Select(name => name.Trim().ToLowerInvariant()) - .Where(name => name.Length > 0) - .Distinct() - .ToList(); - if (names.Any(name => name.Length > LabLimits.StrategyNameLength || !StrategyPattern().IsMatch(name))) - { - throw new ArgumentException("strategies must be strategy names such as maze-drip or git-drip (letters, digits, '.', '_' and '-')."); - } - - var joined = string.Join(',', names); - return joined.Length == 0 ? null - : joined.Length <= LabLimits.StrategiesLength ? joined - : throw new ArgumentException("strategies list is too long."); - } -} diff --git a/src/Flypaper.Storage/Settings/McpTokenStore.cs b/src/Flypaper.Storage/Settings/McpTokenStore.cs index 89396a1..83c8894 100644 --- a/src/Flypaper.Storage/Settings/McpTokenStore.cs +++ b/src/Flypaper.Storage/Settings/McpTokenStore.cs @@ -13,10 +13,10 @@ public sealed class McpTokenStore(IDbContextFactory dbContext return await db.McpTokens.AsNoTracking().OrderBy(t => t.Id).ToListAsync(ct); } - public async Task CreateAsync(string name, string tokenHash, bool canWrite = false, CancellationToken ct = default) + public async Task CreateAsync(string name, string tokenHash, CancellationToken ct = default) { await using var db = await dbContextFactory.CreateDbContextAsync(ct); - var token = new McpTokenEntity { Name = name, TokenHash = tokenHash, CanWrite = canWrite, CreatedAt = timeProvider.GetUtcNow().UtcDateTime }; + var token = new McpTokenEntity { Name = name, TokenHash = tokenHash, CreatedAt = timeProvider.GetUtcNow().UtcDateTime }; db.McpTokens.Add(token); await db.SaveChangesAsync(ct); return token; @@ -28,12 +28,6 @@ public sealed class McpTokenStore(IDbContextFactory dbContext return await db.McpTokens.Where(t => t.Id == id).ExecuteDeleteAsync(ct) > 0; } - public async Task SetCanWriteAsync(int id, bool canWrite, CancellationToken ct = default) - { - await using var db = await dbContextFactory.CreateDbContextAsync(ct); - return await db.McpTokens.Where(t => t.Id == id).ExecuteUpdateAsync(set => set.SetProperty(t => t.CanWrite, canWrite), ct) > 0; - } - public async Task UseAsync(string tokenHash, CancellationToken ct = default) { await using var db = await dbContextFactory.CreateDbContextAsync(ct); diff --git a/src/Flypaper.Web/Components/Layout/MainLayout.razor b/src/Flypaper.Web/Components/Layout/MainLayout.razor index fa954d2..35adbc5 100644 --- a/src/Flypaper.Web/Components/Layout/MainLayout.razor +++ b/src/Flypaper.Web/Components/Layout/MainLayout.razor @@ -4,7 +4,6 @@