familiar-vtt 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of familiar-vtt might be problematic. Click here for more details.

Files changed (105) hide show
  1. package/.github/workflows/publish.yml +23 -0
  2. package/.mcp.json +11 -0
  3. package/ARCHITECTURE.md +320 -0
  4. package/BUSINESS.md +547 -0
  5. package/CLAUDE.md +118 -0
  6. package/COMMUNITY_RESEARCH.md +225 -0
  7. package/LICENSE +21 -0
  8. package/TOOLS_REFERENCE.md +224 -0
  9. package/dist/module/main.js +1016 -0
  10. package/dist/module/main.js.map +7 -0
  11. package/dist/server/server/config.d.ts +22 -0
  12. package/dist/server/server/config.js +33 -0
  13. package/dist/server/server/config.js.map +1 -0
  14. package/dist/server/server/connector.d.ts +26 -0
  15. package/dist/server/server/connector.js +179 -0
  16. package/dist/server/server/connector.js.map +1 -0
  17. package/dist/server/server/http-transport.d.ts +10 -0
  18. package/dist/server/server/http-transport.js +43 -0
  19. package/dist/server/server/http-transport.js.map +1 -0
  20. package/dist/server/server/index.d.ts +2 -0
  21. package/dist/server/server/index.js +59 -0
  22. package/dist/server/server/index.js.map +1 -0
  23. package/dist/server/server/logger.d.ts +6 -0
  24. package/dist/server/server/logger.js +14 -0
  25. package/dist/server/server/logger.js.map +1 -0
  26. package/dist/server/server/tools/bundles.d.ts +56 -0
  27. package/dist/server/server/tools/bundles.js +187 -0
  28. package/dist/server/server/tools/bundles.js.map +1 -0
  29. package/dist/server/server/tools/canvas-environment.d.ts +3 -0
  30. package/dist/server/server/tools/canvas-environment.js +151 -0
  31. package/dist/server/server/tools/canvas-environment.js.map +1 -0
  32. package/dist/server/server/tools/canvas.d.ts +3 -0
  33. package/dist/server/server/tools/canvas.js +134 -0
  34. package/dist/server/server/tools/canvas.js.map +1 -0
  35. package/dist/server/server/tools/cards.d.ts +3 -0
  36. package/dist/server/server/tools/cards.js +35 -0
  37. package/dist/server/server/tools/cards.js.map +1 -0
  38. package/dist/server/server/tools/characters.d.ts +3 -0
  39. package/dist/server/server/tools/characters.js +115 -0
  40. package/dist/server/server/tools/characters.js.map +1 -0
  41. package/dist/server/server/tools/chat.d.ts +3 -0
  42. package/dist/server/server/tools/chat.js +23 -0
  43. package/dist/server/server/tools/chat.js.map +1 -0
  44. package/dist/server/server/tools/combat.d.ts +3 -0
  45. package/dist/server/server/tools/combat.js +38 -0
  46. package/dist/server/server/tools/combat.js.map +1 -0
  47. package/dist/server/server/tools/compendium.d.ts +3 -0
  48. package/dist/server/server/tools/compendium.js +33 -0
  49. package/dist/server/server/tools/compendium.js.map +1 -0
  50. package/dist/server/server/tools/dice.d.ts +3 -0
  51. package/dist/server/server/tools/dice.js +12 -0
  52. package/dist/server/server/tools/dice.js.map +1 -0
  53. package/dist/server/server/tools/effects.d.ts +3 -0
  54. package/dist/server/server/tools/effects.js +54 -0
  55. package/dist/server/server/tools/effects.js.map +1 -0
  56. package/dist/server/server/tools/ember-events.d.ts +3 -0
  57. package/dist/server/server/tools/ember-events.js +34 -0
  58. package/dist/server/server/tools/ember-events.js.map +1 -0
  59. package/dist/server/server/tools/folders.d.ts +3 -0
  60. package/dist/server/server/tools/folders.js +30 -0
  61. package/dist/server/server/tools/folders.js.map +1 -0
  62. package/dist/server/server/tools/helpers.d.ts +10 -0
  63. package/dist/server/server/tools/helpers.js +13 -0
  64. package/dist/server/server/tools/helpers.js.map +1 -0
  65. package/dist/server/server/tools/items.d.ts +3 -0
  66. package/dist/server/server/tools/items.js +23 -0
  67. package/dist/server/server/tools/items.js.map +1 -0
  68. package/dist/server/server/tools/journals.d.ts +3 -0
  69. package/dist/server/server/tools/journals.js +71 -0
  70. package/dist/server/server/tools/journals.js.map +1 -0
  71. package/dist/server/server/tools/macros.d.ts +3 -0
  72. package/dist/server/server/tools/macros.js +32 -0
  73. package/dist/server/server/tools/macros.js.map +1 -0
  74. package/dist/server/server/tools/playlists.d.ts +3 -0
  75. package/dist/server/server/tools/playlists.js +39 -0
  76. package/dist/server/server/tools/playlists.js.map +1 -0
  77. package/dist/server/server/tools/regions.d.ts +3 -0
  78. package/dist/server/server/tools/regions.js +65 -0
  79. package/dist/server/server/tools/regions.js.map +1 -0
  80. package/dist/server/server/tools/registry.d.ts +11 -0
  81. package/dist/server/server/tools/registry.js +73 -0
  82. package/dist/server/server/tools/registry.js.map +1 -0
  83. package/dist/server/server/tools/scenes.d.ts +3 -0
  84. package/dist/server/server/tools/scenes.js +142 -0
  85. package/dist/server/server/tools/scenes.js.map +1 -0
  86. package/dist/server/server/tools/tables.d.ts +3 -0
  87. package/dist/server/server/tools/tables.js +22 -0
  88. package/dist/server/server/tools/tables.js.map +1 -0
  89. package/dist/server/server/tools/world.d.ts +3 -0
  90. package/dist/server/server/tools/world.js +26 -0
  91. package/dist/server/server/tools/world.js.map +1 -0
  92. package/dist/server/shared/constants.d.ts +16 -0
  93. package/dist/server/shared/constants.js +17 -0
  94. package/dist/server/shared/constants.js.map +1 -0
  95. package/dist/server/shared/html.d.ts +4 -0
  96. package/dist/server/shared/html.js +9 -0
  97. package/dist/server/shared/html.js.map +1 -0
  98. package/dist/server/shared/protocol.d.ts +184 -0
  99. package/dist/server/shared/protocol.js +58 -0
  100. package/dist/server/shared/protocol.js.map +1 -0
  101. package/dist/server/shared/types.d.ts +21 -0
  102. package/dist/server/shared/types.js +2 -0
  103. package/dist/server/shared/types.js.map +1 -0
  104. package/module.json +21 -0
  105. package/package.json +81 -0
