feat(entity): Chunk #4 data layer + entity UI (characters & world-building)

Data layer:
- Fuzzy scorer (packages/core/src/fuzzy.ts) with index recovery + unit tests
- Backlink computation (packages/core/src/backlinks.ts) incl. entity-level backlinks
- Consistency checker (packages/core/src/consistency.ts) incl. reciprocity/scope + unit tests
- StorageAdapter contract extended with listEntities/searchEntities/saveEntity/deleteEntity;
  implemented in Local (Dexie) and Server adapters; contract tests cover entity CRUD + ?q= search
- WorldItem.fields now supports list values (keyPeople, rivals); expanded RelationshipKind
- @mention autocomplete extension + picker in the editor package

Entity UI (apps/web/src/features/entities/):
- Generic field renderer (EntityFields) driven by ENTITY_FIELDS/FieldDef
- Tabbed directory with fuzzy search + entity cards (EntitiesView)
- Create/edit/delete drawer (EntityEditor) reusing shared fields
- Relationship editor + force-directed SVG relationship map
- Entity engine stylesheet; wired into nav

Store: project-store entity methods (load/create/update/delete) over the StorageAdapter contract.

CI-green: typecheck, lint, 65 tests, and web build all pass.
This commit is contained in:
Schwitzz
2026-10-25 22:42:55 -05:00
parent 81a44b6e95
commit 4efa71515e
36 changed files with 2764 additions and 82 deletions
+11 -5
View File
@@ -15,6 +15,7 @@ import {
toAISession,
toEntity,
entityToRow,
entitySearchText,
wordCount,
type ProjectRow,
type ShareRow,
@@ -58,7 +59,7 @@ const entityCreate = z.object({
bio: z.string().optional(),
appearance: z.string().optional(),
voice: z.string().optional(),
relationships: z.string().optional(),
relationships: z.array(z.any()).optional(),
arc: z.string().optional(),
status: z.enum(["active", "archived"]).optional(),
tags: z.array(z.string()).optional(),
@@ -315,7 +316,7 @@ export function registerRoutes(app: FastifyInstance): void {
// ---------- Entities (characters / world / notes) ----------
app.get("/api/projects/:id/entities", async (req) => {
const { id } = req.params as { id: string };
const { kind } = req.query as { kind?: string };
const { kind, q } = req.query as { kind?: string; q?: string };
requireProjectAccess(app, req, id);
let rows: EntityRow[];
if (kind) {
@@ -323,7 +324,12 @@ export function registerRoutes(app: FastifyInstance): void {
} else {
rows = db.prepare("SELECT * FROM entities WHERE project_id = ?").all(id) as EntityRow[];
}
return { entities: rows.map(toEntity) };
let entities = rows.map(toEntity);
if (q) {
const needle = q.toLowerCase();
entities = entities.filter((e) => entitySearchText(e).toLowerCase().includes(needle));
}
return { entities };
});
app.post("/api/projects/:id/entities", async (req) => {
@@ -337,7 +343,7 @@ export function registerRoutes(app: FastifyInstance): void {
if (body.kind === "character") {
entity = {
id: eid, projectId: id, name: body.name ?? "", role: body.role ?? "", bio: body.bio ?? "",
appearance: body.appearance ?? "", voice: body.voice ?? "", relationships: body.relationships ?? "",
appearance: body.appearance ?? "", voice: body.voice ?? "", relationships: body.relationships ?? [],
arc: body.arc ?? "", status: body.status ?? "active", tags: body.tags ?? [],
};
} else if (body.kind === "world") {
@@ -374,7 +380,7 @@ export function registerRoutes(app: FastifyInstance): void {
if (kind === "character") {
entity = {
id, projectId, name: body.name ?? existing.name, role: body.role ?? "", bio: body.bio ?? "",
appearance: body.appearance ?? "", voice: body.voice ?? "", relationships: body.relationships ?? "",
appearance: body.appearance ?? "", voice: body.voice ?? "", relationships: body.relationships ?? [],
arc: body.arc ?? "", status: body.status ?? "active", tags: body.tags ?? [],
};
} else if (kind === "world") {