lycheedev 1.1.1 → 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 (115) 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 +129 -94
  26. package/{vendor → payload}/addon/Core/Locale_enUS.lua +129 -96
  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 -742
  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 -43
  85. package/vendor/addon/Lychee Dev_Mainline.toc +0 -43
  86. package/vendor/addon/Lychee Dev_Mists.toc +0 -43
  87. package/vendor/addon/Lychee Dev_Wrath.toc +0 -43
  88. package/vendor/addon/Modules/Automation/Controller.lua +0 -884
  89. package/vendor/addon/Modules/Automation/Report.lua +0 -409
  90. package/vendor/addon/Modules/Automation/auto/auto.lua +0 -12
  91. package/vendor/addon/Modules/FunctionTrace.lua +0 -85
  92. package/vendor/addon/UI/AutomationOverlay.lua +0 -253
  93. package/vendor/addon/UI/Pages/Automation.lua +0 -417
  94. package/vendor/addon/UI/Pages/Diagnostics.lua +0 -289
  95. package/vendor/addon/UI/Pages/Trace.lua +0 -165
  96. package/vendor/skill/SKILL.md +0 -42
  97. package/vendor/skill/agents/openai.yaml +0 -4
  98. package/vendor/skill/references/automation.md +0 -128
  99. package/vendor/skill/references/clients.md +0 -51
  100. package/vendor/skill/references/runtime-investigations.md +0 -104
  101. package/vendor/skill/scripts/automation/__init__.py +0 -1
  102. package/vendor/skill/scripts/automation/registry.py +0 -516
  103. package/vendor/skill/scripts/automation/saved_variables.py +0 -438
  104. package/vendor/skill/scripts/automation/session.py +0 -207
  105. package/vendor/skill/scripts/automation/windows.py +0 -792
  106. package/vendor/skill/scripts/automation.py +0 -1034
  107. package/vendor/skill/scripts/requirements.txt +0 -13
  108. package/vendor/skill/scripts/selftest_offline.py +0 -1061
  109. package/vendor/skill/scripts/test_input_safety.py +0 -132
  110. /package/{vendor → payload}/addon/Media/GitHub.png +0 -0
  111. /package/{vendor → payload}/addon/Media/Logo.png +0 -0
  112. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Forever.lua +0 -0
  113. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mainline.lua +0 -0
  114. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mists.lua +0 -0
  115. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Titan.lua +0 -0
