+
    Q(i7                     B   R t ^ RIt^ RIHt ^ RIHtHt ]'       d   ^ RIHt ^ RI	H
t
 ^ RIHt ^ RI	HtHt R R	 ltR
 R ltR R ltR R ltR(R R lltR R ltR R ltR)R R lltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR*R$ R% lltR+R& R' lltR# ),z,Base utilities for documentation generation.N)Sequence)TYPE_CHECKINGAny)App)	HelpPanel)CommandSpec)
format_docformat_usagec                (    V ^8  d   QhRRR\         /#    appr   returnbool)formats   "X/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/cyclopts/docs/base.py__annotate__r      s     / /5 /T /    c                v    \        V P                  P                  4      ^8H  pV'       d   R# V P                  RJ# )a@  Determine if usage should be shown for an app.

Root apps always show usage (even without default_command, showing "app COMMAND").
Subcommands only show usage if they have a default_command.
This skips usage for command groups that can't be invoked directly.

The determination is made by checking the app_stack depth:
- Stack length of 1 means root app (just the initial frame)
- Stack length > 1 means we're in a subcommand context (frames were pushed)

Parameters
----------
app : App
    The App instance to check.

Returns
-------
bool
    True if usage should be shown.
TN)len	app_stackstackdefault_command)r   is_roots   & r   should_show_usager      s6    , #--%%&!+G ""$..r   c                (    V ^8  d   QhRRR\         /# r   r   )r   s   "r   r   r   /   s     + +5 +T +r   c                    V P                   RJ# )aj  Determine if commands list should be shown for an app.

Only show commands list for apps with a default_command.
Command groups (apps without default_command) skip the list
since their commands will be documented recursively anyway.

Parameters
----------
app : App
    The App instance to check.

Returns
-------
bool
    True if commands list should be shown.
N)r   )r   s   &r   should_show_commands_listr   /   s    " d**r   c                4    V ^8  d   QhRRR\         R\        /# )r   r   r   namer   strr   )r   s   "r   r   r   C   s!     ! !% !s !t !r   c                    \        V P                  P                  RRR7      4      p\        V P                  P                  RRR7      4      pW#,          pW9   # )zCheck if a flag name is a built-in help or version flag.

Parameters
----------
app : App
    The App instance to check against.
name : str
    The flag name to check.

Returns
-------
bool
    True if this is a built-in help or version flag.

help_flags)fallbackversion_flags )setr   resolve)r   r    r$   r&   builtin_flagss   &&   r   _is_builtin_flagr+   C   sQ     S]]**<"*EFJ--o-KLM.M  r   c                J    V ^8  d   QhRRR\         \        ,          R\        /# )r   r   r   namesr   )r   r"   r   )r   s   "r   r   r   X   s%     > >e >HSM >d >r   c                   a  V'       g   R# \         ;QJ d    V 3R lV 4       F  '       d   K   R# 	  R# ! V 3R lV 4       4      # )a  Check if all names in the sequence are builtin help or version flags.

Parameters
----------
app : App
    The App instance to check against.
names : Sequence[str]
    Sequence of flag names to check.

Returns
-------
bool
    True if all names are builtin flags.
Fc              3   <   <"   T F  p\        SV4      x  K  	  R # 5iN)r+   ).0r    r   s   & r   	<genexpr>'is_all_builtin_flags.<locals>.<genexpr>i   s     =utT**us   T)all)r   r-   s   f&r   is_all_builtin_flagsr5   X   s4     3=u=33=3=3=u===r   c          	          V ^8  d   QhR\         \        ,          R,          R\         \        ,          R,          R\        \        \        ,          R,          \        \        ,          R,          3,          /# )r   commands_filterNexclude_commandsr   )listr"   tupler(   )r   s   "r   r   r   l   sR     2 2#Y%23i$&2 3s8d?CHtO+,2r   c                    RpV e!   V  Uu0 uF  q3P                  RR4      kK  	  ppRpV'       d!   V Uu0 uF  q3P                  RR4      kK  	  ppW$3# u upi u upi )aV  Normalize command filter lists by converting underscores to dashes.

