Skip to content

Commit 76993fc

Browse files
Start using git container
1 parent 8c9df40 commit 76993fc

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
# our application makes calls to the curl binary
7171
# therefore, wrap the custom-jdk in a script with curl in the PATH
7272
entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
73-
export PATH=${pkgs.lib.makeBinPath [pkgs.curl pkgs.git]}
73+
export PATH=${pkgs.lib.makeBinPath [pkgs.curl]}
7474
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
7575
exec ${custom-jdk}/bin/agent-graph "$@"
7676
'';

graphs/prompts/journals/2024_09_03.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
description: the glob pattern for files that should be found
6767
container:
6868
image: vonwig/findutils:latest
69+
mounts:
70+
- "/Users/slim/.ssh:/root/.ssh"
6971
command:
7072
- find
7173
- .

prompts/examples/git.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!--
12
---
23
tools:
34
- name: append
@@ -34,16 +35,19 @@ tools:
3435
- "{{args|into}}"
3536
host-dir: /Users/slim/repo/bobloblaw
3637
---
38+
-->
3739

3840
# Background
3941

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

4244
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.
4345

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.
46+
1. Update the `host-dir` entry in the above comment to point at a empty directory. The agent is going to clone into this directory so start with an empty directory.
47+
1. Update the two mounts in git tool entry from the comment above. This is how you will provide credential access to the git container (read-only).
48+
2. Update the prompt in the section below to point at a private repo of your choosing.
49+
50+
The next section contains the prompt that will be sent to the agent. This is where the agent instructions begin.
4751

4852
# prompt user
4953

src/git.clj

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
(ns git
22
(:require
33
[babashka.fs :as fs]
4-
[babashka.process :as p]
4+
[clojure.pprint :as pprint]
55
[clojure.string :as string]
66
dir
7+
docker
78
[hasch.core :as hasch]))
89

910
(set! *warn-on-reflection* true)
@@ -55,35 +56,41 @@
5556
(fs/create-dirs default-dir)
5657
default-dir))))
5758

59+
(defn pull [{:keys [dir ref]}]
60+
(docker/run-container
61+
{:image "alpine/git:latest"
62+
:host-dir (str dir)
63+
:command (concat ["pull" "origin"]
64+
(when ref [ref]))}))
65+
66+
(defn clone [{:keys [dir owner repo ref ref-hash]}]
67+
(docker/run-container
68+
{:image "alpine/git:latest"
69+
:host-dir (str dir)
70+
:command (concat ["clone" "--depth" "1" (format "https://github.com/%s/%s" owner repo)]
71+
(when ref ["-b" ref])
72+
[(format "/project/%s" ref-hash)])}))
73+
5874
(defn prompt-file
5975
"returns the path or nil if the github ref does not resolve
6076
throws if the path in the repo does not exist or if the clone fails"
6177
[ref]
62-
(when-let [{:keys [owner repo ref path] :as git-ref-map} (parse-github-ref ref)]
78+
(when-let [{:keys [ref path] :as git-ref-map} (parse-github-ref ref)]
6379
(let [ref-hash (hashch (select-keys git-ref-map [:owner :repo :ref]))
6480
dir (fs/file (prompts-cache) ref-hash)
6581
_ (if (fs/exists? dir)
66-
(-> (apply p/process
67-
{:dir dir}
68-
(concat
69-
["git" "pull" "origin"]
70-
(when ref [ref])))
71-
(deref))
72-
(-> (apply p/process
73-
{:dir (fs/parent dir)}
74-
(concat
75-
["git" "clone" "--depth" "1" (format "https://github.com/%s/%s" owner repo)]
76-
(when ref ["-b" ref])
77-
[ref-hash]))
78-
(deref)
79-
(p/check)))]
82+
(pull {:dir dir :ref ref})
83+
(clone (merge git-ref-map {:dir (fs/parent dir) :ref-hash ref-hash})))]
8084
(if path
8185
(let [cached-path (fs/file dir path)]
8286
(if (fs/exists? cached-path)
8387
cached-path
8488
(throw (ex-info "repo exists but path does not" {:ref ref}))))
8589
dir))))
8690

91+
(comment
92+
(prompt-file "github:docker/labs-make-runbook?path=prompts/docker/prompt.md"))
93+
8794
(comment
8895
(fs/create-dir (prompts-cache))
8996
(def x "github:docker/labs-make-runbook?ref=main&path=prompts/docker")

0 commit comments

Comments
 (0)