@politty/zod 0.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +561 -0
  3. package/bin/cli.mjs +3 -0
  4. package/dist/arg-registry-YaWTVu_x.d.ts +1025 -0
  5. package/dist/augment.d.ts +15 -0
  6. package/dist/augment.js +1 -0
  7. package/dist/cli-main-Dn88vIyn.js +84 -0
  8. package/dist/cli-run-eibUcgys.js +7 -0
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +16 -0
  11. package/dist/command-k-4yAz4J.js +42 -0
  12. package/dist/compile-cache-Ct41pWGL.js +100 -0
  13. package/dist/compile-cache.d.ts +78 -0
  14. package/dist/compile-cache.js +3 -0
  15. package/dist/completion-gtWX3mwP.js +5608 -0
  16. package/dist/completion.d.ts +242 -0
  17. package/dist/completion.js +4 -0
  18. package/dist/docs.d.ts +770 -0
  19. package/dist/docs.js +3044 -0
  20. package/dist/field-meta-DMy5BcRr.js +146 -0
  21. package/dist/index-CvhsecfS.d.ts +455 -0
  22. package/dist/index.d.ts +799 -0
  23. package/dist/index.js +17 -0
  24. package/dist/log-collector-CoUkLVJB.js +114 -0
  25. package/dist/logger-i_bb-Jhc.js +133 -0
  26. package/dist/prompt-CEIZ-7H1.js +171 -0
  27. package/dist/prompt-clack.d.ts +16 -0
  28. package/dist/prompt-clack.js +32 -0
  29. package/dist/prompt-inquirer.d.ts +16 -0
  30. package/dist/prompt-inquirer.js +47 -0
  31. package/dist/prompt.d.ts +106 -0
  32. package/dist/prompt.js +4 -0
  33. package/dist/register-Bk0K83W2.js +439 -0
  34. package/dist/runner-D72I7wvK.js +2956 -0
  35. package/dist/runner-FvUwOHyE.js +3 -0
  36. package/dist/schema-extractor-DMSozq40.js +250 -0
  37. package/dist/skill.d.ts +608 -0
  38. package/dist/skill.js +1832 -0
  39. package/dist/src-KzC0g5CS.js +191 -0
  40. package/dist/subcommand-router-Cskpofdk.js +134 -0
  41. package/package.json +103 -0
