Builds out the vertical slice for planning and writing a novel. Three front ends — the React UI, an embedded Claude agent, and an MCP stdio server — all go through one REST API, so an edit made from Claude Code and one made in the browser are the same edit. Layout: Domain entities and enums, no dependencies Application services, DTOs, the agent tool-use loop and its 15 tools Infrastructure EF Core 10 + SQLite, Anthropic SDK client Api ASP.NET Core 10 minimal APIs, OpenAPI, ProblemDetails Mcp MCP stdio server, 21 tools over the same REST API Web React 19 + Vite + TanStack Query + Tailwind v4 Data model is Project > Characters / OutlineNodes / Chapters > Scenes, plus agent conversations. The outline is a self-nesting tree so acts, sequences and beats can be arranged however the book wants; scenes carry goal/conflict/outcome because that is what the agent drafts prose from. Notes on a few choices: - Conversation history replays to the model as text only. The agent re-reads current state through its tools rather than trusting a record of edits that may since have changed in the UI. - The user's turn is persisted before the tool loop runs, so a question is recorded even when the model call fails. Turn order uses an explicit sequence column; timestamps tie when a turn completes inside one tick. - Tool failures return is_error results rather than throwing, so the model can read the message and correct itself. MCP tools do the same via CallToolResult, which keeps the API's own message instead of a generic SDK error. - The Anthropic client is constructed lazily. It is injected into the agent service, which also serves read-only endpoints, and those should keep working on an install with no key. Sending without one returns 503, not 400. - DateTimeOffset is stored as UTC ticks. SQLite refuses to ORDER BY the default text form, which every "recently updated first" listing depends on. Tests run against real in-memory SQLite rather than the EF in-memory provider so they exercise the cascade deletes and query translation that actually ship. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S56bfZMGe1hnhpWP4CjjNw
340 lines
16 KiB
C#
340 lines
16 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace NovelSoftware.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialSchema : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Projects",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Title = table.Column<string>(type: "TEXT", maxLength: 300, nullable: false),
|
|
Author = table.Column<string>(type: "TEXT", nullable: true),
|
|
Genre = table.Column<string>(type: "TEXT", nullable: true),
|
|
Logline = table.Column<string>(type: "TEXT", nullable: true),
|
|
Synopsis = table.Column<string>(type: "TEXT", nullable: true),
|
|
Notes = table.Column<string>(type: "TEXT", nullable: true),
|
|
TargetWordCount = table.Column<int>(type: "INTEGER", nullable: true),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Projects", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Characters",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ProjectId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Name = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
Role = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
|
Age = table.Column<string>(type: "TEXT", nullable: true),
|
|
Pronouns = table.Column<string>(type: "TEXT", nullable: true),
|
|
Occupation = table.Column<string>(type: "TEXT", nullable: true),
|
|
Appearance = table.Column<string>(type: "TEXT", nullable: true),
|
|
Personality = table.Column<string>(type: "TEXT", nullable: true),
|
|
Backstory = table.Column<string>(type: "TEXT", nullable: true),
|
|
Want = table.Column<string>(type: "TEXT", nullable: true),
|
|
Need = table.Column<string>(type: "TEXT", nullable: true),
|
|
InternalConflict = table.Column<string>(type: "TEXT", nullable: true),
|
|
ExternalConflict = table.Column<string>(type: "TEXT", nullable: true),
|
|
ArcSummary = table.Column<string>(type: "TEXT", nullable: true),
|
|
Voice = table.Column<string>(type: "TEXT", nullable: true),
|
|
Notes = table.Column<string>(type: "TEXT", nullable: true),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Characters", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Characters_Projects_ProjectId",
|
|
column: x => x.ProjectId,
|
|
principalTable: "Projects",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Conversations",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ProjectId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Title = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Conversations", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Conversations_Projects_ProjectId",
|
|
column: x => x.ProjectId,
|
|
principalTable: "Projects",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Chapters",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ProjectId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Number = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Title = table.Column<string>(type: "TEXT", maxLength: 300, nullable: false),
|
|
Summary = table.Column<string>(type: "TEXT", nullable: true),
|
|
PovCharacterId = table.Column<Guid>(type: "TEXT", nullable: true),
|
|
Setting = table.Column<string>(type: "TEXT", nullable: true),
|
|
Notes = table.Column<string>(type: "TEXT", nullable: true),
|
|
Status = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
|
TargetWordCount = table.Column<int>(type: "INTEGER", nullable: true),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Chapters", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Chapters_Characters_PovCharacterId",
|
|
column: x => x.PovCharacterId,
|
|
principalTable: "Characters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_Chapters_Projects_ProjectId",
|
|
column: x => x.ProjectId,
|
|
principalTable: "Projects",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "CharacterRelationships",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
CharacterId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
RelatedCharacterId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
RelationshipType = table.Column<string>(type: "TEXT", maxLength: 120, nullable: false),
|
|
Description = table.Column<string>(type: "TEXT", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_CharacterRelationships", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_CharacterRelationships_Characters_CharacterId",
|
|
column: x => x.CharacterId,
|
|
principalTable: "Characters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_CharacterRelationships_Characters_RelatedCharacterId",
|
|
column: x => x.RelatedCharacterId,
|
|
principalTable: "Characters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AgentMessages",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ConversationId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Role = table.Column<string>(type: "TEXT", maxLength: 16, nullable: false),
|
|
Sequence = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Content = table.Column<string>(type: "TEXT", nullable: false),
|
|
ToolCallsJson = table.Column<string>(type: "TEXT", nullable: true),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AgentMessages", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_AgentMessages_Conversations_ConversationId",
|
|
column: x => x.ConversationId,
|
|
principalTable: "Conversations",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "OutlineNodes",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ProjectId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ParentId = table.Column<Guid>(type: "TEXT", nullable: true),
|
|
NodeType = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
|
Title = table.Column<string>(type: "TEXT", maxLength: 300, nullable: false),
|
|
Summary = table.Column<string>(type: "TEXT", nullable: true),
|
|
SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
|
|
ChapterId = table.Column<Guid>(type: "TEXT", nullable: true),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OutlineNodes", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_OutlineNodes_Chapters_ChapterId",
|
|
column: x => x.ChapterId,
|
|
principalTable: "Chapters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_OutlineNodes_OutlineNodes_ParentId",
|
|
column: x => x.ParentId,
|
|
principalTable: "OutlineNodes",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "FK_OutlineNodes_Projects_ProjectId",
|
|
column: x => x.ProjectId,
|
|
principalTable: "Projects",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Scenes",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
ChapterId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Title = table.Column<string>(type: "TEXT", maxLength: 300, nullable: false),
|
|
Summary = table.Column<string>(type: "TEXT", nullable: true),
|
|
Goal = table.Column<string>(type: "TEXT", nullable: true),
|
|
Conflict = table.Column<string>(type: "TEXT", nullable: true),
|
|
Outcome = table.Column<string>(type: "TEXT", nullable: true),
|
|
PovCharacterId = table.Column<Guid>(type: "TEXT", nullable: true),
|
|
Location = table.Column<string>(type: "TEXT", nullable: true),
|
|
Prose = table.Column<string>(type: "TEXT", nullable: true),
|
|
WordCount = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Status = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
|
CreatedAt = table.Column<long>(type: "INTEGER", nullable: false),
|
|
UpdatedAt = table.Column<long>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Scenes", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Scenes_Chapters_ChapterId",
|
|
column: x => x.ChapterId,
|
|
principalTable: "Chapters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Scenes_Characters_PovCharacterId",
|
|
column: x => x.PovCharacterId,
|
|
principalTable: "Characters",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AgentMessages_ConversationId_Sequence",
|
|
table: "AgentMessages",
|
|
columns: new[] { "ConversationId", "Sequence" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Chapters_PovCharacterId",
|
|
table: "Chapters",
|
|
column: "PovCharacterId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Chapters_ProjectId_Number",
|
|
table: "Chapters",
|
|
columns: new[] { "ProjectId", "Number" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_CharacterRelationships_CharacterId",
|
|
table: "CharacterRelationships",
|
|
column: "CharacterId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_CharacterRelationships_RelatedCharacterId",
|
|
table: "CharacterRelationships",
|
|
column: "RelatedCharacterId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Characters_ProjectId",
|
|
table: "Characters",
|
|
column: "ProjectId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Conversations_ProjectId",
|
|
table: "Conversations",
|
|
column: "ProjectId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OutlineNodes_ChapterId",
|
|
table: "OutlineNodes",
|
|
column: "ChapterId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OutlineNodes_ParentId",
|
|
table: "OutlineNodes",
|
|
column: "ParentId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OutlineNodes_ProjectId_ParentId_SortOrder",
|
|
table: "OutlineNodes",
|
|
columns: new[] { "ProjectId", "ParentId", "SortOrder" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Scenes_ChapterId_SortOrder",
|
|
table: "Scenes",
|
|
columns: new[] { "ChapterId", "SortOrder" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Scenes_PovCharacterId",
|
|
table: "Scenes",
|
|
column: "PovCharacterId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "AgentMessages");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "CharacterRelationships");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "OutlineNodes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Scenes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Conversations");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Chapters");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Characters");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Projects");
|
|
}
|
|
}
|
|
}
|