diff --git a/functions/hub/clj-kondo/Dockerfile b/functions/hub/clj-kondo/Dockerfile new file mode 100644 index 0000000..3da7391 --- /dev/null +++ b/functions/hub/clj-kondo/Dockerfile @@ -0,0 +1,33 @@ + +# syntax = docker/dockerfile:1.4 +FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder + +WORKDIR /tmp/build +RUN mkdir /tmp/nix-store-closure + +# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here +# hadolint ignore=SC2046 +RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \ + --mount=type=cache,target=/root/.cache \ + --mount=type=bind,target=/tmp/build \ + < (apply babashka.process/process + {:out :string :err :string} + "clj-kondo" + (concat llm-args + ["--config" (pr-str + {:output {:format :json}})])) + (deref))] + (let [dir (fs/file "/thread/clj-kondo")] + (fs/create-dirs dir) + (spit (fs/file dir "lint.json") out)) + (println out) + (when (not (= 0 (:exit p))) + (binding [*out* *err*] + (println err) + (System/exit (:exit p)))))) + (catch Throwable t + (binding [*out* *err*] + (println (str t)) + (System/exit 1)))) diff --git a/functions/hub/clj-kondo/runbook.md b/functions/hub/clj-kondo/runbook.md new file mode 100644 index 0000000..c932e6b --- /dev/null +++ b/functions/hub/clj-kondo/runbook.md @@ -0,0 +1,34 @@ +# Background + +The `curl` function has one parameter. + +* `args`: the args to send to the image + +## Usage + +This function should be given a rw bind mount for the root of a project. + +```sh +docker run --rm \ + --mount type=bind,source=/Users/slim/docker/labs-ai-tools-for-devs,target=/project \ + --workdir /project \ + vonwig/clj-kondo:latest '{"args": ["--lint","."]}' | jq . +``` + +## Build + +```sh +docker build -t vonwig/clj-kondo:latest . +``` + +```sh +# docker:command=build + +docker buildx build \ + --builder hydrobuild \ + --platform linux/amd64,linux/arm64 \ + --tag vonwig/clj-kondo:latest \ + --file Dockerfile \ + --push . +docker pull vonwig/clj-kondo:latest +``` diff --git a/prompts/clj-kondo/020_user_prompt.md b/prompts/clj-kondo/020_user_prompt.md new file mode 100644 index 0000000..2daf7ae --- /dev/null +++ b/prompts/clj-kondo/020_user_prompt.md @@ -0,0 +1 @@ +Lint the clojure code in this project by passing the arguments `--lint .`. diff --git a/prompts/clj-kondo/README.md b/prompts/clj-kondo/README.md new file mode 100644 index 0000000..a94f5a5 --- /dev/null +++ b/prompts/clj-kondo/README.md @@ -0,0 +1,45 @@ +--- +extractors: + - name: go-linguist + - name: project-facts +model: gpt-4 +stream: true +functions: + - name: clj-kondo + description: "lint clojure code" + parameters: + type: object + properties: + args: + type: array + description: "the arguments to pass to the linter" + items: + type: string + container: + image: vonwig/clj-kondo:latest +--- + +# Background + +Ask about violations in a project that contains clojure code. + +## Running the tool + +```sh +docker run --rm \ + -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --mount type=volume,source=docker-prompts,target=/prompts \ + --mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \ + --mount type=bind,source=/Users/slim/docker/labs-ai-tools-for-devs/prompts,target=/app/local \ + --workdir /app \ + vonwig/prompts:local run \ + /Users/slim/docker/labs-ai-tools-for-devs \ + jimclark106 \ + "$(uname -o)" \ + local/clj-kondo \ + --pat "$(cat ~/.secrets/dockerhub-pat-ai-tools-for-devs.txt)" \ + --thread-id "clj-kondo" \ + --save-thread-volume +``` + diff --git a/prompts/curl/README.md b/prompts/curl/README.md new file mode 100644 index 0000000..b8519a4 --- /dev/null +++ b/prompts/curl/README.md @@ -0,0 +1,47 @@ +--- +extractors: + - name: go-linguist + - name: docker-lsp +model: gpt-4 +stream: true +functions: + - name: curl + description: "Run a curl command" + parameters: + type: object + properties: + args: + type: string + description: "The arguments to pass to curl" + container: + image: vonwig/curl:latest +--- + +# Background + +* read tl/dr examples +* read man pages + +After ragging the above content, do we know enough about curl to create and run curl examples. + +Also, what about defining outcomes and having the tool verify that we actually ran this correctly and got the expected results? + +At the end, we should report the command line, and the version of curl that we used. + +## Running the tool + +```sh +DIR=$PWD +docker run --rm -it \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --mount type=volume,source=docker-prompts,target=/prompts \ + --mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \ + --mount type=bind,source=/Users/slim/docker/labs-make-runbook/prompts,target=/my-prompts \ + --workdir /my-prompts \ + vonwig/prompts:latest run \ + $DIR \ + $USER \ + "$(uname -o)" \ + project_type + # "github:docker/labs-make-runbook?ref=main&path=prompts/curl" +``` diff --git a/runbook.md b/runbook.md index 4ac92a9..4e994a0 100644 --- a/runbook.md +++ b/runbook.md @@ -46,7 +46,7 @@ bb -m clean-local-images ```sh docker run --rm \ - -it \ + -it \ -v /var/run/docker.sock:/var/run/docker.sock \ --mount type=bind,source=$PWD,target=/app/local \ --workdir /app \ diff --git a/src/docker.clj b/src/docker.clj index 041d8d8..0b85dcf 100644 --- a/src/docker.clj +++ b/src/docker.clj @@ -67,7 +67,7 @@ ;; entrypoint is an array of strings ;; env is a map ;; Env is an array of name=value strings -(defn create-container [{:keys [image entrypoint command host-dir env thread-volume]}] +(defn create-container [{:keys [image entrypoint command host-dir env thread-id]}] (let [payload (json/generate-string (merge {:Image image @@ -79,7 +79,7 @@ {:Binds (concat [(format "%s:/project:rw" host-dir) "docker-lsp:/docker-lsp"] - (when thread-volume (format "%s:/thread" thread-volume)))} + (when thread-id [(format "%s:/thread:rw" thread-id)]))} :WorkingDir "/project"}) (when entrypoint {:Entrypoint entrypoint}) (when command {:Cmd command})))] diff --git a/src/prompts.clj b/src/prompts.clj index 4b1441f..4b3bee7 100644 --- a/src/prompts.clj +++ b/src/prompts.clj @@ -326,7 +326,7 @@ (def output-handler (fn [x] (jsonrpc/notify :message {:content (json/generate-string x)}))) (defn output-prompts [coll] - (jsonrpc/notify {:message {:content "## Prompts:\n"}}) + (jsonrpc/notify :message {:content "## Prompts:\n"}) (->> coll (mapcat (fn [{:keys [role content]}] [(format "## %s\n" role)