deepclause-sdk 0.4.0 → 0.7.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 (301) hide show
  1. package/README.md +191 -2
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +159 -28
  5. package/dist/agent.js.map +1 -1
  6. package/dist/cli/agent-inbox.d.ts +25 -0
  7. package/dist/cli/agent-inbox.d.ts.map +1 -0
  8. package/dist/cli/agent-inbox.js +46 -0
  9. package/dist/cli/agent-inbox.js.map +1 -0
  10. package/dist/cli/config.d.ts +166 -156
  11. package/dist/cli/config.d.ts.map +1 -1
  12. package/dist/cli/config.js +3 -0
  13. package/dist/cli/config.js.map +1 -1
  14. package/dist/cli/index.d.ts +1 -1
  15. package/dist/cli/index.js +7 -2
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cli/login.d.ts +2 -1
  18. package/dist/cli/login.d.ts.map +1 -1
  19. package/dist/cli/login.js +15 -2
  20. package/dist/cli/login.js.map +1 -1
  21. package/dist/cli/repl.d.ts +61 -1
  22. package/dist/cli/repl.d.ts.map +1 -1
  23. package/dist/cli/repl.js +618 -67
  24. package/dist/cli/repl.js.map +1 -1
  25. package/dist/cli/run.d.ts +1 -0
  26. package/dist/cli/run.d.ts.map +1 -1
  27. package/dist/cli/run.js +3 -1
  28. package/dist/cli/run.js.map +1 -1
  29. package/dist/cli/serve.d.ts +3 -0
  30. package/dist/cli/serve.d.ts.map +1 -0
  31. package/dist/cli/serve.js +131 -0
  32. package/dist/cli/serve.js.map +1 -0
  33. package/dist/cli/set-backend.d.ts +2 -2
  34. package/dist/cli/set-backend.d.ts.map +1 -1
  35. package/dist/cli/set-backend.js +54 -8
  36. package/dist/cli/set-backend.js.map +1 -1
  37. package/dist/cli/work.d.ts +16 -0
  38. package/dist/cli/work.d.ts.map +1 -0
  39. package/dist/cli/work.js +45 -0
  40. package/dist/cli/work.js.map +1 -0
  41. package/dist/index.d.ts +9 -6
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4 -3
  44. package/dist/index.js.map +1 -1
  45. package/dist/judge/llm.d.ts.map +1 -1
  46. package/dist/judge/llm.js +9 -4
  47. package/dist/judge/llm.js.map +1 -1
  48. package/dist/judge/types.d.ts +10 -0
  49. package/dist/judge/types.d.ts.map +1 -1
  50. package/dist/judge/types.js.map +1 -1
  51. package/dist/prolog-src/deepclause_mi.pl +2791 -302
  52. package/dist/prolog-src/deepclause_strings.pl +36 -3
  53. package/dist/repl/agent-inbox.d.ts +73 -0
  54. package/dist/repl/agent-inbox.d.ts.map +1 -0
  55. package/dist/repl/agent-inbox.js +168 -0
  56. package/dist/repl/agent-inbox.js.map +1 -0
  57. package/dist/repl/agent.d.ts +19 -1
  58. package/dist/repl/agent.d.ts.map +1 -1
  59. package/dist/repl/agent.js +44 -13
  60. package/dist/repl/agent.js.map +1 -1
  61. package/dist/repl/auth.d.ts +6 -3
  62. package/dist/repl/auth.d.ts.map +1 -1
  63. package/dist/repl/auth.js +55 -5
  64. package/dist/repl/auth.js.map +1 -1
  65. package/dist/repl/backend.d.ts +30 -0
  66. package/dist/repl/backend.d.ts.map +1 -1
  67. package/dist/repl/backend.js +309 -14
  68. package/dist/repl/backend.js.map +1 -1
  69. package/dist/repl/compaction.d.ts +2 -0
  70. package/dist/repl/compaction.d.ts.map +1 -1
  71. package/dist/repl/compaction.js +9 -0
  72. package/dist/repl/compaction.js.map +1 -1
  73. package/dist/repl/event-history.d.ts +4 -0
  74. package/dist/repl/event-history.d.ts.map +1 -0
  75. package/dist/repl/event-history.js +36 -0
  76. package/dist/repl/event-history.js.map +1 -0
  77. package/dist/repl/harness-tools.d.ts +32 -18
  78. package/dist/repl/harness-tools.d.ts.map +1 -1
  79. package/dist/repl/harness-tools.js +127 -34
  80. package/dist/repl/harness-tools.js.map +1 -1
  81. package/dist/repl/history.d.ts +66 -5
  82. package/dist/repl/history.d.ts.map +1 -1
  83. package/dist/repl/history.js +174 -8
  84. package/dist/repl/history.js.map +1 -1
  85. package/dist/repl/index.d.ts +38 -5
  86. package/dist/repl/index.d.ts.map +1 -1
  87. package/dist/repl/index.js +32 -1
  88. package/dist/repl/index.js.map +1 -1
  89. package/dist/repl/process-backend.d.ts +1 -0
  90. package/dist/repl/process-backend.d.ts.map +1 -1
  91. package/dist/repl/process-executor.d.ts +4 -0
  92. package/dist/repl/process-executor.d.ts.map +1 -1
  93. package/dist/repl/process-executor.js +36 -1
  94. package/dist/repl/process-executor.js.map +1 -1
  95. package/dist/repl/process-worker.d.ts.map +1 -1
  96. package/dist/repl/process-worker.js +33 -8
  97. package/dist/repl/process-worker.js.map +1 -1
  98. package/dist/repl/processes.d.ts +14 -1
  99. package/dist/repl/processes.d.ts.map +1 -1
  100. package/dist/repl/processes.js +8 -2
  101. package/dist/repl/processes.js.map +1 -1
  102. package/dist/repl/reference.d.ts +31 -0
  103. package/dist/repl/reference.d.ts.map +1 -0
  104. package/dist/repl/reference.js +144 -0
  105. package/dist/repl/reference.js.map +1 -0
  106. package/dist/repl/render.d.ts +3 -1
  107. package/dist/repl/render.d.ts.map +1 -1
  108. package/dist/repl/render.js +20 -0
  109. package/dist/repl/render.js.map +1 -1
  110. package/dist/repl/session.d.ts +199 -27
  111. package/dist/repl/session.d.ts.map +1 -1
  112. package/dist/repl/session.js +1471 -219
  113. package/dist/repl/session.js.map +1 -1
  114. package/dist/repl/toolset.d.ts +8 -0
  115. package/dist/repl/toolset.d.ts.map +1 -1
  116. package/dist/repl/toolset.js +53 -4
  117. package/dist/repl/toolset.js.map +1 -1
  118. package/dist/repl/tui/autocomplete.d.ts.map +1 -1
  119. package/dist/repl/tui/autocomplete.js +5 -1
  120. package/dist/repl/tui/autocomplete.js.map +1 -1
  121. package/dist/repl/tui/renderer.d.ts +2 -1
  122. package/dist/repl/tui/renderer.d.ts.map +1 -1
  123. package/dist/repl/tui/renderer.js +23 -4
  124. package/dist/repl/tui/renderer.js.map +1 -1
  125. package/dist/repl/tui/status-bar.d.ts +5 -2
  126. package/dist/repl/tui/status-bar.d.ts.map +1 -1
  127. package/dist/repl/tui/status-bar.js +8 -3
  128. package/dist/repl/tui/status-bar.js.map +1 -1
  129. package/dist/repl/tui/tool-pane.d.ts +1 -1
  130. package/dist/repl/tui/tool-pane.d.ts.map +1 -1
  131. package/dist/repl/tui/tool-pane.js +13 -7
  132. package/dist/repl/tui/tool-pane.js.map +1 -1
  133. package/dist/repl/tui/work-view.d.ts +10 -0
  134. package/dist/repl/tui/work-view.d.ts.map +1 -0
  135. package/dist/repl/tui/work-view.js +28 -0
  136. package/dist/repl/tui/work-view.js.map +1 -0
  137. package/dist/repl/work-hooks.d.ts +29 -0
  138. package/dist/repl/work-hooks.d.ts.map +1 -0
  139. package/dist/repl/work-hooks.js +117 -0
  140. package/dist/repl/work-hooks.js.map +1 -0
  141. package/dist/repl/worker-host.d.ts +2 -0
  142. package/dist/repl/worker-host.d.ts.map +1 -1
  143. package/dist/repl/worker-host.js +48 -4
  144. package/dist/repl/worker-host.js.map +1 -1
  145. package/dist/repl/worker-protocol.d.ts +23 -2
  146. package/dist/repl/worker-protocol.d.ts.map +1 -1
  147. package/dist/repl/worker-protocol.js +1 -1
  148. package/dist/runner.d.ts +2 -2
  149. package/dist/runner.d.ts.map +1 -1
  150. package/dist/runner.js +69 -22
  151. package/dist/runner.js.map +1 -1
  152. package/dist/runtime-identity.json +10 -0
  153. package/dist/serve/agent-broadcast.d.ts +29 -0
  154. package/dist/serve/agent-broadcast.d.ts.map +1 -0
  155. package/dist/serve/agent-broadcast.js +28 -0
  156. package/dist/serve/agent-broadcast.js.map +1 -0
  157. package/dist/serve/agent-preferences.d.ts +16 -0
  158. package/dist/serve/agent-preferences.d.ts.map +1 -0
  159. package/dist/serve/agent-preferences.js +42 -0
  160. package/dist/serve/agent-preferences.js.map +1 -0
  161. package/dist/serve/api-docs.d.ts +61 -0
  162. package/dist/serve/api-docs.d.ts.map +1 -0
  163. package/dist/serve/api-docs.js +122 -0
  164. package/dist/serve/api-docs.js.map +1 -0
  165. package/dist/serve/backend.d.ts +12 -0
  166. package/dist/serve/backend.d.ts.map +1 -0
  167. package/dist/serve/backend.js +52 -0
  168. package/dist/serve/backend.js.map +1 -0
  169. package/dist/serve/capabilities.d.ts +6 -0
  170. package/dist/serve/capabilities.d.ts.map +1 -0
  171. package/dist/serve/capabilities.js +21 -0
  172. package/dist/serve/capabilities.js.map +1 -0
  173. package/dist/serve/example-agent.d.ts +5 -0
  174. package/dist/serve/example-agent.d.ts.map +1 -0
  175. package/dist/serve/example-agent.js +5 -0
  176. package/dist/serve/example-agent.js.map +1 -0
  177. package/dist/serve/files.d.ts +55 -0
  178. package/dist/serve/files.d.ts.map +1 -0
  179. package/dist/serve/files.js +249 -0
  180. package/dist/serve/files.js.map +1 -0
  181. package/dist/serve/harness.d.ts +3 -0
  182. package/dist/serve/harness.d.ts.map +1 -0
  183. package/dist/serve/harness.js +53 -0
  184. package/dist/serve/harness.js.map +1 -0
  185. package/dist/serve/previews.d.ts +40 -0
  186. package/dist/serve/previews.d.ts.map +1 -0
  187. package/dist/serve/previews.js +240 -0
  188. package/dist/serve/previews.js.map +1 -0
  189. package/dist/serve/protocol.d.ts +228 -0
  190. package/dist/serve/protocol.d.ts.map +1 -0
  191. package/dist/serve/protocol.js +2 -0
  192. package/dist/serve/protocol.js.map +1 -0
  193. package/dist/serve/schedules.d.ts +85 -0
  194. package/dist/serve/schedules.d.ts.map +1 -0
  195. package/dist/serve/schedules.js +249 -0
  196. package/dist/serve/schedules.js.map +1 -0
  197. package/dist/serve/server.d.ts +50 -0
  198. package/dist/serve/server.d.ts.map +1 -0
  199. package/dist/serve/server.js +1696 -0
  200. package/dist/serve/server.js.map +1 -0
  201. package/dist/serve/session-worker.d.ts +2 -0
  202. package/dist/serve/session-worker.d.ts.map +1 -0
  203. package/dist/serve/session-worker.js +291 -0
  204. package/dist/serve/session-worker.js.map +1 -0
  205. package/dist/serve/sessions.d.ts +178 -0
  206. package/dist/serve/sessions.d.ts.map +1 -0
  207. package/dist/serve/sessions.js +905 -0
  208. package/dist/serve/sessions.js.map +1 -0
  209. package/dist/serve/storage.d.ts +41 -0
  210. package/dist/serve/storage.d.ts.map +1 -0
  211. package/dist/serve/storage.js +211 -0
  212. package/dist/serve/storage.js.map +1 -0
  213. package/dist/serve/ui/api-docs.html +17 -0
  214. package/dist/serve/ui/api-docs.js +36 -0
  215. package/dist/serve/ui/app.js +958 -0
  216. package/dist/serve/ui/authoring.js +92 -0
  217. package/dist/serve/ui/deepclause-logo.png +0 -0
  218. package/dist/serve/ui/deepclause-mark.svg +1 -0
  219. package/dist/serve/ui/diff.js +16 -0
  220. package/dist/serve/ui/dompurify-LICENSE.txt +202 -0
  221. package/dist/serve/ui/features.css +15 -0
  222. package/dist/serve/ui/files.js +13 -0
  223. package/dist/serve/ui/ibm-plex-mono-latin.woff2 +0 -0
  224. package/dist/serve/ui/ibmplexmono-OFL.txt +93 -0
  225. package/dist/serve/ui/icons.js +30 -0
  226. package/dist/serve/ui/index.html +68 -0
  227. package/dist/serve/ui/manrope-OFL.txt +93 -0
  228. package/dist/serve/ui/manrope-latin.woff2 +0 -0
  229. package/dist/serve/ui/markdown.js +38 -0
  230. package/dist/serve/ui/marked-LICENSE.txt +44 -0
  231. package/dist/serve/ui/marked.js +88 -0
  232. package/dist/serve/ui/purify.js +2454 -0
  233. package/dist/serve/ui/style.css +249 -0
  234. package/dist/serve/ui/web-work.css +247 -0
  235. package/dist/serve/ui/web.css +1848 -0
  236. package/dist/serve/workflow-bundles.d.ts +8 -0
  237. package/dist/serve/workflow-bundles.d.ts.map +1 -0
  238. package/dist/serve/workflow-bundles.js +78 -0
  239. package/dist/serve/workflow-bundles.js.map +1 -0
  240. package/dist/serve/workflow-calls.d.ts +6 -0
  241. package/dist/serve/workflow-calls.d.ts.map +1 -0
  242. package/dist/serve/workflow-calls.js +13 -0
  243. package/dist/serve/workflow-calls.js.map +1 -0
  244. package/dist/serve/workflows.d.ts +93 -0
  245. package/dist/serve/workflows.d.ts.map +1 -0
  246. package/dist/serve/workflows.js +219 -0
  247. package/dist/serve/workflows.js.map +1 -0
  248. package/dist/system/assets/docs/AGENT_PROMPT.md +265 -3008
  249. package/dist/system/assets/docs/DML_AUTHORING.md +151 -291
  250. package/dist/system/assets/docs/DML_BASICS.md +93 -0
  251. package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
  252. package/dist/system/assets/docs/DML_FORMS.md +94 -728
  253. package/dist/system/assets/docs/DML_MEDIA.md +63 -0
  254. package/dist/system/assets/docs/DML_PROCESSES.md +124 -0
  255. package/dist/system/assets/docs/DML_PYTHON.md +74 -0
  256. package/dist/system/assets/docs/DML_REFERENCE.md +353 -2012
  257. package/dist/system/assets/docs/DML_SHELL.md +249 -0
  258. package/dist/system/assets/docs/DML_TASKS.md +119 -0
  259. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
  260. package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
  261. package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
  262. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
  263. package/dist/system/assets/index.d.ts +1 -1
  264. package/dist/system/assets/index.d.ts.map +1 -1
  265. package/dist/system/assets/index.js +7 -0
  266. package/dist/system/assets/index.js.map +1 -1
  267. package/dist/system/environment.d.ts +5 -1
  268. package/dist/system/environment.d.ts.map +1 -1
  269. package/dist/system/environment.js +20 -10
  270. package/dist/system/environment.js.map +1 -1
  271. package/dist/system/runtime/agentvm-manager.d.ts +12 -1
  272. package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
  273. package/dist/system/runtime/agentvm-manager.js +136 -20
  274. package/dist/system/runtime/agentvm-manager.js.map +1 -1
  275. package/dist/system/runtime/shell-manager.d.ts +4 -1
  276. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  277. package/dist/system/runtime/shell-manager.js +1 -1
  278. package/dist/system/runtime/shell-manager.js.map +1 -1
  279. package/dist/system/timezone.d.ts +20 -0
  280. package/dist/system/timezone.d.ts.map +1 -0
  281. package/dist/system/timezone.js +37 -0
  282. package/dist/system/timezone.js.map +1 -0
  283. package/dist/types.d.ts +85 -2
  284. package/dist/types.d.ts.map +1 -1
  285. package/dist/work/index.d.ts +92 -0
  286. package/dist/work/index.d.ts.map +1 -0
  287. package/dist/work/index.js +297 -0
  288. package/dist/work/index.js.map +1 -0
  289. package/docs/DEEP_RESEARCH_EXAMPLE.md +127 -0
  290. package/docs/SERVE.md +664 -0
  291. package/docs/WORK_AGENT_HOOKS_PLAN.md +416 -0
  292. package/docs/WORK_AGENT_INBOX.md +140 -0
  293. package/docs/WORK_AGENT_INBOX_PLAN.md +91 -0
  294. package/docs/WORK_MODE.md +269 -0
  295. package/package.json +35 -4
  296. package/sdk-examples/deep-research.dml +144 -0
  297. package/sdk-examples/deep-research.py +502 -0
  298. package/sdk-examples/hooked-agent.dml +49 -0
  299. package/sdk-examples/subagent-inbox.dml +66 -0
  300. package/src/prolog-src/deepclause_mi.pl +2791 -302
  301. package/src/prolog-src/deepclause_strings.pl +36 -3
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **Effortlessly build efficient model-, task-, or domain-specific harnesses.**
4
4
 
