deepclause-sdk 0.0.89 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/README.md +481 -941
  2. package/dist/agent.d.ts +19 -2
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +75 -21
  5. package/dist/agent.js.map +1 -1
  6. package/dist/cli/config.d.ts +385 -178
  7. package/dist/cli/config.d.ts.map +1 -1
  8. package/dist/cli/config.js +161 -188
  9. package/dist/cli/config.js.map +1 -1
  10. package/dist/cli/index.d.ts +3 -2
  11. package/dist/cli/index.d.ts.map +1 -1
  12. package/dist/cli/index.js +85 -411
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/cli/login.d.ts +29 -0
  15. package/dist/cli/login.d.ts.map +1 -0
  16. package/dist/cli/login.js +184 -0
  17. package/dist/cli/login.js.map +1 -0
  18. package/dist/cli/readline.d.ts +6 -0
  19. package/dist/cli/readline.d.ts.map +1 -0
  20. package/dist/cli/readline.js +15 -0
  21. package/dist/cli/readline.js.map +1 -0
  22. package/dist/cli/repl-bin.d.ts +9 -0
  23. package/dist/cli/repl-bin.d.ts.map +1 -0
  24. package/dist/cli/repl-bin.js +16 -0
  25. package/dist/cli/repl-bin.js.map +1 -0
  26. package/dist/cli/repl.d.ts +216 -0
  27. package/dist/cli/repl.d.ts.map +1 -0
  28. package/dist/cli/repl.js +1392 -0
  29. package/dist/cli/repl.js.map +1 -0
  30. package/dist/cli/run.d.ts +17 -18
  31. package/dist/cli/run.d.ts.map +1 -1
  32. package/dist/cli/run.js +202 -183
  33. package/dist/cli/run.js.map +1 -1
  34. package/dist/cli/set-backend.d.ts +53 -0
  35. package/dist/cli/set-backend.d.ts.map +1 -0
  36. package/dist/cli/set-backend.js +259 -0
  37. package/dist/cli/set-backend.js.map +1 -0
  38. package/dist/cli/visualize.d.ts +42 -0
  39. package/dist/cli/visualize.d.ts.map +1 -0
  40. package/dist/cli/visualize.js +150 -0
  41. package/dist/cli/visualize.js.map +1 -0
  42. package/dist/compiler.d.ts +5 -52
  43. package/dist/compiler.d.ts.map +1 -1
  44. package/dist/compiler.js +4 -768
  45. package/dist/compiler.js.map +1 -1
  46. package/dist/index.d.ts +27 -2
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +18 -2
  49. package/dist/index.js.map +1 -1
  50. package/dist/prolog/bridge.d.ts +5 -1
  51. package/dist/prolog/bridge.d.ts.map +1 -1
  52. package/dist/prolog/bridge.js +10 -1
  53. package/dist/prolog/bridge.js.map +1 -1
  54. package/dist/prolog-src/deepclause_analysis.pl +10 -2
  55. package/dist/prolog-src/deepclause_mi.pl +2440 -49
  56. package/dist/repl/agent.d.ts +90 -0
  57. package/dist/repl/agent.d.ts.map +1 -0
  58. package/dist/repl/agent.js +410 -0
  59. package/dist/repl/agent.js.map +1 -0
  60. package/dist/repl/auth.d.ts +45 -0
  61. package/dist/repl/auth.d.ts.map +1 -0
  62. package/dist/repl/auth.js +116 -0
  63. package/dist/repl/auth.js.map +1 -0
  64. package/dist/repl/backend.d.ts +321 -0
  65. package/dist/repl/backend.d.ts.map +1 -0
  66. package/dist/repl/backend.js +415 -0
  67. package/dist/repl/backend.js.map +1 -0
  68. package/dist/repl/compaction.d.ts +122 -0
  69. package/dist/repl/compaction.d.ts.map +1 -0
  70. package/dist/repl/compaction.js +318 -0
  71. package/dist/repl/compaction.js.map +1 -0
  72. package/dist/repl/export.d.ts +30 -0
  73. package/dist/repl/export.d.ts.map +1 -0
  74. package/dist/repl/export.js +23 -0
  75. package/dist/repl/export.js.map +1 -0
  76. package/dist/repl/frames.d.ts +21 -0
  77. package/dist/repl/frames.d.ts.map +1 -0
  78. package/dist/repl/frames.js +79 -0
  79. package/dist/repl/frames.js.map +1 -0
  80. package/dist/repl/harness-tools.d.ts +99 -0
  81. package/dist/repl/harness-tools.d.ts.map +1 -0
  82. package/dist/repl/harness-tools.js +192 -0
  83. package/dist/repl/harness-tools.js.map +1 -0
  84. package/dist/repl/highlight.d.ts +30 -0
  85. package/dist/repl/highlight.d.ts.map +1 -0
  86. package/dist/repl/highlight.js +285 -0
  87. package/dist/repl/highlight.js.map +1 -0
  88. package/dist/repl/history.d.ts +234 -0
  89. package/dist/repl/history.d.ts.map +1 -0
  90. package/dist/repl/history.js +661 -0
  91. package/dist/repl/history.js.map +1 -0
  92. package/dist/repl/imagegen.d.ts +29 -0
  93. package/dist/repl/imagegen.d.ts.map +1 -0
  94. package/dist/repl/imagegen.js +84 -0
  95. package/dist/repl/imagegen.js.map +1 -0
  96. package/dist/repl/index.d.ts +130 -0
  97. package/dist/repl/index.d.ts.map +1 -0
  98. package/dist/repl/index.js +112 -0
  99. package/dist/repl/index.js.map +1 -0
  100. package/dist/repl/judge.d.ts +51 -0
  101. package/dist/repl/judge.d.ts.map +1 -0
  102. package/dist/repl/judge.js +58 -0
  103. package/dist/repl/judge.js.map +1 -0
  104. package/dist/repl/markdown.d.ts +25 -0
  105. package/dist/repl/markdown.d.ts.map +1 -0
  106. package/dist/repl/markdown.js +103 -0
  107. package/dist/repl/markdown.js.map +1 -0
  108. package/dist/repl/model-resolver.d.ts +59 -0
  109. package/dist/repl/model-resolver.d.ts.map +1 -0
  110. package/dist/repl/model-resolver.js +156 -0
  111. package/dist/repl/model-resolver.js.map +1 -0
  112. package/dist/repl/picker.d.ts +34 -0
  113. package/dist/repl/picker.d.ts.map +1 -0
  114. package/dist/repl/picker.js +81 -0
  115. package/dist/repl/picker.js.map +1 -0
  116. package/dist/repl/project-context.d.ts +16 -0
  117. package/dist/repl/project-context.d.ts.map +1 -0
  118. package/dist/repl/project-context.js +23 -0
  119. package/dist/repl/project-context.js.map +1 -0
  120. package/dist/repl/render.d.ts +187 -0
  121. package/dist/repl/render.d.ts.map +1 -0
  122. package/dist/repl/render.js +808 -0
  123. package/dist/repl/render.js.map +1 -0
  124. package/dist/repl/session.d.ts +424 -0
  125. package/dist/repl/session.d.ts.map +1 -0
  126. package/dist/repl/session.js +1473 -0
  127. package/dist/repl/session.js.map +1 -0
  128. package/dist/repl/status.d.ts +100 -0
  129. package/dist/repl/status.d.ts.map +1 -0
  130. package/dist/repl/status.js +218 -0
  131. package/dist/repl/status.js.map +1 -0
  132. package/dist/repl/tools.d.ts +53 -0
  133. package/dist/repl/tools.d.ts.map +1 -0
  134. package/dist/repl/tools.js +307 -0
  135. package/dist/repl/tools.js.map +1 -0
  136. package/dist/repl/toolset.d.ts +32 -0
  137. package/dist/repl/toolset.d.ts.map +1 -0
  138. package/dist/repl/toolset.js +82 -0
  139. package/dist/repl/toolset.js.map +1 -0
  140. package/dist/repl/tui/editor.d.ts +17 -0
  141. package/dist/repl/tui/editor.d.ts.map +1 -0
  142. package/dist/repl/tui/editor.js +39 -0
  143. package/dist/repl/tui/editor.js.map +1 -0
  144. package/dist/repl/tui/status-bar.d.ts +26 -0
  145. package/dist/repl/tui/status-bar.d.ts.map +1 -0
  146. package/dist/repl/tui/status-bar.js +47 -0
  147. package/dist/repl/tui/status-bar.js.map +1 -0
  148. package/dist/repl/tui/theme.d.ts +30 -0
  149. package/dist/repl/tui/theme.d.ts.map +1 -0
  150. package/dist/repl/tui/theme.js +81 -0
  151. package/dist/repl/tui/theme.js.map +1 -0
  152. package/dist/repl/tui/transcript.d.ts +41 -0
  153. package/dist/repl/tui/transcript.d.ts.map +1 -0
  154. package/dist/repl/tui/transcript.js +139 -0
  155. package/dist/repl/tui/transcript.js.map +1 -0
  156. package/dist/runner.d.ts +143 -13
  157. package/dist/runner.d.ts.map +1 -1
  158. package/dist/runner.js +532 -290
  159. package/dist/runner.js.map +1 -1
  160. package/dist/sdk.d.ts.map +1 -1
  161. package/dist/sdk.js +0 -32
  162. package/dist/sdk.js.map +1 -1
  163. package/dist/system/assets/docs/AGENT_PROMPT.md +1447 -0
  164. package/dist/system/assets/docs/DML_AUTHORING.md +195 -0
  165. package/dist/system/assets/docs/DML_REFERENCE.md +344 -72
  166. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +172 -0
  167. package/dist/system/assets/docs/HARNESS_PATTERNS.md +562 -0
  168. package/dist/system/assets/docs/META_PROMPT.md +68 -0
  169. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +117 -0
  170. package/dist/system/assets/index.d.ts +9 -17
  171. package/dist/system/assets/index.d.ts.map +1 -1
  172. package/dist/system/assets/index.js +26 -85
  173. package/dist/system/assets/index.js.map +1 -1
  174. package/dist/system/runtime/agentvm-manager.d.ts +9 -2
  175. package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
  176. package/dist/system/runtime/agentvm-manager.js +70 -44
  177. package/dist/system/runtime/agentvm-manager.js.map +1 -1
  178. package/dist/system/runtime/media.d.ts +23 -0
  179. package/dist/system/runtime/media.d.ts.map +1 -0
  180. package/dist/system/runtime/media.js +55 -0
  181. package/dist/system/runtime/media.js.map +1 -0
  182. package/dist/system/runtime/shell-limits.d.ts +21 -0
  183. package/dist/system/runtime/shell-limits.d.ts.map +1 -0
  184. package/dist/system/runtime/shell-limits.js +39 -0
  185. package/dist/system/runtime/shell-limits.js.map +1 -0
  186. package/dist/system/runtime/shell-manager.d.ts +8 -3
  187. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  188. package/dist/system/runtime/shell-manager.js +56 -39
  189. package/dist/system/runtime/shell-manager.js.map +1 -1
  190. package/dist/system/runtime/shell-tool-events.js +5 -0
  191. package/dist/system/runtime/shell-tool-events.js.map +1 -1
  192. package/dist/system/runtime/token-usage.d.ts +2 -0
  193. package/dist/system/runtime/token-usage.d.ts.map +1 -1
  194. package/dist/system/runtime/token-usage.js +7 -0
  195. package/dist/system/runtime/token-usage.js.map +1 -1
  196. package/dist/tools.d.ts +3 -21
  197. package/dist/tools.d.ts.map +1 -1
  198. package/dist/tools.js +14 -168
  199. package/dist/tools.js.map +1 -1
  200. package/dist/types.d.ts +136 -119
  201. package/dist/types.d.ts.map +1 -1
  202. package/dist/validate.d.ts +19 -0
  203. package/dist/validate.d.ts.map +1 -0
  204. package/dist/validate.js +338 -0
  205. package/dist/validate.js.map +1 -0
  206. package/dist/visualize/ascii.d.ts +55 -0
  207. package/dist/visualize/ascii.d.ts.map +1 -0
  208. package/dist/visualize/ascii.js +242 -0
  209. package/dist/visualize/ascii.js.map +1 -0
  210. package/dist/visualize/display.d.ts +24 -0
  211. package/dist/visualize/display.d.ts.map +1 -0
  212. package/dist/visualize/display.js +29 -0
  213. package/dist/visualize/display.js.map +1 -0
  214. package/dist/visualize/graphics.d.ts +35 -0
  215. package/dist/visualize/graphics.d.ts.map +1 -0
  216. package/dist/visualize/graphics.js +96 -0
  217. package/dist/visualize/graphics.js.map +1 -0
  218. package/dist/visualize/image.d.ts +38 -0
  219. package/dist/visualize/image.d.ts.map +1 -0
  220. package/dist/visualize/image.js +95 -0
  221. package/dist/visualize/image.js.map +1 -0
  222. package/dist/visualize/index.d.ts +59 -0
  223. package/dist/visualize/index.d.ts.map +1 -0
  224. package/dist/visualize/index.js +198 -0
  225. package/dist/visualize/index.js.map +1 -0
  226. package/dist/visualize/raster.d.ts +23 -0
  227. package/dist/visualize/raster.d.ts.map +1 -0
  228. package/dist/visualize/raster.js +47 -0
  229. package/dist/visualize/raster.js.map +1 -0
  230. package/dist/visualize/svg.d.ts +39 -0
  231. package/dist/visualize/svg.d.ts.map +1 -0
  232. package/dist/visualize/svg.js +148 -0
  233. package/dist/visualize/svg.js.map +1 -0
  234. package/dist/visualize/transcode.d.ts +13 -0
  235. package/dist/visualize/transcode.d.ts.map +1 -0
  236. package/dist/visualize/transcode.js +40 -0
  237. package/dist/visualize/transcode.js.map +1 -0
  238. package/docs/images/repl.png +0 -0
  239. package/package.json +19 -15
  240. package/src/prolog-src/deepclause_analysis.pl +10 -2
  241. package/src/prolog-src/deepclause_mi.pl +2440 -49
  242. package/dist/cli/commands.d.ts +0 -42
  243. package/dist/cli/commands.d.ts.map +0 -1
  244. package/dist/cli/commands.js +0 -246
  245. package/dist/cli/commands.js.map +0 -1
  246. package/dist/cli/compile.d.ts +0 -99
  247. package/dist/cli/compile.d.ts.map +0 -1
  248. package/dist/cli/compile.js +0 -363
  249. package/dist/cli/compile.js.map +0 -1
  250. package/dist/cli/default-skills.d.ts +0 -10
  251. package/dist/cli/default-skills.d.ts.map +0 -1
  252. package/dist/cli/default-skills.js +0 -206
  253. package/dist/cli/default-skills.js.map +0 -1
  254. package/dist/cli/interactive.d.ts +0 -2
  255. package/dist/cli/interactive.d.ts.map +0 -1
  256. package/dist/cli/interactive.js +0 -20
  257. package/dist/cli/interactive.js.map +0 -1
  258. package/dist/cli/mcp.d.ts +0 -56
  259. package/dist/cli/mcp.d.ts.map +0 -1
  260. package/dist/cli/mcp.js +0 -138
  261. package/dist/cli/mcp.js.map +0 -1
  262. package/dist/cli/prompt.d.ts +0 -2
  263. package/dist/cli/prompt.d.ts.map +0 -1
  264. package/dist/cli/prompt.js +0 -2
  265. package/dist/cli/prompt.js.map +0 -1
  266. package/dist/cli/search.d.ts +0 -19
  267. package/dist/cli/search.d.ts.map +0 -1
  268. package/dist/cli/search.js +0 -189
  269. package/dist/cli/search.js.map +0 -1
  270. package/dist/cli/tool-args.d.ts +0 -2
  271. package/dist/cli/tool-args.d.ts.map +0 -1
  272. package/dist/cli/tool-args.js +0 -39
  273. package/dist/cli/tool-args.js.map +0 -1
  274. package/dist/cli/tools.d.ts +0 -36
  275. package/dist/cli/tools.d.ts.map +0 -1
  276. package/dist/cli/tools.js +0 -229
  277. package/dist/cli/tools.js.map +0 -1
  278. package/dist/cli/tui/index.d.ts +0 -22
  279. package/dist/cli/tui/index.d.ts.map +0 -1
  280. package/dist/cli/tui/index.js +0 -29
  281. package/dist/cli/tui/index.js.map +0 -1
  282. package/dist/cli/tui.d.ts +0 -167
  283. package/dist/cli/tui.d.ts.map +0 -1
  284. package/dist/cli/tui.js +0 -5228
  285. package/dist/cli/tui.js.map +0 -1
  286. package/dist/compiler_prompt.d.ts +0 -20
  287. package/dist/compiler_prompt.d.ts.map +0 -1
  288. package/dist/compiler_prompt.js +0 -870
  289. package/dist/compiler_prompt.js.map +0 -1
  290. package/dist/deepclause-cli.skill +0 -0
  291. package/dist/prolog-src/deepclause_mi.pl.bak +0 -570
  292. package/dist/system/assets/docs/CONDUCTOR_PROMPT.md +0 -105
  293. package/dist/system/assets/docs/DML_COMPILER_PROMPT.md +0 -700
  294. package/dist/system/assets/docs/TUI.md +0 -150
  295. package/dist/system/assets/recipes/deepclause-coding-workflow/SKILL.md +0 -100
  296. package/dist/system/assets/skills/conductor.dml +0 -76
  297. package/dist/system/assets/skills/deep-planner.dml +0 -412
  298. package/dist/system/assets/skills/plan.dml +0 -429
  299. package/dist/system/assets/skills/security-planner.dml +0 -337
  300. package/dist/system/assets/skills/skill-creator.dml +0 -187
  301. package/dist/system/runtime/catalog-recipes.d.ts +0 -24
  302. package/dist/system/runtime/catalog-recipes.d.ts.map +0 -1
  303. package/dist/system/runtime/catalog-recipes.js +0 -273
  304. package/dist/system/runtime/catalog-recipes.js.map +0 -1
  305. package/dist/system/runtime/catalog-skills.d.ts +0 -50
  306. package/dist/system/runtime/catalog-skills.d.ts.map +0 -1
  307. package/dist/system/runtime/catalog-skills.js +0 -152
  308. package/dist/system/runtime/catalog-skills.js.map +0 -1
  309. package/dist/system/runtime/conductor.d.ts +0 -105
  310. package/dist/system/runtime/conductor.d.ts.map +0 -1
  311. package/dist/system/runtime/conductor.js +0 -732
  312. package/dist/system/runtime/conductor.js.map +0 -1
  313. package/dist/system/runtime/console-capture.d.ts +0 -9
  314. package/dist/system/runtime/console-capture.d.ts.map +0 -1
  315. package/dist/system/runtime/console-capture.js +0 -67
  316. package/dist/system/runtime/console-capture.js.map +0 -1
  317. package/dist/system/runtime/dml-executor.d.ts +0 -52
  318. package/dist/system/runtime/dml-executor.d.ts.map +0 -1
  319. package/dist/system/runtime/dml-executor.js +0 -203
  320. package/dist/system/runtime/dml-executor.js.map +0 -1
  321. package/dist/system/runtime/runtime-tools.d.ts +0 -31
  322. package/dist/system/runtime/runtime-tools.d.ts.map +0 -1
  323. package/dist/system/runtime/runtime-tools.js +0 -312
  324. package/dist/system/runtime/runtime-tools.js.map +0 -1
  325. package/dist/system/runtime/skill-creator.d.ts +0 -38
  326. package/dist/system/runtime/skill-creator.d.ts.map +0 -1
  327. package/dist/system/runtime/skill-creator.js +0 -763
  328. package/dist/system/runtime/skill-creator.js.map +0 -1
  329. package/src/prolog-src/deepclause_mi.pl.bak +0 -570
