Skip to content

Commit

Permalink
Add git example
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Nov 21, 2024
1 parent 9e0d94b commit 8c9df40
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
55 changes: 55 additions & 0 deletions prompts/examples/git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
tools:
- name: append
parameters:
type: object
properties:
file:
type: string
description: the file to append to
message:
type: string
description: special message
container:
image: vonwig/bash_alpine
command:
- "-c"
- "echo \"{{message}}\" >> {{file}}"
- name: git
parameters:
type: object
properties:
args:
type: array
description: the args to send to git
items:
type: string
container:
image: alpine/git:latest
mounts:
- "/Users/slim/agent/.ssh:/root/.ssh:ro"
- "/Users/slim/agent/.gitconfig:/root/.gitconfig:ro"
command:
- --no-pager
- "{{args|into}}"
host-dir: /Users/slim/repo/bobloblaw
---

# Background

This shows how an agent can work with a _private_ git repository.

This tests that we can clone and make a change to a private repo. The git container mounts a prepared .ssh directory and .gitconfig file. In order to try this one, you'll need to do 3 things.

1. Create an empty directory on your host machine and update the `host-dir` parameter to point at it. Make it empty. The agent is going to clone into this.
1. Update the two mounts in git tool entry. They need a valid .ssh and .gitconfig that are okay sharing with the git container (read-only).
2. Update the prompt below to point at a private repo with a README.md that we can update.

# prompt user

1. use the git tool to clone git@github.com:slimslenderslacks/bobloblaw.git into the current directory. Do not create a new directory. It's okay if this
fails because the repository is already cloned.
2. use the append tool to write me a special message in the README.md file.
3. use the git tool to commit the changes to the README.md file with the message "thankyou for being you".
4. use the git tool to push the changes.

4 changes: 2 additions & 2 deletions src/docker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
;; Tty wraps the process in a pseudo terminal
{:StdinOnce true
:OpenStdin true}
(defn create-container [{:keys [image entrypoint command host-dir env thread-id opts mounts] :or {opts {:Tty true}}}]
(defn create-container [{:keys [image entrypoint working-dir command host-dir env thread-id opts mounts] :or {opts {:Tty true}}}]
(let [payload (json/generate-string
(merge
{:Image image}
Expand All @@ -122,7 +122,7 @@
"/var/run/docker.sock:/var/run/docker.sock"]
(when thread-id [(format "%s:/thread:rw" thread-id)])
mounts)}
:WorkingDir "/project"})
:WorkingDir (or working-dir "/project")})
(when entrypoint {:Entrypoint entrypoint})
(when command {:Cmd command})))]
(curl/post
Expand Down
8 changes: 6 additions & 2 deletions src/tools.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
git
jsonrpc
[selmer.filters :as filters]
[selmer.parser :as selmer]))
[selmer.parser :as selmer]
trace))

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

Expand Down Expand Up @@ -64,13 +65,16 @@
(dissoc defaults :functions)
{:command (interpolate-coll
(-> definition :container :command)
arg-context)})]
arg-context)}
(when-let [wd (-> definition :container :working-dir)]
{:working-dir (first (interpolate arg-context wd))}))]
(jsonrpc/notify
:message
{:debug (format "function call %s"
(with-out-str
(pp/pprint (-> function-call
(update :jwt (fn [s] (if s "xxxxxxx" "not-set")))))))})
(trace/container-call (update function-call :jwt (fn [s] (if s "xxxxxxx" "not-set"))))
(let [{:keys [pty-output exit-code done] :as result} (docker/run-container function-call)
exit-code-fail? (if (false? (:check-exit-code definition))
false
Expand Down

0 comments on commit 8c9df40

Please sign in to comment.