Skip to content

Commit 5617b04

Browse files
ericdalloeca
andcommitted
<commit_analysis>
- Changed files: deps.edn, src/eca/features/tools/shell.clj, test/eca/features/tools/shell_test.clj - Change type: refactor tooling, dependency update, docs expansion, and test updates - Purpose: replace clojure.java.shell with babashka.process for more robust, configurable process execution and clearer behavior; document safe shell usage and our git/PR workflow; keep tests aligned - Impact: introduces babashka/process runtime dep; shell execution now routes through bash -c which improves consistency but may change quoting expectations; tests updated accordingly; no API surface changes for consumers beyond improved docs - Sensitive info: none detected - Draft message: Migrate shell tool to babashka.process; expand eca_shell_command docs; update tests </commit_analysis> Migrate shell tool to babashka.process; expand eca_shell_command docs; update tests - Replace clojure.java.shell with babashka.process and execute via bash -c for consistent env and better output handling - Add babashka/process dependency and align build alias version - Expand tool description with safe execution rules and detailed git/PR guidance - Update tests to stub babashka.process instead of clojure.java.shell Why: more reliable process handling, clearer UX, and consistency across environments. 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca <[email protected]>
1 parent 2a3ef50 commit 5617b04

File tree

3 files changed

+135
-17
lines changed

3 files changed

+135
-17
lines changed

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
io.modelcontextprotocol.sdk/mcp {:mvn/version "0.11.0"}
77
borkdude/dynaload {:mvn/version "0.3.5"}
88
babashka/fs {:mvn/version "0.5.26"}
9+
babashka/process {:mvn/version "0.6.23"}
910
hato/hato {:mvn/version "1.0.0"}
1011
org.slf4j/slf4j-simple {:mvn/version "2.0.17"}
1112
com.googlecode.java-diff-utils/diffutils {:mvn/version "1.3.0"}
@@ -22,7 +23,7 @@
2223
:main-opts ["-m" "kaocha.runner"]}
2324
:build {:extra-paths ["resources"]
2425
:extra-deps {babashka/fs {:mvn/version "0.5.22"}
25-
babashka/process {:mvn/version "0.5.22"}}
26+
babashka/process {:mvn/version "0.6.23"}}
2627
:replace-deps {io.github.clojure/tools.build {:tag "v0.10.7" :sha "573711e"}
2728
com.github.ericdallo/deps-bin {:mvn/version "1.0.0"}
2829
slipset/deps-deploy {:mvn/version "0.2.2"}}

src/eca/features/tools/shell.clj

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
(ns eca.features.tools.shell
22
(:require
33
[babashka.fs :as fs]
4-
[clojure.java.shell :as shell]
4+
[babashka.process :as p]
55
[clojure.string :as string]
66
[eca.config :as config]
77
[eca.features.tools.util :as tools.util]
88
[eca.logger :as logger]
9-
[eca.shared :as shared]))
9+
[eca.shared :as shared :refer [multi-str]]))
1010

1111
(set! *warn-on-reflection* true)
1212

1313
(def ^:private logger-tag "[TOOLS-SHELL]")
1414