Parameters
----------
commands_filter : list[str] | None
    List of commands to include.
exclude_commands : list[str] | None
    List of commands to exclude.

Returns
-------
tuple[set[str] | None, set[str] | None]
    Normalized include and exclude sets for O(1) lookup.
N_-)replace)r7   r8   normalized_includecmdnormalized_excludes   &&   r   normalize_command_filtersrB   l   sl    $ "?NOkk#s3O?OP?Okk#s3?OP11 P Qs
   AAc                    V ^8  d   QhR\         R\        \         ,          R\        \         ,          R,          R\        \         ,          R,          RRR\        /# )	r   r    parent_pathnormalized_commands_filterNnormalized_exclude_commandssubappr   r   )r"   r9   r(   r   )r   s   "r   r   r      sX     5 5
5c5 !$C45 "%SD	5
 5 
5r   c                6   V'       d   RP                  W.,           4      MT pV'       dN   W9   g   WS9   d   R# \        \        V4      4       F'  pRP                  VRV^,            4      pWs9   g   K&   R# 	  Ve   W9   g   WR9   d   R# \        \        V4      4       F'  pRP                  VRV^,            4      pWr9   g   K&   R# 	  \        VR4      '       d=   VP                  '       d+   V F$  pVP                  VR,           4      '       g   K#   R# 	  R# R# )a  Determine if a command should be included based on filters.

Parameters
----------
name : str
    The command name.
parent_path : list[str]
    Path to parent commands.
normalized_commands_filter : set[str] | None
    Set of commands to include (already normalized).
normalized_exclude_commands : set[str] | None
    Set of commands to exclude (already normalized).
subapp : App
    The subcommand App instance.

Returns
-------
bool
    True if the command should be included, False otherwise.
.FNT	_commands)joinranger   hasattrrJ   
startswith)	r    rD   rE   rF   rG   	full_pathiparent_segment
filter_cmds	   &&&&&    r   should_include_commandrS      s    6 3>v-.4I".)2Zs;'(A XXk'AE&:;N< )
 "--1Xs;'(A XXk'AE&:;N; )
 6;''F,<,<,<8
((S99 9 r   c                    V ^8  d   QhR\         R\        \         ,          R,          R\        \         ,          R,          R\        \        \         ,          R,          \        \         ,          R,          3,          /# )r   r    rE   NrF   r   )r"   r(   r:   r9   )r   s   "r   r   r      s\     -5 -5
-5 #C4-5 "%SD-5 49tT#Y--.	-5r   c                   RpVez   . pV Fc  pVP                  V R,           4      '       d9   V\        V 4      ^,           R pVP                  VP                  RR4      4       KY  W@8X  g   Ka  Rp M	  Ve   V'       g   . pRpV'       d   . pV Fz  pVP                  V R,           4      '       d9   V\        V 4      ^,           R pVP                  VP                  RR4      4       KY  VP                  VP                  RR4      4       K|  	  W63# )a  Adjust filter lists for subcommand context.

Parameters
----------
name : str
    The current command name.
normalized_commands_filter : set[str] | None
    Set of commands to include (already normalized).
normalized_exclude_commands : set[str] | None
    Set of commands to exclude (already normalized).

Returns
-------
tuple[list[str] | None, list[str] | None]
    Adjusted commands_filter and exclude_commands lists (denormalized).
NrI   r=   r<   )rN   r   appendr>   )	r    rE   rF   sub_commands_filterrR   
sub_filtersub_exclude_commandsexclude_cmdsub_excludes	   &&&      r   adjust_filters_for_subcommandr\      s   * !- 4J$$TCZ00'D	A8
#**:+=+=c3+GH#&*# 5 *3F"$"!6K%%dSj11)#d)a-/:$++K,?,?S,IJ$++K,?,?S,IJ 7 44r   c          	          V ^8  d   QhRRR\         \        ,          R,          R\        \        \        \        3,          /# )r   r   r   command_chainNr   )r9   r"   r:   )r   s   "r   r   r      s7     ) )e )DI,< )cSVX[mH\ )r   c                    V'       g   V P                   ^ ,          pTpTpMV^ ,          pRP                  V4      pTpW#V3# )a  Get app name, full command path, and title.

