lycheedev 1.2.0 → 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 (118) hide show
  1. package/LICENSE +49 -0
  2. package/README.md +45 -0
  3. package/THIRD_PARTY_NOTICES +812 -0
  4. package/bin/lycheedev.mjs +56 -0
  5. package/native/windows-amd64/lycheedev.exe +0 -0
  6. package/package.json +12 -33
  7. package/payload/addon/Bridge/CaptureWriter.lua +154 -0
  8. package/payload/addon/Bridge/Definitions.lua +3 -0
  9. package/payload/addon/Bridge/Identity.lua +127 -0
  10. package/{vendor/addon/Libs/AutomationQR.lua → payload/addon/Bridge/MatrixSymbol.lua} +23 -30
  11. package/payload/addon/Bridge/ProbeQueue.lua +136 -0
  12. package/payload/addon/Bridge/ProbeRunner.lua +128 -0
  13. package/payload/addon/Bridge/ReceiptView.lua +160 -0
  14. package/payload/addon/Bridge/Reentry.lua +192 -0
  15. package/payload/addon/Bridge/ReportStore.lua +153 -0
  16. package/payload/addon/Bridge/Session.lua +163 -0
  17. package/payload/addon/Clients/Evergreen.lua +2 -0
  18. package/payload/addon/Clients/Live.lua +2 -0
  19. package/payload/addon/Clients/Pandaria.lua +2 -0
  20. package/payload/addon/Clients/Titan.lua +2 -0
  21. package/payload/addon/Core/Compat.lua +59 -0
  22. package/payload/addon/Core/Controls.lua +168 -0
  23. package/{vendor/addon/Core/Bootstrap.lua → payload/addon/Core/Execute.lua} +12 -23
  24. package/{vendor → payload}/addon/Core/Inspector.lua +19 -235
  25. package/{vendor → payload}/addon/Core/Locale.lua +128 -93
  26. package/{vendor → payload}/addon/Core/Locale_enUS.lua +128 -95
  27. package/payload/addon/Core/Persistence.lua +58 -0
  28. package/payload/addon/Core/Platform.lua +58 -0
  29. package/payload/addon/Core/Runtime.lua +25 -0
  30. package/payload/addon/Core/Safety.lua +56 -0
  31. package/{vendor → payload}/addon/Core/Serializer.lua +18 -6
  32. package/payload/addon/Core/Stores.lua +611 -0
  33. package/payload/addon/Lychee Dev_Forever.toc +52 -0
  34. package/payload/addon/Lychee Dev_Mainline.toc +52 -0
  35. package/payload/addon/Lychee Dev_Mists.toc +52 -0
  36. package/payload/addon/Lychee Dev_Wrath.toc +52 -0
  37. package/payload/addon/Modules/AutomationView.lua +393 -0
  38. package/{vendor → payload}/addon/Modules/Diagnostics.lua +92 -36
  39. package/{vendor → payload}/addon/Modules/Events/Catalog.lua +9 -0
  40. package/{vendor → payload}/addon/Modules/Events/Monitor.lua +45 -5
  41. package/payload/addon/Modules/FunctionTrace.lua +150 -0
  42. package/{vendor → payload}/addon/Modules/ObjectInspector.lua +105 -31
  43. package/{vendor → payload}/addon/UI/Export.lua +64 -34
  44. package/{vendor → payload}/addon/UI/Pages/About.lua +26 -14
  45. package/payload/addon/UI/Pages/Automation.lua +446 -0
  46. package/payload/addon/UI/Pages/Diagnostics.lua +402 -0
  47. package/{vendor/addon/UI/Features.lua → payload/addon/UI/Pages/Events.lua} +192 -302
  48. package/{vendor → payload}/addon/UI/Pages/ExportRecords.lua +213 -132
  49. package/{vendor → payload}/addon/UI/Pages/Object.lua +229 -121
  50. package/payload/addon/UI/Pages/Run.lua +423 -0
  51. package/payload/addon/UI/Pages/Trace.lua +314 -0
  52. package/payload/addon/UI/TreeView.lua +246 -0
  53. package/{vendor/addon/UI/MainWindow.lua → payload/addon/UI/Widgets.lua} +89 -529
  54. package/payload/addon/UI/Window.lua +425 -0
  55. package/payload/skill/SKILL.md +87 -0
  56. package/payload/skill/agents/openai.yaml +7 -0
  57. package/payload/skill/references/addon-validation.md +42 -0
  58. package/payload/skill/references/asset-export.md +109 -0
  59. package/payload/skill/references/commands.md +169 -0
  60. package/payload/skill/references/data-investigation.md +242 -0
  61. package/payload/skill/references/error-diagnosis.md +41 -0
  62. package/payload/skill/references/installation.md +18 -0
  63. package/payload/skill/references/live-investigation.md +129 -0
  64. package/payload/skill/references/source-research.md +82 -0
  65. package/payload/skill/scripts/lycheedev.mjs +59 -0
  66. package/release.json +346 -0
  67. package/bin/lycheedev.js +0 -746
  68. package/src/addon.js +0 -95
  69. package/src/config.js +0 -68
  70. package/src/doctor.js +0 -126
  71. package/src/install.js +0 -145
  72. package/src/paths.js +0 -93
  73. package/src/py/instances.py +0 -165
  74. package/src/python.js +0 -111
  75. package/src/skill.js +0 -48
  76. package/src/wow.js +0 -541
  77. package/vendor/addon/Core/Clients/Forever.lua +0 -9
  78. package/vendor/addon/Core/Clients/Mainline.lua +0 -9
  79. package/vendor/addon/Core/Clients/Mists.lua +0 -9
  80. package/vendor/addon/Core/Clients/Titan.lua +0 -9
  81. package/vendor/addon/Core/Compatibility.lua +0 -43
  82. package/vendor/addon/Core/Database.lua +0 -859
  83. package/vendor/addon/Core/Safety.lua +0 -42
  84. package/vendor/addon/Lychee Dev_Forever.toc +0 -44
  85. package/vendor/addon/Lychee Dev_Mainline.toc +0 -44
  86. package/vendor/addon/Lychee Dev_Mists.toc +0 -44
  87. package/vendor/addon/Lychee Dev_Wrath.toc +0 -44
  88. package/vendor/addon/Modules/Automation/Controller.lua +0 -896
  89. package/vendor/addon/Modules/Automation/Reload.lua +0 -101
  90. package/vendor/addon/Modules/Automation/Report.lua +0 -409
  91. package/vendor/addon/Modules/Automation/auto/auto.lua +0 -12
  92. package/vendor/addon/Modules/FunctionTrace.lua +0 -85
  93. package/vendor/addon/UI/AutomationOverlay.lua +0 -253
  94. package/vendor/addon/UI/Pages/Automation.lua +0 -417
  95. package/vendor/addon/UI/Pages/Diagnostics.lua +0 -289
  96. package/vendor/addon/UI/Pages/Trace.lua +0 -165
  97. package/vendor/skill/SKILL.md +0 -44
  98. package/vendor/skill/agents/openai.yaml +0 -4
  99. package/vendor/skill/references/automation.md +0 -130
  100. package/vendor/skill/references/clients.md +0 -51
  101. package/vendor/skill/references/runtime-investigations.md +0 -104
  102. package/vendor/skill/scripts/automation/__init__.py +0 -1
  103. package/vendor/skill/scripts/automation/registry.py +0 -516
  104. package/vendor/skill/scripts/automation/reload.py +0 -121
  105. package/vendor/skill/scripts/automation/saved_variables.py +0 -438
  106. package/vendor/skill/scripts/automation/session.py +0 -207
  107. package/vendor/skill/scripts/automation/windows.py +0 -792
  108. package/vendor/skill/scripts/automation.py +0 -1067
  109. package/vendor/skill/scripts/requirements.txt +0 -13
  110. package/vendor/skill/scripts/selftest_offline.py +0 -1061
  111. package/vendor/skill/scripts/test_input_safety.py +0 -132
  112. package/vendor/skill/scripts/test_reload.py +0 -120
  113. /package/{vendor → payload}/addon/Media/GitHub.png +0 -0
  114. /package/{vendor → payload}/addon/Media/Logo.png +0 -0
  115. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Forever.lua +0 -0
  116. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mainline.lua +0 -0
  117. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mists.lua +0 -0
  118. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Titan.lua +0 -0