5
+ **Web app:** [web.deepclause.ai](https://web.deepclause.ai)
6
+
5
7
  Follow us on [X (@hilbertshelper)](https://x.com/hilbertshelper) · Blog: [deepclause.substack.com](https://deepclause.substack.com)
6
8
 
7
9
  DeepClause is a **Prolog-based runtime for self-modifying agent harnesses**. A
@@ -76,9 +78,87 @@ dependencies and as conceptual foundations.
76
78
  It is likely not worth it when a single prompt or a short script is enough, or
77
79
  when there is no structure you would want to reuse, review, or reproduce.
78
80
 
81
+ ## Develop and Work
82
+
83
+ DeepClause has two ways to use the same harness:
84
+
85
+ | | Develop | Work |
86
+ |---|---|---|
87
+ | Purpose | Author and edit the harness | Use the harness |
88
+ | Input | plain English, or `/goal <dml>` | chat with the declared tools, or run a declared workflow |
89
+ | Can change DML | yes, through transactional commits | no |
90
+ | Needs `shell/1` | no | yes |
91
+
92
+ **Develop is the default.** Describe a skill, tool, or change in plain English;
93
+ the authoring agent writes, tests, and commits it. **Work** is the stable,
94
+ non-authoring surface for a harness that is ready to use.
95
+
96
+ ### Work needs a shell
97
+
98
+ A harness becomes usable in Work when it declares a `shell/1` fact:
99
+
100
+ ```prolog
101
+ shell(_{
102
+ kind: agent,
103
+ system: "You are a concise writing assistant.",
104
+ host_tools: [],
105
+ tools: [
106
+ _{name: "text_length", goal: "length_of",
107
+ description: "Count characters in text.",
108
+ inputs: [_{name: "Text", type: string}],
109
+ outputs: [_{name: "N", type: integer}]}
110
+ ],
111
+ workflows: [
112
+ _{name: "Uppercase", goal: "uppercase",
113
+ inputs: [_{name: "Text", type: string}],
114
+ outputs: [_{name: "Upper", type: string}]}
115
+ ],
116
+ welcome: "Ask about text, or choose Uppercase."
117
+ }).
118
+ ```
119
+
120
+ - `kind: agent` gives a chat assistant that can call only the declared tools and
121
+ workflows. `kind: workflow` gives a workflow-only surface with no assistant.
122
+ - `tools` are declared DML tools; `host_tools` lists host capabilities the
123
+ harness may use (for example `bash`). Host grants and sandbox boundaries still
124
+ apply.
125
+ - Workflow inputs and outputs are typed. Missing or invalid inputs fail before
126
+ execution; a failed, cancelled, or suspended workflow is not success.
127
+ - A harness without `shell/1` has no Work interface. Open Develop or an explicit
128
+ Run instead.
129
+
130
+ ### Entering Work
131
+
132
+ In the TUI:
133
+
134
+ ```text
135
+ /mode work [harness] open a Work conversation
136
+ /workflows list declared workflows
137
+ /workflow "Uppercase" {"Text":"hello"} run exactly that workflow
138
+ /mode develop [harness] return to authoring
139
+ ```
140
+
141
+ From the CLI (assuming a harness named `example`):
142
+
143
+ ```bash
144
+ deepclause repl --mode work --harness example
145
+ deepclause repl --mode work --harness example \
146
+ --workflow "Uppercase" --inputs '{"Text":"hello"}' --json
147
+ ```
148
+
149
+ A manual `--workflow` run executes exactly that workflow and makes **zero
150
+ assistant calls**. An agent shell calls the model only when the conversation
151
+ needs it. Work and Develop are separate conversations with separate snapshots.
152
+ Work is pinned to the harness version it started with; to change the shell,
153
+ tools, or workflows, return to Develop (or open a fresh Work conversation after
154
+ the edit).
155
+
156
+ See [Work mode](docs/WORK_MODE.md) for the full contract and
157
+ [TUI/web reconciliation](docs/TUI_WEB_RECONCILIATION.md) for implementation status.
158
+
79
159
  ## The REPL: a living, self-modifying harness
80
160
 
81
- The REPL keeps a persistent DML module ("the harness"). You talk to it in two ways:
161
+ In default Develop mode, the REPL keeps a persistent DML module ("the harness"). You talk to it in two ways:
82
162
 
83
163
  | Input | Mode |
84
164
  |---|---|
@@ -478,6 +558,58 @@ overrides it. Existing pi installations stay untouched.
478
558
 
479
559
  ### Local models (Ollama, llama.cpp, vLLM)
480
560
 
561
+ #### llama.cpp (router or single-model)
562
+
563
+ When `llama-server` runs in **router mode** (started without `--model` or `-m`),
564
+ the `pi` backend registers pi's built-in `llama.cpp` provider and discovers its
565
+ models live. Point it at the router with `LLAMA_BASE_URL`, or sign in once:
566
+
567
+ ```bash
568
+ # one-off / environment-driven
569
+ export LLAMA_BASE_URL=http://127.0.0.1:8080
570
+ deepclause repl
571
+
572
+ # or persist the router URL + an optional API key and pick a default model
573
+ deepclause login --provider llama.cpp
574
+
575
+ # non-default host and port
576
+ deepclause login --provider llama.cpp --host 192.168.1.50 --port 9000
577
+ deepclause login --provider llama.cpp --base-url http://gpu-box:9000
578
+ deepclause set-backend pi --provider llama.cpp --host 192.168.1.50 --port 9000 \
579
+ --model llama.cpp/<id>
580
+ ```
581
+
582
+ `--base-url` wins over `--host`/`--port`; a bare `--host` defaults the port to
583
+ `8080`, and `--port` alone defaults the host to `127.0.0.1`. Passing an explicit
584
+ endpoint re-runs the login, so the stored router URL is updated. The interactive
585
+ login prompt also accepts a full URL, a bare `host`, or `host:port` when these
586
+ flags are omitted, and `--provider llama.cpp` may be omitted when one of these
587
+ endpoint flags is present. For a router that requires an API key, add
588
+ `--api-key <key>`; the URL is resolved from the explicit flags, then
589
+ `LLAMA_BASE_URL`, then `http://127.0.0.1:8080`.
590
+
591
+ Inside the REPL, `/login` lists `llama.cpp`. Selecting it prompts for a base
592
+ URL, a `host:port`, or a host and then a port. You can also pass the endpoint
593
+ directly:
594
+
595
+ ```text
596
+ /login llama.cpp --host 192.168.1.50 --port 9000
597
+ /login --base-url http://gpu-box:9000
598
+ ```
599
+
600
+ After `/login`, `/model` includes the models discovered by that login (the
601
+ choice still applies on the next start). Use `/model llama.cpp/<id>` to set the
602
+ default, or pass `--model llama.cpp/<id>` for this run. Start the router with
603
+ `--jinja` when you need tool calling for `task/N`.
604
+
605
+ Single-model mode also works: when `/models` does not return router metadata,
606
+ DeepClause falls back to `/v1/models` and registers the reported model. If the
607
+ server exposes neither a model id nor a model path, it uses the placeholder id
608
+ `local-model`. Use `models.json` if you need to pin an exact id for a server
609
+ that rejects arbitrary model names.
610
+
611
+ #### Other OpenAI-compatible endpoints (Ollama, vLLM)
612
+
481
613
  The default `pi` backend reads pi's `models.json`, which can declare **custom
482
614
  OpenAI-compatible providers**, so a local server needs no SDK changes:
483
615
 
@@ -505,7 +637,7 @@ OpenAI-compatible providers**, so a local server needs no SDK changes:
505
637
 
506
638
  ```bash
507
639
  deepclause set-backend pi --list # lists "loc (Local server) — configured [api-key]"
508
- # and the model "loc/lecho"
640
+ # and the model "loc/llama3.1"
509
641
  deepclause repl --model loc:llama3.1
510
642
  ```
511
643
 
@@ -551,6 +683,53 @@ deepclause run <file.dml> --trace t.json --usage u.json
551
683
  deepclause run <file.dml> --no-stream --no-events # only outputs/answers
552
684
  ```
553
685
 
686
+ ## Serve a Work harness
687
+
688
+ ```bash
689
+ deepclause serve writing.dml
690
+ # Pure workflows without model credentials:
691
+ deepclause serve writing.dml --backend env
692
+ ```
693
+
694
+ Open the printed token-bearing URL for the bundled Work interface. One pinned,
695
+ validated `shell/1` is served with multiple independent sessions, background
696
+ processes and logs, forms/input, traces and model-generated diagrams. Switching
697
+ sessions or disconnecting the browser does not stop execution. Agent conversations
698
+ have automatic titles and restore saved memory when you send a new message; manual workflow
699
+ starts create separate execution sessions named after their workflow. Continuation
700
+ never restarts old processes. Assistant tools and host capabilities live in the
701
+ **Info** modal beside **Processes**; **API** opens harness-specific curl/OpenAPI
702
+ documentation. Select the base model with `--model`, or load a stored slot with
703
+ `--harness [name]` (default `main`, from `.deepclause/repl` with
704
+ `.pi/deepclause/repl` fallback). The UI reuses
705
+ DeepClause web branding, styling and safe Markdown rendering. Bash is enabled for
706
+ DML by default (`--no-tools` disables it); `host_tools: [bash]` explicitly exposes
707
+ it to the Work assistant. **Create workflow** opens a separate Develop Agent with
708
+ guidance to discuss and agree a plan in the normal conversation before editing.
709
+ It uses existing REPL transactions and bounded tests with real host capabilities; commits activate versioned
710
+ workflows without a restart. Authors can discover and
711
+ reuse existing typed workflows with DML `run_workflow(Name, Inputs, Result)`;
712
+ root-turn revision pins, cancellation and cycle/depth/call limits apply. Drafts use
713
+ the configured real host capabilities, including Bash and live workflow calls;
714
+ external effects are not rolled back. Forms preserve field descriptions and typed defaults.
715
+ Run workflows manually or through bounded, explicitly enabled schedules,
716
+ and deliver results to another Agent's durable inbox. **Files** opens a workspace
717
+ browser; file forms support uploads/picking, and Agents/DML can present download
718
+ ribbons. There is no arbitrary raw-goal HTTP dispatch for Work. See
719
+ [live workflows, scheduling and files](docs/SERVE_WORKFLOWS.md). Use `--host` and
720
+ `--port` to select the listening interface; network exposure always requires an
721
+ explicit token and normally `--public-url`. Host and Origin validation are enabled
722
+ by default; opt out independently with `--no-host-check` and `--no-origin-check`.
723
+ Only disabling both makes `--public-url` optional. Authentication remains required,
724
+ and disabling checks does not enable CORS.
725
+
726
+ Serve state and its batched JSONL event journal live under
727
+ `.pi/deepclause/serve/`; no legacy workspace initialization is required. Stable
728
+ process/attempt IDs and saved launch definitions prepare for future restart;
729
+ this version never automatically restarts a process. Work mode is not a sandbox
730
+ or multi-tenant isolation. See [Serve](docs/SERVE.md) for configuration, API,
731
+ security boundaries and limitations.
732
+
554
733
  ## Runtime and sandboxing
555
734
 
556
735
  **Engine.** DML is executed by **SWI-Prolog compiled to WebAssembly**
@@ -577,9 +756,19 @@ channel.
577
756
 
578
757
  ```bash
579
758
  deepclause repl --sandbox # run bash inside the AgentVM micro-VM
759
+ deepclause repl --sandbox --allow-network # explicit outbound VM TCP/UDP
760
+ deepclause run skill.dml --sandbox --no-allow-network # override configured VM networking
580
761
  deepclause repl --no-tools # no capability host tools
581
762
  ```
582
763
 
764
+ `--allow-network` / `--no-allow-network` require `--sandbox` and override the
765
+ standalone run/REPL configuration; otherwise their existing `agentvm.network`
766
+ setting applies. Serve defaults to no guest network and does not import that
767
+ legacy configuration. For local HTTP apps, serve also offers opt-in
768
+ `--allow-previews` with a separate-origin **Apps** viewer; see
769
+ [VM app previews](docs/SERVE.md#local-vm-app-previews), including
770
+ [plain-HTTP public hosting](docs/SERVE.md#app-previews-on-a-public-plain-http-deployment).
771
+
583
772
  ```json
584
773
  {
585
774
  "agentvm": { "network": false },
package/dist/agent.d.ts CHANGED
@@ -50,6 +50,8 @@ export interface AgentLoopOptions {
50
50
  baseUrl?: string;
51
51
  providerOptions?: Record<string, Record<string, any>>;
52
52
  target?: ResolvedModel;
53
+ /** Task-scoped reasoning effort (`with_reasoning/2`), passed per call. */
54
+ reasoning?: string;
53
55
  };
54
56
  onOutput: (text: string) => void;
55
57
  onStream?: (chunk: string, done: boolean) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAIf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,QAAQ,EACT,MAAM,YAAY,CAAC;AAKpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAsC9E,MAAM,WAAW,gBAAgB;IAC/B,eAAe,E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C3D,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CACjE;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,mGAAmG;IACnG,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC,CAAC;CACtF;AAq5BD;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CA+wBtF"}
package/dist/agent.js CHANGED
@@ -306,16 +306,43 @@ function describeSchemaFields(typedVar) {
306
306
  const fields = typedVar.fields;
307
307
  if (!fields || fields.length === 0)
308
308
  return undefined;
309
- return fields
310
- .map((field) => {
311
- const notes = [field.type];
312
- if (field.required)
313
- notes.push('required');
314
- else if (field.default !== undefined)
315
- notes.push(`default ${JSON.stringify(field.default)}`);
316
- return `${field.name} (${notes.join(', ')})`;
317
- })
318
- .join(', ');
309
+ return fields.map(describeSchemaField).join(', ');
310
+ }
311
+ /** One field, including a nested schema's own fields. */
312
+ function describeSchemaField(field) {
313
+ const type = field.itemType ? `array<${field.itemType}>` : field.type;
314
+ const notes = [type];
315
+ if (field.required)
316
+ notes.push('required');
317
+ else if (field.default !== undefined)
318
+ notes.push(`default ${JSON.stringify(field.default)}`);
319
+ const head = `${field.name} (${notes.join(', ')})`;
320
+ return field.fields && field.fields.length > 0
321
+ ? `${head} {${field.fields.map(describeSchemaField).join(', ')}}`
322
+ : head;
323
+ }
324
+ /** The type text shown to the nested agent, including a declared schema's fields. */
325
+ function describeOutputType(variable) {
326
+ const base = variable.type === 'array' && variable.itemType
327
+ ? `array<${variable.itemType}>`
328
+ : variable.type;
329
+ const fields = describeSchemaFields(variable);
330
+ return fields ? `${base} {${fields}}` : base;
331
+ }
332
+ /**
333
+ * Match the `variable` argument of `set_result` to a requested output.
334
+ *
335
+ * Models occasionally omit it (providers differ in how they serialise an enum),
336
+ * and an empty name used to abort the whole task with `Unknown variable: `.
337
+ * With a single requested output the intent is unambiguous, so infer it; names
338
+ * are trimmed and compared case-insensitively, as `dict_field/3` does.
339
+ */
340
+ function matchOutputVar(vars, raw) {
341
+ const wanted = typeof raw === 'string' ? raw.trim() : '';
342
+ if (!wanted)
343
+ return vars.length === 1 ? vars[0] : undefined;
344
+ return vars.find((variable) => variable.name === wanted)
345
+ ?? vars.find((variable) => variable.name.toLowerCase() === wanted.toLowerCase());
319
346
  }
320
347
  /**
321
348
  * A declared schema is checked here as well as in the runtime, so the agent is
@@ -329,20 +356,53 @@ function validateSchemaFields(typedVar, value) {
329
356
  return null;
330
357
  if (!isPlainObject(value))
331
358
  return 'Expected an object value';
359
+ return validateFields(fields, value, '');
360
+ }
361
+ /** Validate a value against a field list, naming the nested path in the error. */
362
+ function validateFields(fields, value, prefix) {
363
+ if (!isPlainObject(value)) {
364
+ return prefix ? `Field "${prefix}" should be an object` : 'Expected an object value';
365
+ }
332
366
  const record = value;
333
367
  for (const field of fields) {
334
368
  const present = Object.prototype.hasOwnProperty.call(record, field.name)
335
369
  || Object.keys(record).some((key) => normaliseFieldKey(key) === normaliseFieldKey(field.name));
370
+ const path = prefix ? `${prefix}.${field.name}` : field.name;
336
371
  if (!present) {
337
372
  if (field.required)
338
- return `Missing required field "${field.name}"`;
373
+ return `Missing required field "${path}"`;
339
374
  continue;
340
375
  }
341
376
  const found = record[field.name] ?? Object.entries(record)
342
377
  .find(([key]) => normaliseFieldKey(key) === normaliseFieldKey(field.name))?.[1];
343
- if (!fieldTypeAccepts(field.type, found)) {
344
- return `Field "${field.name}" should be ${field.type}`;
378
+ const error = validateFieldValue(field, found, path);
379
+ if (error)
380
+ return error;
381
+ }
382
+ return null;
383
+ }
384
+ /** Validate one field value, recursing into a list element or nested schema. */
385
+ function validateFieldValue(field, value, path) {
386
+ if (field.itemType) {
387
+ if (!Array.isArray(value))
388
+ return `Field "${path}" should be array<${field.itemType}>`;
389
+ for (let index = 0; index < value.length; index += 1) {
390
+ const item = value[index];
391
+ if (field.fields && field.fields.length > 0) {
392
+ const nested = validateFields(field.fields, item, `${path}[${index}]`);
393
+ if (nested)
394
+ return nested;
395
+ }
396
+ else if (!fieldTypeAccepts(field.itemType, item)) {
397
+ return `Field "${path}[${index}]" should be ${field.itemType}`;
398
+ }
345
399
  }
400
+ return null;
401
+ }
402
+ if (!fieldTypeAccepts(field.type, value))
403
+ return `Field "${path}" should be ${field.type}`;
404
+ if (field.fields && field.fields.length > 0) {
405
+ return validateFields(field.fields, value, path);
346
406
  }
347
407
  return null;
348
408
  }
@@ -526,15 +586,21 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
526
586
  }];
527
587
  if (normalizedOutputVars.length > 0) {
528
588
  const resultTypes = normalizedOutputVars
529
- .map((variable) => `${variable.name}: ${variable.type}${variable.itemType ? `<${variable.itemType}>` : ''}`)
589
+ .map((variable) => `${variable.name}: ${describeOutputType(variable)}`)
530
590
  .join(', ');
531
591
  backendTools.push({
532
592
  name: 'set_result',
533
- description: `Set one requested output variable before calling finish. Required results: ${resultTypes}.`,
593
+ description: `Set one requested output variable before calling finish. Required results: ${resultTypes}. Call it once per variable; the value must match the declared type.`,
534
594
  parameters: {
535
595
  type: 'object',
536
596
  properties: {
537
- variable: { type: 'string', enum: requiredVarNames },
597
+ variable: {
598
+ type: 'string',
599
+ enum: requiredVarNames,
600
+ description: normalizedOutputVars.length === 1
601
+ ? `The output variable name: ${requiredVarNames[0]}.`
602
+ : `One of: ${requiredVarNames.join(', ')}.`,
603
+ },
538
604
  value: {
539
605
  anyOf: [
540
606
  { type: 'string' },
@@ -543,6 +609,7 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
543
609
  { type: 'array' },
544
610
  { type: 'object' },
545
611
  ],
612
+ description: `The value. Expected: ${resultTypes}.`,
546
613
  },
547
614
  },
548
615
  required: ['variable', 'value'],
@@ -580,6 +647,14 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
580
647
  { role: 'user', content: options.conversational ? options.taskDescription : `Subtask: ${options.taskDescription}` },
581
648
  ];
582
649
  const maxIterations = Math.max(1, Number(process.env.DC_MAX_ITERATIONS) || 1000);
650
+ // A nested agent that cannot satisfy `set_result`/`finish` used to retry until
651
+ // the whole turn's model-call budget was gone (100 calls in one observed run).
652
+ // The validation message is the useful part; repeating it does not help, so
653
+ // after a few rejected attempts the task fails with it.
654
+ let rejectedAttempts = 0;
655
+ const maxRejectedAttempts = 4;
656
+ let lastRejection;
657
+ let lastSetResultError;
583
658
  for (let iteration = 0; iteration < maxIterations && !state.finished; iteration++) {
584
659
  if (options.signal?.aborted)
585
660
  break;
@@ -597,6 +672,7 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
597
672
  temperature: options.modelOptions.temperature,
598
673
  maxTokens: options.modelOptions.maxOutputTokens,
599
674
  target: options.modelOptions.target,
675
+ reasoning: options.modelOptions.reasoning,
600
676
  signal: options.signal,
601
677
  onText: options.streaming && options.onStream
602
678
  ? (chunk) => {
@@ -654,12 +730,41 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
654
730
  }
655
731
  }
656
732
  else if (call.name === 'set_result') {
657
- const variableName = String(call.arguments.variable ?? '');
658
- const typedVar = normalizedOutputVars.find((variable) => variable.name === variableName);
733
+ // A provider can deliver a truncated tool call as `arguments: {}`. That
734
+ // is not a type error in the user's data: the value never arrived. Say
735
+ // so, and name the size problem, which is usually the cause.
736
+ const hasValue = Object.prototype.hasOwnProperty.call(call.arguments, 'value');
737
+ if (!hasValue) {
738
+ const typedVarNames = normalizedOutputVars.map((variable) => variable.name).join(', ') || 'none';
739
+ result = {
740
+ success: false,
741
+ error: `set_result received no "value" (the call arrived with no arguments). `
742
+ + `Expected outputs: ${typedVarNames}. The value may be too large for one tool call — `
743
+ + 'return a smaller object, or set the result in a script and return a path.',
744
+ };
745
+ messages.push({ role: 'tool', content: JSON.stringify(result), toolCallId: call.id, toolName: call.name });
746
+ rejectedAttempts += 1;
747
+ lastRejection = JSON.stringify(result);
748
+ lastSetResultError = lastRejection;
749
+ if (rejectedAttempts >= maxRejectedAttempts) {
750
+ throw new Error(`task protocol failed after ${maxRejectedAttempts} attempts: ${lastRejection}`);
751
+ }
752
+ continue;
753
+ }
754
+ const typedVar = matchOutputVar(normalizedOutputVars, call.arguments.variable);
755
+ const requested = typeof call.arguments.variable === 'string'
756
+ ? call.arguments.variable.trim()
757
+ : '';
659
758
  if (!typedVar) {
660
- result = { success: false, error: `Unknown variable: ${variableName}` };
759
+ result = {
760
+ success: false,
761
+ error: requested
762
+ ? `Unknown result variable "${requested}"; expected one of: ${requiredVarNames.join(', ')}.`
763
+ : `Missing "variable"; expected one of: ${requiredVarNames.join(', ')}.`,
764
+ };
661
765
  }
662
766
  else {
767
+ const variableName = typedVar.name;
663
768
  const value = coerceTypedResultValue(typedVar, call.arguments.value);
664
769
  const validationError = validateTypedResultValue(typedVar, value);
665
770
  if (validationError) {
@@ -707,6 +812,33 @@ async function runInjectedAgentLoop(options, normalizedOutputVars, combinedSyste
707
812
  toolCallId: call.id,
708
813
  toolName: call.name,
709
814
  });
815
+ // Count only rejections of the task protocol itself. A user tool that
816
+ // fails is the task's business and may be retried with a fixed argument.
817
+ const rejected = call.name === 'finish'
818
+ ? result.finished === false
819
+ : call.name === 'set_result'
820
+ ? result.success === false
821
+ : false;
822
+ if (rejected) {
823
+ rejectedAttempts += 1;
824
+ lastRejection = JSON.stringify(result);
825
+ if (call.name === 'set_result')
826
+ lastSetResultError = lastRejection;
827
+ }
828
+ else {
829
+ rejectedAttempts = 0;
830
+ }
831
+ if (rejectedAttempts >= maxRejectedAttempts) {
832
+ // `finish` is usually the last call, so quoting only it hides the
833
+ // `set_result` mistake that caused the loop. Report both and name the
834
+ // expected outputs.
835
+ const detail = [lastRejection, lastSetResultError && lastSetResultError !== lastRejection
836
+ ? `last set_result: ${lastSetResultError}`
837
+ : undefined].filter(Boolean).join('; ');
838
+ throw new Error(`task protocol failed after ${maxRejectedAttempts} attempts: ${detail}. `
839
+ + `Expected outputs: ${requiredVarNames.join(', ') || 'none'}. `
840
+ + 'Return them with `set_result` using the declared type, or explain what is missing.');
841
+ }
710
842
  }
711
843
  if (toolCalls.length === 0 && !state.finished) {
712
844
  if (options.conversational) {
@@ -789,11 +921,9 @@ export async function runAgentLoop(options) {
789
921
  // Add set_result tool for output variables
790
922
  if (normalizedOutputVars.length > 0) {
791
923
  const varNames = normalizedOutputVars.map(v => v.name);
792
- const typeSummary = normalizedOutputVars.map(v => {
793
- const renderedType = v.type === 'array' && v.itemType ? `array<${v.itemType}>` : v.type;
794
- const fields = describeSchemaFields(v);
795
- return fields ? `${v.name}: array of objects, each ${fields}` : `${v.name}: ${renderedType}`;
796
- }).join(', ');
924
+ const typeSummary = normalizedOutputVars
925
+ .map((variable) => `${variable.name}: ${describeOutputType(variable)}`)
926
+ .join(', ');
797
927
  const variableSchema = varNames.length === 1
798
928
  ? z.literal(varNames[0])
799
929
  : z.enum(varNames);
@@ -1484,10 +1614,7 @@ async function buildSystemPrompt(options) {
1484
1614
  const resultSection = normalizedOutputVars.length > 0
1485
1615
  ? [
1486
1616
  'You must set all named results before finishing successfully.',
1487
- ...normalizedOutputVars.map((variable) => {
1488
- const typeStr = variable.type === 'array' && variable.itemType ? `array<${variable.itemType}>` : variable.type;
1489
- return `- ${variable.name}: ${typeStr}`;
1490
- }),
1617
+ ...normalizedOutputVars.map((variable) => `- ${variable.name}: ${describeOutputType(variable)}`),
1491
1618
  ].join('\n')
1492
1619
  : 'No named result variables are required. Call finish(true) as soon as the subtask is complete.';
1493
1620
  const stallGuidance = [
@@ -1503,6 +1630,8 @@ async function buildSystemPrompt(options) {
1503
1630
  workspacePath: options.workspacePath,
1504
1631
  environment: options.environment,
1505
1632
  capabilityTool: options.capabilityTool,
1633
+ capabilityTools: [...options.tools.keys()],
1634
+ capabilityLabel: 'task capability tools (not additional DML host grants)',
1506
1635
  }) + describeCurrentTime());
1507
1636
  }
1508
1637
  const template = await readSystemPromptAsset('task', { workspacePath: options.workspacePath });
@@ -1515,6 +1644,8 @@ async function buildSystemPrompt(options) {
1515
1644
  workspacePath: options.workspacePath,
1516
1645
  environment: options.environment,
1517
1646
  capabilityTool: options.capabilityTool,
1647
+ capabilityTools: [...options.tools.keys()],
1648
+ capabilityLabel: 'task capability tools (not additional DML host grants)',
1518
1649
  }) + describeCurrentTime());
1519
1650
  }
1520
1651
  //# sourceMappingURL=agent.js.map