Skip to content

Commit 70b60c2

Browse files
Update sequentialthinking
1 parent 9a1c52d commit 70b60c2

File tree

7 files changed

+205
-3
lines changed

7 files changed

+205
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# syntax = docker/dockerfile:1.4
3+
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder
4+
5+
WORKDIR /tmp/build
6+
RUN mkdir /tmp/nix-store-closure
7+
8+
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
9+
# hadolint ignore=SC2046
10+
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
11+
--mount=type=cache,target=/root/.cache \
12+
--mount=type=bind,target=/tmp/build \
13+
<<EOF
14+
nix \
15+
--extra-experimental-features "nix-command flakes" \
16+
--option filter-syscalls false \
17+
--extra-trusted-substituters "https://cache.iog.io" \
18+
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
19+
--show-trace \
20+
--log-format raw \
21+
build . --out-link /tmp/output/result
22+
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
23+
EOF
24+
25+
FROM babashka/babashka:latest@sha256:9e0381fc4c78ee6ff12fd8836352cf343afba289aceb77e36129d92f30a92cc7
26+
27+
WORKDIR /app
28+
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/output/ /app/
31+
32+
ENTRYPOINT ["/app/result/bin/entrypoint"]
33+
CMD ["--help"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:paths ["."]}

functions/sequentialthinking/flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
description = "{{tool}}";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils, ...}@inputs:
10+
11+
flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = import nixpkgs {
15+
inherit system;
16+
};
17+
18+
in rec
19+
{
20+
packages = rec {
21+
22+
# this derivation just contains the init.clj script
23+
scripts = pkgs.stdenv.mkDerivation {
24+
name = "scripts";
25+
src = ./.;
26+
installPhase = ''
27+
mkdir $out
28+
cp *.clj $out
29+
cp bb.edn $out
30+
'';
31+
};
32+
33+
run-entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
34+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
35+
cd ${scripts}
36+
/usr/local/bin/bb init.clj "$@"
37+
'';
38+
39+
default = pkgs.buildEnv {
40+
name = "bb";
41+
paths = [ run-entrypoint ];
42+
};
43+
};
44+
});
45+
}
46+

functions/sequentialthinking/init.clj

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
(ns init
1+
(ns init
22
(:require
3+
[cheshire.core :as json]
34
[clojure.spec.alpha :as s]))
45

56
;; validate initial thought
@@ -12,4 +13,42 @@
1213
(s/def ::thoughtNumber number?)
1314
(s/def ::totalThoughts number?)
1415
(s/def ::nextThoughtNeeded boolean?)
15-
(s/def ::thought-data (s/keys :req-un [::thought ::thoughtNumber ::totalThoughts ::nextThoughtNeeded]))
16+
17+
(s/def ::isRevision boolean?)
18+
(s/def ::revisesThought number?)
19+
(s/def ::branchFromThought number?)
20+
(s/def ::branchId string?)
21+
(s/def ::needsMoreThoughts boolean?)
22+
(s/def ::thought-data (s/keys :req-un [::thought ::thoughtNumber ::totalThoughts ::nextThoughtNeeded]
23+
:opt-un [::isRevision ::revisesThought ::branchFromThought ::branchId ::needsMoreThoughts]))
24+
25+
(defn process-thought
26+
[m]
27+
(if (not (s/valid? ::thought-data m))
28+
(throw (ex-info "Invalid thought data" (s/explain-data ::thought-data m)))
29+
(let [thought-history (json/parse-string (slurp "thought-history.json") keyword)
30+
branches (json/parse-string (slurp "branches.json") keyword)]
31+
(spit "/sequentialthinking/thought-history.json"
32+
(json/generate-string
33+
(conj thought-history (cond-> m
34+
(> (:thoughtNumber m) (:totalThoughts m)) (assoc :totalThoughts (:thoughtNumber m))))))
35+
(when (= (:branchFromThought m) (:branchId m))
36+
(spit "/sequentialthinking/branches.json"
37+
(json/generate-string
38+
(update branches (:branchId m) (fnil conj []) m))))
39+
(-> m
40+
(select-keys [:thoughtNumber :totalThoughts :nextThoughtNeeded])
41+
(assoc :branches (keys branches))
42+
(assoc :thoughtHistoryLength (count thought-history))))))
43+
44+
(defn -main [& args]
45+
(try
46+
(-> (json/parse-string (first args))
47+
(process-thought)
48+
(json/generate-string)
49+
(println))
50+
(catch Throwable t
51+
(println (.getMessage t))
52+
(System/exit 1))))
53+
54+
(apply -main *command-line-args*)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
```sh
3+
docker build -t vonwig/sequential-thinking:latest .
4+
```
5+
6+
```sh
7+
docker run -it --rm \
8+
-v mcp-sequentialthinking:/sequentialthinking \
9+
vonwig/sequential-thinking:latest \
10+
'{"entities": [{"name": "me"}]}'
11+
```
12+
13+
```sh
14+
docker buildx build \
15+
--builder hydrobuild \
16+
--platform linux/amd64,linux/arm64 \
17+
--tag vonwig/sequentialthinking:latest \
18+
--file Dockerfile \
19+
--push .
20+
docker pull vonwig/sequentialthinking:latest
21+
```
22+

prompts/examples/sequentialthinking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ tools:
9797
- thoughtNumber
9898
- totalThoughts
9999
container:
100-
image: vonwig/sequential-thinking:latest
100+
image: vonwig/sequentialthinking:latest
101101
volumes:
102102
- "mcp-sequentialthinking:/sequentialthinking"
103103
---

0 commit comments

Comments
 (0)