Skip to content

Commit 8c9df40

Browse files
Add git example
1 parent 9e0d94b commit 8c9df40

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

prompts/examples/git.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
tools:
3+
- name: append
4+
parameters:
5+
type: object
6+
properties:
7+
file:
8+
type: string
9+
description: the file to append to
10+
message:
11+
type: string
12+
description: special message
13+
container:
14+
image: vonwig/bash_alpine
15+
command:
16+
- "-c"
17+
- "echo \"{{message}}\" >> {{file}}"
18+
- name: git
19+
parameters:
20+
type: object
21+
properties:
22+
args:
23+
type: array
24+
description: the args to send to git
25+
items:
26+
type: string
27+
container:
28+
image: alpine/git:latest
29+
mounts:
30+
- "/Users/slim/agent/.ssh:/root/.ssh:ro"
31+
- "/Users/slim/agent/.gitconfig:/root/.gitconfig:ro"
32+
command:
33+
- --no-pager
34+
- "{{args|into}}"
35+
host-dir: /Users/slim/repo/bobloblaw
36+
---
37+
38+
# Background
39+
40+
This shows how an agent can work with a _private_ git repository.
41+
42+
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.
43+
44+
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.
45+
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).
46+
2. Update the prompt below to point at a private repo with a README.md that we can update.
47+
48+
# prompt user
49+
50+
1. use the git tool to clone [email protected]:slimslenderslacks/bobloblaw.git into the current directory. Do not create a new directory. It's okay if this
51+
fails because the repository is already cloned.
52+
2. use the append tool to write me a special message in the README.md file.
53+
3. use the git tool to commit the changes to the README.md file with the message "thankyou for being you".
54+
4. use the git tool to push the changes.
55+

src/docker.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
;; Tty wraps the process in a pseudo terminal
108108
{:StdinOnce true
109109
:OpenStdin true}
110-
(defn create-container [{:keys [image entrypoint command host-dir env thread-id opts mounts] :or {opts {:Tty true}}}]
110+
(defn create-container [{:keys [image entrypoint working-dir command host-dir env thread-id opts mounts] :or {opts {:Tty true}}}]
111111
(let [payload (json/generate-string
112112
(merge
113113
{:Image image}
@@ -122,7 +122,7 @@
122122
"/var/run/docker.sock:/var/run/docker.sock"]
123123
(when thread-id [(format "%s:/thread:rw" thread-id)])
124124
mounts)}
125-
:WorkingDir "/project"})
125+
:WorkingDir (or working-dir "/project")})
126126
(when entrypoint {:Entrypoint entrypoint})
127127
(when command {:Cmd command})))]
128128
(curl/post

src/tools.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
git
99
jsonrpc
1010
[selmer.filters :as filters]
11-
[selmer.parser :as selmer]))
11+
[selmer.parser :as selmer]
12+
trace))
1213

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

@@ -64,13 +65,16 @@
6465
(dissoc defaults :functions)
6566
{:command (interpolate-coll
6667
(-> definition :container :command)
67-
arg-context)})]
68+
arg-context)}
69+
(when-let [wd (-> definition :container :working-dir)]
70+
{:working-dir (first (interpolate arg-context wd))}))]
6871
(jsonrpc/notify
6972
:message
7073
{:debug (format "function call %s"
7174
(with-out-str
7275
(pp/pprint (-> function-call
7376
(update :jwt (fn [s] (if s "xxxxxxx" "not-set")))))))})
77+
(trace/container-call (update function-call :jwt (fn [s] (if s "xxxxxxx" "not-set"))))
7478
(let [{:keys [pty-output exit-code done] :as result} (docker/run-container function-call)
7579
exit-code-fail? (if (false? (:check-exit-code definition))
7680
false

0 commit comments

Comments
 (0)