@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
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import { i as toKebabCase, r as toCamelCase } from "./field-meta-DMy5BcRr.js";
2
+ import { t as arg$1 } from "./register-Bk0K83W2.js";
3
+ import { n as generateCompileCacheShim } from "./src-KzC0g5CS.js";
4
+ import { r as getUnknownKeysMode, t as extractFields } from "./schema-extractor-DMSozq40.js";
5
+ import { n as defineCommand$1, t as createDefineCommand$1 } from "./command-k-4yAz4J.js";
6
+ import { o as isLazyCommand, s as lazy } from "./subcommand-router-Cskpofdk.js";
7
+ import { a as generateCompletion, p as generateBundledCompletionWorker, s as withCompletionCommand } from "./completion-gtWX3mwP.js";
8
+ import { C as generateHelp, E as createDualCaseProxy, S as ReservedFieldNameError, T as renderMarkdown, _ as DuplicateFieldError, a as formatCommandValidationErrors, b as PositionalConfigError, c as validateCrossSchemaCollisions, d as validateDuplicateNegations, f as validatePositionalConfig, g as DuplicateAliasError, h as CaseVariantCollisionError, i as parseArgv, l as validateDuplicateAliases, m as validateReservedFieldNames, n as runMain, o as validateCaseVariantCollisions, p as validateReservedAliases, r as formatValidationErrors, s as validateCommand, t as runCommand, u as validateDuplicateFields, v as DuplicateNegationError, w as renderInline, x as ReservedAliasError, y as FieldTypeConflictError } from "./runner-D72I7wvK.js";
9
+ import { a as symbols, i as styles, n as logger, r as setColorEnabled, t as isColorEnabled } from "./logger-i_bb-Jhc.js";
10
+
11
+ //#region src/index.ts
12
+ const defineCommand = defineCommand$1;
13
+ const createDefineCommand = createDefineCommand$1;
14
+ const arg = arg$1;
15
+
16
+ //#endregion
17
+ export { CaseVariantCollisionError, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, FieldTypeConflictError, PositionalConfigError, ReservedAliasError, ReservedFieldNameError, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompileCacheShim, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, validateReservedFieldNames, withCompletionCommand };
@@ -0,0 +1,114 @@
1
+ //#region ../core/src/executor/log-collector.ts
2
+ /**
3
+ * Mapping from log level to output stream
4
+ */
5
+ const LOG_STREAM_MAP = {
6
+ log: "stdout",
7
+ info: "stdout",
8
+ debug: "stdout",
9
+ warn: "stderr",
10
+ error: "stderr"
11
+ };
12
+ /**
13
+ * All log levels
14
+ */
15
+ const ALL_LOG_LEVELS = [
16
+ "log",
17
+ "info",
18
+ "debug",
19
+ "warn",
20
+ "error"
21
+ ];
22
+ /**
23
+ * Format console arguments to string
24
+ */
25
+ function formatArgs(args) {
26
+ return args.map((arg) => {
27
+ if (arg instanceof Error) return arg.message;
28
+ if (typeof arg === "object" && arg !== null) try {
29
+ return JSON.stringify(arg);
30
+ } catch {
31
+ return String(arg);
32
+ }
33
+ return String(arg);
34
+ }).join(" ");
35
+ }
36
+ /**
37
+ * Create a log collector that intercepts console methods
38
+ *
39
+ * @param options - Options for the log collector
40
+ * @returns A log collector instance
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const collector = createLogCollector();
45
+ * collector.start();
46
+ *
47
+ * console.log("Info message");
48
+ * console.error("Something went wrong");
49
+ * console.warn("This is a warning");
50
+ *
51
+ * collector.stop();
52
+ * const logs = collector.getLogs();
53
+ * // {
54
+ * // entries: [
55
+ * // { message: "Info message", level: "log", stream: "stdout", timestamp: ... },
56
+ * // { message: "Something went wrong", level: "error", stream: "stderr", timestamp: ... },
57
+ * // { message: "This is a warning", level: "warn", stream: "stderr", timestamp: ... }
58
+ * // ]
59
+ * // }
60
+ * ```
61
+ */
62
+ function createLogCollector(options = {}) {
63
+ const entries = [];
64
+ const levels = options.levels ?? ALL_LOG_LEVELS;
65
+ const passthrough = options.passthrough ?? true;
66
+ let originals = null;
67
+ const createInterceptor = (level, original) => {
68
+ return (...args) => {
69
+ entries.push({
70
+ message: formatArgs(args),
71
+ timestamp: /* @__PURE__ */ new Date(),
72
+ level,
73
+ stream: LOG_STREAM_MAP[level]
74
+ });
75
+ if (passthrough) original.apply(console, args);
76
+ };
77
+ };
78
+ return {
79
+ getLogs() {
80
+ return { entries: [...entries] };
81
+ },
82
+ start() {
83
+ if (originals !== null) return;
84
+ originals = {
85
+ log: console.log,
86
+ info: console.info,
87
+ debug: console.debug,
88
+ warn: console.warn,
89
+ error: console.error
90
+ };
91
+ for (const level of levels) console[level] = createInterceptor(level, originals[level]);
92
+ },
93
+ stop() {
94
+ if (originals === null) return;
95
+ for (const level of levels) console[level] = originals[level];
96
+ originals = null;
97
+ }
98
+ };
99
+ }
100
+ /**
101
+ * Merge multiple CollectedLogs into one (sorted by timestamp)
102
+ */
103
+ function mergeLogs(...logsArray) {
104
+ return { entries: logsArray.flatMap((l) => l.entries).sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) };
105
+ }
106
+ /**
107
+ * Create an empty CollectedLogs object
108
+ */
109
+ function emptyLogs() {
110
+ return { entries: [] };
111
+ }
112
+
113
+ //#endregion
114
+ export { emptyLogs as n, mergeLogs as r, createLogCollector as t };
@@ -0,0 +1,133 @@
1
+ import { styleText } from "node:util";
2
+
3
+ //#region ../core/src/output/logger.ts
4
+ /**
5
+ * Check if color output should be disabled
6
+ */
7
+ function shouldDisableColor() {
8
+ if (process.env.NO_COLOR !== void 0) return true;
9
+ if (process.env.FORCE_COLOR === "0") return true;
10
+ if (process.env.FORCE_COLOR) return false;
11
+ if (process.env.CI) return true;
12
+ if (!process.stdout.isTTY) return true;
13
+ return false;
14
+ }
15
+ /**
16
+ * Global flag to control color output
17
+ */
18
+ let colorDisabled = shouldDisableColor();
19
+ /**
20
+ * Enable or disable color output programmatically
21
+ */
22
+ function setColorEnabled(enabled) {
23
+ colorDisabled = !enabled;
24
+ }
25
+ /**
26
+ * Check if color output is currently enabled
27
+ */
28
+ function isColorEnabled() {
29
+ return !colorDisabled;
30
+ }
31
+ /**
32
+ * Create a style function that applies the given styles
33
+ */
34
+ function createStyleFn(...styleArgs) {
35
+ return (text) => {
36
+ if (colorDisabled) return text;
37
+ let result = text;
38
+ for (const style of styleArgs) result = styleText(style, result);
39
+ return result;
40
+ };
41
+ }
42
+ /**
43
+ * Semantic style functions for inline text styling
44
+ */
45
+ const styles = {
46
+ success: createStyleFn("green"),
47
+ error: createStyleFn("red"),
48
+ warning: createStyleFn("yellow"),
49
+ info: createStyleFn("cyan"),
50
+ bold: createStyleFn("bold"),
51
+ dim: createStyleFn("dim"),
52
+ italic: createStyleFn("italic"),
53
+ underline: createStyleFn("underline"),
54
+ red: createStyleFn("red"),
55
+ green: createStyleFn("green"),
56
+ yellow: createStyleFn("yellow"),
57
+ blue: createStyleFn("blue"),
58
+ magenta: createStyleFn("magenta"),
59
+ cyan: createStyleFn("cyan"),
60
+ white: createStyleFn("white"),
61
+ gray: createStyleFn("gray"),
62
+ command: createStyleFn("bold"),
63
+ commandName: createStyleFn("bold", "underline", "cyan"),
64
+ option: createStyleFn("cyan"),
65
+ optionName: createStyleFn("bold"),
66
+ placeholder: createStyleFn("dim"),
67
+ defaultValue: createStyleFn("dim"),
68
+ required: createStyleFn("yellow"),
69
+ description: (text) => text,
70
+ sectionHeader: createStyleFn("bold", "underline"),
71
+ version: createStyleFn("dim")
72
+ };
73
+ /**
74
+ * Standardized symbols for CLI output
75
+ */
76
+ const symbols = {
77
+ success: styles.green("✓"),
78
+ error: styles.red("✖"),
79
+ warning: styles.yellow("⚠"),
80
+ info: styles.cyan("ℹ"),
81
+ bullet: styles.gray("•"),
82
+ arrow: styles.gray("→")
83
+ };
84
+ /**
85
+ * Logger for CLI output
86
+ */
87
+ const logger = {
88
+ /**
89
+ * Log informational message
90
+ */
91
+ info(message) {
92
+ console.log(message);
93
+ },
94
+ /**
95
+ * Log success message
96
+ */
97
+ success(message) {
98
+ console.log(`${symbols.success} ${styles.success(message)}`);
99
+ },
100
+ /**
101
+ * Log warning message
102
+ */
103
+ warn(message) {
104
+ console.warn(`${symbols.warning} ${styles.warning(message)}`);
105
+ },
106
+ /**
107
+ * Log error message
108
+ */
109
+ error(message) {
110
+ console.error(`${symbols.error} ${styles.error(message)}`);
111
+ },
112
+ /**
113
+ * Log raw message without prefix
114
+ */
115
+ log(message) {
116
+ console.log(message);
117
+ },
118
+ /**
119
+ * Log empty line
120
+ */
121
+ newline() {
122
+ console.log("");
123
+ },
124
+ /**
125
+ * Log debug message with dim color
126
+ */
127
+ debug(message) {
128
+ console.log(styles.dim(message));
129
+ }
130
+ };
131
+
132
+ //#endregion
133
+ export { symbols as a, styles as i, logger as n, setColorEnabled as r, isColorEnabled as t };
@@ -0,0 +1,171 @@
1
+ //#region ../core/src/prompt/prompt-resolver.ts
2
+ /**
3
+ * Resolve prompt configuration for a field.
4
+ *
5
+ * Priority for prompt type:
6
+ * 1. Explicit type from prompt.type
7
+ * 2. Explicit choices from prompt.choices (forces "select")
8
+ * 3. Inherited from completion metadata (file/directory -> "text")
9
+ * 4. Auto-detected from the extracted field type (adapter-provided):
10
+ * - enum (has enumValues) -> "select"
11
+ * - boolean -> "confirm"
12
+ * - string/number/unknown -> "text"
13
+ *
14
+ * Returns null if the field has no prompt metadata or prompting is disabled.
15
+ */
16
+ function resolvePromptConfig(field) {
17
+ const promptMeta = field.prompt;
18
+ if (!promptMeta || promptMeta.enabled === false) return null;
19
+ const message = promptMeta.message ?? field.description ?? field.name;
20
+ const rawType = resolvePromptType(field, promptMeta);
21
+ const choices = resolveChoices(field, promptMeta, rawType);
22
+ return {
23
+ field,
24
+ type: rawType === "select" && !choices ? "text" : rawType,
25
+ message,
26
+ ...choices && { choices }
27
+ };
28
+ }
29
+ function hasChoices(list) {
30
+ return list !== void 0 && list.length > 0;
31
+ }
32
+ function resolvePromptType(field, promptMeta) {
33
+ if (promptMeta.type) return promptMeta.type === "file" || promptMeta.type === "directory" ? "text" : promptMeta.type;
34
+ if (hasChoices(promptMeta.choices)) return "select";
35
+ if (field.completion?.type === "file" || field.completion?.type === "directory") return "text";
36
+ if (hasChoices(field.enumValues)) return "select";
37
+ if (field.type === "boolean") return "confirm";
38
+ return "text";
39
+ }
40
+ function resolveChoices(field, promptMeta, type) {
41
+ if (hasChoices(promptMeta.choices)) return promptMeta.choices.map((c) => typeof c === "string" ? {
42
+ label: c,
43
+ value: c
44
+ } : c);
45
+ if (type === "select" && hasChoices(field.enumValues)) return field.enumValues.map((v) => ({
46
+ label: v,
47
+ value: v
48
+ }));
49
+ }
50
+ /**
51
+ * Filter fields that need prompting (missing value + prompt configured).
52
+ *
53
+ * For discriminatedUnion schemas, variant-aware narrowing is handled by the
54
+ * caller (promptMissingArgs) which prompts the discriminator first and then
55
+ * passes only the active variant's fields. For plain union schemas, this
56
+ * iterates all fields across every variant without narrowing.
57
+ *
58
+ * Fields with Zod defaults that also have prompt metadata will be prompted
59
+ * when the raw value is undefined. This is intentional: `prompt: {}` is an
60
+ * explicit opt-in to interactive input. Omit prompt metadata to let the
61
+ * default apply silently.
62
+ */
63
+ function getFieldsToPrompt(fields, rawArgs) {
64
+ const configs = [];
65
+ for (const field of fields) {
66
+ if (rawArgs[field.name] !== void 0) continue;
67
+ if (field.type === "array") continue;
68
+ const config = resolvePromptConfig(field);
69
+ if (config) configs.push(config);
70
+ }
71
+ return configs;
72
+ }
73
+
74
+ //#endregion
75
+ //#region ../core/src/prompt/tty-detector.ts
76
+ /**
77
+ * Detect whether the current environment supports interactive prompts.
78
+ * Returns false in CI, piped input, or non-TTY environments.
79
+ */
80
+ function isInteractive() {
81
+ if (!process.stdin.isTTY) return false;
82
+ if (!process.stdout.isTTY) return false;
83
+ if (process.env.CI) return false;
84
+ if (process.env.POLITTY_NO_PROMPT) return false;
85
+ return true;
86
+ }
87
+
88
+ //#endregion
89
+ //#region ../core/src/prompt/index.ts
90
+ /**
91
+ * Prompt for missing argument values interactively.
92
+ *
93
+ * Only prompts for fields that have `prompt` metadata set via `arg()` and
94
+ * whose values are still undefined after CLI and env resolution.
95
+ * Returns rawArgs unchanged in non-interactive environments.
96
+ */
97
+ async function promptMissingArgs(rawArgs, extracted, options) {
98
+ if (!(options.interactive ?? isInteractive())) return rawArgs;
99
+ const adapter = options.adapter;
100
+ const result = { ...rawArgs };
101
+ if (extracted.schemaType === "discriminatedUnion" && extracted.discriminator && extracted.variants) await promptDiscriminatedUnion(adapter, result, extracted);
102
+ else if (extracted.schemaType === "union" || extracted.schemaType === "xor") {} else await promptAllFields(adapter, result, extracted.fields);
103
+ return result;
104
+ }
105
+ async function promptDiscriminatedUnion(adapter, result, extracted) {
106
+ const { discriminator, variants } = extracted;
107
+ if (!discriminator || !variants) return;
108
+ if (result[discriminator] === void 0) {
109
+ const discField = findDiscriminatorField(extracted.fields, variants, discriminator);
110
+ const discConfig = discField ? resolvePromptConfig(discField) : null;
111
+ if (discConfig) {
112
+ const allValues = variants.map((v) => v.discriminatorValue).filter(Boolean);
113
+ if (allValues.length > 0) {
114
+ discConfig.type = "select";
115
+ discConfig.choices = allValues.map((v) => ({
116
+ label: v,
117
+ value: v
118
+ }));
119
+ }
120
+ await promptAndCollect(adapter, result, discConfig);
121
+ }
122
+ }
123
+ const discValue = String(result[discriminator] ?? "");
124
+ const activeVariant = variants.find((v) => v.discriminatorValue === discValue);
125
+ if (activeVariant) await promptAllFields(adapter, result, activeVariant.fields.filter((f) => f.name !== discriminator));
126
+ }
127
+ /**
128
+ * Find the discriminator field with prompt metadata, checking the
129
+ * deduplicated top-level fields first, then scanning per-variant fields.
130
+ */
131
+ function findDiscriminatorField(fields, variants, discriminator) {
132
+ const topLevel = fields.find((f) => f.name === discriminator);
133
+ if (topLevel?.prompt) return topLevel;
134
+ for (const variant of variants) {
135
+ const field = variant.fields.find((f) => f.name === discriminator);
136
+ if (field?.prompt) return field;
137
+ }
138
+ }
139
+ async function promptAllFields(adapter, result, fields) {
140
+ const fieldsToPrompt = getFieldsToPrompt(fields, result);
141
+ for (const config of fieldsToPrompt) await promptAndCollect(adapter, result, config);
142
+ }
143
+ async function promptAndCollect(adapter, result, config) {
144
+ const { message } = config;
145
+ let value;
146
+ switch (config.type) {
147
+ case "text":
148
+ value = await adapter.text({
149
+ message,
150
+ placeholder: config.field.placeholder
151
+ });
152
+ break;
153
+ case "password":
154
+ value = await adapter.password({ message });
155
+ break;
156
+ case "confirm":
157
+ value = await adapter.confirm({ message });
158
+ break;
159
+ case "select":
160
+ value = await adapter.select({
161
+ message,
162
+ options: config.choices ?? []
163
+ });
164
+ break;
165
+ }
166
+ if (adapter.isCancelled(value)) throw new Error("Prompt cancelled by user");
167
+ result[config.field.name] = value;
168
+ }
169
+
170
+ //#endregion
171
+ export { resolvePromptConfig as i, isInteractive as n, getFieldsToPrompt as r, promptMissingArgs as t };
@@ -0,0 +1,16 @@
1
+ import { I as PromptResolver } from "./arg-registry-YaWTVu_x.js";
2
+ //#region ../core/src/prompt/clack/index.d.ts
3
+ /**
4
+ * Prompt resolver backed by @clack/prompts.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { runMain, defineCommand } from "politty";
9
+ * import { prompt } from "politty/prompt/clack";
10
+ *
11
+ * runMain(cmd, { version: "1.0.0", prompt });
12
+ * ```
13
+ */
14
+ declare const prompt: PromptResolver;
15
+ //#endregion
16
+ export { prompt };
@@ -0,0 +1,32 @@
1
+ import "./register-Bk0K83W2.js";
2
+ import { t as promptMissingArgs } from "./prompt-CEIZ-7H1.js";
3
+ import { confirm, isCancel, password, select, text } from "@clack/prompts";
4
+
5
+ //#region ../core/src/prompt/clack/index.ts
6
+ function createClackAdapter() {
7
+ return {
8
+ text: (config) => text({
9
+ message: config.message,
10
+ ...config.placeholder !== void 0 && { placeholder: config.placeholder }
11
+ }),
12
+ password: (config) => password(config),
13
+ confirm: (config) => confirm(config),
14
+ select: (config) => select(config),
15
+ isCancelled: isCancel
16
+ };
17
+ }
18
+ /**
19
+ * Prompt resolver backed by @clack/prompts.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { runMain, defineCommand } from "politty";
24
+ * import { prompt } from "politty/prompt/clack";
25
+ *
26
+ * runMain(cmd, { version: "1.0.0", prompt });
27
+ * ```
28
+ */
29
+ const prompt = (rawArgs, extracted) => promptMissingArgs(rawArgs, extracted, { adapter: createClackAdapter() });
30
+
31
+ //#endregion
32
+ export { prompt };
@@ -0,0 +1,16 @@
1
+ import { I as PromptResolver } from "./arg-registry-YaWTVu_x.js";
2
+ //#region ../core/src/prompt/inquirer/index.d.ts
3
+ /**
4
+ * Prompt resolver backed by @inquirer/prompts.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { runMain, defineCommand } from "politty";
9
+ * import { prompt } from "politty/prompt/inquirer";
10
+ *
11
+ * runMain(cmd, { version: "1.0.0", prompt });
12
+ * ```
13
+ */
14
+ declare const prompt: PromptResolver;
15
+ //#endregion
16
+ export { prompt };
@@ -0,0 +1,47 @@
1
+ import "./register-Bk0K83W2.js";
2
+ import { t as promptMissingArgs } from "./prompt-CEIZ-7H1.js";
3
+ import { confirm, input, password, select } from "@inquirer/prompts";
4
+
5
+ //#region ../core/src/prompt/inquirer/index.ts
6
+ const cancelSymbol = Symbol("inquirer-cancel");
7
+ async function wrapCancellation(fn) {
8
+ try {
9
+ return await fn();
10
+ } catch (error) {
11
+ if (error instanceof Error && error.name === "ExitPromptError") return cancelSymbol;
12
+ throw error;
13
+ }
14
+ }
15
+ function createInquirerAdapter() {
16
+ return {
17
+ text: (config) => wrapCancellation(() => input({
18
+ message: config.message,
19
+ ...config.placeholder !== void 0 && { default: config.placeholder }
20
+ })),
21
+ password: (config) => wrapCancellation(() => password({ message: config.message })),
22
+ confirm: (config) => wrapCancellation(() => confirm({ message: config.message })),
23
+ select: (config) => wrapCancellation(() => select({
24
+ message: config.message,
25
+ choices: config.options.map((o) => ({
26
+ name: o.label,
27
+ value: o.value
28
+ }))
29
+ })),
30
+ isCancelled: (value) => value === cancelSymbol
31
+ };
32
+ }
33
+ /**
34
+ * Prompt resolver backed by @inquirer/prompts.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { runMain, defineCommand } from "politty";
39
+ * import { prompt } from "politty/prompt/inquirer";
40
+ *
41
+ * runMain(cmd, { version: "1.0.0", prompt });
42
+ * ```
43
+ */
44
+ const prompt = (rawArgs, extracted) => promptMissingArgs(rawArgs, extracted, { adapter: createInquirerAdapter() });
45
+
46
+ //#endregion
47
+ export { prompt };
@@ -0,0 +1,106 @@
1
+ import { X as ResolvedFieldMeta, Y as ExtractedFields } from "./arg-registry-YaWTVu_x.js";
2
+ //#region ../core/src/prompt/types.d.ts
3
+ /**
4
+ * Resolved prompt configuration for a single field
5
+ */
6
+ interface ResolvedPromptConfig {
7
+ /** Field metadata */
8
+ field: ResolvedFieldMeta;
9
+ /** Resolved prompt type */
10
+ type: "text" | "password" | "confirm" | "select";
11
+ /** Message to display to the user */
12
+ message: string;
13
+ /** Choices for select prompts */
14
+ choices?: Array<{
15
+ label: string;
16
+ value: string;
17
+ }>;
18
+ }
19
+ /**
20
+ * Adapter interface for prompt rendering.
21
+ * Implement this to use a custom prompt library instead of the default @clack/prompts.
22
+ */
23
+ interface PromptAdapter {
24
+ /** Prompt for free-form text input */
25
+ text(config: {
26
+ message: string;
27
+ placeholder?: string | undefined;
28
+ }): Promise<string | symbol>;
29
+ /** Prompt for masked text input */
30
+ password(config: {
31
+ message: string;
32
+ }): Promise<string | symbol>;
33
+ /** Prompt for yes/no confirmation */
34
+ confirm(config: {
35
+ message: string;
36
+ }): Promise<boolean | symbol>;
37
+ /** Prompt for single selection from options */
38
+ select(config: {
39
+ message: string;
40
+ options: Array<{
41
+ label: string;
42
+ value: string;
43
+ }>;
44
+ }): Promise<string | symbol>;
45
+ /** Check if a prompt result indicates user cancellation */
46
+ isCancelled(value: unknown): boolean;
47
+ }
48
+ //#endregion
49
+ //#region ../core/src/prompt/prompt-resolver.d.ts
50
+ /**
51
+ * Resolve prompt configuration for a field.
52
+ *
53
+ * Priority for prompt type:
54
+ * 1. Explicit type from prompt.type
55
+ * 2. Explicit choices from prompt.choices (forces "select")
56
+ * 3. Inherited from completion metadata (file/directory -> "text")
57
+ * 4. Auto-detected from the extracted field type (adapter-provided):
58
+ * - enum (has enumValues) -> "select"
59
+ * - boolean -> "confirm"
60
+ * - string/number/unknown -> "text"
61
+ *
62
+ * Returns null if the field has no prompt metadata or prompting is disabled.
63
+ */
64
+ declare function resolvePromptConfig(field: ResolvedFieldMeta): ResolvedPromptConfig | null;
65
+ /**
66
+ * Filter fields that need prompting (missing value + prompt configured).
67
+ *
68
+ * For discriminatedUnion schemas, variant-aware narrowing is handled by the
69
+ * caller (promptMissingArgs) which prompts the discriminator first and then
70
+ * passes only the active variant's fields. For plain union schemas, this
71
+ * iterates all fields across every variant without narrowing.
72
+ *
73
+ * Fields with Zod defaults that also have prompt metadata will be prompted
74
+ * when the raw value is undefined. This is intentional: `prompt: {}` is an
75
+ * explicit opt-in to interactive input. Omit prompt metadata to let the
76
+ * default apply silently.
77
+ */
78
+ declare function getFieldsToPrompt(fields: ResolvedFieldMeta[], rawArgs: Record<string, unknown>): ResolvedPromptConfig[];
79
+ //#endregion
80
+ //#region ../core/src/prompt/tty-detector.d.ts
81
+ /**
82
+ * Detect whether the current environment supports interactive prompts.
83
+ * Returns false in CI, piped input, or non-TTY environments.
84
+ */
85
+ declare function isInteractive(): boolean;
86
+ //#endregion
87
+ //#region ../core/src/prompt/index.d.ts
88
+ /**
89
+ * Options for promptMissingArgs behavior
90
+ */
91
+ interface PromptOptions {
92
+ /** Prompt adapter to use for rendering prompts */
93
+ adapter: PromptAdapter;
94
+ /** Override interactive detection (force enable/disable prompts) */
95
+ interactive?: boolean;
96
+ }
97
+ /**
98
+ * Prompt for missing argument values interactively.
99
+ *
100
+ * Only prompts for fields that have `prompt` metadata set via `arg()` and
101
+ * whose values are still undefined after CLI and env resolution.
102
+ * Returns rawArgs unchanged in non-interactive environments.
103
+ */
104
+ declare function promptMissingArgs(rawArgs: Record<string, unknown>, extracted: ExtractedFields, options: PromptOptions): Promise<Record<string, unknown>>;
105
+ //#endregion
106
+ export { type PromptAdapter, PromptOptions, type ResolvedPromptConfig, getFieldsToPrompt, isInteractive, promptMissingArgs, resolvePromptConfig };
package/dist/prompt.js ADDED
@@ -0,0 +1,4 @@
1
+ import "./register-Bk0K83W2.js";
2
+ import { i as resolvePromptConfig, n as isInteractive, r as getFieldsToPrompt, t as promptMissingArgs } from "./prompt-CEIZ-7H1.js";
3
+
4
+ export { getFieldsToPrompt, isInteractive, promptMissingArgs, resolvePromptConfig };