§
    ÚŽ’jË}  ã                   óº   — d Z ddlZddlmZmZmZ ddlZddlmZ ddl	m
Z
mZ ddlmZmZ d	d
lmZmZmZmZmZ d	dlmZmZ ddlmZ ddlmZ  G d„ de
¦  «        ZdS )zThe bash tool in agentscope.é    N)ÚAsyncGeneratorÚAnyÚListé   )ÚBashCommandParseré   )ÚToolBaseÚToolMiddlewareBase)ÚDEFAULT_DANGEROUS_FILESÚDEFAULT_DANGEROUS_DIRECTORIESé   )ÚPermissionContextÚPermissionDecisionÚPermissionBehaviorÚPermissionModeÚPermissionRule)Ú	TextBlockÚToolResultState)Ú	ToolChunk)ÚBackendBasec                   óT  ‡ — e Zd ZU dZd Zeed<   	 dZeed<   	 ddddœdd	dœd
dddddœdœdgdœZe	ee
f         ed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   eedddfdee         dee         deej        e         z  dz  dee         dz  dedz  d dfˆ fd!„Zd"e	ee
f         d efd#„Zd"e	ee
f         d$ed efd%„Zd&edz  d"e	ee
f         d efd'„Zd"e	ee
f         d ed(         fd)„Zded ee         fd*„Z ded edz  fd+„Z!d,ed efd-„Z"	 	 d1deded/e#d e$e%df         fd0„Z&ˆ xZ'S )2ÚBashzThe bash tool.Únameuf  Executes a bash command and returns its output.

The working directory persists between commands, but shell state does
not. The shell environment is initialized from the user's profile
(bash or zsh).

IMPORTANT: Avoid using this tool to run `find`, `grep`, `cat`, `head`,
`tail`, `sed`, `awk`, or `echo` commands, unless explicitly instructed
or after you have verified that a dedicated tool cannot accomplish your
task. Instead, use the appropriate dedicated tool as this will provide
a much better experience for the user:

 - File search: Use Glob (NOT find or ls)
 - Content search: Use Grep (NOT grep or rg)
 - Read files: Use Read (NOT cat/head/tail)
 - Edit files: Use Edit (NOT sed/awk)
 - Write files: Use Write (NOT echo >/cat <<EOF)
 - Communication: Output text directly (NOT echo/printf)

While the Bash tool can do similar things, it's better to use the
built-in tools as they provide a better user experience and make it
easier to review tool calls and give permission.

# Instructions
 - If your command will create new directories or files, first use
   this tool to run `ls` to verify the parent directory exists and is
   the correct location.
 - Always quote file paths that contain spaces with double quotes in
   your command (e.g., cd "path with spaces/file.txt")
 - Try to maintain your current working directory throughout the
   session by using absolute paths and avoiding usage of `cd`. You may
   use `cd` if the User explicitly requests it.
 - You may specify an optional timeout in milliseconds (up to 600000ms
   / 10 minutes). By default, your command will timeout after 120000ms
   (2 minutes).
 - Write a clear, concise description of what your command does. For
   simple commands, keep it brief (5-10 words). For complex commands
   (piped commands, obscure flags, or anything hard to understand at a
   glance), include enough context so that the user can understand what
   your command will do.
 - When issuing multiple commands:
  - If the commands are independent and can run in parallel, make
    multiple Bash tool calls in a single message. Example: if you need
    to run "git status" and "git diff", send a single message with two
    Bash tool calls in parallel.
  - If the commands depend on each other and must run sequentially,
    use a single Bash call with '&&' to chain them together.
  - Use ';' only when you need to run commands sequentially but don't
    care if earlier commands fail.
  - DO NOT use newlines to separate commands (newlines are ok in
    quoted strings).
 - For git commands:
  - Prefer to create a new commit rather than amending an existing
    commit.
  - Before running destructive operations (e.g., git reset --hard, git
    push --force, git checkout --), consider whether there is a safer
    alternative that achieves the same goal. Only use destructive
    operations when they are truly the best approach.
  - Never skip hooks (--no-verify) or bypass signing (--no-gpg-sign,
    -c commit.gpgsign=false) unless the user has explicitly asked for
    it. If a hook fails, investigate and fix the underlying issue.
 - Avoid unnecessary `sleep` commands:
  - Do not sleep between commands that can run immediately â€” just run
    them.
  - Do not retry failing commands in a sleep loop â€” diagnose the root
    cause or consider an alternative approach.
  - If you must sleep, keep the duration short (1-5 seconds) to avoid
    blocking the user.ÚdescriptionÚobjectÚstringzThe bash command to execute.)Útyper   z”Clear, concise description of what this command does. For simple commands, keep it brief (5-10 words). For complex commands, include enough context.Úintegerz?Optional timeout in milliseconds (default: 120000, max: 600000)éÀÔ éÀ'	 r   )r   r   ÚdefaultÚmaximumÚminimum)Úcommandr   Útimeoutr$   )r   Ú
