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
@@ -1,299 +1,159 @@
1
- # DML authoring guide (REPL)
2
-
3
- How to think about a REPL harness. For code, see `HARNESS_EXAMPLES.md` (idiomatic
4
- harness shapes) and `PROLOG_SNIPPETS.md` (tested building blocks).
5
-
6
- ## 0. What a harness is
7
-
8
- A harness is a **living library of reusable DML skills** for the workspace —
9
- not a single program. A skill is a predicate; name them descriptively and run
10
- them with `execute` (during a turn) or `/goal`. Skills are built from:
11
-
12
- - **helper predicates** (plain Prolog/CLP),
13
- - **semantic judgments** (`choose`/`rate`/`verify`/`probability`),
14
- - **host tools** via `exec/2`, and
15
- - **model calls** via `task/N` — a bounded agentic turn that may itself call
16
- other skills.
17
-
18
- The module is **data = code**: small/medium structured data belongs in it as
19
- facts (`country(ch, "Switzerland").`), inspected and queried exactly like
20
- predicates (`listing`, `/goal`, `execute`). Add data as facts when it is small
21
- enough to reason over; keep large datasets in a file or a linked script rather
22
- than bloating the module.
23
-
24
- A harness may also carry **test predicates** that pin the intended behavior of a
25
- skill — for example `test_<name>`, or a small `check/2` runner over
26
- input/expected pairs. When you change a skill, update or add its test and run it
27
- so the change is verified, not assumed.
28
-
29
- So a harness evolves like a codebase through **composition and reuse**: prefer
30
- an existing predicate over a near-duplicate. Change it **only when the user
31
- asks** — create on a fresh workspace, and afterwards touch only what the request
32
- requires; never refactor or extend it on your own initiative.
33
-
34
- **Generalize, don't specialize.** Prefer a few small, composable primitives over
35
- a predicate per request, and express one-off requests by composing them (or a
36
- direct `/goal`) instead of naming a predicate for every phrasing. A hard-coded
37
- "latest image in `~/Downloads`" is wrong; even `find_latest(Dir, Pattern, Path)`
38
- is fairly narrow — the reusable parts (list a directory, filter, pick a
39
- best/latest element) are shared by many tasks. Ask whether another caller would
40
- plausibly reuse the predicate with different arguments; if only this request
41
- would, do not add it. A harness of many task-shaped helpers is as bad as one
42
- hard-coded script.
43
-
44
- **Declare the shape of structured model output.** `list(object(B))` does not say
45
- what is in the dicts, so every consumer re-derives defaults and tolerates missing
46
- fields by hand. `schema(Name, [field(Field, Type, Option)])` is checked when the
47
- result binds: defaults filled, a missing `required` field or a wrong type reported
48
- against the field name, an undeclared field kept so a mistake stays visible. Name it
49
- in the output — `task(…, list(schema(author, Authors)))` — or apply it by hand with
50
- `schema_fill(author, Raw, Author)`.
51
-
52
- **Know which conversation the model sees.** `task/N` is sent the memory built so
53
- far and writes its reply back, so consecutive `task/N` calls accumulate history —
54
- pass values as explicit arguments instead of relying on the model to remember them.
55
- `prompt/N` is fresh (no memory, no tools) and is the right choice for a classifier,
56
- extractor, or transformation that must not be swayed by the conversation;
57
- `with_fresh_memory(Goal)` does the same for a group of steps, and restores the
58
- caller's memory on exit. A `task/N` inside a `tool/2` body starts empty: give it the
59
- context as an argument.
60
-
61
- **Start small, then improve.** Write the smallest harness that answers the actual
62
- request end to end — often a single predicate — run it on a real input, and show
63
- the user the result *before* extending it. Say what it does, what it does not do
64
- yet, and what you would add next, then let the next request decide. A harness grows
65
- in the direction the user actually takes it.
66
-
67
- Adding capability speculatively is the expensive mistake, and it costs more here
68
- than in a normal codebase: every predicate is part of the harness the next turn has
69
- to reason about, and every helper is one more thing the model can be offered as a
70
- tool. Do not write an error taxonomy before an error has occurred, retry and
71
- fallback policies before something has failed, caching or configuration layers
72
- before there is a reason, or a predicate per case for cases you have not seen.
73
- Prefer the smallest change that makes the failing input work.
74
-
75
- Signs you are overengineering:
76
-
77
- - a predicate with one caller whose arguments are all literals from the request;
78
- - an abstraction (a schema, an options list, a dispatch table) built for a single
79
- shape or a single value;
80
- - a helper "framework" written before the first end-to-end run;
81
- - generalizing across cases that no one has asked for yet;
82
- - a harness that does not run yet, because the parts are still being made tidy.
83
-
84
- A small change is also easier to trust: each commit is one reviewable unit, the
85
- `end_turn` probes report on a small surface, and `rollback` stays cheap. A harness
86
- that is incomplete but working is a better answer than one that is complete and
87
- unverified.
88
-
89
- **Do not parse in DML — shell out or ask the model.** Prolog string handling is
90
- the fiddliest thing here, and a hand-rolled parser (`sub_string/5`,
91
- `split_string/4`, `atom_concat/3`, `format/2`, an accumulator) is the easiest way
92
- to write DML that looks right and is quietly wrong. Split the work by what it is.
93
- Mechanical work — pull a field, change a format, count, filter — belongs in a
94
- **helper script** (`script_file/2` + `exec(bash(argv: [...]))`), which is testable
95
- outside DML and written in a language made for text; have it emit **JSON** and read
96
- it with `json_get/3`/`json_gets/3`/`json_text/2` instead of splitting stdout.
97
- Work that needs *understanding* — find the field named X, classify, summarise —
98
- belongs in a **model call** with a typed output (`task("…", list(string(Items)))`,
99
- `schema/2`, `choose`/`rate`/`verify`). DML sequences and checks; it does not parse.
100
-
101
- **Prefer orchestration over algorithms.** A skill should read as a short
102
- sequence of steps. Describe each step with `task/N` (which sees the conversation
103
- memory) or `prompt/N` (fresh context) and let the model extract, classify,
104
- summarise, or decide; keep the Prolog between the steps to simple guards
105
- (`->`, `;`, `once/1`, `==`, `\==`), `member/2`, `between/3`, `format/2`, and
106
- small arithmetic. Reach for deep recursion, hand-rolled list algorithms, CLP, or
107
- `assert`/`retract` only when the task is genuinely algorithmic — and prefer a
108
- one-shot `execute` goal over committing it as a skill. DML is the orchestration
109
- layer, not the logic library.
110
-
111
- ## 1. Skills vs one-shot work
112
-
113
- A harness is a library of reusable **capabilities**, not a record of what you
114
- did. Most requests mix two things, and you must separate them:
115
-
116
- - **A reusable capability** — worth a named, documented, tested predicate. It
117
- takes its inputs as arguments and works for any caller (`describe_image(Path,
118
- Text)`, `tally(List, Counts)`).
119
- - **A one-off action** — the concrete step for *this* request. Run it now with
120
- an `execute` goal or `bash`; do not commit it as a predicate.
121
-
122
- Example — "find the latest image in `~/Downloads` and tell me what's on it":
123
- run the "find/copy the latest file" step once in the turn, and add only
124
- `describe_image(Path, Text)` as the skill. Finding a latest file, copying files
125
- around, moving data, or any single concrete invocation is a task, not a skill.
126
-
127
- Never bake environment-specific values into a predicate: no host paths
128
- (`/home/...`), machine-specific directories, or fixed filenames — a skill takes
129
- them as arguments. A predicate that exists only to be called once, with literals
130
- frozen in, is a script in disguise.
131
-
132
- ## 2. Only use tools from the catalog
133
-
134
- The HOST TOOL CATALOG above is the complete set of `exec(...)` capability tools.
135
- Do not invent names — there is no `calculator`, `fetch_url`, `web_search`, or
136
- `vm_exec` unless the catalog lists it. By default the only capability tool is
137
- **`bash`**.
138
-
139
- **Prefer the shell for file I/O.** Use `bash` for reading, writing, copying, and
140
- converting files. The DML file predicates (`read_file/2`, `open/3`,
141
- `read_string/3`, `write_file/2`, `make_directory_path/1`, `directory_files/2`, …)
142
- are for when the content must be bound and reasoned over **inside Prolog** — not
143
- for moving bytes around. Reading a file into DML just to shell it out again is a
144
- smell.
145
-
146
- ## 3. Scripts are files, linked from the harness
147
-
148
- Materialize a script by running a DML goal with the `execute` tool — for example
149
- `make_directory_path("scripts"), write_file("scripts/x.py", "…")` — then link it
150
- with `script_file/2` and run it with `bash`. `write_file/2` writes to the
151
- workspace immediately and does **not** create parent directories.
152
- `script_file/2` is just a fact: it tells `export` which files belong to the
153
- harness. Use a literal workspace-relative path and one fact per name. `export harness.zip` bundles the
154
- `.dml` plus every linked file; `export harness.dml` inlines them so the single
155
- file stays portable.
156
-
157
- Untrusted data (URLs, file contents, user text) goes through a file or `stdin`,
158
- never interpolated into the shell command string. See `HARNESS_EXAMPLES.md` §1.
159
-
160
- A linked script is for a genuinely external capability (a library, `ffmpeg`, an
161
- API) — not a substitute for a shell command you run once, and not one script per
162
- request. When a script is the capability, it is a component: parameterize it and
163
- document it with `doc/2`.
164
-
165
- ## 4. Annotate the harness (self-describing)
166
-
167
- Keep the harness self-describing. `module_doc/1` is the harness's **skill
168
- description** — the one line that says what the harness does and when to use it,
169
- the same role a skill's `description` plays for routing. Write it like
170
- frontmatter, not like a title:
1
+ # Authoring a living harness
2
+
3
+ Start small, then improve. Use the smallest end-to-end design that satisfies the
4
+ request, verify it on real input and show the user. Reuse existing predicates;
5
+ do not build speculative abstractions, duplicate helpers or a predicate per one-off
6
+ request. A harness is reusable capabilities, not a log of everything performed.
7
+
8
+ ## Design and inspect
9
+
10
+ Call `listing(filter: "all")` first, then relevant `Name/Arity` entries.
11
+ Walk the user through a short plan: inputs/defaults, steps, reused workflows,
12
+ outputs, real evidence sources, effects, missing capabilities and test strategy.
13
+ Ask focused material questions with suggested defaults, then wait for approval
14
+ BEFORE transactions, file writes, execution or publication. Do not treat an initial
15
+ request as agreement on an unseen design. Discuss and agree the plan in the normal
16
+ conversation, then implement it. After a material scope change, agree a revised
17
+ plan. Do not keep reopening settled choices.
18
+ Normal conversational agents use `shell/1` plus tools/workflows, not a custom loop.
19
+ Use explicit argument modes and typed model outputs from the first small version.
20
+
21
+ Simple exact logic stays in DML; substantial parsing/file algorithms belong in
22
+ scripts; semantic work uses typed prompt/task calls. Choose by actual need, not
23
+ by a blanket ban on Prolog or a blanket preference for models. Read `patterns`
24
+ for a matching small shape and `examples` for a complete tested one.
25
+
26
+ ## Common workflow building blocks
27
+
28
+ - **Reuse:** inspect `reference(topic: "workflows")` for host-supplied names,
29
+ descriptions, typed inputs/outputs and revision pins before creating a duplicate.
30
+ Same-module helpers are ordinary predicate calls. With the serve host grant,
31
+ `run_workflow("Existing name", _{'Text':Text}, R)` invokes another workflow;
32
+ require `get_dict(ok,R,true)`, then `get_dict(outputs,R,Outputs)` and extract
33
+ its named output. Child runtimes close on return; reuse completed outputs, not
34
+ detached process handles. On failure inspect status/error and stop or report it; never
35
+ claim success. This host capability is not universally available in SDK/browser
36
+ embeddings. It does not import code or grant another workflow's tools.
37
+ - **Retrieval pipeline:** choose approved feeds/endpoints or existing collectors;
38
+ retrieve with a registered tool, set request/response/time/count bounds, extract
39
+ dated evidence + source URLs + retrieval time, filter/deduplicate, then synthesize
40
+ and cite only that evidence. A tool-free prompt/llm is NOT web search. Never
41
+ replace fresh evidence with model knowledge. Fail honestly on no/failed evidence.
42
+ Fixture tests validate transformations, not live retrieval or factual freshness.
43
+ - **Scripts/files:** inspect `tools` for the actual registry. If Bash exists use
44
+ `exec(bash(argv:["python3","scripts/collect.py",Topic]),R)`, inspect exitCode,
45
+ stdout and stderr; throw/report nonzero exit, do not summarize errors as results.
46
+ `run_script/3` checks the exit code and parses JSON with a granted Bash/Python
47
+ backend. Link reusable code with script_file/2; pass arguments as argv, not shell
48
+ interpolation. No granted interpreter means script execution is unavailable.
49
+ - **Typed model stages:** deterministic validation/filtering in DML/scripts;
50
+ `prompt(...,string(Summary))` for evidence-grounded isolated synthesis, task for
51
+ explicitly scoped tools/memory. Pass evidence as data, not trusted instructions.
52
+ - **Inputs/results:** keep a small typed interface, useful field descriptions,
53
+ defaults for truly optional inputs, and named outputs (not answer/1). Persist
54
+ deliverables at workspace-relative unique paths; keep secrets out of source.
55
+ - **Effects/schedules:** bound work, make effects single-solution, propagate errors
56
+ and cancellation; no implicit retries. Publishing does not run or schedule it.
57
+
58
+ ## Clock and today
59
+
60
+ No Bash is needed for the runtime UTC date:
171
61
 
