Skip to content

Commit

Permalink
Add clj-kondo
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Jul 24, 2024
1 parent 66ce4ce commit 515bb6f
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 4 deletions.
33 changes: 33 additions & 0 deletions functions/hub/clj-kondo/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
<<EOF
nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
--extra-trusted-substituters "https://cache.iog.io" \
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
--show-trace \
--log-format raw \
build . --out-link /tmp/output/result
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
EOF

FROM scratch

WORKDIR /app

COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/output/ /app/

ENTRYPOINT ["/app/result/bin/entrypoint"]
CMD ["--help"]
61 changes: 61 additions & 0 deletions functions/hub/clj-kondo/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions functions/hub/clj-kondo/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "fasttext";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils, ...}@inputs:

flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};

in rec
{
packages = rec {

# this derivation just contains the init.clj script
scripts = pkgs.stdenv.mkDerivation {
name = "scripts";
src = ./.;
installPhase = ''
cp init.clj $out
'';
};

# the script must have gh in the PATH
default = pkgs.writeShellScriptBin "entrypoint" ''
export PATH=${pkgs.lib.makeBinPath [pkgs.clj-kondo]}
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
${pkgs.babashka}/bin/bb ${scripts} "$@"
'';
};
});
}
28 changes: 28 additions & 0 deletions functions/hub/clj-kondo/init.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns init
(:require
[babashka.fs :as fs]
[babashka.process]
[cheshire.core]))

(try
(let [[json-string & args] *command-line-args*
{llm-args :args} (cheshire.core/parse-string json-string true)]
(let [{:keys [out err] :as p} (-> (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))))
34 changes: 34 additions & 0 deletions functions/hub/clj-kondo/runbook.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions prompts/clj-kondo/020_user_prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lint the clojure code in this project by passing the arguments `--lint .`.
45 changes: 45 additions & 0 deletions prompts/clj-kondo/README.md
Original file line number Diff line number Diff line change
@@ -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
```

47 changes: 47 additions & 0 deletions prompts/curl/README.md
Original file line number Diff line number Diff line change
@@ -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"
```
2 changes: 1 addition & 1 deletion runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions src/docker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})))]
Expand Down
2 changes: 1 addition & 1 deletion src/prompts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 515bb6f

Please sign in to comment.