propertiesÚrequiredÚinput_schemaFÚis_mcpÚis_read_onlyÚis_concurrency_safeÚis_external_toolÚis_state_injectedNÚdangerous_filesÚdangerous_directoriesÚcwdÚmiddlewaresÚbackendÚreturnc                 ó*  •— ddl m} t          ¦   «                              |¬¦  «         t	          ¦   «         | _        t          |¦  «        | _        t          |¦  «        | _        |�t          j
        |¦  «        nd| _        |p	 |¦   «         | _         dS )a  Initialize the bash tool.

        Args:
            dangerous_files (`list[str]`, optional):
                Sensitive files that require explicit user confirmation,
                even in BYPASS mode. Matched by basename
                (case-insensitive). Defaults to `DEFAULT_DANGEROUS_FILES`.
                Pass a custom list to fully replace the defaults, or `[]`
                to disable the filename check.
            dangerous_directories (`list[str]`, optional):
                Sensitive directories that require explicit user
                confirmation. Matched when any path segment equals an
                entry (case-insensitive). Defaults to
                `DEFAULT_DANGEROUS_DIRECTORIES`. Pass a custom list to
                fully replace the defaults, or `[]` to disable the
                directory check.
            cwd (`str | os.PathLike[str] | None`, optional):
                The working directory used when executing bash commands.
            middlewares (`List[ToolMiddlewareBase] | None`, optional):
                Tool middlewares wrapping the tool execution.
            backend (`BackendBase | None`, optional):
                The sandbox backend to use for shell execution. When
                ``None``, a :class:`LocalBackend` is created.
        r   )ÚLocalBackend)r1   N)Ú_backendr5   ÚsuperÚ__init__r   Ú_bash_parserÚlistr.   r/   ÚosÚfspathÚ_cwd)Úselfr.   r/   r0   r1   r2   r5   Ú	__class__s          €úLC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\tool\_builtin\_bash.pyr8   zBash.__init__‰   s�   ø€ ð@ 	+Ð*Ð*Ð*Ð*Ð*å‰Œ×Ò [ÐÑ1Ô1Ð1Ý-Ñ/Ô/ˆÔå# OÑ4Ô4ˆÔÝ%)Ð*?Ñ%@Ô%@ˆÔ"Ø&) o•B”I˜c‘N”N�N¸4ˆŒ	ØÐ1 < <¡>¤>ˆŒˆˆó    Ú
tool_inputc              ƒ   ó°   K  — |                      dd¦  «        }|s| j        S | j                             |¦  «        rdS | j                             |¦  «        S )a�  Decide whether this specific bash invocation is read-only.

        Inspects the command and returns ``True`` for known-safe read-only
        commands (e.g. ``ls``, ``cat``, ``grep``, ``git status``). The
        static :attr:`is_read_only` class attribute is ``False`` because
        Bash can execute arbitrary commands; this method overrides that
        with a per-invocation answer.
        r$   Ú F)Úgetr*   r9   Úcheck_injection_riskÚis_read_only_command)r>   rB   r$   s      r@   Úcheck_read_onlyzBash.check_read_only³   sc   è è € ð —.’. ¨BÑ/Ô/ˆØð 	%ØÔ$Ð$ð Ô×1Ò1°'Ñ:Ô:ð 	Ø�5ØÔ ×5Ò5°gÑ>Ô>Ð>rA   Úcontextc              ƒ   ó>  ‡ ‡K  — |                      dd¦  «        }|st          t          j        d¬¦  «        S ‰ j                             |¦  «        }|r t          t          j        d|› �dd¬¦  «        S ‰ j                             |¦  «        rt          t          j        d	d
