deepclause-sdk 0.4.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 +134 -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 +437 -54
- package/dist/cli/repl.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 +2426 -253
- package/dist/prolog-src/deepclause_strings.pl +36 -3
- package/dist/repl/agent.d.ts +5 -0
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +19 -7
- 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 +25 -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 +52 -2
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +113 -4
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +27 -5
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +27 -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 +7 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +128 -23
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +895 -196
- 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.map +1 -1
- package/dist/runner.js +50 -19
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +10 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +265 -3008
- package/dist/system/assets/docs/DML_AUTHORING.md +81 -299
- 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 -1971
- 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 +49 -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 +2426 -253
- package/src/prolog-src/deepclause_strings.pl +36 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Media and HTML
|
|
2
|
+
|
|
3
|
+
Media is a workspace reference, not image bytes in DML. Analysis, display and
|
|
4
|
+
generation are DIFFERENT capabilities. Check the active model/host before promising
|
|
5
|
+
vision or image generation. Videos/audio are not generic DML image inputs.
|
|
6
|
+
|
|
7
|
+
## Vision input
|
|
8
|
+
|
|
9
|
+
```prolog
|
|
10
|
+
describe_image(Path, Text) :-
|
|
11
|
+
read_media(Path, Image),
|
|
12
|
+
attach_media(Image),
|
|
13
|
+
with_tools([], task("Describe only the attached image.", string(Text))).
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`read_media(Path, Media)` derives a reference `media(Path, Mime)`; it does not
|
|
17
|
+
load bytes into Prolog. `attach_media(Media)` adds a reference to harness memory;
|
|
18
|
+
the next vision-capable task resolves the bytes for the model. A fresh `prompt/N`
|
|
19
|
+
does NOT read that memory, so attaching then prompting loses the image.
|
|
20
|
+
Pass media paths explicitly into nested tools; their task memory starts fresh.
|
|
21
|
+
|
|
22
|
+
Use workspace images, not remote URLs/base64 embedded in clauses. PNG/JPEG/GIF/
|
|
23
|
+
WebP are the portable vision formats; SVG display and actual model input support
|
|
24
|
+
are host-dependent. A text-only model does not magically see image contents;
|
|
25
|
+
report the limitation or use an explicitly available conversion/vision capability.
|
|
26
|
+
Semantic judgments (`choose/rate/verify/probability`) are text-only.
|
|
27
|
+
|
|
28
|
+
## Display and save
|
|
29
|
+
|
|
30
|
+
`output(media("charts/plot.png"))` displays an existing image.
|
|
31
|
+
`output(media{svg: Svg})` displays inline SVG where the host supports it.
|
|
32
|
+
The authoring host `show_image(path)` displays a workspace image to the person;
|
|
33
|
+
it is not a call asking a model to analyse it.
|
|
34
|
+
|
|
35
|
+
`save_image(Media, OutPath)` copies a referenced image or writes inline SVG.
|
|
36
|
+
Create parent directories first. Display does not persist a file by itself, and
|
|
37
|
+
saving does not display it; use the appropriate separate operation.
|
|
38
|
+
|
|
39
|
+
## Image generation
|
|
40
|
+
|
|
41
|
+
`task("Description", media(ImagePath))` selects an image-generation path rather
|
|
42
|
+
than a normal text agent turn. It requires a CONFIGURED image backend, otherwise
|
|
43
|
+
the runtime reports generation unavailable. Selecting a text/vision model via
|
|
44
|
+
`with_model` does not install an image generator. When configured, the output is
|
|
45
|
+
a workspace path; display it separately with `output(media(ImagePath))`.
|
|
46
|
+
|
|
47
|
+
The current browser session embedding does not configure an image backend by
|
|
48
|
+
default. Prefer deterministic SVG or a supported Python image workflow if it
|
|
49
|
+
fits the request, but do not mislabel that as model image generation.
|
|
50
|
+
|
|
51
|
+
## HTML miniapps
|
|
52
|
+
|
|
53
|
+
Browser hosts can display `output(html("miniapp/index.html"))`; the file must
|
|
54
|
+
exist. Write the complete HTML file once, with inline assets or allowed relative
|
|
55
|
+
assets. The renderer sandboxes scripts and does not grant app DOM/credential access.
|
|
56
|
+
`window.dc.call('double(21, X)')` calls a bounded goal in the rendering owner.
|
|
57
|
+
The promise returns `{ok, output, bindings, error?}`. Keep called predicates bounded
|
|
58
|
+
and deterministic. A reference to a predicate is not a replacement for defining it.
|
|
59
|
+
|
|
60
|
+
The browser miniapp bridge also supports `readFile`, `readBytes`, `list`, `stat`
|
|
61
|
+
and `fetch` for confined workspace paths; byte reads are capped. These are browser
|
|
62
|
+
renderer APIs, not DML host tool names. A plain HTML answer fence is not a trusted
|
|
63
|
+
workspace page. Do not assume these APIs exist in terminal or other embeddings.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Processes and concurrency
|
|
2
|
+
|
|
3
|
+
A process is a session-scoped DML execution with private harness/memory snapshot
|
|
4
|
+
and a mailbox. Parallelism is real; do not infer from Prolog's normal sequential
|
|
5
|
+
conjunction that DML lacks `swarm`/processes. Read before first process use.
|
|
6
|
+
|
|
7
|
+
## Choosing a process pattern
|
|
8
|
+
|
|
9
|
+
Use one `prompt/N` or scoped `task/N` for a short focused model step.
|
|
10
|
+
Use `maplist/3` for sequential mapping; `swarm/3,4` for independent bounded work.
|
|
11
|
+
Use `spawn/2` when work outlives the current turn; use a service for long-lived
|
|
12
|
+
message/state logic or single-writer coordination. Avoid a process per tiny
|
|
13
|
+
operation; every worker costs a session and often a model call.
|
|
14
|
+
|
|
15
|
+
## Parallel mapping
|
|
16
|
+
|
|
17
|
+
`swarm(Worker, Items, Results[, Concurrency])` calls Worker(Item, Value) in an
|
|
18
|
+
isolated process per item; default concurrency 4. Results preserve input order,
|
|
19
|
+
each `ok(Value)` or `failed`. Inspect failures; do not assume every item succeeded.
|
|
20
|
+
`pmap(Worker, Items, Values)` returns bare values and fails if any worker fails.
|
|
21
|
+
Bound input size and concurrency; live process limits and provider limits apply.
|
|
22
|
+
|
|
23
|
+
```prolog
|
|
24
|
+
double(N, R) :- R is N * 2.
|
|
25
|
+
parallel_values(Items, Results) :- swarm(double, Items, Results, 2).
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Keep worker outputs structured/plain values and their effects deterministic.
|
|
29
|
+
Do not make independent workers overwrite the same file; last sync may win.
|
|
30
|
+
|
|
31
|
+
## Spawn and result messages
|
|
32
|
+
|
|
33
|
+
`spawn(Goal, Pid)` returns immediately; `spawn_opt(Goal, Pid, Options)` adds name,
|
|
34
|
+
priority, timeout and code options. Child variables are COPIES: no child output
|
|
35
|
+
variable binds a variable in the parent. Use messages or a terminal answer.
|
|
36
|
+
|
|
37
|
+
```prolog
|
|
38
|
+
worker(Parent, Input) :-
|
|
39
|
+
prompt("Summarise: {Input}", string(Summary)),
|
|
40
|
+
send(Parent, done(Summary)).
|
|
41
|
+
start_summary(Input, Pid) :- self(Me), spawn(worker(Me, Input), Pid).
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
A separate foreground goal can receive the result. `wait(Pid, Outcome)` reports
|
|
45
|
+
`ok(Text)`, `failed(Error)` or `killed(Reason)`; use a message for structured
|
|
46
|
+
results. A worker's terminal result is text, not a shared output argument.
|
|
47
|
+
Commit harness edits before spawning; snapshots already running do not update.
|
|
48
|
+
Module/memory isolation does NOT imply a copied filesystem. In the current
|
|
49
|
+
browser, session/child/Python workers mount one live OPFS-backed /workspace.
|
|
50
|
+
Completed writes are shared; use messages to order producer/consumer operations
|
|
51
|
+
and coordinate concurrent writers. Other embeddings must state their own file
|
|
52
|
+
visibility guarantees. Create required artifacts before their first use.
|
|
53
|
+
|
|
54
|
+
## Mailboxes
|
|
55
|
+
|
|
56
|
+
`send(Target, Term)` copies a message. Target can be a pid or registered name.
|
|
57
|
+
`receive(Message[, TimeoutMs])` consumes mailbox messages; use bounded waits.
|
|
58
|
+
`receive_match(Template, Message, TimeoutMs)` selects a matching message and
|
|
59
|
+
keeps unrelated messages. For custom request/reply protocols use correlation
|
|
60
|
+
refs (`make_ref/1`) so replies cannot be confused.
|
|
61
|
+
`self(Pid)`, `register(Name, Pid)` and `whereis(Name, Pid)` identify processes.
|
|
62
|
+
A simple foreground `input/1` does not consume a worker's message; `next/1`
|
|
63
|
+
dispatches `user(Text)` versus `message(Term)` for custom event-driven conversations.
|
|
64
|
+
|
|
65
|
+
## Services
|
|
66
|
+
|
|
67
|
+
`serve(Name, Loop[, Pid])` starts and registers a process.
|
|
68
|
+
`service_call(Target, Request, Reply[, TimeoutMs])` sends
|
|
69
|
+
`request(From, Ref, Request)` and waits for `reply(Ref, Reply)`.
|
|
70
|
+
`service_cast(Target, Message)` sends without waiting. The service loop receives
|
|
71
|
+
requests, sends the correlated reply, then recurses with its new state.
|
|
72
|
+
|
|
73
|
+
```prolog
|
|
74
|
+
counter(N) :-
|
|
75
|
+
receive(M),
|
|
76
|
+
( M = request(From, Ref, read)
|
|
77
|
+
-> send(From, reply(Ref, N)), counter(N)
|
|
78
|
+
; M = request(From, Ref, bump)
|
|
79
|
+
-> Next is N + 1, send(From, reply(Ref, Next)), counter(Next)
|
|
80
|
+
; M = stop -> true
|
|
81
|
+
; counter(N)
|
|
82
|
+
).
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use a registered service name for cross-turn reuse, `ps`/`process_info` to inspect
|
|
86
|
+
liveness, and `ps(code: name)` to inspect its snapshot. Model-token usage can be
|
|
87
|
+
zero for a deterministic service; that does not mean it is stopped.
|
|
88
|
+
|
|
89
|
+
## Lifecycle and cleanup
|
|
90
|
+
|
|
91
|
+
`wait/1` succeeds only for successful termination. `exit(Reason)` terminates the
|
|
92
|
+
current process; `exit(Target, Reason)` stops a peer. The authoring host tool
|
|
93
|
+
`stop` is NOT a DML `stop/1` predicate. `sleep(Ms)` yields; `now_ms/1` gives time.
|
|
94
|
+
Stop/reap test workers on success, error or timeout. An execute call can leave
|
|
95
|
+
session-scoped processes running; a scratch module is not a scratch world.
|
|
96
|
+
|
|
97
|
+
Browser worker-hosted processes cannot render forms. Their host can proxy explicit
|
|
98
|
+
`input/2` where supported, but structured form workflows belong in foreground.
|
|
99
|
+
`suspend(Continuation)` is an advanced safe-point operation; close streams/forms
|
|
100
|
+
before suspending and verify host resume support. Do not suspend inside a host call.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Python host capability
|
|
2
|
+
|
|
3
|
+
Use this topic only if the CURRENT host catalog registers `python`. The browser
|
|
4
|
+
registers Python/Pyodide and has no shell. Other embeddings may supply a different
|
|
5
|
+
capability; never guess based on a generic example.
|
|
6
|
+
|
|
7
|
+
## Contract
|
|
8
|
+
|
|
9
|
+
DML calls `exec(python(code: Code), Result)` or
|
|
10
|
+
`exec(python(script: "scripts/worker.py", argv: ["value"]), Result)`.
|
|
11
|
+
Supported options: `code`, `script`, `argv`, `timeoutMs`, `packages`.
|
|
12
|
+
`script` takes precedence over `code`. `argv` is a LIST OF STRINGS, passed
|
|
13
|
+
verbatim; spaces, quotes and empty strings are not shell-split.
|
|
14
|
+
There is no `stdin` option. Pass text as an argv element or through a workspace
|
|
15
|
+
file; do not rewrite source code to inject values.
|
|
16
|
+
|
|
17
|
+
```prolog-goal
|
|
18
|
+
exec(python(code: "import json,sys\nprint(json.dumps({'text':sys.argv[1]}))", argv: ["Ada Lovelace"]), R),
|
|
19
|
+
get_dict(exitCode, R, 0), get_dict(stdout, R, Json), atom_json_dict(Json, Data, []).
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The host returns a dict with `exitCode`, `stdout`, `stderr`. A tool that ran with
|
|
23
|
+
nonzero exit is NOT a successful computation just because exec returned a dict.
|
|
24
|
+
Inspect status/exit code; `catch/3` only catches actual exceptions. Unknown
|
|
25
|
+
parameters and host refusal are different from nonzero script exits or plain
|
|
26
|
+
DML failure. Do not silently convert errors to empty results.
|
|
27
|
+
|
|
28
|
+
## Paths and shared files
|
|
29
|
+
|
|
30
|
+
Working directory is `/workspace`. Use relative workspace paths or `/workspace/...`.
|
|
31
|
+
Python and DML share that tree. Their private `/tmp` filesystems are NOT the
|
|
32
|
+
same: stage shared bytes under `/workspace/.staging/` or a unique workspace path
|
|
33
|
+
and clean up. Do not hardcode host `/home/...` paths or use a fixed shared staging
|
|
34
|
+
filename for concurrent runs. Standard Python `open` does not create parents.
|
|
35
|
+
The authoring `write_file` TOOL creates parents; DML `write_file/2` does not.
|
|
36
|
+
|
|
37
|
+
Scripts run in a browser sandbox, not a complete OS. No shell, Node/npm, CLI
|
|
38
|
+
binaries or native CPython wheels. Network requests use browser egress/CORS;
|
|
39
|
+
`import js; response = await js.fetch(url)` is available. Do not promise arbitrary
|
|
40
|
+
web crawling or desktop browser automation. Read the CURRENT schemas via
|
|
41
|
+
`reference(topic: "tools", section: "python")` if unsure.
|
|
42
|
+
|
|
43
|
+
## Linked scripts
|
|
44
|
+
|
|
45
|
+
Write nontrivial code once during authoring, in a workspace `.py` file; link it
|
|
46
|
+
for export, then call it. Script link names MUST differ from predicate names.
|
|
47
|
+
|
|
48
|
+
```prolog
|
|
49
|
+
script_file(count_py, "scripts/count.py").
|
|
50
|
+
count_words(Path, N) :-
|
|
51
|
+
run_script(count_py, [Path], Stats),
|
|
52
|
+
get_dict(words, Stats, N).
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`run_script(Name, Args, Value)` resolves the link, converts atoms/numbers to argv
|
|
56
|
+
strings, checks `exitCode`, and parses stdout JSON (otherwise returns stdout).
|
|
57
|
+
The script prints one JSON result with a newline; diagnostics belong on stderr.
|
|
58
|
+
A nonzero exit throws `script_failed(...)`. Link files with `script_file/2` so
|
|
59
|
+
export can bundle them; a path mentioned only in code is not a package manifest.
|
|
60
|
+
`delete("script_file:count_py")` removes just that link, not the file or predicate.
|
|
61
|
+
|
|
62
|
+
Do not use `sys.exit()` in Pyodide helper scripts: the current bridge can report
|
|
63
|
+
SystemExit(0) as a failed run. Return normally and print JSON instead. Do not
|
|
64
|
+
assume separate invocations clear all Python modules; test repeated runs when
|
|
65
|
+
import state matters. That is a runtime behavior to inspect, not a reason to
|
|
66
|
+
invent process-isolation flags.
|
|
67
|
+
|
|
68
|
+
## Packages
|
|
69
|
+
|
|
70
|
+
`packages: ["package==version"]` installs compatible packages into the current
|
|
71
|
+
harness environment. Use pinned pure-Python/Pyodide-compatible packages.
|
|
72
|
+
`python_packages(action: "install", packages: [...])` and action `"list"` manage
|
|
73
|
+
the same environment. This is not a native OS package manager; arbitrary wheels
|
|
74
|
+
will not work. Prefer stdlib when it solves the job.
|