@drsamonline/cli 0.12.3 → 0.12.5

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 (2) hide show
  1. package/package.json +11 -11
  2. package/src/cli.js +53 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drsamonline/cli",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "The `sui` command line.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,15 +27,15 @@
27
27
  "registry": "https://registry.npmjs.org/"
28
28
  },
29
29
  "dependencies": {
30
- "@drsamonline/catalog": "^0.12.3",
31
- "@drsamonline/compression": "^0.12.3",
32
- "@drsamonline/core": "^0.12.3",
33
- "@drsamonline/gateway": "^0.12.3",
34
- "@drsamonline/kits": "^0.12.3",
35
- "@drsamonline/mcp": "^0.12.3",
36
- "@drsamonline/prober": "^0.12.3",
37
- "@drsamonline/redteam": "^0.12.3",
38
- "@drsamonline/router": "^0.12.3",
39
- "@drsamonline/vault": "^0.12.3"
30
+ "@drsamonline/catalog": "^0.12.5",
31
+ "@drsamonline/compression": "^0.12.5",
32
+ "@drsamonline/core": "^0.12.5",
33
+ "@drsamonline/gateway": "^0.12.5",
34
+ "@drsamonline/kits": "^0.12.5",
35
+ "@drsamonline/mcp": "^0.12.5",
36
+ "@drsamonline/prober": "^0.12.5",
37
+ "@drsamonline/redteam": "^0.12.5",
38
+ "@drsamonline/router": "^0.12.5",
39
+ "@drsamonline/vault": "^0.12.5"
40
40
  }
41
41
  }
package/src/cli.js CHANGED
@@ -36,17 +36,31 @@ const HERE_DIR = dirname(fileURLToPath(import.meta.url));
36
36
  */
37
37
  const RUN_AS = (() => {
38
38
  const invoked = String(process.argv[1] ?? '');
39
- // a global install (npm link, or a published package) has a bare `sui` on PATH
40
- if (/node_modules/.test(invoked) || !/apps[\\/]cli[\\/]bin/.test(invoked)) return 'sui';
39
+ // A published install has the package on disk under node_modules, so the
40
+ // reliable command is the package name — not `sui`, which is a bin name and not
41
+ // something `npx` can resolve. Printing `npx sui` sent people to a command that
42
+ // cannot work, and it did so again the moment the package was renamed.
43
+ if (/node_modules/.test(invoked)) {
44
+ const pkg = JSON.parse(readFileSync(join(HERE_DIR, '..', 'package.json'), 'utf8'));
45
+ return `npx ${pkg.name}`;
46
+ }
47
+ if (!/apps[\\/]cli[\\/]bin/.test(invoked)) return 'sui';
41
48
  return process.platform === 'win32' ? '.\\sui.cmd' : './sui';
42
49
  })();
43
50
 