1515
(defn ^:private shell-command [arguments {:keys [db config]}]
16-
(let [command (get arguments "command")
16+
(let [command-args (get arguments "command")
17+
command (first (string/split command-args #"\s+"))
1718
user-work-dir (get arguments "working_directory")
18-
exclude-cmds (-> config :nativeTools :shell :excludeCommands set)
19-
command-args (string/split command #" ")]
19+
exclude-cmds (-> config :nativeTools :shell :excludeCommands set)]
2020
(or (tools.util/invalid-arguments arguments [["working_directory" #(or (nil? %)
2121
(fs/exists? %)) "working directory $working_directory does not exist"]
22-
["commmand" (constantly (not (contains? exclude-cmds (first command-args)))) (format "Cannot run command '%s' because it is excluded by eca config."
23-
(first command-args))]])
22+
["commmand" (constantly (not (contains? exclude-cmds command))) (format "Cannot run command '%s' because it is excluded by eca config."
23+
command)]])
2424
(let [work-dir (or (some-> user-work-dir fs/canonicalize str)
2525
(some-> (:workspace-folders db)
2626
first
2727
:uri
2828
shared/uri->filename)
2929
(config/get-property "user.home"))
30-
command-and-opts (concat [] command-args [:dir work-dir])
30+
command-and-opts (concat ["bash -c"] command-args [:dir work-dir])
3131
_ (logger/debug logger-tag "Running command:" command-and-opts)
3232
result (try
33-
(apply shell/sh command-and-opts)
33+
(p/shell {:dir work-dir :out :string :err :string} "bash -c" command-args)
3434
(catch Exception e
3535
{:exit 1 :err (.getMessage e)}))
3636
err (some-> (:err result) string/trim)
@@ -51,8 +51,125 @@
5151

5252
(def definitions
5353
{"eca_shell_command"
54-
{:description (str "Execute an arbitrary shell command and return the output. "
55-
"Useful to run commands like `ls`, `git status`, etc.")
54+
{:description (multi-str "Execute an arbitrary shell command and return the output.
55+
1. Command Execution:
56+
- Always quote file paths that contain spaces with double quotes (e.g., cd \" path with spaces/file.txt \")
57+
- Examples of proper quoting:
58+
- cd \"/Users/name/My Documents\" (correct)
59+
- cd /Users/name/My Documents (incorrect - will fail)
60+
- python \"/path/with spaces/script.py\" (correct)
61+
- python /path/with spaces/script.py (incorrect - will fail)
62+
- After ensuring proper quoting, execute the command.
63+
- Capture the output of the command.
64+
- VERY IMPORTANT: You MUST avoid using search command `grep`. Instead use eca_grep to search. You MUST avoid read tools like `cat`, `head`, `tail`, and `ls`, and use eca_read_file or eca_directory_tree.
65+
66+
# Committing changes with git
67+
68+
When the user asks you to create a new git commit, follow these steps carefully:
69+
70+
1.:
71+
- Run a git status command to see all untracked files.
72+
- Run a git diff command to see both staged and unstaged changes that will be committed.
73+
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
74+
75+
2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
76+
77+
<commit_analysis>
78+
- List the files that have been changed or added
79+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
80+
- Brainstorm the purpose or motivation behind these changes
81+
- Assess the impact of these changes on the overall project
82+
- Check for any sensitive information that shouldn't be committed
83+
- Draft a concise (1-2 sentences) commit message that focuses on the \"why\" rather than the \"what\"
84+
- Ensure your language is clear, concise, and to the point
85+
- Ensure the message accurately reflects the changes and their purpose (i.e. \"add\" means a wholly new feature, \" update \" means an enhancement to an existing feature, \"fix\" means a bug fix, etc.)
86+
- Ensure the message is not generic (avoid words like \"Update\" or \"Fix\" without context)
87+
- Review the draft message to ensure it accurately reflects the changes and their purpose
88+
</commit_analysis>
89+
90+
3.:
91+
- Add relevant untracked files to the staging area.
92+
- Create the commit with a message ending with:
93+
🤖 Generated with [eca](https://eca.dev)
94+
95+
Co-Authored-By: eca <[email protected]>
96+
- Run git status to make sure the commit succeeded.
97+
98+
4. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
99+
100+
Important notes:
101+
- Use the git context at the start of this conversation to determine which files are relevant to your commit. Be careful not to stage and commit files (e.g. with `git add .`) that aren't relevant to your commit.
102+
- NEVER update the git config
103+
- DO NOT run additional commands to read or explore code, beyond what is available in the git context
104+
- DO NOT push to the remote repository
105+
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
106+
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
107+
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
108+
- Return an empty response - the user will see the git output directly
109+
- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
110+
<example>
111+
git commit -m \"$(cat <<'EOF'
112+
Commit message here.
113+
114+
🤖 Generated with [opencode](https://opencode.ai)
115+
116+
Co-Authored-By: opencode <[email protected]>
117+
EOF
118+
)\"
119+
</example>
120+
121+
# Creating pull requests
122+
Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
123+
124+
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
125+
126+
1. In order to understand the current state of the branch since it diverged from the main branch:
127+
- Run a git status command to see all untracked files
128+
- Run a git diff command to see both staged and unstaged changes that will be committed
129+
- Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
130+
- Run a git log command and `git diff main...HEAD` to understand the full commit history for the current branch (from the time it diverged from the `main` branch)
131+
132+
2. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (NOT just the latest commit, but ALL commits that will be included in the pull request!!!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:
133+
134+
<pr_analysis>
135+
- List the commits since diverging from the main branch
136+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
137+
- Brainstorm the purpose or motivation behind these changes
138+
- Assess the impact of these changes on the overall project
139+
- Do not use tools to explore code, beyond what is available in the git context
140+
- Check for any sensitive information that shouldn't be committed
141+
- Draft a concise (1-2 bullet points) pull request summary that focuses on the \"why\" rather than the \"what\"
142+
- Ensure the summary accurately reflects all changes since diverging from the main branch
143+
- Ensure your language is clear, concise, and to the point
144+
- Ensure the summary accurately reflects the changes and their purpose (ie. \"add\" means a wholly new feature, " update " means an enhancement to an existing feature, \"fix\" means a bug fix, etc.)
145+
- Ensure the summary is not generic (avoid words like \"Update\" or \"Fix\" without context)
146+
- Review the draft summary to ensure it accurately reflects the changes and their purpose
147+
</pr_analysis>
148+
149+
3. ALWAYS run the following commands in parallel:
150+
- Create new branch if needed
151+
- Push to remote with -u flag if needed
152+
- Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
153+
<example>
154+
gh pr create --title \"the pr title\" --body \"$(cat <<'EOF'
155+
## Summary
156+
<1-3 bullet points>
157+
158+
## Test plan
159+
[Checklist of TODOs for testing the pull request...]
160+
161+
🤖 Generated with [opencode](https://opencode.ai)
162+
EOF
163+
)\"
164+
</example>
165+
166+
Important:
167+
- NEVER update the git config
168+
- Return the PR URL when you're done, so the user can see it
169+
170+
# Other common operations
171+
- View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments
172+
")
56173
:parameters {:type "object"
57174
:properties {"command" {:type "string"
58175
:description "The shell command to execute."}

test/eca/features/tools/shell_test.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns eca.features.tools.shell-test
22
(:require
33
[babashka.fs :as fs]
4-
[clojure.java.shell :as shell]
4+
[babashka.process :as p]
55
[clojure.test :refer [deftest is testing]]
66
[eca.features.tools.shell :as f.tools.shell]
77
[eca.test-helper :as h]
@@ -26,7 +26,7 @@
2626
{:type :text
2727
:text "Stderr:\nSome error"}]}
2828
(with-redefs [fs/exists? (constantly true)
29-
shell/sh (constantly {:exit 1 :err "Some error"})]
29+
p/shell (constantly {:exit 1 :err "Some error"})]
3030
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
3131
{"command" "ls -lh"}
3232
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))
@@ -36,7 +36,7 @@
3636
:contents [{:type :text
3737
:text "Some text"}]}
3838
(with-redefs [fs/exists? (constantly true)
39-
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
39+
p/shell (constantly {:exit 0 :out "Some text" :err "Other text"})]
4040
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
4141
{"command" "ls -lh"}
4242
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))
@@ -46,7 +46,7 @@
4646
:contents [{:type :text
4747
:text "Some text"}]}
4848
(with-redefs [fs/exists? (constantly true)
49-
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
49+
p/shell (constantly {:exit 0 :out "Some text" :err "Other text"})]
5050
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
5151
{"command" "ls -lh"
5252
"working_directory" (h/file-path "/project/foo/src")}
@@ -57,7 +57,7 @@
5757
:contents [{:type :text
5858
:text "Some text"}]}
5959
(with-redefs [fs/exists? (constantly true)
60-
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
60+
p/shell (constantly {:exit 0 :out "Some text" :err "Other text"})]
6161
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
6262
{"command" "rm -r /project/foo/src"}
6363
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}

0 commit comments

Comments
 (0)