@g33ks/foundryvtt-mcp 0.0.0-stage → 2.0.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 (96) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +468 -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 +410 -0
  7. package/dist/cli/prompt.js +117 -0
  8. package/dist/cli/snippets.js +49 -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 +415 -0
  14. package/dist/diagnostics/client.js +353 -0
  15. package/dist/diagnostics/types.js +94 -0
  16. package/dist/foundry/auth.js +220 -0
  17. package/dist/foundry/browser-detect.js +170 -0
  18. package/dist/foundry/client.js +5555 -0
  19. package/dist/foundry/dice-formula.js +154 -0
  20. package/dist/foundry/event-log.js +299 -0
  21. package/dist/foundry/headless-gm-session.js +740 -0
  22. package/dist/foundry/journal-history.js +90 -0
  23. package/dist/foundry/journal-integrity.js +306 -0
  24. package/dist/foundry/module-bridge.js +413 -0
  25. package/dist/foundry/types.js +52 -0
  26. package/dist/foundry/world-cache.js +386 -0
  27. package/dist/index.js +107 -0
  28. package/dist/mcp-server.js +63 -0
  29. package/dist/server.js +159 -0
  30. package/dist/shared/build-order.js +134 -0
  31. package/dist/shared/config-hash.js +62 -0
  32. package/dist/shared/config-notice.js +55 -0
  33. package/dist/shared/control.js +255 -0
  34. package/dist/shared/daemon-link.js +135 -0
  35. package/dist/shared/daemon.js +313 -0
  36. package/dist/shared/ipc-client.js +200 -0
  37. package/dist/shared/ipc-server.js +316 -0
  38. package/dist/shared/paths.js +79 -0
  39. package/dist/shared/protocol.js +230 -0
  40. package/dist/shared/relay-config.js +65 -0
  41. package/dist/shared/relay.js +120 -0
  42. package/dist/shared/rotating-log.js +57 -0
  43. package/dist/shared/spawn.js +39 -0
  44. package/dist/shared/state-file.js +33 -0
  45. package/dist/shared/token.js +62 -0
  46. package/dist/shared/version.js +57 -0
  47. package/dist/tools/base.js +74 -0
  48. package/dist/tools/definitions.js +3109 -0
  49. package/dist/tools/handlers/actor-mutations.js +128 -0
  50. package/dist/tools/handlers/actors.js +114 -0
  51. package/dist/tools/handlers/chat-mutations.js +49 -0
  52. package/dist/tools/handlers/chat.js +36 -0
  53. package/dist/tools/handlers/combat-mutations.js +215 -0
  54. package/dist/tools/handlers/combat-order.js +94 -0
  55. package/dist/tools/handlers/combat.js +51 -0
  56. package/dist/tools/handlers/compendium.js +83 -0
  57. package/dist/tools/handlers/diagnostics.js +438 -0
  58. package/dist/tools/handlers/dice.js +54 -0
  59. package/dist/tools/handlers/effects.js +103 -0
  60. package/dist/tools/handlers/events.js +50 -0
  61. package/dist/tools/handlers/generation.js +258 -0
  62. package/dist/tools/handlers/item-mutations.js +132 -0
  63. package/dist/tools/handlers/items.js +53 -0
  64. package/dist/tools/handlers/journal-mutations.js +230 -0
  65. package/dist/tools/handlers/journals.js +80 -0
  66. package/dist/tools/handlers/module-bridge.js +421 -0
  67. package/dist/tools/handlers/placeable-mutations.js +272 -0
  68. package/dist/tools/handlers/resources.js +203 -0
  69. package/dist/tools/handlers/roll-tables.js +97 -0
  70. package/dist/tools/handlers/scene-mutations.js +159 -0
  71. package/dist/tools/handlers/scenes.js +355 -0
  72. package/dist/tools/handlers/settings.js +53 -0
  73. package/dist/tools/handlers/tile-mutations.js +56 -0
  74. package/dist/tools/handlers/token-mutations.js +356 -0
  75. package/dist/tools/handlers/users.js +59 -0
  76. package/dist/tools/handlers/utils.js +47 -0
  77. package/dist/tools/handlers/wall-mutations.js +98 -0
  78. package/dist/tools/handlers/world-documents.js +222 -0
  79. package/dist/tools/handlers/world.js +92 -0
  80. package/dist/tools/index.js +25 -0
  81. package/dist/tools/new-router.js +97 -0
  82. package/dist/tools/registry.js +79 -0
  83. package/dist/tools/resources.js +63 -0
  84. package/dist/tools/router.js +688 -0
  85. package/dist/tools/write-tools.js +97 -0
  86. package/dist/utils/cache-instance.js +30 -0
  87. package/dist/utils/cache.js +205 -0
  88. package/dist/utils/diagnostics.js +332 -0
  89. package/dist/utils/guards.js +17 -0
  90. package/dist/utils/image-size.js +160 -0
  91. package/dist/utils/log-args.js +47 -0
  92. package/dist/utils/logger.js +203 -0
  93. package/dist/utils/refusal.js +30 -0
  94. package/dist/utils/sanitize.js +22 -0
  95. package/dist/utils/serial-queue.js +22 -0
  96. package/package.json +124 -4
