politty 0.11.6 → 0.11.7

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 (50) hide show
  1. package/README.md +30 -1
  2. package/dist/augment.d.ts +1 -16
  3. package/dist/augment.js +2 -0
  4. package/dist/cli-run-DGe88d0G.js +14 -0
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.js +13 -9
  7. package/dist/compile-cache.d.ts +1 -79
  8. package/dist/compile-cache.js +2 -2
  9. package/dist/completion.d.ts +1 -0
  10. package/dist/completion.js +3 -0
  11. package/dist/docs.d.ts +1 -0
  12. package/dist/docs.js +3 -0
  13. package/dist/index.d.ts +10 -814
  14. package/dist/index.js +17 -8
  15. package/dist/prompt-clack.d.ts +1 -0
  16. package/dist/prompt-clack.js +3 -0
  17. package/dist/prompt-inquirer.d.ts +1 -0
  18. package/dist/prompt-inquirer.js +3 -0
  19. package/dist/prompt.d.ts +1 -0
  20. package/dist/prompt.js +3 -0
  21. package/dist/skill.d.ts +1 -0
  22. package/dist/skill.js +3 -0
  23. package/package.json +18 -45
  24. package/dist/arg-registry-SrNIsq-d.d.ts +0 -981
  25. package/dist/cli-main.d.ts +0 -1
  26. package/dist/cli-main.js +0 -86
  27. package/dist/command-B4yA4LXX.js +0 -43
  28. package/dist/compile-cache-NnTkjJMV.js +0 -101
  29. package/dist/completion/index.d.ts +0 -3
  30. package/dist/completion/index.js +0 -3
  31. package/dist/completion-D9SKGJad.js +0 -5610
  32. package/dist/docs/index.d.ts +0 -771
  33. package/dist/docs/index.js +0 -3024
  34. package/dist/index-qqwo5WZT.d.ts +0 -673
  35. package/dist/log-collector-DK32-73m.js +0 -115
  36. package/dist/logger-DbDkjdfO.js +0 -134
  37. package/dist/prompt/clack/index.d.ts +0 -17
  38. package/dist/prompt/clack/index.js +0 -32
  39. package/dist/prompt/index.d.ts +0 -107
  40. package/dist/prompt/index.js +0 -3
  41. package/dist/prompt/inquirer/index.d.ts +0 -17
  42. package/dist/prompt/inquirer/index.js +0 -47
  43. package/dist/prompt-Cc8Tfmdv.js +0 -172
  44. package/dist/runner-BGs_QMJM.js +0 -3
  45. package/dist/runner-xN7248Ph.js +0 -2966
  46. package/dist/schema-extractor-wzJ1cGon.js +0 -488
  47. package/dist/skill/index.d.ts +0 -584
  48. package/dist/skill/index.js +0 -1756
  49. package/dist/src-BiCtSNrn.js +0 -193
  50. package/dist/subcommand-router-CTzHPGzF.js +0 -135