package/README.md CHANGED
@@ -1,1097 +1,637 @@
1
- # DeepClause TUI Agent, CLI and SDK
1
+ # DeepClause SDK
2
+
3
+ **Effortlessly build efficient model-, task-, or domain-specific harnesses.**
4
+
5
+ Follow us on [X (@hilbertshelper)](https://x.com/hilbertshelper) · Blog: [deepclause.substack.com](https://deepclause.substack.com)
6
+
7
+ DeepClause is a **Prolog-based runtime for self-modifying agent harnesses**. A
8
+ harness created with DeepClause is a self contained library in the form of a **DML** module. DML (DeepClause Meta Language) is a Prolog DSL with added functionality for LLM model calls, semantic
9
+ judgments (Jev-type models), and constraints. An LLM agent embedded in the runtime reads, extends, and tests code in a live module a turn by
10
+ turn. You drive it from an interactive **REPL**. Using the REPL once can successively build a custom harness that is optimized for a specific use case.
11
+
12
+ DML runs on **SWI-Prolog compiled to WebAssembly** — the whole language runtime
13
+ is in-process and portable, with no native Prolog to install.
14
+
15
+ Most agent stacks contain a lot of separate moving parts: tools in one place,
16
+ prompts in another, memory in a third, and the workflow as a graph or a chain
17
+ somewhere else. DML folds them into one idea — a **predicate**. A skill is a
18
+ clause, a tool is a clause, memory and state are clauses, control flow and
19
+ retries are clause order and backtracking, and a workflow is simply predicates
20
+ calling predicates. Because it is one language in one self-contained file, the
21
+ parts can read, reuse, and extend one another, and a whole harness can be
22
+ inspected, versioned, and moved as a unit.
23
+
24
+ That shape pays off most when a capability is *specific*. Because a harness is a
25
+ single module you can edit, diff, and version — and because the REPL lets an
26
+ authoring agent grow it by talking — it is unusually cheap to build one tuned to
27
+ a particular **model** (its prompt style, context budget, reasoning level), a
28
+ particular **task**, or a particular **domain**. The same file can also route
29
+ individual calls across several models with `with_model/2`: a cheap model for
30
+ classification, a strong one for the hard step, all decided in plain Prolog.
31
+
32
+ ![The DeepClause REPL: an authoring turn running tests, committing, and rendering a diagram inline](docs/images/repl.png)
33
+
34
+ ## Dependencies and acknowledgements
35
+
36
+ DeepClause stands on other people's work, and is grateful for it:
37
+
38
+ - **[Pi](https://pi.dev)** (`@earendil-works/pi-coding-agent` and
39
+ `@earendil-works/pi-ai`) — the `pi` backend reuses Pi's model catalog,
40
+ credential store, streaming, cancellation, and usage accounting, and the
41
+ interactive REPL TUI is built on Pi's terminal UI library
42
+ (`@earendil-works/pi-tui`). Thanks to the **Pi developers** for building and
43
+ sharing it.
44
+ - **[SWI-Prolog](https://www.swi-prolog.org/)** — the Prolog engine that DML
45
+ runs on, compiled to WebAssembly so the whole runtime is in-process and
46
+ portable. SWI-Prolog is created and maintained by **Jan Wielemaker** and the
47
+ SWI-Prolog community.
48
+ - **[Markus Triska](https://www.metalevel.at/)** — his work on
49
+ meta-interpreters, constraint logic programming, and the
50
+ `library(clpfd)`/`library(clpq)` libraries underpins DML's executable
51
+ meta-interpreter and constraint layer.
52
+
53
+ DML, the REPL, and the SDK are original work; these projects are used as
54
+ dependencies and as conceptual foundations.
55
+
56
+ ## Why would I use this?
57
+
58
+ - **Reproducibility.** Control flow, retries, and validation are Prolog clauses
59
+ you can read and re-run, so a DML harness tends to produce the same result shape
60
+ across sessions and machines. The model is consulted only at the points you
61
+ choose, and its outputs are typed where that helps.
62
+ - **Auditability.** Each turn is a transaction: the module is snapshotted, the
63
+ change is committed replace-by-predicate, and the session, event trace, and
64
+ harness versions are recorded and remain queryable. It is possible to see what
65
+ changed, when, and in response to what.
66
+ - **Regulated and high-stakes settings.** Where a workflow has to be reviewed,
67
+ versioned, and reproduced — and where it helps to keep deterministic logic
68
+ separate from model judgment — a small, inspectable harness is easier to
69
+ scrutinise than a prompt. The transaction record and `rollback.` are meant to
70
+ support that kind of review, not replace it.
71
+ - **Research in neurosymbolic AI.** DML offers a concrete substrate for
72
+ combining symbolic reasoning (Prolog, CLP, backtracking) with LLM calls and
73
+ semantic judgments in one program, and for studying how such a system behaves
74
+ as an agent edits it over time (transactions, history, rollback).
75
+
76
+ It is likely not worth it when a single prompt or a short script is enough, or
77
+ when there is no structure you would want to reuse, review, or reproduce.
78
+
79
+ ## The REPL: a living, self-modifying harness
80
+
81
+ The REPL keeps a persistent DML module ("the harness"). You talk to it in two ways:
82
+
83
+ | Input | Mode |
84
+ |---|---|
85
+ | `<plain English>` (default) | **author** — the agent writes, tests, and commits DML |
86
+ | `/goal <dml>` | **run** — query the current harness |
2
87
 
3
- *Update (09/2026): Now also available as an extension for the pi coding agent: [https://github.com/deepclause/deepclause-pi](https://github.com/deepclause/deepclause-pi).*
4
-
5
- Compile markdown specs into executable logic programs. Guaranteed execution semantics for agentic workflows. Comes with a minimal coding agent incl. a nostalgic Borland-style TUI.
6
-
7
- ![docs/overview.png](docs/DeepClause_AI_Logic_Framework_Overview.png)
8
- ![docs/tui.png](docs/tui.png)
9
-
10
-
11
- ## What This Is
12
-
13
- AI skills and tools are everywhere, but most are still just prompts. When a prompt fails, you tweak it. When you need branching logic, you write wrapper code. When you want retry behavior, you build it yourself.
14
-
15
- DeepClause takes a different approach: **compile task descriptions into DML programs** - a Prolog-based language that handles control flow, error recovery, and tool orchestration automatically.
16
-
17
- The three main ways to use DeepClause are:
18
-
19
- 1. Coding Agent
20
- - Specialty: Create executable plans from specs and prompts
21
- 2. General Purpose Automation
22
- - Compile recurring tasks into skills, small logic programs that orchestrate agents, prompts, and deterministic code
23
- 3. Testbed for LLM+Prolog
24
- - Explore how constrained logic, tool calls, and model output interact in a reproducible runtime
25
-
26
- ## Host-provided LLM backend
27
-
28
- DeepClause can run on a model supplied by an embedding host instead of configuring an SDK provider. Pass an `LLMBackend` to `createDeepClause()`:
29
-
30
- ```ts
31
- import { createDeepClause, type LLMBackend } from "deepclause-sdk";
32
-
33
- const llmBackend: LLMBackend = {
34
- async complete(request) {
35
- const response = await hostModel.complete({
36
- messages: request.messages,
37
- tools: request.tools,
38
- signal: request.signal,
39
- });
40
-
41
- return {
42
- text: response.text,
43
- toolCalls: response.toolCalls,
44
- usage: response.usage,
45
- };
46
- },
47
- };
48
-
49
- const deepclause = await createDeepClause({
50
- model: "host-active-model",
51
- llmBackend,
52
- });
53
- ```
54
-
55
- The backend receives model messages, DML task tools, cancellation, token limits, and an optional `onText` callback. It returns text, structured tool calls, usage, and optional opaque `providerData` for replaying provider-native assistant state across agent-loop iterations. When a backend is supplied, DeepClause does not require provider credentials.
56
-
57
- DML-defined tool predicates remain available to `task/N` loops under a runtime tool whitelist. Calls made by those predicates through `exec/2` are still checked against the host policy, so an embedding can expose high-level DML tools without exposing its complete runtime tool registry.
58
-
59
-
60
- ## Benchmark: DeepPlanning Travel Planning
61
-
62
- DeepClause was evaluated on the [DeepPlanning](https://arxiv.org/abs/2601.18137) travel planning benchmark, which tests long-horizon agentic planning with verifiable constraints (time, budget, geography). The benchmark requires agents to gather information via tool calls, reason about local constraints, and produce globally coherent multi-day itineraries evaluated across 8 commonsense dimensions and personalized hard constraints.
63
-
64
- | Agent | Plan Model | Run Model | Composite | Case Acc | Delivery |
65
- |-------|-----------|-----------|-----------|----------|----------|
66
- | Qwen-Agent baseline (paper) | qwen3.6-35b-a3b | qwen3.6-35b-a3b | 22.2% | 0.0% | 82.5% |
67
- | DeepClause DML (direct) | qwen3.6-35b-a3b | qwen3.6-35b-a3b | 36.5% | 0.0% | **98.3%** |
68
- | DeepClause DML (plan-execute) | qwen3.6-plus | qwen3.6-35b-a3b | **42.9%** | 0.0% | 96.7% |
69
-
70
- Full comparison with frontier models from the DeepPlanning paper (travel planning only):
71
-
72
- | Model | CS | PS | Comp | Case Acc |
73
- |-------|-----|-----|------|----------|
74
- | **Non-Reasoning Models** | | | | |
75
- | Anthropic/Claude-4.5-Opus (w/o thinking) | 67.5 | 58.8 | 63.1 | 6.7 |
76
- | Anthropic/Claude-4.5-Sonnet (w/o thinking) | 53.4 | 42.8 | 48.1 | 1.1 |
77
- | Alibaba/Qwen3-Max (w/o thinking) | 36.7 | 30.7 | 31.8 | 0.8 |
78
- | ByteDance/Seed-1.8-minimal | 43.0 | 47.5 | 45.3 | 0.0 |
79
- | Alibaba/Qwen-Plus (w/o thinking) | 37.3 | 13.0 | 25.1 | 0.0 |
80
- | Z.ai/GLM-4.7 (w/o thinking) | 38.9 | 22.5 | 30.7 | 0.0 |
81
- | DeepSeek-AI/DeepSeek-V3.2 (w/o thinking) | 37.4 | 12.1 | 24.7 | 0.0 |
82
- | OpenAI/GPT-5.2-none | 54.3 | 29.9 | 42.1 | 0.4 |
83
- | xAI/Grok-4.1-Fast (non-reasoning) | 39.6 | 19.7 | 29.6 | 0.0 |
84
- | **Reasoning Models** | | | | |
85
- | OpenAI/GPT-5.2-high | 88.5 | 83.3 | 85.8 | 35.0 |
86
- | Anthropic/Claude-4.5-Opus (w/ thinking) | 79.3 | 70.9 | 75.1 | 22.7 |
87
- | OpenAI/GPT-5-high | 78.7 | 65.9 | 72.3 | 18.9 |
88
- | Google/Gemini-3-Flash-Preview | 67.1 | 57.7 | 62.4 | 5.9 |
89
- | Alibaba/Qwen3-Max (w/ thinking) | 64.0 | 61.7 | 62.8 | 13.8 |
90
- | Anthropic/Claude-4.5-Sonnet (w/ thinking) | 65.2 | 58.4 | 61.8 | 7.6 |
91
- | OpenAI/o3 | 76.5 | 55.6 | 66.1 | 11.3 |
92
- | Google/Gemini-3-Pro-Preview | 58.4 | 25.1 | 41.8 | 0.7 |
93
- | Deepseek-AI/DeepSeek-V3.2 (w/ thinking) | 47.4 | 35.0 | 41.2 | 0.7 |
94
- | ByteDance/Seed-1.8-high | 43.6 | 56.7 | 50.1 | 0.0 |
95
- | xAI/Grok-4.1-Fast (reasoning) | 57.1 | 37.7 | 47.4 | 2.7 |
96
- | Alibaba/Qwen-Plus (w/ thinking) | 35.4 | 22.4 | 28.9 | 0.0 |
97
- | Google/Gemini-2.5-Pro | 62.3 | 42.0 | 52.2 | 3.2 |
98
- | Z.ai/GLM-4.7 (w/ thinking) | 44.0 | 44.6 | 44.3 | 0.4 |
99
- | OpenAI/o4-mini | 58.0 | 36.6 | 47.2 | 3.0 |
100
- | Moonshot-AI/Kimi-K2-Thinking | 45.2 | 32.5 | 38.9 | 0.0 |
101
- | qwen3.6-35b-a3b baseline | 44.5 | 0.0 | 22.2 | 0.0 |
102
- | **DeepClause** | | | | |
103
- | DeepClause plan-execute (qwen3.6-35b-a3b) | 32.9 | 40.0 | 36.5 | 0.0 |
104
- | DeepClause plan-execute (plan: qwen3.6-plus, run: qwen3.6-35b-a3b) | 34.1 | 51.7 | **42.9** | 0.0 |
105
-
106
- CS = Commonsense Score, PS = Personalized Score, Comp = Composite Score. Results from the DeepPlanning paper (Table 2, travel planning only) are averaged over four runs across Chinese and English variants; DeepClause results are on the English subset. The DeepClause plan-execute variant outperforms the Qwen-Agent baseline by +93% on composite score (42.9% vs 22.2%) using the same execution model, and matches or exceeds several frontier reasoning models (DeepSeek-V3.2 w/ thinking: 41.2%, Gemini-3-Pro-Preview: 41.8%) — without any internal reasoning capability.
107
-
108
- The plan-execute variant runs in two phases. In the **plan phase**, a stronger model (qwen3.6-plus) analyzes the travel request and generates a self-contained DML file: it derives a system prompt, decomposes the request into 3-6 focused gathering tasks, and assembles DML program that includes all tool definitions and the execution logic. In the **execute phase**, a cheaper model (qwen3.6-35b-a3b) runs the generated DML.
109
-
110
- Example for a generated plan:
88
+ ```text
89
+ dml> add a research(Question, Answer) skill that answers with task/2 and cites sources
90
+ dml> run research on "why is the sky blue?"
91
+ A = "Rayleigh scattering scatters short wavelengths more strongly..."
111
92
 
93
+ dml> /goal research("why is the sky blue?", A). % the same skill, run directly
112
94
  ```
113
- :- use_module(library(http/json)).
114
-
115
- % --- Travel Tool Bridge ---
116
-
117
- run_tool(ToolName, ArgsDict, Result) :-
118
- param(db_path, DbPath),
119
- param(bridge_dir, BridgeDir),
120
- param(bench_dir, BenchDir),
121
- param(python_path, PythonPath),
122
- (var(PythonPath) -> PythonPath = 'python3' ; true),
123
- atom_json_dict(ArgsJson, ArgsDict, []),
124
- format(string(ArgsFile), ".dc_bridge_~w.json", [ToolName]),
125
- exec(write_file(path: ArgsFile, content: ArgsJson), _),
126
- format(string(Cmd), "~w '~w/python-bridge.py' --domain travel --db-path '~w' --bench-dir '~w' --tool ~w --args-file '~w'", [PythonPath, BridgeDir, DbPath, BenchDir, ToolName, ArgsFile]),
127
- exec(bash(command: Cmd), Raw),
128
- parse_bridge_result(Raw, Result).
129
-
130
- tool(query_train_info(Origin, Dest, Date, Result),
131
- "Search for train tickets between two cities on a given date. Returns train number, times, stations, duration, seat class, remaining seats, price.") :-
132
- run_tool(query_train_info, _{origin: Origin, destination: Dest, depDate: Date}, Result).
133
-
134
-
135
- [ ... more tool definitions ...]
136
-
137
- agent_main(Request) :-
138
- system("You are a travel planning agent creating a detailed itinerary for 4 travelers from Zhengzhou to Quanzhou (Nov 12-15, 2025). Execute the planned gathering steps autonomously without asking for user input.\n\nRULES:\n- All information must come from tool results — never fabricate names, prices, or details\n- Restaurant names must be EXACT matches from recommend_restaurants/query_restaurant_details results\n- Use recommend_restaurants with attraction/hotel coordinates passed as STRINGS, not restaurant coordinates\n- Current City on intercity travel days must use 'from CityA to CityB' format (literal 'from' and 'to')\n- Budget: all prices are per-unit; multiply by number of travelers/rooms in the final summary\n- Schedule times must be continuous with no gaps; do not schedule breakfast; full days require lunch+dinner\n- Last day (Nov 15) must end at the departure airport/station for the return journey\n- Select the shortest-duration direct outbound flight, a 4-star hotel with free parking, the 3 highest-rated attractions, and the cheapest restaurant in Donghai Bay area\n\nProceed through all gathering steps, then compile the complete itinerary with continuous daily schedules, exact venue names, and accurate budget calculations."),
139
- user(Request),
140
- task("Search for direct flights from Zhengzhou to Quanzhou on November 12, 2025, and return flights from Quanzhou to Zhengzhou on November 15, 2025, for 4 passengers, identif
141
- ying the shortest-duration direct flight option for the outbound journey."),
142
- task("Search for four-star hotels in Quanzhou with free parking available for check-in on November 12, 2025 and check-out on November 15, 2025, accommodating 4 guests."),
143
- task("Search for and recommend top-rated attractions in Quanzhou, then retrieve details to identify the three highest-rated attractions."),
144
- task("Search for restaurants in the Donghai Bay area of Quanzhou and find the one with the lowest average spending per person."),
145
- task('Based on all gathered information, generate the complete travel itinerary inside <plan></plan> tags. Include day-by-day schedule with times, Current City, attractions,
146
- meals with EXACT restaurant names from tool results, transport details, and a budget summary where per-unit costs are multiplied by number of travelers/rooms.', string(DraftPlan)
147
- ),
148
- task('Review this travel plan for errors and fix them. Check ALL of the following:
149
- 1. BUDGET: Is total cost (per-person costs * travelers, per-room costs * rooms) within budget?
150
- 2. TIME CONTINUITY: Are times continuous with no gaps or overlaps? Each activity end time = next start time.
151
- 3. MEAL RULES: Full sightseeing days need lunch AND dinner. No breakfast. Meals 1-2 hours. At least 2 hours between lunch and dinner.
152
- 4. DAILY STRUCTURE: Every day except last ends at hotel. Last day ends at departure airport/station.
153
- 5. GEOSPATIAL: No teleportation — travel_city between different locations.
154
- 6. DIVERSITY: No repeating restaurants or attractions across days.
155
- 7. NAMES: All names EXACTLY match tool results — no abbreviations or renames.
156
- 8. CURRENT CITY: Intercity days must say "from CityA to CityB".
157
-
158
- Plan to review:
159
- {DraftPlan}
160
-
161
- If the plan has errors, output the CORRECTED plan inside <plan></plan> tags. If it is already correct, output it unchanged inside <plan></plan> tags. Store the final verified plan in VerifiedPlan.', string(VerifiedPlan)),
162
- answer(VerifiedPlan).
163
-
164
- agent_main(Request) :-
165
- system('You are a travel planning assistant. Create a travel plan using the available tools. Output inside <plan></plan> tags with budget summary.'),
166
- user(Request),
167
- task('Create a complete travel plan using all available tools. Output inside <plan></plan> tags.', string(Plan)),
168
- answer(Plan).
169
- ```
170
-
171
-
172
95
 
173
- ## Install and Run
96
+ The default mode is the interesting one: describe what you want and the
97
+ authoring agent edits the module for you through tools, testing as it goes. Ask
98
+ for anything — add a skill, add a tool, change existing logic, run or test code
99
+ in the living module, or just ask a question about the harness.
174
100
 
175
- DeepClause requires Node.js 18+.
101
+ ### A worked session
176
102
 
177
- ### Global install
103
+ A full pass: create a skill, watch the transaction, run it, export it, and load
104
+ it again as a new harness.
178
105
 
179
- ```bash
180
- npm install -g deepclause-sdk
181
-
182
- # Pick one provider and export its API key
183
- export OPENAI_API_KEY="sk-..."
184
- # or: export ANTHROPIC_API_KEY="..."
185
- # or: export GOOGLE_GENERATIVE_AI_API_KEY="..."
186
- # or: export OPENROUTER_API_KEY="..."
187
-
188
- # Initialize the current workspace
189
- deepclause init --model openai:gpt-4o
106
+ **1. Create (one transaction)**
190
107
 
191
- # Inspect the configured slots
192
- deepclause show-model
193
-
194
- # Start the fullscreen conductor TUI
195
- deepclause
196
-
197
- # Or run one headless conductor turn
198
- deepclause -p "Summarize the repository architecture"
199
- ```
108
+ ```text
109
+ dml> add a research(Question, Answer) skill that answers with task/2
200
110
 
201
- ### One-off usage with npx
111
+ ⚙ begin_turn
112
+ ✔ begin_turn · 2ms
113
+ ⚙ assert_many(clauses=module_doc("…"), research(Question, Answer) :- task(…), doc(research/2, …))
114
+ ✔ assert_many · 11ms
115
+ ⚙ execute
116
+ research("Why is the sky blue?", A).
117
+ ▸ Task Answer this research question: Why is the sky blue?
118
+ ✔ Task done
119
+ A = "Rayleigh scattering…"
120
+ ✔ execute · 3.7s
121
+ ⚙ end_turn(summary=Add research/2)
122
+ ✔ end_turn · 4ms — {"committed":true,"changed":["+research/2","+module_doc/1","+doc/2"]}
202
123
 
203
- ```bash
204
- npx deepclause-sdk@latest init --model openai:gpt-4o
205
- npx deepclause-sdk@latest show-model
206
- npx deepclause-sdk@latest
124
+ Added research/2 — a one-call task/2 research skill.
207
125
  ```
208
126
 
209
- All commands except `init`, `help`, `--help`, `--version`, and `-V` expect a `.deepclause/` directory in the current workspace.
210
-
211
- `deepclause init` creates:
212
-
213
- - `.deepclause/config.json`
214
- - `.deepclause/tools/`
215
- - `.deepclause/docs/`
216
- - `.deepclause/docs/TUI.md`
217
- - `.deepclause/system/`
218
- - `.deepclause/system/recipes/`
219
- - `.deepclause/.gitignore`
220
- - seeded local skills: `deep-research` and `research-search-reader`
221
- - seeded example recipe: `deepclause-coding-workflow`
222
- - editable system overrides:
223
- - `conductor.dml`
224
- - `skill-creator.dml`
225
- - `CONDUCTOR_PROMPT.md`
226
- - `DML_COMPILER_PROMPT.md`
227
- - `TASK_PROMPT.md`
228
-
229
- The default recipe is created at `.deepclause/system/recipes/deepclause-coding-workflow/SKILL.md`. It is a real example, not a placeholder: it teaches the conductor how to approach local repository changes with small edits and focused validation. You can edit it, remove it, or add your own recipes next to it.
230
-
231
- Recipes are plain markdown guidance, not executable DML. If you want to add or update one, edit `.deepclause/system/recipes/<slug>/SKILL.md` directly. The conductor can search those recipe files on future turns via `consult_recipes`.
232
-
233
- ## TUI Agent
234
-
235
- Running `deepclause` with no subcommand starts the fullscreen TUI.
236
-
237
- - Session list on the left
238
- - Messages in the center
239
- - Execution log and context summary on the right
240
- - Slash commands such as `/new`, `/sessions`, `/set-model <model> [--slot <slot>]`, `/compile <spec>`, `/skill-creator <spec>`, `/cancel`, and `/<skill> [args]`
241
- - Direct shell commands with `!<command>`, streamed live in the execution pane and cancelled with `/cancel`
242
- - Persistent shell commands with `!!<command>`, which also append the command and its output to the active session transcript so the conductor can see them on the next turn
243
-
244
- Use `!<command>` when you just want an ephemeral shell escape in the execution pane. Use `!!<command>` when the shell result should become part of the conversation state for later conductor turns.
245
-
246
- For non-interactive use, `deepclause -p "..."` runs a single headless conductor turn with a fresh session.
247
-
248
- ### Basic Structure
249
-
250
- The TUI is the interface around a single built-in agent: the conductor.
251
-
252
- - The TUI itself is just the UI shell: session browser, messages pane, execution log, and context view.
253
- - The conductor is the actual agent that receives your prompt each turn and decides what to do.
254
- - The conductor is implemented as a system DML skill plus a system prompt.
255
- - The conductor can answer directly, call an existing local skill, consult the recipe library for workflow guidance, invoke the skill creator to make a new skill, use shell tools, or do web research.
256
-
257
- Conceptually, a TUI turn works like this:
258
-
259
- 1. Load the current session from `.deepclause/sessions/<session-id>/`.
260
- 2. Build the conductor prompt from the resolved conductor prompt template, the current skill catalog, the recipe library, assistant memory, task memory, and session transcript.
261
- 3. Run the conductor DML with the `gateway` model slot.
262
- 4. Stream the conductor's own activity and any child-skill events into the execution log on the right.
263
- 5. Persist the final user/assistant messages, structured `execution-log.jsonl`, and updated usage counters back into the session directory.
264
-
265
- The conductor is the router and orchestrator for the CLI runtime. Normal compiled skills are the workers it delegates to. When the conductor launches a normal skill, that skill runs with the `run` model slot. When it launches the skill creator, that child run uses the `compile` model slot instead.
266
-
267
- ### Skills, Recipes, and the Conductor
268
-
269
- DeepClause separates three things that other agent systems often collapse into one prompt surface.
270
-
271
- - **Conductor**: the built-in router. It owns the conversation, inspects the workspace context, and decides whether to solve directly, run a skill, consult a recipe, or create a new skill.
272
- - **Skills**: executable DML workers stored in `.deepclause/tools/`. These are compiled programs with explicit tool calls, branching, retries, recursion, and parameters.
273
- - **Recipes**: markdown guidance stored in `.deepclause/system/recipes/`. These are instruction packs for workflows, conventions, checklists, and examples. They are searched via `consult_recipes`, not executed as child workers.
274
- - **Skill creator**: the built-in compiler/orchestrator that turns a natural-language spec into a tested local skill.
275
-
276
- That distinction matters in practice:
277
-
278
- - Use a **recipe** when you need to know how to approach a task.
279
- - Use a **skill** when you need a reusable automation that should actually execute.
280
- - Use the **conductor** when you want the system to choose between those options for the current turn.
281
-
282
- If the task is to create or refine workflow guidance itself, add or edit a recipe markdown file under `.deepclause/system/recipes/<slug>/SKILL.md`. Do not send recipe authoring through `deepclause compile` unless you actually want an executable skill instead of a guidance document.
127
+ The agent opened a transaction (`begin_turn`), wrote the predicates
128
+ (`assert_many`), tested them with `execute`, and committed with `end_turn` — which
129
+ printed the predicates it changed and recorded a version. Had the turn failed,
130
+ the host would have rolled the module back to exactly its prior state.
283
131
 
284
- Minimal recipe example:
285
-
286
- ```md
287
- ---
288
- name: DeepClause Coding Workflow
289
- description: Guidance for implementing and validating local repository changes.
290
- tags: [coding, tests, docs]
291
- when_to_use:
292
- - implementing a feature or bug fix in the current repository
293
- priority: high
294
- ---
295
-
296
- # Workflow
297
-
298
- 1. Start from a concrete anchor.
299
- 2. Make the smallest grounded edit.
300
- 3. Run the narrowest validation that can falsify it.
301
- ```
302
-
303
- Minimal skill example:
132
+ **2. Inspect, run, undo**
304
133
 
305
134
  ```text
306
- deepclause compile fix-imports.md
307
- deepclause run .deepclause/tools/fix-imports.dml src/index.ts
308
- ```
309
-
310
- The recipe is guidance. The skill is an executable worker.
311
-
312
- ### The `/plan` Command
313
-
314
- `plan` is a built-in system command that turns a request into a standalone DML plan file under `plans/` in the workspace.
315
-
316
- How it works:
317
-
318
- 1. You provide a request, for example from the TUI as `/plan ...` or through the command listing interface.
319
- 2. DeepClause uses the packaged or workspace-overridden `src/system/assets/skills/plan.dml` implementation to classify the request, collect any needed recipe guidance, and draft a numbered task list.
320
- 3. The plan generator derives a system prompt for the resulting plan, includes the DeepClause coding workflow recipe, and assembles a deterministic `.dml` file.
321
- 4. The generated file is written to `plans/<name>.dml`, validated, and then available to run like any other plan or skill.
322
- 5. In the TUI, `/<plan> [args]` runs a plan from `plans/` when no compiled skill with the same name exists.
323
-
324
- The important design point is that `plan` does not try to invent a whole new agent architecture each time. It produces a small executable plan file from the request, with the runtime and recipes providing the reusable behavior.
135
+ dml> /listing
136
+ skill: Research a question and return a written answer.
325
137
 
326
- ### How This Differs From Other Agent Systems
138
+ doc/2
139
+ doc(research/2,"Answer a question in one model call. research(+Question, -Answer). …").
327
140
 
328
- Systems like `AGENTS.md`, Cursor rules, Claude Skills, or other instruction-pack formats are mostly about giving the model reusable context. DeepClause supports that same need through **recipes**, but it does not stop there.
141
+ module_doc/1
142
+ module_doc("Research a question and return a written answer. …").
329
143
 
330
- What is different here:
144
+ research/2
145
+ research(A,B) :-
146
+ task("Answer this question: {A}",B).
331
147
 
332
- - DeepClause keeps **guidance** and **execution** separate. Recipes are markdown guidance; skills are compiled programs.
333
- - A DeepClause skill is not just a saved prompt. It is a DML program that the runtime executes with Prolog semantics.
334
- - The conductor can decide between **consulting a recipe**, **running a compiled skill**, or **creating a new skill**.
335
- - Model choice is split by role: `gateway` for orchestration, `run` for worker execution, and `compile` for skill creation.
336
- - The compiled `.dml` is inspectable and versionable, so the automation logic is explicit instead of hidden in a long prompt.
148
+ dml> /goal research("Why is the sky blue?", A).
149
+ A = "Rayleigh scattering…"
337
150
 
338
- ### Memory Tools
151
+ dml> /rollback
152
+ rolled back harness: version 1 → 0
339
153
 
340
- The memory tools are there so the conductor can keep durable technical notes across turns instead of re-deriving everything from scratch every time.
341
-
342
- - `messages.jsonl` is the conversation transcript. This is the raw history of user and assistant messages.
343
- - `assistant-memory.md` is long-lived assistant context that gets injected into the conductor prompt each turn.
344
- - `task-memory.md` is technical working memory: commands that worked, failure modes, local architecture notes, repair strategies, and other distilled learnings.
345
-
346
- In the current conductor, memory updates are produced as part of the main `task(...)` call. The conductor asks the model for two outputs:
347
-
348
- - `FinalAnswer`: the user-facing reply
349
- - `MemoryUpdate`: the complete updated task-memory markdown, or `NONE`
350
-
351
- When `MemoryUpdate` contains actual content, the runtime persists it through `update_memory`, which replaces `task-memory.md` with the complete updated memory contents.
352
-
353
- That distinction matters:
354
-
355
- - use the transcript for exact conversation history
356
- - use task memory for compressed technical learnings that should help future turns
357
- - use assistant memory for stable higher-level context, tone, or persistent instructions
358
-
359
- In the current CLI runtime, task memory is the main writable memory channel exposed to the conductor. Assistant memory is loaded and shown in the TUI, but it is not automatically updated by a built-in conductor tool in the same way.
154
+ dml> /goal research("Why is the sky blue?", A).
155
+ false. % the skill is gone
156
+ ```
360
157
 
361
- ### Session and Memory Files
158
+ `end_turn` is the only commit point, and `/rollback` moves the harness back one
159
+ committed version (here, to the baseline) — so nothing is committed silently.
362
160
 
363
- Each TUI session lives under `.deepclause/sessions/<session-id>/`:
161
+ **3. Export**
364
162
 
365
163
  ```text
366
- .deepclause/
367
- sessions/
368
- <session-id>/
369
- session.json
370
- messages.jsonl
371
- execution-log.jsonl
372
- assistant-memory.md
373
- task-memory.md
374
- usage.json
375
- specs/
164
+ dml> /export research.dml
165
+ exported 3 clauses, 0 tools, 0 scripts → research.dml
376
166
  ```
377
167
 
378
- - `session.json` stores the session title and timestamps.
379
- - `messages.jsonl` is the append-only user/assistant transcript that gets replayed into future conductor turns.
380
- - `execution-log.jsonl` stores structured JSONL records for conductor turns, direct `/skill` runs, direct `/skill-creator` runs, child-skill events, tool calls, streamed model output, errors, and completion summaries.
381
- - `assistant-memory.md` is loaded into the conductor prompt as stable assistant context.
382
- - `task-memory.md` is loaded into the conductor prompt as technical working memory.
383
- - `usage.json` stores token usage summaries by model.
384
- - `specs/` is used when the conductor invokes the skill creator and saves generated spec drafts for that session.
385
-
386
- When a task fails, looks stuck, or needs to be retried, `execution-log.jsonl` is the first file to inspect. It gives you the concrete failing tool call, streamed model behavior, and any successful prior pattern in the same session instead of forcing you to guess from the final transcript alone.
387
-
388
- In the CLI runtime today, task memory is the actively updated memory channel: the conductor can emit a `MemoryUpdate`, which persists through `update_memory` into `task-memory.md`. `assistant-memory.md` is still loaded every turn, but it is primarily something you inspect or edit manually unless you build additional tooling around it.
389
-
390
- ### Hacking the Conductor and Skill Creator
168
+ `research.dml` is a plain DML file: commit it, diff it, mail it. Use a `.zip`
169
+ target to bundle linked `script_file/2` scripts.
391
170
 
392
- There are two levels of customization.
393
-
394
- #### 1. Workspace-local system overrides
395
-
396
- If you want to customize behavior for one workspace without modifying the package, place override files here:
397
-
398
- - `.deepclause/system/conductor.dml`
399
- - `.deepclause/system/skill-creator.dml`
400
- - `.deepclause/system/CONDUCTOR_PROMPT.md`
401
- - `.deepclause/system/DML_COMPILER_PROMPT.md`
402
- - `.deepclause/system/TASK_PROMPT.md`
403
- - `.deepclause/system/recipes/<recipe-slug>/SKILL.md`
404
-
405
- When present, the CLI runtime prefers those files over the packaged system DML and system prompt markdown. For recipes, workspace files override packaged recipes with the same slug.
406
-
407
- `.deepclause/system/TASK_PROMPT.md` is the markdown template used for `task(...)` and `prompt(...)` harness calls. `deepclause init` seeds it into the workspace, and the runtime resolves that workspace copy before falling back to the packaged default.
408
-
409
- #### 2. Source-level hacking in this repository
410
-
411
- If you are developing DeepClause itself, these are the main files to edit:
412
-
413
- - `src/system/assets/skills/conductor.dml` - the conductor's DML logic
414
- - `src/system/assets/skills/skill-creator.dml` - the skill creator's DML logic
415
- - `src/system/assets/docs/CONDUCTOR_PROMPT.md` - the conductor system prompt template
416
- - `src/system/assets/docs/DML_COMPILER_PROMPT.md` - the skill creator/compiler system prompt template
417
- - `src/system/assets/docs/TASK_PROMPT.md` - the `task(...)` / `prompt(...)` harness template
418
- - `src/system/assets/recipes/` - packaged default recipes copied into new workspaces
419
- - `src/system/runtime/conductor.ts` - session loading, memory injection, tool registration, child-skill routing
420
- - `src/system/runtime/skill-creator.ts` - compile-slot execution, skill-creator tool registration, validation/testing/deploy flow
421
- - `src/system/runtime/catalog-recipes.ts` - recipe discovery, frontmatter parsing, and query matching
422
-
423
- Notes:
424
-
425
- - The conductor uses the `gateway` model slot.
426
- - Normal compiled skills use the `run` model slot.
427
- - The skill creator uses the `compile` model slot.
428
- - The TUI context pane shows the resolved source paths for the conductor DML/prompt, skill creator DML/prompt, and task prompt template.
429
- - Changes to those `.deepclause/system/` files are picked up on the next conductor turn, skill-creator run, or `task(...)` / `prompt(...)` execution; a dedicated TUI reload is not required.
430
-
431
- After source-level changes, rebuild the package:
171
+ **4. Load it elsewhere (a harness from somewhere else)**
432
172
 
433
173
  ```bash
434
- npm install
435
- npm run build
174
+ deepclause repl -l research.dml
436
175
  ```
437
176
 
438
- If you want to run the CLI from a source checkout while hacking on it:
177
+ Loading a file targets the harness named after it (`research`), creating it if
178
+ needed. The file becomes that harness's **baseline**, so it works with no prior
179
+ history: `/rollback` floors at the loaded file, never at empty.
180
+
181
+ **5. Several harnesses in one project**
439
182
 
440
183
  ```bash
441
- npm install
442
- npm run build
443
- npm run cli -- init
444
- npm run cli --
184
+ deepclause repl # harness `main`
185
+ deepclause repl --harness support # harness `support`
186
+ deepclause repl -l research.dml # harness `research`
445
187
  ```
446
188
 
447
- ## Model and Provider Configuration
448
-
449
- DeepClause separates model choice into three slots:
189
+ Each harness has its own content and version history under
190
+ `.deepclause/repl/harnesses/<name>/`. A fresh session loads its harness's current
191
+ content (the agent continues what is there instead of re-creating it), and
192
+ `/rollback` never crosses harnesses.
450
193
 
451
- - `gateway` - conductor and orchestration turns
452
- - `run` - compiled skill execution
453
- - `compile` - skill compilation and `_skill-creator`
194
+ ### Example: build a coding agent
454
195
 
455
- The canonical model id format is `provider:model`, but the CLI also accepts `provider/model` and, for common built-ins, bare model names that it can infer.
196
+ You can ask for a whole **capability**, not just a one-off answer:
456
197
 
457
- Example `.deepclause/config.json`:
198
+ ```text
199
+ dml> build me a coding agent harness for this repo
200
+
201
+ ⚙ listing
202
+ ✔ listing · 1ms
203
+ ⚙ begin_turn
204
+ ✔ begin_turn · 2ms
205
+ ⚙ define(head=run_shell(Command, Output), clauses=run_shell(Command, Output) :- exec(bash(…), Result), …)
206
+ ✔ define · 31ms
207
+ ⚙ define(head=fs_read(Path, Text), clauses=fs_read(Path, Text) :- read_file(Path, Text).)
208
+ ✔ define · 6ms
209
+ ⚙ define(head=fs_write(Path, Content), clauses=fs_write(Path, Content) :- write_file(Path, Content).)
210
+ ✔ define · 5ms
211
+ ⚙ define(head=fs_grep(Pattern, Path, Matches), clauses=fs_grep(Pattern, Path, Matches) :- …)
212
+ ✔ define · 7ms
213
+ ⚙ assert_many(clauses=tool(run_shell(…)) :- run_shell(…). tool(fs_read(…)) :- …. …)
214
+ ✔ assert_many · 4ms
215
+ ⚙ define(head=explain(Question, Answer), clauses=explain(Question, Answer) :- system(…), with_tools(…).)
216
+ ✔ define · 8ms
217
+ ⚙ define(head=patch(File, Issue, Summary), clauses=patch(File, Issue, Summary) :- system(…), with_tools(…).)
218
+ ✔ define · 9ms
219
+ ⚙ execute
220
+ fs_read("package.json", T), run_shell("npm test", R).
221
+ ✔ execute · 1.4s
222
+ ⚙ end_turn(summary=Add coding-agent skills: run_shell/fs_read/fs_write/fs_grep + explain/patch)
223
+ ✔ end_turn · 12ms — {"committed":true,"changed":["+run_shell/2","+fs_read/2","+fs_write/2","+fs_grep/3","+explain/2","+patch/3"]}
224
+
225
+ A coding-agent harness is ready: a small shell/file toolset exposed to `task/N`, plus
226
+ `explain/2` and `patch/3` skills that scope those tools per task.
227
+ ```
228
+
229
+ The harness it built (trimmed):
458
230
 
459
- ```json
460
- {
461
- "models": {
462
- "gateway": "openai:gpt-4o",
463
- "run": "openrouter:google/gemini-2.5-flash",
464
- "compile": "anthropic:claude-sonnet-4-20250514"
465
- },
466
- "temperatures": {
467
- "gateway": 0.7,
468
- "run": 0.7,
469
- "compile": 0.4
470
- },
471
- "providers": {
472
- "openai": {
473
- "apiKey": "${OPENAI_API_KEY}"
474
- },
475
- "anthropic": {
476
- "apiKey": "${ANTHROPIC_API_KEY}"
477
- },
478
- "google": {
479
- "apiKey": "${GOOGLE_GENERATIVE_AI_API_KEY}"
480
- },
481
- "openrouter": {
482
- "apiKey": "${OPENROUTER_API_KEY}",
483
- "baseUrl": "https://openrouter.ai/api/v1"
484
- }
485
- },
486
- "agentvm": {
487
- "network": false
488
- },
489
- "workspace": "./workspace",
490
- "dmlBase": ".deepclause/tools"
491
- }
492
- ```
231
+ ```prolog
232
+ module_doc("Coding agent: read, search, and edit a repository and run its tests.").
493
233
 
494
- Configuration values support `${ENV_VAR}` and `$ENV_VAR` interpolation.
234
+ run_shell(Command, Output) :-
235
+ exec(bash(command: Command), Result),
236
+ ( get_dict(stdout, Result, Out) -> Output = Out ; Output = "" ).
495
237
 
496
- ### Setting Models from the CLI
238
+ fs_read(Path, Text) :- read_file(Path, Text).
239
+ fs_write(Path, Content) :- write_file(Path, Content).
497
240
 
498
- ```bash
499
- # Update all three slots
500
- deepclause set-model openai:gpt-4o
241
+ fs_grep(Pattern, Path, Matches) :-
242
+ format(atom(Cmd), "grep -rn -- ~w ~w", [Pattern, Path]),
243
+ exec(bash(command: Cmd), Result),
244
+ ( get_dict(stdout, Result, Out) -> Matches = Out ; Matches = "" ).
501
245
 
502
- # Only change the compile slot
503
- deepclause set-model anthropic:claude-sonnet-4-20250514 --slot compile
246
+ % `tool/2` only exposes the predicates above to the nested agent in task/N.
247
+ tool(run_shell(Command, Output), "Run a shell command; returns stdout.") :- run_shell(Command, Output).
248
+ tool(fs_read(Path, Text), "Read a workspace file.") :- fs_read(Path, Text).
249
+ tool(fs_write(Path, Content), "Write a workspace file.") :- fs_write(Path, Content).
250
+ tool(fs_grep(Pattern, Path, Matches), "Search a path; returns matching lines.") :- fs_grep(Pattern, Path, Matches).
504
251
 
505
- # Use OpenRouter for the conductor only
506
- deepclause set-model openrouter:google/gemini-2.5-flash --slot gateway
252
+ doc(explain/2, "Explain code relevant to a question. explain(+Question, -Answer).").
253
+ explain(Question, Answer) :-
254
+ system("You are a coding assistant working in a repository. Cite file paths and line numbers."),
255
+ with_tools([run_shell, fs_read, fs_grep],
256
+ task("Answer this question about the repository: {Question}", Answer)).
507
257
 
508
- # Inspect the resolved slot values
509
- deepclause show-model
258
+ doc(patch/3, "Apply a minimal fix and run the tests. patch(+File, +Issue, -Summary).").
259
+ patch(File, Issue, Summary) :-
260
+ system("Make the smallest change that fixes the issue. Run the project's tests and report the result."),
261
+ with_tools([run_shell, fs_read, fs_write, fs_grep],
262
+ task("Fix this issue in {File}: {Issue}. Then run the tests and report what changed.", Summary)).
510
263
  ```
511
264
 
512
- ### Provider Notes
513
-
514
- | Provider | Canonical example | API key env var | Notes |
515
- |----------|-------------------|-----------------|-------|
516
- | OpenAI | `openai:gpt-4o` | `OPENAI_API_KEY` | You can also set `providers.openai.baseUrl` for an OpenAI-compatible endpoint. |
517
- | Anthropic | `anthropic:claude-sonnet-4-20250514` | `ANTHROPIC_API_KEY` | Native Anthropic adapter. |
518
- | Google | `google:gemini-2.5-flash` | `GOOGLE_GENERATIVE_AI_API_KEY` | Native Google Generative AI adapter. |
519
- | OpenRouter | `openrouter:anthropic/claude-sonnet-4` | `OPENROUTER_API_KEY` | Use any OpenRouter model path. |
520
- | Custom | `custom:local:qwen3-32b` | `LLM_PROVIDER_LOCAL_API_KEY` | Uses the OpenAI-compatible transport with a custom base URL. |
521
-
522
- ### Custom Provider
265
+ Use it:
523
266
 
524
- `custom:` is for OpenAI-compatible endpoints that you want to name explicitly instead of pretending they are one of the built-in providers.
267
+ ```text
268
+ dml> /goal explain("where are the CLI entry points?", A).
269
+ A = "…"
525
270
 
526
- Format:
271
+ dml> /goal patch("src/cli.ts", "the --help flag is missing", S).
272
+ S = "…"
527
273
 
528
- ```text
529
- custom:<provider-name>:<model-name>
274
+ dml> /export coding_agent.dml
530
275
  ```
531
276
 
532
- Example:
533
-
534
277
  ```bash
535
- export LLM_PROVIDER_LOCAL_BASE_URL="http://localhost:11434/v1"
536
- export LLM_PROVIDER_LOCAL_API_KEY="dummy"
537
-
538
- deepclause set-model custom:local:qwen3-32b --slot run
539
- deepclause show-model
278
+ deepclause repl -l coding_agent.dml # harness `coding_agent`
279
+ deepclause run coding_agent.dml --goal 'explain("…", A)' # one-shot
540
280
  ```
541
281
 
542
282
  Notes:
543
283
 
544
- - `custom:local:qwen3-32b` reads `LLM_PROVIDER_LOCAL_BASE_URL` and `LLM_PROVIDER_LOCAL_API_KEY`.
545
- - The provider name is uppercased and normalized when constructing env vars, so `custom:my-lab:model-x` becomes `LLM_PROVIDER_MY_LAB_BASE_URL` and `LLM_PROVIDER_MY_LAB_API_KEY`.
546
- - `custom:` providers are not configured under the `providers` object in `config.json`; they are resolved from env vars.
547
- - Internally, `custom:` uses the OpenAI-compatible transport, so your endpoint must speak an OpenAI-style chat/completions API.
548
-
549
- ## Runtime Model
550
-
551
- DeepClause executes DML in a local CLI runtime:
552
-
553
- - **Prolog runtime in WASM**: The DML logic engine runs in SWI-Prolog compiled to WebAssembly.
554
- - **Host shell by default**: Shell tools run in the active local workspace shell.
555
- - **AgentVM on demand**: Pass `--sandbox` when you want shell tools to run inside [AgentVM](https://github.com/deepclause/agentvm) instead.
556
-
557
- This keeps the default workflow simple for local development while still supporting an isolated shell backend when needed.
558
-
559
- The active shell backend also appears in the TUI and runtime events with labels such as `host[bwrap]`, `host[clean-room]`, `host[bwrap strict]`, and `sandbox[agentvm]`.
560
-
561
- Host-shell isolation details:
562
-
563
- - `shell.wrapper: "auto"` prefers `bwrap` on Linux and `sandbox-exec` on macOS when available, then falls back to `clean-room`.
564
- - `shell.wrapper` can also force `clean-room`, `bwrap`, or `sandbox-exec` when you want deterministic behavior across machines.
565
- - `shell.strictIsolation: true` requests stricter host-shell isolation. On Linux with `bwrap`, that adds `--unshare-net` so shell commands lose outbound network access.
566
- - The Linux `bwrap` path preserves common DNS setups where `/etc/resolv.conf` is a symlink into `/run`, so resolver lookups continue to work on `systemd-resolved` hosts.
567
-
568
- Linux note: when `bubblewrap` is available, DeepClause will prefer it for host-shell isolation. On some Ubuntu/AppArmor systems, `kernel.apparmor_restrict_unprivileged_userns=1` blocks the unprivileged user-namespace path that `bwrap` needs, which surfaces as `bwrap: setting up uid map: Permission denied`. In that case DeepClause correctly falls back to the clean-room host shell. If you want `bwrap` on those hosts, you need a permitted AppArmor/userns configuration, a setuid-capable `bwrap` install, or `--sandbox` with AgentVM instead.
284
+ - `tool/2` is only an annotation; the *capabilities* are the predicates above, so
285
+ they are reachable from `execute` / `/goal` **and** from `task/N`.
286
+ - `with_tools/2` scopes which tools a `task/N` turn may call — `explain` cannot
287
+ edit files, `patch` can.
288
+ - Because a `task/N` turn can call these tools (and itself), the module is an
289
+ RLM-style harness, not a fixed script.
569
290
 
570
- ## Beyond Markdown: Why Logic Programming?
291
+ ### Model switching
571
292
 
572
- Markdown skills are great for simple, linear workflows. But real-world tasks often need:
293
+ A harness can choose the model for individual calls with `with_model/2`, so you
294
+ can route cheap work to a small model and hard work to a strong one — or tune a
295
+ whole harness to one model:
573
296
 
574
- - **Branching logic** - Try approach A, fall back to B if it fails
575
- - **Iteration** - Process a list of items one by one
576
- - **State management** - Isolate context between sub-tasks
577
- - **Error recovery** - Handle failures gracefully
578
- - **Composition** - Build complex skills from simpler ones
579
-
580
- When you give markdown instructions to a typical agentic loop, there's no guarantee these requirements will actually be followed—the LLM might ignore the fallback logic or skip items in a list.
581
-
582
- By compiling to Prolog, you get **guaranteed execution semantics**: backtracking ensures fallbacks happen, recursion processes every item, and unification binds variables correctly. You define *what* should happen—the runtime guarantees *how*.
583
-
584
-
585
-
586
- ## Spec-Driven Development That Compiles
587
-
588
- [Spec-driven development](https://martinfowler.com/articles/exploring-gen-ai/sdd-3-tools.html) proposes writing specifications before code, with the spec becoming the source of truth. Current SDD tools (Kiro, spec-kit, Tessl) generate elaborate markdown artifacts that are then fed to coding agents—but the output is still non-deterministic, and you end up reviewing both specs *and* generated code.
297
+ ```prolog
298
+ % a cheap model for classification
299
+ triage(Message, Team) :-
300
+ with_model("openai:gpt-4o-mini",
301
+ prompt("Classify as billing/orders/account: {Message}", Team)).
589
302
 
590
- DeepClause offers a different approach: **specs that compile to actual programs**.
303
+ % a strong model at high reasoning, only for the hard step
304
+ review(Diff, Notes) :-
305
+ with_model("anthropic:claude-sonnet-4#high",
306
+ task("Review this diff and list defects:\n{Diff}", Notes)).
591
307
 
592
- ```bash
593
- # Your spec
594
- cat > api-client.md << 'EOF'
595
- # API Client Generator
596
- Generate a TypeScript API client from an OpenAPI spec URL.
597
-
598
- ## Arguments
599
- - SpecUrl: URL to an OpenAPI/Swagger JSON specification
600
-
601
- ## Behavior
602
- - Fetch the OpenAPI spec from SpecUrl
603
- - Extract endpoints and types
604
- - Generate typed client code
605
- - Write to output file
606
- EOF
607
-
608
- # Compile it once
609
- deepclause compile api-client.md
610
-
611
- # Run it deterministically, forever
612
- deepclause run api-client.dml "https://api.example.com/openapi.json"
308
+ % full control via a dict
309
+ with_model(model{provider: "google", id: "gemini-2.5-pro",
310
+ temperature: 0.2, maxTokens: 8192}, Goal).
613
311
  ```
614
312
 
615
- The compiled `.dml` is inspectable logic—you can see exactly what it does:
616
-
617
- ```prolog
618
- tool(fetch_spec(Url, Spec), "Fetch OpenAPI specification") :-
619
- exec(web_fetch(url: Url), Spec).
620
-
621
- agent_main(SpecUrl) :-
622
- system("You are an API client generator..."),
623
- fetch_spec(SpecUrl, Spec),
624
- task("Extract endpoints from: {Spec}", Endpoints),
625
- task("Generate TypeScript client for: {Endpoints}", Code),
626
- exec(vm_exec(command: "cat > client.ts"), Code),
627
- answer("Generated client.ts").
628
- ```
313
+ `with_model` scopes the `task/N`, `prompt/N` and `sample_token/N` calls inside
314
+ `Goal` (judgments keep their own backend); the innermost scope wins, and it
315
+ composes with `with_reasoning/2`. The models available to a session are the
316
+ **credentialed** ones from pi's catalog, each shown to the authoring agent with
317
+ its price (USD per 1M tokens, in/out) so it can pick the cheapest model that
318
+ fits — call the `models` tool for the live list. An unknown or unsigned-in model
319
+ fails with a clear error.
629
320
 
630
- Unlike traditional SDD where specs guide but don't control, DeepClause specs **become** the executable. The spec *is* the code—just at a higher abstraction level.
321
+ ### Sessions
631
322
 
632
- ## Compile and Run a Skill
323
+ The REPL also records sessions, turns, and harness versions under
324
+ `.deepclause/repl/`, so you can pick a conversation back up later. Its harness,
325
+ conversation memory, and turn count are restored:
633
326
 
634
327
  ```bash
635
- # Create a task description
636
- cat > .deepclause/tools/explain.md << 'EOF'
637
- # Code Explainer
638
-
639
- Explain what a piece of code does in plain English.
640
-
641
- ## Arguments
642
- - Code: The source code to explain
643
-
644
- ## Behavior
645
- - Break down the code into logical sections
646
- - Explain each section's purpose
647
- - Note any potential issues
648
- EOF
649
-
650
- # Compile to executable DML
651
- deepclause compile .deepclause/tools/explain.md
652
-
653
- # Run it
654
- deepclause run .deepclause/tools/explain.dml "function fib(n) { return n < 2 ? n : fib(n-1) + fib(n-2) }"
655
-
656
- # Or trigger skill creation directly from the TUI with:
657
- # /compile <spec>
658
- # /skill-creator <spec>
659
- # Or update the configured model selection from the TUI with:
660
- # /set-model openai:gpt-4.1 --slot run
661
- # Or run a direct workspace shell command with:
662
- # !npm test
328
+ deepclause repl --session last # resume the most recent session
329
+ deepclause repl --session repl_m9x1_1 # …or one by id
663
330
  ```
664
331
 
665
- Compilation now runs two security-oriented checks on the generated DML:
332
+ ### Why Prolog/DML for a self-modifying harness
666
333
 
667
- - Prolog static analysis for taint flow, dangerous tool usage, and capability extraction
668
- - An LLM security audit that reviews the generated DML and returns a short Markdown report
334
+ An RLM-style harness works best when the harness *is* the program the model
335
+ edits. DML makes that literal:
669
336
 
670
- The LLM audit runs by default for `deepclause compile`, `deepclause compile-all`, and one-shot `deepclause run -p ...`. Use `--no-audit` if you want to skip only the LLM review. Static analysis still runs either way.
337
+ - **The harness is data = code.** Skills are predicates, data is facts
338
+ (`city(ch, "Zürich").`). The model reads it (`listing`), queries it
339
+ (`/goal`), extends it, and reuses it — no separate plugin format and no
340
+ recompile step.
341
+ - **One language for logic and language.** Recursion, backtracking, and CLP
342
+ constraints sit next to LLM calls (`task/N`) and typed semantic judgments
343
+ (`choose`, `verify`, `rate`, `probability`) in the same clause.
344
+ - **Composable skills.** A `task/N` call runs a bounded agentic turn that may
345
+ itself call other skills, so the library grows by composition and reuse.
346
+ - **Small and inspectable.** Everything a harness can do is visible in the
347
+ module and the host tool catalog (by default `bash`, plus the human-in-the-loop
348
+ `ask_user` / `input/2`).
671
349
 
672
- ## Use Cases
350
+ ### Transactions
673
351
 
674
- ### Reliable tools for coding agents
352
+ A prompt turn is an **edit transaction**:
675
353
 
676
- Give your AI coding assistant more deterministic, inspectable tools instead of hoping prompts work:
354
+ 1. the living module is snapshotted;
355
+ 2. the authoring agent edits predicates with tools (`define`/`assert`/`assert_many`/
356
+ `retract`/`delete`) and tests them with `execute`;
357
+ 3. `end_turn` validates and commits the change, recording a version;
358
+ 4. `rollback` — or a failed turn — restores the harness unchanged.
677
359
 
678
- ```bash
679
- # Define a tool the agent can use
680
- cat > .deepclause/tools/api-docs.md << 'EOF'
681
- # API Documentation Lookup
682
- Search for API documentation and summarize usage patterns.
683
-
684
- ## Arguments
685
- - Query: The API or library name to look up
686
-
687
- ## Tools needed
688
- - web_search
689
-
690
- ## Behavior
691
- - Search for official documentation
692
- - Summarize usage patterns and examples
693
- EOF
694
-
695
- # Compile it once
696
- deepclause compile .deepclause/tools/api-docs.md
697
-
698
- # Now your coding agent can run it reliably
699
- deepclause run .deepclause/tools/api-docs.dml "Stripe PaymentIntent"
700
- ```
701
-
702
- The compiled `.dml` files execute the same way every time—no prompt variance, no skipped steps. Build up a library of tools your agent can trust.
360
+ For anything larger than a couple of predicates the agent is instructed to commit
361
+ working pieces as it goes (`execute` → `end_turn` → `begin_turn`), so a late
362
+ failure does not lose earlier progress.
703
363
 
704
- ### Automation pipelines
364
+ ### Auditability
705
365
 
706
- Chain compiled programs together:
366
+ Every session, turn, event trace, and harness version is written under
367
+ `.deepclause/repl/` — per harness under `harnesses/<name>/` (`harness.dml`,
368
+ `baseline.dml`, `HEAD.json`, `changes.jsonl`, `versions/`) — and exposed to DML
369
+ as queryable `harness_*` facts (`harness_session/5`, `harness_turn/5`,
370
+ `harness_change/5`, `harness_changed/4`, `harness_head/4`, `harness_trace/3`).
371
+ `rollback.` restores the previous version, step by step, and a harness can query
372
+ its own past:
707
373
 
708
- ```bash
709
- deepclause run review-code.dml src/handler.ts > review.md
710
- deepclause run summarize.dml review.md
374
+ ```prolog
375
+ recent_changes(N, Changes) :-
376
+ findall(Version-Timestamp, harness_change(Version, Timestamp, commit, _, _), All),
377
+ last_n(All, N, Changes).
711
378
  ```
712
379
 
713
- ### Shareable, versionable task logic
714
-
715
- Check `.dml` files into version control. The logic is inspectable—you can see exactly what the program does, not just what prompt it sends.
716
-
717
- ## Example Task Descriptions
380
+ See [`docs/REPL.md`](docs/REPL.md) and
381
+ [`docs/DML_REPL_SESSION_HISTORY.md`](docs/DML_REPL_SESSION_HISTORY.md).
718
382
 
719
- ### Web Research
720
- ```markdown
721
- # Web Research
722
- Search the web and synthesize findings into a report.
383
+ ### Commands
723
384
 
724
- ## Arguments
725
- - Question: The research question to investigate
385
+ `/goal <dml>`, `/listing [filter]`, `/viz [entry] [--spec]`, `/show <path>`,
386
+ `/gen <prompt>`, `/help`, `/reset`, `/rollback`, `/compact [notes]`,
387
+ `/export [file]`, `/model [id]`, `/freeze`/`/unfreeze`, `/params`,
388
+ `/trace`/`/notrace`, `/halt` (aliases `/exit`, `/quit`). The legacy
389
+ `goal:`/`listing.` dotted forms still work.
726
390
 
727
- ## Tools needed
728
- - web_search
391
+ ## Install
729
392
 
730
- ## Behavior
731
- - Search for 3-5 authoritative sources on the Question
732
- - Extract key findings from each
733
- - Write a summary with inline citations
393
+ ```bash
394
+ npm install deepclause-sdk
734
395
  ```
735
396
 
736
- ### Code Review
737
- ```markdown
738
- # Code Review
739
- Review code for bugs, security issues, and style.
740
-
741
- ## Arguments
742
- - FilePath: Path to the file to review
743
-
744
- ## Tools needed
745
- - vm_exec (to read files)
397
+ ## Quick start
746
398
 
747
- ## Behavior
748
- - Read the file at FilePath
749
- - Check for common bugs and anti-patterns
750
- - Identify security concerns
751
- - Suggest improvements
752
- - Be concise and actionable
399
+ ```bash
400
+ deepclause init # write .deepclause/config.json
401
+ deepclause login # sign in to provider, then pick a model
402
+ deepclause repl # interactive
403
+ deepclause repl --session last # resume the most recent session
404
+ deepclause run skill.dml "arg" # one-shot
753
405
  ```
754
406
 
755
- ### Data Analysis
756
- ```markdown
757
- # CSV Analyzer
758
- Analyze a CSV file and describe its contents.
759
-
760
- ## Arguments
761
- - FilePath: Path to the CSV file to analyze
407
+ ### Backends
762
408
 
763
- ## Tools needed
764
- - vm_exec (to run Python)
409
+ `pi` is the default: it reuses pi's model catalog and credential store. `env`
410
+ uses the SDK's own provider/API keys.
765
411
 
766
- ## Behavior
767
- - Load the CSV at FilePath with pandas
768
- - Describe the schema (columns, types, row count)
769
- - Identify interesting patterns
770
- - Generate summary statistics
412
+ ```bash
413
+ deepclause login [--provider <id>] [--api-key <key>|--oauth] [--model provider/model] [--thinking <level>]
414
+ deepclause logout [provider]
415
+ deepclause set-backend status
416
+ deepclause set-backend env # switch to provider API keys
771
417
  ```
772
418
 
773
- ## Available Tools
419
+ For reasoning-capable models, `deepclause login`/`set-backend`/`set-model` prompt
420
+ for a thinking level (`off|minimal|low|medium|high|xhigh|max`); pass `--thinking`
421
+ to skip the picker. It is stored as `backend.thinkingLevel` and forwarded to pi
422
+ only for models that support it.
774
423
 
775
- Common built-in runtime tools:
424
+ Credentials live in pi's agent dir (`~/.pi/agent`) unless `backend.agentDir`
425
+ overrides it. Existing pi installations stay untouched.
776
426
 
777
- | Tool | Description |
778
- |------|-------------|
779
- | `web_search` | Search the web using Brave Search (requires `BRAVE_API_KEY`) |
780
- | `news_search` | Search recent news |
781
- | `url_fetch` | Fetch a URL or save it into the workspace |
782
- | `bash` | Run shell commands in the active workspace shell |
783
- | `vm_exec` | Alias of `bash`; with `--sandbox`, runs in AgentVM |
427
+ ## run
784
428
 
785
- Some tools are runtime-role specific rather than globally available to every skill. For example:
786
-
787
- - the conductor adds tools such as `run_skill`, `create_skill`, and `update_memory`
788
- - the skill creator adds tools such as `list_skills`, `write_file`, `validate_dml`, `test_dml`, and `deploy_skill`
789
-
790
- Additional tools can come from configured MCP servers. Use `deepclause list-tools` to see the built-ins plus anything exposed by your configured MCP servers.
791
-
792
- ## CLI Reference
429
+ `run` uses the **same engine as the REPL**: it opens a module, loads the
430
+ DML file (`.dml` or a `.zip` bundle), runs one entry, and renders events through
431
+ the REPL renderer. The entry is `agent_main/N` (chosen by the number of
432
+ positional arguments) or an explicit `--goal`.
793
433
 
794
434
  ```bash
795
- deepclause init # Set up .deepclause/ folder
796
- deepclause compile <file.md> # Compile Markdown to DML
797
- deepclause compile-all <dir> # Compile all .md files in directory
798
- deepclause run <file.dml> [args] # Execute a compiled skill
799
- deepclause # Start the interactive conductor TUI
800
- deepclause -p <text> # Run one headless conductor turn
801
- deepclause list-commands # List available compiled skills
802
- deepclause list-tools # Show available tools
803
- deepclause show-model # Show gateway/run/compile slots
804
- deepclause set-model <model> # Change all slots or one slot with --slot
435
+ deepclause run <file.dml> [args...] # call agent_main/N
436
+ deepclause run <file.dml> --goal '<dml>' # explicit entry goal
437
+ deepclause run <file.dml> --dry-run # print the resolved entry
438
+ deepclause run <file.dml> --trace t.json --usage u.json
439
+ deepclause run <file.dml> --no-stream --no-events # only outputs/answers
805
440
  ```
806
441
 
807
- ### Run Options
442
+ ## Runtime and sandboxing
808
443
 
809
- ```bash
810
- deepclause run skill.dml "input" \
811
- --model google:gemini-2.5-flash \ # Override the run model for this execution
812
- --stream \ # Stream output
813
- --verbose \ # Show tool calls
814
- --workspace ./data \ # Set working directory
815
- --sandbox # Use AgentVM instead of the local shell
816
- ```
444
+ **Engine.** DML is executed by **SWI-Prolog compiled to WebAssembly**
445
+ (`vendor/swipl-wasm`, loaded through `src/prolog/`). It runs in-process — no
446
+ native Prolog install, no external server — with the standard SWI libraries
447
+ available (constraint solving via `clpfd`, `clpq`, `clpr`; plus regex, dicts,
448
+ and DCGs). Validation runs on the same engine.
817
449
 
818
- ### Compile Options
450
+ **Workspace confinement.** DML file predicates and `bash` all run against the
451
+ active **workspace** (`.` or `--workspace <path>`) using workspace-relative
452
+ paths; harness paths cannot escape it.
819
453
 
820
- `deepclause compile` and `deepclause compile-all` use the `compile` model slot. They accept `--model`, `--provider`, `--temperature`, `--max-attempts`, `--sandbox`, and `--no-audit`.
454
+ **Shell execution.** `bash` is the only capability tool, with two backends:
821
455
 
822
- Static analysis always runs. `--no-audit` disables only the LLM security audit.
456
+ | Backend | When | Notes |
457
+ |---|---|---|
458
+ | host shell | default | isolated by a wrapper: `clean-room`, `bwrap` (bubblewrap), or `sandbox-exec` (macOS); `auto` picks the best available |
459
+ | AgentVM | `--sandbox` | WASM micro-VM; network disabled by default |
823
460
 
824
- One-shot prompt mode uses the same compile pipeline before execution, so `deepclause run -p "..." --no-audit` disables the LLM audit there as well.
461
+ Network access is **off by default** (`agentvm.network: false`), and `bwrap`
462
+ with `shell.strictIsolation: true` also disables it. `--no-tools` registers no
463
+ capability tool at all; `ask_user` / `input/2` remain the human-in-the-loop
464
+ channel.
825
465
 
826
466
  ```bash
827
- deepclause compile skill.md \
828
- --model claude-sonnet-4-20250514 \
829
- --provider anthropic \
830
- --temperature 0.2 \
831
- --max-attempts 4
832
-
833
- deepclause compile-all ./specs \
834
- --model claude-sonnet-4-20250514 \
835
- --provider anthropic \
836
- --no-audit
467
+ deepclause repl --sandbox # run bash inside the AgentVM micro-VM
468
+ deepclause repl --no-tools # no capability host tools
837
469
  ```
838
470
 
839
- ## Configuration
840
-
841
- The main configuration surface is `.deepclause/config.json`.
842
-
843
- The most important fields are covered above in:
844
-
845
- - [Install and Run](#install-and-run)
846
- - [TUI Conductor](#tui-conductor)
847
- - [Model and Provider Configuration](#model-and-provider-configuration)
848
-
849
- Other useful config fields:
850
-
851
471
  ```json
852
472
  {
853
- "agentvm": {
854
- "network": false
855
- },
856
- "shell": {
857
- "wrapper": "auto",
858
- "strictIsolation": false
859
- },
860
- "compaction": {
861
- "enabled": true,
862
- "bindings": [
863
- {
864
- "name": "default-session",
865
- "scope": "session",
866
- "trigger": "before_user_message",
867
- "compactor": {
868
- "source": ".deepclause/system/default-session-compactor.dml",
869
- "sourceType": "file",
870
- "timeoutMs": 15000,
871
- "inheritTools": false
872
- }
873
- },
874
- {
875
- "name": "default-loop",
876
- "scope": "loop",
877
- "trigger": "before_model_call",
878
- "compactor": {
879
- "source": ".deepclause/system/default-loop-compactor.dml",
880
- "sourceType": "file",
881
- "timeoutMs": 15000,
882
- "inheritTools": false
883
- }
884
- }
885
- ]
886
- },
887
- "workspace": "./workspace",
888
- "dmlBase": ".deepclause/tools",
889
- "mcp": {
890
- "servers": {
891
- "filesystem": {
892
- "command": "npx",
893
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
894
- }
895
- }
896
- }
473
+ "agentvm": { "network": false },
474
+ "shell": { "wrapper": "auto", "strictIsolation": false }
897
475
  }
898
476
  ```
899
477
 
900
- - `agentvm.network` controls whether shell commands in `--sandbox` mode get outbound network access.
901
- - `shell.wrapper` chooses the host-shell isolation backend: `auto`, `clean-room`, `bwrap`, or `sandbox-exec`.
902
- - `shell.strictIsolation` requests stricter host execution. On Linux with `bwrap`, that disables network access with a separate network namespace.
903
- - `compaction.enabled` toggles the compaction system for session and loop memory.
904
- - `compaction.bindings` attaches DML compactors to runtime hook points such as `before_user_message` and `before_model_call`.
905
- - `workspace` sets the default working directory used by shell/file tools.
906
- - `dmlBase` changes where compiled local skills are written.
907
- - `mcp.servers` registers MCP servers that then appear in `deepclause list-tools`.
478
+ ## visualize
908
479
 
909
- ### Compaction Is Hackable
480
+ Turn a harness into a diagram: `visualize` reads the harness `listing`
481
+ (source + `doc/2` annotations) and asks the active model for a Mermaid chart of
482
+ one entry, then renders it.
910
483
 
911
- The default compaction bindings point at seeded DML files in `.deepclause/system/default-session-compactor.dml` and `.deepclause/system/default-loop-compactor.dml`. Those are ordinary workspace files, so you can edit them directly instead of treating compaction as a black box.
912
-
913
- At the moment, the packaged defaults are intentionally conservative: they skip compaction until the history is at least `8`/`12` messages and roughly `50000` estimated tokens for session/loop history respectively.
914
-
915
- For example, the default session compactor currently gates on:
916
-
917
- ```prolog
918
- should_skip_session_compaction(_MessageCount, EstimatedTokens) :-
919
- EstimatedTokens < 50000.
484
+ ```bash
485
+ deepclause visualize skill.dml -g router/2 --presentation -o router.png
486
+ deepclause visualize skill.dml -g router/2 --spec -o router.spec.svg
487
+ deepclause visualize skill.dml -g router/2 --ascii
920
488
  ```
921
489
 
922
- If you want compaction to kick in earlier or later, you have two straightforward options:
490
+ `-g/--goal` names the entry predicate to document. `--presentation` (default) is
491
+ an audience-facing overview (inputs, steps, answer); `--spec` shows engineering
492
+ detail (decisions, `task`/`exec` calls, branches, fallbacks). A `.mmd` output
493
+ writes the Mermaid source; `.svg`/`.png` render it **without a browser** (SVG is
494
+ generated directly, PNG via the bundled `@resvg/resvg-js` rasterizer), and the
495
+ `.mmd` is always written beside the image. `--ascii` prints a terminal-friendly
496
+ Unicode tree instead of a file.
923
497
 
924
- - Edit the seeded DML compactor files in `.deepclause/system/` and change the heuristics directly.
925
- - Repoint `compaction.bindings` in `.deepclause/config.json` to a different file, an inline compactor, or a binding with its own `model`, `provider`, `gasLimit`, `timeoutMs`, `inheritTools`, or `toolPolicy` settings.
498
+ In the REPL, `/viz [entry] [--spec]` draws a skill inline: on Kitty/Ghostty/
499
+ WezTerm/iTerm2 it emits an inline image (through pi-tui's terminal-image encoder);
500
+ on other terminals it falls back to the ASCII tree. Force a renderer with
501
+ `/viz --graphics=kitty|iterm2|ascii|off`. The authoring agent's `visualize` tool
502
+ uses the same path, so *"visualize this harness"* paints the image too (and
503
+ falls back to the ASCII tree on terminals without image support).
926
504
 
927
- ## Understanding DML
505
+ ## Media (images)
928
506
 
929
- The compiled `.dml` files use DML (DeepClause Meta Language), a dialect of Prolog designed for AI workflows.
507
+ Images are workspace files referenced by a `media(Path, Mime)` term; the bytes
508
+ never enter Prolog or conversation memory. Read a reference and attach it, and the
509
+ next `task/N` sends it to a vision-capable model:
930
510
 
931
511
  ```prolog
932
- % Generated from research.md
933
- tool(search(Query, Results), "Search the web") :-
934
- exec(web_search(query: Query), Results).
935
-
936
- agent_main(Topic) :-
937
- system("You are a research assistant..."),
938
- task("Research {Topic} and summarize findings."),
939
- answer("Done").
512
+ agent_main :-
513
+ read_media("photos/fox.png", Image),
514
+ attach_media(Image),
515
+ task("Describe the image in one sentence.", Description),
516
+ answer(Description).
940
517
  ```
941
518
 
942
- You can edit DML directly for fine-grained control. See the [DML Reference](./docs/DML_REFERENCE.md) for the full language spec.
943
-
519
+ Only PNG/JPEG/GIF/WebP/SVG are accepted, and judgments stay text-only.
944
520
 
945
- ### Backtracking: Automatic Retry Logic
946
-
947
- Prolog's backtracking means you can define multiple approaches. If one fails, execution automatically tries the next:
521
+ Images can also be **displayed** and **generated**:
948
522
 
949
523
  ```prolog
950
- % Try fast approach first, fall back to thorough approach
951
- agent_main(Question) :-
952
- system("Answer concisely."),
953
- task("Answer: {Question}"),
954
- validate_answer, % Fails if answer is inadequate
955
- answer("Done").
956
-
957
- agent_main(Question) :-
958
- system("Be thorough and detailed."),
959
- task("Research and answer: {Question}"),
960
- answer("Done").
524
+ output(media("charts/plot.png")). % show an image inline (kitty/iTerm2)
525
+ task("a red fox in snow", media(Img)), % generate → Img = "…/image-….png"
526
+ output(media(Img)). % …and show it
961
527
  ```
962
528
 
963
- If `validate_answer` fails, Prolog backtracks and tries the second clause. No explicit if/else needed. Backtracking resets the execution state (including LLM context) to the original choice point!
964
-
965
- ### Recursion: Processing Lists
966
-
967
- Handle variable-length inputs naturally:
968
-
969
- ```prolog
970
- % Process each file in a list
971
- process_files([]).
972
- process_files([File|Rest]) :-
973
- task("Review {File} for issues."),
974
- process_files(Rest).
975
-
976
- agent_main(Files) :-
977
- process_files(Files),
978
- answer("All files reviewed.").
979
- ```
529
+ `output(media{svg: Svg})` shows inline SVG; `save_image(Media, "out.svg")`
530
+ persists a reference. On other terminals the path is printed (and opened with
531
+ `xdg-open`/`open`), and `--json` emits a `media` event with base64 PNG data. In
532
+ the REPL: `/show <path>` and `/gen <prompt>`. See [`docs/DML_MEDIA.md`](docs/DML_MEDIA.md).
980
533
 
981
- ### Memory Isolation: Independent Sub-tasks
534
+ ## TypeScript SDK
982
535
 
983
- Use `prompt/N` for LLM calls that shouldn't share context:
536
+ ```ts
537
+ import { createDeepClause } from 'deepclause-sdk';
984
538
 
985
- ```prolog
986
- agent_main(Topic) :-
987
- system("You are a researcher."),
988
- task("Research {Topic} deeply.", Findings),
989
-
990
- % Independent critique - fresh context, no bias from main research
991
- prompt("As a skeptic, critique: {Findings}", Critique),
992
-
993
- % Back to main context
994
- task("Address this critique: {Critique}"),
995
- answer("Done").
539
+ const dc = await createDeepClause({ model: 'gpt-4o', provider: 'openai' });
540
+ for await (const event of dc.runDML(dmlSource, { args: ['topic'] })) {
541
+ if (event.type === 'answer') console.log(event.answer ?? event.content);
542
+ }
543
+ await dc.dispose();
996
544
  ```
997
545
 
998
- ### Tool Scoping: Controlled Capabilities
546
+ To reuse pi's model and credentials from a host, pass an injected `LLMBackend`
547
+ (`createPiBackend`) and judgment backends (`createLLMJudgeBackend`,
548
+ `createJevJudgeBackend`).
999
549
 
1000
- Limit what tools are available to specific sub-tasks:
550
+ The REPL is embeddable too:
1001
551
 
1002
- ```prolog
1003
- tool(dangerous_action(X, Result), "Do something risky") :-
1004
- exec(vm_exec(command: X), Result).
1005
-
1006
- agent_main(Task) :-
1007
- % Main task has all tools
1008
- task("Plan how to: {Task}", Plan),
1009
-
1010
- % Execute with restricted tools - no dangerous_action allowed
1011
- without_tools([dangerous_action], (
1012
- task("Execute this plan safely: {Plan}")
1013
- )),
1014
- answer("Done").
1015
- ```
1016
-
1017
- ### Composition: Building Blocks
1018
-
1019
- Define reusable predicates and compose them:
552
+ ```ts
553
+ import { createHarnessRepl } from 'deepclause-sdk';
1020
554
 
1021
- ```prolog
1022
- % Reusable building blocks
1023
- search_and_summarize(Query, Summary) :-
1024
- exec(web_search(query: Query), Results),
1025
- task("Summarize: {Results}", Summary).
1026
-
1027
- verify_facts(Text, Verified) :-
1028
- task("Fact-check this text: {Text}", Issues),
1029
- (Issues = "none" -> Verified = Text ; fix_issues(Text, Issues, Verified)).
1030
-
1031
- % Compose into a skill
1032
- agent_main(Topic) :-
1033
- search_and_summarize(Topic, Draft),
1034
- verify_facts(Draft, Final),
1035
- answer(Final).
555
+ const repl = await createHarnessRepl({ model: 'gpt-4o', provider: 'openai' });
556
+ for await (const event of repl.query('fact(5, F)')) {
557
+ if (event.type === 'solution') console.log(event.solution?.bindings);
558
+ }
559
+ await repl.dispose();
1036
560
  ```
1037
561
 
1038
- ### Shared Predicates Across DML Files
1039
-
1040
- When a skill grows beyond one file, move reusable predicates into helper files and load them at the top of the main DML. This is useful for shared search helpers, validation predicates, common formatting logic, or domain-specific utilities that multiple skills reuse.
562
+ ## Validation
1041
563
 
1042
- ```prolog
1043
- % .deepclause/tools/repo-review/helpers/search_helpers.dml
1044
- normalize_query(Query, Normalized) :-
1045
- format(string(Normalized), "site:github.com ~w", [Query]).
1046
-
1047
- search_and_summarize(Query, Summary) :-
1048
- normalize_query(Query, Normalized),
1049
- exec(web_search(query: Normalized), Results),
1050
- task("Summarize these results: {Results}", Summary).
1051
- ```
564
+ ```ts
565
+ import { validateWithProlog } from 'deepclause-sdk/validate';
1052
566
 
1053
- ```prolog
1054
- % .deepclause/tools/repo-review.dml
1055
- :- use_module(library(lists)).
1056
- :- use_module(library(clpfd)).
1057
- :- consult('.deepclause/tools/repo-review/helpers/search_helpers.dml').
1058
-
1059
- agent_main(Topic) :-
1060
- search_and_summarize(Topic, Summary),
1061
- answer(Summary).
567
+ const { valid, errors, warnings } = await validateWithProlog(dmlSource);
1062
568
  ```
1063
569
 
1064
- - Use `:- use_module(library(...)).` for standard SWI-Prolog libraries such as `lists`, `clpfd`, `clpq`, and `clpr`.
1065
- - Use `:- consult('workspace-relative/path.dml').` for local shared DML helpers inside the workspace.
1066
- - Local `:- use_module('.deepclause/tools/repo-review/helpers/search_helpers.dml').` also works as a convenience alias, but today it has consult-style loading semantics rather than full SWI module export filtering.
1067
- - When a helper belongs to one skill, keep it in a dedicated subfolder such as `.deepclause/tools/<skill-slug>/helpers/` so the skill and its shared predicates stay together.
1068
-
1069
- ## Using as a Library
1070
-
1071
- Embed DeepClause in your own applications:
1072
-
1073
- ```typescript
1074
- import { createDeepClause } from 'deepclause-sdk';
570
+ ## Configuration
1075
571
 
1076
- const dc = await createDeepClause({
1077
- model: 'gpt-4o',
1078
- apiKey: process.env.OPENAI_API_KEY,
1079
- });
572
+ `.deepclause/config.json` (created by `init`):
1080
573
 
1081
- for await (const event of dc.runDML(code)) {
1082
- console.log(event.type, event.content);
574
+ ```json
575
+ {
576
+ "backend": { "kind": "pi", "model": "anthropic/claude-sonnet-4" },
577
+ "temperatures": { "run": 0.7 },
578
+ "providers": { "openai": { "apiKey": "..." } },
579
+ "agentvm": { "network": false },
580
+ "shell": { "wrapper": "auto", "strictIsolation": false, "timeoutMs": 0, "idleTimeoutMs": 180000 },
581
+ "repl": {
582
+ "tui": "auto",
583
+ "harness": "main",
584
+ "showReasoning": "summary",
585
+ "maxModelCalls": 100,
586
+ "compaction": { "enabled": true, "auto": true },
587
+ "media": { "dir": ".deepclause/media", "open": true, "inlineJson": true, "imageModel": "openai:gpt-image-1" },
588
+ "history": { "enabled": true, "dir": ".deepclause/repl", "trace": "summary" }
589
+ },
590
+ "judgment": { "default": "llm", "jev": { "enabled": false } }
1083
591
  }
1084
-
1085
- await dc.dispose();
1086
592
  ```
1087
593
 
1088
- See [sdk-examples/](./sdk-examples/) for more.
594
+ ## Repository layout
1089
595
 
1090
- ## More Resources
596
+ ```text
597
+ src/
598
+ ├── repl/ # living-module REPL (session, agent, render, history, media, models)
599
+ ├── cli/ # init, run, repl, login, set-backend, visualize
600
+ ├── visualize/ # diagrams: Mermaid → Unicode tree / SVG / PNG + terminal graphics
601
+ ├── system/ # shell/AgentVM, config, model database + catalog, bundled docs
602
+ ├── judge/ # semantic judgment backends (llm, jev, mock)
603
+ ├── prolog/ # SWI-Prolog-WASM loader/bridge
604
+ ├── prolog-src/ # deepclause_mi.pl, deepclause_analysis.pl, …
605
+ ├── agent.ts # task/agent loop
606
+ ├── runner.ts # DML execution
607
+ ├── sdk.ts # createDeepClause
608
+ └── validate.ts # DML validation/linting
609
+
610
+ vendor/
611
+ └── swipl-wasm/ # SWI-Prolog compiled to WebAssembly (the DML engine)
612
+ ```
613
+
614
+ Bundled prompt assets: `AGENT_PROMPT.md` (the authoring agent's contract),
615
+ `DML_REFERENCE.md` (language), `DML_AUTHORING.md` (guide),
616
+ `HARNESS_EXAMPLES.md` (idiomatic shapes), `HARNESS_PATTERNS.md` (harness shapes
617
+ by use case), `PROLOG_SNIPPETS.md` (tested building blocks).
618
+
619
+ ## Development
1091
620
 
1092
- - [DML Reference](./docs/DML_REFERENCE.md) - Full language documentation
1093
- - [Examples](./dml-examples/) - Sample DML programs
1094
- - [Architecture](./ARCHITECTURE.md) - How it works
621
+ ```bash
622
+ npm run build # tsc + copy prolog + assets
623
+ npm test # vitest
624
+ npm run repl # deepclause repl via tsx
625
+ ```
626
+
627
+ See [`docs/`](docs/): [`STATUS.md`](docs/STATUS.md) (current state),
628
+ [`REPL.md`](docs/REPL.md),
629
+ [`DML_REPL_PROPOSAL.md`](docs/DML_REPL_PROPOSAL.md),
630
+ [`DML_REPL_SESSION_HISTORY.md`](docs/DML_REPL_SESSION_HISTORY.md),
631
+ [`DML_MEDIA.md`](docs/DML_MEDIA.md),
632
+ [`DML_MODEL_SWITCHING.md`](docs/DML_MODEL_SWITCHING.md),
633
+ [`DML_REPL_WORKER_EXECUTION.md`](docs/DML_REPL_WORKER_EXECUTION.md) (plan),
634
+ [`JUDGMENT_BACKENDS.md`](docs/JUDGMENT_BACKENDS.md).
1095
635
 
1096
636
  ## License
1097
637