@@ -0,0 +1,170 @@
1
+ /**
2
+ * @fileoverview Finds a Chromium-based browser for the headless GM session.
3
+ *
4
+ * Known install locations per system, checked on disk, in this order:
5
+ * Chrome, Edge, Brave, Vivaldi, a system Chromium, then Playwright's own
6
+ * Chromium. The browser is then launched by its executable path, never by a
7
+ * Playwright channel: channels build their Windows paths from environment
8
+ * variables that an MCP client may not pass on (Claude desktop forwards an
9
+ * allowlist without `ProgramFiles(x86)`), so the Windows prefixes here also
10
+ * fall back on `SYSTEMDRIVE` and on hard-coded `C:\` paths.
11
+ *
12
+ * Pure apart from the default `exists`: tests pass a simulated file system.
13
+ */
14
+ import { statSync } from 'node:fs';
15
+ import path from 'node:path';
16
+ /** Install advice when nothing was found. */
17
+ export const NO_BROWSER_ADVICE = 'Install Google Chrome, Microsoft Edge or Brave, or set FOUNDRY_HEADLESS_GM_EXECUTABLE_PATH ' +
18
+ 'to the executable of a Chromium-based browser.';
19
+ const PLAYWRIGHT_CHROMIUM = "Playwright's Chromium";
20
+ function fileExists(file) {
21
+ try {
22
+ return statSync(file).isFile();
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ /** `env[name]` ignoring case, as Windows does (a plain object does not). */
29
+ function envValue(env, name) {
30
+ const key = Object.keys(env).find((k) => k.toLowerCase() === name.toLowerCase());
31
+ const value = key !== undefined ? env[key] : undefined;
32
+ return value ? value : undefined;
33
+ }
34
+ function unique(paths, caseInsensitive) {
35
+ const seen = new Set();
36
+ return paths.filter((p) => {
37
+ const key = caseInsensitive ? p.toLowerCase() : p;
38
+ if (seen.has(key)) {
39
+ return false;
40
+ }
41
+ seen.add(key);
42
+ return true;
43
+ });
44
+ }
45
+ /** Directories that may hold `Vendor\Product\Application\x.exe`, machine-wide first. */
46
+ function windowsPrefixes(env) {
47
+ const join = path.win32.join;
48
+ const drive = envValue(env, 'SYSTEMDRIVE') ?? envValue(env, 'HOMEDRIVE');
49
+ const profile = envValue(env, 'USERPROFILE');
50
+ const candidates = [
51
+ envValue(env, 'PROGRAMFILES'),
52
+ envValue(env, 'PROGRAMFILES(X86)'),
53
+ envValue(env, 'LOCALAPPDATA'),
54
+ drive ? join(`${drive}\\`, 'Program Files') : undefined,
55
+ drive ? join(`${drive}\\`, 'Program Files (x86)') : undefined,
56
+ profile ? join(profile, 'AppData', 'Local') : undefined,
57
+ 'C:\\Program Files',
58
+ 'C:\\Program Files (x86)',
59
+ ];
60
+ return unique(candidates.filter((p) => p !== undefined), true);
61
+ }
62
+ const WINDOWS_SUFFIXES = [
63
+ ['Chrome', 'Google\\Chrome\\Application\\chrome.exe'],
64
+ ['Edge', 'Microsoft\\Edge\\Application\\msedge.exe'],
65
+ ['Brave', 'BraveSoftware\\Brave-Browser\\Application\\brave.exe'],
66
+ ['Vivaldi', 'Vivaldi\\Application\\vivaldi.exe'],
67
+ ['Chromium', 'Chromium\\Application\\chrome.exe'],
68
+ ];
69
+ const MAC_APPS = [
70
+ ['Chrome', 'Google Chrome.app/Contents/MacOS/Google Chrome'],
71
+ ['Edge', 'Microsoft Edge.app/Contents/MacOS/Microsoft Edge'],
72
+ ['Brave', 'Brave Browser.app/Contents/MacOS/Brave Browser'],
73
+ ['Vivaldi', 'Vivaldi.app/Contents/MacOS/Vivaldi'],
74
+ ['Chromium', 'Chromium.app/Contents/MacOS/Chromium'],
75
+ ];
76
+ /** Fixed paths first, then commands looked up on PATH (and the usual bin dirs). */
77
+ const LINUX_LOCATIONS = [
78
+ ['Chrome', ['/opt/google/chrome/chrome'], ['google-chrome-stable', 'google-chrome']],
79
+ ['Edge', ['/opt/microsoft/msedge/msedge'], ['microsoft-edge-stable', 'microsoft-edge']],
80
+ ['Brave', ['/opt/brave.com/brave/brave'], ['brave-browser', 'brave']],
81
+ ['Vivaldi', ['/opt/vivaldi/vivaldi'], ['vivaldi-stable', 'vivaldi']],
82
+ [
83
+ 'Chromium',
84
+ ['/usr/lib/chromium/chromium', '/usr/lib/chromium-browser/chromium-browser'],
85
+ ['chromium', 'chromium-browser'],
86
+ ],
87
+ ];
88
+ function candidatesFor(platform, env, homedir) {
89
+ if (platform === 'win32') {
90
+ const prefixes = windowsPrefixes(env);
91
+ return WINDOWS_SUFFIXES.flatMap(([name, suffix]) => prefixes.map((prefix) => [name, path.win32.join(prefix, suffix)]));
92
+ }
93
+ if (platform === 'darwin') {
94
+ const roots = ['/Applications', ...(homedir ? [path.posix.join(homedir, 'Applications')] : [])];
95
+ return MAC_APPS.flatMap(([name, app]) => roots.map((root) => [name, path.posix.join(root, app)]));
96
+ }
97
+ const pathDirs = unique([
98
+ ...(envValue(env, 'PATH') ?? '').split(':').filter(Boolean),
99
+ '/usr/bin',
100
+ '/usr/local/bin',
101
+ '/snap/bin',
102
+ ], false);
103
+ return LINUX_LOCATIONS.flatMap(([name, fixed, commands]) => [
104
+ ...fixed.map((p) => [name, p]),
105
+ ...commands.flatMap((command) => pathDirs.map((dir) => [name, path.posix.join(dir, command)])),
106
+ ]);
107
+ }
108
+ /** Every Chromium-based browser present, in preference order, and every path checked. */
109
+ export function findBrowsers(options = {}) {
110
+ const platform = options.platform ?? process.platform;
111
+ const env = options.env ?? process.env;
112
+ const exists = options.exists ?? fileExists;
113
+ const candidates = candidatesFor(platform, env, options.homedir);
114
+ if (options.playwrightPath) {
115
+ candidates.push([PLAYWRIGHT_CHROMIUM, options.playwrightPath]);
116
+ }
117
+ const found = [];
118
+ const tried = [];
119
+ const seenNames = new Set();
120
+ const seenPaths = new Set();
121
+ for (const [name, file] of candidates) {
122
+ const key = platform === 'win32' ? file.toLowerCase() : file;
123
+ if (seenPaths.has(key)) {
124
+ continue;
125
+ }
126
+ seenPaths.add(key);
127
+ tried.push(file);
128
+ // One location per browser: the first is the one that would run.
129
+ if (!seenNames.has(name) && exists(file)) {
130
+ found.push({ name, path: file });
131
+ seenNames.add(name);
132
+ }
133
+ }
134
+ return { found, tried };
135
+ }
136
+ /** Error text when no browser is installed at any known location. */
137
+ export function noBrowserMessage(tried) {
138
+ return [
139
+ `No browser found for the headless GM session. ${NO_BROWSER_ADVICE}`,
140
+ 'Without this session the companion module cannot connect to the bridge.',
141
+ `Locations tried: ${tried.join('; ')}`,
142
+ ].join(' ');
143
+ }
144
+ /** Name of the browser an explicit path points to, from its file name. */
145
+ export function browserNameFromPath(file) {
146
+ const base = (file.split(/[\\/]/).pop() ?? '').toLowerCase().replace(/\.exe$/, '');
147
+ if (base.startsWith('brave')) {
148
+ return 'Brave';
149
+ }
150
+ if (base.startsWith('msedge') ||
151
+ base.startsWith('microsoft edge') ||
152
+ base.startsWith('microsoft-edge')) {
153
+ return 'Edge';
154
+ }
155
+ if (base.startsWith('vivaldi')) {
156
+ return 'Vivaldi';
157
+ }
158
+ if (base.startsWith('chromium') || (base === 'chrome' && /chromium|ms-playwright/i.test(file))) {
159
+ return 'Chromium';
160
+ }
161
+ if (base === 'chrome' || base.startsWith('google chrome') || base.startsWith('google-chrome')) {
162
+ return 'Chrome';
163
+ }
164
+ return 'Browser';
165
+ }
166
+ /** e.g. `Brave — C:\…\brave.exe (detected)`. */
167
+ export function describeBrowser(choice) {
168
+ return `${choice.name} — ${choice.path} (${choice.origin})`;
169
+ }
170
+ //# sourceMappingURL=browser-detect.js.map