deepclause-sdk 0.0.88 → 0.1.0

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