44
51
  const VERSION = (() => {
45
- try {
46
- return JSON.parse(readFileSync(join(HERE_DIR, '..', '..', '..', 'package.json'), 'utf8')).version;
47
- } catch {
48
- return '0.0.0-unknown';
52
+ // The CLI's own manifest, not the repository root: from a registry install there
53
+ // is no repository root, and walking up to one printed 0.0.0-unknown on a
54
+ // package that was published correctly.
55
+ for (const candidate of [join(HERE_DIR, '..', 'package.json'), join(HERE_DIR, '..', '..', '..', 'package.json')]) {
56
+ try {
57
+ const version = JSON.parse(readFileSync(candidate, 'utf8')).version;
58
+ if (version) return version;
59
+ } catch {
60
+ /* try the next one */
61
+ }
49
62
  }
63
+ return '0.0.0-unknown';
50
64
  })();
51
65
 
52
66
  export async function run(argv = process.argv.slice(2)) {
@@ -193,7 +207,7 @@ async function cmdUp(flags) {
193
207
  const e = /** @type {any} */ (err);
194
208
  if (e.code === 'EADDRINUSE') {
195
209
  throw new ConfigError(
196
- `Port ${port} is already in use. Either stop what is on it, or start sui elsewhere: npx sui start --port ${port + 1}`,
210
+ `Port ${port} is already in use. Either stop what is on it, or start sui elsewhere: ${RUN_AS} start --port ${port + 1}`,
197
211
  { detail: e.message, path: 'server.port' },
198
212
  );
199
213
  }
@@ -400,7 +414,7 @@ async function cmdTools(flags, args) {
400
414
  if (want) {
401
415
  const configPath = defaultConfigPath();
402
416
  const config = configPath ? JSON.parse(readFileSync(configPath, 'utf8')) : null;
403
- if (!config) throw new ConfigError('No config yet. Run `npx sui init` first.');
417
+ if (!config) throw new ConfigError(`No config yet. Run \`${RUN_AS} init\` first.`);
404
418
  const combo = flags.combo ?? Object.keys(config.combos ?? {})[0];
405
419
  const port = config.server?.port ?? 8787;
406
420
  const result = writeToolConfig(want, {
@@ -437,11 +451,11 @@ async function cmdTools(flags, args) {
437
451
  async function cmdMigrate(flags, args) {
438
452
  const file = args[0] ?? flags.from;
439
453
  if (!file) {
440
- throw new ConfigError('Say which config to import: npx sui migrate ./9router.json');
454
+ throw new ConfigError(`Say which config to import: ${RUN_AS} migrate ./9router.json`);
441
455
  }
442
456
  const imported = readMigrationSource(resolve(file));
443
457
  const configPath = flags.config ?? defaultConfigPath();
444
- if (!configPath) throw new ConfigError('No sui config yet. Run `npx sui init` first.');
458
+ if (!configPath) throw new ConfigError(`No sui config yet. Run \`${RUN_AS} init\` first.`);
445
459
  const currentRaw = JSON.parse(readFileSync(configPath, 'utf8'));
446
460
  const gateway = await createGateway({ configPath, ledgerFile: null });
447
461
  const diff = diffImport(gateway.config, imported);
@@ -523,14 +537,14 @@ async function cmdKeys(flags, args) {
523
537
  const sub = args[0] ?? (flags.hash ? 'hash' : null);
524
538
  if (sub !== 'hash') {
525
539
  console.log('');
526
- console.log('Usage: npx sui keys hash [--config <file>]');
540
+ console.log(`Usage: ${RUN_AS} keys hash [--config <file>]`);
527
541
  console.log('');
528
542
  console.log('Rewrites every plaintext key in apiKeys as a SHA-256 hash. The keys');
529
543
  console.log('themselves still work — they are simply no longer stored in the file.');
530
544
  return;
531
545
  }
532
546
  const path = flags.config ?? defaultConfigPath();
533
- if (!path) throw new ConfigError('No config found. Run `npx sui init` first.');
547
+ if (!path) throw new ConfigError(`No config found. Run \`${RUN_AS} init\` first.`);
534
548
  const raw = JSON.parse(readFileSync(path, 'utf8'));
535
549
  const keys = Array.isArray(raw.apiKeys) ? raw.apiKeys : [];
536
550
  let changed = 0;
@@ -572,7 +586,7 @@ function cmdInvariants(flags) {
572
586
 
573
587
  function createGatewayConfig(path) {
574
588
  const resolved = path ?? defaultConfigPath();
575
- if (!resolved) throw new ConfigError('No config found. Run `npx sui init` first.');
589
+ if (!resolved) throw new ConfigError(`No config found. Run \`${RUN_AS} init\` first.`);
576
590
  return normalizeConfig(JSON.parse(readFileSync(resolved, 'utf8')), { path: resolved, env: loadEnvFile('.env', { ...process.env }) });
577
591
  }
578
592
 
@@ -580,34 +594,34 @@ function help() {
580
594
  console.log(`
581
595
  sui ${VERSION} — one endpoint for every LLM
582
596
 
583
- npx sui first run: find keys, find tools, prove the route, start
584
- npx sui init the same, explicitly --demo --force --port 8787
585
- npx sui start run the gateway --port 8787 --config <file> --no-workers
597
+ ${RUN_AS} first run: find keys, find tools, prove the route, start
598
+ ${RUN_AS} init the same, explicitly --demo --force --port 8787
599
+ ${RUN_AS} start run the gateway --port 8787 --config <file> --no-workers
586
600
  (aliases: up, serve)
587
- npx sui invariants every hard constraint, and which are enforced
588
- npx sui keys hash replace plaintext API keys with SHA-256 hashes
589
- npx sui doctor one real turn per combo, and say what broke
590
- npx sui models the combos and what they can reach --json
591
- npx sui cost spend, latency and A/B arms --json --all (alias: usage)
601
+ ${RUN_AS} invariants every hard constraint, and which are enforced
602
+ ${RUN_AS} keys hash replace plaintext API keys with SHA-256 hashes
603
+ ${RUN_AS} doctor one real turn per combo, and say what broke
604
+ ${RUN_AS} models the combos and what they can reach --json
605
+ ${RUN_AS} cost spend, latency and A/B arms --json --all (alias: usage)
592
606
  --by user|tool for charge-back attribution
593
- npx sui tools point a coding tool here --set <tool-id>
594
- npx sui migrate <file> import from 9router / OmniRoute / HubGate --apply --only a,b
595
- npx sui catalog [q] the provider catalogue, and what is still unverified
596
- npx sui probe [name] liveness, readiness and suitability checks (B2.3)
597
- npx sui compress <file|-> [--preset lite|standard|aggressive|ultra] [--text "…"]
598
- npx sui budget which preset the remaining quota would choose
599
- npx sui savings what cache hits and compression did not spend --all
600
- npx sui explain [combo] why a route would go where it goes (B7.4)
601
- npx sui tenants what each API key has spent, and what it may reach
602
- npx sui mcp serve the gateway over MCP --transport stdio|http --port 8788
603
- npx sui recipe list named config patches: list, show, apply --dry-run --force
604
- npx sui local find a model server on this machine --write --timeout 300
605
- npx sui sandbox run code in a contained process --self-test --wall --heap
606
- npx sui redteam [combo] attack your own route with 10 obfuscations (B6.2)
607
- npx sui vault <cmd> init | set <provider> | list | remove <provider> | status
608
- npx sui config <cmd> show | get <path> | set <path> <value> | unset <path>
609
- npx sui tokens --check WCAG AA on the dashboard tokens, computed by tokens-kit
610
- npx sui kits the vendored kits and whether they load
607
+ ${RUN_AS} tools point a coding tool here --set <tool-id>
608
+ ${RUN_AS} migrate <file> import from 9router / OmniRoute / HubGate --apply --only a,b
609
+ ${RUN_AS} catalog [q] the provider catalogue, and what is still unverified
610
+ ${RUN_AS} probe [name] liveness, readiness and suitability checks (B2.3)
611
+ ${RUN_AS} compress <file|-> [--preset lite|standard|aggressive|ultra] [--text "…"]
612
+ ${RUN_AS} budget which preset the remaining quota would choose
613
+ ${RUN_AS} savings what cache hits and compression did not spend --all
614
+ ${RUN_AS} explain [combo] why a route would go where it goes (B7.4)
615
+ ${RUN_AS} tenants what each API key has spent, and what it may reach
616
+ ${RUN_AS} mcp serve the gateway over MCP --transport stdio|http --port 8788
617
+ ${RUN_AS} recipe list named config patches: list, show, apply --dry-run --force
618
+ ${RUN_AS} local find a model server on this machine --write --timeout 300
619
+ ${RUN_AS} sandbox run code in a contained process --self-test --wall --heap
620
+ ${RUN_AS} redteam [combo] attack your own route with 10 obfuscations (B6.2)
621
+ ${RUN_AS} vault <cmd> init | set <provider> | list | remove <provider> | status
622
+ ${RUN_AS} config <cmd> show | get <path> | set <path> <value> | unset <path>
623
+ ${RUN_AS} tokens --check WCAG AA on the dashboard tokens, computed by tokens-kit
624
+ ${RUN_AS} kits the vendored kits and whether they load
611
625
 
612
626
  Endpoint, once running: http://127.0.0.1:8787/v1
613
627
  Dashboard: http://127.0.0.1:8787/