Skip to content

Commit 865001b

Browse files
Add lorax and background processes
1 parent a8f633c commit 865001b

File tree

7 files changed

+66
-41
lines changed

7 files changed

+66
-41
lines changed

prompts/catalog.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,9 @@ registry:
220220
name: qrencode
221221
prompts: 1
222222
resources: {}
223+
speculative_execution:
224+
description: >
225+
Use lorax from Claude. Lorax is a speculative execution tool that can be used
226+
to make edits and run tools in an isolated sandbox.
227+
ref: github:docker/labs-ai-tools-for-devs?path=prompts/lorax/speculative.md
228+
icon: https://vonwig.github.io/prompts.docs/img/speculative_hu15687469033092380316.webp

prompts/lorax/speculative.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
defs:
3+
- lorax: &lorax
4+
image: lorax:latest
5+
entrypoint: lorax
26
model: claude-3-5-sonnet-20241022
37
tools:
48
- name: sandbox-source
@@ -8,34 +12,29 @@ tools:
812
properties:
913
host-dir:
1014
type: string
11-
user-source:
15+
name:
1216
type: string
13-
container:
14-
image: vonwig/speculative:latest
15-
mounts:
16-
- "{{host-dir|safe}}:/repo"
17-
commands:
17+
container:
18+
<<: [*lorax]
19+
command:
1820
- sandbox
1921
- source
2022
- "-n"
21-
- "{{user-source}}"
22-
- /repo
23+
- "{{name}}"
24+
- "{{host-dir}}"
25+
background: true
2326
- name: sandbox-clone
24-
description: create a sandbox for a host repo and respond with the id of the new sandbox
27+
description: create a sandbox and respond with the id of the new sandbox
2528
parameters:
2629
type: object
2730
properties:
2831
sandbox-name:
2932
type: string
30-
user-source:
31-
type: string
3233
container:
33-
image: vonwig/speculative:latest
34-
commands:
34+
<<: [*lorax]
35+
command:
3536
- sandbox
3637
- clone
37-
- "{{user-source}}"
38-
- "--name"
3938
- "{{sandbox-name}}"
4039
- name: sandbox-snapshot
4140
description: snapshot the current state of a sandbox
@@ -45,8 +44,8 @@ tools:
4544
sandbox-id:
4645
type: string
4746
container:
48-
image: vonwig/speculative:latest
49-
commands:
47+
<<: [*lorax]
48+
command:
5049
- sandbox
5150
- snapshot
5251
- "{{sandbox-id}}"
@@ -60,8 +59,8 @@ tools:
6059
tree-id:
6160
type: string
6261
container:
63-
image: vonwig/speculative:latest
64-
commands:
62+
<<: [*lorax]
63+
command:
6564
- sandbox
6665
- restore
6766
- "{{sandbox-id}}"
@@ -76,8 +75,8 @@ tools:
7675
image:
7776
type: string
7877
container:
79-
image: vonwig/speculative:latest
80-
commands:
78+
<<: [*lorax]
79+
command:
8180
- sandbox
8281
- exec
8382
- --mount-image
@@ -93,8 +92,8 @@ tools:
9392
path:
9493
type: string
9594
container:
96-
image: vonwig/speculative:latest
97-
commands:
95+
<<: [*lorax]
96+
command:
9897
- sandbox
9998
- delete
10099
- "{{sandbox-id}}"
@@ -109,8 +108,8 @@ tools:
109108
path:
110109
type: string
111110
container:
112-
image: vonwig/speculative:latest
113-
commands:
111+
<<: [*lorax]
112+
command:
114113
- sandbox
115114
- rm
116115
- "{{sandbox-id}}"
@@ -124,8 +123,8 @@ tools:
124123
tree-id:
125124
type: string
126125
container:
127-
image: vonwig/speculative:latest
128-
commands:
126+
<<: [*lorax]
127+
command:
129128
- sandbox
130129
- diff
131130
- "{{sandbox-id}}"
@@ -138,15 +137,18 @@ tools:
138137
diff:
139138
type: string
140139
container:
141-
image: vonwig/speculative:latest
142-
commands:
140+
<<: [*lorax]
141+
command:
143142
- sandbox
144143
- apply
145144
- user-source
146145
- "{{diff}}"
147146
---
148147

148+
# xprompt
149+
150+
Make a cloned repo available to the sandbox. The host repo is '/Users/slim/vonwig/altaservice' and it should be named atlas
151+
149152
# prompt
150153

151-
* create a sandbox for the host repo at '/Users/slim/vonwig/altaservice' and name it atlas
152-
* execute
154+
Clone the sandbox named atlas. We will get back the id of the new sandbox and we should remember that.

