@theholocron/kyber 5.0.0-alpha.343 → 5.0.0-alpha.344

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/README.md CHANGED
@@ -10,17 +10,17 @@ Published, so a second CLI can import it. `@theholocron/cli` is its first consum
10
10
 
11
11
  ## Subpaths
12
12
 
13
- | Subpath | What it gives a CLI |
14
- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
15
- | `/ui` | Status glyphs and colours, padded status rows, a check-rows renderer (`printCheckRows`, `printCheckSummary`, `summariseChecks`, `declaredVsActual`), a depth-limited JSON view, a spinner that only shows on a terminal (and `createRetryNotice(subscribe)`, which says on it when a request is retried, given the HTTP client's retry hook), wait-for-Enter, open-in-file-browser, the error for "a prompt was needed but there is no terminal", and the cleaning of error text before it reaches a terminal (`describeError`, `commandFailureMessage`, `logReason`, `sanitizeDetail`, `stripControl`). |
16
- | `/notifier` | A cached, best-effort "a newer version exists" notice for an npm package: `checkForUpdates({ name, currentVersion, cacheDir })` returns a function that prints a boxed notice to stderr, or `null`. Silent in CI and with `NO_UPDATE_NOTIFIER`. |
17
- | `/secrets` | Handling tokens safely, with no terminal UI: owner-only (`0600`) files, shredding a file that held tokens, the wait-for-the-import-then-delete step that follows (`finishCredentialsFile`: deletes the file on Enter, Ctrl-C or a closed terminal), "does git ignore this path", dotenv lines that survive quoting, reading a `.env` at the repo root, the clipboard, the OS keyring (`createKeyring({ service })`, best-effort, `@napi-rs/keyring` optional), an in-process store for credentials a provider returned, `--token` / `--token vendor=value` parsing, and resolving a token from the flag, the environment, that store and the keyring (`createResolveToken`, `createFeatureResolver`, `AuthError`). |
18
- | `/prompts` | A searchable menu (`pickMenuItem`), and prompting for the positionals and options a command left out (`promptForPositionals`, `promptForOptions`): required options always asked, the rest behind one checkbox, mutually exclusive `modes`, secret options masked, and a value that is asked last (`askLast`). They take small structural types (`PositionalCommand`, `OptionsCommand`), not the CLI's command registry. |
19
- | `/menu` | The interactive menu of a CLI, driven by data: `launchMenu(entries, argv, { bin, envPrefix })` shows a searchable, nested picker over a list of `MenuEntry`, asks for the positionals and options the command needs, then spawns the CLI again with the answers. A command that supports `--dry-run` is previewed first and then confirmed (`--skip-dry-run` opts out); a preview that reports `DRY_RUN_NOOP_EXIT_CODE` skips the question. Secret options never reach argv: they travel as `<envPrefix>_<OPTION>` env vars, and a preview child gets `dryRunPreviewEnvVar(envPrefix)`. `createMenu({ bin, envPrefix })` binds it once (returning `launchMenu(entries, argv, options?)` and `dryRunPreviewEnvVar`). Also `menuItems`, `buildChildArgv`, `forwardedFlags`, `secretEnv`, `shouldPreviewDryRun`. |
20
- | `/testing` | A test harness for a CLI: `createCliRunner` runs a built binary in a fresh directory with an environment built from nothing, `runCommand` runs one yargs command module through a real parse, `ensureBuilt` is a Vitest global setup that builds only when `dist` is missing or stale, and `hermeticCreateRequire` resolves modules only from one directory. |
21
- | `/observability` | The logging and telemetry wiring of a CLI: `createCliLogger({ envPrefix, resolveAxiom? })` returns a memoized root logger (`buildCliLogger`, `getLogger`, `reportError`, `getRunId`, `resolveLogLevel`) whose level comes from `--log` / `--verbose` / `--quiet`, then `<PREFIX>_LOG_LEVEL`, then the config file, and is quiet on a terminal unless asked; `createCliTelemetry({ envPrefix, dsn, posthogKey, posthogHost })` returns Sentry error reporting and PostHog analytics behind `<PREFIX>_TELEMETRY=false`. `@theholocron/observability` is an optional peer. |
22
- | `/config` | A `<name>.config.{ts,js,mjs,cjs,json}` for a new CLI: `createConfigSystem({ name, derive?, resolve, merge })` returns `defineConfig`, `loadConfig` (walks up to `.git`) and `compose()` (dedupe by `id`, all unmet `requires` in one `ConfigError`, per-key merge). Strategies: `lastWins`, `shallowMerge`, `union`, `mergeByKey`. `@theholocron/datapad` is an optional peer. |
23
- | `/flags` | The options every command of a tool takes: `addGlobalOptions(parser, { describe?, cwd? })` declares `--dry-run`, a repeatable `--token` and `--cwd` once on the root; `tokenContext(values, report)` parses the `--token` values and reports a bad one without a stack trace; `groupMenu(parent, open)` is the hidden default command that makes a bare group (`tool repo`) do something useful; `InferArgs` types a command's handler arguments from its builder. |
13
+ | Subpath | What it gives a CLI |
14
+ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
15
+ | `/ui` | Status glyphs and colours, padded status rows, a check-rows renderer (`printCheckRows`, `printCheckSummary`, `summariseChecks`, `declaredVsActual`), a depth-limited JSON view, a spinner that only shows on a terminal (and `createRetryNotice(subscribe)`, which says on it when a request is retried, given the HTTP client's retry hook), wait-for-Enter, open-in-file-browser, the error for "a prompt was needed but there is no terminal", and the cleaning of error text before it reaches a terminal (`describeError`, `commandFailureMessage`, `logReason`, `sanitizeDetail`, `stripControl`). |
16
+ | `/notifier` | A cached, best-effort "a newer version exists" notice for an npm package: `checkForUpdates({ name, currentVersion, cacheDir })` returns a function that prints a boxed notice to stderr, or `null`. Silent in CI and with `NO_UPDATE_NOTIFIER`. |
17
+ | `/secrets` | Handling tokens safely, with no terminal UI: owner-only (`0600`) files, shredding a file that held tokens, the wait-for-the-import-then-delete step that follows (`finishCredentialsFile`: deletes the file on Enter, Ctrl-C or a closed terminal), "does git ignore this path", dotenv lines that survive quoting, reading a `.env` at the repo root, the clipboard, the OS keyring (`createKeyring({ service })`, best-effort, `@napi-rs/keyring` optional), an in-process store for credentials a provider returned, `--token` / `--token vendor=value` parsing, and resolving a token from the flag, the environment, that store and the keyring (`createResolveToken`, `createFeatureResolver`, `AuthError`). |
18
+ | `/prompts` | A searchable menu (`pickMenuItem`), and prompting for the positionals and options a command left out (`promptForPositionals`, `promptForOptions`): required options always asked, the rest behind one checkbox, mutually exclusive `modes`, secret options masked, and a value that is asked last (`askLast`). They take small structural types (`PositionalCommand`, `OptionsCommand`), not the CLI's command registry. |
19
+ | `/menu` | The interactive menu of a CLI, driven by data: `launchMenu(entries, argv, { bin, envPrefix })` shows a searchable, nested picker over a list of `MenuEntry`, asks for the positionals and options the command needs, then spawns the CLI again with the answers. A command that supports `--dry-run` is previewed first and then confirmed (`--skip-dry-run` opts out); a preview that reports `DRY_RUN_NOOP_EXIT_CODE` skips the question. Secret options never reach argv: they travel as `<envPrefix>_<OPTION>` env vars, and a preview child gets `dryRunPreviewEnvVar(envPrefix)`. `createMenu({ bin, envPrefix })` binds it once (returning `launchMenu(entries, argv, options?)` and `dryRunPreviewEnvVar`). `createCommandRegistry(entries, label?)` declares the commands once and returns `{ entries, getEntry(name) }` (a repeated name throws), and `numeric` is a ready `validate` for a number prompt. Also `menuItems`, `buildChildArgv`, `forwardedFlags`, `secretEnv`, `shouldPreviewDryRun`. |
20
+ | `/testing` | A test harness for a CLI: `createCliRunner` runs a built binary in a fresh directory with an environment built from nothing, `runCommand` runs one yargs command module through a real parse, `ensureBuilt` is a Vitest global setup that builds only when `dist` is missing or stale, and `hermeticCreateRequire` resolves modules only from one directory. |
21
+ | `/observability` | The logging and telemetry wiring of a CLI: `createCliLogger({ envPrefix, resolveAxiom? })` returns a memoized root logger (`buildCliLogger`, `getLogger`, `reportError`, `getRunId`, `resolveLogLevel`) whose level comes from `--log` / `--verbose` / `--quiet`, then `<PREFIX>_LOG_LEVEL`, then the config file, and is quiet on a terminal unless asked; `createCliTelemetry({ envPrefix, dsn, posthogKey, posthogHost })` returns Sentry error reporting and PostHog analytics behind `<PREFIX>_TELEMETRY=false`. `@theholocron/observability` is an optional peer. |
22
+ | `/config` | A `<name>.config.{ts,js,mjs,cjs,json}` for a new CLI: `createConfigSystem({ name, derive?, resolve, merge })` returns `defineConfig`, `loadConfig` (walks up to `.git`) and `compose()` (dedupe by `id`, all unmet `requires` in one `ConfigError`, per-key merge). Strategies: `lastWins`, `shallowMerge`, `union`, `mergeByKey`. `@theholocron/datapad` is an optional peer. |
23
+ | `/flags` | The options every command of a tool takes: `addGlobalOptions(parser, { describe?, cwd? })` declares `--dry-run`, a repeatable `--token` and `--cwd` once on the root; `tokenContext(values, report)` parses the `--token` values and reports a bad one without a stack trace; `groupMenu(parent, open)` is the hidden default command that makes a bare group (`tool repo`) do something useful; `InferArgs` types a command's handler arguments from its builder. |
24
24
 
25
25
  ## Usage
26
26
 
package/dist/menu.d.mts CHANGED
@@ -75,6 +75,26 @@ interface MenuEntry {
75
75
  * shape identically with no need to know which kind of command it came from.
76
76
  */
77
77
  export declare function buildChildArgv(entry: MenuEntry, positionals: string[], resolved: ResolvedOptions, parentArgv: Record<string, unknown>, dryRunOverride?: boolean): string[];
78
+ /** A CLI's command catalog: the entries in menu order, and a lookup by full name. See {@link createCommandRegistry}. */
79
+ interface CommandRegistry<E extends MenuEntry = MenuEntry> {
80
+ /** Every entry, in the order they were declared (the order the menu lists them in). */
81
+ entries: E[];
82
+ /** The entry for a full command name (`"auth set"`); throws when there is none. */
83
+ getEntry(name: string): E;
84
+ }
85
+ /**
86
+ * Declare a CLI's commands once, as a list of {@link MenuEntry}, and get the catalog the menu and the prompts
87
+ * read from: hand `entries` to {@link launchMenu}, and have a leaf command's handler call `getEntry(name)` to
88
+ * prompt for just its own missing positionals (`promptForPositionals`).
89
+ *
90
+ * The list is kept in the order given. A repeated name is a mistake (the menu would list it twice and
91
+ * `getEntry` could only reach the first), so it throws here, when the catalog is built, not at the prompt.
92
+ *
93
+ * @param entries - The commands, in menu order.
94
+ * @param label - Names the catalog in error messages (default `"menu"`).
95
+ * @throws When two entries share a name.
96
+ */
97
+ export declare function createCommandRegistry<E extends MenuEntry>(entries: E[], label?: string): CommandRegistry<E>;
78
98
  /** How {@link launchMenu} is bound to one particular CLI. */
79
99
  interface LaunchMenuConfig {
80
100
  /** The CLI's binary name, used in the default non-interactive hint (`Run \`<bin> --help\` …`). */
@@ -179,6 +199,11 @@ export declare const BACK = "back";
179
199
  * Registration order is kept.
180
200
  */
181
201
  export declare function menuItems(entries: MenuEntry[], path?: string[]): MenuItem[];
202
+ /**
203
+ * A `validate` function for an `input` positional or option (`PositionalPrompt.validate`) that accepts only
204
+ * digits; anything else returns the message `"enter a number"`.
205
+ */
206
+ export declare const numeric: (value: string) => boolean | string;
182
207
  /**
183
208
  * Secret option answers, keyed by the env var their handler reads instead
184
209
  * of argv (`ps` and shell history expose argv, never a child's own env) —
@@ -197,4 +222,4 @@ export declare function secretEnv(resolved: ResolvedOptions, envPrefix: string):
197
222
  * straight to the real run").
198
223
  */
199
224
  export declare function shouldPreviewDryRun(entry: MenuEntry, parentArgv: Record<string, unknown>): boolean;
200
- export type { LaunchMenuConfig, MenuEntry };
225
+ export type { CommandRegistry, LaunchMenuConfig, MenuEntry };
package/dist/menu.mjs CHANGED
@@ -75,6 +75,34 @@ function buildChildArgv(entry, positionals, resolved, parentArgv, dryRunOverride
75
75
  ...forwardedFlags(parentArgv, dryRunOverride)
76
76
  ];
77
77
  }
78
+ // src/menu/create-command-registry/create-command-registry.ts
79
+ /**
80
+ * Declare a CLI's commands once, as a list of {@link MenuEntry}, and get the catalog the menu and the prompts
81
+ * read from: hand `entries` to {@link launchMenu}, and have a leaf command's handler call `getEntry(name)` to
82
+ * prompt for just its own missing positionals (`promptForPositionals`).
83
+ *
84
+ * The list is kept in the order given. A repeated name is a mistake (the menu would list it twice and
85
+ * `getEntry` could only reach the first), so it throws here, when the catalog is built, not at the prompt.
86
+ *
87
+ * @param entries - The commands, in menu order.
88
+ * @param label - Names the catalog in error messages (default `"menu"`).
89
+ * @throws When two entries share a name.
90
+ */
91
+ function createCommandRegistry(entries, label = "menu") {
92
+ const seen = /* @__PURE__ */ new Set();
93
+ for (const { name } of entries) {
94
+ if (seen.has(name)) throw new Error(`${label}: duplicate command registry entry "${name}"`);
95
+ seen.add(name);
96
+ }
97
+ return {
98
+ entries,
99
+ getEntry(name) {
100
+ const entry = entries.find((e) => e.name === name);
101
+ if (!entry) throw new Error(`${label}: no command registry entry named "${name}"`);
102
+ return entry;
103
+ }
104
+ };
105
+ }
78
106
  // src/menu/dry-run-preview-env-var/dry-run-preview-env-var.ts
79
107
  /**
80
108
  * The env var {@link launchMenu} sets on a dry-run preview child (`<ENV_PREFIX>_DRY_RUN_PREVIEW`), so its
@@ -319,4 +347,10 @@ function createMenu({ bin, envPrefix }) {
319
347
  dryRunPreviewEnvVar: dryRunPreviewEnvVar(envPrefix)
320
348
  };
321
349
  }
322
- export { BACK, DRY_RUN_NOOP_EXIT_CODE, GROUP, buildChildArgv, createMenu, dryRunPreviewEnvVar, forwardedFlags, launchMenu, menuItems, secretEnv, shouldPreviewDryRun };
350
+ // src/menu/numeric/numeric.ts
351
+ /**
352
+ * A `validate` function for an `input` positional or option (`PositionalPrompt.validate`) that accepts only
353
+ * digits; anything else returns the message `"enter a number"`.
354
+ */
355
+ const numeric = (value) => /^\d+$/.test(value) ? true : "enter a number";
356
+ export { BACK, DRY_RUN_NOOP_EXIT_CODE, GROUP, buildChildArgv, createCommandRegistry, createMenu, dryRunPreviewEnvVar, forwardedFlags, launchMenu, menuItems, numeric, secretEnv, shouldPreviewDryRun };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/kyber",
3
- "version": "5.0.0-alpha.343",
3
+ "version": "5.0.0-alpha.344",
4
4
  "description": "The reusable parts of a command-line tool: terminal output, prompts, the interactive menu, the update notifier, safe handling of tokens, a test harness and the global flags.",
5
5
  "keywords": [
6
6
  "cli",
@@ -90,10 +90,10 @@
90
90
  "typescript": "^5.9.3",
91
91
  "vitest": "^5.0.5",
92
92
  "yargs": "^18.1.0",
93
+ "@theholocron/datapad": "5.0.0-alpha.344",
94
+ "@theholocron/observability": "0.7.0-alpha.1",
93
95
  "@theholocron/eslint-config": "^8.9.0-alpha.8",
94
- "@theholocron/datapad": "5.0.0-alpha.343",
95
96
  "@theholocron/tsconfig": "^8.9.0-alpha.8",
96
- "@theholocron/observability": "0.7.0-alpha.1",
97
97
  "@theholocron/tsdown-config": "^8.9.0-alpha.8",
98
98
  "@theholocron/vitest-config": "^8.9.0-alpha.8"
99
99
  },
@@ -106,7 +106,7 @@
106
106
  "dotenv": "^17.0.0",
107
107
  "ora": "^9.0.0",
108
108
  "yargs": "^18.0.0",
109
- "@theholocron/datapad": "^5.0.0-alpha.343",
109
+ "@theholocron/datapad": "^5.0.0-alpha.344",
110
110
  "@theholocron/observability": "^0.7.0-alpha.1"
111
111
  },
112
112
  "peerDependenciesMeta": {