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/docs/SERVE.md ADDED
@@ -0,0 +1,664 @@
1
+ # Serve a Work harness over HTTP
2
+
3
+ `deepclause serve` hosts **one validated Work harness**, with multiple independent
4
+ server-owned conversations and a bundled web interface. The client reuses the
5
+ DeepClause web project's warm-grey/teal theme, logo, Work navigation and fonts;
6
+ it adds responsive navigation/process drawers and safe Markdown/code rendering. It never exposes Develop,
7
+ arbitrary goals, compilation, or a remote file editor.
8
+
9
+ Agent shells can declare DML `on_start`/`on_message` hooks with persistent explicit
10
+ state and editable model-facing memory. Direct hook replies bypass the outer
11
+ assistant; `continue` retains the normal assistant and its declared `run_workflow`
12
+ tool. Manual workflow runs do not invoke agent hooks. See
13
+ [`WORK_MODE.md`](WORK_MODE.md#stateful-dml-agent-hooks) and
14
+ [`../sdk-examples/hooked-agent.dml`](../sdk-examples/hooked-agent.dml).
15
+
16
+ ## Quick start
17
+
18
+ Build from source once (`npm run build`), then:
19
+
20
+ ```bash
21
+ deepclause serve writing.dml
22
+ # From this checkout: node dist/cli/index.js serve writing.dml
23
+ ```
24
+
25
+ Open the printed URL, including its `#token=…` fragment. The client moves the token
26
+ into tab-local session storage and removes the fragment. The fragment is not sent
27
+ in HTTP requests. Treat the printed URL as a secret.
28
+
29
+ The default model backend is pi: existing model selection, credentials and model
30
+ catalog are reused; the server does not request keys or change provider environment
31
+ variables. Explicit `--model` and `--thinking` overrides are available. Environment
32
+ provider credentials can be used with `--backend env --model openai:gpt-4o`.
33
+ Pure workflows need no credentials with `--backend env`.
34
+
35
+ ```bash
36
+ # Reuse pi's existing authentication; select a provider/model explicitly:
37
+ deepclause serve writing.dml --model anthropic/claude-sonnet-4-20250514
38
+ # Or use existing environment-provider credentials:
39
+ deepclause serve writing.dml --backend env --model openai:gpt-4o-mini
40
+ ```
41
+
42
+ ### Model and reasoning settings
43
+
44
+ Three layers can set the model, and two can set reasoning. They compose in this
45
+ order, narrowest last:
46
+
47
+ 1. **Deployment (startup).** `--backend pi|env` and `--model`:
48
+ - pi: `--model provider/model` (for example `deepseek/deepseek-flash`);
49
+ - env: `--model provider:model` with credentials already in the environment.
50
+ `--thinking off|minimal|low|medium|high|xhigh|max` sets the default reasoning
51
+ level for the deployment. On pi it is validated against the chosen model and
52
+ dropped with a warning when unsupported; on `--backend env` it maps through
53
+ the bundled model database (effort, token budget or thinking config) and is
54
+ ignored with a warning when the model declares no reasoning support.
55
+ 2. **DML scope (`with_model/2`)** — `with_model("provider:model", Goal)`
56
+ switches one goal, including `#level` (`with_model("deepseek/deepseek-reasoner#high", Goal)`).
57
+ `provider/model` and `provider:model` are both accepted; the provider must
58
+ exist and have credentials. The scope applies to `task/N`, `prompt/N`,
59
+ `sample_token/N` and LLM-backed judgments.
60
+ 3. **DML scope (`with_reasoning/2`)** — `with_reasoning(Goal, Effort)` sets
61
+ `none|low|medium|high` for one goal. It now reaches both backends: pi maps it
62
+ onto the model's thinking level for those calls only, and the env backend
63
+ translates it into provider options. `none` disables thinking for the scope.
64
+
65
+ There is deliberately no server-wide live model switch: restart `serve` with a
66
+ different `--model`/`--thinking` for a new deployment default. Changing a saved
67
+ Agent's model or a published workflow's model is not a separate permission; the
68
+ server always uses its current model plus the DML scopes above. Startup prints
69
+ `Model: provider/model`; `/api/harness` and the UI footer expose that selection.
70
+ Explicitly continued conversations use the current server model and current tool
71
+ policy, not saved credentials or a stale model setting.
72
+
73
+ A minimal example:
74
+
75
+ ```prolog
76
+ uppercase(Text, Upper) :- string_upper(Text, Upper).
77
+
78
+ shell(_{
79
+ kind: agent,
80
+ system: "You are a concise writing assistant.",
81
+ welcome: "Ask about writing, or choose Uppercase.",
82
+ host_tools: [],
83
+ tools: [],
84
+ workflows: [_{name: "Uppercase", goal: "uppercase",
85
+ inputs: [_{name: "Text", type: string}],
86
+ outputs: [_{name: "Upper", type: string}]}]
87
+ }).
88
+ ```
89
+
90
+ Use `kind: workflow` for workflows without a chat assistant. An `agent_main` entry
91
+ is not required. Missing or invalid `shell/1` fails startup; helpers are never
92
+ implicitly exported. See [Work mode](./WORK_MODE.md) for types and semantics.
93
+
94
+ ## Configuration and workspace
95
+
96
+ ```bash
97
+ deepclause serve writing.dml --workspace ./project --port 8080
98
+ deepclause serve --harness writing --workspace ./project
99
+ deepclause serve --harness --workspace ./project # defaults to the main slot
100
+ ```
101
+
102
+ Choose a file **or** `--harness [name]`, not both. An explicit `.dml` file may
103
+ live anywhere inside the workspace, including `.deepclause/`. Real-path/symlink
104
+ containment still prevents loading source from outside the workspace.
105
+
106
+ Named slots are read from the standalone SDK's
107
+ `.deepclause/repl/harnesses/<name>/harness.dml` first, then
108
+ `.pi/deepclause/repl/harnesses/<name>/harness.dml` for compatibility. A HEAD-only
109
+ slot falls back to `HEAD.json` and its matching `versions/NNNN_*.json` module in
110
+ the same store. The standalone SDK store takes precedence if both contain a
111
+ source. Lookup is read-only: it does not initialize, migrate, or rewrite either
112
+ store, and source loading does not import standalone credentials/configuration.
113
+
114
+ For an existing standalone REPL workspace, either command works without copying:
115
+
116
+ ```bash
117
+ deepclause serve .deepclause/repl/harnesses/main/harness.dml
118
+ deepclause serve --harness main
119
+ ```
120
+
121
+ Serve runtime state and policy defaults remain under `.pi/deepclause/`; this
122
+ standalone source lookup does not change the pi extension's workspace layout.
123
+
124
+ Runtime defaults are read from `.pi/deepclause/config.json` through the shared
125
+ Work policy resolver (`repl.gasLimit`, `maxModelCalls`, `maxDepth`,
126
+ `providerConcurrency`, `compaction`). No configuration file is created/overwritten.
127
+
128
+ New serve state defaults to:
129
+
130
+ ```text
131
+ .pi/deepclause/serve/
132
+ server.lock
133
+ events.jsonl
134
+ diagrams/<artifact-id>.json # bounded SVG/Mermaid artifacts
135
+ sessions/<session-id>/
136
+ session.json
137
+ processes.json
138
+ trace.json # when captured
139
+ trace-<process-id>.json # when captured
140
+ history/ # SDK-owned snapshots and history
141
+ ```
142
+
143
+ `--state-dir` changes the root, which must remain inside the workspace. State
144
+ paths cannot be symlinked. New directories/files are created with private
145
+ permissions. A missing state-local `.gitignore` is seeded to ignore runtime data. Existing user documentation and DML files are not overwritten.
146
+ Each runtime has a distinct SDK history root, avoiding shared history/HEAD writers.
147
+ The main server is the sole event-journal/process-registry writer.
148
+
149
+ Startup captures a pinned **base deployment** snapshot. Fresh Work Agents start
150
+ from that snapshot, not another conversation's mutated facts. Editing its source
151
+ files does not change the base deployment. Separately, **Create workflow** opens a
152
+ Develop Agent: successful REPL commits atomically activate versioned workflows
153
+ without restarting serve. Running jobs and schedules retain their selected code
154
+ and asset revisions. Work Agents refresh only their external workflow catalog
155
+ between turns. See [Live workflows, schedules and files](SERVE_WORKFLOWS.md).
156
+
157
+ ## Sessions and processes
158
+
159
+ The sidebar separates **Agents**, **Workflows**, and **Runs**; the header also
160
+ opens **Schedules** and the button-hidden workspace **Files** browser:
161
+
162
+ - **New agent** asks for a name, optional additional system instructions, and
163
+ whether to allow incoming Agent/workflow messages. The instructions are
164
+ appended to the existing harness prompt, not substituted for it. Workflow-only
165
+ deployments can create restricted result-reviewing Agents without shell or
166
+ authoring tools. Agent conversations have a chat composer.
167
+ - **Agent settings** edits name/instructions and **Allow incoming messages**.
168
+ Multiple Agents can opt in independently; there is no workspace default or
169
+ per-run recipient grant. DML names its destination explicitly. Instruction
170
+ edits require an idle Agent; receiver permission is checked on every send. See [Agent management](SERVE_WORKFLOWS.md#agent-creation-settings-and-deletion).
171
+ - The trash button permanently deletes an Agent's private runtime/history/inbox/
172
+ traces/draft and shared-journal records, revokes its receiver permission and pauses
173
+ schedules targeting it. **Close** remains separate and retains saved history.
174
+ Published workflows and ordinary workspace files are not deleted.
175
+ - Clicking a workflow opens its input dialog and creates a **new, independent
176
+ workflow execution session** named after that workflow. It does not run inside
177
+ or interrupt the selected agent conversation. The workflow run has no composer;
178
+ status and typed result/outputs are also available in `session.workflow`.
179
+ - Completed workflow roots remain live when they may own processes. Explicitly
180
+ close unneeded runs to release a slot; closing stops their managed processes.
181
+ - Unless a user supplied a name, Agent titles are generated by the selected model after the first chat and every
182
+ third chat. It generates a purpose-based name and one-sentence summary. The naming
183
+ job has no tools, a 12-second timeout, at most 160 output tokens, and bounded
184
+ question/answer context. Naming usage is included in session
185
+ totals (`usage.source: session_title`). Failure falls back to the first question
186
+ and never fails the chat. A manual rename wins races and disables auto-naming
187
+ for that conversation. An untitled continued conversation is named from its
188
+ restored questions, without needing another chat first. Workflow naming never
189
+ makes an LLM call.
190
+ - **Info**, at the top right beside **Processes**, contains Assistant tools and
191
+ Host capabilities. Those sections are no longer shown in the sidebar. Assistant
192
+ tools are descriptive, not direct manual invocation controls; their diagram
193
+ buttons remain available in Info.
194
+
195
+ Each live session owns a root worker, its conversation, foreground operation,
196
+ input/forms and background process host. Workflow-only deployments do not create
197
+ an empty agent session at startup. Older workflow-only multi-run histories are
198
+ labelled as legacy workflow sessions, not resumable agent conversations.
199
+
200
+ - Switching sessions or disconnecting the browser does **not** stop execution.
201
+ - Foreground operations are serialized per session; different sessions can run
202
+ concurrently. Manual workflow starts call the exact named entry without an
203
+ assistant decision.
204
+ - Stop foreground cancels that operation. Stopping a selected process respects
205
+ existing process links. Closing a session explicitly stops all its processes.
206
+ - Sessions with services are never silently expired. Default maximum: 8 live
207
+ sessions. Close sessions explicitly to release slots.
208
+ - Provider concurrency is bounded across sessions (default 4). Each SDK process
209
+ host also has its existing live-process/mailbox limits.
210
+ - Default foreground wall-clock limit: 10 minutes (`--operation-timeout <ms>`).
211
+ Work gas defaults to 1,000,000; gas is not a universal native-call time limit.
212
+ - An operation that cannot acknowledge cancellation within 2 seconds triggers
213
+ root-worker termination. That session is marked interrupted; other sessions
214
+ continue. Host calls are brokered by the server so cancellation can reach them.
215
+ - Node's existing L2 worker hosts a session's processes together. If stopping one
216
+ requires hard termination, the whole session and sibling processes are marked
217
+ interrupted. The UI warns about this rather than claiming process-local hard
218
+ preemption.
219
+
220
+ The process panel shows states, activity, registered aliases, mailbox depth and
221
+ usage. Select a process for logs, follow-tail, saved log pages, and its trace.
222
+ Logs continue to be collected when the process/session is not selected.
223
+
224
+ ### Continue a saved agent conversation
225
+
226
+ Selecting saved history does not start execution. A compatible saved agent has
227
+ an editable composer: **send a message to continue**, with no separate Continue
228
+ button. The chat operation first restores the same session ID, durable SDK memory
229
+ and private harness state, then submits the new message. It works after explicit
230
+ Close, runtime interruption or a server restart. Workflows can start separate runs
231
+ while history is selected; diagrams do not require a live conversation. API clients
232
+ can optionally call `POST /api/sessions/:id/continue` to reopen without a new message.
233
+
234
+ Continuation requires the same deployment **program hash**, a valid saved snapshot,
235
+ and a free live-session slot. A file basename (`harness`) and a named slot (`main`)
236
+ may label the same program differently; this does not block continuation. The
237
+ original SDK history namespace is retained, so changing launch syntax cannot
238
+ silently lose conversation memory.
239
+
240
+ A genuinely different program is rejected rather than silently mixed with saved
241
+ state. Its history stays read-only, the UI explains the saved/current hashes, and
242
+ an enabled **New agent conversation** action is offered instead of a dead Continue
243
+ button. The current server model,
244
+ authentication and tool policy apply. Missing/corrupt saved process metadata is
245
+ reported rather than overwritten. A new conversation is the fallback when an
246
+ old deployment cannot be restored.
247
+
248
+ Executable snapshots must preserve clause order within each Prolog predicate.
249
+ Older builds with the source-view ordering defect could save reordered clauses,
250
+ breaking cut/fallback dispatch and coordinator reuse. Updating the SDK does not
251
+ repair those already-saved programs: redeploy the reviewed original source and
252
+ start a fresh Agent. Do not guess a new clause order or replay failed jobs as a
253
+ migration. Removing saved state is a separate, explicitly destructive action.
254
+
255
+ **Conversation continuation is not process recovery.** The UI/API explicitly list
256
+ previous interrupted process attempts: those managed processes stopped when the
257
+ old runtime ended and were **not restarted**. Old forms, input handles, mailboxes
258
+ and suspended execution continuations are not restored. The SDK also adds a
259
+ resume note to the agent's memory so it does not assume old services are alive.
260
+ New processes use a fresh PID namespace; old PIDs cannot address new processes.
261
+ External side effects/independently daemonized commands are not rolled back.
262
+
263
+ Workflow execution sessions remain inspectable history, not agent conversations;
264
+ start another workflow to create a fresh run. Merely opening a saved session never
265
+ restarts processes or replays a workflow.
266
+
267
+ ### Process definitions: restart-ready, not automatic restart
268
+
269
+ Each process has a stable logical ID and an attempt ID separate from its PID.
270
+ Before its body runs, the host awaits atomic persistence of a launch definition:
271
+ goal/options/snapshot, deployment identity, effective model, capability names and
272
+ limits. Failed registration prevents execution. Explicit Stop persists
273
+ `desiredState: stopped` before cancellation.
274
+
275
+ This version deliberately has **no process Restart action or automatic recovery**.
276
+ Saved sessions remain history until a new chat message or explicit API continuation
277
+ reopens them (agent only); no background
278
+ process is silently recreated. A future process restart can execute a saved definition
279
+ as a fresh attempt, subject to current policy and dependency checks. It is not
280
+ checkpoint/resume, and may repeat side effects. There is no exactly-once guarantee.
281
+
282
+ Live DML suspension has an explicit Resume action; merely viewing history never
283
+ executes a continuation. Forms/handles/mailboxes are not restored from event logs.
284
+
285
+ ## Traces and diagrams
286
+
287
+ Root and process traces come from actual SDK MI/tool traces, not inferred logs.
288
+ The SDK caps its internal trace store at 50,000 entries; HTTP captures expose at
289
+ most 10,000 entries and report partial/truncated status. The process host retains
290
+ traces for up to 50 completed children; serve also saves captures at process/turn
291
+ completion where available. If a busy engine cannot answer, return the last saved
292
+ capture with an explicit stale/partial note, or report unavailable. Trace contents
293
+ can include sensitive arguments/results.
294
+
295
+ Diagram buttons are available for declared workflows/tools. Generation makes an
296
+ explicit model call on a separate pinned, capability-free runtime, with usage
297
+ reported to the requesting session, including saved history. Global
298
+ `POST /api/diagrams` works even before a workflow-only deployment has any sessions;
299
+ without a session owner its usage is recorded in the server journal. Diagrams
300
+ always explain the current pinned deployment, not a different archived program.
301
+ Results are cached by deployment/entry/mode
302
+ for this server lifetime. One generation at a time is allowed, with cancellation.
303
+ Artifacts are stored separately from the journal (maximum 4 MiB), so replay
304
+ contains references rather than large SVG payloads. The UI displays SVG as an
305
+ image and offers Mermaid source. These are model-generated
306
+ explanations, not exact execution traces. No executable HTML miniapp bridge exists.
307
+
308
+ The UI renders sanitized Markdown with the same marked/DOMPurify stack as
309
+ DeepClause web. Code fences remain code; HTML applications, scripts, remote media
310
+ embeds and the `dc.call`/workspace bridges are never enabled. File
311
+ inputs are existing workspace-relative files, with real-path/symlink containment
312
+ checks for manual workflows and assistant-declared tools. File inputs offer an
313
+ upload or workspace picker, Files opens a bounded browser, and relative Markdown
314
+ file links, `download_file` and DML `output(file(Path))` produce authenticated
315
+ attachment ribbons. HTML is never executed on the Work origin. See the
316
+ [file policy and API](SERVE_WORKFLOWS.md#files-browser-picker-and-downloads).
317
+
318
+ ## Event journal
319
+
320
+ The JSONL file contains the same versioned envelope as the SSE feed:
321
+
322
+ ```json
323
+ {"v":1,"seq":42,"time":"2026-11-19T10:00:00Z","sessionId":"s_…","processId":"p_…","attemptId":"a_…","kind":"process_event","payload":{"type":"output","content":"Checked sources"}}
324
+ ```
325
+
326
+ Events are broadcast immediately and buffered in a memory ring capped at 2,000
327
+ events and 8 MiB. Disk appends are serialized, batched every 250 ms, 200 events or
328
+ 256 KiB, and flushed at turn end
329
+ and graceful shutdown. No per-event fsync: abrupt crashes/power loss can lose the
330
+ unflushed tail. The journal is not a transactional execution log.
331
+
332
+ At startup the file is scanned to recover sequence numbers and the recent buffer.
333
+ Malformed/incomplete records are diagnosed and skipped, and an incomplete final
334
+ line is terminated before appending. Writes that fail produce a persistence warning;
335
+ execution continues. Lost batches are not silently represented as durable.
336
+
337
+ Sensitive credential-shaped fields and the bearer token are redacted before
338
+ memory, broadcast and disk. Add text patterns with repeatable `--redact <regex>`.
339
+ This is not a guarantee of automatic secret detection. The executable process
340
+ registry/SDK snapshots are private recovery metadata, not redacted launch code.
341
+
342
+ Clients reconnect with a sequence cursor. Memory covers normal reconnects; JSONL
343
+ history supplies bounded older pages. A cursor gap requests snapshot/history
344
+ refresh. Large traces are separate captures; large strings are truncated in events.
345
+ The browser retains recent events and offers paged saved process logs.
346
+
347
+ No indexes, database, log rotation or automatic retention deletion are added.
348
+ Archive state while the server is stopped. Preserve sequence continuity if retaining
349
+ an active journal; archive the entire state directory for a clean deployment.
350
+ The ownership lock prevents two servers sharing a state directory. After a crash,
351
+ verify the recorded PID is not serving before manually removing `server.lock`.
352
+
353
+ ## HTTP API
354
+
355
+ API requests require `Authorization: Bearer <token>`. JSON action requests require
356
+ `Content-Type: application/json`; maximum body size is 256 KiB. No query-string
357
+ authentication or permissive CORS is supported.
358
+
359
+ The **API** header link opens `/api-docs`, a bundled documentation page generated
360
+ for the deployed harness. It reuses tab authentication and includes typed workflow
361
+ curl examples, continuation, processes, inputs/forms, traces, diagrams and SSE.
362
+ `GET /api/docs` returns the same discovery data, and `GET /api/openapi.json` returns
363
+ OpenAPI 3.1. The page can download that document. Examples use token placeholders;
364
+ no bearer secret is embedded in documentation responses.
365
+
366
+ | Method/path | Purpose |
367
+ |---|---|
368
+ | `GET /api/docs` / `GET /api/openapi.json` | Authenticated harness-specific docs / OpenAPI |
369
+ | `GET /api/harness` | Public Work interface, model/capabilities and persistence health |
370
+ | `GET /api/sessions` | Live and archived sessions |
371
+ | `POST /api/sessions` | New Agent `{title,additionalSystemPrompt,allowMessages}`; a name is required for workflow-only result-reviewing Agents |
372
+ | `POST /api/workflows/:name/runs` | New isolated workflow execution (`{ "inputs": {…} }`); returns 202, sessionId and operationId |
373
+ | `POST /api/sessions/:id/continue` | Explicit saved-agent continuation (`{}`); returns restored view and process-loss notice |
374
+ | `GET/PATCH/DELETE /api/sessions/:id` | Inspect/edit Agent settings; DELETE closes and retains history |
375
+ | `DELETE /api/sessions/:id?purge=true` | Permanently delete an Agent and its private records |
376
+ | `POST /api/sessions/:id/operations` | Agent chat / live suspension resume; legacy workflow starts remain compatible; returns 202 |
377
+ | `POST /api/sessions/:id/cancel` | Cancel the identified current operation |
378
+ | `POST /api/sessions/:id/inputs/:inputId` | Answer/cancel pending input |
379
+ | `POST /api/sessions/:id/forms/:formId` | Submit action, revision and values |
380
+ | `GET /api/sessions/:id/processes` | Current process table |
381
+ | `GET /api/sessions/:id/processes/:processId/logs` | Saved log events |
382
+ | `POST /api/sessions/:id/processes/:processId/stop` | Explicit process stop (`{}`) |
383
+ | `GET /api/sessions/:id/trace` | Root trace capture |
384
+ | `GET /api/sessions/:id/processes/:processId/trace` | Process trace capture |
385
+ | `POST /api/diagrams` | Generate/cache declared entry diagram; optional sessionId, no live session required |
386
+ | `POST /api/diagrams/jobs/:jobId/cancel` | Cancel global generation (`{}`) |
387
+ | `POST /api/sessions/:id/diagrams` | Compatibility route attributing generation to a live/saved session |
388
+ | `POST /api/sessions/:id/diagrams/:jobId/cancel` | Cancel generation (`{}`) |
389
+ | `GET /api/diagrams/:artifactId` | Read a saved diagram artifact |
390
+ | `GET /api/events?after=N` | Authenticated multiplexed SSE |
391
+ | `GET /api/events/history?after=N&limit=500` | JSONL replay; optional sessionId/processId filters |
392
+
393
+ Example for the minimal harness above (the running server's API page generates
394
+ commands for its **actual** declared workflows and input types):
395
+
396
+ ```bash
397
+ export BASE_URL='http://127.0.0.1:8080'
398
+ export DC_SERVE_TOKEN='paste-the-server-token-here'
399
+ curl -X POST "$BASE_URL/api/workflows/Uppercase/runs" \
400
+ -H "Authorization: Bearer $DC_SERVE_TOKEN" \
401
+ -H 'Content-Type: application/json' \
402
+ --data '{"inputs":{"Text":"hello"}}'
403
+ # Save sessionId from that response, then inspect status and typed outputs:
404
+ export SESSION_ID='s_...'
405
+ curl "$BASE_URL/api/sessions/$SESSION_ID" \
406
+ -H "Authorization: Bearer $DC_SERVE_TOKEN"
407
+ curl -N "$BASE_URL/api/events" \
408
+ -H "Authorization: Bearer $DC_SERVE_TOKEN"
409
+ ```
410
+
411
+ `session.kind` distinguishes `agent` / `workflow`; a run's name, status and actual
412
+ result are in `session.workflow`. A repeated workflow creates another session;
413
+ POSTing another workflow to an already-started execution session is rejected.
414
+
415
+ For compatibility, the old operation body
416
+ `{"kind":"workflow","name":"Uppercase","inputs":{"Text":"hello"}}`
417
+ can still run inside an agent session. New clients should use the dedicated
418
+ workflow-run endpoint rather than mix conversations and manual runs.
419
+
420
+ Chat body: `{"kind":"chat","text":"Help me write…"}`.
421
+ Resume body: `{"kind":"resume"}`.
422
+ Cancel body: `{"operationId":"…"}`.
423
+ Workflow success is determined by `workflow_result.result`, not merely an ended
424
+ stream. Do not automatically retry operations after network errors: effects may
425
+ already have happened.
426
+
427
+ ## Security and public exposure
428
+
429
+ This is for a **trusted operator, trusted harness and trusted users** sharing one
430
+ principal. A bearer token is not tenant isolation. Sessions have independent runtime
431
+ state, but share workspace files. Concurrent filesystem side effects require
432
+ harness-level coordination. No distributed writer leases are implemented.
433
+
434
+ **Bash is enabled by default in serve.** Existing DML `exec(bash(...), Result)`
435
+ and background processes can use it without another flag. To expose bash directly
436
+ to the Work assistant, declare `host_tools: [bash]` in `shell/1`. Both declaration
437
+ and host registration are required; undeclared tools are not exposed to the model.
438
+ The original host tool/approval wrapper, cancellation signal and SDK tool policy
439
+ are preserved. This does not expose arbitrary DML/authoring tools.
440
+
441
+ ```bash
442
+ deepclause serve writing.dml --no-tools # disable host capabilities
443
+ deepclause serve writing.dml --tools bash # explicit selection
444
+ deepclause serve writing.dml --sandbox --require-sandbox
445
+ ```
446
+
447
+ Only the supported `bash` capability is registered. **Info** reports whether
448
+ it is available to DML only, to the assistant as well, or disabled by the host.
449
+ Startup also prints the effective shell backend and whether it is sandboxed.
450
+ Without a sandbox, bash executes as your user account. Only serve trusted harnesses
451
+ to trusted users; use `--no-tools` when shell access is not needed.
452
+
453
+ `--sandbox` selects the **AgentVM Linux/WASM shell backend** for DML workflows,
454
+ background processes, and explicitly declared assistant bash tools. Each live
455
+ session lazily starts its own VM on its first bash call, mounts the workspace
456
+ read/write at `/workspace`, and disables guest networking by default. `--allow-network`
457
+ explicitly enables outbound VM TCP/UDP; `--no-allow-network` disables it. These
458
+ flags require `--sandbox`; they do not change a host shell's network policy.
459
+ Networking includes reachable host/private networks, not just the Internet. Model requests still
460
+ use the server's configured model backend, not guest networking. Bash calls within
461
+ one session share a command channel and are serialized; different sessions retain
462
+ independent VMs. Cancelling an active command or hitting its timeout resets that
463
+ VM and cancels pending commands rather than replaying them. Cancelling a queued
464
+ command does not interrupt another command. Saved processes are never restarted.
465
+ There is no fallback to an unsandboxed host shell if AgentVM fails to start.
466
+ `--no-tools` continues to disable bash even with `--sandbox`.
467
+
468
+ Work mode and worker isolation are not a security sandbox. `--require-sandbox`
469
+ fails if the effective shell boundary is unavailable; combine it with `--sandbox`
470
+ to select AgentVM explicitly. AgentVM/WASI is experimental, not a production
471
+ multi-tenant security boundary. Shell sandboxing does not isolate the HTTP server,
472
+ model provider, or all SDK operations. Native/workspace operations remain subject
473
+ to the SDK's existing boundaries and operator grants.
474
+
475
+ Default bind is loopback with a generated token. Explicit tokens must contain at
476
+ least 24 non-whitespace characters. Non-loopback always requires an explicit secret
477
+ and, by default, an expected public origin:
478
+
479
+ ```bash
480
+ export DC_SERVE_TOKEN='a-long-random-secret-at-least-24-characters'
481
+ deepclause serve writing.dml --host 0.0.0.0 \
482
+ --public-url https://work.example.com --token-env DC_SERVE_TOKEN
483
+ ```
484
+
485
+ ### Optional Host and Origin checks
486
+
487
+ Both checks are **enabled by default** and can be disabled independently:
488
+
489
+ - `--no-host-check` accepts requests addressed to other hostnames/IPs.
490
+ - `--no-origin-check` accepts a supplied `Origin` other than the canonical origin.
491
+ An absent Origin is already allowed for clients such as curl.
492
+
493
+ For a trusted deployment that needs access through multiple addresses:
494
+
495
+ ```bash
496
+ export DC_SERVE_TOKEN="$(openssl rand -hex 32)"
497
+ deepclause serve writing.dml --host 0.0.0.0 --port 8080 \
498
+ --token-env DC_SERVE_TOKEN --no-host-check --no-origin-check
499
+ ```
500
+
501
+ Choose a real hostname/IP in the browser, not `0.0.0.0`. `--public-url` is optional
502
+ only when **both** checks are disabled; when provided it remains the canonical
503
+ origin for startup links and API documentation. Disabling only one check leaves
504
+ the other enforced against that origin, so accepting alias Host headers alone
505
+ does not accept alias browser Origins on POST requests.
506
+
507
+ SDK callers use `startServe({ ..., hostCheck: false, originCheck: false })`.
508
+ These are startup options, not settings an Agent or HTTP client can change.
509
+ The CLI reports both states and warns when either check is disabled.
510
+
511
+ **This reduces DNS-rebinding/cross-origin protection.** Bearer authentication and
512
+ non-loopback token requirements are unchanged. It does not enable CORS, add
513
+ permissive preflight responses, relax CSP, grant sandbox/network access, or
514
+ remove the separate app-preview gateway checks. Use only on trusted networks
515
+ with trusted clients; prefer explicit origins and TLS for exposed deployments.
516
+
517
+ ### App previews on a public plain-HTTP deployment
518
+
519
+ When the Work origin is not loopback, previews need a name browsers can reach
520
+ the per-app ports through:
521
+
522
+ ```bash
523
+ deepclause serve app-agent.dml --host 0.0.0.0 --port 8080 \
524
+ --public-url http://laptop.example.ts.net:8080 --token-env DC_SERVE_TOKEN \
525
+ --sandbox --allow-network --allow-previews --preview-host laptop.example.ts.net
526
+ ```
527
+
528
+ `--preview-host` is the explicit opt-in. It only names the origin; the server
529
+ still owns the per-app ports, one-time launch, cookie authentication, request/
530
+ response limits and blocked redirects described below. The Work page's CSP
531
+ frames that host on any port, and each app keeps its own origin.
532
+
533
+ Requirements and limits:
534
+
535
+ - Every preview port range must be reachable by the browser (e.g. all ports on a
536
+ tailnet or private LAN). A normal reverse proxy that forwards only `:8080`
537
+ cannot reach them.
538
+ - The preview gateway binds the same address as `--host` (for example `0.0.0.0`),
539
+ so remote clients can connect. Restrict that with firewall rules when needed.
540
+ - Plain HTTP only. An `https` Work origin needs TLS for every preview port, i.e.
541
+ a per-app hostname/certificate; that mode is not implemented. Keep previews on
542
+ loopback behind such a proxy, or host them on a separate plain-HTTP interface.
543
+ - Apps still must not be treated as trusted: keep the Work token out of them and
544
+ publish only what the VM is allowed to expose.
545
+ - Cookies are host-scoped, not port-scoped: the preview cookie lives on
546
+ `--preview-host`, the same host as the Work UI. It is HttpOnly and per-preview
547
+ random, and the Work UI authenticates with session storage rather than cookies.
548
+
549
+ ### Local VM app previews
550
+
551
+ ```bash
552
+ deepclause serve app-agent.dml --sandbox --allow-network --allow-previews
553
+ ```
554
+
555
+ This opt-in supports loopback Work deployments by default, and remote plain-HTTP
556
+ deployments through `--preview-host <hostname>` (see above). Start an app bound to
557
+ `0.0.0.0` inside the session VM, then
558
+ publish its guest port in **Apps**, through the authenticated API, or from trusted
559
+ DML using `exec(bash(previewPort:3000), Result)`. Host bash tools expose this field
560
+ only when previews are enabled. To unpublish use
561
+ `exec(bash(closePreviewPort:3000), Result)`. Do not combine app actions with
562
+ `command`/`argv`. Publication is not a readiness check or a server launch.
563
+
564
+ Each app gets its own ephemeral HTTP origin (loopback by default), never a path
565
+ on the authenticated Work origin, so app code cannot read the Work UI's token,
566
+ cookies or storage. **Apps → Open preview**
567
+ mints a one-use URL (60-second validity) and establishes a session-lifetime
568
+ HttpOnly/SameSite cookie before loading the app. Never send the Work bearer token
569
+ to that origin. The proxy drops browser Authorization/Cookie and app Set-Cookie
570
+ headers; app HTML never executes on the Work origin. The sandboxed iframe has no
571
+ SDK bridge, top navigation/popups, service workers or external browser network
572
+ access. Root-relative assets and HTTP APIs work; WebSockets/HMR, CDN assets,
573
+ public publishing and remote/reverse-proxy previews are not supported yet.
574
+
575
+ Ports are integers 1024..65535, at most three per session; clients cannot choose
576
+ arbitrary target hosts or host bind ports. The internal TCP forward always binds
577
+ the gateway's loopback; the preview gateway itself listens on loopback unless
578
+ public hosting is enabled. Local OS processes can access loopback: this is not
579
+ multi-user/tenant isolation. Requests are bounded to 1 MiB, responses to 16 MiB,
580
+ and proxy idle timeouts to 30 seconds. External redirects are rejected.
581
+
582
+ Close publication to revoke its listeners/connections; it does not kill the guest
583
+ server process. Session close/interruption, VM reset and serve shutdown revoke all
584
+ previews. No app process or port forward is restored/replayed. Starting an app
585
+ with `... >/tmp/app.log 2>&1 </dev/null &` keeps its console output out of the
586
+ programmatic shell channel; inspect the log and actual HTTP response for readiness.
587
+
588
+ API (all require normal Work bearer authentication):
589
+
590
+ - `GET /api/sessions/{id}/previews`
591
+ - `POST /api/sessions/{id}/previews` with `{"port":3000}`
592
+ - `POST /api/sessions/{id}/previews/3000/launch` with `{}`
593
+ - `DELETE /api/sessions/{id}/previews/3000`
594
+
595
+ ### Binding to a specific address or LAN
596
+
597
+ `--host` and `--port` control the listening socket independently of the expected
598
+ browser origin. Defaults: `--host 127.0.0.1 --port 8080`.
599
+
600
+ ```bash
601
+ # Another local port:
602
+ deepclause serve writing.dml --host 127.0.0.1 --port 9090
603
+ # IPv6 loopback:
604
+ deepclause serve writing.dml --host ::1 --port 9090
605
+
606
+ # All IPv4 interfaces; replace the example LAN IP with this machine's address:
607
+ export DC_SERVE_TOKEN="$(openssl rand -hex 32)"
608
+ deepclause serve writing.dml --host 0.0.0.0 --port 9090 \
609
+ --public-url http://192.168.1.50:9090 --token-env DC_SERVE_TOKEN
610
+ ```
611
+
612
+ Use a specific interface IP instead of `0.0.0.0` to bind only that interface.
613
+ Open the printed public URL; `0.0.0.0` is a bind address, not a browser destination.
614
+ Non-loopback bindings always require an explicit token; a public origin is also
615
+ required unless both request checks are explicitly disabled as described above.
616
+ Plain HTTP exposes the token to
617
+ the network: use it only on a trusted LAN, or use HTTPS via a reverse proxy.
618
+ The CLI prints the actual listening address/port separately from the public URL.
619
+
620
+ Use a TLS reverse proxy that preserves the public Host, disables buffering for
621
+ SSE, and allows long-lived event responses. Enabled Host/Origin checks are exact. No provider
622
+ credentials are sent to the browser; no login or arbitrary RPC endpoint exists.
623
+
624
+ ## Development checks
625
+
626
+ ```bash
627
+ npm run test:serve # builds worker/assets, then focused tests
628
+ npm run smoke:serve # Node >=22 + Google Chrome; CHROME overrides binary
629
+ npm run smoke:previews # real AgentVM app + Chrome isolation/cleanup checks
630
+ DC_TEST_AGENTVM=1 npx vitest run tests/serve-previews-vm.test.ts
631
+ npm test
632
+ npm run check:runtime
633
+ ```
634
+
635
+ The SDK package includes UI assets and workers. No sibling web checkout, browser
636
+ WASM/Pyodide installation or frontend development server is needed at runtime.
637
+
638
+ ## Agent inbox and headless subagent results
639
+
640
+ Agent shells can opt into `inbox: _{sources:[process]}` (Work contract 3). A declared
641
+ Work tool/hook captures `agent_self(Main)` and passes it to a child; the child uses
642
+ `agent_post(Main, message{text:Text, data:result{...}}, Id)`. Serve's session worker
643
+ queues the message durably, then schedules the ordinary hook/assistant turn through
644
+ its server-owned operation machinery. No SSE connection or browser is required.
645
+ The transcript labels the process sender; returning users see responses and unread
646
+ background counts. Human/tool approvals still wait for explicit input.
647
+
648
+ The inbox status panel provides Pause/Resume background. Pausing holds subsequent
649
+ messages; Stop cancels the current operation. Authenticated live-session control:
650
+ `POST /api/sessions/{id}/inbox` with `{"action":"pause"}` or
651
+ `{"action":"resume"}`. No API allows arbitrary cross-session posting. Limits,
652
+ checkpoint failures and hook errors pause delivery instead of silently retrying.
653
+ On server restart, running messages are interrupted and pending data is held until
654
+ human activity or explicit resume. Processes/services are never restarted.
655
+
656
+ Try from the SDK checkout:
657
+
658
+ ```sh
659
+ deepclause serve sdk-examples/subagent-inbox.dml
660
+ ```
661
+
662
+ Ask for one or more self-contained background tasks. Workers are bounded and
663
+ intentionally have no host/browsing tools. See [the inbox contract](WORK_AGENT_INBOX.md)
664
+ and [implementation plan](WORK_AGENT_INBOX_PLAN.md) for details.