feat: implement core application structure with Fastify server and SQLite persistence

- Add Fastify server in `app/src/index.ts` with health check and API routes for game state and turn processing.
- Create `latentEntities.ts` to handle personal item plausibility and promote beliefs to facts based on actor context.
- Introduce `llmAdapter.ts` for action extraction from prose input.
- Develop `truthEngine.ts` for pure validation logic, handling all verbs with explicit rejection reasons.
- Define new types in `types.ts` for facts, affordances, and latent entity requests/resolutions.
- Update `docker-compose.yml` for improved service structure and volume management.
- Create frontend structure with React, including Dockerfile, Vite configuration, and initial components for state inspection.
- Implement basic styles and HTML structure for the frontend application.
- Document current status and next steps in `thoughts.md`.
This commit is contained in:
2026-04-23 21:08:38 -04:00
parent 14a07bca7a
commit 1df2ae8164
20 changed files with 1830 additions and 14 deletions

View File

@@ -2,10 +2,19 @@
## Current Status
- Scaffold complete: `charactergarden/` folder structure created per spec section 9
- Core contracts defined in `app/src/types.ts`: Entity, Action, Verb, ValidationResult, StateChange, GameEvent, Turn, Belief, Summary
- Core contracts defined in `app/src/types.ts`: Entity, Action, Verb, ValidationResult, StateChange, GameEvent, Turn, Belief, Fact, Affordance, Summary
- `docker-compose.yml` created; ollama service gated behind `--profile llm` (not required for MVP)
- `.env` created with defaults
- Nothing is implemented yet — no logic, no database, no server
- `.env` / `.env.example` / `.gitignore` in place
- Container-first runtime files added: app/frontend Dockerfiles and `.dockerignore`s
- **Truth Engine implemented** in `app/src/truthEngine.ts` — pure function, no I/O, no LLM
- `validate(actions, worldState)` → ValidationResult
- `applyChanges(worldState, changes)` → new WorldState (immutable)
- All 8 verbs handled with explicit rejection reasons
- `move` now supports a built-in offscene room convention via `createOffsceneRoom()`
- `latentEntities.ts` can promote plausible personal items from belief to fact when the actor has carrying context
- `db.ts` added with SQLite schema + persistence helpers for `entities`, `events`, `turns`, `beliefs`, and `summaries`
- Minimal Fastify server + app pipeline added with seeded world state and fallback parser
- Minimal Vite React inspector added for visual boot testing and state inspection
## Current Architecture Decisions
- App: Node.js + Fastify + TypeScript
@@ -13,17 +22,24 @@
- Database: better-sqlite3 (synchronous, no ORM)
- Ollama is optional; system must work without it (per section 14)
- `Event` type renamed `GameEvent` in code to avoid collision with the DOM `Event` global
- Latent personal items are gated by facts-derived affordances, not accepted directly from beliefs
- The offscene room is represented as a normal room entity with id `offscene`
- App and frontend should be run and validated through Docker Compose rather than host-installed Node
## Next Steps
1. Implement Truth Engine (`app/src/truthEngine.ts`) — pure validation, no I/O
2. Add SQLite schema + db module (`app/src/db.ts`) with the 5 tables from section 7
3. Implement App service / turn flow (`app/src/index.ts`) per section 6
4. Add Fastify route `POST /turn` that executes the full pipeline
5. Stub LLM adapter (`app/src/llmAdapter.ts`) with a fallback parser
1. Implement App service / turn flow (`app/src/app.ts`) per section 6
2. Validate Docker boot and iterate on any compile/runtime failures
3. Expand fallback parser coverage and tighten truth-engine world rules
4. Add LLM adapter implementation beyond fallback parsing
## Open Questions
- Should room/location be an Entity attribute or a separate entity type?
- What is the initial world state for the MVP (12 rooms, ≤3 characters)?
- Should latent personal-item plausibility live only on actor attributes, or also look at worn item/container entities?
## Session Notes
- 2026-04-23: Project started. Scaffold and type contracts created. No logic yet.
- 2026-04-23: Project started. Scaffold, type contracts, .gitignore, and .env.example created.
- 2026-04-23: Truth Engine implemented. Pure validation with per-verb handlers and immutable applyChanges helper.
- 2026-04-23: Added facts/affordances + latent entity resolver for improv-style personal items, plus offscene room support.
- 2026-04-23: Added SQLite schema module. Host `npm install` is blocked by `better-sqlite3` on Windows Node 25, so runtime validation should happen inside Docker on an LTS Node image instead.
- 2026-04-23: Added minimal backend/frontend boot slice so the project can be tested visually through Docker.