¬¦  «        S ‰ j         	                    |¦  «        }|r t          t          j        d|› �dd¬¦  «        S ‰ j         
                    |‰ j        ¦  «        }|r t          t          j        d|› �dd¬¦  «        S ‰                      |¦  «        }|r5d                     |¦  «        }t          t          j        d|› �dd¬¦  «        S ‰                      |¦  «        ƒ d{V —†}	|	r!t          t          j        d|	› d�dd¬¦  «        S ‰j        t           j        t           j        fv r°h d£}
|                     ¦   «         r,|                     ¦   «                              ¦   «         d         nd}||
v rfd„ ‰ j                             |¦  «        D ¦   «         }|r@t-          ˆˆ fd„|D ¦   «         ¦  «        r$t          t          j        d|› d�d|› d�¬¦  «        S t          t          j        d|› �¬¦  «        S )uô  Check permissions for bash command execution.

        This method implements Bash-specific permission checks:

        0. Injection risk check (bypass-immune safety ASK if command
           contains dynamic expansion like ``$(...)`` or ``<(...)``)
        1. Read-only command check â€” auto-ALLOW in **every mode**
           (including DEFAULT) for known-safe read-only commands
           (``ls``, ``pwd``, ``git status``, ``cat``, etc.). This is
           the static counterpart to :meth:`check_read_only`.
        2. Dangerous command pattern check (bypass-immune safety ASK)
        3. Sed in-place constraint check (bypass-immune safety ASK)
        4. Dangerous path check for config files (bypass-immune safety
           ASK)
        5. Dangerous removal path check for system dirs (bypass-immune
           safety ASK)
        6. ACCEPT_EDITS auto-allow for ``mkdir``/``touch``/``rm``/
           ``rmdir``/``mv``/``cp``/``sed`` â€” only when **every**
           target path resolves inside a working directory
        7. PASSTHROUGH (engine continues with rule matching)

        "Bypass-immune" decisions set
        :attr:`PermissionDecision.bypass_immune` so they cannot be
        silenced by allow rules in DEFAULT mode. In BYPASS mode all
        bypass-immune ASKs are intentionally skipped â€” see
        :attr:`PermissionMode.BYPASS`.

        Args:
            tool_input (`dict[str, Any]`):
                The tool input containing "command" key
            context (`PermissionContext`):
                The permission context with mode and rules

        Returns:
            `PermissionDecision`:
                ALLOW for safe operations, ASK for dangerous operations,
                PASSTHROUGH to let Engine continue with rule matching
        r$   rD   zEmpty command)ÚbehaviorÚmessagezPermission required: zSSafety check: command contains dynamic expansion that cannot be statically analyzedT)rK   rL   Údecision_reasonÚbypass_immunez(Permission granted for read-only commandzRead-only command is allowed)rK   rL   rM   z9Permission required: Command contains dangerous pattern: z0Safety check: dangerous command pattern detectedz9Safety check: sed in-place modification of dangerous filez, z?Permission required: Bash command operates on sensitive paths: z9Safety check: dangerous file or directory in bash commandNz'Dangerous removal operation detected: 'z‰'

