deepclause-sdk 0.3.0 → 0.6.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.
- package/README.md +148 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +154 -28
- package/dist/agent.js.map +1 -1
- package/dist/cli/config.d.ts +150 -140
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +3 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/login.d.ts +2 -1
- package/dist/cli/login.d.ts.map +1 -1
- package/dist/cli/login.js +15 -2
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/repl.d.ts +54 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +467 -53
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -0
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/set-backend.d.ts +2 -2
- package/dist/cli/set-backend.d.ts.map +1 -1
- package/dist/cli/set-backend.js +54 -8
- package/dist/cli/set-backend.js.map +1 -1
- package/dist/cli/work.d.ts +16 -0
- package/dist/cli/work.d.ts.map +1 -0
- package/dist/cli/work.js +45 -0
- package/dist/cli/work.js.map +1 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/prolog-src/deepclause_mi.pl +2596 -268
- package/dist/prolog-src/deepclause_strings.pl +36 -3
- package/dist/repl/agent.d.ts +12 -0
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +40 -16
- package/dist/repl/agent.js.map +1 -1
- package/dist/repl/auth.d.ts +6 -3
- package/dist/repl/auth.d.ts.map +1 -1
- package/dist/repl/auth.js +55 -5
- package/dist/repl/auth.js.map +1 -1
- package/dist/repl/backend.d.ts +24 -0
- package/dist/repl/backend.d.ts.map +1 -1
- package/dist/repl/backend.js +292 -12
- package/dist/repl/backend.js.map +1 -1
- package/dist/repl/compaction.d.ts +2 -0
- package/dist/repl/compaction.d.ts.map +1 -1
- package/dist/repl/compaction.js +9 -0
- package/dist/repl/compaction.js.map +1 -1
- package/dist/repl/event-history.d.ts +4 -0
- package/dist/repl/event-history.d.ts.map +1 -0
- package/dist/repl/event-history.js +33 -0
- package/dist/repl/event-history.js.map +1 -0
- package/dist/repl/harness-tools.d.ts +26 -18
- package/dist/repl/harness-tools.d.ts.map +1 -1
- package/dist/repl/harness-tools.js +103 -34
- package/dist/repl/harness-tools.js.map +1 -1
- package/dist/repl/history.d.ts +75 -3
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +155 -4
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +33 -5
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +30 -0
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/reference.d.ts +31 -0
- package/dist/repl/reference.d.ts.map +1 -0
- package/dist/repl/reference.js +143 -0
- package/dist/repl/reference.js.map +1 -0
- package/dist/repl/render.d.ts +3 -1
- package/dist/repl/render.d.ts.map +1 -1
- package/dist/repl/render.js +17 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +166 -23
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +980 -188
- package/dist/repl/session.js.map +1 -1
- package/dist/repl/tui/autocomplete.d.ts.map +1 -1
- package/dist/repl/tui/autocomplete.js +5 -1
- package/dist/repl/tui/autocomplete.js.map +1 -1
- package/dist/repl/tui/renderer.d.ts +2 -1
- package/dist/repl/tui/renderer.d.ts.map +1 -1
- package/dist/repl/tui/renderer.js +20 -3
- package/dist/repl/tui/renderer.js.map +1 -1
- package/dist/repl/tui/status-bar.d.ts +5 -2
- package/dist/repl/tui/status-bar.d.ts.map +1 -1
- package/dist/repl/tui/status-bar.js +8 -3
- package/dist/repl/tui/status-bar.js.map +1 -1
- package/dist/repl/tui/tool-pane.d.ts +1 -1
- package/dist/repl/tui/tool-pane.d.ts.map +1 -1
- package/dist/repl/tui/tool-pane.js +13 -7
- package/dist/repl/tui/tool-pane.js.map +1 -1
- package/dist/repl/tui/work-view.d.ts +10 -0
- package/dist/repl/tui/work-view.d.ts.map +1 -0
- package/dist/repl/tui/work-view.js +28 -0
- package/dist/repl/tui/work-view.js.map +1 -0
- package/dist/runner.d.ts +7 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +81 -23
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +10 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +265 -2943
- package/dist/system/assets/docs/DML_AUTHORING.md +81 -295
- package/dist/system/assets/docs/DML_BASICS.md +93 -0
- package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
- package/dist/system/assets/docs/DML_FORMS.md +94 -728
- package/dist/system/assets/docs/DML_MEDIA.md +63 -0
- package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
- package/dist/system/assets/docs/DML_PYTHON.md +74 -0
- package/dist/system/assets/docs/DML_REFERENCE.md +224 -1912
- package/dist/system/assets/docs/DML_SHELL.md +107 -0
- package/dist/system/assets/docs/DML_TASKS.md +112 -0
- package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
- package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
- package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
- package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
- package/dist/system/assets/index.d.ts +1 -1
- package/dist/system/assets/index.d.ts.map +1 -1
- package/dist/system/assets/index.js +7 -0
- package/dist/system/assets/index.js.map +1 -1
- package/dist/system/environment.d.ts +1 -1
- package/dist/system/environment.d.ts.map +1 -1
- package/dist/system/environment.js +10 -6
- package/dist/system/environment.js.map +1 -1
- package/dist/system/runtime/shell-manager.d.ts +1 -1
- package/dist/system/runtime/shell-manager.d.ts.map +1 -1
- package/dist/types.d.ts +62 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/work/index.d.ts +82 -0
- package/dist/work/index.d.ts.map +1 -0
- package/dist/work/index.js +232 -0
- package/dist/work/index.js.map +1 -0
- package/package.json +12 -3
- package/src/prolog-src/deepclause_mi.pl +2596 -268
- package/src/prolog-src/deepclause_strings.pl +36 -3
|
@@ -1,295 +1,81 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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:
|
|
171
|
-
|
|
172
|
-
```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).").
|
|
177
|
-
```
|
|
178
|
-
|
|
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:
|
|
210
|
-
|
|
211
|
-
```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).
|
|
216
|
-
```
|
|
217
|
-
|
|
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
|
-
- `assert`/`assert_many` are for a **new** predicate: they append, so against an
|
|
245
|
-
existing one both versions would stay live with their clauses interleaved, and
|
|
246
|
-
the runtime refuses the call rather than let that happen.
|
|
247
|
-
- `retract` removes the clauses matching its pattern and says how many; `delete`
|
|
248
|
-
removes a whole predicate. `retract` fails when nothing matched — check that
|
|
249
|
-
the pattern is the one you meant.
|
|
250
|
-
- Clause order matters: base case before a recursive rule; give a whole predicate
|
|
251
|
-
to `define`/`assert_many` at once (clauses in the order written).
|
|
252
|
-
- Verify after changing a predicate: `listing(Name/Arity)`.
|
|
253
|
-
- Bounded iteration only: finite recursion or an explicit bound. `execute` is
|
|
254
|
-
gas-limited and the turn has a model-call budget, but a single builtin call
|
|
255
|
-
(e.g. an unbounded `label/1`) is not interrupted.
|
|
256
|
-
- **CLP is advanced — use it only for a real constraint problem.** Bound every
|
|
257
|
-
domain (`X ins 0..N`) before `label/1`, prefer `once/1`, and keep the model
|
|
258
|
-
small: an under-specified or unsatisfiable model searches forever, and there
|
|
259
|
-
is no per-goal timeout. Never reach for CLP as a shortcut for arithmetic.
|
|
260
|
-
- **Know whether you are sandboxed.** The session's environment block says which
|
|
261
|
-
backend is in effect. With a sandbox (`bwrap`, AgentVM, `sandbox-exec`),
|
|
262
|
-
`bash` is isolated and writes outside the workspace are confined. With
|
|
263
|
-
`clean-room` there is **no** sandbox: commands run as the user, writes outside
|
|
264
|
-
the workspace are real files that persist, and a `rm` is a real `rm`. Explore
|
|
265
|
-
what is available (`python3 --version`, `pip list`, `which jq`) and install a
|
|
266
|
-
dependency when a skill genuinely needs one; installs are sandbox/session-local
|
|
267
|
-
and do not travel with an exported harness, so prefer the standard library.
|
|
268
|
-
- If a harness genuinely requires isolation, the **user** can add
|
|
269
|
-
`:- require_sandbox.` (through `/set-require-sandbox`). It makes the load fail
|
|
270
|
-
rather than run unsandboxed. Do not add it yourself.
|
|
271
|
-
- Do **not** use `agent_main` unless the user asks for a `deepclause run` /
|
|
272
|
-
`/dc-run` skill.
|
|
273
|
-
- Media: reference images with `media(Path, Mime)` (`read_media/2` +
|
|
274
|
-
`attach_media/1`); never inline bytes.
|
|
275
|
-
|
|
276
|
-
## 7. Concurrency and subagents
|
|
277
|
-
|
|
278
|
-
Most skills are a short sequence of `task/N` calls in the foreground. Reach for a
|
|
279
|
-
**subagent** only when the work must outlive the turn, wait for a message, or run
|
|
280
|
-
in parallel.
|
|
281
|
-
|
|
282
|
-
- **Fan out over a list** (`swarm/3`, `pmap/3`): the same worker over many items,
|
|
283
|
-
each in its own process, results in input order. Bound the list.
|
|
284
|
-
- **Background a long goal** (`spawn/2`): report the id and carry on; the user
|
|
285
|
-
watches it with `/ps --watch --logs`.
|
|
286
|
-
- **A service** (`serve/2` — or `serve/3` for the pid — plus `service_call/3`): a long-lived `receive` loop that
|
|
287
|
-
answers requests; also good for a single-writer or rate-limited step.
|
|
288
|
-
|
|
289
|
-
A subagent is isolated (private module snapshot) and asynchronous (value
|
|
290
|
-
semantics): its `assert`/`retract` do not touch the harness, and a result comes
|
|
291
|
-
back by `send/2` or the child's `answer/1`, never by an output argument. Prefer
|
|
292
|
-
`swarm` over hand-rolled `spawn`+`receive` unless you need a custom protocol.
|
|
293
|
-
|
|
294
|
-
Do not fan out an unbounded list (each item is a process and usually a model
|
|
295
|
-
call), and do not spawn for a single model call.
|
|
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
|
+
Clarify input, output, execution surface and evidence of correctness. If ambiguous,
|
|
12
|
+
ask one question before editing; once settled, do not reopen the same decision.
|
|
13
|
+
Normal conversational agents use `shell/1` plus tools/workflows, not a custom loop.
|
|
14
|
+
Use explicit argument modes and typed model outputs from the first small version.
|
|
15
|
+
|
|
16
|
+
Simple exact logic stays in DML; substantial parsing/file algorithms belong in
|
|
17
|
+
scripts; semantic work uses typed prompt/task calls. Choose by actual need, not
|
|
18
|
+
by a blanket ban on Prolog or a blanket preference for models. Read `patterns`
|
|
19
|
+
for a matching small shape and `examples` for a complete tested one.
|
|
20
|
+
|
|
21
|
+
## Transactions
|
|
22
|
+
|
|
23
|
+
`begin_turn` opens a snapshot; call it once, not before every define. `define`
|
|
24
|
+
and `delete` are refused without an open transaction. `end_turn` validates and
|
|
25
|
+
commits a version; `rollback` discards the open edit. After committing, open a
|
|
26
|
+
new transaction before editing again. Check per-call results and end_turn warnings.
|
|
27
|
+
`committed: false` or no changed predicates means the intended edit may not have
|
|
28
|
+
landed. Verify `listing` rather than asserting it worked.
|
|
29
|
+
|
|
30
|
+
Change the module only through those tools. Do not consult/load a workspace DML
|
|
31
|
+
file to bypass edits. A system library directive is different from importing a
|
|
32
|
+
user DML file. The user can load a harness as a separate action.
|
|
33
|
+
|
|
34
|
+
## Define targets
|
|
35
|
+
|
|
36
|
+
`define(head, clauses)` adds a NEW or replaces EXISTING complete predicate block.
|
|
37
|
+
Head is an indicator `"foo/2"` or actual head `"foo(A, B)"`, not a function name
|
|
38
|
+
whose arity you hope the tool infers. The block must define the target and may
|
|
39
|
+
include related predicates/annotations. All clauses end with their own period.
|
|
40
|
+
Preserve ordering; replacing a recursive predicate requires all its clauses.
|
|
41
|
+
|
|
42
|
+
For keyed annotations, use the actual two-argument head:
|
|
43
|
+
`define("doc(foo/2, _)", "doc(foo/2, \"...\").")`.
|
|
44
|
+
`doc(foo/2)` would name doc/1 and is rejected. `doc/2`, `schema/2`, `script_file/2`
|
|
45
|
+
merge by key so other entries survive. Changing foo/3 to foo/2 creates a different
|
|
46
|
+
predicate: delete the old one/doc key and define the new one in one transaction.
|
|
47
|
+
|
|
48
|
+
## Delete targets
|
|
49
|
+
|
|
50
|
+
- `delete("foo/2")`: whole predicate and its associated nested tool annotation.
|
|
51
|
+
- `delete("tool:foo/2")`: nested tool annotation, keeping delegate.
|
|
52
|
+
- `delete("doc:foo/2")`: one documentation entry.
|
|
53
|
+
- `delete("schema:person")`: one schema key.
|
|
54
|
+
- `delete("script_file:extract_py")`: one script link, not the file.
|
|
55
|
+
|
|
56
|
+
Missing annotation keys are errors. No assertion/retraction tools are offered.
|
|
57
|
+
Use define with the complete remaining clause set to remove one clause.
|
|
58
|
+
Script link names must differ from all user predicate names; prefer `_py` or
|
|
59
|
+
`script_` link names, not the predicate they implement.
|
|
60
|
+
|
|
61
|
+
## Documentation and scripts
|
|
62
|
+
|
|
63
|
+
`module_doc(Text)` describes purpose/when to use the harness. `doc(Name/Arity, Text)`
|
|
64
|
+
records inputs/outputs and an example goal; count every actual predicate argument.
|
|
65
|
+
`script_file(Name, Path)` links a workspace file for export. Write a script once
|
|
66
|
+
with the authoring write_file tool, then link/call it. Do not repeatedly overwrite
|
|
67
|
+
helper source every time a workflow runs. Unlinked files are not promised portable.
|
|
68
|
+
Do not hardcode user-specific host paths or secrets in code/facts.
|
|
69
|
+
|
|
70
|
+
## Test and hand over
|
|
71
|
+
|
|
72
|
+
A small pure validation test, actual bounded input, error case and cancellation
|
|
73
|
+
case where relevant are enough for the first version. Side effects must be
|
|
74
|
+
intentional and single-solution. Debug intermediate values with output/1 rather
|
|
75
|
+
than adding more model steps. Foreground form workflows cannot be exercised in
|
|
76
|
+
browser scratch execute; ask for a foreground run and test pure rules separately.
|
|
77
|
+
|
|
78
|
+
End_turn warnings are contract evidence, not a reason to add bogus alias predicates
|
|
79
|
+
to satisfy stale docs. Correct the annotation or arity. Clean up fixtures and test
|
|
80
|
+
processes you created, but never delete unrelated user files. Summarize what was
|
|
81
|
+
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.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Debugging DML
|
|
2
|
+
|
|
3
|
+
Reproduce the smallest failing goal, inspect the actual result, then change the
|
|
4
|
+
smallest relevant predicate. A supported contract is cheaper to read than guesses.
|
|
5
|
+
|
|
6
|
+
## Zero solutions versus exceptions
|
|
7
|
+
|
|
8
|
+
`solutions: []` means the goal failed; `catch/3` will not intercept ordinary
|
|
9
|
+
failure. Inspect each boundary: input type, missing field, guard, host tool, output
|
|
10
|
+
binding. Use `(Goal -> output("succeeded") ; output("failed here"))` and temporary
|
|
11
|
+
`output/1` calls with intermediate values. Remove noisy diagnostics afterwards.
|
|
12
|
+
Do not turn a failed fetch or cancelled form into invented success data.
|
|
13
|
+
An empty predicate and a handler primitive are different: `current_predicate`
|
|
14
|
+
can report false for built-in DML handlers such as `form/2` or `exec/2`.
|
|
15
|
+
|
|
16
|
+
## Model calls
|
|
17
|
+
|
|
18
|
+
Read `tasks` for memory/type/tool scope errors. A bare output is a string, not a
|
|
19
|
+
number; use type wrappers. A task sees harness memory, not the authoring request.
|
|
20
|
+
A prompt sees only its own description and no attached memory images.
|
|
21
|
+
Pass exact inputs, include them in the description, and guard empty data before
|
|
22
|
+
a model can fill gaps from prior knowledge. A tool named in prose is not registered.
|
|
23
|
+
|
|
24
|
+
## Host failures
|
|
25
|
+
|
|
26
|
+
Read the CURRENT schema via `tools` before retrying a parameter error. Inspect
|
|
27
|
+
host failure, `exitCode`, `stderr`, `stdout` separately; a nonzero Python exit may
|
|
28
|
+
still return a dict. `run_script/3` checks exit and parses JSON for you.
|
|
29
|
+
In the browser, Python has no stdin option and DML/Python private tmp directories
|
|
30
|
+
are different. Use workspace argv/files, not source-code interpolation.
|
|
31
|
+
For script-name conflicts, rename the link (`foo_py`) or predicate; use
|
|
32
|
+
`delete("script_file:old_name")` for a stale link.
|
|
33
|
+
|
|
34
|
+
## Execution contexts
|
|
35
|
+
|
|
36
|
+
| Context | Structured forms | Test isolation |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| Foreground query/run with UI | yes, via session handler | normal session/run |
|
|
39
|
+
| Work workflow/tool foreground runner | yes, via session handler | not disposable test worker |
|
|
40
|
+
| Browser authoring execute worker | no | disposable engine; host/file effects real |
|
|
41
|
+
| Browser worker-hosted process | no | private code/memory snapshot; live shared workspace |
|
|
42
|
+
|
|
43
|
+
The same goal can be valid but unsupported in a particular host. Interactive form
|
|
44
|
+
flows must be tested in foreground, not by repeatedly trying scratch execute.
|
|
45
|
+
Test pure validation separately; cancellation/unavailable is NOT a submitted record.
|
|
46
|
+
No capability directive is necessary. Close forms on every exit path.
|
|
47
|
+
|
|
48
|
+
## Edits and annotations
|
|
49
|
+
|
|
50
|
+
Read `authoring` for transaction/target contracts. `define` takes a head matching
|
|
51
|
+
the actual predicate arity. For one doc use `doc(foo/2, _)`, NOT `doc(foo/2)`.
|
|
52
|
+
Arity changes add a different predicate; remove the old predicate/doc key explicitly.
|
|
53
|
+
`delete("doc:foo/2")`, `delete("schema:Name")`, `delete("script_file:Name")`
|
|
54
|
+
remove one entry, never all docs/schemas/scripts. Missing keys are errors.
|
|
55
|
+
Read the end_turn result, not your intent; verify `listing` after changes.
|
|
56
|
+
|
|
57
|
+
## Process failures
|
|
58
|
+
|
|
59
|
+
Use `ps`, process state/errors, and the process harness version. A service keeps
|
|
60
|
+
its spawn-time snapshot; an edit does not hot-update it. Children cannot bind
|
|
61
|
+
parent outputs. Use messages or wait outcomes, inspect `failed` swarm items, bound
|
|
62
|
+
receives, and stop/reap test processes. Do not equate zero model tokens with a dead
|
|
63
|
+
service. See `processes` for exact signatures.
|
|
64
|
+
|
|
65
|
+
## Logs and bounds
|
|
66
|
+
|
|
67
|
+
Read only a short tail of `.deepclause/repl/sessions/<id>/events.jsonl` using the
|
|
68
|
+
available host capability when normal tool results are insufficient. Logs can
|
|
69
|
+
contain user data, prompts and arguments. Do not dump them wholesale to the model.
|
|
70
|
+
Use execute's `timeoutMs`, result limits and reduced bindings for scratch tests;
|
|
71
|
+
foreground goals/processes have different cancellation guarantees. Bound finite
|
|
72
|
+
search and builtin inference separately; gas alone cannot preempt every builtin.
|
|
73
|
+
After a couple of failed attempts, report the evidence and remaining uncertainty.
|