@@ -1,488 +0,0 @@
1
- import { z } from "zod";
2
-
3
- //#region src/core/arg-registry.ts
4
- /**
5
- * Custom registry for politty argument metadata
6
- * This avoids polluting Zod's GlobalMeta
7
- */
8
- const argRegistry = z.registry();
9
- function arg(schema, meta) {
10
- if (meta) argRegistry.add(schema, meta);
11
- return schema;
12
- }
13
- /**
14
- * Get metadata for a schema from the registry
15
- *
16
- * @param schema - The Zod schema
17
- * @returns The metadata if registered, undefined otherwise
18
- */
19
- function getArgMeta$1(schema) {
20
- return argRegistry.get(schema);
21
- }
22
-
23
- //#endregion
24
- //#region src/core/schema-extractor.ts
25
- /**
26
- * Get ArgMeta from both the custom registry and Zod's _def
27
- * Priority: custom registry > _def.argMeta
28
- */
29
- function getArgMeta(schema) {
30
- const fromRegistry = getArgMeta$1(schema);
31
- if (fromRegistry) return fromRegistry;
32
- if (typeof schema.meta === "function") {
33
- const meta = schema.meta();
34
- if (meta && typeof meta === "object") return meta;
35
- }
36
- const def = schema._def;
37
- if (def?.argMeta) return def.argMeta;
38
- if (def?.meta) return def.meta;
39
- }
40
- /**
41
- * Long flag names reserved for built-in handling (parseArgs / scanForSubcommand
42
- * intercept these before option parsing), so custom negation names must avoid them.
43
- */
44
- const RESERVED_NEGATION_NAMES = /* @__PURE__ */ new Set([
45
- "help",
46
- "help-all",
47
- "version"
48
- ]);
49
- /**
50
- * Get the type name from a zod schema (v4 compatible)
51
- */
52
- function getTypeName(schema) {
53
- const s = schema;
54
- return s.def?.type ?? s._def?.type ?? s.type;
55
- }
56
- /**
57
- * Detect unknown keys handling mode from a Zod object schema
58
- *
59
- * In Zod v4:
60
- * - Default (strip): _def.catchall is undefined
61
- * - strict: _def.catchall is ZodNever (type = "never")
62
- * - passthrough: _def.catchall is ZodUnknown (type = "unknown")
63
- */
64
- function getUnknownKeysMode(schema) {
65
- const s = schema;
66
- const catchall = (s.def ?? s._def)?.catchall;
67
- if (!catchall) return "strip";
68
- const catchallType = getTypeName(catchall);
69
- if (catchallType === "never") return "strict";
70
- if (catchallType === "unknown" || catchallType === "any") return "passthrough";
71
- return "strip";
72
- }
73
- /**
74
- * Get the inner schema, unwrapping optional, nullable, default, etc.
75
- */
76
- function unwrapSchema(schema) {
77
- const typeName = getTypeName(schema);
78
- const s = schema;
79
- const def = s.def ?? s._def;
80
- if (typeName === "optional" || typeName === "nullable" || typeName === "default") {
81
- const innerSchema = def?.innerType;
82
- if (innerSchema) return unwrapSchema(innerSchema);
83
- }
84
- if (typeName === "pipe") {
85
- const innerSchema = def?.in ?? def?.schema;
86
- if (innerSchema) return unwrapSchema(innerSchema);
87
- }
88
- return schema;
89
- }
90
- /**
91
- * Detect the base type of a schema
92
- */
93
- function detectType(schema) {
94
- switch (getTypeName(unwrapSchema(schema))) {
95
- case "string":
96
- case "enum": return "string";
97
- case "number":
98
- case "int": return "number";
99
- case "boolean": return "boolean";
100
- case "array": return "array";
101
- default: return "unknown";
102
- }
103
- }
104
- /**
105
- * Extract enum values from a schema if it's an enum type
106
- *
107
- * @param schema - The Zod schema to extract enum values from
108
- * @returns Array of enum values if schema is an enum, undefined otherwise
109
- */
110
- function extractEnumValues(schema) {
111
- const innerSchema = unwrapSchema(schema);
112
- const typeName = getTypeName(innerSchema);
113
- const s = innerSchema;
114
- const def = s.def ?? s._def;
115
- if (typeName === "enum") {
116
- const entries = def?.entries;
117
- if (entries && typeof entries === "object") return Object.values(entries);
118
- const values = def?.values;
119
- if (Array.isArray(values)) return values;
120
- const options = s.options;
121
- if (Array.isArray(options)) return options;
122
- }
123
- if (typeName === "array") {
124
- const element = def?.element;
125
- if (element) return extractEnumValues(element);
126
- }
127
- if (typeName === "union") {
128
- const options = def?.options;
129
- if (Array.isArray(options)) {
130
- const literalValues = [];
131
- for (const option of options) if (getTypeName(option) === "literal") {
132
- const optionDef = option.def ?? option._def;
133
- const value = optionDef?.value;
134
- const values = optionDef?.values;
135
- const literalValue = value ?? values?.[0];
136
- if (typeof literalValue === "string") literalValues.push(literalValue);
137
- }
138
- if (literalValues.length === options.length && literalValues.length > 0) return literalValues;
139
- }
140
- }
141
- }
142
- /**
143
- * Convert camelCase to kebab-case
144
- * @example toKebabCase("dryRun") => "dry-run"
145
- * @example toKebabCase("outputDir") => "output-dir"
146
- * @example toKebabCase("XMLParser") => "xml-parser"
147
- */
148
- function toKebabCase(str) {
149
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
150
- }
151
- /**
152
- * Convert hyphen-separated sequences to camelCase.
153
- *
154
- * Replaces `-x` (hyphen followed by a lowercase letter) with the uppercase
155
- * variant. Non-hyphenated input (e.g., already camelCase) is returned as-is.
156
- *
157
- * @param str - A string that may contain hyphens
158
- * @example toCamelCase("dry-run") => "dryRun"
159
- * @example toCamelCase("output-dir") => "outputDir"
160
- * @example toCamelCase("dryRun") => "dryRun"
161
- */
162
- function toCamelCase(str) {
163
- return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
164
- }
165
- /**
166
- * Check if a schema is required (not optional or has default)
167
- *
168
- * Note: We only check isOptional(), not isNullable(), because CLI arguments
169
- * are either present (string value) or absent (undefined), never null.
170
- * Also, some coerce types incorrectly report isNullable()=true.
171
- */
172
- function isRequired(schema) {
173
- return !schema.isOptional();
174
- }
175
- /**
176
- * Extract default value from schema if present
177
- */
178
- function extractDefaultValue(schema) {
179
- const typeName = getTypeName(schema);
180
- const s = schema;
181
- const def = s.def ?? s._def;
182
- if (typeName === "default") {
183
- const defaultValue = def?.defaultValue;
184
- if (typeof defaultValue === "function") return defaultValue();
185
- return defaultValue;
186
- }
187
- if (typeName === "optional" || typeName === "nullable") {
188
- const innerSchema = def?.innerType;
189
- if (innerSchema) return extractDefaultValue(innerSchema);
190
- }
191
- }
192
- /**
193
- * Extract description from schema
194
- */
195
- function extractDescription(schema) {
196
- if (schema.description) return schema.description;
197
- const typeName = getTypeName(schema);
198
- const s = schema;
199
- const def = s.def ?? s._def;
200
- if (typeName === "optional" || typeName === "nullable" || typeName === "default") {
201
- const innerSchema = def?.innerType;
202
- if (innerSchema) return extractDescription(innerSchema);
203
- }
204
- }
205
- /**
206
- * Resolve field metadata from schema and argRegistry
207
- */
208
- function resolveFieldMeta(name, schema) {
209
- const argMeta = getArgMeta(schema) ?? getArgMeta(unwrapSchema(schema));
210
- const description = argMeta?.description ?? extractDescription(schema);
211
- const cliName = toKebabCase(name);
212
- const enumValues = extractEnumValues(schema);
213
- const aliasPattern = /^[A-Za-z0-9][A-Za-z0-9-]*$/;
214
- const normalizeAliasList = (input, metaKey) => {
215
- if (input == null) return void 0;
216
- const normalized = (Array.isArray(input) ? input : [input]).map((a) => {
217
- if (typeof a !== "string") throw new Error(`Invalid ${metaKey} for field "${name}": expected string or string[], received ${typeof a}.`);
218
- const candidate = a.trim().replace(/^-+/, "");
219
- if (candidate.length === 0 || !aliasPattern.test(candidate)) throw new Error(`Invalid ${metaKey} "${a}" for field "${name}": aliases must match ${aliasPattern}.`);
220
- return candidate;
221
- });
222
- const result = Array.from(new Set(normalized));
223
- return result.length > 0 ? result : void 0;
224
- };
225
- const alias = normalizeAliasList(argMeta?.alias, "alias");
226
- const visibleSet = new Set(alias ?? []);
227
- const hiddenAlias = normalizeAliasList(argMeta?.hiddenAlias, "hiddenAlias")?.filter((a) => !visibleSet.has(a));
228
- const hiddenAliasFinal = hiddenAlias && hiddenAlias.length > 0 ? hiddenAlias : void 0;
229
- const fieldType = detectType(schema);
230
- const rawNegation = argMeta?.negation;
231
- let negation;
232
- if (rawNegation !== void 0 && rawNegation !== null) if (typeof rawNegation === "boolean") {
233
- if (fieldType !== "boolean") throw new Error(`Invalid negation for field "${name}": negation can only be used on boolean fields.`);
234
- negation = rawNegation;
235
- } else {
236
- if (typeof rawNegation !== "string") throw new Error(`Invalid negation for field "${name}": expected string or boolean, received ${typeof rawNegation}.`);
237
- const candidate = rawNegation.trim().replace(/^-+/, "");
238
- if (candidate.length === 0 || !aliasPattern.test(candidate)) throw new Error(`Invalid negation "${rawNegation}" for field "${name}": negation names must match ${aliasPattern}.`);
239
- if (RESERVED_NEGATION_NAMES.has(candidate)) throw new Error(`Invalid negation "${rawNegation}" for field "${name}": negation cannot use reserved built-in flag names (${[...RESERVED_NEGATION_NAMES].map((n) => `--${n}`).join(", ")}).`);
240
- if (fieldType !== "boolean") throw new Error(`Invalid negation for field "${name}": negation can only be used on boolean fields.`);
241
- negation = candidate;
242
- }
243
- const rawNegationDescription = argMeta?.negationDescription;
244
- let negationDescription;
245
- if (rawNegationDescription !== void 0 && rawNegationDescription !== null) {
246
- if (typeof rawNegationDescription !== "string") throw new Error(`Invalid negationDescription for field "${name}": expected string, received ${typeof rawNegationDescription}.`);
247
- if (negation === false) throw new Error(`Invalid negationDescription for field "${name}": negationDescription cannot be used when negation is false.`);
248
- if (negation === void 0) throw new Error(`Invalid negationDescription for field "${name}": negationDescription requires \`negation\` to be set (string or true).`);
249
- const trimmed = rawNegationDescription.trim();
250
- if (trimmed.length === 0) throw new Error(`Invalid negationDescription for field "${name}": negationDescription must be a non-empty string.`);
251
- negationDescription = trimmed;
252
- }
253
- const negationDisplay = typeof negation === "string" ? negation : negation === true ? `no-${cliName}` : void 0;
254
- const meta = {
255
- name,
256
- cliName,
257
- alias,
258
- hiddenAlias: hiddenAliasFinal,
259
- description,
260
- positional: argMeta?.positional ?? false,
261
- placeholder: argMeta?.placeholder,
262
- env: argMeta?.env,
263
- required: isRequired(schema),
264
- defaultValue: extractDefaultValue(schema),
265
- type: fieldType,
266
- schema,
267
- enumValues,
268
- completion: argMeta?.completion,
269
- prompt: argMeta?.prompt,
270
- negation,
271
- negationDisplay,
272
- negationDescription,
273
- effect: argMeta?.effect
274
- };
275
- if (argMeta && "overrideBuiltinAlias" in argMeta && argMeta.overrideBuiltinAlias === true) meta.overrideBuiltinAlias = true;
276
- return meta;
277
- }
278
- /**
279
- * Get the combined list of visible + hidden aliases for a field.
280
- * Used by the parser and validators which treat both equally,
281
- * while help/docs/completion rely on `field.alias` only.
282
- */
283
- function getAllAliases(field) {
284
- if (!field.alias && !field.hiddenAlias) return [];
285
- return [...field.alias ?? [], ...field.hiddenAlias ?? []];
286
- }
287
- /**
288
- * Get shape from a ZodObject
289
- */
290
- function getObjectShape(schema) {
291
- const s = schema;
292
- return (s.def ?? s._def)?.shape ?? s.shape ?? {};
293
- }
294
- /**
295
- * Extract fields from a ZodObject
296
- */
297
- function extractFromObject(schema) {
298
- const shape = getObjectShape(schema);
299
- return Object.entries(shape).map(([name, fieldSchema]) => resolveFieldMeta(name, fieldSchema));
300
- }
301
- /**
302
- * Extract fields from a discriminated union
303
- */
304
- function extractFromDiscriminatedUnion(schema) {
305
- const s = schema;
306
- const def = s.def ?? s._def;
307
- const discriminator = def?.discriminator ?? "";
308
- const options = def?.options ?? [];
309
- const allFieldsMap = /* @__PURE__ */ new Map();
310
- const variants = [];
311
- for (const option of options) {
312
- const shape = getObjectShape(option);
313
- const variantFields = [];
314
- let discriminatorValue = "";
315
- const discriminatorSchema = shape[discriminator];
316
- if (discriminatorSchema) {
317
- const typeName = getTypeName(discriminatorSchema);
318
- if (typeName === "literal") {
319
- const litDef = discriminatorSchema.def ?? discriminatorSchema._def;
320
- const value = litDef?.value;
321
- const values = litDef?.values;
322
- discriminatorValue = String(value ?? values?.[0] ?? "");
323
- } else if (typeName === "enum") {
324
- const enumValues = extractEnumValues(discriminatorSchema);
325
- if (enumValues && enumValues.length === 1) discriminatorValue = enumValues[0];
326
- }
327
- }
328
- for (const [name, fieldSchema] of Object.entries(shape)) {
329
- const fieldMeta = resolveFieldMeta(name, fieldSchema);
330
- variantFields.push(fieldMeta);
331
- if (!allFieldsMap.has(name)) allFieldsMap.set(name, fieldMeta);
332
- }
333
- const variantDescription = extractDescription(option);
334
- variants.push({
335
- discriminatorValue,
336
- fields: variantFields,
337
- ...variantDescription ? { description: variantDescription } : {}
338
- });
339
- }
340
- const description = extractDescription(schema);
341
- return {
342
- fields: Array.from(allFieldsMap.values()),
343
- schema,
344
- schemaType: "discriminatedUnion",
345
- unknownKeysMode: getUnknownKeysMode(schema),
346
- discriminator,
347
- variants,
348
- ...description ? { description } : {}
349
- };
350
- }
351
- /**
352
- * Extract fields from a union-like schema (union or xor)
353
- */
354
- function extractFromUnionLike(schema, schemaType) {
355
- const s = schema;
356
- const options = (s.def ?? s._def)?.options ?? [];
357
- const allFieldsMap = /* @__PURE__ */ new Map();
358
- const unionOptions = [];
359
- for (const option of options) {
360
- const extracted = extractFields(option);
361
- unionOptions.push(extracted);
362
- for (const field of extracted.fields) if (!allFieldsMap.has(field.name)) allFieldsMap.set(field.name, field);
363
- }
364
- const description = extractDescription(schema);
365
- return {
366
- fields: Array.from(allFieldsMap.values()),
367
- schema,
368
- schemaType,
369
- unknownKeysMode: getUnknownKeysMode(schema),
370
- unionOptions,
371
- ...description ? { description } : {}
372
- };
373
- }
374
- /**
375
- * Extract fields from an intersection
376
- */
377
- function extractFromIntersection(schema) {
378
- const s = schema;
379
- const def = s.def ?? s._def;
380
- const left = def?.left;
381
- const right = def?.right;
382
- const allFieldsMap = /* @__PURE__ */ new Map();
383
- const extractSubFields = (subSchema) => {
384
- if (!subSchema) return;
385
- const extracted = extractFields(subSchema);
386
- for (const field of extracted.fields) if (!allFieldsMap.has(field.name)) allFieldsMap.set(field.name, field);
387
- };
388
- extractSubFields(left);
389
- extractSubFields(right);
390
- const description = extractDescription(schema);
391
- return {
392
- fields: Array.from(allFieldsMap.values()),
393
- schema,
394
- schemaType: "intersection",
395
- unknownKeysMode: getUnknownKeysMode(schema),
396
- ...description ? { description } : {}
397
- };
398
- }
399
- /**
400
- * Cache for extractFields results to avoid redundant schema extraction
401
- */
402
- const extractFieldsCache = /* @__PURE__ */ new WeakMap();
403
- /**
404
- * Extract all fields from a schema
405
- *
406
- * @param schema - The args schema (ZodObject, ZodDiscriminatedUnion, etc.)
407
- * @returns Extracted field information
408
- */
409
- function extractFields(schema) {
410
- const cached = extractFieldsCache.get(schema);
411
- if (cached) return cached;
412
- let result;
413
- const typeName = getTypeName(schema);
414
- const s = schema;
415
- const def = s.def ?? s._def;
416
- switch (typeName) {
417
- case "object": {
418
- const description = extractDescription(schema);
419
- result = {
420
- fields: extractFromObject(schema),
421
- schema,
422
- schemaType: "object",
423
- unknownKeysMode: getUnknownKeysMode(schema),
424
- ...description ? { description } : {}
425
- };
426
- break;
427
- }
428
- case "union":
429
- if (def?.discriminator) result = extractFromDiscriminatedUnion(schema);
430
- else result = extractFromUnionLike(schema, "union");
431
- break;
432
- case "xor":
433
- result = extractFromUnionLike(schema, "xor");
434
- break;
435
- case "intersection":
436
- result = extractFromIntersection(schema);
437
- break;
438
- case "pipe": {
439
- const pipeInner = def?.in ?? def?.schema;
440
- if (pipeInner) {
441
- const innerResult = extractFields(pipeInner);
442
- const pipeDescription = extractDescription(schema);
443
- result = {
444
- ...innerResult,
445
- schema,
446
- ...pipeDescription ? { description: pipeDescription } : {}
447
- };
448
- break;
449
- }
450
- const pipeDescription = extractDescription(schema);
451
- result = {
452
- fields: [],
453
- schema,
454
- schemaType: "object",
455
- unknownKeysMode: getUnknownKeysMode(schema),
456
- ...pipeDescription ? { description: pipeDescription } : {}
457
- };
458
- break;
459
- }
460
- default: {
461
- const description = extractDescription(schema);
462
- result = {
463
- fields: [],
464
- schema,
465
- schemaType: "object",
466
- unknownKeysMode: getUnknownKeysMode(schema),
467
- ...description ? { description } : {}
468
- };
469
- break;
470
- }
471
- }
472
- extractFieldsCache.set(schema, result);
473
- return result;
474
- }
475
- /**
476
- * Get extracted fields from a command
477
- *
478
- * @param command - The command to extract fields from
479
- * @returns Extracted field information, or null if command has no args schema
480
- */
481
- function getExtractedFields(command) {
482
- if (!command.args) return null;
483
- return extractFields(command.args);
484
- }
485
-
486
- //#endregion
487
- export { toCamelCase as a, getUnknownKeysMode as i, getAllAliases as n, toKebabCase as o, getExtractedFields as r, arg as s, extractFields as t };
488
- //# sourceMappingURL=schema-extractor-wzJ1cGon.js.map