This command would remove a critical system directory. This requires explicit approval and cannot be auto-allowed by permission rules.z7Safety check: dangerous removal of critical system path>   ÚcpÚmvÚrmÚsedÚmkdirÚrmdirÚtouchr   c                 ó   — g | ]\  }}|‘ŒS © rW   )Ú.0Ú_cmdÚpaths      r@   ú
<listcomp>z*Bash.check_permissions.<locals>.<listcomp>j  s,   € ð  ð  ð  á"˜˜dð ð ð  ð  rA   c              3   óD   •K  — | ]}‰                      |‰¦  «        V — Œd S )N)Ú_path_in_allowed_working_path)rX   rZ   rI   r>   s     €€r@   ú	<genexpr>z)Bash.check_permissions.<locals>.<genexpr>v  sG   øè è € ð (ð (àð ×6Ò6°t¸WÑEÔEð(ð (ð (ð (ð (ð (rA   zPermission granted for 'z@' command (filesystem command, all targets in working directory)zFilesystem command 'zI' is auto-allowed because all target paths are within a working directoryzExecute bash command: )rE   r   r   ÚPASSTHROUGHr9   rF   ÚASKrG   ÚALLOWÚcheck_dangerous_commandÚcheck_sed_constraintsr.   Ú"_extract_dangerous_paths_from_bashÚjoinÚ_check_dangerous_removal_pathÚmoder   ÚACCEPT_EDITSÚDONT_ASKÚstripÚsplitÚextract_file_pathsÚall)r>   rB   rI   r$   Úinjection_reasonÚdangerous_patternÚ	sed_errorÚdangerous_pathsÚ	paths_strÚremoval_pathÚfilesystem_commandsÚbase_commandÚtarget_pathss   ` `          r@   Úcheck_permissionszBash.check_permissionsÌ   sÁ  øøè è € ðX —.’. ¨BÑ/Ô/ˆØð 	Ý%Ý+Ô7Ø'ðñ ô ð ð  Ô,×AÒAÀ'ÑJÔJÐØð 	Ý%Ý+Ô/ØBÐ0@ÐBÐBð!?à"ðñ ô ð ð Ô×1Ò1°'Ñ:Ô:ð 	Ý%Ý+Ô1ØBØ >ðñ ô ð ð !Ô-×EÒEÀgÑNÔNÐØð 	Ý%Ý+Ô/ð0Ø-ð0ð 0ð!à"ðñ ô ð ð Ô%×;Ò;ØØÔ ñ
ô 
ˆ	ð ð 	Ý%Ý+Ô/Ø;°	Ð;Ð;ð!$à"ðñ ô ð ð ×AÒAÀ'ÑJÔJˆØð 		ØŸ	š	 /Ñ2Ô2ˆIÝ%Ý+Ô/ð0Ø$-ð0ð 0ð!,à"ðñ ô ð ð "×?Ò?ÀÑHÔHÐHÐHÐHÐHÐHÐHˆØð 
	Ý%Ý+Ô/ð?Ø ð?ð ?ð ?ð!'à"ð	ñ 	ô 	ð 	ð$ Œ<ÝÔ'ÝÔ#ð
ð 
ð 
ð#ð #ð #Ðð /6¯mªm©o¬oÐE�—’‘”×%Ò%Ñ'Ô'¨Ô*Ð*À2ð ð Ð2Ð2Ð2ð ð  à&*Ô&7×&JÒ&JØñ'ô 'ð ñ  ô  �ð  ð ¥Cð (ð (ð (ð (ð (à ,ð(ñ (ô (ñ %ô %ð õ .Ý!3Ô!9ð!.¸<ð !.ð !.ð !.ð:°<ð :ð :ð :ð
ñ 
ô 
ð 
õ "Ý'Ô3Ø6¨WÐ6Ð6ð
ñ 
ô 
ð 	
rA   Úrule_contentc              ƒ   óþ  K  — |€dS |                      dd¦  «        }|                     d¦  «        r:|dd…                              ¦   «         }|                     |dz   ¦  «        p||k    S dt          d	t
          fd
