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.
Files changed (135) hide show
  1. package/README.md +148 -2
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +154 -28
  4. package/dist/agent.js.map +1 -1
  5. package/dist/cli/config.d.ts +150 -140
  6. package/dist/cli/config.d.ts.map +1 -1
  7. package/dist/cli/config.js +3 -0
  8. package/dist/cli/config.js.map +1 -1
  9. package/dist/cli/login.d.ts +2 -1
  10. package/dist/cli/login.d.ts.map +1 -1
  11. package/dist/cli/login.js +15 -2
  12. package/dist/cli/login.js.map +1 -1
  13. package/dist/cli/repl.d.ts +54 -1
  14. package/dist/cli/repl.d.ts.map +1 -1
  15. package/dist/cli/repl.js +467 -53
  16. package/dist/cli/repl.js.map +1 -1
  17. package/dist/cli/run.d.ts.map +1 -1
  18. package/dist/cli/run.js +4 -0
  19. package/dist/cli/run.js.map +1 -1
  20. package/dist/cli/set-backend.d.ts +2 -2
  21. package/dist/cli/set-backend.d.ts.map +1 -1
  22. package/dist/cli/set-backend.js +54 -8
  23. package/dist/cli/set-backend.js.map +1 -1
  24. package/dist/cli/work.d.ts +16 -0
  25. package/dist/cli/work.d.ts.map +1 -0
  26. package/dist/cli/work.js +45 -0
  27. package/dist/cli/work.js.map +1 -0
  28. package/dist/index.d.ts +8 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +4 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/prolog-src/deepclause_mi.pl +2596 -268
  33. package/dist/prolog-src/deepclause_strings.pl +36 -3
  34. package/dist/repl/agent.d.ts +12 -0
  35. package/dist/repl/agent.d.ts.map +1 -1
  36. package/dist/repl/agent.js +40 -16
  37. package/dist/repl/agent.js.map +1 -1
  38. package/dist/repl/auth.d.ts +6 -3
  39. package/dist/repl/auth.d.ts.map +1 -1
  40. package/dist/repl/auth.js +55 -5
  41. package/dist/repl/auth.js.map +1 -1
  42. package/dist/repl/backend.d.ts +24 -0
  43. package/dist/repl/backend.d.ts.map +1 -1
  44. package/dist/repl/backend.js +292 -12
  45. package/dist/repl/backend.js.map +1 -1
  46. package/dist/repl/compaction.d.ts +2 -0
  47. package/dist/repl/compaction.d.ts.map +1 -1
  48. package/dist/repl/compaction.js +9 -0
  49. package/dist/repl/compaction.js.map +1 -1
  50. package/dist/repl/event-history.d.ts +4 -0
  51. package/dist/repl/event-history.d.ts.map +1 -0
  52. package/dist/repl/event-history.js +33 -0
  53. package/dist/repl/event-history.js.map +1 -0
  54. package/dist/repl/harness-tools.d.ts +26 -18
  55. package/dist/repl/harness-tools.d.ts.map +1 -1
  56. package/dist/repl/harness-tools.js +103 -34
  57. package/dist/repl/harness-tools.js.map +1 -1
  58. package/dist/repl/history.d.ts +75 -3
  59. package/dist/repl/history.d.ts.map +1 -1
  60. package/dist/repl/history.js +155 -4
  61. package/dist/repl/history.js.map +1 -1
  62. package/dist/repl/index.d.ts +33 -5
  63. package/dist/repl/index.d.ts.map +1 -1
  64. package/dist/repl/index.js +30 -0
  65. package/dist/repl/index.js.map +1 -1
  66. package/dist/repl/reference.d.ts +31 -0
  67. package/dist/repl/reference.d.ts.map +1 -0
  68. package/dist/repl/reference.js +143 -0
  69. package/dist/repl/reference.js.map +1 -0
  70. package/dist/repl/render.d.ts +3 -1
  71. package/dist/repl/render.d.ts.map +1 -1
  72. package/dist/repl/render.js +17 -0
  73. package/dist/repl/render.js.map +1 -1
  74. package/dist/repl/session.d.ts +166 -23
  75. package/dist/repl/session.d.ts.map +1 -1
  76. package/dist/repl/session.js +980 -188
  77. package/dist/repl/session.js.map +1 -1
  78. package/dist/repl/tui/autocomplete.d.ts.map +1 -1
  79. package/dist/repl/tui/autocomplete.js +5 -1
  80. package/dist/repl/tui/autocomplete.js.map +1 -1
  81. package/dist/repl/tui/renderer.d.ts +2 -1
  82. package/dist/repl/tui/renderer.d.ts.map +1 -1
  83. package/dist/repl/tui/renderer.js +20 -3
  84. package/dist/repl/tui/renderer.js.map +1 -1
  85. package/dist/repl/tui/status-bar.d.ts +5 -2
  86. package/dist/repl/tui/status-bar.d.ts.map +1 -1
  87. package/dist/repl/tui/status-bar.js +8 -3
  88. package/dist/repl/tui/status-bar.js.map +1 -1
  89. package/dist/repl/tui/tool-pane.d.ts +1 -1
  90. package/dist/repl/tui/tool-pane.d.ts.map +1 -1
  91. package/dist/repl/tui/tool-pane.js +13 -7
  92. package/dist/repl/tui/tool-pane.js.map +1 -1
  93. package/dist/repl/tui/work-view.d.ts +10 -0
  94. package/dist/repl/tui/work-view.d.ts.map +1 -0
  95. package/dist/repl/tui/work-view.js +28 -0
  96. package/dist/repl/tui/work-view.js.map +1 -0
  97. package/dist/runner.d.ts +7 -1
  98. package/dist/runner.d.ts.map +1 -1
  99. package/dist/runner.js +81 -23
  100. package/dist/runner.js.map +1 -1
  101. package/dist/runtime-identity.json +10 -0
  102. package/dist/system/assets/docs/AGENT_PROMPT.md +265 -2943
  103. package/dist/system/assets/docs/DML_AUTHORING.md +81 -295
  104. package/dist/system/assets/docs/DML_BASICS.md +93 -0
  105. package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
  106. package/dist/system/assets/docs/DML_FORMS.md +94 -728
  107. package/dist/system/assets/docs/DML_MEDIA.md +63 -0
  108. package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
  109. package/dist/system/assets/docs/DML_PYTHON.md +74 -0
  110. package/dist/system/assets/docs/DML_REFERENCE.md +224 -1912
  111. package/dist/system/assets/docs/DML_SHELL.md +107 -0
  112. package/dist/system/assets/docs/DML_TASKS.md +112 -0
  113. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
  114. package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
  115. package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
  116. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
  117. package/dist/system/assets/index.d.ts +1 -1
  118. package/dist/system/assets/index.d.ts.map +1 -1
  119. package/dist/system/assets/index.js +7 -0
  120. package/dist/system/assets/index.js.map +1 -1
  121. package/dist/system/environment.d.ts +1 -1
  122. package/dist/system/environment.d.ts.map +1 -1
  123. package/dist/system/environment.js +10 -6
  124. package/dist/system/environment.js.map +1 -1
  125. package/dist/system/runtime/shell-manager.d.ts +1 -1
  126. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  127. package/dist/types.d.ts +62 -2
  128. package/dist/types.d.ts.map +1 -1
  129. package/dist/work/index.d.ts +82 -0
  130. package/dist/work/index.d.ts.map +1 -0
  131. package/dist/work/index.js +232 -0
  132. package/dist/work/index.js.map +1 -0
  133. package/package.json +12 -3
  134. package/src/prolog-src/deepclause_mi.pl +2596 -268
  135. 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.