lycheedev 1.0.3 → 1.0.4

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.
package/bin/lycheedev.js CHANGED
@@ -6,12 +6,13 @@ import path from 'node:path';
6
6
 
7
7
  import { runDoctor } from '../src/doctor.js';
8
8
  import { runInstall } from '../src/install.js';
9
- import { loadConfig } from '../src/config.js';
9
+ import { loadConfig, updateConfig } from '../src/config.js';
10
10
  import { runAutomation } from '../src/python.js';
11
11
  import {
12
12
  findInstances,
13
13
  findSavedVariablesCandidates,
14
14
  formatInstance,
15
+ matchPinned,
15
16
  resolveInstance,
16
17
  scanClients,
17
18
  } from '../src/wow.js';
@@ -27,6 +28,8 @@ commands
27
28
  doctor report what is installed and what is missing
28
29
  clients list every detected build and its addon state
29
30
  instances list running game clients (build, pid, window)
31
+ use [index] pin one running client as the default target
32
+ use --clear drop the pin
30
33
  send <text> type one slash command into the running game
31
34
  capture poll the game window and decode the completion notice
32
35
  run --task <id> deliver, decode, reload once and read the result ticket
@@ -52,8 +55,10 @@ options
52
55
  -v, --version show the version
53
56
 
54
57
  Every non-retail client runs as WowClassic.exe, so a running client is matched
55
- by its install path, not its process name. When several clients are open, run
56
- "lycheedev instances" first and pass --instance <index> to choose one.
58
+ by its install path, not its process name. With several clients open, run
59
+ "lycheedev instances" then "lycheedev use <index>" to pin one as the target;
60
+ the pin stores the build, so it survives a restart even though the pid and
61
+ window handle change. Pass --instance <index> to override it for one command.
57
62
 
58
63
  The automation subcommands are thin wrappers over the bundled python helper, so