„} ||¦  «        sH|}|                     dd¦  «        }|                     dd¦  «        }|                     dd¦  «        }||v S d}d}|}|                     d|¦  «        }|                     d|¦  «        }d}	|	D ]}
|                     |
d|
z   ¦  «        }Œ|                     dd¦  «        }|                     |d¦  «        }|                     |d¦  «        }|                     d¦  «        r5|dd…         }|                     ¦   «         }t          j	        ||¦  «        rdS 	 t          t          j	        ||¦  «        ¦  «        S # t          j
        $ r |                     dd¦  «        |v cY S w xY w)a$  Match Bash command using regex-based wildcard matching.

        Implements wildcard matching with escape sequences:
        - Supports \* for literal asterisk and \\ for literal backslash
        - Special optimization: "git *" matches both "git" and "git add"
        - Prefix pattern (e.g., "git:*"): matches commands starting with "git "
        - Wildcard pattern: converts to regex with proper escape handling
        - Substring pattern: exact substring matching
        - If rule_content is None, matches all invocations
         (tool-name-level rule)

        Args:
            rule_content: The command pattern to match, or None to match all
            tool_input: Must contain a "command" key with the command string

        Returns:
            True if pattern matches the command
        NTr$   rD   ú:*éþÿÿÿú Úpatternr3   c                 ó    — d}|t          | ¦  «        k     r8| |         dk    r|dz  }n| |         dk    rdS |dz  }|t          | ¦  «        k     °8dS )z0Check if pattern contains unescaped * wildcards.r   ú\r   Ú*Tr   F)Úlen)r}   Úis     r@   Úhas_wildcardsz&Bash.match_rule.<locals>.has_wildcards¯  si   € àˆAØ•c˜'‘l”lÒ"Ð"Ø˜1”: Ò%Ð%Ø˜‘F�A�AØ˜Q”Z 3Ò&Ð&Ø˜4à˜‘F�Að •c˜'‘l”lÒ"Ð"ð �5rA   z\\z BACKSLASH ú\*r€   r   z ESCAPED_STAR z ESCAPED_BACKSLASH z.^$+?{}[]|()z.*)rE   Úendswithrj   Ú
startswithÚstrÚboolÚreplaceÚrstripÚreÚ	fullmatchÚerror)r>   rx   rB   r$   Úprefixrƒ   r}   ÚESCAPED_STARÚESCAPED_BACKSLASHÚspecial_charsÚcharÚbase_patterns               r@   Ú
match_rulezBash.match_ruleŒ  sP  è è € ð0 ÐØ�4à—.’. ¨BÑ/Ô/ˆð × Ò  Ñ&Ô&ð 	IØ! # 2 #Ô&×,Ò,Ñ.Ô.ˆFØ×%Ò% f¨s¡lÑ3Ô3ÐH°wÀ&Ò7HÐHð
	¥3ð 
	­4ð 
	ð 
	ð 
	ð 
	ð ˆ}˜\Ñ*Ô*ð 	&ð #ˆGØ—o’o fÐ.AÑBÔBˆGØ—o’o e¨SÑ1Ô1ˆGØ—o’oÐ&9¸4Ñ@Ô@ˆGà˜gÐ%Ð%ð .ˆØ7Ðàˆà—/’/ &Ð*;Ñ<Ô<ˆà—/’/ %¨Ñ6Ô6ˆð (ˆØ!ð 	9ð 	9ˆDØ—o’o d¨D°4©KÑ8Ô8ˆGˆGð —/’/ # tÑ,Ô,ˆð —/’/ ,°Ñ6Ô6ˆØ—/’/Ð"3°UÑ;Ô;ˆð ×Ò˜DÑ!Ô!ð 	Ø" 3 B 3œ<ˆLà'×.Ò.Ñ0Ô0ˆLÝŒ|˜L¨'Ñ2Ô2ð Ø�tð	<Ý�œ W¨gÑ6Ô6Ñ7Ô7Ð7øÝŒxð 	<ð 	<ð 	<à×'Ò'¨¨RÑ0Ô0°GÐ;Ð;Ð;Ð;ð	<øøøs   Æ0!G Ç'G<Ç;G<r   c           	   ƒ   óò   K  — |                      dd¦  «        }|sg S | j                             |d¬¦  «        }|sg S g }|D ]5}|                     t	          d|› d�t
          j        d¬¦  «        ¦  «         Œ6|S )	aÉ  Generate suggested permission rules for Bash commands.

        Generates prefix rules based on command + subcommand (two words).
        For example, "git commit -m 'xxx'" generates "git commit:*".

        Args:
            tool_input (`dict[str, Any]`):
                The tool input data containing "command" key

        Returns:
            `List[PermissionRule]`:
                List of suggested permission rules based on command prefixes
        r$   rD   é   )Úmax_prefixesr   rz   Ú	suggested)Ú	tool_namerx   rK   Úsource)rE   r9   Úextract_command_prefixesÚappendr   r   ra   )r>   rB   r$   ÚprefixesÚrulesrŽ   s         r@   Úgenerate_suggestionszBash.generate_suggestionsí  s»   è è € ð$ —.’. ¨BÑ/Ô/ˆØð 	ØˆIð Ô$×=Ò=ØØð >ñ 
