@karmaniverous/jeeves 0.4.0 → 0.4.1

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.
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import * as commander from 'commander';
3
+ import { execSync, spawnSync } from 'node:child_process';
3
4
  import { existsSync, readFileSync, writeFileSync, renameSync, mkdirSync, cpSync, rmSync } from 'node:fs';
4
5
  import { join, dirname } from 'node:path';
5
6
  import { gte } from 'semver';
6
- import 'node:child_process';
7
7
  import { z } from 'zod';
8
8
  import { lock } from 'proper-lockfile';
9
9
  import { fileURLToPath } from 'node:url';
@@ -261,14 +261,89 @@ const PLATFORM_COMPONENTS = [
261
261
  * Core library version, inlined at build time.
262
262
  *
263
263
  * @remarks
264
- * The `0.3.1` placeholder is replaced by
264
+ * The `0.4.0` placeholder is replaced by
265
265
  * `@rollup/plugin-replace` during the build with the actual version
266
266
  * from `package.json`. This ensures the correct version survives
267
267
  * when consumers bundle core into their own dist (where runtime
268
268
  * `import.meta.url`-based resolution would find the wrong package.json).
269
269
  */
270
270
  /** The core library version from package.json (inlined at build time). */
271
- const CORE_VERSION = '0.3.1';
271
+ const CORE_VERSION = '0.4.0';
272
+
273
+ /**
274
+ * Dynamic discovery of installed Jeeves component CLIs.
275
+ *
276
+ * @remarks
277
+ * Scans for globally-installed `@karmaniverous/jeeves-*` packages
278
+ * (excluding `-openclaw` plugins) and registers proxy subcommands
279
+ * on the parent CLI. Each discovered component gets a `jeeves {name}`
280
+ * command that spawns `jeeves-{name}` with passthrough args.
281
+ */
282
+ /**
283
+ * Discover globally-installed jeeves component packages.
284
+ *
285
+ * @remarks
286
+ * Runs `npm ls -g --json` and filters for packages matching
287
+ * `@karmaniverous/jeeves-*` (excluding `-openclaw` plugins).
288
+ * Returns short component names (e.g., 'watcher', 'runner').
289
+ *
290
+ * @returns Array of discovered component names.
291
+ */
292
+ function discoverComponentPackages() {
293
+ try {
294
+ const output = execSync('npm ls -g --json --depth=0', {
295
+ encoding: 'utf-8',
296
+ timeout: 10_000,
297
+ stdio: ['pipe', 'pipe', 'pipe'],
298
+ });
299
+ const parsed = JSON.parse(output);
300
+ if (!parsed.dependencies)
301
+ return [];
302
+ const names = [];
303
+ for (const pkgName of Object.keys(parsed.dependencies)) {
304
+ // Match @karmaniverous/jeeves-{name} but not -openclaw
305
+ const match = /^@karmaniverous\/jeeves-([a-z]+)$/.exec(pkgName);
306
+ if (match && !pkgName.endsWith('-openclaw')) {
307
+ names.push(match[1]);
308
+ }
309
+ }
310
+ return names;
311
+ }
312
+ catch {
313
+ return [];
314
+ }
315
+ }
316
+ /**
317
+ * Register proxy subcommands for discovered component CLIs.
318
+ *
319
+ * @remarks
320
+ * For each discovered component, adds `jeeves {name} [args...]`
321
+ * that spawns `jeeves-{name} [args...]` as a child process.
322
+ *
323
+ * @param program - The parent Commander program.
324
+ * @param componentNames - Discovered component names.
325
+ */
326
+ function registerComponentProxies(program, componentNames) {
327
+ for (const name of componentNames) {
328
+ const binName = `jeeves-${name}`;
329
+ program
330
+ .command(name)
331
+ .description(`Proxy to ${binName} CLI`)
332
+ .allowUnknownOption()
333
+ .allowExcessArguments()
334
+ .action((_opts, cmd) => {
335
+ // Collect all args after the component name
336
+ const args = cmd.args;
337
+ const result = spawnSync(binName, args, {
338
+ stdio: 'inherit',
339
+ shell: true,
340
+ });
341
+ if (result.status !== null && result.status !== 0) {
342
+ process.exitCode = result.status;
343
+ }
344
+ });
345
+ }
346
+ }
272
347
 
273
348
  /**
274
349
  * Workspace and config root initialization.
@@ -1969,11 +2044,13 @@ function registerUninstallCommand(program) {
1969
2044
  }
1970
2045
 
1971
2046
  /**
1972
- * Jeeves CLI — platform content seeding, teardown, and status.
2047
+ * Jeeves CLI — platform content seeding, teardown, status, and
2048
+ * dynamic subcommand discovery for installed component CLIs.
1973
2049
  *
1974
2050
  * @remarks
1975
2051
  * Entry point for the `jeeves` CLI command. Provides install, uninstall,
1976
- * and status subcommands.
2052
+ * and status subcommands, plus dynamic proxy commands for any installed
2053
+ * `@karmaniverous/jeeves-*` component packages.
1977
2054
  */
1978
2055
  const cli = new Command()
1979
2056
  .name('jeeves')
@@ -1984,4 +2061,7 @@ const cli = new Command()
1984
2061
  registerInstallCommand(cli);
1985
2062
  registerUninstallCommand(cli);
1986
2063
  registerStatusCommand(cli);
2064
+ // Dynamic discovery: register proxy subcommands for installed components
2065
+ const discoveredComponents = discoverComponentPackages();
2066
+ registerComponentProxies(cli, discoveredComponents);
1987
2067
  cli.parse();