@g33ks/foundryvtt-mcp 0.0.0-stage → 2.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.
Files changed (100) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +457 -2
  3. package/dist/character/manager.js +208 -0
  4. package/dist/cli/checks.js +307 -0
  5. package/dist/cli/config-file.js +120 -0
  6. package/dist/cli/init.js +414 -0
  7. package/dist/cli/prompt.js +117 -0
  8. package/dist/cli/snippets.js +64 -0
  9. package/dist/combat/manager.js +371 -0
  10. package/dist/config/env-layers.js +49 -0
  11. package/dist/config/index.js +298 -0
  12. package/dist/config/sources.js +201 -0
  13. package/dist/core.js +481 -0
  14. package/dist/diagnostics/client.js +291 -0
  15. package/dist/diagnostics/types.js +94 -0
  16. package/dist/foundry/auth.js +224 -0
  17. package/dist/foundry/browser-detect.js +170 -0
  18. package/dist/foundry/client.js +5874 -0
  19. package/dist/foundry/dice-formula.js +154 -0
  20. package/dist/foundry/event-log.js +298 -0
  21. package/dist/foundry/headless-gm-session.js +857 -0
  22. package/dist/foundry/journal-conflicts.js +141 -0
  23. package/dist/foundry/journal-history.js +90 -0
  24. package/dist/foundry/journal-integrity.js +322 -0
  25. package/dist/foundry/message-author.js +19 -0
  26. package/dist/foundry/module-bridge.js +441 -0
  27. package/dist/foundry/types.js +52 -0
  28. package/dist/foundry/world-cache.js +386 -0
  29. package/dist/index.js +107 -0
  30. package/dist/mcp-server.js +65 -0
  31. package/dist/server.js +159 -0
  32. package/dist/shared/build-order.js +134 -0
  33. package/dist/shared/config-hash.js +62 -0
  34. package/dist/shared/config-notice.js +55 -0
  35. package/dist/shared/control.js +291 -0
  36. package/dist/shared/daemon-link.js +135 -0
  37. package/dist/shared/daemon.js +311 -0
  38. package/dist/shared/ipc-client.js +200 -0
  39. package/dist/shared/ipc-server.js +316 -0
  40. package/dist/shared/paths.js +79 -0
  41. package/dist/shared/protocol.js +230 -0
  42. package/dist/shared/relay-config.js +65 -0
  43. package/dist/shared/relay.js +120 -0
  44. package/dist/shared/rotating-log.js +57 -0
  45. package/dist/shared/spawn.js +39 -0
  46. package/dist/shared/state-file.js +33 -0
  47. package/dist/shared/token.js +62 -0
  48. package/dist/shared/version.js +57 -0
  49. package/dist/tools/base.js +74 -0
  50. package/dist/tools/definitions.js +3109 -0
  51. package/dist/tools/handlers/actor-mutations.js +128 -0
  52. package/dist/tools/handlers/actors.js +114 -0
  53. package/dist/tools/handlers/chat-mutations.js +49 -0
  54. package/dist/tools/handlers/chat.js +38 -0
  55. package/dist/tools/handlers/combat-mutations.js +215 -0
  56. package/dist/tools/handlers/combat-order.js +94 -0
  57. package/dist/tools/handlers/combat.js +51 -0
  58. package/dist/tools/handlers/compendium.js +83 -0
  59. package/dist/tools/handlers/diagnostics.js +450 -0
  60. package/dist/tools/handlers/dice.js +54 -0
  61. package/dist/tools/handlers/effects.js +103 -0
  62. package/dist/tools/handlers/events.js +50 -0
  63. package/dist/tools/handlers/generation.js +258 -0
  64. package/dist/tools/handlers/item-mutations.js +132 -0
  65. package/dist/tools/handlers/items.js +53 -0
  66. package/dist/tools/handlers/journal-mutations.js +230 -0
  67. package/dist/tools/handlers/journals.js +80 -0
  68. package/dist/tools/handlers/module-bridge.js +421 -0
  69. package/dist/tools/handlers/placeable-mutations.js +272 -0
  70. package/dist/tools/handlers/resources.js +203 -0
  71. package/dist/tools/handlers/roll-tables.js +97 -0
  72. package/dist/tools/handlers/scene-mutations.js +159 -0
  73. package/dist/tools/handlers/scenes.js +355 -0
  74. package/dist/tools/handlers/settings.js +53 -0
  75. package/dist/tools/handlers/tile-mutations.js +56 -0
  76. package/dist/tools/handlers/token-mutations.js +356 -0
  77. package/dist/tools/handlers/users.js +59 -0
  78. package/dist/tools/handlers/utils.js +48 -0
  79. package/dist/tools/handlers/wall-mutations.js +98 -0
  80. package/dist/tools/handlers/world-documents.js +222 -0
  81. package/dist/tools/handlers/world.js +92 -0
  82. package/dist/tools/index.js +25 -0
  83. package/dist/tools/new-router.js +97 -0
  84. package/dist/tools/registry.js +79 -0
  85. package/dist/tools/resources.js +63 -0
  86. package/dist/tools/router.js +688 -0
  87. package/dist/tools/tool-dependencies.js +194 -0
  88. package/dist/tools/write-tools.js +97 -0
  89. package/dist/utils/cache-instance.js +30 -0
  90. package/dist/utils/cache.js +205 -0
  91. package/dist/utils/diagnostics.js +332 -0
  92. package/dist/utils/guards.js +17 -0
  93. package/dist/utils/image-size.js +160 -0
  94. package/dist/utils/log-args.js +47 -0
  95. package/dist/utils/logger.js +203 -0
  96. package/dist/utils/mcp-errors.js +47 -0
  97. package/dist/utils/refusal.js +30 -0
  98. package/dist/utils/sanitize.js +22 -0
  99. package/dist/utils/serial-queue.js +22 -0
  100. package/package.json +124 -4
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @fileoverview Dice formula parsing and evaluation for the local roller (laurigates/foundryvtt-mcp#219).
3
+ *
4
+ * The local roller used to scan a formula with `/(\d+)d(\d+)([+-]\d+)?/g`, which
5
+ * only captures a modifier glued directly to a dice term. Everything else the
6
+ * caller's character-class validator let through — a space-separated modifier
7
+ * (`1d20 + 5`), a second bonus (`1d20+5+3`), a count-less die (`d20`), a second
8
+ * dice term (`2d6+1d4`), parentheses — was silently dropped from the total. A
9
+ * dropped term produces a plausible number that is simply wrong, which for a
10
+ * dice roller is worse than an error: nothing signals that the formula was not
11
+ * understood.
12
+ *
13
+ * So this module does two things, in this order of importance:
14
+ * 1. Parses the whole formula into dice terms and standalone constants.
15
+ * 2. Consumes the input end to end, and throws a specific error on anything it
16
+ * cannot represent. Nothing is ever dropped in silence.
17
+ *
18
+ * The supported grammar is deliberately small:
19
+ *
20
+ * formula := sign? term ( sign term )*
21
+ * term := dice | constant
22
+ * dice := digit* 'd' digit+ // a missing count means 1
23
+ * constant := digit+
24
+ * sign := '+' | '-'
25
+ *
26
+ * Parentheses, multiplication and Foundry's modifier syntax (`4d6kh3`, `1d20r1`)
27
+ * are NOT supported and are rejected by name rather than ignored.
28
+ */
29
+ /**
30
+ * Upper bound on dice per term. A formula is capped at 100 characters upstream,
31
+ * which still allows five-digit counts; rolling those is pointless and slow, so
32
+ * it is refused explicitly rather than attempted.
33
+ */
34
+ export const MAX_DICE_PER_TERM = 1000;
35
+ /** Matches one term at a fixed offset: `NdS`, `dS`, or a bare constant. */
36
+ const TERM_PATTERN = /(\d*)d(\d+)|(\d+)/y;
37
+ function invalid(formula, detail) {
38
+ return new Error(`Invalid dice formula "${formula}": ${detail}`);
39
+ }
40
+ function isWhitespace(char) {
41
+ return char !== undefined && /\s/.test(char);
42
+ }
43
+ /**
44
+ * Parses a dice formula into its terms.
45
+ *
46
+ * @throws {Error} if the formula is empty, or holds anything the grammar above
47
+ * cannot represent. The message names the offending formula and what was
48
+ * wrong with it.
49
+ */
50
+ export function parseDiceFormula(formula) {
51
+ if (typeof formula !== 'string' || formula.trim() === '') {
52
+ throw new Error('Invalid dice formula: the formula is empty.');
53
+ }
54
+ if (formula.includes('(') || formula.includes(')')) {
55
+ throw new Error(`Unsupported dice formula "${formula}": parentheses are not supported. ` +
56
+ 'Expand the expression into plain terms joined by + or - (e.g. "1d20+5").');
57
+ }
58
+ const terms = [];
59
+ let index = 0;
60
+ let sign = 1;
61
+ const skipWhitespace = () => {
62
+ while (isWhitespace(formula[index])) {
63
+ index += 1;
64
+ }
65
+ };
66
+ skipWhitespace();
67
+ if (formula[index] === '+' || formula[index] === '-') {
68
+ sign = formula[index] === '-' ? -1 : 1;
69
+ index += 1;
70
+ skipWhitespace();
71
+ }
72
+ for (;;) {
73
+ if (index >= formula.length) {
74
+ throw invalid(formula, 'it ends with a dangling operator.');
75
+ }
76
+ TERM_PATTERN.lastIndex = index;
77
+ const match = TERM_PATTERN.exec(formula);
78
+ if (!match) {
79
+ throw invalid(formula, `unexpected "${formula[index]}" at position ${index}. Supported syntax: dice terms ` +
80
+ '(NdS, or dS for a single die) and whole numbers, joined by + or -.');
81
+ }
82
+ index = TERM_PATTERN.lastIndex;
83
+ const [, rawCount, rawSides, rawConstant] = match;
84
+ if (rawSides !== undefined) {
85
+ // A missing count means one die: "d20" is "1d20".
86
+ const count = rawCount === '' || rawCount === undefined ? 1 : Number.parseInt(rawCount, 10);
87
+ const sides = Number.parseInt(rawSides, 10);
88
+ if (sides < 1) {
89
+ throw invalid(formula, 'a die must have at least 1 side.');
90
+ }
91
+ if (count > MAX_DICE_PER_TERM) {
92
+ throw invalid(formula, `too many dice (${count}); the limit is ${MAX_DICE_PER_TERM} per term.`);
93
+ }
94
+ terms.push({ kind: 'dice', sign, count, sides });
95
+ }
96
+ else {
97
+ terms.push({ kind: 'constant', sign, value: Number.parseInt(rawConstant ?? '0', 10) });
98
+ }
99
+ skipWhitespace();
100
+ if (index >= formula.length) {
101
+ return terms;
102
+ }
103
+ const operator = formula[index];
104
+ if (operator !== '+' && operator !== '-') {
105
+ throw invalid(formula, `unexpected "${operator}" at position ${index}; terms must be joined by + or -.`);
106
+ }
107
+ sign = operator === '-' ? -1 : 1;
108
+ index += 1;
109
+ skipWhitespace();
110
+ }
111
+ }
112
+ /** Renders one evaluated term, e.g. `2d6: [3, 5]` or `5`. */
113
+ function renderTerm(term) {
114
+ return term.kind === 'dice'
115
+ ? `${term.count}d${term.sides}: [${term.rolls.join(', ')}]`
116
+ : `${term.value}`;
117
+ }
118
+ /**
119
+ * Rolls a formula and returns the total together with the terms that produced it.
120
+ *
121
+ * @param formula - Formula in the grammar documented above.
122
+ * @param rng - Uniform [0, 1) source; injectable so tests can be deterministic.
123
+ * @throws {Error} for any formula {@link parseDiceFormula} cannot represent.
124
+ */
125
+ export function evaluateDiceFormula(formula, rng = Math.random) {
126
+ const parsed = parseDiceFormula(formula);
127
+ const terms = [];
128
+ let total = 0;
129
+ for (const term of parsed) {
130
+ if (term.kind === 'constant') {
131
+ total += term.sign * term.value;
132
+ terms.push(term);
133
+ continue;
134
+ }
135
+ const rolls = [];
136
+ for (let i = 0; i < term.count; i += 1) {
137
+ rolls.push(Math.floor(rng() * term.sides) + 1);
138
+ }
139
+ const value = rolls.reduce((sum, roll) => sum + roll, 0);
140
+ total += term.sign * value;
141
+ terms.push({ ...term, rolls, value });
142
+ }
143
+ const rendered = terms
144
+ .map((term, position) => {
145
+ const body = renderTerm(term);
146
+ if (position === 0) {
147
+ return term.sign === -1 ? `-${body}` : body;
148
+ }
149
+ return `${term.sign === -1 ? '-' : '+'} ${body}`;
150
+ })
151
+ .join(' ');
152
+ return { total, breakdown: `${rendered} = ${total}`, terms };
153
+ }
154
+ //# sourceMappingURL=dice-formula.js.map
@@ -0,0 +1,298 @@
1
+ /**
2
+ * @fileoverview In-memory, cursor-addressed log of world activity.
3
+ *
4
+ * `world-cache.ts` consumes every `modifyDocument` broadcast to keep the cached
5
+ * snapshot current, then discards the fact that anything happened. That left an
6
+ * agent with no way to learn about a player's action except to re-poll
7
+ * `get_chat_messages` / `get_combat_state` in a loop and diff the results.
8
+ *
9
+ * This module keeps the *notification* alongside the cache update: each
10
+ * broadcast is summarized into one {@link WorldEvent} and appended to a bounded
11
+ * ring. Readers address the ring by an opaque monotonic cursor and may block on
12
+ * {@link WorldEventLog.wait} until something new lands, so waiting costs one
13
+ * suspended request instead of N polling round-trips.
14
+ *
15
+ * Pure logic by design — no socket, no IO, no imports from `client.ts`. Mirrors
16
+ * the layering of `world-cache.ts` so both are testable against plain objects.
17
+ */
18
+ import { isRecord } from '../utils/guards.js';
19
+ import { stripHtml } from '../utils/sanitize.js';
20
+ import { messageAuthorId } from './message-author.js';
21
+ /** Longest chat excerpt carried in a summary line, in characters. */
22
+ const MAX_SUMMARY_TEXT = 200;
23
+ /**
24
+ * Bounded ring of {@link WorldEvent}s with cursor reads and long-poll waits.
25
+ *
26
+ * Sequence numbers are assigned by the log and never reused, so a cursor stays
27
+ * meaningful even after the events it pointed at have been evicted — that is
28
+ * how {@link EventReadResult.dropped} can report a gap rather than silently
29
+ * skipping it.
30
+ */
31
+ export class WorldEventLog {
32
+ capacity;
33
+ events = [];
34
+ waiters = [];
35
+ nextSeq = 1;
36
+ constructor(capacity) {
37
+ this.capacity = Math.max(1, Math.floor(capacity));
38
+ }
39
+ /**
40
+ * Appends an event, evicting the oldest once over capacity, and wakes every
41
+ * pending waiter.
42
+ *
43
+ * @returns The sequence number assigned to the new event.
44
+ */
45
+ append(event) {
46
+ const seq = this.nextSeq++;
47
+ this.events.push({ ...event, seq, at: Date.now() });
48
+ while (this.events.length > this.capacity) {
49
+ this.events.shift();
50
+ }
51
+ this.wakeAll();
52
+ return seq;
53
+ }
54
+ /** Sequence number of the newest event; 0 when empty. */
55
+ head() {
56
+ return this.nextSeq - 1;
57
+ }
58
+ /** Sequence number of the oldest retained event; 0 when empty. */
59
+ oldest() {
60
+ return this.events.length > 0 ? (this.events[0]?.seq ?? 0) : 0;
61
+ }
62
+ /** Number of events currently retained. */
63
+ size() {
64
+ return this.events.length;
65
+ }
66
+ /**
67
+ * Returns matching events newer than `afterSeq`, capped at `limit`.
68
+ *
69
+ * `nextCursor` is `head()` on a complete read but the last returned event's
70
+ * `seq` on a truncated one. Both halves matter: returning `head()` after
71
+ * truncation would skip the matches that did not fit, while returning the
72
+ * last match every time would make a caller whose filter excludes recent
73
+ * traffic re-scan the same non-matching events on every call.
74
+ */
75
+ read(afterSeq, filter, limit) {
76
+ const cap = Math.max(1, Math.floor(limit));
77
+ const oldest = this.oldest();
78
+ // Events between the caller's cursor and the oldest retained event have
79
+ // been evicted. Report the size of that hole so the caller knows its view
80
+ // of the world is incomplete rather than merely quiet.
81
+ let dropped = 0;
82
+ let from = afterSeq;
83
+ if (afterSeq > 0 && oldest > 0 && afterSeq < oldest - 1) {
84
+ dropped = oldest - 1 - afterSeq;
85
+ from = oldest - 1;
86
+ }
87
+ const events = [];
88
+ let more = false;
89
+ for (const event of this.events) {
90
+ if (event.seq <= from) {
91
+ continue;
92
+ }
93
+ if (!matchesFilter(event, filter)) {
94
+ continue;
95
+ }
96
+ if (events.length >= cap) {
97
+ more = true;
98
+ break;
99
+ }
100
+ events.push(event);
101
+ }
102
+ const last = events.length > 0 ? events[events.length - 1] : undefined;
103
+ const nextCursor = more && last ? last.seq : this.head();
104
+ return { events, nextCursor, dropped, more };
105
+ }
106
+ /**
107
+ * Resolves as soon as an event newer than `afterSeq` exists, or after
108
+ * `timeoutMs`, whichever comes first. Never rejects.
109
+ *
110
+ * The up-front `head()` check is not an optimization: without it, an event
111
+ * appended between a caller's `read` and its `wait` would already have woken
112
+ * nobody, and the caller would block for the full timeout despite the news it
113
+ * was waiting for having arrived.
114
+ */
115
+ wait(afterSeq, timeoutMs) {
116
+ if (this.head() > afterSeq) {
117
+ return Promise.resolve();
118
+ }
119
+ if (timeoutMs <= 0) {
120
+ return Promise.resolve();
121
+ }
122
+ return new Promise((resolve) => {
123
+ const waiter = {
124
+ resolve,
125
+ timer: setTimeout(() => {
126
+ this.waiters = this.waiters.filter((candidate) => candidate !== waiter);
127
+ resolve();
128
+ }, timeoutMs),
129
+ };
130
+ this.waiters.push(waiter);
131
+ });
132
+ }
133
+ /** Resolves and clears every pending waiter, leaking no timers. */
134
+ wakeAll() {
135
+ if (this.waiters.length === 0) {
136
+ return;
137
+ }
138
+ const pending = this.waiters;
139
+ this.waiters = [];
140
+ for (const waiter of pending) {
141
+ clearTimeout(waiter.timer);
142
+ waiter.resolve();
143
+ }
144
+ }
145
+ }
146
+ function matchesFilter(event, filter) {
147
+ if (filter.kinds && filter.kinds.length > 0 && !filter.kinds.includes(event.kind)) {
148
+ return false;
149
+ }
150
+ if (filter.types && filter.types.length > 0) {
151
+ const wanted = filter.types.map((entry) => entry.toLowerCase());
152
+ if (!wanted.includes(event.type.toLowerCase())) {
153
+ return false;
154
+ }
155
+ }
156
+ if (filter.actions && filter.actions.length > 0 && !filter.actions.includes(event.action)) {
157
+ return false;
158
+ }
159
+ if (filter.sceneId && event.sceneId !== filter.sceneId) {
160
+ return false;
161
+ }
162
+ // Absent userId passes deliberately — see EventFilter.excludeUserId.
163
+ if (filter.excludeUserId && event.userId === filter.excludeUserId) {
164
+ return false;
165
+ }
166
+ return true;
167
+ }
168
+ /** Truncates to {@link MAX_SUMMARY_TEXT}, marking that it was cut. */
169
+ function truncate(text) {
170
+ const flat = text.replace(/\s+/g, ' ').trim();
171
+ return flat.length > MAX_SUMMARY_TEXT ? `${flat.slice(0, MAX_SUMMARY_TEXT)}…` : flat;
172
+ }
173
+ /** Extracts the scene id a broadcast pertains to, if any. */
174
+ function resolveSceneId(broadcast, docs) {
175
+ const match = broadcast.parentUuid?.match(/^Scene\.([a-zA-Z0-9]+)/);
176
+ if (match) {
177
+ return match[1];
178
+ }
179
+ if (broadcast.type === 'Scene') {
180
+ const id = docs[0]?._id;
181
+ return typeof id === 'string' ? id : undefined;
182
+ }
183
+ return undefined;
184
+ }
185
+ function userName(worldData, userId) {
186
+ if (!userId || !worldData) {
187
+ return undefined;
188
+ }
189
+ return worldData.users?.find((user) => user._id === userId)?.name;
190
+ }
191
+ function actorName(worldData, actorId) {
192
+ if (!actorId || !worldData) {
193
+ return undefined;
194
+ }
195
+ return worldData.actors?.find((actor) => actor._id === actorId)?.name;
196
+ }
197
+ /**
198
+ * Renders one `modifyDocument` broadcast as a {@link WorldEvent}.
199
+ *
200
+ * `worldData` is consulted only for cheap id→name lookups so summaries read as
201
+ * "Token Goblin moved" rather than "Token aBcDeFgHiJkLmNoP moved"; a null
202
+ * snapshot degrades to ids and never fails.
203
+ */
204
+ export function summarizeDocumentBroadcast(broadcast, worldData) {
205
+ const docs = broadcast.result.filter(isRecord);
206
+ const ids = broadcast.action === 'delete'
207
+ ? broadcast.result.filter((entry) => typeof entry === 'string')
208
+ : docs.map((doc) => doc._id).filter((id) => typeof id === 'string');
209
+ const first = docs[0];
210
+ // Foundry sends update payloads as diffs, so the payload's own keys *are*
211
+ // the changed set — no comparison against the cache is needed.
212
+ const changed = first ? Object.keys(first).filter((key) => key !== '_id') : [];
213
+ let data;
214
+ if (first && broadcast.action === 'update') {
215
+ data = {};
216
+ for (const key of changed) {
217
+ data[key] = first[key];
218
+ }
219
+ }
220
+ else if (first && broadcast.action === 'create') {
221
+ const highlights = {};
222
+ if (typeof first.name === 'string') {
223
+ highlights.name = first.name;
224
+ }
225
+ if (typeof first.type === 'string' || typeof first.type === 'number') {
226
+ highlights.type = first.type;
227
+ }
228
+ if (Object.keys(highlights).length > 0) {
229
+ data = highlights;
230
+ }
231
+ }
232
+ if (data && Object.keys(data).length === 0) {
233
+ data = undefined;
234
+ }
235
+ const event = {
236
+ kind: 'document',
237
+ type: broadcast.type,
238
+ action: broadcast.action,
239
+ ids,
240
+ summary: '',
241
+ ...(broadcast.userId ? { userId: broadcast.userId } : {}),
242
+ };
243
+ const sceneId = resolveSceneId(broadcast, docs);
244
+ if (sceneId) {
245
+ event.sceneId = sceneId;
246
+ }
247
+ if (data) {
248
+ event.data = data;
249
+ }
250
+ event.summary = renderSummary(broadcast, first, changed, ids, worldData);
251
+ return event;
252
+ }
253
+ function renderSummary(broadcast, first, changed, ids, worldData) {
254
+ const { type, action } = broadcast;
255
+ const name = first && typeof first.name === 'string' ? first.name : undefined;
256
+ if (type === 'ChatMessage' && action === 'create' && first) {
257
+ const speaker = isRecord(first.speaker) ? first.speaker : undefined;
258
+ const alias = speaker && typeof speaker.alias === 'string' ? speaker.alias : undefined;
259
+ const author = alias ?? userName(worldData, messageAuthorId(first) ?? broadcast.userId) ?? 'Unknown';
260
+ const raw = typeof first.content === 'string' ? first.content : '';
261
+ const text = truncate(stripHtml(raw));
262
+ const flavor = typeof first.flavor === 'string' ? truncate(stripHtml(first.flavor)) : '';
263
+ const body = text || flavor || '(no text)';
264
+ return `💬 ${author}: ${body}`;
265
+ }
266
+ if (type === 'Token' && action === 'update' && first) {
267
+ const label = name ?? ids[0] ?? 'unknown';
268
+ if (typeof first.x === 'number' || typeof first.y === 'number') {
269
+ return `🧙 Token ${label} → (${String(first.x ?? '?')}, ${String(first.y ?? '?')})`;
270
+ }
271
+ return `🧙 Token ${label}: ${changed.join(', ') || 'updated'}`;
272
+ }
273
+ if (type === 'Actor' && action === 'update') {
274
+ const label = name ?? actorName(worldData, ids[0]) ?? ids[0] ?? 'unknown';
275
+ return `🎭 Actor ${label}: ${changed.join(', ') || 'updated'}`;
276
+ }
277
+ if (type === 'Combat' && action === 'update' && first) {
278
+ const parts = [];
279
+ if (first.round !== undefined) {
280
+ parts.push(`round ${String(first.round)}`);
281
+ }
282
+ if (first.turn !== undefined) {
283
+ parts.push(`turn ${String(first.turn)}`);
284
+ }
285
+ return `⚔️ Combat ${parts.length > 0 ? parts.join(', ') : changed.join(', ') || 'updated'}`;
286
+ }
287
+ if (type === 'ActiveEffect' && (action === 'create' || action === 'delete')) {
288
+ const label = name ?? ids[0] ?? 'unknown';
289
+ const where = broadcast.parentUuid ?? 'unknown';
290
+ return `✨ Effect ${label} ${action === 'create' ? 'applied to' : 'removed from'} ${where}`;
291
+ }
292
+ if (type === 'Wall' && action === 'update' && first && first.ds !== undefined) {
293
+ return `🚪 Door ${ids[0] ?? 'unknown'} state → ${String(first.ds)}`;
294
+ }
295
+ const label = name ? `${name} (${ids.join(', ')})` : ids.join(', ') || 'unknown';
296
+ return `📄 ${action} ${type} ${label}`;
297
+ }
298
+ //# sourceMappingURL=event-log.js.map