ô 
ˆð
 ð 	àˆIð ˆØð 	ð 	ˆFØ�LŠLÝØ$Ø$*   Ý/Ô5Ø&ð	ñ ô ñô ð ð ð ˆrA   c                 ó¢   — g }| j                              |¦  «        }|D ]/\  }}|                      |¦  «        r|                     |¦  «         Œ0|S )a�  Extract dangerous paths from a bash command using tree-sitter.

        Checks for dangerous paths in:
        - File-manipulating commands (rm, mv, cp, chmod, chown, sed, touch)
        - Output redirections (>, >>)

        Args:
            command (`str`):
                The bash command string

        Returns:
            `list[str]`:
                List of dangerous paths found in the command
        )r9   rl   Ú_is_dangerous_pathrœ   )r>   r$   rq   Ú
file_pathsÚ	_cmd_namerZ   s         r@   rd   z'Bash._extract_dangerous_paths_from_bash  se   € ð$ ˆð Ô&×9Ò9¸'ÑBÔBˆ
à)ð 	-ð 	-‰OˆI�tØ×&Ò& tÑ,Ô,ð -Ø×&Ò& tÑ,Ô,Ð,øàÐrA   c              ƒ   ó   K  — |                      ¦   «                              ¦   «         }|sdS 	 | j        j                             t          |d¦  «        ¦  «        }| j                             |j        |¦  «        }n# t          $ r |g}Y nw xY w|D ]¼}|                      ¦   «                              ¦   «         }|sŒ+|d         }|dvrŒ8d}|t          |¦  «        k     ro||         }	|	 
                    d¦  «        r|dz  }Œ6|	                      d¦  «        }
