|
14 | 14 |
|
15 | 15 | (def ^:private logger-tag "[AGENTS-MD]") |
16 | 16 |
|
| 17 | +(def ^:private tool-arg-name |
| 18 | + "Maps tool names to the argument name used for regex pattern matching in argsMatchers. |
| 19 | + Only tools that support pattern-based approval need an entry here." |
| 20 | + {"eca__shell_command" "command"}) |
| 21 | + |
| 22 | +(defn ^:private parse-tool-entry |
| 23 | + "Parses a tool entry string into [tool-name config]. |
| 24 | + Plain names like 'eca__read_file' -> ['eca__read_file' {}] |
| 25 | + Pattern entries like 'eca__shell_command(npm run .*)' -> ['eca__shell_command' {:argsMatchers {'command' ['npm run .*']}}]" |
| 26 | + [entry] |
| 27 | + (let [s (str entry)] |
| 28 | + (if-let [[_ tool-name pattern] (re-matches #"(.+?)\((.+)\)" s)] |
| 29 | + (if-let [arg-name (get tool-arg-name tool-name)] |
| 30 | + [tool-name {:argsMatchers {arg-name [pattern]}}] |
| 31 | + (do (logger/warn logger-tag (format "Tool '%s' has pattern '%s' but no arg-name mapping in tool-arg-name; pattern will be ignored" tool-name pattern)) |
| 32 | + [tool-name {}])) |
| 33 | + [s {}]))) |
| 34 | + |
17 | 35 | (defn ^:private tools-list->approval-map |
18 | | - [tool-names] |
19 | | - (when (seq tool-names) |
20 | | - (into {} (map (fn [name] [(str name) {}]) tool-names)))) |
| 36 | + [tool-entries] |
| 37 | + (when (seq tool-entries) |
| 38 | + (reduce |
| 39 | + (fn [acc entry] |
| 40 | + (let [[tool-name config] (parse-tool-entry entry)] |
| 41 | + (if (contains? acc tool-name) |
| 42 | + ;; Merge argsMatchers patterns for repeated tool entries |
| 43 | + (update-in acc [tool-name :argsMatchers] |
| 44 | + (fn [existing new-matchers] |
| 45 | + (merge-with into existing new-matchers)) |
| 46 | + (:argsMatchers config)) |
| 47 | + (assoc acc tool-name config)))) |
| 48 | + {} |
| 49 | + tool-entries))) |
21 | 50 |
|
22 | 51 | (defn ^:private md->agent-config |
23 | 52 | [{:keys [description mode model steps tools body inherit]}] |
|
0 commit comments