@@ -0,0 +1,15 @@
1
+ import { n as ArgMeta } from "./arg-registry-YaWTVu_x.js";
2
+ //#region src/augment.d.ts
3
+ declare module "zod" {
4
+ interface ZodTypeDef {
5
+ argMeta?: ArgMeta;
6
+ }
7
+ interface GlobalMeta {
8
+ description?: string;
9
+ positional?: boolean;
10
+ placeholder?: string;
11
+ alias?: string | string[] | readonly string[];
12
+ hiddenAlias?: string | string[] | readonly string[];
13
+ overrideBuiltinAlias?: boolean;
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,84 @@
1
+ import { n as generateCompileCacheShim, t as formatShimPath } from "./src-KzC0g5CS.js";
2
+ import { a as internalField, i as internalArgs } from "./schema-extractor-DMSozq40.js";
3
+ import { n as defineCommand } from "./command-k-4yAz4J.js";
4
+ import { p as generateBundledCompletionWorker } from "./completion-gtWX3mwP.js";
5
+ import { n as runMain } from "./runner-D72I7wvK.js";
6
+
7
+ //#region ../core/src/cli-main.ts
8
+ const generateWorkerCommand = defineCommand({
9
+ name: "generate-worker",
10
+ description: "Generate and verify a bundled shell completion worker",
11
+ args: internalArgs({
12
+ bin: internalField.string({
13
+ description: "CLI binary or built JS entry file to invoke",
14
+ placeholder: "PATH"
15
+ }),
16
+ program: internalField.string({
17
+ description: "Program name embedded in worker metadata",
18
+ placeholder: "NAME"
19
+ }),
20
+ shell: internalField.enum([
21
+ "bash",
22
+ "zsh",
23
+ "fish"
24
+ ], {
25
+ description: "Shell worker to generate",
26
+ placeholder: "SHELL"
27
+ }),
28
+ out: internalField.optionalString({
29
+ description: "Output worker path (defaults to dist/completion/<shell>-worker.<ext>)",
30
+ placeholder: "PATH"
31
+ }),
32
+ verify: internalField.boolean({ description: "Verify __completion-worker-path resolves to the generated worker" })
33
+ }),
34
+ async run(args) {
35
+ await generateBundledCompletionWorker({
36
+ bin: args.bin,
37
+ programName: args.program,
38
+ shell: args.shell,
39
+ ...args.out !== void 0 && { outputPath: args.out },
40
+ verify: args.verify
41
+ });
42
+ }
43
+ });
44
+ runMain(defineCommand({
45
+ name: "politty",
46
+ description: "politty development utilities",
47
+ subCommands: {
48
+ "generate-shim": defineCommand({
49
+ name: "generate-shim",
50
+ description: "Generate a compile-cache bin shim that loads the real CLI via dynamic import",
51
+ args: internalArgs({
52
+ entry: internalField.optionalStringArray({
53
+ description: "Module specifier the shim imports, relative to the shim file; repeatable, one per bin/--out (defaults to ./cli.js, ./cli.mjs, ./index.js, or ./index.mjs next to each shim)",
54
+ placeholder: "SPECIFIER"
55
+ }),
56
+ out: internalField.optionalStringArray({
57
+ description: "Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)",
58
+ placeholder: "PATH"
59
+ }),
60
+ program: internalField.optionalString({
61
+ description: "Program name for the cache directory, applied to all shims (defaults per shim to its bin name)",
62
+ placeholder: "NAME"
63
+ })
64
+ }),
65
+ run(args) {
66
+ const cwd = process.cwd();
67
+ const results = generateCompileCacheShim({
68
+ ...args.entry !== void 0 && { entry: args.entry },
69
+ ...args.out !== void 0 && { out: args.out },
70
+ ...args.program !== void 0 && { program: args.program },
71
+ cwd
72
+ });
73
+ for (const result of results) console.log(`Generated compile-cache shim: ${formatShimPath(result.outputPath, cwd)} (program: ${result.program}, entry: ${result.entry})`);
74
+ }
75
+ }),
76
+ "generate-worker": generateWorkerCommand
77
+ }
78
+ })).catch((error) => {
79
+ console.error(error instanceof Error ? error.message : String(error));
80
+ process.exit(1);
81
+ });
82
+
83
+ //#endregion
84
+ export { };
@@ -0,0 +1,7 @@
1
+ import "./register-Bk0K83W2.js";
2
+
3
+ //#region src/cli-run.ts
4
+ await import("./cli-main-Dn88vIyn.js");
5
+
6
+ //#endregion
7
+ export { };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cli.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { n as enableCompileCache } from "./compile-cache-Ct41pWGL.js";
3
+
4
+ //#region src/cli.ts
5
+ /**
6
+ * Bin shim: enable the on-disk V8 compile cache before the real CLI graph
7
+ * is compiled, so warm starts skip recompilation (Node >= 22.8.0; no-op
8
+ * otherwise). The actual CLI lives in `cli-run.ts` and is loaded via
9
+ * dynamic import — ESM static imports are compiled during the link phase,
10
+ * before any code runs, so they could never hit a cache enabled here.
11
+ */
12
+ enableCompileCache("politty");
13
+ await import("./cli-run-eibUcgys.js");
14
+
15
+ //#endregion
16
+ export { };
@@ -0,0 +1,42 @@
1
+ //#region ../core/src/core/command.ts
2
+ function defineCommand(config) {
3
+ return {
4
+ name: config.name,
5
+ description: config.description,
6
+ aliases: config.aliases,
7
+ args: config.args,
8
+ subCommands: config.subCommands,
9
+ setup: config.setup,
10
+ run: config.run,
11
+ cleanup: config.cleanup,
12
+ notes: config.notes,
13
+ examples: config.examples
14
+ };
15
+ }
16
+ /**
17
+ * Create a typed defineCommand factory with pre-bound global args type.
18
+ * This is the recommended pattern for type-safe global options.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // global-args.ts
23
+ * type GlobalArgsType = { verbose: boolean; config?: string };
24
+ * export const defineAppCommand = createDefineCommand<GlobalArgsType>();
25
+ *
26
+ * // commands/build.ts
27
+ * export const buildCommand = defineAppCommand({
28
+ * name: "build",
29
+ * args: z.object({ output: arg(z.string().default("dist")) }),
30
+ * run: (args) => {
31
+ * args.verbose; // typed via GlobalArgsType
32
+ * args.output; // typed via local args
33
+ * },
34
+ * });
35
+ * ```
36
+ */
37
+ function createDefineCommand() {
38
+ return defineCommand;
39
+ }
40
+
41
+ //#endregion
42
+ export { defineCommand as n, createDefineCommand as t };
@@ -0,0 +1,100 @@
1
+ import * as nodeModule from "node:module";
2
+ import { join } from "node:path";
3
+ import { homedir } from "node:os";
4
+
5
+ //#region ../core/src/compile-cache.ts
6
+ /**
7
+ * Node.js on-disk compile cache (V8 code cache) helpers.
8
+ *
9
+ * `node:module`'s `enableCompileCache` (Node.js >= 22.8.0) persists compiled
10
+ * bytecode to disk so warm starts skip recompilation. Because ESM static
11
+ * import graphs are compiled during the link phase — before any user code
12
+ * runs — enabling the cache inside `runMain` only covers modules imported
13
+ * *after* the call (e.g. `lazy()` subcommands). To cover the whole CLI,
14
+ * enable it from a minimal bin shim that dynamically imports the real entry:
15
+ *
16
+ * ```ts
17
+ * #!/usr/bin/env node
18
+ * import { enableCompileCache } from "politty/compile-cache";
19
+ *
20
+ * enableCompileCache("my-cli");
21
+ * await import("./cli.js");
22
+ * ```
23
+ *
24
+ * This module must stay dependency-free (node builtins only) so the shim's
25
+ * static graph — the part that can never be cached — stays tiny.
26
+ */
27
+ /**
28
+ * Reduce a program name to a single safe path segment. Path separators and
29
+ * a leading scope marker are collapsed (`@scope/cli` → `scope-cli`) so the
30
+ * name cannot escape the cache root; names that reduce to nothing (or to
31
+ * `.`/`..`) yield `undefined`. Realistic command names pass through
32
+ * unchanged.
33
+ */
34
+ function sanitizeProgramName(programName) {
35
+ const safe = programName.replace(/^@/, "").replace(/[/\\]+/g, "-").trim();
36
+ if (!safe || /^[.-]+$/.test(safe)) return void 0;
37
+ return safe;
38
+ }
39
+ /**
40
+ * Compute the cache directory for a program following the same XDG
41
+ * convention as the shell-completion dispatcher scripts
42
+ * (`src/completion/dispatcher.ts`), so direct CLI runs and completion
43
+ * workers share one warm cache:
44
+ * `${XDG_CACHE_HOME:-$HOME/.cache}/<sanitized programName>/node-compile-cache`.
45
+ * The program name is first reduced to a single safe path segment by
46
+ * {@link sanitizeProgramName} (e.g. `@scope/cli` → `scope-cli`). The
47
+ * dispatcher scripts use the raw name, but a completion program name is a
48
+ * single shell word resolved on PATH and can never contain separators, so
49
+ * for every name that can actually reach both sides the two paths coincide.
50
+ *
51
+ * Returns `undefined` when no home directory can be resolved or the program
52
+ * name does not reduce to a safe path segment; callers fall back to Node's
53
+ * default location (`NODE_COMPILE_CACHE` or the OS tmpdir).
54
+ */
55
+ function compileCacheDir(programName) {
56
+ const safeName = sanitizeProgramName(programName);
57
+ if (safeName === void 0) return void 0;
58
+ const xdg = process.env.XDG_CACHE_HOME;
59
+ if (xdg) return join(xdg, safeName, "node-compile-cache");
60
+ try {
61
+ const home = homedir();
62
+ if (!home) return void 0;
63
+ return join(home, ".cache", safeName, "node-compile-cache");
64
+ } catch {
65
+ return;
66
+ }
67
+ }
68
+ /**
69
+ * Enable the Node.js on-disk compile cache for this process.
70
+ *
71
+ * - No-ops (returns `{ enabled: false }`) on runtimes without
72
+ * `module.enableCompileCache` (Node.js < 22.8.0) and never throws.
73
+ * - When the `NODE_COMPILE_CACHE` environment variable is set it always
74
+ * wins, keeping runs spawned by completion scripts (which set the same
75
+ * variable) consistent with direct runs.
76
+ * - Repeat calls are harmless: Node keeps the directory from the first
77
+ * successful call.
78
+ *
79
+ * @param options - Program name (string shorthand) or {@link CompileCacheOptions}.
80
+ */
81
+ function enableCompileCache(options) {
82
+ const opts = typeof options === "string" ? { programName: options } : options ?? {};
83
+ try {
84
+ const enable = nodeModule.enableCompileCache;
85
+ if (typeof enable !== "function") return { enabled: false };
86
+ let dir;
87
+ if (!process.env.NODE_COMPILE_CACHE) dir = opts.cacheDir ?? (opts.programName !== void 0 ? compileCacheDir(opts.programName) : void 0);
88
+ const result = dir === void 0 ? enable() : enable(dir);
89
+ const status = nodeModule.constants?.compileCacheStatus;
90
+ return {
91
+ enabled: status !== void 0 ? result.status === status.ENABLED || result.status === status.ALREADY_ENABLED : result.status === 0 || result.status === 1,
92
+ ...result.directory !== void 0 && { directory: result.directory }
93
+ };
94
+ } catch {
95
+ return { enabled: false };
96
+ }
97
+ }
98
+
99
+ //#endregion
100
+ export { enableCompileCache as n, compileCacheDir as t };
@@ -0,0 +1,78 @@
1
+ //#region ../core/src/compile-cache.d.ts
2
+ /**
3
+ * Node.js on-disk compile cache (V8 code cache) helpers.
4
+ *
5
+ * `node:module`'s `enableCompileCache` (Node.js >= 22.8.0) persists compiled
6
+ * bytecode to disk so warm starts skip recompilation. Because ESM static
7
+ * import graphs are compiled during the link phase — before any user code
8
+ * runs — enabling the cache inside `runMain` only covers modules imported
9
+ * *after* the call (e.g. `lazy()` subcommands). To cover the whole CLI,
10
+ * enable it from a minimal bin shim that dynamically imports the real entry:
11
+ *
12
+ * ```ts
13
+ * #!/usr/bin/env node
14
+ * import { enableCompileCache } from "politty/compile-cache";
15
+ *
16
+ * enableCompileCache("my-cli");
17
+ * await import("./cli.js");
18
+ * ```
19
+ *
20
+ * This module must stay dependency-free (node builtins only) so the shim's
21
+ * static graph — the part that can never be cached — stays tiny.
22
+ */
23
+ /**
24
+ * Options for {@link enableCompileCache}.
25
+ */
26
+ interface CompileCacheOptions {
27
+ /**
28
+ * Program name used to derive the default cache directory
29
+ * (`${XDG_CACHE_HOME:-$HOME/.cache}/<sanitized programName>/node-compile-cache`
30
+ * — see {@link compileCacheDir} for how the name is sanitized).
31
+ * Ignored when `cacheDir` is set.
32
+ */
33
+ programName?: string;
34
+ /** Explicit cache directory (takes precedence over `programName`). */
35
+ cacheDir?: string;
36
+ }
37
+ /**
38
+ * Result of {@link enableCompileCache}.
39
+ */
40
+ interface CompileCacheResult {
41
+ /** Whether the compile cache is active for this process. */
42
+ enabled: boolean;
43
+ /** Directory the cache is (or was already) persisted to, when known. */
44
+ directory?: string;
45
+ }
46
+ /**
47
+ * Compute the cache directory for a program following the same XDG
48
+ * convention as the shell-completion dispatcher scripts
49
+ * (`src/completion/dispatcher.ts`), so direct CLI runs and completion
50
+ * workers share one warm cache:
51
+ * `${XDG_CACHE_HOME:-$HOME/.cache}/<sanitized programName>/node-compile-cache`.
52
+ * The program name is first reduced to a single safe path segment by
53
+ * {@link sanitizeProgramName} (e.g. `@scope/cli` → `scope-cli`). The
54
+ * dispatcher scripts use the raw name, but a completion program name is a
55
+ * single shell word resolved on PATH and can never contain separators, so
56
+ * for every name that can actually reach both sides the two paths coincide.
57
+ *
58
+ * Returns `undefined` when no home directory can be resolved or the program
59
+ * name does not reduce to a safe path segment; callers fall back to Node's
60
+ * default location (`NODE_COMPILE_CACHE` or the OS tmpdir).
61
+ */
62
+ declare function compileCacheDir(programName: string): string | undefined;
63
+ /**
64
+ * Enable the Node.js on-disk compile cache for this process.
65
+ *
66
+ * - No-ops (returns `{ enabled: false }`) on runtimes without
67
+ * `module.enableCompileCache` (Node.js < 22.8.0) and never throws.
68
+ * - When the `NODE_COMPILE_CACHE` environment variable is set it always
69
+ * wins, keeping runs spawned by completion scripts (which set the same
70
+ * variable) consistent with direct runs.
71
+ * - Repeat calls are harmless: Node keeps the directory from the first
72
+ * successful call.
73
+ *
74
+ * @param options - Program name (string shorthand) or {@link CompileCacheOptions}.
75
+ */
76
+ declare function enableCompileCache(options?: string | CompileCacheOptions): CompileCacheResult;
77
+ //#endregion
78
+ export { CompileCacheOptions, CompileCacheResult, compileCacheDir, enableCompileCache };
@@ -0,0 +1,3 @@
1
+ import { n as enableCompileCache, t as compileCacheDir } from "./compile-cache-Ct41pWGL.js";
2
+
3
+ export { compileCacheDir, enableCompileCache };