|                      |
¦  «        ƒ d{V —†r|
c S |dz  }|t          |¦  «        k     °oŒ½dS )a>  Check if a rm/rmdir command targets a critical system path.

        Detects commands like `rm -rf /`, `rm -rf /usr`, `rmdir ~` that
        would destroy critical system directories. Unlike _is_dangerous_path
        (which checks against a configurable list of sensitive config files),
        this checks against a fixed set of system-level paths that must
        never be removed regardless of user configuration.

        Dangerous paths are:
        - Root directory (/)
        - Home directory (~)
        - Wildcard alone (*) or as dir/* (removes everything)
        - Direct children of root (/usr, /etc, /tmp, /var, etc.)

        Args:
            command (`str`):
                The bash command string

        Returns:
            `str | None`:
                The dangerous path if found, None otherwise
        NÚutf8r   )rQ   rT   r   ú-z'")rj   rk   r9   ÚparserÚparseÚbytesÚsplit_compound_commandÚ	root_nodeÚ	Exceptionr�   r†   Ú_is_dangerous_removal_path)r>   r$   ÚtokensÚtreeÚsubcommandsÚsubcmdÚsubcmd_tokensÚbaser‚   ÚtokrZ   s              r@   rf   z"Bash._check_dangerous_removal_path8  s™  è è € ð. —’‘”×&Ò&Ñ(Ô(ˆØð 	Ø�4ð	$ØÔ$Ô+×1Ò1µ%¸ÀÑ2HÔ2HÑIÔIˆDØÔ+×BÒBØ”Øñô ˆKˆKøõ ð 	$ð 	$ð 	$Ø"˜)ˆKˆKˆKð	$øøøð "ð 	ð 	ˆFØ"ŸLšL™NœN×0Ò0Ñ2Ô2ˆMØ ð ØØ  Ô#ˆDØ˜?Ð*Ð*Øð ˆAØ•c˜-Ñ(Ô(Ò(Ð(Ø# AÔ&�à—>’> #Ñ&Ô&ð Ø˜‘F�AØØ—y’y Ñ'Ô'�Ø×8Ò8¸Ñ>Ô>Ð>Ð>Ð>Ð>Ð>Ð>ð  Ø�K�K�KØ�Q‘�ð •c˜-Ñ(Ô(Ò(Ð(øð ˆts   ®AA< Á<BÂBrZ   c              ƒ   óø  K  — |dv rdS |                      d¦  «        s|                      d¦  «        rdS | j                             |¦  «        ƒ d{V —†}| j                             ¦   «         ƒ d{V —†}| j                             ||¬¦  «        }| j                             d¦  «        ƒ d{V —†}||k    rdS | j                             |¦  «        }||k    rdS | j                             |¦  «        |k    rdS dS )	aù  Check if a path is a critical system directory that must not be
        removed.

        All path resolution is performed via the backend so that the
        check operates on the **backend environment's** ``$HOME`` /
        ``cwd`` / path semantics, not the host process's.

        Args:
            path (`str`):
                The path to check (may be relative, absolute, or contain ~)

        Returns:
            `bool`:
                True if removing this path would be catastrophic
        )r€   z./*ú/Tz/*r„   N)r0   Ú~F)r…   r6   Ú
expanduserÚgetcwdÚabspathÚdirname)r>   rZ   ÚexpandedÚbackend_cwdÚabs_pathÚhomeÚparents          r@   r­   zBash._is_dangerous_removal_pathu  s4  è è € ð$ Ð$Ð$Ð$Ø�4à�=Š=˜ÑÔð 	 $§-¢-°Ñ"6Ô"6ð 	Ø�4ð œ×1Ò1°$Ñ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7ˆØ œM×0Ò0Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2ˆØ”=×(Ò(¨°{Ð(ÑCÔCˆð ”]×-Ò-¨cÑ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2ˆØ�tÒÐØ�4ð
 ”×&Ò& xÑ0Ô0ˆØ�vÒÐØ�4ð
 Œ=× Ò  Ñ(Ô(¨FÒ2Ð2Ø�4àˆurA   rD   r%   c                ó†  K  — t          |d¦  «        }|dz  }	 t          j        dk    rdd|g}ndd|g}| j                             || j        |¬¦  «        ƒ d	{V —†}|j                             d
d¬¦  «                             dd¦  «        }|j	                             d
d¬¦  «                             dd¦  «        }	|j
        dk    rC|j	        dk    r8d|› d|› �}
t          t          |
¬¦  «        gt          j        d¬¦  «        W V — d	S |}|	r|r|dz  }||	z  }t          |¦  «        dk    r|d	d…         dz   }|                     ¦   «         sjd|› d�}|r|d|› �z  }|	r|d|	› �z  }t          |¦  «        dk    r|d	d…         dz   }t          t          |¬¦  «        gt          j        d¬¦  «        W V — d	S t          t          |¬¦  «        gt          j        d¬¦  «        W V — d	S # t$          $ rN}d|› dt'          |¦  «        › �}
t          t          |
¬¦  «        gt          j        d¬¦  «        W V — Y d	}~d	S d	}~ww xY w)ad  Execute the bash and return the output.

        Args:
            command: The bash command to execute.
            description: Optional description of what the command does.
            timeout: Timeout in milliseconds (default: 120000, max: 600000).

        Yields:
            ToolChunk: The tool execution result with stdout/stderr content.
        r    g     @�@ÚntÚcmdz/cz/bin/shz-c)r0   r%   Nzutf-8r‰   )Úerrorsz
ú
éÿÿÿÿs	   timed outzCommand timed out after zms: )ÚtextT)ÚcontentÚstateÚis_lasti0u  z
... (output truncated)zCommand failed: z	
Stdout:
z	
Stderr:
z
Error: )Úminr;   r   r6   Ú
exec_shellr=   ÚstdoutÚdecoder‰   ÚstderrÚ	exit_coder   r   r   ÚERRORr�   ÚokÚRUNNINGr¬   r‡   )r>   r$   r   r%   Ú
timeout_msÚtimeout_secÚshell_commandÚresultrÍ   rÏ   Ú	error_msgÚoutputÚerror_resultÚes                 r@   Úcallz	Bash.call©  s†  è è € õ$ ˜ &Ñ)Ô)ˆ
Ø  6Ñ)ˆðW	õ Œw˜$ŠˆØ!&¨¨gÐ 6��à!*¨D°'Ð :�Øœ=×3Ò3ØØ”IØ#ð 4ñ ô ð ð ð ð ð ð ˆFð ”]×)Ò)ØØ ð *ñ ô ÷ Šg�f˜dÑ#Ô#ð ð ”]×)Ò)ØØ ð *ñ ô ÷ Šg�f˜dÑ#Ô#ð ð Ô 2Ò%Ð%¨&¬-¸<Ò*GÐ*GàH¨zÐHÐH¸wÐHÐHð õ  Ý&¨IÐ6Ñ6Ô6Ð7Ý)Ô/Ø ðñ ô ð ð ð ð ð
 �ð ˆFØð !Øð #Ø˜d‘N�FØ˜&Ñ �õ �6‰{Œ{˜UÒ"Ð"Ø   œÐ*DÑD�ð —9’9‘;”;ð à=°'Ð=Ð=Ð=�Øð ;Ø Ð$:°&Ð$:Ð$:Ñ:�LØð ;Ø Ð$:°&Ð$:Ð$:Ñ:�Lõ �|Ñ$Ô$ uÒ,Ð,à$ V e VÔ,Ð/IÑIð !õ  Ý&¨LÐ9Ñ9Ô9Ð:Ý)Ô/Ø ðñ ô ð ð ð ð ð ð õ  Ý&¨FÐ3Ñ3Ô3Ð4Ý)Ô1Ø ðñ ô ð ð ð ð ð ð øõ ð 	ð 	ð 	àE¨7ÐEÐE½SÀ¹V¼VÐEÐEˆIÝÝ"¨	Ð2Ñ2Ô2Ð3Ý%Ô+Øðñ ô ð ð ð ð ð ð ð ð ð ð øøøøð	øøøs&   ™C/G( Ä
B,G( Æ8.G( Ç(
I Ç2AH;È;I )rD   r   )(Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r‡   Ú__annotations__r   r(   Údictr   r)   rˆ   r*   r+   r,   r-   r   r   r:   r;   ÚPathLiker   r
   r   r8   rH   r   r   rw   r”   rŸ   rd   rf   r­   Úintr   r   rÜ   Ú__classcell__)r?   s   @r@   r   r      s�  ø€ € € € € € ØÐà€Dˆ#ÐÐÑØ/ðC€K�ð Cð Cñ CðH 2ð ð !Ø=ðð ð
 !ððð ð "ð5ð "Ø!Øð	ð 	ð
ð 
ð2 �Kð7$ð $€L�$�s˜C�x”.ð ð ñ ð< €FˆDÐÐÑØ€L�$ÐÐÑØ %Ð˜Ð%Ð%Ñ%Ø"Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#ð &=Ø+HØ-1Ø7;Ø&*ð(2ð (2à˜cœð(2ð  $ Cœyð(2ð �2”;˜sÔ#Ñ# dÑ*ð	(2ð
 Ð,Ô-°Ñ4ð(2ð ˜tÑ#ð(2ð 
ð(2ð (2ð (2ð (2ð (2ð (2ðT?à˜˜c˜”Nð?ð 
ð?ð ?ð ?ð ?ð2~
à˜˜c˜”Nð~
ð #ð~
ð 
ð	~
ð ~
ð ~
ð ~
ð@_<à˜D‘jð_<ð ˜˜c˜”Nð_<ð 
ð	_<ð _<ð _<ð _<ðB,à˜˜c˜”Nð,ð 
ÐÔ	ð,ð ,ð ,ð ,ð\àðð 
ˆcŒðð ð ð ð:;¸3ð ;À3ÈÁ:ð ;ð ;ð ;ð ;ðz2°Sð 2¸Tð 2ð 2ð 2ð 2ðn Øð	lð làðlð ðlð ð	lð
 
˜	 4˜Ô	(ðlð lð lð lð lð lð lð lrA   r   )rà   r;   Útypingr   r   r   r‹   r9   r   Ú_baser	   r
   Ú
_constantsr   r   Ú
permissionr   r   r   r   r   rL   r   r   Ú	_responser   r6   r   r   rW   rA   r@   ú<module>rë      sO  ðà "Ð "Ø 	€	€	€	Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 	€	€	€	à +Ð +Ð +Ð +Ð +Ð +Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 2Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø !Ð !Ð !Ð !Ð !Ð !Ø !Ð !Ð !Ð !Ð !Ð !ð|ð |ð |ð |ð |ˆ8ñ |ô |ð |ð |ð |rA   