package/BUSINESS.md ADDED
@@ -0,0 +1,547 @@
1
+ # Familiar — Business & Strategy
2
+
3
+ ## Vision
4
+
5
+ **Problem**: DMs with busy lives (kids, work, everything) want to run great sessions but don't have hours to prep. Existing AI DM tools are text-only (Friends & Fables) or barely functional.
6
+
7
+ **Solution**: An AI DM assistant that controls a real virtual tabletop. The AI manages scenes, moves tokens on battle maps, tracks combat, rolls dice, plays music, triggers animations — everything a human DM does in Foundry, but automated. The DM stays in control; the AI handles the heavy lifting.
8
+
9
+ **Who this is for**:
10
+ - DMs who don't have time to prep but want full VTT sessions
11
+ - Solo players or small groups without a dedicated DM
12
+ - DMs who want AI assistance during live sessions (NPC dialogue, rule lookups, encounter management)
13
+
14
+ **Positioning**: We don't compete with visual modules (Dice So Nice, Sequencer, Token Magic FX) — we **integrate** with them. We don't replace the DM — we **assist** them. We don't rebuild what exists — we **orchestrate** it.
15
+
16
+ **Approach**: Build iteratively — implement a feature, test it live against the running Foundry instance, verify it works, then move on. No big-bang releases.
17
+
18
+ ## Market Context
19
+
20
+ - Only serious AI DM project for Foundry VTT (the original foundry-vtt-mcp has 23 working tools and is largely dormant)
21
+ - Text-only AI DMs exist (Friends & Fables with 100k+ users, AI Game Master, AI Realm) but no one else controls a real VTT with 124+ tools
22
+ - Foundry has ~5,000 modules and 70,000+ community members — massive ecosystem to integrate with
23
+ - The Foundry creator is anti-AI, but we're pro-creativity: helping DMs, not replacing them or artists
24
+
25
+ ## Business Model
26
+
27
+ - **Closed source** — proprietary. Protects competitive advantage as the only serious AI DM platform for Foundry VTT
28
+ - **Current phase**: Everything free. Focus on building the product, getting users, and proving the concept. No paywall until we have enough premium content to justify it
29
+ - **Free tier** (built-in LLM client): User's own API key, works great for chat, moving tokens, basic AI assistance. Most users will be happy here
30
+ - **Paid tier** (€5/month "AI DM Pro"): For power users who want the AI to fully DM sessions, prep encounters, generate battlemaps, run entire campaigns. We set up MCP integration with their existing AI subscription (Claude Max, ChatGPT Plus, Gemini Advanced, etc.) so they can use unlimited AI with their flat-fee plan. Plus premium features
31
+ - **Planned premium features**: AI battlemap generation, AI portrait/token art generation, AI NPC voices, campaign modules (Ember etc.), premium visual effect presets, premium sound presets
32
+ - **MCP setup service** (Phase 13): One-click MCP configs for top 3 AI platforms (Claude, Gemini, ChatGPT). Setup wizard in module settings auto-detects OS, generates config, copy-to-clipboard. Subscriber's existing AI subscription powers unlimited AI DM. Gemini is free (no subscription needed). See Phase 13 for full details
33
+ - **Future license enforcement**: Stripe subscription → license key → verified at startup. One serverless function, no usage tracking, no metering
34
+
35
+ ## Installation Vision: Plug & Play
36
+
37
+ **Goal**: Install module in Foundry → pick your AI → paste API key → done. No terminal, no Node.js, no MCP knowledge.
38
+
39
+ ### Target User Experience
40
+ 1. Foundry → Install Modules → paste manifest URL or find in package browser → Enable
41
+ 2. Module Settings → pick AI provider → paste API key → Connect
42
+ 3. Start playing with your AI DM
43
+
44
+ ### Supported AI Providers (planned)
45
+ The module settings will offer pre-configured providers. User just picks one and pastes their API key:
46
+
47
+ | Provider | Models | Key |
48
+ |----------|--------|-----|
49
+ | OpenRouter | 200+ models (Claude, GPT-4, Gemini, Llama, Mistral, etc.) — one key for everything | `sk-or-...` |
50
+ | Anthropic | Claude Opus 4, Sonnet 4, Haiku 4 | `sk-ant-...` |
51
+ | OpenAI | GPT-4o, GPT-4.1, o3, o4-mini | `sk-...` |
52
+ | Google | Gemini 2.5 Pro, Gemini 2.5 Flash | `AIza...` |
53
+ | Groq | Llama, Mistral, Gemma (fast & cheap) | `gsk_...` |
54
+ | Mistral | Mistral Large, Medium, Small | `...` |
55
+ | Together AI | Open source models (Llama, Qwen, DeepSeek) | `...` |
56
+ | DeepSeek | DeepSeek V3, R1 (powerful & affordable) | `sk-...` |
57
+ | xAI (Grok) | Grok 3, Grok 3 Mini | `xai-...` |
58
+ | Cohere | Command R+, Command A (strong tool use) | `...` |
59
+ | Perplexity | Sonar Pro (AI search with web access) | `pplx-...` |
60
+ | Fireworks AI | Fast inference (Llama, DeepSeek, Qwen) | `fw_...` |
61
+ | Cerebras | Ultra-fast inference (fastest Llama) | `csk-...` |
62
+ | SambaNova | Fast inference with free tier | `...` |
63
+ | LM Studio | Local models via LM Studio (free, private) | localhost |
64
+ | Ollama | Any local model (free, private, no API key) | localhost |
65
+
66
+ **Voice providers** (NPC dialogue — separate API key):
67
+
68
+ | Provider | Voices | Key |
69
+ |----------|--------|-----|
70
+ | ElevenLabs (Recommended) | 10,000+ voices, best quality + sound effects | `sk_...` |
71
+ | Cartesia (Sonic) | Ultra-fast (40ms latency), real-time NPC dialogue | `...` |
72
+ | PlayHT | 600+ voices, 140+ languages, budget option | `...` |
73
+ | OpenAI TTS | 10 voices (Alloy, Nova, Onyx, etc.), uses existing OpenAI key | `sk-...` |
74
+
75
+ **Image providers** (battlemaps, portraits, tokens — separate API key):
76
+
77
+ | Provider | Models | Key |
78
+ |----------|--------|-----|
79
+ | OpenAI (DALL-E / GPT Image) | GPT Image 1, DALL-E 3 | `sk-...` |
80
+ | Stability AI | Stable Diffusion 3.5, Stable Image Ultra/Core | `sk-...` |
81
+ | fal.ai (Flux) | Flux Pro, Dev, Schnell (fast & cheap) | UUID key |
82
+ | Leonardo AI | Fantasy art specialization (great for D&D) | `...` |
83
+ | Replicate | 200+ community models, custom fine-tunes | `r8_...` |
84
+
85
+ **Recommended for beginners**: OpenRouter — one key, all models, pay per use.
86
+ **Total**: 16 chat + 4 voice + 5 image = **25 AI providers**.
87
+
88
+ ### Architecture: Current (MCP) vs. Future (Built-in)
89
+
90
+ **Current architecture** (works now, power users):
91
+ ```
92
+ MCP Client (Claude Desktop/Code/Cursor)
93
+ ↓ stdio (MCP protocol)
94
+ MCP Server (Node.js process)
95
+ ↓ WebSocket (localhost)
96
+ Foundry Module (browser)
97
+ ↓ Foundry API
98
+ Game World
99
+ ```
100
+
101
+ **Future architecture** (plug & play, everyone):
102
+ ```
103
+ Foundry Module (browser)
104
+ ├── Built-in LLM client (calls AI provider API directly)
105
+ ├── Tool execution (same 124 tools, runs in browser)
106
+ ├── Chat UI in Foundry sidebar
107
+ └── Foundry API
108
+ Game World
109
+ ```
110
+
111
+ The future architecture eliminates the MCP server entirely. The Foundry module talks directly to the AI provider API. No Node.js, no separate process, no MCP config. Everything lives inside the Foundry module.
112
+
113
+ **Both architectures will be supported** — MCP for power users who want Claude Code/Cursor integration, built-in for everyone else.
114
+
115
+ ### Release Roadmap
116
+ ```
117
+ PHASE 1 (now): MCP server + Foundry module (current, working)
118
+ PHASE 2 (next): Foundry package browser listing + npx support
119
+ → 2-step install: module + MCP config
120
+ PHASE 3 (target): Built-in LLM client in Foundry module
121
+ → 1-step install: module only, pick AI in settings
122
+ ```
123
+
124
+ ## Competitive Landscape
125
+
126
+ ### vs. FoundryAI (derekhearst — primary competitor, actively developed)
127
+
128
+ FoundryAI is a browser-only Foundry module with OpenRouter integration. Open source (MIT).
129
+ Built with AI assistance (6,600 lines first commit, 0→v1.0 in 24 hours). Study their code at github.com/derekhearst/FoundryAI
130
+
131
+ | Aspect | FoundryAI | Familiar (this) |
132
+ |--------|-----------|-------------------|
133
+ | Working tools | ~45 | **124** (3x more) |
134
+ | Canvas layers (walls, lights, sounds, notes) | None | **31 tools** |
135
+ | Audio/playlists | Basic | **6 tools** (full control) |
136
+ | Macros | None | **4 tools** (CRUD + execute) |
137
+ | Folders/Regions | None | **6 tools** |
138
+ | Weather/darkness/fog | None | **Yes** |
139
+ | In-browser chat UI | **Yes (Svelte sidebar)** | **Yes** (ApplicationV2 popout, streaming, tool badges) |
140
+ | Quick actions menu | No | **Planned** (one-click combat/scene/music/lookup actions) |
141
+ | Plug & play install | **Yes (module + API key)** | **Yes** (settings UI + chat UI + floating button) |
142
+ | Multi-provider | **Yes (OpenRouter)** | **Yes** (25 providers: 16 chat + 4 voice + 5 image) |
143
+ | RAG/vector search | **Yes (IndexedDB)** | Not yet |
144
+ | Text-to-speech | **Yes (OpenRouter TTS)** | Not yet |
145
+ | Session recaps | **Yes (auto journal)** | Not yet |
146
+ | NPC roleplay mode | **Yes (per-actor chat)** | Not yet |
147
+ | Architecture | Browser-only | MCP server + browser module |
148
+ | Status | Active (updated daily) | Active |
149
+
150
+ **Their architecture (learn from this):**
151
+ - Raw `fetch()` to OpenRouter API — no SDK, no proxy. 3 runtime deps (micromark only)
152
+ - Tools defined in OpenAI function-calling format, executed via switch statement in browser
153
+ - Svelte 5 (runes mode) for chat UI, mounted in ApplicationV2 via SvelteApplication bridge
154
+ - SSE streaming with ReadableStream reader
155
+ - Settings: all `config: false` + custom Svelte panel via `registerMenu()`
156
+ - Chat sessions persisted as JournalEntry flags
157
+ - Context tracking with auto-summarization when threshold hit
158
+ - Build: Vite + Svelte 5 + SCSS
159
+
160
+ **Their UX features we should adopt (observed March 2026):**
161
+ - **AI Settings panel**: max tokens, max tool calls sliders as parameters
162
+ - **Tool category toggles**: ~40 tools organized in categories, each toggleable on/off — lets users limit what the AI can do
163
+ - **Text-to-speech**: Enable TTS toggle for NPC dialogue
164
+ - **AI Data Access**: Configure which journal folders the AI can read
165
+ - **System prompt override**: Custom system prompt field
166
+ - **Context management**: Auto-summarize when context exceeds 85% threshold, configurable
167
+ - **Chat session manager**: List all chats (like Claude's sidebar), new chat / archive / switch between sessions
168
+ - **Context indicator**: Visual bubble showing token usage (e.g. "0 / 200k") — always visible
169
+ - **Roleplay as Actor**: Button to start dedicated NPC chat session
170
+ - **Reindex RAG**: Rebuild the vector index on demand
171
+ - **Generate Session Recap**: One-click journal summary of the session
172
+
173
+ **Where we beat them:** 3x tools (124 vs ~45), full canvas control, complete VTT coverage, 25 AI providers, quick actions menu (planned)
174
+ **Where they beat us:** UX maturity (chat sessions, context tracking, TTS, RAG, session recaps, actor roleplay, tool toggles)
175
+ **Strategy:** Keep our tool advantage, systematically close the UX gap. Priority order:
176
+ 1. Quick Actions menu (differentiator — they don't have this)
177
+ 2. Chat sessions (new chat / archive / switch)
178
+ 3. Context tracking with auto-summarization
179
+ 4. Tool category toggles (let users control what AI can do)
180
+ 5. Session recaps
181
+ 6. TTS / Actor roleplay / RAG
182
+
183
+ ### vs. foundry-vtt-mcp (adambdooley — largely dormant since Jan 2026)
184
+
185
+ | Aspect | foundry-vtt-mcp | Familiar (this) |
186
+ |--------|---------------------------|-------------------|
187
+ | Working tools | 23 (token tools broken) | **124** (19 domains) |
188
+ | Combat management | None | Full (start, end, turns, initiative) |
189
+ | Canvas layers | None | 31 tools (walls, lights, sounds, notes, doors) |
190
+ | Audio/playlists | None | 6 tools |
191
+ | Architecture | Dual-process (wrapper + backend) | Single process |
192
+ | Status | Last commit Jan 30, 2026 | Actively developed |
193
+
194
+ ### vs. Other Foundry AI modules
195
+
196
+ | Module | Type | Tools | Active | Notes |
197
+ |--------|------|-------|--------|-------|
198
+ | Loremaster | Chat + proxy | 11 | Yes | $5-30/mo subscription, PDF adventure upload, Year Zero Engine only |
199
+ | Cibola 8 | Image gen | 0 | Yes | AI portraits/battlemaps/TTS, Patreon subscription |
200
+ | RPGX AI Assistant | Chat (Ollama) | 0 | Moderate | Local LLM chatbot, 0.59% market share (~500 installs) |
201
+ | Phil's AI Assistant | Prompt gen | 0 | Yes | Copy/paste workflow, zero API cost |
202
+ | PF2e AI Combat | Combat advisor | 0 | No | PF2e only, suggestions only |
203
+ | foundryvtt-mcp (laurigates) | MCP + Socket.IO | 19 | Yes | No module needed, `npx` install, no canvas control |
204
+
205
+ ### vs. Friends & Fables (fables.gg — standalone AI TTRPG platform)
206
+
207
+ Friends & Fables is a standalone web-based AI TTRPG platform (not a VTT module). Built by Sidequest Labs (cofounders Will Liu & David Melnychuk). Claims 100,000+ users, 10,000+ Discord members. Started as a Discord bot, evolved into a full web platform. Self-described as "the world's first generative tabletop roleplaying game (GTTRPG)."
208
+
209
+ **How it works**: Players interact via text with an AI Game Master called "Franz." Franz narrates, adjudicates D&D 5e rules, tracks stats, manages inventory, and adapts to player choices. It's a text RPG with some visual elements (generated maps, images), not a traditional VTT.
210
+
211
+ **Tech stack**: Next.js + Tailwind CSS frontend. Multi-model AI backend using a "mixture of models depending on the task" — Gemini, Llama, GPT, Grok, plus custom fine-tuned models. Two narration models: "Finch" (fast) and "Fenix" (premium, better instruction following). Powered by their "ACE-1" engine (Agentic Campaign Engine).
212
+
213
+ **ACE-1 Architecture (innovative — study this)**:
214
+ - Multiple specialized AI agents that collaborate: one for narration, one for rule-checking, one for state-tracking
215
+ - Purpose-built TTRPG database for game state (not unstructured chat history) — character stats, coordinates, locations, quests stored structurally
216
+ - "Atomic memory" system — memories stored as discrete facts ("Neela offered 50 gold for safe transport of her cat") rather than hierarchical summaries that lose detail
217
+ - Smart memory prioritization by type, recency, and algorithmic scoring; users can lock critical memories
218
+ - Memory capacity tiered: Free 30, Starter 50, Pro 70, Legend 100
219
+ - "Unknown Entity System" — NPCs/locations stay hidden until players encounter them at matching coordinates, preventing metagaming
220
+ - NPC relationship tracking — scores adjust based on player interactions (gifts increase, violence decreases)
221
+ - Trope reduction algorithm — actively avoids clichés (Elara, hooded figures, windmills), steerable by user feedback
222
+ - "View Context" button lets users inspect what Franz actually sees — great for debugging
223
+ - "@mention" system guarantees specific entity info is included in next AI response
224
+
225
+ **Key features**:
226
+ - AI Game Master (Franz) with D&D 5e rules enforcement
227
+ - Solo play or multiplayer (up to 6 players, async/sync)
228
+ - World building tools: continents, cities, dungeons, NPCs, monsters, items, spells, lore pages
229
+ - Quest system with branching paths and dynamic outcomes
230
+ - POI (Point of Interest) maps — auto-generated, players can place tokens
231
+ - Text-to-speech narration with per-NPC character voices
232
+ - Image generation for characters, locations, items
233
+ - Travel system between locations
234
+ - Inventory management with carrying capacity
235
+ - NPC conversation mode (isolated to nearby characters)
236
+ - Adventure vs. Downtime pacing modes
237
+ - Community world sharing (play worlds others created)
238
+ - Custom instructions segmented by function (narration vs. NPC dialogue) with validation feedback
239
+
240
+ **Pricing** (as of late 2025):
241
+ - **Free**: 5-25 AI turns/day, 3-player campaigns, 30 memories
242
+ - **Starter**: $19.95/mo — unlimited turns, 4 players, 50 memories, 100 credits, 6,500 char context
243
+ - **Pro**: $29.95/mo — 5 players, 70 memories, 300 credits, 9,000 char context
244
+ - **Legend**: $39.95/mo — 6 players, 100 memories, 600 credits, 13,500 char context
245
+ - Credits used for premium narration model (Fenix) and image generation
246
+ - Annual billing: ~17% discount
247
+
248
+ **Strengths (what we can learn from)**:
249
+ 1. **Structured game state DB** — they don't store game state in chat history, they use a purpose-built database. This prevents hallucination and accuracy degradation over long sessions. We should consider structured state for our context management
250
+ 2. **Atomic memory system** — discrete facts vs. lossy summarization. Better than simple "summarize old messages" approach
251
+ 3. **Multi-agent architecture** — specialized agents for different tasks (narration, rules, state) rather than one monolithic prompt. Could inspire our tool-calling architecture
252
+ 4. **Trope reduction** — actively fighting AI clichés is a great UX touch
253
+ 5. **Context transparency** — "View Context" button builds trust and helps debugging
254
+ 6. **Entity mention system** — "@mention to guarantee context inclusion" is a smart UX pattern
255
+ 7. **Community world sharing** — marketplace/library of pre-built worlds
256
+ 8. **Async multiplayer** — play-by-post style, everyone plays at their own pace
257
+ 9. **Instruction validation** — telling users if their custom instructions will work as intended
258
+ 10. **Per-NPC voices** — Franz switches voices during dialogue automatically
259
+
260
+ **Weaknesses (where we win)**:
261
+ 1. **No real VTT** — text-only with basic POI maps. No battle maps, no token movement on grids, no walls/lighting, no fog of war. Our 124 tools controlling a real VTT is a fundamentally different (superior) experience for tactical combat
262
+ 2. **No module ecosystem** — standalone platform, can't integrate with 5,000+ Foundry modules (Dice So Nice, Sequencer, Token Magic FX, etc.)
263
+ 3. **No visual combat** — no grid-based tactical combat with token positioning, line of sight, AoE templates. Their "combat" is text descriptions
264
+ 4. **Memory complaints** — users report "it needs constant reminding of what you are trying to do" and having to repeat requests. Their atomic memory helps but context windows are still small (6,500-13,500 chars on paid tiers)
265
+ 5. **Expensive** — $20-40/mo for a text RPG. We're free (user brings own API key) or $5/mo for premium
266
+ 6. **Vendor lock-in** — users can't choose their own AI model/provider. We support 25 providers
267
+ 7. **No existing content import** — can't use D&D Beyond characters, published adventures, existing Foundry worlds. We work with whatever's already in your Foundry
268
+ 8. **Closed ecosystem** — everything happens inside their platform. We integrate with the DM's existing workflow
269
+ 9. **Generic tropes** — despite their trope reduction system, users report clichéd outputs requiring careful prompting
270
+ 10. **Server reliability** — peak-hour slowdowns reported; we run locally
271
+
272
+ **Key differentiator**: They're building a standalone AI-first TTRPG platform. We're building an AI assistant for an existing professional-grade VTT. Different philosophies:
273
+ - Friends & Fables: "Replace the VTT with AI-native text RPG"
274
+ - Familiar: "Augment the VTT with AI — keep everything DMs already love, add intelligence"
275
+
276
+ Their target audience is people who want quick AI-driven text adventures (especially solo or async). Our target audience is DMs who want AI assistance while running full visual VTT sessions.
277
+
278
+ **Ideas to steal**:
279
+ - Atomic memory for session persistence (Phase 12 context management)
280
+ - Context visibility ("View Context" equivalent in our chat UI)
281
+ - Entity @mention system for guaranteed context inclusion
282
+ - Trope reduction patterns in system prompts
283
+ - Instruction validation feedback
284
+ - Community-shared content (quest modules, world templates)
285
+ - Adventure vs. Downtime pacing modes as system prompt presets
286
+
287
+ ### vs. Other Text-only AI DMs (AI Realm, AI Game Master, etc.)
288
+
289
+ | Aspect | Text-only AI DMs | Familiar |
290
+ |--------|-----------------|-------------|
291
+ | Battle maps | No | Yes — full token/scene control |
292
+ | Visual combat | No | Yes — initiative, conditions, HP tracking on map |
293
+ | Music/ambiance | No | Yes — playlist control |
294
+ | Dice with visuals | No | Yes — 3D dice (via Dice So Nice) |
295
+ | Animations | No | Planned (via Sequencer + JB2A) |
296
+ | Module ecosystem | N/A | Integrates with 5,000+ Foundry modules |
297
+
298
+ ## Implementation Phases
299
+
300
+ ### Phase 1 — Foundation ✅
301
+ - [x] Project scaffold (TypeScript, ESLint, Vitest, Husky)
302
+ - [x] Shared protocol (Zod schemas, message types)
303
+ - [x] WebSocket connector (server-side, with ping/pong)
304
+ - [x] Config (Zod-validated env vars)
305
+ - [x] Logger (Pino)
306
+
307
+ ### Phase 2 — MCP Server Core ✅
308
+ - [x] MCP server with stdio transport (`@modelcontextprotocol/sdk`)
309
+ - [x] Tool registry pattern
310
+ - [x] Wire connector to MCP tool calls
311
+ - [x] Read-only tools: `get-world-info`, `get-character`, `list-characters`, `list-party-members`
312
+ - [x] Tests for server + tools (protocol test fixed)
313
+
314
+ ### Phase 3 — Foundry Module ✅
315
+ - [x] Module manifest (`module.json`)
316
+ - [x] WebSocket client with reconnection logic
317
+ - [x] Query handler routing
318
+ - [x] Character data access (read — full D&D 5e sheet formatting)
319
+ - [x] Scene data access (read)
320
+ - [x] Module settings UI (port, auto-connect)
321
+ - [x] Module deployed and live in Foundry (Ember world)
322
+
323
+ ### Phase 4 — Live Testing & Fixes ✅
324
+ - [x] Live test all existing tools against Ember world
325
+ - [x] Fix broken tools found during testing
326
+ - [x] Verify data formats are correct (D&D 5e 2024 system paths)
327
+ - [x] Code cleanup: 112 lint errors → 0, Foundry type declarations, registerTool API
328
+ - [x] `toggle-pause` tool added (needs MCP server restart to test)
329
+
330
+ ### Phase 5 — Session Essentials (Complete the MVP) ✅
331
+ - [x] `update-token` (hidden, elevation, size, rotation, disposition)
332
+ - [x] `roll-dice` — roll formula (1d20+5, 2d6+3), show result in Foundry chat
333
+ - [x] `search-compendium` — search items/creatures/spells by name
334
+ - [x] `get-compendium-entry` — full stat block (with compact mode option)
335
+ - [x] `list-compendium-packs` — available packs
336
+ - [x] `switch-scene` — change active scene
337
+
338
+ ### Phase 6 — Encounter & Combat Management ✅
339
+ - [x] `create-actor-from-compendium` — spawn creatures into world from compendium
340
+ - [x] `create-tokens` — place tokens on scene at x,y (batch support)
341
+ - [x] `delete-tokens` — remove tokens from scene
342
+ - [x] Combat management: `start-combat`, `end-combat`, `get-combat`, `next-turn`, `next-round`
343
+ - [x] Initiative rolls: `roll-initiative`, `roll-npc-initiative`
344
+ - [x] `get-available-conditions` — list all system status effects
345
+
346
+ ### Phase 7 — Character & Inventory Deep Dive ✅
347
+ - [x] `search-character-items` — search inventory/spells/features (token-efficient)
348
+ - [x] `get-character-item` — full detail for specific item/spell/feature on a character
349
+ - [x] `add-compendium-to-character` — add item/spell from compendium
350
+ - [x] `delete-character-items` — remove items
351
+ - [x] `rename-character`
352
+ - [x] Creature filtering: search by CR, type, size (for encounter building)
353
+ - [ ] `use-item` — cast spell / use ability (triggers Foundry dialog) — deferred
354
+
355
+ ### Phase 8 — Campaign & Journal Tools (Ember Content) ✅
356
+ - [x] `list-journals` — list all journal entries (filter by folder)
357
+ - [x] `search-journals` — search by title/content with snippets
358
+ - [x] `get-journal` — full journal with all pages (HTML stripped)
359
+ - [x] `get-journal-page` — single page with full content
360
+ - [x] `assign-ownership` — give player access to an actor (NONE/LIMITED/OBSERVER/OWNER)
361
+ - [x] `remove-ownership` — revoke player access
362
+
363
+ ### Phase 9 — Canvas Controls ✅
364
+ - [x] 30 canvas tools: templates, tiles, drawings, walls, lights, sounds, notes (full CRUD)
365
+ - [x] `toggle-door`, `close-all-doors` — door control
366
+ - [x] `set-darkness` — animated darkness level transitions
367
+ - [x] `reset-fog` — reset fog of war exploration
368
+ - [x] `capture-screen` — screenshot the current canvas view
369
+
370
+ ### Phase 10 — Environment & Atmosphere ✅
371
+ - [x] `get-weather-effects`, `set-weather` — weather effect presets (rain, snow, fog, etc.)
372
+ - [x] `send-chat-message`, `get-recent-messages` — chat integration
373
+ - [x] `list-playlists`, `play-playlist`, `stop-playlist`, `stop-all-playlists` — playlist control
374
+ - [x] `play-track`, `stop-track` — individual track control
375
+ - [x] `list-rollable-tables`, `get-rollable-table`, `roll-table` — rollable tables
376
+ - [x] `list-card-stacks`, `get-card-stack`, `draw-cards`, `shuffle-deck`, `reset-deck` — card stacks
377
+ - [x] `list-macros`, `create-macro`, `execute-macro`, `delete-macro` — macro management
378
+
379
+ ### Phase 11 — Polish & Release
380
+ - [x] Fix ESLint violations — 0 errors
381
+ - [x] Fix test suite — passing
382
+ - [ ] README with setup instructions
383
+ - [ ] Foundry package browser listing (submit to foundryvtt.com/packages/submit)
384
+ - [ ] GitHub Actions release workflow (build → zip → upload → Foundry API)
385
+
386
+ ### Phase 12 — Plug & Play (Built-in LLM Client)
387
+ The #1 priority. Eliminates the MCP server requirement. Users install the module and go.
388
+
389
+ - [x] AI provider settings UI (ApplicationV2 — custom _renderHTML, no Handlebars)
390
+ - 16 chat providers (OpenRouter, OpenAI, Anthropic, Google, Groq, Mistral, Together AI, DeepSeek, xAI, Cohere, Perplexity, Fireworks, Cerebras, SambaNova, LM Studio, Ollama)
391
+ - 4 voice providers (ElevenLabs, Cartesia, PlayHT, OpenAI TTS) — separate API key for NPC dialogue
392
+ - 5 image providers (OpenAI DALL-E, Stability AI, fal.ai, Leonardo AI, Replicate) — separate API key for battlemaps/portraits
393
+ - 3 independent API keys active simultaneously (chat + voice + image)
394
+ - Model/voice dropdown (static defaults + dynamic fetch from provider API)
395
+ - Test connection button (auto-fetches models/voices on success)
396
+ - Enable toggles for voice and image (collapsed when disabled)
397
+ - Temperature slider, max tokens, streaming toggle
398
+ - Scrollable window for smaller screens
399
+ - Save/Cancel buttons
400
+ - Tested: OpenRouter ✅, OpenAI ✅ — all providers use same pattern
401
+ - [x] Built-in LLM client (browser → AI provider API directly via fetch)
402
+ - No proxy needed — OpenAI, Anthropic, OpenRouter all support CORS from browser
403
+ - 124 tools in OpenAI function-calling format (src/module/ai/tools/*.ts)
404
+ - Tool execution calls Foundry handlers directly in-browser (no WebSocket round-trip)
405
+ - SSE streaming parser with async generator (src/module/ai/streaming.ts)
406
+ - Anthropic Messages API adapter (src/module/ai/anthropic-adapter.ts)
407
+ - Multi-step tool calling loop (up to 15 iterations)
408
+ - Provider-agnostic: works with all 16 chat providers from settings
409
+ - StreamCallbacks API for UI integration (onToken, onToolCallStart, onToolCallEnd, onComplete, onError)
410
+ - [x] Lazy-loaded tool bundles (industry best practice — reduces token overhead by ~90%)
411
+ - 124 tools organized into 19 domain bundles (characters, scenes, combat, etc.)
412
+ - Core bundles always loaded: dice, world, chat, combat, characters (~29 tools)
413
+ - Additional bundles enabled on demand via `list-tool-bundles` / `enable-tool-bundle` meta-tools
414
+ - MCP server: uses SDK enable/disable + `tools/list_changed` notifications for client sync
415
+ - Built-in chat: `ChatBundleManager` dynamically builds tool list per API request
416
+ - Addresses the "too many tools" problem: LLMs degrade at >30 tools, fail at >100 (GitHub research)
417
+ - Files: `src/server/tools/bundles.ts`, `src/module/ai/tools/bundles.ts`
418
+ - [x] Chat UI in Foundry (PopOut ApplicationV2 window, not sidebar — v13 sidebar tabs are buggy)
419
+ - Streaming text rendering (token by token with blinking cursor)
420
+ - Tool call badges with category icons (124 tools, color-coded: green=done, yellow=running, red=error)
421
+ - Hover over tool badge → shows result JSON tooltip
422
+ - Thinking indicator (3 pulsing dots) before first token
423
+ - Custom lightweight markdown renderer (no external deps) — code blocks, bold, italic, lists, headers, links
424
+ - Auto-scroll to newest message
425
+ - Enter to send, Shift+Enter for newline, auto-resize textarea
426
+ - Welcome screen + "not configured" state with setup button
427
+ - Clear chat + Settings buttons in header
428
+ - D&D-themed styling: warm terracotta/beige Claude color palette, wizard hat icon, fantasy language
429
+ - Floating terracotta button (bottom-left) to open chat — always visible
430
+ - Keyboard shortcut: Ctrl+Shift+Space
431
+ - `familiar.openChat()` / `getMessages()` / `isProcessing()` API for macro integration
432
+ - Multi-turn tool calling works: text → tools → more text → more tools → final response
433
+ - Tested live: get-world-info, roll-dice, search-compendium → create-actor → create-tokens, set-darkness + close-all-doors + send-chat-message chains all working
434
+ - No framework (vanilla JS/HTML/CSS in ApplicationV2) — keeps esbuild build simple
435
+ - Files: `src/module/ai/chat-app.ts` (chat window), `src/module/ai/markdown.ts` (renderer)
436
+ - [ ] Quick Actions menu (Phase 12.4 — next priority)
437
+ - "+" button in chat input area that opens a categorized action menu
438
+ - One-click common actions that auto-fill or directly execute prompts
439
+ - Categories with pre-built prompts:
440
+ - **Combat**: "Start combat", "Roll initiative for all", "Next turn", "End combat"
441
+ - **Scene**: "Set up ambush (darkness + doors)", "Dawn/day/dusk/night lighting", "Switch scene"
442
+ - **Creatures**: "Summon creature from compendium", "Place random encounter"
443
+ - **Music**: "Play combat music", "Play exploration music", "Stop all music"
444
+ - **Lookup**: "Search compendium", "Check character stats", "Look up spell/item"
445
+ - **Narration**: "Describe the scene", "NPC dialogue", "Roll on random table"
446
+ - Expandable over time with user-defined custom quick actions (saved in settings)
447
+ - Power users type prompts, casual users click buttons — both workflows supported
448
+ - [ ] Session persistence (save conversations as JournalEntries)
449
+ - [ ] Context window tracking + auto-summarization
450
+ - [ ] Keep MCP mode for power users (Claude Desktop/Code integration)
451
+
452
+ ### Phase 13 — MCP for Top AI Platforms (Use Your Subscription)
453
+ The killer feature: users pay $0-20/mo for their existing AI subscription and get **unlimited** AI DM.
454
+ No per-token costs, no "how much does this session cost" stress — just play.
455
+ This is 10x better than Friends & Fables and every other AI DM tool.
456
+
457
+ **Business model**: Free trial (1 month) → €5/mo AI DM Pro. MCP setup pays for itself after 1 session
458
+ (API costs for a single session = $5-15, subscription = flat $0-20/mo for unlimited).
459
+
460
+ **Two paths, same 124 tools:**
461
+ - **Free tier** (API key): Module → pick AI → paste key → done. Pay per use.
462
+ - **Pro tier** (MCP subscription): Module → click "MCP Setup" → use your Claude/Gemini subscription. Unlimited AI DM.
463
+
464
+ #### Phase 13.1 — Claude Desktop & Claude Code (Priority 1) ✅→🔨
465
+ The #1 AI for coding and reasoning. Most power users already have Claude Pro/Max.
466
+ - [ ] Config templates for all 3 OS (Windows, Mac, Linux)
467
+ - Claude Desktop: `%APPDATA%\Claude\claude_desktop_config.json` (Win), `~/Library/Application Support/Claude/claude_desktop_config.json` (Mac), `~/.config/Claude/claude_desktop_config.json` (Linux)
468
+ - Claude Code: `.mcp.json` (project) or `~/.claude.json` (global)
469
+ - [ ] MCP Setup wizard in Foundry module settings
470
+ - Auto-detect OS → show correct config path
471
+ - Copy-to-clipboard button with pre-filled config
472
+ - Step-by-step instructions (3 steps max)
473
+ - [ ] Claude Desktop Extension (.mcpb) — one-click install from Claude Desktop itself
474
+ - [ ] `npx foundry-mcp setup claude` CLI command for power users
475
+ - [ ] Test & verify with Claude Pro subscription (Sonnet 4, Opus 4)
476
+ - Subscription needed: Claude Pro ($20/mo) or Max ($100/mo)
477
+ - Transport: stdio ✅ (already supported, no server changes needed)
478
+ - Tool limit: none ✅
479
+
480
+ #### Phase 13.2 — Gemini CLI (Priority 1)
481
+ The surprise winner: **completely free** with Gemini 2.5 Pro (60 req/min, 1000/day). No subscription needed.
482
+ This alone makes foundry-mcp accessible to everyone.
483
+ - [ ] Config template: `~/.gemini/settings.json` (same on all OS)
484
+ - [ ] MCP Setup wizard support for Gemini (auto-detect, copy config)
485
+ - [ ] `npx foundry-mcp setup gemini` CLI command
486
+ - [ ] Test & verify with Gemini CLI (free tier)
487
+ - [ ] Document folder trust requirement (`gemini trust` needed for project folder)
488
+ - [ ] Note: no underscores in server names (Gemini parser quirk)
489
+ - Subscription needed: **none** (free Google account) ✅
490
+ - Transport: stdio ✅ (already supported, no server changes needed)
491
+ - Tool limit: none ✅
492
+
493
+ #### Phase 13.3 — ChatGPT Desktop (Priority 2)
494
+ Biggest user base. Requires HTTP/SSE transport (no stdio support). More work but huge reach.
495
+ - [ ] Add Streamable HTTP transport to MCP server (`@modelcontextprotocol/sdk` supports it)
496
+ - New env var: `FOUNDRY_MCP_TRANSPORT=stdio|http` (default: stdio, backward compatible)
497
+ - New env var: `FOUNDRY_MCP_HTTP_PORT=3006` (separate from WebSocket port)
498
+ - Same single-process architecture: HTTP transport + WebSocket bridge to Foundry
499
+ - [ ] Local HTTPS setup guide (ngrok or Cloudflare Tunnel for localhost → HTTPS)
500
+ - Or: bundled self-signed cert option for local-only use
501
+ - [ ] ChatGPT Developer Mode setup instructions
502
+ - Settings → Apps → Create → paste MCP endpoint URL
503
+ - Requires ChatGPT Plus ($20/mo) or Pro ($200/mo)
504
+ - [ ] `npx foundry-mcp setup chatgpt` CLI command (starts HTTP server + ngrok tunnel)
505
+ - [ ] Test & verify with ChatGPT Plus subscription
506
+ - [ ] Handle ChatGPT quirks: no error passthrough, hallucinated parameters, no workspace support
507
+ - Transport: Streamable HTTP/SSE (new, needs implementation)
508
+ - Tool limit: unknown (needs testing)
509
+ - Note: Once HTTP transport exists, xAI Grok API and other HTTP-only clients get support for free
510
+
511
+ #### Phase 13.4 — Future MCP Clients
512
+ Once HTTP transport is built (Phase 13.3), these become easy additions:
513
+ - [ ] xAI Grok (API-level MCP, HTTP/SSE) — no desktop app, API only
514
+ - [ ] Cursor (stdio ✅ but 40-tool hard limit — needs tool profiles: combat/exploration/full)
515
+ - [ ] Windsurf (stdio ✅ but 100-tool limit — needs 24 tools disabled, or tool profiles)
516
+ - [ ] VS Code + GitHub Copilot (stdio ✅, growing MCP support)
517
+ - [ ] Tool profiles system: pre-configured tool subsets for clients with limits
518
+ - `combat` profile: ~30 tools (combat, tokens, characters, dice)
519
+ - `exploration` profile: ~35 tools (scenes, canvas, audio, journals)
520
+ - `full` profile: all 124 tools (Claude, Gemini — no limits)
521
+
522
+ ### Phase 14 — Premium Features (Future)
523
+ - [ ] AI battlemap generation (user's API key → image gen → Foundry scene)
524
+ - [ ] AI portrait/token art generation
525
+ - [ ] AI NPC voices (TTS via OpenRouter or ElevenLabs)
526
+ - [ ] Campaign modules (Ember etc.)
527
+ - [ ] RAG/vector search for world lore (local IndexedDB, embeddings via user's API)
528
+ - [ ] Session recaps (auto-generated journal summaries)
529
+ - [ ] Actor roleplay mode (dedicated NPC chat sessions)
530
+
531
+ ## Dependencies
532
+
533
+ ### Runtime
534
+ - `@modelcontextprotocol/sdk` — MCP protocol implementation
535
+ - `ws` — WebSocket server (lightweight, no socket.io overhead)
536
+ - `zod` — Schema validation for config & protocol
537
+ - `pino` — Fast structured logging
538
+
539
+ ### Dev
540
+ - `typescript`, `tsx` — TypeScript toolchain
541
+ - `esbuild` — Fast bundler for Foundry module
542
+ - `eslint` + plugins — Linting (security, sonarjs, unicorn, etc.)
543
+ - `prettier` — Formatting
544
+ - `vitest` — Testing
545
+ - `husky` + `lint-staged` — Pre-commit hooks
546
+ - `commitlint` — Conventional commit enforcement
547
+ - `knip` — Dead code detection