package/src/wow.js DELETED
@@ -1,541 +0,0 @@
1
- /** Locate World of Warcraft installations, their builds, and running instances. */
2
-
3
- import { execFileSync } from 'node:child_process';
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
-
8
- import { addonFolderName, exists, isDir } from './paths.js';
9
-
10
- const here = path.dirname(fileURLToPath(import.meta.url));
11
- const instancesScript = path.join(here, 'py', 'instances.py');
12
-
13
- /**
14
- * Locate a Python 3 interpreter.
15
- *
16
- * This lives here instead of `python.js` on purpose: `python.js` only depends
17
- * on `paths.js`, and importing it from here would create a cycle.
18
- */
19
- export function findPythonBin() {
20
- if (process.env.LYCHEEDEV_PYTHON) return process.env.LYCHEEDEV_PYTHON;
21
- const candidates = process.platform === 'win32'
22
- ? ['python', 'python3', 'py']
23
- : ['python3', 'python'];
24
- for (const candidate of candidates) {
25
- try {
26
- const out = execFileSync(candidate, ['-c', 'import sys; print(sys.version_info[0])'], {
27
- encoding: 'utf8', windowsHide: true, timeout: 15000,
28
- });
29
- if (out.trim().startsWith('3')) return candidate;
30
- } catch {
31
- // try the next candidate
32
- }
33
- }
34
- return null;
35
- }
36
-
37
- /**
38
- * Every flavor folder Blizzard ships. `id` is the stable key used by the CLI;
39
- * `folder` is what Blizzard names the directory; `toc` is the addon catalog
40
- * that serves it, or null when the addon does not support that build.
41
- *
42
- * The Titan folder is `_classic_titan_`, which holds client 3.80.2 — the build
43
- * the addon's Wrath TOC targets (Interface 38002). The previous value
44
- * `_classic_arena_` does not exist, so an installed Titan client was silently
45
- * skipped by both `install` and `doctor`.
46
- *
47
- * A folder name is a location, not an identity: the game reuses a test folder
48
- * for whatever is on the test track. `_classic_beta_` currently carries WoW:
49
- * Forever (`1.60.1`) for players on that track, so the folder alone cannot
50
- * decide the product. `resolveProduct` reads the client's own `.flavor.info`
51
- * product code first and falls back to the build version, and only then to the
52
- * folder default recorded here.
53
- */
54
- export const CLIENT_FLAVORS = [
55
- { id: 'retail', folder: '_retail_', label: 'Retail', exe: 'Wow.exe', toc: 'Lychee Dev_Mainline.toc', product: 'wow', buildPrefix: null },
56
- { id: 'classic', folder: '_classic_', label: 'Classic', exe: 'WowClassic.exe', toc: 'Lychee Dev_Mists.toc', product: 'wow_classic', buildPrefix: null },
57
- { id: 'titan', folder: '_classic_titan_', label: 'Classic Titan', exe: 'WowClassic.exe', toc: 'Lychee Dev_Wrath.toc', product: 'wow_classic_titan', buildPrefix: null },
58
- // The Forever test track. Listed for both layouts so either one is detected.
59
- { id: 'forever', folder: '_classic_beta_', label: 'Forever', exe: 'WowClassic.exe', toc: 'Lychee Dev_Forever.toc', product: 'wow_forever', buildPrefix: '1.60.' },
60
- { id: 'forever', folder: '_forever_', label: 'Forever', exe: 'WowClassic.exe', toc: 'Lychee Dev_Forever.toc', product: 'wow_forever', buildPrefix: '1.60.' },
61
- // The MoP-era classic test track historically used the same `_classic_beta_`
62
- // folder, so keep it known and explain it instead of hiding the folder.
63
- { id: 'classicBeta', folder: '_classic_beta_', label: 'Classic Beta', exe: 'WowClassic.exe', toc: null, product: 'wow_classic_beta', buildPrefix: '5.5.' },
64
- { id: 'classicEra', folder: '_classic_era_', label: 'Classic Era', exe: 'WowClassic.exe', toc: null, product: 'wow_classic_era', buildPrefix: null },
65
- { id: 'anniversary', folder: '_anniversary_', label: 'Anniversary', exe: 'WowClassic.exe', toc: null, product: 'wow_anniversary', buildPrefix: null },
66
- { id: 'beta', folder: '_beta_', label: 'Beta', exe: 'WowB.exe', toc: null, product: 'wow_beta', buildPrefix: null },
67
- ];
68
-
69
- /** Flavors with an addon catalog, i.e. the builds the addon can install into. */
70
- export function supportedFlavors() {
71
- return CLIENT_FLAVORS.filter((flavor) => flavor.toc);
72
- }
73
-
74
- /**
75
- * The client's own product code, read from the `.flavor.info` file the launcher
76
- * writes next to the executable. It is ground truth for which product a folder
77
- * actually holds, and the only signal that stays correct when Blizzard reuses a
78
- * folder name. Returns null when the file is absent or unreadable.
79
- */
80
- export function readFlavorProduct(flavorDir) {
81
- for (const name of ['.flavor.info', 'flavor.info']) {
82
- const file = path.join(flavorDir, name);
83
- if (!exists(file)) continue;
84
- let text;
85
- try {
86
- text = fs.readFileSync(file, 'utf8');
87
- } catch {
88
- continue;
89
- }
90
- const match = text.match(/\b(wow[a-z0-9_]*)\b/i);
91
- if (match) return match[1].toLowerCase();
92
- }
93
- return null;
94
- }
95
-
96
- /**
97
- * The product a flavor folder actually holds. The client's declared product
98
- * wins; then the build version, because a reused folder still reports its own
99
- * version; then the folder default.
100
- */
101
- export function resolveProduct(flavor, flavorDir, version) {
102
- return readFlavorProduct(flavorDir)
103
- || (version && flavor.buildPrefix && version.startsWith(flavor.buildPrefix) ? flavor.product : null)
104
- || flavor.product;
105
- }
106
-
107
- /**
108
- * Pick the flavor entry that matches a client's real identity: the product, or
109
- * the build when the product is unknown, and only then the folder default.
110
- */
111
- export function flavorForClient({ folder, product = null, version = null }) {
112
- const byFolder = CLIENT_FLAVORS.filter((flavor) => flavor.folder === folder);
113
- if (product) {
114
- const exact = byFolder.find((flavor) => flavor.product === product);
115
- if (exact) return exact;
116
- }
117
- if (version) {
118
- const byBuild = byFolder.find((flavor) => flavor.buildPrefix && version.startsWith(flavor.buildPrefix));
119
- if (byBuild) return byBuild;
120
- }
121
- return byFolder[0] || null;
122
- }
123
-
124
- /** Every folder name the CLI recognises, for error messages and documentation. */
125
- export function knownFolders() {
126
- return [...new Set(CLIENT_FLAVORS.map((flavor) => flavor.folder))];
127
- }
128
-
129
- export function flavorById(id) {
130
- return CLIENT_FLAVORS.find((flavor) => flavor.id === id) || null;
131
- }
132
-
133
- /**
134
- * The first flavor registered for a folder. A folder may have several entries
135
- * (see `_classic_beta_`), so use `flavorForClient` when the client's own
136
- * product or build is known.
137
- */
138
- export function flavorByFolder(folder) {
139
- return CLIENT_FLAVORS.find((flavor) => flavor.folder === folder) || null;
140
- }
141
-
142
- const KNOWN_ROOTS = {
143
- win32: [
144
- 'C:\\Program Files (x86)\\World of Warcraft',
145
- 'C:\\Program Files\\World of Warcraft',
146
- 'D:\\World of Warcraft',
147
- 'D:\\Game\\World of Warcraft',
148
- 'E:\\World of Warcraft',
149
- 'E:\\Game\\World of Warcraft',
150
- ],
151
- darwin: ['/Applications/World of Warcraft'],
152
- linux: [],
153
- };
154
-
155
- function looksLikeWowRoot(dir) {
156
- if (!isDir(dir)) return false;
157
- return CLIENT_FLAVORS.some((flavor) => isDir(path.join(dir, flavor.folder)));
158
- }
159
-
160
- /** Roots on this machine that contain at least one known flavor folder. */
161
- export function detectWowRoots() {
162
- const candidates = [];
163
- const seen = new Set();
164
- const push = (dir) => {
165
- if (!dir || seen.has(dir)) return;
166
- seen.add(dir);
167
- if (looksLikeWowRoot(dir)) candidates.push(dir);
168
- };
169
-
170
- for (const root of KNOWN_ROOTS[process.platform] || []) push(root);
171
- for (const drive of ['C', 'D', 'E', 'F']) {
172
- push(`${drive}:\\World of Warcraft`);
173
- push(`${drive}:\\Game\\World of Warcraft`);
174
- }
175
- return candidates;
176
- }
177
-
178
- /** Client version, read from the executable's own file metadata. */
179
- function exeVersion(exePath) {
180
- try {
181
- const out = execFileSync('powershell', [
182
- '-NoProfile', '-Command',
183
- `(Get-Item -LiteralPath '${exePath.replace(/'/g, "''")}').VersionInfo.FileVersion`,
184
- ], { encoding: 'utf8', windowsHide: true, timeout: 20000 });
185
- const value = out.replace(/^\uFEFF/, '').trim();
186
- return value || null;
187
- } catch {
188
- return null;
189
- }
190
- }
191
-
192
- /**
193
- * Every flavor folder's executable version under one root, in a single call.
194
- *
195
- * The version has to come from the executable's file metadata, which needs
196
- * PowerShell on Windows, and starting it once per client costs about a second on
197
- * a full install. One invocation returns the whole map, so the cost is paid once
198
- * no matter how many clients are present.
199
- */
200
- const FLAVOR_EXE_CANDIDATES = ['Wow.exe', 'WowClassic.exe', 'WowB.exe'];
201
-
202
- export function readExecutableVersions(wowRoot) {
203
- const dirs = [...new Set(CLIENT_FLAVORS.map((flavor) => flavor.folder))];
204
- const script = [
205
- '$ErrorActionPreference = "SilentlyContinue"',
206
- '$root = $env:LYCHEEDEV_VERSIONS_ROOT',
207
- '$names = $env:LYCHEEDEV_VERSIONS_FOLDERS -split ","',
208
- '$exes = @("Wow.exe", "WowClassic.exe", "WowB.exe")',
209
- 'foreach ($name in $names) {',
210
- ' foreach ($exe in $exes) {',
211
- ' $path = Join-Path $root ($name + "\\" + $exe)',
212
- ' if (Test-Path -LiteralPath $path) {',
213
- ' $version = (Get-Item -LiteralPath $path).VersionInfo.FileVersion',
214
- ' Write-Output ($name + "`t" + $version)',
215
- ' break',
216
- ' }',
217
- ' }',
218
- '}',
219
- ].join('\n');
220
-
221
- const versions = new Map();
222
- if (process.platform !== 'win32') return versions;
223
- try {
224
- // The root and folder list travel as environment variables: passing them as
225
- // arguments to `-Command` lets PowerShell reinterpret a Windows path, which
226
- // silently yields an empty map and a much slower per-client fallback.
227
- const out = execFileSync('powershell', [
228
- '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script,
229
- ], {
230
- encoding: 'utf8',
231
- windowsHide: true,
232
- timeout: 60000,
233
- env: {
234
- ...process.env,
235
- LYCHEEDEV_VERSIONS_ROOT: wowRoot,
236
- LYCHEEDEV_VERSIONS_FOLDERS: dirs.join(','),
237
- },
238
- });
239
- for (const line of out.replace(/^\uFEFF/, '').split(/\r?\n/)) {
240
- const [folder, version] = line.split('\t');
241
- if (!folder || !version) continue;
242
- versions.set(folder.trim(), version.trim());
243
- }
244
- } catch {
245
- return versions;
246
- }
247
- return versions;
248
- }
249
-
250
- /**
251
- * Describe every flavor present under a root, including builds the addon does
252
- * not serve, so `doctor` can explain them instead of ignoring them silently.
253
- */
254
- export function scanClients(wowRoot) {
255
- const versions = readExecutableVersions(wowRoot);
256
- const found = [];
257
- const seenDirs = new Set();
258
- for (const flavor of CLIENT_FLAVORS) {
259
- const flavorDir = path.join(wowRoot, flavor.folder);
260
- if (!isDir(flavorDir)) continue;
261
- // Two entries can share one folder; describe that folder only once.
262
- if (seenDirs.has(flavorDir)) continue;
263
- seenDirs.add(flavorDir);
264
-
265
- const addonsDir = path.join(flavorDir, 'Interface', 'AddOns');
266
- const exePath = path.join(flavorDir, flavor.exe);
267
- const hasExe = exists(exePath);
268
- // The batch result is keyed by folder; fall back to a direct read for an
269
- // install whose executable name does not match the recorded one.
270
- const version = versions.get(flavor.folder)
271
- || (hasExe ? exeVersion(exePath) : null);
272
- // Which product this folder really holds decides id, label and catalog.
273
- const product = resolveProduct(flavor, flavorDir, version);
274
- const resolved = flavorForClient({ folder: flavor.folder, product, version }) || flavor;
275
-
276
- found.push({
277
- ...flavor,
278
- ...resolved,
279
- flavorDir,
280
- addonsDir,
281
- addonsDirExists: isDir(addonsDir),
282
- exePath: hasExe ? exePath : null,
283
- version,
284
- folderProduct: product,
285
- installedDir: path.join(addonsDir, addonFolderName),
286
- installed: resolved.toc ? exists(path.join(addonsDir, addonFolderName, resolved.toc)) : false,
287
- });
288
- }
289
- return found;
290
- }
291
-
292
- /** Account-level SavedVariables candidates, newest first. */
293
- export function findSavedVariablesCandidates(wowRoot, flavorFolder) {
294
- const accountsDir = path.join(wowRoot, flavorFolder, 'WTF', 'Account');
295
- if (!isDir(accountsDir)) return [];
296
- const results = [];
297
- for (const account of fs.readdirSync(accountsDir, { withFileTypes: true })) {
298
- if (!account.isDirectory()) continue;
299
- const file = path.join(accountsDir, account.name, 'SavedVariables', `${addonFolderName}.lua`);
300
- if (!exists(file)) continue;
301
- let mtime = 0;
302
- try {
303
- mtime = fs.statSync(file).mtimeMs;
304
- } catch {
305
- mtime = 0;
306
- }
307
- results.push({ account: account.name, path: file, mtime });
308
- }
309
- return results.sort((a, b) => b.mtime - a.mtime);
310
- }
311
-
312
- /**
313
- * Running game instances.
314
- *
315
- * Window handles need the Win32 enumeration API, which Node cannot call, so a
316
- * small read-only helper does it: `src/py/instances.py` enumerates visible
317
- * windows and reads process image paths without opening a process.
318
- *
319
- * Blizzard ships every non-retail client as `WowClassic.exe`, so the process
320
- * name cannot identify a build. The executable path narrows it to an install
321
- * folder, but a folder is a location rather than an identity: the helper also
322
- * reports the folder's `.flavor.info` product and `version.txt` build, and
323
- * those decide which client the window actually is.
324
- *
325
- * The answer is memoized for the life of the process. A single command resolves
326
- * the target more than once (once to pick the window, once to forward), and
327
- * re-enumerating would both pay for another interpreter start and risk the two
328
- * lookups disagreeing about which windows exist.
329
- */
330
- let instancesCache = null;
331
-
332
- export function findInstances({ pythonBin = null, refresh = false } = {}) {
333
- if (!refresh && instancesCache !== null) return instancesCache;
334
- instancesCache = enumerateInstances(pythonBin);
335
- return instancesCache;
336
- }
337
-
338
- function enumerateInstances(pythonBin) {
339
- if (process.platform !== 'win32') return [];
340
- const python = pythonBin || findPythonBin();
341
- if (!python || !exists(instancesScript)) return [];
342
-
343
- let rows = [];
344
- try {
345
- const out = execFileSync(python, ['-B', instancesScript], {
346
- encoding: 'utf8',
347
- windowsHide: true,
348
- timeout: 30000,
349
- env: { ...process.env, PYTHONIOENCODING: 'utf-8' },
350
- });
351
- const parsed = JSON.parse(out.replace(/^\uFEFF/, '') || '[]');
352
- rows = Array.isArray(parsed) ? parsed : [parsed];
353
- } catch {
354
- return [];
355
- }
356
-
357
- return rows
358
- .map((row) => {
359
- const resolved = flavorForClient({
360
- folder: row.flavorFolder,
361
- product: row.product || null,
362
- version: row.version || null,
363
- });
364
- return {
365
- ...row,
366
- flavorId: resolved ? resolved.id : row.flavorId,
367
- flavorLabel: resolved ? resolved.label : row.flavorLabel,
368
- supported: Boolean(resolved && resolved.toc),
369
- };
370
- })
371
- .sort((a, b) => (a.flavorId || '').localeCompare(b.flavorId || '') || a.pid - b.pid);
372
- }
373
-
374
- /**
375
- * Choose which running instance a command targets.
376
- *
377
- * One instance needs no flag. Several instances of different builds are picked
378
- * with `--client`. Several instances of the *same* build are genuinely
379
- * ambiguous, so the caller must pass `--instance <index>` after seeing the
380
- * table; guessing would type into the wrong game window.
381
- */
382
- export function resolveInstance(instances, { clientId = null, index = null } = {}) {
383
- const supported = instances.filter((item) => item.supported);
384
- if (supported.length === 0) {
385
- return { error: 'no supported World of Warcraft instance is running' };
386
- }
387
- if (index !== null && index !== undefined) {
388
- const chosen = supported[Number(index)];
389
- if (!chosen) {
390
- return { error: `--instance ${index} is out of range (0..${supported.length - 1})` };
391
- }
392
- return { instance: chosen };
393
- }
394
- const candidates = clientId ? supported.filter((item) => item.flavorId === clientId) : supported;
395
- if (candidates.length === 0) {
396
- return { error: `no running instance for client '${clientId}'` };
397
- }
398
- if (candidates.length === 1) {
399
- return { instance: candidates[0] };
400
- }
401
- return {
402
- error: `${candidates.length} instances match; pass --instance <index>`,
403
- candidates,
404
- };
405
- }
406
-
407
- /**
408
- * Find the instance a saved pin refers to.
409
- *
410
- * A pin stores the build plus which instance of that build, because window
411
- * handles and pids change every launch. The number shown to the user counts
412
- * among supported instances, so the same index works here.
413
- */
414
- export function matchPinned(instances, pin) {
415
- if (!pin || !pin.flavor) return null;
416
- const supported = instances.filter((item) => item.supported);
417
- const ofFlavor = supported.filter((item) => item.flavorId === pin.flavor);
418
- if (ofFlavor.length === 0) return null;
419
- // A pin taken while the windows carried identity markers names the character,
420
- // which survives the window being closed and reopened far better than an
421
- // ordinal does. Fall back to the ordinal for pins saved before identity was
422
- // available, and for builds whose windows show no marker.
423
- if (pin.character) {
424
- const named = ofFlavor.filter((item) => identityKey(item) === pin.character);
425
- if (named.length === 1) return named[0];
426
- }
427
- return ofFlavor[pin.ordinal || 0] || ofFlavor[0];
428
- }
429
-
430
- export function formatInstance(instance, index) {
431
- const flavor = instance.flavorLabel || instance.flavorFolder || 'unknown';
432
- const suffix = instance.supported ? '' : ' (the addon does not serve this build)';
433
- const hwnd = instance.hwnd ? `0x${instance.hwnd.toString(16)}` : '-';
434
- const version = instance.version ? ` v${instance.version}` : '';
435
- const title = instance.title ? ` "${instance.title}"` : '';
436
- const line = ` [${index}] ${flavor.padEnd(14)} pid=${String(instance.pid).padEnd(8)} `
437
- + `hwnd=${hwnd.padEnd(12)}${version}${title}${suffix}`;
438
- // Identity comes from the in-game marker when the caller asked for it; it is
439
- // the only thing that says which character is behind the window.
440
- const identity = instance.identity;
441
- if (!identity) return line;
442
- const name = identity.realm ? `${identity.id}-${identity.realm}` : identity.id;
443
- return `${line}\n character: ${name}`
444
- + `${identity.client ? ` client: ${identity.client}` : ''}`
445
- + `${identity.build ? ` build: ${identity.build}` : ''}`;
446
- }
447
-
448
- /**
449
- * A stable key for the character a window reports, or null when it reported none.
450
- *
451
- * The identity marker is the only thing that says which character is behind a
452
- * window, so it is what makes two same-build windows distinguishable. Realm is
453
- * part of the key because two realms can carry a character with the same name.
454
- */
455
- export function identityKey(instance) {
456
- const identity = instance && instance.identity;
457
- if (!identity || !identity.id) return null;
458
- return `${identity.id}\u0000${identity.realm || ''}`;
459
- }
460
-
461
- /** The `character-realm` label shown to the user, or null without a marker. */
462
- export function identityLabel(instance) {
463
- const identity = instance && instance.identity;
464
- if (!identity || !identity.id) return null;
465
- return identity.realm ? `${identity.id}-${identity.realm}` : identity.id;
466
- }
467
-
468
- /**
469
- * Decide whether several running instances can be told apart.
470
- *
471
- * Different builds are safe: the install path identifies them, so `--client`
472
- * picks one. Several windows of the *same* build are only a problem when they
473
- * cannot be named: if each window shows an identity marker with a distinct
474
- * character, the user can choose one by name. Identical characters — or windows
475
- * that showed no marker — remain genuinely indistinguishable, and pinning an
476
- * ordinal there would only look precise while risking a command in the wrong
477
- * game, so the caller still asks for one window.
478
- */
479
- export function describeAmbiguity(instances) {
480
- const supported = instances.filter((item) => item.supported);
481
- const byBuild = new Map();
482
- for (const instance of supported) {
483
- if (!byBuild.has(instance.flavorId)) byBuild.set(instance.flavorId, []);
484
- byBuild.get(instance.flavorId).push(instance);
485
- }
486
- const duplicates = [...byBuild.entries()].filter(([, list]) => list.length > 1);
487
-
488
- // Within each colliding build, group the windows by the character they report.
489
- // Every window without a marker shares one anonymous group: a pid is not
490
- // something the user can recognise or confirm, so two unmarked windows of one
491
- // build must stay ambiguous rather than looking separable.
492
- const collisions = [];
493
- for (const [flavorId, list] of duplicates) {
494
- const byCharacter = new Map();
495
- for (const instance of list) {
496
- const key = identityKey(instance) || '\u0000anonymous';
497
- if (!byCharacter.has(key)) byCharacter.set(key, []);
498
- byCharacter.get(key).push(instance);
499
- }
500
- const sameCharacter = [...byCharacter.values()].filter((group) => group.length > 1);
501
- collisions.push({ flavorId, instances: list, byCharacter, sameCharacter });
502
- }
503
-
504
- return {
505
- supported,
506
- duplicates,
507
- collisions,
508
- // Several builds open: picking one is unambiguous.
509
- multipleBuilds: byBuild.size > 1,
510
- // Same build, but every window carries its own character: the user can pick.
511
- sameBuildNamed: collisions.some((entry) => entry.sameCharacter.length === 0
512
- && entry.byCharacter.size > 1),
513
- // Same build and no way to separate them: still ask for a single window.
514
- sameBuildCollision: collisions.some((entry) => entry.sameCharacter.length > 0),
515
- };
516
- }
517
-
518
- /**
519
- * Resolve the character a user named to the window that reports it.
520
- *
521
- * Accepts `Name-Realm` or a bare `Name`. A bare name that matches several
522
- * windows is ambiguous and returns the candidates instead of guessing.
523
- */
524
- export function matchIdentity(instances, query) {
525
- const wanted = String(query || '').trim().toLowerCase();
526
- if (!wanted) return { error: 'no character name given' };
527
- const supported = instances.filter((item) => item.supported);
528
- const matches = supported.filter((instance) => {
529
- const label = identityLabel(instance);
530
- if (!label) return false;
531
- const lower = label.toLowerCase();
532
- return lower === wanted || lower.split('-')[0] === wanted;
533
- });
534
- if (matches.length === 0) {
535
- return { error: `no running window reports the character '${query}'`, candidates: supported };
536
- }
537
- if (matches.length > 1) {
538
- return { error: `${matches.length} windows report '${query}'; use Name-Realm`, candidates: matches };
539
- }
540
- return { instance: matches[0] };
541
- }
@@ -1,9 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- ns.Client = {
4
- id = "forever",
5
- name = "Forever",
6
- flavor = "Forever",
7
- interface = 16001,
8
- baseline = "1.60.1",
9
- }
@@ -1,9 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- ns.Client = {
4
- id = "retail",
5
- name = "Retail",
6
- flavor = "Mainline",
7
- interface = 120100,
8
- baseline = "12.1.0",
9
- }
@@ -1,9 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- ns.Client = {
4
- id = "classic",
5
- name = "Classic",
6
- flavor = "Mists",
7
- interface = 50504,
8
- baseline = "5.5.4",
9
- }
@@ -1,9 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- ns.Client = {
4
- id = "titan",
5
- name = "Classic Titan",
6
- flavor = "Titan",
7
- interface = 38002,
8
- baseline = "3.80.2",
9
- }
@@ -1,43 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local client = assert(ns.Client, "Lychee Dev client profile must load first")
4
-
5
- function client.GetAddOnMetadata(addon, field)
6
- return C_AddOns.GetAddOnMetadata(addon, field)
7
- end
8
-
9
- function client.GetMouseFocus()
10
- local foci = GetMouseFoci()
11
- if issecretvalue(foci) or type(foci) ~= "table" or not foci[1]
12
- or issecretvalue(foci[1]) then
13
- return nil
14
- end
15
- return foci[1]
16
- end
17
-
18
- -- UI units per physical screen pixel, for screen-space overlays such as the
19
- -- automation status blocks and QR notice. GetPhysicalScreenSize was verified on
20
- -- the Retail 12.1.0 baseline only; other clients use the legacy 768-height
21
- -- approximation until verified.
22
- function client.GetPhysicalPixelSize()
23
- if GetPhysicalScreenSize then
24
- local succeeded, width, height = pcall(GetPhysicalScreenSize)
25
- if succeeded and not (issecretvalue and (issecretvalue(width) or issecretvalue(height)))
26
- and width and width > 0 and GetScreenWidth then
27
- local uiWidth = GetScreenWidth()
28
- if uiWidth and uiWidth > 0 and not (issecretvalue and issecretvalue(uiWidth)) then
29
- return uiWidth / width
30
- end
31
- end
32
- end
33
- -- Fallback for clients without a verified GetPhysicalScreenSize: the legacy
34
- -- 768-height approximation treats the screen as 768 physical pixels tall,
35
- -- so one physical pixel spans (uiHeight / 768) UI units. The inverse,
36
- -- 768 / uiHeight, would shrink the 4x4 physical-pixel status blocks below
37
- -- their specified minimum on tall UIs.
38
- local uiHeight = GetScreenHeight and GetScreenHeight() or nil
39
- if uiHeight and uiHeight > 0 and not (issecretvalue and issecretvalue(uiHeight)) then
40
- return uiHeight / 768
41
- end
42
- return 1
43
- end