package/bin/lycheedev.js DELETED
@@ -1,742 +0,0 @@
1
- #!/usr/bin/env node
2
- /** lycheedev command line entry. */
3
-
4
- import { readFileSync } from 'node:fs';
5
- import fs from 'node:fs';
6
- import os from 'node:os';
7
- import path from 'node:path';
8
- import { randomBytes } from 'node:crypto';
9
-
10
- import { runDoctor } from '../src/doctor.js';
11
- import { runInstall } from '../src/install.js';
12
- import { loadConfig, updateConfig } from '../src/config.js';
13
- import { runAutomation } from '../src/python.js';
14
- import {
15
- describeAmbiguity,
16
- findInstances,
17
- findSavedVariablesCandidates,
18
- formatInstance,
19
- identityKey,
20
- identityLabel,
21
- matchIdentity,
22
- matchPinned,
23
- resolveInstance,
24
- scanClients,
25
- } from '../src/wow.js';
26
- import { addonFolderName, exists } from '../src/paths.js';
27
-
28
- const HELP = `lycheedev - Lychee Dev installer and World of Warcraft automation driver
29
-
30
- usage: lycheedev <command> [options]
31
-
32
- commands
33
- install install python dependencies, the skill and the addon
34
- update refresh dependencies, skill and addon to this version
35
- doctor report what is installed and what is missing
36
- clients list every detected build and its addon state
37
- instances list running game clients (build, pid, window)
38
- instances --identify also read each window's character and build marker
39
- use [index] pin one running client as the default target
40
- use --character <n> pin the window that reports character <n>
41
- use --clear drop the pin
42
- send <text> type one slash command into the running game
43
- capture poll the game window and decode the completion notice
44
- run --task <id> deliver, decode, reload once and read the result ticket
45
- bugs --count <n> snapshot recent errors and read the result ticket
46
- ack --ticket <t> report that a ticket was read (received|failed)
47
- task <sub> manage the in-game task registry (upsert/list/remove)
48
- sv <sub> discover SavedVariables and read a ticket (find/read)
49
- profile <sub> bind a client install for direct automation.py use
50
- status summarize the local session log
51
- recover show reload intents that were never confirmed
52
-
53
- options
54
- --wow-root <path> folder that contains _retail_/_classic_/_classic_titan_
55
- --client <id> retail | classic | titan | forever (default: the configured one)
56
- --instance <index> which running client to target when several are open
57
- --character <name> target the window reporting that character (Name or Name-Realm)
58
- --identify also read each window's character marker (instances, use)
59
- --hwnd <handle> target one window directly, skipping instance lookup
60
- --pid <pid> expected process id for the target window
61
- --python <bin> python interpreter to use
62
- --force redo work that is already present
63
- --reset-registry install the addon with an empty task registry
64
- --json machine-readable output where supported
65
- -h, --help show this help
66
- -v, --version show the version
67
-
68
- Every non-retail client runs as WowClassic.exe, so a running client is matched
69
- by its install path, not its process name. A folder is only a location: the CLI
70
- also reads each client's own .flavor.info product code and version.txt build, so
71
- a reused test folder (such as _classic_beta_ carrying WoW: Forever) is still
72
- identified correctly. With several clients open, run "lycheedev instances" then
73
- "lycheedev use <index>" to pin one as the target; the pin stores the build, so it
74
- survives a restart even though the pid and window handle change. Pass
75
- --instance <index> to override it for one command.
76
-
77
- When several windows share one build, they are told apart by the character each
78
- window reports: run "/dev auto identify" in each game window, then
79
- "lycheedev instances --identify" to read them, and pin by name with
80
- "lycheedev use --character <name>". Windows that report the same character, or
81
- that show no marker, remain ambiguous and the CLI asks for one window to be
82
- closed rather than risking a command in the wrong game.
83
-
84
- The automation subcommands are thin wrappers over the bundled python helper, so
85
- the same arguments it accepts are forwarded unchanged.`;
86
-
87
- const SHORT_FLAGS = { '-h': 'help', '-v': 'version' };
88
-
89
- function parse(argv) {
90
- const flags = {};
91
- const rest = [];
92
- for (let index = 0; index < argv.length; index += 1) {
93
- const token = argv[index];
94
- if (token === '--') {
95
- rest.push(...argv.slice(index + 1));
96
- break;
97
- }
98
- if (SHORT_FLAGS[token]) {
99
- flags[SHORT_FLAGS[token]] = true;
100
- continue;
101
- }
102
- if (token.startsWith('--')) {
103
- const [name, inline] = token.slice(2).split('=');
104
- if (inline !== undefined) {
105
- flags[name] = inline;
106
- } else if (argv[index + 1] && !argv[index + 1].startsWith('-')) {
107
- flags[name] = argv[index + 1];
108
- index += 1;
109
- } else {
110
- flags[name] = true;
111
- }
112
- continue;
113
- }
114
- rest.push(token);
115
- }
116
- return { flags, rest };
117
- }
118
-
119
- /** hwnd/pid/exe-path derived from config so the automation commands line up. */
120
- function targetArgs(client) {
121
- const args = [];
122
- if (client && client.hwnd) args.push('--hwnd', String(client.hwnd));
123
- if (client && client.pid) args.push('--pid', String(client.pid));
124
- const exePath = client?.exePath || client?.instance?.exePath;
125
- if (exePath) args.push('--exe-path', exePath);
126
- return args;
127
- }
128
-
129
- function requireClient(flags) {
130
- const config = loadConfig();
131
- const ids = Object.keys(config.clients);
132
- const requested = flags.client;
133
- if (requested) {
134
- if (!config.clients[requested]) {
135
- console.error(`error: unknown client '${requested}'; known: ${ids.join(', ') || 'none'}`);
136
- return { error: true };
137
- }
138
- return { config, client: config.clients[requested], id: requested };
139
- }
140
- if (ids.length === 0) {
141
- console.error('error: no client configured; run `lycheedev install --wow-root <path>`');
142
- return { error: true };
143
- }
144
- if (ids.length === 1) {
145
- return { config, client: config.clients[ids[0]], id: ids[0] };
146
- }
147
- // Several clients are installed; the one recorded at install time is the
148
- // default so routine commands stay short, and --client overrides it.
149
- const fallback = config.defaultClient;
150
- if (fallback && config.clients[fallback]) {
151
- return { config, client: config.clients[fallback], id: fallback };
152
- }
153
- console.error(`error: several clients configured (${ids.join(', ')}); pass --client <id>`);
154
- return { error: true };
155
- }
156
-
157
- function runClients(flags) {
158
- const config = loadConfig();
159
- const root = flags['wow-root'] || config.wowRoot;
160
- if (!root || !exists(root)) {
161
- console.error('error: no World of Warcraft root; run `lycheedev install --wow-root <path>`');
162
- return 1;
163
- }
164
- console.log(root);
165
- for (const client of scanClients(root)) {
166
- const version = client.version ? `v${client.version}` : 'unknown version';
167
- // The product is the client's own identity; the folder is only where it
168
- // lives, and one folder can serve different products over time.
169
- const product = client.folderProduct && client.folderProduct !== client.product
170
- ? `[${client.folderProduct}] `
171
- : '';
172
- const state = !client.toc
173
- ? 'not served by the addon'
174
- : (client.installed ? 'addon installed' : 'addon missing');
175
- console.log(` ${client.id.padEnd(12)} ${client.folder.padEnd(18)} `
176
- + `${(product + version).padEnd(18)} ${state}`);
177
- }
178
- return 0;
179
- }
180
-
181
- /** `lycheedev instances`: which game clients are running right now. */
182
- function runInstances(flags) {
183
- const config = loadConfig();
184
- let instances = findInstances({ pythonBin: flags.python || null });
185
- if (instances.length === 0) {
186
- console.log('no World of Warcraft instance is running');
187
- return 0;
188
- }
189
-
190
- // `--identify` asks each window to report the character and build it holds.
191
- // Capture reads the window surface directly, so no window needs the
192
- // foreground and nothing is typed into the game.
193
- let identifyNote = null;
194
- if (flags.identify) {
195
- const supported = instances.filter((item) => item.supported);
196
- if (supported.length === 0) {
197
- identifyNote = 'no served build is running, so there is nothing to identify';
198
- } else {
199
- const probed = probeIdentities(supported, flags);
200
- if (probed.error) {
201
- identifyNote = probed.error;
202
- } else {
203
- const byHwnd = new Map(probed.list.map((entry) => [String(entry.hwnd), entry]));
204
- instances = instances.map((instance) => {
205
- const entry = byHwnd.get(String(instance.hwnd));
206
- if (!entry || !entry.identity) return instance;
207
- return { ...instance, identity: entry.identity };
208
- });
209
- const unidentified = probed.list.filter((entry) => !entry.identity);
210
- if (unidentified.length) {
211
- identifyNote = `${unidentified.length} window(s) show no identity marker; `
212
- + 'run `/dev auto identify` in each game window you care about, then retry';
213
- }
214
- }
215
- }
216
- }
217
-
218
- const pinned = matchPinned(instances, config.pinnedInstance);
219
- console.log('running instances:');
220
- instances.forEach((instance, index) => {
221
- console.log(formatInstance(instance, index));
222
- });
223
- const supported = instances.filter((item) => item.supported);
224
- console.log('');
225
- if (pinned) {
226
- const label = pinned.flavorLabel || pinned.flavorFolder;
227
- console.log(`pinned: ${label} (pid ${pinned.pid}), pid ${pinned.pid} - commands target it`);
228
- } else if (config.pinnedInstance) {
229
- console.log('pinned client is not running; run `lycheedev use` to repin');
230
- }
231
- if (supported.length === 0) {
232
- console.log('none of these builds are served by the addon');
233
- } else if (!pinned && supported.length > 1) {
234
- const shape = describeAmbiguity(instances);
235
- if (shape.sameBuildCollision) {
236
- // Do not suggest `use <index>` here: pinning is refused for windows that
237
- // cannot be told apart, so pointing at it would send the user in a circle.
238
- console.log('several clients are running and cannot be told apart: run '
239
- + '`/dev auto identify` in each game window, then `lycheedev use --character <name>`');
240
- } else {
241
- console.log('several clients are running: `lycheedev use <index>` pins one, '
242
- + 'or pass --instance <index> per command');
243
- }
244
- } else if (!pinned) {
245
- console.log('commands target this instance automatically');
246
- }
247
- if (identifyNote) console.log(identifyNote);
248
- return 0;
249
- }
250
-
251
- /**
252
- * Ask the Python helper to read the identity marker from each window.
253
- *
254
- * The instance list is handed over as a file rather than arguments, because
255
- * every field has to survive the trip and a command line is a fragile place to
256
- * put it. The name is unpredictable and the file is created exclusively, so a
257
- * pre-existing file at that path cannot be followed or silently overwritten.
258
- */
259
- function probeIdentities(supported, flags) {
260
- const windowsFile = path.join(os.tmpdir(),
261
- `lycheedev-windows-${process.pid}-${randomBytes(8).toString('hex')}.json`);
262
- try {
263
- fs.writeFileSync(windowsFile, JSON.stringify(supported), { encoding: 'utf8', flag: 'wx' });
264
- const args = ['identify', '--windows-json', windowsFile];
265
- if (flags.timeout) args.push('--timeout', String(flags.timeout));
266
- const result = runAutomation(args, {
267
- pythonBin: flags.python || null,
268
- inherit: false,
269
- });
270
- if (!result.ok) {
271
- return { error: `could not read identity markers: ${result.stderr || 'helper failed'}` };
272
- }
273
- return { list: JSON.parse(result.stdout || '[]') };
274
- } catch (error) {
275
- return { error: `could not read identity markers: ${error.message}` };
276
- } finally {
277
- try {
278
- fs.unlinkSync(windowsFile);
279
- } catch {
280
- // A leftover temp file is harmless.
281
- }
282
- }
283
- }
284
-
285
- /**
286
- * Resolve the live game window a command should type into.
287
- *
288
- * Precedence: an explicit `--hwnd`/`--pid`, then `--instance <index>`, then
289
- * `--character <name>`, then the saved pin, then `--client`, and finally the only
290
- * running instance when there is exactly one. `WowClassic.exe` looks identical
291
- * for every classic build, so an ambiguous choice fails loudly instead of typing
292
- * into the wrong game.
293
- *
294
- * Windows of one build are distinguishable when each reports a different
295
- * character; only windows that report the same character (or no marker at all)
296
- * are genuinely ambiguous, and those still fail loudly.
297
- */
298
- function resolveRuntime(flags) {
299
- if (flags.hwnd || flags.pid) {
300
- return { hwnd: flags.hwnd, pid: flags.pid };
301
- }
302
- const instances = findInstances({ pythonBin: flags.python || null });
303
- const supported = instances.filter((item) => item.supported);
304
-
305
- if (flags.instance !== undefined) {
306
- const chosen = supported[Number(flags.instance)];
307
- if (!chosen) {
308
- console.error(`error: --instance ${flags.instance} is out of range (0..${supported.length - 1})`);
309
- supported.forEach((item, index) => console.log(formatInstance(item, index)));
310
- return { error: true };
311
- }
312
- return toTarget(chosen);
313
- }
314
-
315
- if (flags.character) {
316
- // A named character is only findable if the window showed its marker, so
317
- // probe first; this is read-only capture and types nothing.
318
- const named = resolveByCharacter(instances, flags.character, flags);
319
- if (named.error) return { error: true };
320
- return toTarget(named.instance);
321
- }
322
-
323
- if (!flags.client) {
324
- const config = loadConfig();
325
- const pinned = matchPinned(instances, config.pinnedInstance);
326
- if (pinned) {
327
- return toTarget(pinned);
328
- }
329
- if (config.pinnedInstance) {
330
- console.error('error: the pinned client is not running; run `lycheedev use` again '
331
- + 'or pass --instance <index>');
332
- }
333
- }
334
-
335
- const resolved = resolveInstance(instances, { clientId: flags.client || null, index: null });
336
- if (resolved.error) {
337
- const shape = describeAmbiguity(instances);
338
- if (shape.sameBuildCollision) {
339
- // Same build and no way to separate the windows: no flag can pick the right
340
- // one reliably, so ask for a single window rather than inviting a wrong guess.
341
- for (const entry of shape.collisions) {
342
- for (const group of entry.sameCharacter) {
343
- const label = group[0].flavorLabel || entry.flavorId;
344
- console.error(`error: ${group.length} ${label} clients report the same character `
345
- + `and cannot be told apart`);
346
- console.error(` close all but one, or close these pids: `
347
- + group.map((i) => i.pid).join(', '));
348
- }
349
- }
350
- if (!shape.sameBuildNamed) {
351
- console.error(' run `/dev auto identify` in each game window, then retry '
352
- + 'with --identify');
353
- }
354
- } else if (supported.length > 1) {
355
- // Several windows of one build, and the caller filtered to that build. They
356
- // may well be separable by character, so say how rather than just failing.
357
- console.error(`error: ${resolved.error}`);
358
- console.error(' if each window shows a different character, run '
359
- + '`/dev auto identify` in each, then pass --character <name>; '
360
- + 'otherwise pass --instance <index>');
361
- } else {
362
- console.error(`error: ${resolved.error}`);
363
- }
364
- if (resolved.candidates) {
365
- resolved.candidates.forEach((item, index) => console.log(formatInstance(item, index)));
366
- }
367
- if (supported.length === 0 && instances.length > 0) {
368
- instances.forEach((item, index) => console.log(formatInstance(item, index)));
369
- }
370
- return { error: true };
371
- }
372
- return toTarget(resolved.instance);
373
- }
374
-
375
- /**
376
- * Find the window reporting a named character, probing the markers first.
377
- *
378
- * Names only exist inside the marker, so read it when the caller has not already
379
- * supplied it. Returns `{ instance }` or `{ error: true }` after explaining why.
380
- */
381
- function resolveByCharacter(instances, query, flags) {
382
- const supported = instances.filter((item) => item.supported);
383
- if (supported.length === 0) {
384
- console.error('error: no served build is running');
385
- return { error: true };
386
- }
387
-
388
- let probed = supported;
389
- if (!supported.some((item) => item.identity)) {
390
- const result = probeIdentities(supported, flags);
391
- if (result.error) {
392
- console.error('error: could not read identity markers; run '
393
- + '`lycheedev instances --identify` after `/dev auto identify` in each game window');
394
- return { error: true };
395
- }
396
- const byHwnd = new Map(result.list.map((entry) => [String(entry.hwnd), entry]));
397
- probed = supported.map((instance) => {
398
- const entry = byHwnd.get(String(instance.hwnd));
399
- return entry && entry.identity ? { ...instance, identity: entry.identity } : instance;
400
- });
401
- }
402
-
403
- const matched = matchIdentity(probed, query);
404
- if (matched.error) {
405
- console.error(`error: ${matched.error}`);
406
- (matched.candidates || probed).forEach((item, index) => console.log(formatInstance(item, index)));
407
- return { error: true };
408
- }
409
- return { instance: matched.instance };
410
- }
411
-
412
- function toTarget(instance) {
413
- return {
414
- hwnd: instance.hwnd ? `0x${instance.hwnd.toString(16)}` : null,
415
- pid: instance.pid ? String(instance.pid) : null,
416
- instance,
417
- };
418
- }
419
-
420
- /**
421
- * `lycheedev use [index|--character <name>]`: keep one running client as the
422
- * default target.
423
- *
424
- * The pin stores the build, the instance ordinal and — when the window showed
425
- * its identity marker — the character. The character is the durable half: pids
426
- * and window handles change every launch, and an ordinal shifts as soon as the
427
- * windows are opened in a different order.
428
- */
429
- function runUse(flags, rest) {
430
- let instances = findInstances({ pythonBin: flags.python || null });
431
- let shape = describeAmbiguity(instances);
432
- let supported = shape.supported;
433
-
434
- if (flags.clear) {
435
- updateConfig({ pinnedInstance: null });
436
- console.log('cleared the pinned client');
437
- return 0;
438
- }
439
- if (supported.length === 0) {
440
- console.error('error: no supported World of Warcraft instance is running');
441
- if (instances.length > 0) {
442
- instances.forEach((item, index) => console.log(formatInstance(item, index)));
443
- }
444
- return 1;
445
- }
446
-
447
- // Probing is read-only capture that types nothing, so do it whenever it could
448
- // resolve an ambiguity. An explicit index or character already is the decision,
449
- // so probing then would only add seconds of waiting for no new information.
450
- const decided = Boolean(flags.character) || rest.length > 0 || flags.instance !== undefined;
451
- const wantsIdentity = Boolean(flags.character) || Boolean(flags.identify)
452
- || (shape.sameBuildCollision && !decided);
453
- if (wantsIdentity) {
454
- const probed = probeIdentities(supported, flags);
455
- if (probed.error) {
456
- if (flags.character) {
457
- console.error(`error: ${probed.error}`);
458
- return 1;
459
- }
460
- // Without an explicit name request the pin can still be taken by ordinal.
461
- } else {
462
- const byHwnd = new Map(probed.list.map((entry) => [String(entry.hwnd), entry]));
463
- instances = instances.map((instance) => {
464
- const entry = byHwnd.get(String(instance.hwnd));
465
- return entry && entry.identity ? { ...instance, identity: entry.identity } : instance;
466
- });
467
- supported = instances.filter((item) => item.supported);
468
- shape = describeAmbiguity(instances);
469
- }
470
- }
471
-
472
- // Pinning by name is the recommended path when several windows share a build.
473
- if (flags.character) {
474
- const matched = matchIdentity(supported, flags.character);
475
- if (matched.error) {
476
- console.error(`error: ${matched.error}`);
477
- (matched.candidates || supported).forEach((item, index) => console.log(formatInstance(item, index)));
478
- return 1;
479
- }
480
- return savePin(matched.instance);
481
- }
482
-
483
- // Only windows that report the same character (or no marker at all) are
484
- // genuinely indistinguishable; those still get asked for a single window.
485
- if (shape.sameBuildCollision) {
486
- for (const entry of shape.collisions) {
487
- for (const group of entry.sameCharacter) {
488
- const label = group[0].flavorLabel || entry.flavorId;
489
- console.error(`error: ${group.length} ${label} clients cannot be told apart`);
490
- console.error(` close all but one, or close these pids: `
491
- + group.map((i) => i.pid).join(', '));
492
- }
493
- }
494
- console.error(' or run `/dev auto identify` in each game window and then '
495
- + '`lycheedev use --character <name>`');
496
- supported.forEach((item, index) => console.log(formatInstance(item, index)));
497
- return 1;
498
- }
499
-
500
- const requested = rest.length > 0
501
- ? Number(rest[0])
502
- : (flags.instance !== undefined ? Number(flags.instance) : null);
503
- let chosen;
504
- let ordinal;
505
- if (requested !== null) {
506
- chosen = supported[requested];
507
- if (!chosen) {
508
- console.error(`error: instance ${requested} is out of range (0..${supported.length - 1})`);
509
- supported.forEach((item, index) => console.log(formatInstance(item, index)));
510
- return 1;
511
- }
512
- ordinal = supported
513
- .slice(0, requested)
514
- .filter((item) => item.flavorId === chosen.flavorId)
515
- .length;
516
- } else {
517
- if (supported.length > 1) {
518
- console.error('error: several clients are running; pass an index, e.g. `lycheedev use 0`');
519
- supported.forEach((item, index) => console.log(formatInstance(item, index)));
520
- return 1;
521
- }
522
- [chosen] = supported;
523
- ordinal = 0;
524
- }
525
-
526
- return savePin(chosen, ordinal);
527
- }
528
-
529
- /** Persist a pin, preferring the character when the window reported one. */
530
- function savePin(chosen, ordinal = 0) {
531
- const pin = { flavor: chosen.flavorId, ordinal };
532
- // The character is the durable half of the pin; the ordinal stays as a
533
- // fallback for a build whose windows never showed a marker.
534
- const character = identityKey(chosen);
535
- if (character) pin.character = character;
536
-
537
- updateConfig({ pinnedInstance: pin });
538
- const label = chosen.flavorLabel || chosen.flavorFolder;
539
- const name = identityLabel(chosen);
540
- console.log(`pinned ${label}${name ? ` (${name})` : ''} (pid ${chosen.pid})`);
541
- console.log('commands now target it; pass --instance <index> or --character <name> to override');
542
- return 0;
543
- }
544
-
545
- function main(argv) {
546
- const { flags, rest } = parse(argv);
547
- const command = rest.shift();
548
-
549
- // Help and version are answers, not errors: they must not depend on whether a
550
- // command was supplied.
551
- if (flags.help) {
552
- console.log(HELP);
553
- return 0;
554
- }
555
- if (flags.version) {
556
- const pkg = JSON.parse(
557
- readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
558
- );
559
- console.log(pkg.version || 'unknown');
560
- return 0;
561
- }
562
- if (!command) {
563
- console.log(HELP);
564
- return 1;
565
- }
566
-
567
- switch (command) {
568
- case 'install':
569
- return runInstall({ flags });
570
- case 'update':
571
- return runInstall({ flags: { ...flags, force: true } });
572
- case 'doctor':
573
- return runDoctor({ flags });
574
- case 'clients':
575
- return runClients(flags);
576
- case 'instances':
577
- return runInstances(flags);
578
- case 'use':
579
- return runUse(flags, rest);
580
- case 'help':
581
- console.log(HELP);
582
- return 0;
583
- default:
584
- break;
585
- }
586
-
587
- // Everything else is forwarded to the bundled python helper.
588
- const target = requireClient(flags);
589
- if (target.error) return 1;
590
-
591
- const forwarded = [];
592
- const client = target.client || {};
593
- // The python helper wants the installed addon directory itself, not the
594
- // AddOns folder that contains it.
595
- if (client.addonsDir) forwarded.push('--install-dir', path.join(client.addonsDir, addonFolderName));
596
-
597
- // Commands that type into the game must target a live window, and the
598
- // executable name cannot tell two instances apart, so resolve which running
599
- // instance to use before forwarding.
600
- const runtime = ['send', 'capture', 'run', 'bugs'].includes(command)
601
- ? resolveRuntime(flags)
602
- : null;
603
- if (runtime && runtime.error) return 1;
604
- const live = runtime && runtime.hwnd
605
- ? runtime
606
- : null;
607
-
608
- switch (command) {
609
- case 'send': {
610
- const text = rest.join(' ');
611
- if (!text) {
612
- console.error('error: send needs the command text, e.g. `lycheedev send "/dev auto status x"`');
613
- return 1;
614
- }
615
- if (!live) return 1;
616
- return forward(['send', ...targetArgs(live), '--text', text, ...passthrough(flags)]);
617
- }
618
- case 'capture':
619
- if (!live) return 1;
620
- return forward(['capture', ...targetArgs(live), ...passthrough(flags)]);
621
- case 'run':
622
- if (!flags.task) {
623
- console.error('error: run needs --task <id>');
624
- return 1;
625
- }
626
- if (!live) return 1;
627
- if (!client.svPath) {
628
- console.error('error: no SavedVariables path recorded for this client; re-run `lycheedev install`');
629
- return 1;
630
- }
631
- return forward(['run', ...forwarded, ...targetArgs(live), '--task', flags.task, '--sv', client.svPath,
632
- ...passthrough(flags)]);
633
- case 'bugs':
634
- if (!flags.count) {
635
- console.error('error: bugs needs --count <1-100>');
636
- return 1;
637
- }
638
- if (!live) return 1;
639
- if (!client.svPath) {
640
- console.error('error: no SavedVariables path recorded for this client; re-run `lycheedev install`');
641
- return 1;
642
- }
643
- return forward(['bugs', ...targetArgs(live), '--count', String(flags.count), '--sv', client.svPath,
644
- ...passthrough(flags)]);
645
- case 'ack': {
646
- if (!flags.ticket || !flags.status) {
647
- console.error('error: ack needs --ticket <t> --status received|failed');
648
- return 1;
649
- }
650
- // An acknowledgement also has to reach a live window.
651
- const ackTarget = resolveRuntime(flags);
652
- if (ackTarget.error) return 1;
653
- return forward(['ack', ...targetArgs(ackTarget), '--ticket', flags.ticket,
654
- '--status', flags.status, ...passthrough(flags)]);
655
- }
656
- case 'task': {
657
- const sub = rest.shift();
658
- if (!sub) {
659
- console.error('error: task needs a subcommand: upsert, list or remove');
660
- return 1;
661
- }
662
- return forward(['task', sub, ...forwarded, ...passthrough(flags)]);
663
- }
664
- case 'sv': {
665
- const sub = rest.shift();
666
- if (sub === 'find') {
667
- // The wrapper already knows the plaintext install and can enumerate the
668
- // account folders itself, so `sv find` needs no profile binding.
669
- const config = loadConfig();
670
- const root = flags['wow-root'] || config.wowRoot;
671
- if (!root || !exists(root)) {
672
- console.error('error: no World of Warcraft root; run `lycheedev install --wow-root <path>`');
673
- return 1;
674
- }
675
- const candidates = findSavedVariablesCandidates(root, client.flavorFolder);
676
- if (candidates.length === 0) {
677
- console.error(`no account-level '${addonFolderName}.lua' found under ${root}`);
678
- return 1;
679
- }
680
- for (const candidate of candidates) console.log(candidate.path);
681
- return 0;
682
- }
683
- if (sub === 'read') {
684
- if (!flags.ticket) {
685
- console.error('error: sv read needs --ticket <t>');
686
- return 1;
687
- }
688
- const svPath = flags.sv || client.svPath;
689
- if (!svPath) {
690
- console.error('error: no SavedVariables path known for this client; '
691
- + 'run `lycheedev install`, or pass --sv <path>');
692
- return 1;
693
- }
694
- return forward(['sv', 'read', '--sv', svPath, '--ticket', flags.ticket,
695
- ...passthrough(flags)]);
696
- }
697
- console.error('error: sv needs a subcommand: find or read');
698
- return 1;
699
- }
700
- case 'profile':
701
- case 'status':
702
- case 'recover':
703
- return forward([command, ...rest, ...passthrough(flags)]);
704
- default:
705
- console.error(`error: unknown command '${command}'`);
706
- console.log(HELP);
707
- return 1;
708
- }
709
-
710
- function passthrough(all) {
711
- const out = [];
712
- // These are either handled by the wrapper itself or are global python
713
- // options that `forward()` places before the subcommand.
714
- const handled = ['wow-root', 'client', 'python', 'force', 'reset-registry', 'task', 'count',
715
- 'ticket', 'status', 'json', 'help', 'version', 'data-dir', 'installation', 'instance'];
716
- for (const [name, value] of Object.entries(all)) {
717
- if (handled.includes(name)) continue;
718
- if (value === true) out.push(`--${name}`);
719
- else out.push(`--${name}`, String(value));
720
- }
721
- return out;
722
- }
723
-
724
- function forward(args) {
725
- // `--data-dir` and `--installation` are global options of the python helper,
726
- // so they must precede the subcommand or argparse rejects them. Everything
727
- // else stays where the caller put it.
728
- const globals = [];
729
- if (flags['data-dir']) globals.push('--data-dir', String(flags['data-dir']));
730
- if (flags.installation) globals.push('--installation', String(flags.installation));
731
- const finalArgs = [...globals, ...args];
732
- if (process.env.LYCHEEDEV_DEBUG) {
733
- console.error(`[debug] python automation.py ${finalArgs.join(' ')}`);
734
- }
735
- const result = runAutomation(finalArgs, {
736
- pythonBin: flags.python || (target.config || {}).pythonBin,
737
- });
738
- return typeof result.status === 'number' ? result.status : 1;
739
- }
740
- }
741
-
742
- process.exitCode = main(process.argv.slice(2));