politty 0.4.0 → 0.4.1

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 (39) hide show
  1. package/dist/completion/index.cjs +4 -3
  2. package/dist/completion/index.cjs.map +1 -1
  3. package/dist/completion/index.d.cts +2 -2
  4. package/dist/completion/index.d.cts.map +1 -1
  5. package/dist/completion/index.d.ts +2 -2
  6. package/dist/completion/index.d.ts.map +1 -1
  7. package/dist/completion/index.js +3 -3
  8. package/dist/completion/index.js.map +1 -1
  9. package/dist/docs/index.cjs +2 -2
  10. package/dist/docs/index.js +2 -2
  11. package/dist/{extractor-JfoYSoMk.js → extractor-DO-FDKkW.js} +397 -295
  12. package/dist/extractor-DO-FDKkW.js.map +1 -0
  13. package/dist/{extractor-CqfDnGKd.cjs → extractor-cjruDqQ2.cjs} +404 -296
  14. package/dist/extractor-cjruDqQ2.cjs.map +1 -0
  15. package/dist/index.cjs +3 -3
  16. package/dist/index.d.cts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +3 -3
  19. package/dist/{runner-9dLE13Dv.cjs → runner-0yr2HFay.cjs} +2 -2
  20. package/dist/{runner-9dLE13Dv.cjs.map → runner-0yr2HFay.cjs.map} +1 -1
  21. package/dist/{runner-LJRI4haB.js → runner-BoZpJtIR.js} +2 -2
  22. package/dist/{runner-LJRI4haB.js.map → runner-BoZpJtIR.js.map} +1 -1
  23. package/dist/schema-extractor-CHiBRT39.d.ts.map +1 -1
  24. package/dist/{schema-extractor-CP3ar0Wi.js → schema-extractor-DAkmmrOy.js} +5 -1
  25. package/dist/schema-extractor-DAkmmrOy.js.map +1 -0
  26. package/dist/schema-extractor-DyfK21m_.d.cts.map +1 -1
  27. package/dist/{schema-extractor-Cv7ipqLS.cjs → schema-extractor-Mk1MHBkQ.cjs} +5 -1
  28. package/dist/schema-extractor-Mk1MHBkQ.cjs.map +1 -0
  29. package/dist/{extractor-DsJ6hYqQ.d.cts → value-completion-resolver-0xf8_07p.d.cts} +56 -11
  30. package/dist/value-completion-resolver-0xf8_07p.d.cts.map +1 -0
  31. package/dist/{extractor-CCi4rjSI.d.ts → value-completion-resolver-CUKbibx-.d.ts} +56 -11
  32. package/dist/value-completion-resolver-CUKbibx-.d.ts.map +1 -0
  33. package/package.json +6 -5
  34. package/dist/extractor-CCi4rjSI.d.ts.map +0 -1
  35. package/dist/extractor-CqfDnGKd.cjs.map +0 -1
  36. package/dist/extractor-DsJ6hYqQ.d.cts.map +0 -1
  37. package/dist/extractor-JfoYSoMk.js.map +0 -1
  38. package/dist/schema-extractor-CP3ar0Wi.js.map +0 -1
  39. package/dist/schema-extractor-Cv7ipqLS.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor-DO-FDKkW.js","names":["extractOptions"],"sources":["../src/core/command.ts","../src/completion/bash.ts","../src/completion/dynamic/candidate-generator.ts","../src/completion/value-completion-resolver.ts","../src/completion/dynamic/context-parser.ts","../src/completion/dynamic/shell-formatter.ts","../src/completion/dynamic/complete-command.ts","../src/completion/fish.ts","../src/completion/zsh.ts","../src/completion/extractor.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type {\n ArgsSchema,\n Command,\n Example,\n NonRunnableCommand,\n RunnableCommand,\n SubCommandsRecord,\n} from \"../types.js\";\n\n/**\n * Infer args type from schema, defaults to empty object if undefined\n */\ntype InferArgs<TArgsSchema> = TArgsSchema extends z.ZodType\n ? z.infer<TArgsSchema>\n : Record<string, never>;\n\n/**\n * Config for defining a command\n * @template TArgsSchema - The Zod schema type for arguments\n * @template TResult - The return type of run function (void if no run)\n */\ninterface DefineCommandConfig<TArgsSchema extends ArgsSchema | undefined, TResult> {\n name: string;\n description?: string;\n args?: TArgsSchema;\n subCommands?: SubCommandsRecord;\n setup?: (context: { args: InferArgs<TArgsSchema> }) => void | Promise<void>;\n run?: (args: InferArgs<TArgsSchema>) => TResult;\n cleanup?: (context: {\n args: InferArgs<TArgsSchema>;\n error?: Error | undefined;\n }) => void | Promise<void>;\n notes?: string;\n examples?: Example[];\n}\n\n/**\n * Config with run function (runnable command)\n */\ninterface RunnableConfig<\n TArgsSchema extends ArgsSchema | undefined,\n TResult,\n> extends DefineCommandConfig<TArgsSchema, TResult> {\n run: (args: InferArgs<TArgsSchema>) => TResult;\n}\n\n/**\n * Config without run function (non-runnable command)\n */\ninterface NonRunnableConfig<TArgsSchema extends ArgsSchema | undefined> extends Omit<\n DefineCommandConfig<TArgsSchema, void>,\n \"run\"\n> {\n run?: undefined;\n}\n\n/**\n * Define a CLI command with type-safe arguments\n *\n * @param config - Command configuration\n * @returns A defined command with preserved type information\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { arg, defineCommand } from \"politty\";\n *\n * const command = defineCommand({\n * name: \"greet\",\n * args: z.object({\n * name: arg(z.string(), { description: \"Name to greet\", positional: true }),\n * loud: arg(z.boolean().default(false), { alias: \"l\", description: \"Use uppercase\" }),\n * }),\n * run: (args) => {\n * const greeting = `Hello, ${args.name}!`;\n * console.log(args.loud ? greeting.toUpperCase() : greeting);\n * },\n * });\n *\n * // Type of command.argsSchema is preserved as z.ZodObject<...>\n * // Type of command.run is (args: { name: string; loud: boolean }) => void\n * ```\n *\n * @example\n * ```ts\n * // With discriminated union for subcommand-like behavior\n * const command = defineCommand({\n * name: \"resource\",\n * args: z.discriminatedUnion(\"action\", [\n * z.object({\n * action: z.literal(\"create\"),\n * name: arg(z.string(), { description: \"Resource name\" }),\n * }),\n * z.object({\n * action: z.literal(\"delete\"),\n * id: arg(z.coerce.number(), { description: \"Resource ID\" }),\n * }),\n * ]),\n * run: (args) => {\n * if (args.action === \"create\") {\n * console.log(`Creating ${args.name}`);\n * } else {\n * console.log(`Deleting ${args.id}`);\n * }\n * },\n * });\n * ```\n */\n// Overload 1: with run function - returns RunnableCommand with preserved schema type\nexport function defineCommand<\n TArgsSchema extends ArgsSchema | undefined = undefined,\n TResult = void,\n>(\n config: RunnableConfig<TArgsSchema, TResult>,\n): RunnableCommand<TArgsSchema, InferArgs<TArgsSchema>, TResult>;\n\n// Overload 2: without run function - returns NonRunnableCommand with preserved schema type\nexport function defineCommand<TArgsSchema extends ArgsSchema | undefined = undefined>(\n config: NonRunnableConfig<TArgsSchema>,\n): NonRunnableCommand<TArgsSchema, InferArgs<TArgsSchema>>;\n\n// Implementation\nexport function defineCommand<\n TArgsSchema extends ArgsSchema | undefined = undefined,\n TResult = void,\n>(\n config: RunnableConfig<TArgsSchema, TResult> | NonRunnableConfig<TArgsSchema>,\n): Command<TArgsSchema, InferArgs<TArgsSchema>, TResult> {\n return {\n name: config.name,\n description: config.description,\n args: config.args as TArgsSchema,\n subCommands: config.subCommands,\n setup: config.setup,\n run: config.run,\n cleanup: config.cleanup,\n notes: config.notes,\n examples: config.examples,\n } as Command<TArgsSchema, InferArgs<TArgsSchema>, TResult>;\n}\n","/**\n * Bash completion script generator (dynamic)\n */\n\nimport type { AnyCommand } from \"../types.js\";\nimport type { CompletionOptions, CompletionResult } from \"./types.js\";\n\n/**\n * Generate bash completion script for a command\n *\n * Generates a minimal script that delegates all logic to the CLI's __complete command.\n * The shell script only handles:\n * - Getting current command line tokens\n * - Calling __complete with --shell bash\n * - Setting COMPREPLY from the output\n * - Falling back to native file/directory completion when directed\n */\nexport function generateBashCompletion(\n _command: AnyCommand,\n options: CompletionOptions,\n): CompletionResult {\n const programName = options.programName;\n\n return {\n script: `# Bash completion for ${programName}\n# Generated by politty\n\n_${programName}_completions() {\n COMPREPLY=()\n local IFS=$'\\\\n'\n\n # Rejoin words split by '=' in COMP_WORDBREAKS (e.g. --opt=value)\n local -a _words=()\n local _i=1\n while (( _i <= COMP_CWORD )); do\n if [[ \"\\${COMP_WORDS[_i]}\" == \"=\" && \\${#_words[@]} -gt 0 ]]; then\n _words[\\${#_words[@]}-1]+=\"=\\${COMP_WORDS[_i+1]:-}\"\n (( _i += 2 ))\n else\n _words+=(\"\\${COMP_WORDS[_i]}\")\n (( _i++ ))\n fi\n done\n\n local lines prev_opts=\"$-\"\n set -f\n lines=($(${programName} __complete --shell bash -- \"\\${_words[@]}\" 2>/dev/null))\n [[ \"$prev_opts\" != *f* ]] && set +f\n\n local count=\\${#lines[@]}\n if (( count == 0 )); then\n return 0\n fi\n\n local last=\"\\${lines[count-1]}\"\n local directive=0\n if [[ \"$last\" == :* ]]; then\n directive=\"\\${last:1}\"\n unset 'lines[count-1]'\n (( count-- ))\n fi\n\n # Parse @ext: metadata (extension filter for native file completion)\n local extensions=\"\"\n if (( count > 0 )); then\n local maybe_ext=\"\\${lines[count-1]}\"\n if [[ \"$maybe_ext\" == @ext:* ]]; then\n extensions=\"\\${maybe_ext:5}\"\n unset 'lines[count-1]'\n fi\n fi\n\n local cur=\"\"\n (( \\${#_words[@]} > 0 )) && cur=\"\\${_words[\\${#_words[@]}-1]}\"\n\n # Strip --opt= prefix for native file/directory completion\n local inline_prefix=\"\"\n if [[ \"$cur\" == --*=* ]]; then\n inline_prefix=\"\\${cur%%=*}=\"\n cur=\"\\${cur#*=}\"\n fi\n\n # 16 = FileCompletion: delegate entirely to native file completion\n if (( directive & 16 )); then\n local -a entries=($(compgen -f -- \"$cur\"))\n if [[ -n \"$inline_prefix\" ]]; then\n local i\n for (( i=0; i<\\${#entries[@]}; i++ )); do\n entries[$i]=\"\\${inline_prefix}\\${entries[$i]}\"\n done\n fi\n COMPREPLY=(\"\\${entries[@]}\")\n compopt -o filenames\n return 0\n fi\n\n # Extension-filtered file completion: keep matching files + directories\n if [[ -n \"$extensions\" ]]; then\n local -a all_entries=($(compgen -f -- \"$cur\"))\n local IFS=','\n local -a ext_arr=($extensions)\n IFS=$'\\\\n'\n for f in \"\\${all_entries[@]}\"; do\n if [[ -d \"$f\" ]]; then\n COMPREPLY+=(\"\\${inline_prefix}$f\")\n else\n for ext in \"\\${ext_arr[@]}\"; do\n if [[ \"$f\" == *\".$ext\" ]]; then\n COMPREPLY+=(\"\\${inline_prefix}$f\")\n break\n fi\n done\n fi\n done\n compopt -o filenames\n compopt +o default 2>/dev/null\n return 0\n fi\n\n # Start with JS candidates\n if (( \\${#lines[@]} > 0 )); then\n COMPREPLY=(\"\\${lines[@]}\")\n fi\n\n # 32 = DirectoryCompletion: merge native directory matches\n if (( directive & 32 )); then\n local -a dirs=($(compgen -d -- \"$cur\"))\n if [[ -n \"$inline_prefix\" ]]; then\n local i\n for (( i=0; i<\\${#dirs[@]}; i++ )); do\n dirs[$i]=\"\\${inline_prefix}\\${dirs[$i]}\"\n done\n fi\n COMPREPLY+=(\"\\${dirs[@]}\")\n compopt -o filenames\n fi\n\n # 2 = NoFileCompletion, 32 = DirectoryCompletion:\n # suppress -o default file fallback when completions are restricted\n if (( directive & 2 )) || (( directive & 32 )); then\n compopt +o default 2>/dev/null\n fi\n\n return 0\n}\n\n# Register the completion function\ncomplete -o default -F _${programName}_completions ${programName}\n`,\n shell: \"bash\",\n installInstructions: `# To enable completions, add the following to your ~/.bashrc:\n\n# Option 1: Source directly\neval \"$(${programName} completion bash)\"\n\n# Option 2: Save to a file\n${programName} completion bash > ~/.local/share/bash-completion/completions/${programName}\n\n# Then reload your shell or run:\nsource ~/.bashrc`,\n };\n}\n","/**\n * Generate completion candidates based on context\n */\n\nimport { execSync } from \"node:child_process\";\nimport type { CompletionContext } from \"./context-parser.js\";\n\n/**\n * Completion directive flags (bitwise)\n */\nexport const CompletionDirective = {\n /** Default completion behavior */\n Default: 0,\n /** Don't add space after completion */\n NoSpace: 1,\n /** Don't offer file completion (even if no other completions) */\n NoFileCompletion: 2,\n /** Filter completions using current word as prefix */\n FilterPrefix: 4,\n /** Keep the order of completions */\n KeepOrder: 8,\n /** Trigger file completion */\n FileCompletion: 16,\n /** Trigger directory completion */\n DirectoryCompletion: 32,\n /** Error occurred during completion */\n Error: 64,\n} as const;\n\n/**\n * A completion candidate\n */\nexport interface CompletionCandidate {\n /** The completion value */\n value: string;\n /** Optional description */\n description?: string | undefined;\n /** Type hint for display purposes */\n type?: \"option\" | \"subcommand\" | \"value\" | \"file\" | \"directory\";\n}\n\n/**\n * Result of candidate generation\n */\nexport interface CandidateResult {\n /** Completion candidates */\n candidates: CompletionCandidate[];\n /** Directive flags for shell behavior */\n directive: number;\n /** File extensions for shell-native filtering (e.g., [\"json\", \"yaml\"]) */\n fileExtensions?: string[] | undefined;\n}\n\n/**\n * Generate completion candidates based on context\n */\nexport function generateCandidates(context: CompletionContext): CandidateResult {\n const candidates: CompletionCandidate[] = [];\n let directive = CompletionDirective.Default;\n\n switch (context.completionType) {\n case \"subcommand\":\n return generateSubcommandCandidates(context);\n\n case \"option-name\":\n return generateOptionNameCandidates(context);\n\n case \"option-value\":\n return generateOptionValueCandidates(context);\n\n case \"positional\":\n return generatePositionalCandidates(context);\n\n default:\n return { candidates, directive };\n }\n}\n\n/**\n * Execute a shell command and return results as candidates\n */\nfunction executeShellCommand(command: string): CompletionCandidate[] {\n try {\n const output = execSync(command, { encoding: \"utf-8\", timeout: 5000 });\n return output\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .map((line) => ({ value: line, type: \"value\" as const }));\n } catch {\n return [];\n }\n}\n\n/**\n * Result of resolving value candidates\n */\ninterface ValueResolutionResult {\n directive: number;\n fileExtensions?: string[] | undefined;\n}\n\n/**\n * Resolve value completion, executing shell commands and file lookups in JS\n */\nfunction resolveValueCandidates(\n vc: { type: string; choices?: string[]; shellCommand?: string; extensions?: string[] },\n candidates: CompletionCandidate[],\n _currentWord: string,\n description?: string,\n): ValueResolutionResult {\n let directive = CompletionDirective.FilterPrefix;\n let fileExtensions: string[] | undefined;\n\n switch (vc.type) {\n case \"choices\":\n if (vc.choices) {\n for (const choice of vc.choices) {\n candidates.push({\n value: choice,\n description,\n type: \"value\",\n });\n }\n }\n directive |= CompletionDirective.NoFileCompletion;\n break;\n\n case \"file\":\n if (vc.extensions && vc.extensions.length > 0) {\n // Delegate to shell with extension filter metadata\n fileExtensions = Array.from(\n new Set(\n vc.extensions\n .map((ext) => ext.trim().replace(/^\\./, \"\"))\n .filter((ext) => ext.length > 0),\n ),\n );\n if (fileExtensions.length === 0) {\n // All extensions were invalid → treat as unfiltered file completion\n fileExtensions = undefined;\n directive |= CompletionDirective.FileCompletion;\n }\n } else {\n // No extensions: let shell handle native file completion\n directive |= CompletionDirective.FileCompletion;\n }\n break;\n\n case \"directory\":\n directive |= CompletionDirective.DirectoryCompletion;\n break;\n\n case \"command\":\n // Execute shell command in JS and add results as candidates\n if (vc.shellCommand) {\n candidates.push(...executeShellCommand(vc.shellCommand));\n }\n directive |= CompletionDirective.NoFileCompletion;\n break;\n\n case \"none\":\n directive |= CompletionDirective.NoFileCompletion;\n break;\n }\n\n return { directive, fileExtensions };\n}\n\n/**\n * Generate subcommand candidates\n */\nfunction generateSubcommandCandidates(context: CompletionContext): CandidateResult {\n const candidates: CompletionCandidate[] = [];\n let directive = CompletionDirective.FilterPrefix;\n\n // Add subcommands\n for (const name of context.subcommands) {\n // Get description from the subcommand if possible\n let description: string | undefined;\n if (context.currentCommand.subCommands) {\n const sub = context.currentCommand.subCommands[name];\n if (sub && typeof sub !== \"function\") {\n description = sub.description;\n }\n }\n\n candidates.push({\n value: name,\n description,\n type: \"subcommand\",\n });\n }\n\n // Add options when no subcommands exist, or when typing an option prefix\n if (candidates.length === 0 || context.currentWord.startsWith(\"-\")) {\n const optionResult = generateOptionNameCandidates(context);\n candidates.push(...optionResult.candidates);\n }\n\n return { candidates, directive };\n}\n\n/**\n * Generate option name candidates\n */\nfunction generateOptionNameCandidates(context: CompletionContext): CandidateResult {\n const candidates: CompletionCandidate[] = [];\n const directive = CompletionDirective.FilterPrefix;\n\n // Filter out already used options\n const availableOptions = context.options.filter((opt) => {\n // Array options can be specified multiple times, so keep them available.\n if (opt.valueType === \"array\") {\n return true;\n }\n\n return !context.usedOptions.has(opt.cliName) && !context.usedOptions.has(opt.alias || \"\");\n });\n\n for (const opt of availableOptions) {\n candidates.push({\n value: `--${opt.cliName}`,\n description: opt.description,\n type: \"option\",\n });\n }\n\n // Add help option if not already used\n if (!context.usedOptions.has(\"help\")) {\n candidates.push({\n value: \"--help\",\n description: \"Show help information\",\n type: \"option\",\n });\n }\n\n return { candidates, directive };\n}\n\n/**\n * Generate option value candidates\n */\nfunction generateOptionValueCandidates(context: CompletionContext): CandidateResult {\n const candidates: CompletionCandidate[] = [];\n\n if (!context.targetOption) {\n return { candidates, directive: CompletionDirective.FilterPrefix };\n }\n\n const vc = context.targetOption.valueCompletion;\n if (!vc) {\n return { candidates, directive: CompletionDirective.FilterPrefix };\n }\n\n const { directive, fileExtensions } = resolveValueCandidates(vc, candidates, context.currentWord);\n return { candidates, directive, fileExtensions };\n}\n\n/**\n * Generate positional argument candidates\n */\nfunction generatePositionalCandidates(context: CompletionContext): CandidateResult {\n const candidates: CompletionCandidate[] = [];\n\n // Get the positional at current index, clamping to last (variadic) positional\n const positionalIndex = context.positionalIndex ?? 0;\n const positional =\n context.positionals[positionalIndex] ??\n (context.positionals.at(-1)?.variadic ? context.positionals.at(-1) : undefined);\n\n if (!positional) {\n return { candidates, directive: CompletionDirective.FilterPrefix };\n }\n\n const vc = positional.valueCompletion;\n if (!vc) {\n return { candidates, directive: CompletionDirective.FilterPrefix };\n }\n\n const { directive, fileExtensions } = resolveValueCandidates(\n vc,\n candidates,\n context.currentWord,\n positional.description,\n );\n return { candidates, directive, fileExtensions };\n}\n","/**\n * Shared value completion resolver\n *\n * Resolves value completion metadata from field information.\n * Used by both the static extractor and the dynamic context parser.\n */\n\nimport type { ValueCompletion } from \"./types.js\";\n\n/**\n * Minimal field interface needed for resolving value completion.\n * Both ResolvedFieldMeta and inline context-parser types satisfy this.\n */\nexport interface ValueCompletionField {\n completion?:\n | {\n type?: string;\n custom?: { choices?: string[]; shellCommand?: string };\n extensions?: string[];\n }\n | undefined;\n enumValues?: string[] | undefined;\n}\n\n/**\n * Resolve value completion from field metadata\n *\n * Priority:\n * 1. Explicit custom completion (choices or shellCommand)\n * 2. Explicit completion type (file, directory, none)\n * 3. Auto-detected enum values from schema\n */\nexport function resolveValueCompletion(field: ValueCompletionField): ValueCompletion | undefined {\n const meta = field.completion;\n\n // Priority 1: Explicit custom completion\n if (meta?.custom) {\n if (meta.custom.choices && meta.custom.choices.length > 0) {\n return { type: \"choices\", choices: meta.custom.choices };\n }\n if (meta.custom.shellCommand) {\n return { type: \"command\", shellCommand: meta.custom.shellCommand };\n }\n }\n\n // Priority 2: Explicit completion type\n if (meta?.type) {\n if (meta.type === \"file\") {\n return meta.extensions ? { type: \"file\", extensions: meta.extensions } : { type: \"file\" };\n }\n if (meta.type === \"directory\") {\n return { type: \"directory\" };\n }\n if (meta.type === \"none\") {\n return { type: \"none\" };\n }\n }\n\n // Priority 3: Auto-detect from enum schema\n if (field.enumValues && field.enumValues.length > 0) {\n return { type: \"choices\", choices: field.enumValues };\n }\n\n return undefined;\n}\n","/**\n * Parse completion context from partial command line\n */\n\nimport { extractFields } from \"../../core/schema-extractor.js\";\nimport type { AnyCommand } from \"../../types.js\";\nimport type { CompletableOption, CompletablePositional } from \"../types.js\";\nimport { resolveValueCompletion } from \"../value-completion-resolver.js\";\n\n/**\n * Completion type indicates what kind of completion is expected\n */\nexport type CompletionType =\n | \"subcommand\" // Completing a subcommand name\n | \"option-name\" // Completing an option name (--xxx, -x)\n | \"option-value\" // Completing an option's value\n | \"positional\"; // Completing a positional argument\n\n/**\n * Context for completion at current cursor position\n */\nexport interface CompletionContext {\n /** Subcommand path from root (e.g., [\"plugin\", \"add\"]) */\n subcommandPath: string[];\n /** The resolved command at current path */\n currentCommand: AnyCommand;\n /** Current word being typed (may be partial) */\n currentWord: string;\n /** Previous word (useful for option value detection) */\n previousWord: string;\n /** What type of completion is expected */\n completionType: CompletionType;\n /** Target option when completing option value */\n targetOption?: CompletableOption | undefined;\n /** Positional index when completing positional argument */\n positionalIndex?: number | undefined;\n /** Available options for current command */\n options: CompletableOption[];\n /** Available subcommands */\n subcommands: string[];\n /** Available positionals */\n positionals: CompletablePositional[];\n /** Options already used (to avoid duplicates) */\n usedOptions: Set<string>;\n /** Number of positional arguments already provided */\n providedPositionalCount: number;\n}\n\n/**\n * Extract options from a command\n */\nfunction extractOptions(command: AnyCommand): CompletableOption[] {\n if (!command.args) {\n return [];\n }\n\n const extracted = extractFields(command.args);\n return extracted.fields\n .filter((field) => !field.positional)\n .map((field) => ({\n name: field.name,\n cliName: field.cliName,\n alias: field.alias,\n description: field.description,\n takesValue: field.type !== \"boolean\",\n valueType: field.type,\n required: field.required,\n valueCompletion: resolveValueCompletion(field),\n }));\n}\n\n/**\n * Extract positionals from a command\n */\nfunction extractPositionalsForContext(command: AnyCommand): CompletablePositional[] {\n if (!command.args) {\n return [];\n }\n\n const extracted = extractFields(command.args);\n return extracted.fields\n .filter((field) => field.positional)\n .map((field, index) => ({\n name: field.name,\n cliName: field.cliName,\n position: index,\n description: field.description,\n required: field.required,\n variadic: field.type === \"array\",\n valueCompletion: resolveValueCompletion(field),\n }));\n}\n\n/**\n * Get subcommand names from a command\n */\nfunction getSubcommandNames(command: AnyCommand): string[] {\n if (!command.subCommands) {\n return [];\n }\n // Filter out internal subcommands (e.g., __complete)\n return Object.keys(command.subCommands).filter((name) => !name.startsWith(\"__\"));\n}\n\n/**\n * Resolve subcommand by name\n */\nfunction resolveSubcommand(command: AnyCommand, name: string): AnyCommand | null {\n if (!command.subCommands) {\n return null;\n }\n\n const sub = command.subCommands[name];\n if (!sub) {\n return null;\n }\n\n // Skip async subcommands (can't inspect statically)\n if (typeof sub === \"function\") {\n return null;\n }\n\n return sub;\n}\n\n/**\n * Check if a word is an option (starts with - or --)\n */\nfunction isOption(word: string): boolean {\n return word.startsWith(\"-\");\n}\n\n/**\n * Parse option name from word (e.g., \"--foo=bar\" -> \"foo\", \"-v\" -> \"v\")\n */\nfunction parseOptionName(word: string): string {\n if (word.startsWith(\"--\")) {\n const withoutPrefix = word.slice(2);\n const eqIndex = withoutPrefix.indexOf(\"=\");\n return eqIndex >= 0 ? withoutPrefix.slice(0, eqIndex) : withoutPrefix;\n }\n if (word.startsWith(\"-\")) {\n return word.slice(1, 2); // First char after -\n }\n return word;\n}\n\n/**\n * Check if option has inline value (e.g., \"--foo=bar\")\n */\nfunction hasInlineValue(word: string): boolean {\n return word.includes(\"=\");\n}\n\n/**\n * Find option by name or alias\n */\nfunction findOption(\n options: CompletableOption[],\n nameOrAlias: string,\n): CompletableOption | undefined {\n return options.find((opt) => opt.cliName === nameOrAlias || opt.alias === nameOrAlias);\n}\n\n/**\n * Parse completion context from command line arguments\n *\n * @param argv - Arguments after the program name (e.g., [\"build\", \"--fo\"])\n * @param rootCommand - The root command\n * @returns Completion context\n */\nexport function parseCompletionContext(argv: string[], rootCommand: AnyCommand): CompletionContext {\n // Initialize with root command\n let currentCommand = rootCommand;\n const subcommandPath: string[] = [];\n\n // Track used options and positional count\n const usedOptions = new Set<string>();\n let positionalCount = 0;\n\n // Process arguments to resolve subcommands and track state\n let i = 0;\n let options = extractOptions(currentCommand);\n let afterDoubleDash = false;\n\n // Traverse subcommands\n while (i < argv.length - 1) {\n const word = argv[i]!;\n\n // \"--\" marks the end of option parsing\n if (!afterDoubleDash && word === \"--\") {\n afterDoubleDash = true;\n i++;\n continue;\n }\n\n // Skip options and their values (before \"--\")\n if (!afterDoubleDash && isOption(word)) {\n const optName = parseOptionName(word);\n const opt = findOption(options, optName);\n\n if (opt) {\n usedOptions.add(opt.cliName);\n if (opt.alias) usedOptions.add(opt.alias);\n\n // Skip next word if option takes value and doesn't have inline value\n if (opt.takesValue && !hasInlineValue(word)) {\n i++;\n }\n }\n i++;\n continue;\n }\n\n // Check if this is a subcommand (before \"--\")\n const subcommand = afterDoubleDash ? null : resolveSubcommand(currentCommand, word);\n if (subcommand) {\n subcommandPath.push(word);\n currentCommand = subcommand;\n options = extractOptions(currentCommand);\n usedOptions.clear(); // Reset for new subcommand\n positionalCount = 0;\n i++;\n continue;\n }\n\n // Otherwise it's a positional argument\n positionalCount++;\n i++;\n }\n\n // Get current and previous word\n const currentWord: string = argv[argv.length - 1] ?? \"\";\n const previousWord: string = argv[argv.length - 2] ?? \"\";\n\n // Extract data for current command\n const positionals = extractPositionalsForContext(currentCommand);\n const subcommands = getSubcommandNames(currentCommand);\n\n // Determine completion type\n let completionType: CompletionType;\n let targetOption: CompletableOption | undefined;\n let positionalIndex: number | undefined;\n\n // Case 1: Previous word is an option that takes a value\n if (!afterDoubleDash && previousWord && isOption(previousWord) && !hasInlineValue(previousWord)) {\n const optName = parseOptionName(previousWord);\n const opt = findOption(options, optName);\n if (opt && opt.takesValue) {\n completionType = \"option-value\";\n targetOption = opt;\n } else if (currentWord.startsWith(\"-\")) {\n // Previous word is boolean flag, current word starts with - → option name\n completionType = \"option-name\";\n } else {\n completionType = determineDefaultCompletionType(\n currentWord,\n subcommands,\n positionals,\n positionalCount,\n );\n if (completionType === \"positional\") {\n positionalIndex = positionalCount;\n }\n }\n }\n // Case 2: Current word is an option with inline value (--foo=)\n else if (!afterDoubleDash && currentWord.startsWith(\"--\") && hasInlineValue(currentWord)) {\n const optName = parseOptionName(currentWord);\n const opt = findOption(options, optName);\n if (opt && opt.takesValue) {\n completionType = \"option-value\";\n targetOption = opt;\n } else {\n completionType = \"option-name\";\n }\n }\n // Case 3: Current word starts with - (completing option name)\n else if (!afterDoubleDash && currentWord.startsWith(\"-\")) {\n completionType = \"option-name\";\n }\n // Case 4: Determine based on available subcommands and positionals\n else {\n completionType = determineDefaultCompletionType(\n currentWord,\n subcommands,\n positionals,\n positionalCount,\n afterDoubleDash,\n );\n if (completionType === \"positional\") {\n positionalIndex = positionalCount;\n }\n }\n\n return {\n subcommandPath,\n currentCommand,\n currentWord,\n previousWord,\n completionType,\n targetOption,\n positionalIndex,\n options,\n subcommands,\n positionals,\n usedOptions,\n providedPositionalCount: positionalCount,\n };\n}\n\n/**\n * Determine default completion type when not completing an option\n */\nfunction determineDefaultCompletionType(\n currentWord: string,\n subcommands: string[],\n positionals: CompletablePositional[],\n positionalCount: number,\n afterDoubleDash?: boolean,\n): CompletionType {\n // After --, everything is positional — never suggest subcommands or options\n if (afterDoubleDash) {\n return \"positional\";\n }\n\n // If there are subcommands and current word might match one, suggest subcommands\n if (subcommands.length > 0) {\n // Check if any subcommand starts with current word\n const matchingSubcommands = subcommands.filter((s) => s.startsWith(currentWord));\n if (matchingSubcommands.length > 0 || currentWord === \"\") {\n return \"subcommand\";\n }\n }\n\n // If there are positionals to complete\n if (positionalCount < positionals.length) {\n return \"positional\";\n }\n\n // If the last positional is variadic (array), continue with positional\n if (positionals.length > 0 && positionals[positionals.length - 1]!.variadic) {\n return \"positional\";\n }\n\n // Default to subcommand (will show options too)\n return \"subcommand\";\n}\n","/**\n * Shell-specific output formatter for completion candidates\n *\n * Formats completion candidates into shell-native output so that\n * shell scripts can consume them with minimal parsing logic.\n */\n\nimport type { ShellType } from \"../types.js\";\nimport {\n CompletionDirective,\n type CandidateResult,\n type CompletionCandidate,\n} from \"./candidate-generator.js\";\n\n/**\n * Options for shell-specific formatting\n */\nexport interface ShellFormatOptions {\n /** Target shell type */\n shell: ShellType;\n /** Current word being completed (used for prefix filtering) */\n currentWord: string;\n /** For bash: the prefix before '=' in --opt=value completions */\n inlinePrefix?: string | undefined;\n}\n\n/**\n * Format completion candidates for the specified shell\n *\n * @returns Shell-ready output string (lines separated by newline, last line is :directive)\n */\nexport function formatForShell(result: CandidateResult, options: ShellFormatOptions): string {\n switch (options.shell) {\n case \"bash\":\n return formatForBash(result, options);\n case \"zsh\":\n return formatForZsh(result, options);\n case \"fish\":\n return formatForFish(result, options);\n }\n}\n\n/**\n * Check if the FilterPrefix directive is set\n */\nfunction shouldFilterPrefix(directive: number): boolean {\n return (directive & CompletionDirective.FilterPrefix) !== 0;\n}\n\n/**\n * Filter candidates by prefix\n */\nfunction filterByPrefix(candidates: CompletionCandidate[], prefix: string): CompletionCandidate[] {\n if (!prefix) return candidates;\n return candidates.filter((c) => c.value.startsWith(prefix));\n}\n\n/**\n * Append extension metadata and directive to output lines\n */\nfunction appendMetadata(lines: string[], result: CandidateResult): void {\n if (result.fileExtensions && result.fileExtensions.length > 0) {\n lines.push(`@ext:${result.fileExtensions.join(\",\")}`);\n }\n lines.push(`:${result.directive}`);\n}\n\n/**\n * Format for bash\n *\n * - Pre-filters candidates by currentWord prefix (replaces compgen -W)\n * - Handles --opt=value inline values by prepending prefix\n * - Outputs plain values only (no descriptions - bash COMPREPLY doesn't support them)\n * - Last line: :directive\n */\nfunction formatForBash(result: CandidateResult, options: ShellFormatOptions): string {\n let { candidates } = result;\n\n if (shouldFilterPrefix(result.directive)) {\n candidates = filterByPrefix(candidates, options.currentWord);\n }\n\n const lines: string[] = candidates.map((c) => {\n if (options.inlinePrefix) {\n return `${options.inlinePrefix}${c.value}`;\n }\n return c.value;\n });\n\n appendMetadata(lines, result);\n return lines.join(\"\\n\");\n}\n\n/**\n * Format for zsh\n *\n * - Outputs value:description pairs for _describe\n * - Colons in values/descriptions are escaped with backslash\n * - Last line: :directive\n */\nfunction formatForZsh(result: CandidateResult, _options: ShellFormatOptions): string {\n const lines: string[] = result.candidates.map((c) => {\n const escapedValue = c.value.replace(/:/g, \"\\\\:\");\n if (c.description) {\n const escapedDesc = c.description.replace(/:/g, \"\\\\:\");\n return `${escapedValue}:${escapedDesc}`;\n }\n return escapedValue;\n });\n\n appendMetadata(lines, result);\n return lines.join(\"\\n\");\n}\n\n/**\n * Format for fish\n *\n * - Outputs value\\tdescription pairs\n * - Last line: :directive\n */\nfunction formatForFish(result: CandidateResult, _options: ShellFormatOptions): string {\n const lines: string[] = result.candidates.map((c) => {\n if (c.description) {\n return `${c.value}\\t${c.description}`;\n }\n return c.value;\n });\n\n appendMetadata(lines, result);\n return lines.join(\"\\n\");\n}\n","/**\n * Dynamic completion command implementation\n *\n * This creates a hidden `__complete` command that outputs completion candidates\n * for shell scripts to consume. Usage:\n *\n * mycli __complete --shell bash -- build --fo\n * mycli __complete --shell zsh -- plugin add\n *\n * Output format depends on the target shell:\n * bash: plain values (pre-filtered by prefix), last line :directive\n * zsh: value:description pairs, last line :directive\n * fish: value\\tdescription pairs, last line :directive\n */\n\nimport { z } from \"zod\";\nimport { arg } from \"../../core/arg-registry.js\";\nimport { defineCommand } from \"../../core/command.js\";\nimport type { AnyCommand, Command } from \"../../types.js\";\nimport { generateCandidates } from \"./candidate-generator.js\";\nimport { parseCompletionContext } from \"./context-parser.js\";\nimport { formatForShell } from \"./shell-formatter.js\";\n\n/**\n * Detect inline option-value prefix (e.g., \"--format=\" from \"--format=json\")\n */\nfunction detectInlinePrefix(currentWord: string): string | undefined {\n if (currentWord.startsWith(\"--\") && currentWord.includes(\"=\")) {\n return currentWord.slice(0, currentWord.indexOf(\"=\") + 1);\n }\n return undefined;\n}\n\n/**\n * Schema for the __complete command\n */\nconst completeArgsSchema = z.object({\n shell: arg(z.enum([\"bash\", \"zsh\", \"fish\"]), {\n description: \"Target shell for output formatting\",\n }),\n // The arguments to complete are passed after --\n args: arg(z.array(z.string()).default([]), {\n positional: true,\n description: \"Arguments to complete\",\n variadic: true,\n }),\n});\n\ntype CompleteArgs = z.infer<typeof completeArgsSchema>;\n\n/**\n * Create the dynamic completion command\n *\n * @param rootCommand - The root command to generate completions for\n * @param programName - The program name (optional, defaults to rootCommand.name)\n * @returns A command that outputs completion candidates\n */\nexport function createDynamicCompleteCommand(\n rootCommand: AnyCommand,\n _programName?: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Command<typeof completeArgsSchema, CompleteArgs, any> {\n return defineCommand({\n name: \"__complete\",\n // No description - this is a hidden command\n args: completeArgsSchema,\n run(args) {\n // Parse the completion context\n const context = parseCompletionContext(args.args, rootCommand);\n\n // Generate candidates (shellCommand/file extensions resolved in JS)\n const result = generateCandidates(context);\n\n // Detect bash inline option-value prefix\n const inlinePrefix = detectInlinePrefix(context.currentWord);\n\n // Format for the target shell\n const output = formatForShell(result, {\n shell: args.shell,\n currentWord: inlinePrefix\n ? context.currentWord.slice(inlinePrefix.length)\n : context.currentWord,\n inlinePrefix,\n });\n\n console.log(output);\n },\n });\n}\n\n/**\n * Check if a command tree contains the __complete command\n */\nexport function hasCompleteCommand(command: AnyCommand): boolean {\n return Boolean(command.subCommands?.[\"__complete\"]);\n}\n","/**\n * Fish completion script generator (dynamic)\n */\n\nimport type { AnyCommand } from \"../types.js\";\nimport type { CompletionOptions, CompletionResult } from \"./types.js\";\n\n/**\n * Generate fish completion script for a command\n *\n * Generates a minimal script that delegates all logic to the CLI's __complete command.\n * The shell script only handles:\n * - Getting current command line tokens\n * - Calling __complete with --shell fish\n * - Echoing output as completions\n * - Falling back to native file/directory completion when directed\n */\nexport function generateFishCompletion(\n _command: AnyCommand,\n options: CompletionOptions,\n): CompletionResult {\n const programName = options.programName;\n\n return {\n script: `# Fish completion for ${programName}\n# Generated by politty\n\nfunction __fish_${programName}_complete\n set -l args (commandline -opc)\n set -e args[1]\n set -l directive 0\n set -l extensions \"\"\n\n # commandline -opc excludes the current token; always include it\n set -l ct (commandline -ct)\n if test (count $ct) -eq 0\n set -a args \"\"\n else\n set -a args $ct\n end\n\n for line in (${programName} __complete --shell fish -- $args 2>/dev/null)\n if string match -q ':*' -- $line\n set directive (string sub -s 2 -- $line)\n else if string match -q '@ext:*' -- $line\n set extensions (string sub -s 6 -- $line)\n else if test -n \"$line\"\n echo $line\n end\n end\n\n # 16 = FileCompletion: delegate entirely to native file completion\n if test (math \"bitand($directive, 16)\") -ne 0\n __fish_complete_path\n return\n end\n\n # Extension-filtered file completion: keep matching files + directories\n if test -n \"$extensions\"\n set -l cur (commandline -ct)\n test (count $cur) -eq 0; and set cur \"\"\n __fish_complete_directories \"$cur\"\n for ext in (string split \",\" -- $extensions)\n for f in \"$cur\"*.$ext\n if test -f \"$f\"\n echo $f\n end\n end\n end\n return\n end\n\n # 32 = DirectoryCompletion: add native directory matches\n if test (math \"bitand($directive, 32)\") -ne 0\n __fish_complete_directories\n end\nend\n\n# Clear existing completions\ncomplete -e -c ${programName}\n\n# Register completion\ncomplete -c ${programName} -f -a '(__fish_${programName}_complete)'\n`,\n shell: \"fish\",\n installInstructions: `# To enable completions, run one of the following:\n\n# Option 1: Source directly\n${programName} completion fish | source\n\n# Option 2: Save to the fish completions directory\n${programName} completion fish > ~/.config/fish/completions/${programName}.fish\n\n# The completion will be available immediately in new shell sessions.\n# To use in the current session, run:\nsource ~/.config/fish/completions/${programName}.fish`,\n };\n}\n","/**\n * Zsh completion script generator (dynamic)\n */\n\nimport type { AnyCommand } from \"../types.js\";\nimport type { CompletionOptions, CompletionResult } from \"./types.js\";\n\n/**\n * Generate zsh completion script for a command\n *\n * Generates a minimal script that delegates all logic to the CLI's __complete command.\n * The shell script only handles:\n * - Getting current command line tokens\n * - Calling __complete with --shell zsh\n * - Passing output directly to _describe\n * - Falling back to native file/directory completion when directed\n */\nexport function generateZshCompletion(\n _command: AnyCommand,\n options: CompletionOptions,\n): CompletionResult {\n const programName = options.programName;\n\n return {\n script: `#compdef ${programName}\n\n# Zsh completion for ${programName}\n# Generated by politty\n\n_${programName}() {\n local -a candidates\n local line directive=0\n local -a args=(\"\\${words[@]:1}\")\n local -a output=(\"\\${(@f)$(${programName} __complete --shell zsh -- \"\\${args[@]}\" 2>/dev/null)}\")\n\n local extensions=\"\"\n for line in \"\\${output[@]}\"; do\n if [[ \"$line\" == :* ]]; then\n directive=\"\\${line:1}\"\n elif [[ \"$line\" == @ext:* ]]; then\n extensions=\"\\${line:5}\"\n elif [[ -n \"$line\" ]]; then\n candidates+=(\"$line\")\n fi\n done\n\n # 16 = FileCompletion: delegate entirely to native file completion\n if (( directive & 16 )); then\n _files\n return 0\n fi\n\n # Extension-filtered file completion: call _files -g per extension\n if [[ -n \"$extensions\" ]]; then\n local ext\n for ext in \\${(s:,:)extensions}; do\n _files -g \"*.$ext\"\n done\n return 0\n fi\n\n if (( \\${#candidates[@]} > 0 )); then\n _describe 'completions' candidates\n fi\n\n # 32 = DirectoryCompletion: add native directory matches\n if (( directive & 32 )); then\n _files -/\n fi\n\n # 2 = NoFileCompletion, 32 = DirectoryCompletion:\n # prevent fallback to default completers (e.g. file completion)\n if (( directive & 2 )) || (( directive & 32 )); then\n return 0\n fi\n}\n\n# Prevent _files -g from falling back to showing all files when no pattern matches\nzstyle ':completion:*:*:${programName}:*' file-patterns '%p:globbed-files *(-/):directories'\n\ncompdef _${programName} ${programName}\n`,\n shell: \"zsh\",\n installInstructions: `# To enable completions, add the following to your ~/.zshrc:\n\n# Option 1: Source directly (add before compinit)\neval \"$(${programName} completion zsh)\"\n\n# Option 2: Save to a file in your fpath\n${programName} completion zsh > ~/.zsh/completions/_${programName}\n\n# Make sure your fpath includes the completions directory:\n# fpath=(~/.zsh/completions $fpath)\n# autoload -Uz compinit && compinit\n\n# Then reload your shell or run:\nsource ~/.zshrc`,\n };\n}\n","/**\n * Extract completion data from commands\n */\n\nimport { extractFields, type ResolvedFieldMeta } from \"../core/schema-extractor.js\";\nimport type { AnyCommand } from \"../types.js\";\nimport type {\n CompletableOption,\n CompletablePositional,\n CompletableSubcommand,\n CompletionData,\n} from \"./types.js\";\nimport { resolveValueCompletion } from \"./value-completion-resolver.js\";\n\n/**\n * Convert a resolved field to a completable option\n */\nfunction fieldToOption(field: ResolvedFieldMeta): CompletableOption {\n return {\n name: field.name,\n cliName: field.cliName,\n alias: field.alias,\n description: field.description,\n // Booleans are flags that don't require a value\n takesValue: field.type !== \"boolean\",\n valueType: field.type,\n required: field.required,\n valueCompletion: resolveValueCompletion(field),\n };\n}\n\n/**\n * Extract options from a command's args schema\n */\nfunction extractOptions(command: AnyCommand): CompletableOption[] {\n if (!command.args) {\n return [];\n }\n\n const extracted = extractFields(command.args);\n return extracted.fields\n .filter((field) => !field.positional) // Only include flags/options, not positionals\n .map(fieldToOption);\n}\n\n/**\n * Extract positional arguments from a command\n */\nexport function extractPositionals(command: AnyCommand): ResolvedFieldMeta[] {\n if (!command.args) {\n return [];\n }\n\n const extracted = extractFields(command.args);\n return extracted.fields.filter((field) => field.positional);\n}\n\n/**\n * Extract completable positional arguments from a command\n */\nfunction extractCompletablePositionals(command: AnyCommand): CompletablePositional[] {\n if (!command.args) {\n return [];\n }\n\n const extracted = extractFields(command.args);\n return extracted.fields\n .filter((field) => field.positional)\n .map((field, index) => ({\n name: field.name,\n cliName: field.cliName,\n position: index,\n description: field.description,\n required: field.required,\n valueCompletion: resolveValueCompletion(field),\n }));\n}\n\n/**\n * Extract a completable subcommand from a command\n */\nfunction extractSubcommand(name: string, command: AnyCommand): CompletableSubcommand {\n const subcommands: CompletableSubcommand[] = [];\n\n // Extract subcommands recursively (only sync subcommands for now)\n if (command.subCommands) {\n for (const [subName, subCommand] of Object.entries(command.subCommands)) {\n // Skip async subcommands as we can't inspect them statically\n if (typeof subCommand === \"function\") {\n // For async subcommands, add a placeholder\n subcommands.push({\n name: subName,\n description: \"(lazy loaded)\",\n subcommands: [],\n options: [],\n positionals: [],\n });\n } else {\n subcommands.push(extractSubcommand(subName, subCommand));\n }\n }\n }\n\n return {\n name,\n description: command.description,\n subcommands,\n options: extractOptions(command),\n positionals: extractCompletablePositionals(command),\n };\n}\n\n/**\n * Extract completion data from a command tree\n */\nexport function extractCompletionData(command: AnyCommand, programName: string): CompletionData {\n const rootSubcommand = extractSubcommand(programName, command);\n\n return {\n command: rootSubcommand,\n programName,\n // Global options are the options defined on the root command\n globalOptions: rootSubcommand.options,\n };\n}\n"],"mappings":";;;;;AA2HA,SAAgB,cAId,QACuD;AACvD,QAAO;EACL,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,OAAO,OAAO;EACd,KAAK,OAAO;EACZ,SAAS,OAAO;EAChB,OAAO,OAAO;EACd,UAAU,OAAO;EAClB;;;;;;;;;;;;;;;AC1HH,SAAgB,uBACd,UACA,SACkB;CAClB,MAAM,cAAc,QAAQ;AAE5B,QAAO;EACL,QAAQ,yBAAyB,YAAY;;;GAG9C,YAAY;;;;;;;;;;;;;;;;;;;eAmBA,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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