Parameters
----------
app : App
    The cyclopts App instance.
command_chain : Optional[List[str]]
    Chain of parent commands leading to this app.

Returns
-------
Tuple[str, str, str]
    (app_name, full_command, title)
 )r    rK   )r   r^   app_namefull_commandtitles   &&   r   get_app_inford      sF     88A; #xx.5((r   c          	          V ^8  d   QhR\         \        ,          R,          R\        R\        R\         \        ,          /# )r   r^   Ncommand_namera   r   )r9   r"   )r   s   "r   r   r     s9     ( (tCy4'7 (s (VY (^bcf^g (r   c                *    V '       d
   W.,           # W!.# )a
  Build command chain for a subcommand.

Parameters
----------
command_chain : Optional[List[str]]
    Current command chain.
command_name : str
    Name of the subcommand.
app_name : str
    Name of the root app.

Returns
-------
List[str]
    Updated command chain.
r'   )r^   rf   ra   s   &&&r   build_command_chainrh     s    " ~--''r   c                0    V ^8  d   QhR\         R\         /# )r   command_pathr   )r"   )r   s   "r   r   r   #  s      # # r   c                v    V P                  4       P                  RR4      p\        P                  ! RRV4      pV# )a  Generate a URL-friendly anchor from a command path.

Converts spaces to hyphens and lowercases the string to match
how markdown/HTML processors generate anchors from headings.
Strips leading dashes to match markdown processor behavior.

Parameters
----------
command_path : str
    Full command path (e.g., "myapp files cp").

Returns
-------
str
    Anchor string (e.g., "myapp-files-cp").

Examples
--------
>>> generate_anchor("myapp files cp")
'myapp-files-cp'
>>> generate_anchor("myapp --install-completion")
'myapp-install-completion'
r`   r=   z-+)lowerr>   resub)rj   anchors   & r   generate_anchorrp   #  s6    0 !))#s3FVVE3'FMr   c          
      D    V ^8  d   QhR\         RRRRR\        R\        /# )r   rf   rG   r   
parent_appinclude_hiddenr   r!   )r   s   "r   r   r   A  s1      c 5 e ]a fj r   c                    \        W 4      '       d   R# \        V\        V4      4      '       g   R# V'       g   VP                  '       g   R# R# )a@  Check if a command should be skipped.

Parameters
----------
command_name : str
    Name of the command.
subapp : App
    The subcommand App instance.
parent_app : App
    The parent App instance.
include_hidden : bool
    Whether to include hidden commands.

Returns
-------
bool
    True if command should be skipped.
TF)r+   
isinstancetypeshow)rf   rG   rr   rs   s   &&&&r   should_skip_commandrx   A  s8    & 
11fd:.//&+++r   c          	      N    V ^8  d   QhRRRRR\         R\        \        ,          /# )r   r   r   panelr   rs   r   )r   r9   r   )r   s   "r   r   r   `  s5     ^ ^U ^; ^ ^QUVYQZ ^r   c                    V'       d   VP                   # VP                    Uu. uF3  q3P                  '       d   \        WP                  4      '       d   K1  VNK5  	  up# u upi )a$  Filter help panel entries based on visibility settings.

Parameters
----------
app : App
    The App instance to check against.
panel : HelpPanel
    The help panel to filter.
include_hidden : bool
    Whether to include hidden entries.