172
62
  ```prolog
173
- module_doc("Support triage: classify a customer message and route it to the right team. Use when a message needs a team.").
174
-
175
- doc(classify/2, "Route a support message to a team. classify(+Message, -Team). Example: /goal classify(\"I was charged twice\", T).").
176
- doc(tally/2, "Count occurrences of each item. tally(+List, -Counts) yields Key-N pairs. Example: tally([a,b,a], C).").
63
+ today_utc(Date) :-
64
+ get_time(Stamp),
65
+ stamp_date_time(Stamp, DT, 'UTC'),
66
+ format_time(string(Date), "%Y-%m-%d", DT).
177
67
  ```
178
68
 
179
- - `module_doc(Text)` — the skill description. It is the **first line of the
180
- manifest** (`- skill: ...`), so **read it at the start of the session and
181
- re-read it whenever the harness changes**. A file with only `module_doc/1` and
182
- no predicates is still a valid skill: it advertises the capability while the
183
- body is empty.
184
- - `tool(Head, "desc") :- Body.` — **an annotation, not an implementation**: it
185
- exposes an existing predicate to the nested agent in `task/N`. Define the
186
- predicate normally and delegate
187
- (`tool(count_words(File, Count), "…") :- count_words(File, Count).`), so the
188
- same predicate is callable from `execute` / `/goal` **and** from `task/N`. Logic
189
- placed only inside `tool/2` is unreachable from `execute` (the loader asserts
190
- `tool(Head)`, never `Head`).
191
- - Annotate **capabilities** (file I/O, search, a script) that a nested agent
192
- should use — not the LLM steps themselves. A `tool/2` whose implementation
193
- calls `task/N` and advertises the same job is offered to the agent inside that
194
- `task/N`, which then calls it. Absent the tool call stack, wrapper predicates
195
- are the same job twice; keep the step a skill, or scope the task with
196
- `without_tools([Head], task(…))`.
197
- - `doc(Name/Arity, Text)` — one fact per skill, helper, or tool; terse, with
198
- arguments (`+in` / `-out`) and an example goal.
199
-
200
- They are shown in the manifest (so the next turn sees them), in `listing`, and
201
- survive `export`. When you change a predicate, update its `doc/2`; when the
202
- harness's purpose changes, update `module_doc/1`.
203
-
204
- ## 5. Media (images)
205
-
206
- Images are **workspace files**, referenced by `media(Path, Mime)`; the bytes
207
- never enter Prolog or conversation memory. Read a reference with `read_media/2`
208
- and put it in context with `attach_media/1`; the next `task/N` sends it to the
209
- model as an image block:
69
+ For a simple "today" workflow compute it internally, rather than requiring a date
70
+ input. This engine has no tzdata: `stamp_date_time/3` takes `'UTC'` or an integer
71
+ offset, so name a market zone through `zone_date_time/3` (DST-correct) instead:
210
72
 