59
64
  the same arguments it accepts are forwarded unchanged.`;
@@ -146,21 +151,31 @@ function runClients(flags) {
146
151
 
147
152
  /** `lycheedev instances`: which game clients are running right now. */
148
153
  function runInstances(flags) {
154
+ const config = loadConfig();
149
155
  const instances = findInstances({ pythonBin: flags.python || null });
150
156
  if (instances.length === 0) {
151
157
  console.log('no World of Warcraft instance is running');
152
158
  return 0;
153
159
  }
160
+ const pinned = matchPinned(instances, config.pinnedInstance);
154
161
  console.log('running instances:');
155
- instances.forEach((instance, index) => console.log(formatInstance(instance, index)));
162
+ instances.forEach((instance, index) => {
163
+ console.log(formatInstance(instance, index));
164
+ });
156
165
  const supported = instances.filter((item) => item.supported);
157
- const sameBuild = supported.length > 1;
158
166
  console.log('');
167
+ if (pinned) {
168
+ const label = pinned.flavorLabel || pinned.flavorFolder;
169
+ console.log(`pinned: ${label} (pid ${pinned.pid}), pid ${pinned.pid} - commands target it`);
170
+ } else if (config.pinnedInstance) {
171
+ console.log('pinned client is not running; run `lycheedev use` to repin');
172
+ }
159
173
  if (supported.length === 0) {
160
174
  console.log('none of these builds are served by the addon');
161
- } else if (sameBuild) {
162
- console.log('several instances are running: target one with `--instance <index>`');
163
- } else {
175
+ } else if (!pinned && supported.length > 1) {
176
+ console.log('several clients are running: `lycheedev use <index>` pins one, '
177
+ + 'or pass --instance <index> per command');
178
+ } else if (!pinned) {
164
179
  console.log('commands target this instance automatically');
165
180
  }
166
181
  return 0;
@@ -169,28 +184,55 @@ function runInstances(flags) {
169
184
  /**
170
185
  * Resolve the live game window a command should type into.
171
186
  *
172
- * The executable name cannot identify a build, so the running instance list is
173
- * the source of truth: `--instance <index>` picks explicitly, `--client`
174
- * filters by build, and a single match needs no flag at all. `--hwnd`/`--pid`
175
- * still override for scripted use.
187
+ * Precedence: an explicit `--hwnd`/`--pid`, then `--instance <index>`, then the
188
+ * saved pin, then `--client`, and finally the only running instance when there
189
+ * is exactly one. `WowClassic.exe` looks identical for every classic build, so
190
+ * an ambiguous choice fails loudly instead of typing into the wrong game.
176
191
  */
177
192
  function resolveRuntime(flags) {
178
193
  if (flags.hwnd || flags.pid) {
179
194
  return { hwnd: flags.hwnd, pid: flags.pid };
180
195
  }
181
196
  const instances = findInstances({ pythonBin: flags.python || null });
182
- const resolved = resolveInstance(instances, {
183
- clientId: flags.client || null,
184
- index: flags.instance !== undefined ? flags.instance : null,
185
- });
197
+ const supported = instances.filter((item) => item.supported);
198
+
199
+ if (flags.instance !== undefined) {
200
+ const chosen = supported[Number(flags.instance)];
201
+ if (!chosen) {
202
+ console.error(`error: --instance ${flags.instance} is out of range (0..${supported.length - 1})`);
203
+ supported.forEach((item, index) => console.log(formatInstance(item, index)));
204
+ return { error: true };
205
+ }
206
+ return toTarget(chosen);
207
+ }
208
+
209
+ if (!flags.client) {
210
+ const config = loadConfig();
211
+ const pinned = matchPinned(instances, config.pinnedInstance);
212
+ if (pinned) {
213
+ return toTarget(pinned);
214
+ }
215
+ if (config.pinnedInstance) {
216
+ console.error('error: the pinned client is not running; run `lycheedev use` again '
217
+ + 'or pass --instance <index>');
218
+ }
219
+ }
220
+
221
+ const resolved = resolveInstance(instances, { clientId: flags.client || null, index: null });
186
222
  if (resolved.error) {
187
223
  console.error(`error: ${resolved.error}`);
188
224
  if (resolved.candidates) {
189
225
  resolved.candidates.forEach((item, index) => console.log(formatInstance(item, index)));
190
226
  }
227
+ if (supported.length === 0 && instances.length > 0) {
228
+ instances.forEach((item, index) => console.log(formatInstance(item, index)));
229
+ }
191
230
  return { error: true };
192
231
  }
193
- const instance = resolved.instance;
232
+ return toTarget(resolved.instance);
233
+ }
234
+
235
+ function toTarget(instance) {
194
236
  return {
195
237
  hwnd: instance.hwnd ? `0x${instance.hwnd.toString(16)}` : null,
196
238
  pid: instance.pid ? String(instance.pid) : null,
@@ -198,6 +240,60 @@ function resolveRuntime(flags) {
198
240
  };
199
241
  }
200
242
 
243
+ /**
244
+ * `lycheedev use [index]`: keep one running client as the default target.
245
+ *
246
+ * Stores only the build and the instance ordinal, so the pin survives a
247
+ * restart even though the pid and window handle do not.
248
+ */
249
+ function runUse(flags, rest) {
250
+ const instances = findInstances({ pythonBin: flags.python || null });
251
+ const supported = instances.filter((item) => item.supported);
252
+
253
+ if (flags.clear) {
254
+ updateConfig({ pinnedInstance: null });
255
+ console.log('cleared the pinned client');
256
+ return 0;
257
+ }
258
+ if (supported.length === 0) {
259
+ console.error('error: no supported World of Warcraft instance is running');
260
+ if (instances.length > 0) {
261
+ instances.forEach((item, index) => console.log(formatInstance(item, index)));
262
+ }
263
+ return 1;
264
+ }
265
+
266
+ const requested = rest.length > 0 ? Number(rest[0]) : (flags.instance !== undefined ? Number(flags.instance) : null);
267
+ let chosen;
268
+ let ordinal;
269
+ if (requested !== null) {
270
+ chosen = supported[requested];
271
+ if (!chosen) {
272
+ console.error(`error: instance ${requested} is out of range (0..${supported.length - 1})`);
273
+ supported.forEach((item, index) => console.log(formatInstance(item, index)));
274
+ return 1;
275
+ }
276
+ ordinal = supported
277
+ .slice(0, requested)
278
+ .filter((item) => item.flavorId === chosen.flavorId)
279
+ .length;
280
+ } else {
281
+ if (supported.length > 1) {
282
+ console.error('error: several clients are running; pass an index, e.g. `lycheedev use 0`');
283
+ supported.forEach((item, index) => console.log(formatInstance(item, index)));
284
+ return 1;
285
+ }
286
+ [chosen] = supported;
287
+ ordinal = 0;
288
+ }
289
+
290
+ updateConfig({ pinnedInstance: { flavor: chosen.flavorId, ordinal } });
291
+ const label = chosen.flavorLabel || chosen.flavorFolder;
292
+ console.log(`pinned ${label}${ordinal > 0 ? ` instance ${ordinal}` : ''} (pid ${chosen.pid})`);
293
+ console.log('commands now target it; pass --instance <index> to override');
294
+ return 0;
295
+ }
296
+
201
297
  function main(argv) {
202
298
  const { flags, rest } = parse(argv);
203
299
  const command = rest.shift();
@@ -231,6 +327,8 @@ function main(argv) {
231
327
  return runClients(flags);
232
328
  case 'instances':
233
329
  return runInstances(flags);
330
+ case 'use':
331
+ return runUse(flags, rest);
234
332
  case 'help':
235
333
  console.log(HELP);
236
334
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lycheedev",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "lycheedev: install the World of Warcraft inspection addon, its in-game automation tooling, and drive it from the command line.",
5
5
  "keywords": [
6
6
  "wow",
package/src/config.js CHANGED
@@ -8,6 +8,10 @@ const EMPTY = {
8
8
  pythonBin: null,
9
9
  installedAt: null,
10
10
  packageVersion: null,
11
+ // Which running client commands should target. `flavor` pins a build,
12
+ // `ordinal` picks among several instances of that same build. Window
13
+ // handles and pids change every launch, so only these stable fields persist.
14
+ pinnedInstance: null,
11
15
  };
12
16
 
13
17
  export function loadConfig() {
package/src/wow.js CHANGED
@@ -233,6 +233,21 @@ export function resolveInstance(instances, { clientId = null, index = null } = {
233
233
  };
234
234
  }
235
235
 
236
+ /**
237
+ * Find the instance a saved pin refers to.
238
+ *
239
+ * A pin stores the build plus which instance of that build, because window
240
+ * handles and pids change every launch. The number shown to the user counts
241
+ * among supported instances, so the same index works here.
242
+ */
243
+ export function matchPinned(instances, pin) {
244
+ if (!pin || !pin.flavor) return null;
245
+ const supported = instances.filter((item) => item.supported);
246
+ const ofFlavor = supported.filter((item) => item.flavorId === pin.flavor);
247
+ if (ofFlavor.length === 0) return null;
248
+ return ofFlavor[pin.ordinal || 0] || ofFlavor[0];
249
+ }
250
+
236
251
  export function formatInstance(instance, index) {
237
252
  const flavor = instance.flavorLabel || instance.flavorFolder || 'unknown';
238
253
  const suffix = instance.supported ? '' : ' (the addon does not serve this build)';
@@ -6,7 +6,7 @@
6
6
  ## Notes-zhCN: 运行 Lua,检查对象与事件,追踪函数并查看错误。
7
7
  ## Notes-zhTW: 執行 Lua,檢查物件與事件,追蹤函式並檢視錯誤。
8
8
  ## Author: Follen
9
- ## Version: 1.0.3
9
+ ## Version: 1.0.4
10
10
  ## Dependencies: !BugGrabber
11
11
  ## SavedVariables: LycheeDevDB, DumperDB
12
12
  ## IconTexture: Interface\AddOns\Lychee Dev\Media\Logo.png
@@ -6,7 +6,7 @@
6
6
  ## Notes-zhCN: 运行 Lua,检查对象与事件,追踪函数并查看错误。
7
7
  ## Notes-zhTW: 執行 Lua,檢查物件與事件,追蹤函式並檢視錯誤。
8
8
  ## Author: Follen
9
- ## Version: 1.0.3
9
+ ## Version: 1.0.4
10
10
  ## Dependencies: !BugGrabber
11
11
  ## SavedVariables: LycheeDevDB, DumperDB
12
12
  ## IconTexture: Interface\AddOns\Lychee Dev\Media\Logo.png
@@ -6,7 +6,7 @@
6
6
  ## Notes-zhCN: 运行 Lua,检查对象与事件,追踪函数并查看错误。
7
7
  ## Notes-zhTW: 執行 Lua,檢查物件與事件,追蹤函式並檢視錯誤。
8
8
  ## Author: Follen
9
- ## Version: 1.0.3
9
+ ## Version: 1.0.4
10
10
  ## Dependencies: !BugGrabber
11
11
  ## SavedVariables: LycheeDevDB, DumperDB
12
12
  ## IconTexture: Interface\AddOns\Lychee Dev\Media\Logo.png