Class CodingAgentShell

  • All Implemented Interfaces:

    
    public final class CodingAgentShell
    
                        

    Enhanced shell command execution subsystem for AI coding agents.

    Extends AgentShell's basic read-only command support to include full development tooling: compilers, build systems, package managers, version control, scripting runtimes, and more. Designed for use in autonomous coding agents that need to write, build, test, and deploy code.

    Commands are validated against a tiered allow-list:

    • safe — read-only commands always permitted (subset of AgentShell whitelist)

    • dev — development tools permitted when allowDevTools is true (default)

    • network — network-accessing tools require explicit opt-in (allowNetwork)

    • destructive — write/delete operations require explicit opt-in (allowDestructive)

    Environment variables can be injected per-session or per-command.

    • Constructor Detail

      • CodingAgentShell

        CodingAgentShell(Path baseDir, Long defaultTimeoutSeconds, Boolean allowDevTools, Boolean allowNetwork, Boolean allowDestructive)
    • Method Detail

      • getCanonicalWorkspaceDir

         final Path getCanonicalWorkspaceDir()

        Canonical workspace directory used as the default command working directory.

      • execute

         final String execute(String command, Long timeoutSeconds, String workingDir, Map<String, String> env)

        Execute a command with full development tool support.

        Parameters:
        command - The command to execute
        timeoutSeconds - Timeout in seconds (default: 120, max: 600)
        workingDir - Working directory override (absolute, or relative to baseDir)
        env - Additional environment variables for this command
        Returns:

        Formatted execution result string

      • setEnv

         final Unit setEnv(String name, String value)

        Set a persistent environment variable for all subsequent commands in this session.

      • allowCommand

         final Unit allowCommand(String name)

        Allow a specific command by its base name (e.g. "ffmpeg", "pandoc"). This adds the command to a per-instance allow-list that overrides the category check — even if the command is not in any predefined set, it will be permitted.

        Example:

        shell.allowCommand("ffmpeg")    // allow ffmpeg even though it's not in DEV_COMMANDS
        shell.allowCommand("pandoc")    // allow pandoc
      • denyCommand

         final Unit denyCommand(String name)

        Deny a specific command by its base name (e.g. "git", "curl"). This adds the command to a per-instance deny-list. The deny list takes priority over everything — even SAFE_COMMANDS and explicit allows — so you can lock down a command entirely.

        Example:

        shell.denyCommand("git")        // block git entirely
        shell.denyCommand("curl")       // block curl even if allowNetwork=true
      • resetCommand

         final Unit resetCommand(String name)

        Remove a command from both the allow and deny lists, reverting to the default category-based policy.

      • allowPattern

         final Unit allowPattern(Regex pattern)

        Allow commands matching a regex pattern. The full command string (e.g. "pip install requests") is tested against the pattern.

        Example:

        shell.allowPattern(Regex("pip\\s+install.*"))   // allow pip install
        shell.allowPattern(Regex("npm\\s+run\\s+.*"))   // allow npm run <script>
      • denyPattern

         final Unit denyPattern(Regex pattern)

        Deny commands matching a regex pattern. Deny patterns take priority over allow patterns — if a command matches both, it is denied.

        Example:

        shell.denyPattern(Regex("git\\s+push.*--force"))  // block force push
        shell.denyPattern(Regex("rm\\s+-rf\\s+/"))         // block recursive root delete
      • explain

         final String explain(String command)

        Show the current effective policy for a command — why it's allowed or denied. Returns a human-readable explanation.

      • isAllowed

         final Boolean isAllowed(String command)

        Check whether a command would be allowed without actually executing it.

      • git

         final String git(String args, Long timeoutSeconds)

        Execute a git command in the workspace.

      • detectProjectType

         final String detectProjectType()

        Detect the project type in the workspace by looking for build files.