211
73
  ```prolog
212
- describe_image(Path, Text) :-
213
- read_media(Path, Image),
214
- attach_media(Image),
215
- task("Describe the attached image in one sentence.", Text).
74
+ market_date(Zone, Date) :-
75
+ get_time(Stamp), zone_date_time(Stamp, Zone, DT),
76
+ format_time(string(Date), "%Y-%m-%d", DT).
216
77
  ```
217
78
 
218
- Only PNG/JPEG/GIF/WebP are accepted. This needs a vision-capable model; keep a
219
- textual description in memory when it does not. Semantic judgments stay
220
- text-only — never attach media to them.
221
-
222
- ## 6. Guard rails
223
-
224
- - Read first: call `listing`.
225
- - **Paths: use `/workspace/...`.** The workspace is the working directory, so
226
- `out/report.txt` and `/workspace/out/report.txt` are the same file — but write
227
- the `/workspace` form, because it means the same thing from DML, from
228
- `exec(bash(...))`, and from the shell tool on every backend. Everything outside
229
- `/workspace` is the session's ephemeral VM filesystem: fine for scratch, never
230
- for a result, because **only files under `/workspace` reach the host**. Scratch
231
- goes in `$TMPDIR` (per-session in every backend), not a bare `/tmp`.
232
- `directory_files/2` returns **bare names**, so build one
233
- (`atom_concat('images/', Name, Path)`). Prefer `bash`/host file tools for file
234
- operations; use the DML file predicates only for content you must reason over
235
- in Prolog.
236
- - **Side-effecting skills must be deterministic.** Any skill that calls
237
- `task/N`, `prompt/N`, `exec/2`, `read_media/2`, `attach_media/1`, or writes a
238
- file must yield exactly one solution with no choicepoint left across the side
239
- effect (`once/1`, `->`, or a cut). Otherwise backtracking re-runs the model
240
- call: slow, costly, and a different answer each time.
241
- - Replace a predicate with `define(head, clauses)`, where the head names the
242
- predicate being replaced and must be one of the predicates the block defines.
243
- Never patch it clause by clause.
244
- - Open the transaction once with `begin_turn`; it is idempotent and returns a
245
- reminder if it is already open. Do not call it again before every edit.
246
- - `assert`/`assert_many` are only for a **new** predicate: they reject a
247
- predicate that already has any clauses. This includes `doc/2` and other
248
- annotation/fact predicates. There is no append operation in the authoring
249
- tools. To change an existing predicate, use `define` with its complete clause
250
- set; to add a `doc/2` fact, include all existing doc facts in that `define`.
251
- - `retract` removes the clauses matching its pattern and says how many; `delete`
252
- removes a whole predicate. `retract` fails when nothing matched — check that
253
- the pattern is the one you meant.
254
- - Clause order matters: base case before a recursive rule; give a whole predicate
255
- to `define`/`assert_many` at once (clauses in the order written).
256
- - Verify after changing a predicate: `listing(Name/Arity)`.
257
- - Bounded iteration only: finite recursion or an explicit bound. `execute` is
258
- gas-limited and the turn has a model-call budget, but a single builtin call
259
- (e.g. an unbounded `label/1`) is not interrupted.
260
- - **CLP is advanced — use it only for a real constraint problem.** Bound every
261
- domain (`X ins 0..N`) before `label/1`, prefer `once/1`, and keep the model
262
- small: an under-specified or unsatisfiable model searches forever, and there
263
- is no per-goal timeout. Never reach for CLP as a shortcut for arithmetic.
264
- - **Know whether you are sandboxed.** The session's environment block says which
265
- backend is in effect. With a sandbox (`bwrap`, AgentVM, `sandbox-exec`),
266
- `bash` is isolated and writes outside the workspace are confined. With
267
- `clean-room` there is **no** sandbox: commands run as the user, writes outside
268
- the workspace are real files that persist, and a `rm` is a real `rm`. Explore
269
- what is available (`python3 --version`, `pip list`, `which jq`) and install a
270
- dependency when a skill genuinely needs one; installs are sandbox/session-local
271
- and do not travel with an exported harness, so prefer the standard library.
272
- - If a harness genuinely requires isolation, the **user** can add
273
- `:- require_sandbox.` (through `/set-require-sandbox`). It makes the load fail
274
- rather than run unsandboxed. Do not add it yourself.
275
- - Do **not** use `agent_main` unless the user asks for a `deepclause run` /
276
- `/dc-run` skill.
277
- - Media: reference images with `media(Path, Mime)` (`read_media/2` +
278
- `attach_media/1`); never inline bytes.
279
-
280
- ## 7. Concurrency and subagents
281
-
282
- Most skills are a short sequence of `task/N` calls in the foreground. Reach for a
283
- **subagent** only when the work must outlive the turn, wait for a message, or run
284
- in parallel.
285
-
286
- - **Fan out over a list** (`swarm/3`, `pmap/3`): the same worker over many items,
287
- each in its own process, results in input order. Bound the list.
288
- - **Background a long goal** (`spawn/2`): report the id and carry on; the user
289
- watches it with `/ps --watch --logs`.
290
- - **A service** (`serve/2` — or `serve/3` for the pid — plus `service_call/3`): a long-lived `receive` loop that
291
- answers requests; also good for a single-writer or rate-limited step.
292
-
293
- A subagent is isolated (private module snapshot) and asynchronous (value
294
- semantics): its `assert`/`retract` do not touch the harness, and a result comes
295
- back by `send/2` or the child's `answer/1`, never by an output argument. Prefer
296
- `swarm` over hand-rolled `spawn`+`receive` unless you need a custom protocol.
297
-
298
- Do not fan out an unbounded list (each item is a process and usually a model
299
- call), and do not spawn for a single model call.
79
+ `local_date_time(Stamp, DT)` follows the host zone and `zone_offset(Zone, Stamp, Off)`
80
+ exposes the offset. If a date override is useful declare a string default `""` and
81
+ explicitly interpret empty/`"today"`. Preserve an explicit valid ISO date. UTC
82
+ date, a market's local date and the last trading session are different policies;
83
+ agree which one is needed. A fixed prompt timestamp is not a trading calendar.
84
+
85
+ ## Draft versus live validation
86
+
87
+ Read `tools` for the actual registry. In serve, drafts inherit the configured host
88
+ tools, sandbox and network policy: Bash works when enabled, including without a
89
+ sandbox. Commands, network requests, messages and composed workflow calls are real.
90
+ Receive permissions, explicit new-Agent approvals and disabled tools still apply.
91
+ The separate draft directory protects source ownership, not the host from effects.
92
+ Scripts run with that directory as cwd; selected file inputs are copied there.
93
+ Private draft downloads are local presentation rather than published links.
94
+ Agree on bounded effectful tests in the normal conversation; prefer fixtures when
95
+ adequate and never claim fixture tests prove live retrieval. Transactions do not
96
+ undo shell/file/network/message effects. On an unsandboxed host the network flag
97
+ is not a firewall; AgentVM networking still follows the server's network setting.
98
+
99
+ ## Transactions
100
+
101
+ `begin_turn` opens a snapshot; call it once, not before every define. `define`
102
+ and `delete` are refused without an open transaction. `end_turn` validates and
103
+ commits a version; `rollback` discards the open edit. After committing, open a
104
+ new transaction before editing again. Check per-call results and end_turn warnings.
105
+ `committed: false` or no changed predicates means the intended edit may not have
106
+ landed. Verify `listing` rather than asserting it worked.
107
+
108
+ Change the module only through those tools. Do not consult/load a workspace DML
109
+ file to bypass edits. A system library directive is different from importing a
110
+ user DML file. The user can load a harness as a separate action.
111
+
112
+ ## Define targets
113
+
114
+ `define(head, clauses)` adds a NEW or replaces EXISTING complete predicate block.
115
+ Head is an indicator `"foo/2"` or actual head `"foo(A, B)"`, not a function name
116
+ whose arity you hope the tool infers. The block must define the target and may
117
+ include related predicates/annotations. All clauses end with their own period.
118
+ Preserve ordering; replacing a recursive predicate requires all its clauses.
119
+
120
+ For keyed annotations, use the actual two-argument head:
121
+ `define("doc(foo/2, _)", "doc(foo/2, \"...\").")`.
122
+ `doc(foo/2)` would name doc/1 and is rejected. `doc/2`, `schema/2`, `script_file/2`
123
+ merge by key so other entries survive. Changing foo/3 to foo/2 creates a different
124
+ predicate: delete the old one/doc key and define the new one in one transaction.
125
+
126
+ ## Delete targets
127
+
128
+ - `delete("foo/2")`: whole predicate and its associated nested tool annotation.
129
+ - `delete("tool:foo/2")`: nested tool annotation, keeping delegate.
130
+ - `delete("doc:foo/2")`: one documentation entry.
131
+ - `delete("schema:person")`: one schema key.
132
+ - `delete("script_file:extract_py")`: one script link, not the file.
133
+
134
+ Missing annotation keys are errors. No assertion/retraction tools are offered.
135
+ Use define with the complete remaining clause set to remove one clause.
136
+ Script link names must differ from all user predicate names; prefer `_py` or
137
+ `script_` link names, not the predicate they implement.
138
+
139
+ ## Documentation and scripts
140
+
141
+ `module_doc(Text)` describes purpose/when to use the harness. `doc(Name/Arity, Text)`
142
+ records inputs/outputs and an example goal; count every actual predicate argument.
143
+ `script_file(Name, Path)` links a workspace file for export. Write a script once
144
+ with the authoring write_file tool, then link/call it. Do not repeatedly overwrite
145
+ helper source every time a workflow runs. Unlinked files are not promised portable.
146
+ Do not hardcode user-specific host paths or secrets in code/facts.
147
+
148
+ ## Test and hand over
149
+
150
+ A small pure validation test, actual bounded input, error case and cancellation
151
+ case where relevant are enough for the first version. Side effects must be
152
+ intentional and single-solution. Debug intermediate values with output/1 rather
153
+ than adding more model steps. Foreground form workflows cannot be exercised in
154
+ browser scratch execute; ask for a foreground run and test pure rules separately.
155
+
156
+ End_turn warnings are contract evidence, not a reason to add bogus alias predicates
157
+ to satisfy stale docs. Correct the annotation or arity. Clean up fixtures and test
158
+ processes you created, but never delete unrelated user files. Summarize what was
159
+ observed, what is still unverified and how to run it.
@@ -0,0 +1,93 @@
1
+ # DML basics
2
+
3
+ DML is Prolog with host-interpreted operations for models, tools, forms and
4
+ processes. A harness is a library; `agent_main/N` is optional for positional runs.
5
+ Read these contracts when syntax or failure behavior is uncertain.
6
+
7
+ ## Terms and arguments
8
+
9
+ Variables start uppercase or `_`; lowercase words are atoms, and double quotes
10
+ are strings. `'two words'` is a quoted atom, not a string. `true` and `false`
11
+ are atoms. A bare `_` is a fresh anonymous variable on every occurrence.
12
+ Lists are `[a,b,c]` or `[Head|Tail]`; dicts are `_{name: "Ada", age: 36}` with
13
+ ATOM keys. Read controlled keys with `get_dict(name, D, X)`, varying model keys
14
+ with `dict_field(D, name, X)`.
15
+
16
+ Predicates are relations, not functions. `greet("Ada", Greeting)` supplies an
17
+ input and leaves the output variable to be bound. `greet/2` counts BOTH
18
+ arguments. `greet(+Name, -Text)` is documentation for intended modes.
19
+ Do not call `Text = greet("Ada")` expecting evaluation.
20
+
21
+ ## Clauses and goals
22
+
23
+ A fact states a relation; a rule gives a body that must succeed:
24
+
25
+ ```prolog
26
+ team(billing).
27
+ team(orders).
28
+ greet(Name, Text) :- format(string(Text), "Hello ~w", [Name]).
29
+ ```
30
+
31
+ Every fact/rule ends with a period, including `doc/2`, `schema/2`, `script_file/2`
32
+ and `shell/1`. Newlines alone do not separate clauses. `%` starts a line comment.
33
+ A query such as `greet("Ada", X)` runs the body and returns `X = "Hello Ada"`.
34
+ A predicate may have several clauses; their written order matters.
35
+
36
+ ## Unification and arithmetic
37
+
38
+ `X = Y` unifies terms, binding variables if possible. `X = 1 + 2` binds a TERM,
39
+ not 3. `X is 1 + 2` evaluates arithmetic; inputs must be bound numbers.
40
+ `A =:= B` compares evaluated numbers. `A == B` tests identical terms without
41
+ binding; `A \== B` tests non-identity now. `dif(A, B)` constrains them to remain
42
+ different. A string `"yes"` and atom `yes` are not identical.
43
+
44
+ Use `number_string/2` or `atom_string/2` deliberately at a type boundary; do not
45
+ sprinkle conversions blindly. Model type wrappers bind actual numbers/booleans.
46
+
47
+ ## Control flow
48
+
49
+ `A, B` is conjunction, `A ; B` disjunction. Parenthesize branching:
50
+
51
+ ```prolog
52
+ size_label(Text, Label) :-
53
+ string_length(Text, N),
54
+ ( N > 100 -> Label = long ; Label = short ).
55
+ ```
56
+
57
+ `\+ Goal` means the goal cannot be proved under current bindings. It is not
58
+ semantic truth or a model judgment. `catch(Goal, E, Recovery)` catches EXCEPTIONS,
59
+ not ordinary failure. `throw(Error)` raises an exception.
60
+
61
+ ## Failure and determinism
62
+
63
+ A false guard or missing relation yields zero solutions; it may not throw.
64
+ `findall(X, Goal, Xs)` yields `[]` for no solutions, while `setof`/`bagof` fail.
65
+ `get_dict` fails for a missing key and throws for an invalid key/dict type.
66
+
67
+ Pure relations can enumerate intentionally. `once(Goal)` chooses the first
68
+ solution, `!` discards local alternatives, and `(C -> T ; E)` commits the
69
+ condition. Select a deterministic input BEFORE a model/file/network effect.
70
+ An earlier choicepoint can replay a later effect on backtracking. A trailing
71
+ cut only commits paths that reached it. Do not retry irreversible actions by
72
+ backtracking; use explicit, bounded, safe retry policies.
73
+
74
+ ## Values and output
75
+
76
+ A reusable skill, nested tool or shell workflow binds its output arguments and
77
+ returns. The caller composes those values.
78
+ `output(Text)` emits progress/display without adding model memory.
79
+ `answer(Text)` emits the final one-shot answer and terminates the goal; it is NOT
80
+ `end_turn` and does not assign workflow outputs. Use it at a run entry point,
81
+ not in a helper whose caller must continue.
82
+
83
+ `system/1`/`user/1` add DML harness memory, not authoring conversation.
84
+ See `reference(topic: "tasks", section: "memory")` before relying on context.
85
+
86
+ ## Standard glue
87
+
88
+ Use `maplist/3` for sequential mapping; it passes each item plus an output to a
89
+ predicate. Use `include/3`, `exclude/3`, `memberchk/2`, `findall/3`, `sort/2`,
90
+ `msort/2`, `sum_list/2`, JSON helpers and `format/3` for small exact operations.
91
+ `sort/2` removes duplicates; `msort/2` keeps them. `directory_files/2` gives bare
92
+ entry names. Do not hand-build a large parser/list algorithm when a script fits.
93
+ `reference(topic: "snippets")` has precise short recipes.