Returns
-------
List[Any]
    Filtered panel entries.
)entriesr-   r5   )r   rz   rs   es   &&& r   filter_help_entriesr~   `  sC    " }}}}]}!WWW9McSZSZ9[AA}]]]s   .AAc                B    V ^8  d   QhRRR\         R\        R,          /# )r   r   r   help_formatr   N)r"   r   )r   s   "r   r   r   w  s%      U  t r   c                    \        W4      pV# )zExtract app description.

Parameters
----------
app : App
    The App instance.
help_format : str
    Help format type.

Returns
-------
Optional[Any]
    The extracted description object, or None.
)r   )r   r   descriptions   && r   extract_descriptionr   w  s     S.Kr   c                6    V ^8  d   QhRRR\         R,          /# )r   r   r   r   N)r   )r   s   "r   r   r     s      u t r   c                z    V P                   e!   V P                   '       d   V P                   # R# \        V . 4      pV# )zExtract usage string.

Parameters
----------
app : App
    The App instance.

Returns
-------
Optional[Any]
    The extracted usage object, or None.
N)usager	   )r   r   s   & r   extract_usager     s6     yyIIIsyy/4/b!ELr   c                ^    V ^8  d   QhR\         R\        \         ,          R\         R\         /# )r   
usage_textr^   prefixr   )r"   r9   )r   s   "r   r   r     s-     ! !# !d3i ! !VY !r   c                   V '       g   R# RV 9   d!   V P                  RR4      P                  4       p V'       d   RP                  V4      MRpV P                  R^4      p\	        V4      ^8  d@   V'       d8   V'       d   V RV RV^,           2MV RV^,           2pVP                  4       # V'       d"   V'       d   V RV 2MTpVP                  4       # V'       d   V RV  2MT pVP                  4       # )a  Format usage line with proper command path.

Parameters
----------
usage_text : str
    Raw usage text.
command_chain : List[str]
    Command chain for the app.
prefix : str
    Optional prefix for the usage line (e.g., "$").

Returns
-------
str
    Formatted usage line.
 zUsage:r`   N)r>   striprK   splitr   )r   r^   r   rb   parts
usage_lines   &&&   r   format_usage_liner     s    " :''"5;;=
.;388M*LT1%E
5zA~->Dxqaaz:\NZ[\abc\d[eJf
  
39xq/|
  28xq-Z
r   c                4    V ^8  d   QhRRR\         R\         /# )r   r   r   rs   resolve_lazyr   )r   s   "r   r   r     s!     3 3% 3 3T 3r   c              #    "   V P                   '       g   R# \        4       pV P                   P                  4        F  w  rE\        W4      '       d   K  \	        V\
        4      '       d/   VP                  '       g   V'       g   KJ  VP                  V 4      pMTp\	        V\        V 4      4      '       g   K{  V'       g   VP                  '       g   K  \        V4      pWs9   d   K  VP                  V4       WF3x  K  	  R# 5i)a  Iterate through app commands, yielding valid resolved subapps.

Automatically resolves CommandSpec instances to App instances.
Each unique subapp is yielded only once (first occurrence wins).

Parameters
----------
app : App
    The App instance.
include_hidden : bool
    Whether to include hidden commands.
resolve_lazy : bool
    If ``True`` (default), resolve lazy commands (import their modules) to
    include them in the output. If ``False``, skip unresolved lazy commands.
    Set to ``True`` when generating static artifacts that need all commands,
    such as documentation or shell completion scripts.

Yields
------
Tuple[str, App]
    (command_name, resolved_subapp) for each valid command.
N)rJ   r(   itemsr+   ru   r   is_resolvedr)   rv   rw   idadd)r   rs   r   seenr    app_or_specrG   app_ids   &&&     r   iterate_commandsr     s     . ===UD ]]002C&&k;//***< ((-F F&$s),,fkkk F>l/ 3s   A8D;D:D>D1D)NNr0   )r   )FT)__doc__rm   collections.abcr   typingr   r   cyclopts.corer   cyclopts.helpr   cyclopts.command_specr   r   r	   r   r   r+   r5   rB   rS   r\   rd   rh   rp   rx   r~   r   r   r   r   r'   r   r   <module>r      sz    2 	 $ %!' - 2/@+(!*>(2:5p-5`)6(.<>^.&(!H3 3r   