eca icon indicating copy to clipboard operation
eca copied to clipboard

Improve granularity of approve `eca_shell_command` tool

Open afucher opened this issue 1 year ago • 20 comments

Using the new "approve and remember" with the eca_shell_command tool does not work as I expect, since it just allows every call to this tool independent which command it is executing. So, I allow it to run a git checkout -b <new_branch> and now it can do anything in my shell 😅

Cursor for example, the allow list is per command not tool in this case:

Image Image

Claude also has this feature:

Image Image

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

afucher avatar Oct 10 '25 13:10 afucher

The approve is by tool-call-name here, let me check if it's working as expected

ericdallo avatar Oct 10 '25 13:10 ericdallo

Yeah, but in this case the tool is always eca_shell_command, no matter which command it is running

afucher avatar Oct 10 '25 13:10 afucher

Ah you are right, we are saving by tool name, not sure there is much to do here unless we make ifs specifically for that tool

ericdallo avatar Oct 10 '25 13:10 ericdallo

@zikajk any thoughts?

ericdallo avatar Oct 10 '25 13:10 ericdallo

Yes, I agree. I wanted to open this ticket myself :-). I am just not sure what is the best granularity.

zikajk avatar Oct 10 '25 14:10 zikajk

each tool call may have different args, so we will need to have an optional extensibility for them, but I agree it makes sense We will need to think how to adapt this to the protocol too, if we intend to change UX

ericdallo avatar Oct 10 '25 14:10 ericdallo

updated the description with Claude example of the same feature

afucher avatar Oct 13 '25 11:10 afucher

@afucher does claude saves per shell command + args so? if the command is echo > foo | awk | ... it will save only for that specific command or any echo commands?

ericdallo avatar Oct 13 '25 12:10 ericdallo

FWIW claude code makes heavy use of calling lightweight models like haiku to perform basic security checks. You can read about this here: https://jannesklaas.github.io/ai/2025/07/20/claude-code-agent-design.html

Ramblurr avatar Oct 16 '25 07:10 Ramblurr

There is a similar, but less problematic, issue with other tool calls as well. For example, eca_*_file. If I allow, say, eca_write_file README.md, I have now allowed eca_write_file for all files. I'm bringing this up so that we can come up with a general solution that could apply to all tools.

bombaywalla avatar Oct 16 '25 17:10 bombaywalla

There is a similar, but less problematic, issue with other tool calls as well. For example, eca_*_file. If I allow, say, eca_write_file README.md, I have now allowed eca_write_file for all files. I'm bringing this up so that we can come up with a general solution that could apply to all tools.

I believe this is how it should behave. It wouldn't be really helpful if you would have to allow it for each file, right?

zikajk avatar Oct 16 '25 17:10 zikajk

Yeah, I'm not sure what's the best way to solve this issue, that's why I didn't touch yet, would be nice to have something generic but what would be the logic?

ericdallo avatar Oct 16 '25 18:10 ericdallo

@Ramblurr I don't see there anything related to the issue. Am I missing something? @ericdallo I would just save the "main" command like CC does. This is an example of my project local settings, that has been updated based on my interactive auto-approvals.

     "Bash(grep:*)",
      "mcp__sequential-thinking__sequentialthinking",
      "mcp__clojure-mcp__glob_files",
      "mcp__clojure-mcp__grep",
      "Bash(rg:*)",
      "mcp__clojure-mcp__scratch_pad",
      "Bash(clj-kondo:*)",
      "Bash(find:*)"

zikajk avatar Oct 16 '25 18:10 zikajk

Btw. The issue @bombaywalla has can be solved by manually specifing the file(s) by argsMatchers, right?

zikajk avatar Oct 16 '25 18:10 zikajk

@Ramblurr I don't see there anything related to the issue. Am I missing something?

In the linked article read the section heading "Haiku For Security Checks" it explains how they are using the small/fast model haiku for identifying "similar" commands

Ramblurr avatar Oct 18 '25 11:10 Ramblurr

I’ve been thinking about whether we could try something similar to CC. Basically, when the LLM calls ECA_SHELL, it would simultaneously return the part of the command we can use in the approval mechanism—it's risky, but I don't see much of an alternative.

For other edit tools, it would probably suffice to create a rule where: a) approval is applied to the repository / workspace. b) if the folder is neither a repository nor a workspace, it applies to the given directory.

@ericdallo wdyt?

zikajk avatar May 03 '26 12:05 zikajk

I think so, I'm ok exploring and testing what works best for this

ericdallo avatar May 04 '26 18:05 ericdallo

I mentioned this same problem in Slack. My proposed solution was a bash parser. Unfortunately, bash isn't the easiest to parse. One option is a parser like Antlr and finding a grammar. Here is a POC I had deepseek whip up using shfmt. It's a cli tool that takes a bash string and outputs an AST. For the diff above, shfmt is outputting json and which is parsed to a vector of commands and args. That is then returned to the client to be displayed however. With the AST, we can do fine grain permissions on commands their args. That's not implemented for this POC but it's trivial to implement.

This does add an optional dependency though.

andilavera avatar May 11 '26 13:05 andilavera

I liked this command break down, not sure abotu the protocl, but it's the best so far I guess

ericdallo avatar Jul 13 '26 15:07 ericdallo

thanks for the POC @AndiLavera, implemented but making a thing layer in clojure instead shfmt. requires client update, only on emacs for now, will work on other clients

Image

ericdallo avatar Jul 13 '26 23:07 ericdallo