src/docker.clj

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
[clojure.string :as string]
99
[creds]
1010
jsonrpc
11+
[jsonrpc.logger :as logger]
1112
logging
1213
schema)
1314
(:import
14-
[java.net UnixDomainSocketAddress]
15+
[java.net URLEncoder UnixDomainSocketAddress]
1516
[java.nio ByteBuffer]
1617
[java.nio.channels SocketChannel]
1718
[java.util Arrays Base64]))
@@ -109,7 +110,6 @@
109110
{:StdinOnce true
110111
:OpenStdin true}
111112
(defn create-container [{:keys [image entrypoint workdir command host-dir env thread-id opts mounts volumes] :or {opts {:Tty true}}}]
112-
#_(jsonrpc/notify :message {:content (str m)})
113113
(let [payload (json/generate-string
114114
(merge
115115
{:Image image}
@@ -126,14 +126,15 @@
126126
(or volumes mounts))}
127127
:WorkingDir (or workdir "/project")}
128128
(when entrypoint {:Entrypoint entrypoint})
129-
(when command {:Cmd command})))]
129+
(when command {:Cmd command})))
130+
ascii-payload (String. (.getBytes payload "ASCII")) ]
130131
(curl/post
131132
"http://localhost/containers/create"
132133
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
133134
:throw false
134-
:body payload
135+
:body ascii-payload
135136
:headers {"Content-Type" "application/json"
136-
"Content-Length" (count payload)}})))
137+
"Content-Length" (count ascii-payload)}})))
137138

138139
(defn create-volume [{:keys [Name]}]
139140
(curl/post "http://localhost/volumes/create"
@@ -308,6 +309,16 @@
308309
:AttachStdin false}}
309310
println)))
310311

312+
(defn run-background-function
313+
"run container function with no stdin, and no streaming output"
314+
[m]
315+
(when (not (has-image? (:image m)))
316+
(-pull m))
317+
(let [x (create m)]
318+
(start x)
319+
;; TODO schedule shutdown hook
320+
{:done :running}))
321+
311322
(defn run-function
312323
"run container function with no stdin, and no streaming output"
313324
[{:keys [timeout] :or {timeout 600000} :as m}]
@@ -439,8 +450,12 @@
439450
returns ::container-response"
440451
[m]
441452
;; (schema/validate :schema/container-definition)
442-
(if (-> m :stdin :file)
453+
(cond
454+
(-> m :stdin :file)
443455
(run-with-stdin-content m)
456+
(true? (:background m))
457+
(run-background-function m)
458+
:else
444459
(run-function m)))
445460

446461
(defn get-login-info-from-desktop-backend

src/graph.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
(let [[chunk-handler sample] (providers (llm-provider (or (:model metadata) model)))
4949
[c h] (chunk-handler)
5050
request (merge
51-
(dissoc metadata :agent :host-dir :workdir :prompt-format :description :name :parameter-values :arguments :resources) ; TODO should we just select relevant keys instead of removing bad ones
51+
(dissoc metadata :agent :host-dir :workdir :prompt-format :description :name :parameter-values :arguments :resources :defs) ; TODO should we just select relevant keys instead of removing bad ones
5252
{:messages messages
5353
:level level}
5454
(when (seq functions) {:tools functions})

src/jsonrpc/server.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
(mapcat
110110
(fn [[k v]] (map (partial entry->prompt-listing k v) (:messages v))))
111111
(into []))}]
112-
(logger/info prompts)
113112
prompts))
114113

115114
(defmethod lsp.server/receive-request "prompts/get" [_ {:keys [db*]} {:keys [name arguments]}]
@@ -125,7 +124,6 @@
125124
(vals)
126125
(map #(select-keys % [:uri :name :description :mimeType])))
127126
[])}]
128-
(logger/info resources)
129127
resources))
130128

131129
(defmethod lsp.server/receive-request "resources/read" [_ {:keys [db*]} params]
@@ -329,6 +327,7 @@
329327
(->> params (lsp.server/send-notification server "notifications/prompts/list_changed")))
330328

331329
(publish-resource-list-changed [_ params]
330+
(logger/info "send resource list changed")
332331
(->> params (lsp.server/send-notification server "notifications/resources/list_changed")))
333332

334333
(publish-resource-updated [_ params]
@@ -338,6 +337,7 @@
338337
(logger/info "send tool list changed")
339338
(->> params (lsp.server/send-notification server "notifications/tools/list_changed")))
340339
(publish-docker-notify [_ method params]
340+
(logger/info (format "%s - %s" method params))
341341
(lsp.server/send-notification server method params)))
342342

343343
(def registry "/prompts/registry.yaml")

src/schema.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
(s/def ::pty-output string?)
4747
(s/def ::exit-code integer?)
4848
(s/def ::info any?)
49-
(s/def ::done #{:timeout :exited})
49+
(s/def ::done #{:timeout :exited :running})
5050
(s/def ::timeout integer?)
5151
(s/def ::kill-container any?)
5252
(s/def ::container-response (s/keys :req-un [::pty-output ::exit-code ::info ::done]

src/tools.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
(resolve pty-output)
9999
(and (= :exited done) (not exit-code-fail?))
100100
(resolve "success")
101+
(= :running done)
102+
(resolve "success")
101103
(and (= :exited done) exit-code-fail?)
102104
(fail (format "call exited with non-zero code (%d): %s" exit-code pty-output))
103105
(= :timeout done)

0 commit comments

Comments
 (0)