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.
Files changed (131) hide show
  1. package/README.md +134 -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 +437 -54
  16. package/dist/cli/repl.js.map +1 -1
  17. package/dist/cli/set-backend.d.ts +2 -2
  18. package/dist/cli/set-backend.d.ts.map +1 -1
  19. package/dist/cli/set-backend.js +54 -8
  20. package/dist/cli/set-backend.js.map +1 -1
  21. package/dist/cli/work.d.ts +16 -0
  22. package/dist/cli/work.d.ts.map +1 -0
  23. package/dist/cli/work.js +45 -0
  24. package/dist/cli/work.js.map +1 -0
  25. package/dist/index.d.ts +8 -6
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/prolog-src/deepclause_mi.pl +2426 -253
  30. package/dist/prolog-src/deepclause_strings.pl +36 -3
  31. package/dist/repl/agent.d.ts +5 -0
  32. package/dist/repl/agent.d.ts.map +1 -1
  33. package/dist/repl/agent.js +19 -7
  34. package/dist/repl/agent.js.map +1 -1
  35. package/dist/repl/auth.d.ts +6 -3
  36. package/dist/repl/auth.d.ts.map +1 -1
  37. package/dist/repl/auth.js +55 -5
  38. package/dist/repl/auth.js.map +1 -1
  39. package/dist/repl/backend.d.ts +24 -0
  40. package/dist/repl/backend.d.ts.map +1 -1
  41. package/dist/repl/backend.js +292 -12
  42. package/dist/repl/backend.js.map +1 -1
  43. package/dist/repl/compaction.d.ts +2 -0
  44. package/dist/repl/compaction.d.ts.map +1 -1
  45. package/dist/repl/compaction.js +9 -0
  46. package/dist/repl/compaction.js.map +1 -1
  47. package/dist/repl/event-history.d.ts +4 -0
  48. package/dist/repl/event-history.d.ts.map +1 -0
  49. package/dist/repl/event-history.js +33 -0
  50. package/dist/repl/event-history.js.map +1 -0
  51. package/dist/repl/harness-tools.d.ts +25 -18
  52. package/dist/repl/harness-tools.d.ts.map +1 -1
  53. package/dist/repl/harness-tools.js +103 -34
  54. package/dist/repl/harness-tools.js.map +1 -1
  55. package/dist/repl/history.d.ts +52 -2
  56. package/dist/repl/history.d.ts.map +1 -1
  57. package/dist/repl/history.js +113 -4
  58. package/dist/repl/history.js.map +1 -1
  59. package/dist/repl/index.d.ts +27 -5
  60. package/dist/repl/index.d.ts.map +1 -1
  61. package/dist/repl/index.js +27 -0
  62. package/dist/repl/index.js.map +1 -1
  63. package/dist/repl/reference.d.ts +31 -0
  64. package/dist/repl/reference.d.ts.map +1 -0
  65. package/dist/repl/reference.js +143 -0
  66. package/dist/repl/reference.js.map +1 -0
  67. package/dist/repl/render.d.ts +3 -1
  68. package/dist/repl/render.d.ts.map +1 -1
  69. package/dist/repl/render.js +7 -0
  70. package/dist/repl/render.js.map +1 -1
  71. package/dist/repl/session.d.ts +128 -23
  72. package/dist/repl/session.d.ts.map +1 -1
  73. package/dist/repl/session.js +895 -196
  74. package/dist/repl/session.js.map +1 -1
  75. package/dist/repl/tui/autocomplete.d.ts.map +1 -1
  76. package/dist/repl/tui/autocomplete.js +5 -1
  77. package/dist/repl/tui/autocomplete.js.map +1 -1
  78. package/dist/repl/tui/renderer.d.ts +2 -1
  79. package/dist/repl/tui/renderer.d.ts.map +1 -1
  80. package/dist/repl/tui/renderer.js +20 -3
  81. package/dist/repl/tui/renderer.js.map +1 -1
  82. package/dist/repl/tui/status-bar.d.ts +5 -2
  83. package/dist/repl/tui/status-bar.d.ts.map +1 -1
  84. package/dist/repl/tui/status-bar.js +8 -3
  85. package/dist/repl/tui/status-bar.js.map +1 -1
  86. package/dist/repl/tui/tool-pane.d.ts +1 -1
  87. package/dist/repl/tui/tool-pane.d.ts.map +1 -1
  88. package/dist/repl/tui/tool-pane.js +13 -7
  89. package/dist/repl/tui/tool-pane.js.map +1 -1
  90. package/dist/repl/tui/work-view.d.ts +10 -0
  91. package/dist/repl/tui/work-view.d.ts.map +1 -0
  92. package/dist/repl/tui/work-view.js +28 -0
  93. package/dist/repl/tui/work-view.js.map +1 -0
  94. package/dist/runner.d.ts.map +1 -1
  95. package/dist/runner.js +50 -19
  96. package/dist/runner.js.map +1 -1
  97. package/dist/runtime-identity.json +10 -0
  98. package/dist/system/assets/docs/AGENT_PROMPT.md +265 -3008
  99. package/dist/system/assets/docs/DML_AUTHORING.md +81 -299
  100. package/dist/system/assets/docs/DML_BASICS.md +93 -0
  101. package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
  102. package/dist/system/assets/docs/DML_FORMS.md +94 -728
  103. package/dist/system/assets/docs/DML_MEDIA.md +63 -0
  104. package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
  105. package/dist/system/assets/docs/DML_PYTHON.md +74 -0
  106. package/dist/system/assets/docs/DML_REFERENCE.md +224 -1971
  107. package/dist/system/assets/docs/DML_SHELL.md +107 -0
  108. package/dist/system/assets/docs/DML_TASKS.md +112 -0
  109. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
  110. package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
  111. package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
  112. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
  113. package/dist/system/assets/index.d.ts +1 -1
  114. package/dist/system/assets/index.d.ts.map +1 -1
  115. package/dist/system/assets/index.js +7 -0
  116. package/dist/system/assets/index.js.map +1 -1
  117. package/dist/system/environment.d.ts +1 -1
  118. package/dist/system/environment.d.ts.map +1 -1
  119. package/dist/system/environment.js +10 -6
  120. package/dist/system/environment.js.map +1 -1
  121. package/dist/system/runtime/shell-manager.d.ts +1 -1
  122. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  123. package/dist/types.d.ts +49 -2
  124. package/dist/types.d.ts.map +1 -1
  125. package/dist/work/index.d.ts +82 -0
  126. package/dist/work/index.d.ts.map +1 -0
  127. package/dist/work/index.js +232 -0
  128. package/dist/work/index.js.map +1 -0
  129. package/package.json +12 -3
  130. package/src/prolog-src/deepclause_mi.pl +2426 -253
  131. package/src/prolog-src/deepclause_strings.pl +36 -3
@@ -0,0 +1,107 @@
1
+ # Work shell contract
2
+
3
+ Use a normal shell assistant for ordinary conversation, even with a custom
4
+ persona, welcome or tools. Write a DML chat loop only for explicitly custom
5
+ turn-by-turn control logic. A shell library needs no `agent_main`.
6
+
7
+ ## Agent shell
8
+
9
+ ```prolog
10
+ length_of(Text, N) :- string_length(Text, N).
11
+ label(Text, Label) :- prompt("Give a short title for: {Text}", string(Label)).
12
+ shell(_{
13
+ kind: agent,
14
+ system: "You are a concise writing assistant.",
15
+ host_tools: [],
16
+ tools: [_{name: "text_length", goal: "length_of", description: "Count characters.",
17
+ inputs: [_{name: "Text", type: string}], outputs: [_{name: "N", type: integer}]}],
18
+ workflows: [_{name: "Create title", goal: "label",
19
+ inputs: [_{name: "Text", type: string}], outputs: [_{name: "Label", type: string}]}],
20
+ welcome: "Ask about text, or create a title."
21
+ }).
22
+ ```
23
+
24
+ The Work assistant gets real typed tools plus `run_workflow` if workflows exist.
25
+ It does not get DML/authoring tools such as `execute`, `listing` or `define`.
26
+ Describe persona/domain in `system`; put capability semantics in tool descriptions.
27
+ `welcome` is Markdown. Users can edit this contract in the web Shell editor or in
28
+ Develop. TUI Work is entered with `deepclause repl --mode work --harness NAME`;
29
+ `/workflows` opens its chooser. Without a shell, use Develop or an explicit Run;
30
+ internal predicates are never automatically exported.
31
+
32
+ ## Metadata names must be text, not variables
33
+
34
+ Write `name: "Query"`, `name: "Url"`, `name: "Report"` (or quoted atoms).
35
+ Bare capitalized `Query`, `Url`, `Report` are Prolog variables, not labels. They
36
+ produce unbound/empty runtime parameter names. The visual editor quotes names
37
+ for you; when authoring DML directly, include the quotes.
38
+
39
+ `end_turn` refuses an invalid shell before publishing a version. Keep the
40
+ transaction open, correct the declarations, then commit again. Full-source
41
+ editor saves are checked too. This validates the Work interface; executing a
42
+ backing predicate alone is not a substitute for validating its tool declaration.
43
+
44
+ ## Inputs and outputs
45
+
46
+ For EVERY tool/workflow, actual predicate arguments are inputs followed by outputs,
47
+ in declared order. Arity = input count + output count. Manual starts ask only
48
+ inputs, leaving outputs unbound. Bind outputs and return; do not call `answer/1`
49
+ in place of returning them. An output cannot be left unbound just because text
50
+ was printed. Use zero outputs explicitly for a side-effect-only workflow.
51
+
52
+ Supported Work boundary types are string, integer, number, boolean and file.
53
+ A `file` input is a workspace-relative path supplied by the picker/upload, not raw
54
+ bytes or a raw Prolog term. Object/array boundary types are currently rejected;
55
+ use a JSON string or a file instead. General task/schema outputs still support
56
+ complex values. Runtime tool schemas are authoritative, not a wish list.
57
+ Old `args` is legacy input data only; author new shells with `inputs`/`outputs`.
58
+
59
+ ## Workflows versus tools
60
+
61
+ A workflow is a recurring user task with a prescribed result, e.g. intake,
62
+ reporting or a review. Users can start it from the sidebar; the assistant can use
63
+ `run_workflow(name, inputs)`. A tool is a composable capability the ASSISTANT
64
+ chooses. Tools appear for discovery but cannot be run directly from the sidebar.
65
+ Do not export internal helpers, docs, schemas or all predicates indiscriminately.
66
+
67
+ `shell.tools` is NOT `tool/2`: the latter exposes a predicate to a nested agent
68
+ inside `task/N`, with a single last output and input types in its annotation.
69
+ A predicate may participate in both interfaces if needed, with one implementation.
70
+ Host tools are a third surface (`exec/2`); `host_tools: [show_image]` allows the
71
+ Work image-display helper, not arbitrary DML/host execution.
72
+
73
+ ## Workflow-only shell
74
+
75
+ ```prolog
76
+ uppercase(Text, Upper) :- string_upper(Text, Upper).
77
+ shell(_{kind: workflow, system: "", host_tools: [], tools: [],
78
+ workflows: [_{name: "Uppercase", goal: "uppercase",
79
+ inputs: [_{name: "Text", type: string}],
80
+ outputs: [_{name: "Upper", type: string}]}], welcome: "Choose a task."}).
81
+ ```
82
+
83
+ There is no assistant loop. A manual start executes exactly the selected workflow
84
+ with validated inputs and no intervening assistant call, for BOTH shell kinds.
85
+ Outputs are named typed values; no solution/unbound output/cancel/suspend is not
86
+ success. Active Work conversations are pinned to their program/script snapshot;
87
+ refresh opens a new one instead of mixing an old shell with new code.
88
+ Interactive workflows must run through foreground form/input handlers. Browser
89
+ scratch `execute` workers and worker-hosted processes do not support forms.
90
+ Test pure validation/headless paths separately from actual foreground form submits.
91
+
92
+ ## Custom conversation
93
+
94
+ A custom DML `input/1` + `chat/1` loop is for a required protocol or per-turn
95
+ state, e.g. staged intake that validates each stage before advancing. Merely
96
+ asking for a conversational agent or changing its persona does not require it.
97
+ Use `next/1` only if the conversation must also react to process messages.
98
+ Such loops must run in foreground with an input host, not inside scratch execute.
99
+ See `examples` section `custom-intake` for a minimal custom staged protocol.
100
+
101
+ ## Authoring and validation
102
+
103
+ Define the shell together with the predicates it exposes in one transaction.
104
+ Validate goal names/arities, unique tool/workflow names, input/output types and
105
+ bound output values. Keep the shell small and its descriptions specific.
106
+ A shell change refreshes Work; an already-running process still has its old
107
+ harness snapshot. Do not assume a live process updates with edits.
@@ -0,0 +1,112 @@
1
+ # Model calls, schemas and nested tools
2
+
3
+ Choose by tools, memory and output contract, not by which name sounds familiar.
4
+
5
+ ## Selecting a model operation
6
+
7
+ | Operation | Context | Tools | Result |
8
+ |---|---|---|---|
9
+ | `prompt(Description, Type(Out))` | fresh; no memory read/write | no callable harness tools | typed output |
10
+ | `task(Description, Type(Out))` | DML harness memory; reply accumulates | declared nested tools, scoped explicitly | typed output |
11
+ | `llm(Messages, Reply)` | explicit message list (or supported text input) | none | raw text; no memory writeback |
12
+ | `chat(Message[, Reply])` | ongoing DML conversation | nested tools | conversational reply |
13
+ | `choose/rate/verify/judge` | explicit evidence/state | none | constrained semantic judgment |
14
+
15
+ For a normal Work assistant, use `shell/1`; `chat` is only for an explicitly
16
+ custom conversation protocol. `task/1` and `prompt/1` discard structured outputs;
17
+ prefer output-bearing forms when a later step needs the value.
18
+
19
+ ## Typed outputs
20
+
21
+ A bare output variable is a string. Supported common wrappers:
22
+ `string(X)`, `integer(X)`, `number(X)`, `float(X)`, `boolean(X)`,
23
+ `list(string(Xs))`, `object(D)`, `schema(person, D)`,
24
+ `list(schema(person, Ds))`. Types are checked by the runtime, not just prose.
25
+ `media(X)` is image generation, not a general file output, and needs an image backend.
26
+
27
+ ```prolog
28
+ schema(person, [field(name, string, required), field(age, integer, default(0))]).
29
+ extract_person(Text, Person) :-
30
+ prompt("Extract a person from: {Text}", schema(person, Person)).
31
+ ```
32
+
33
+ Schema field types include primitives, `list(Type)` and nested `schema(Name)` /
34
+ `schema(Name, _)`. Defaults fill missing fields; missing required/wrong-typed
35
+ fields fail validation; undeclared fields are retained. `schema_fill/3` applies a
36
+ schema to an existing dict. Keep one structured result per conceptual step.
37
+ Multiple typed outputs are possible; use the actual argument names consistently.
38
+
39
+ ## Memory
40
+
41
+ Authoring conversation, Work chat and DML harness memory are different stores.
42
+ A task sees ONLY harness memory (prior DML `system`, `user`, `task` messages),
43
+ not the authoring user's whole conversation. Pass the input explicitly.
44
+ Consecutive tasks accumulate conversation memory; prompts neither read nor change
45
+ it. Do not assume a typed result is restated in assistant prose or all tool results
46
+ remain in memory; pass the actual bound outputs explicitly to the next step.
47
+
48
+ ```prolog
49
+ explain(Text, Report) :-
50
+ with_fresh_memory((
51
+ task("Find the main claim: {Text}", string(Claim)),
52
+ task("Explain the claim using only {Text}: {Claim}", string(Report))
53
+ )).
54
+ ```
55
+
56
+ `with_fresh_memory/1` isolates a group: its tasks share memory WITH EACH OTHER,
57
+ then the original memory is restored. `system/1` and `user/1` changes are
58
+ backtrackable. A task inside a nested `tool/N` engine starts fresh: context must
59
+ be an input or supplied with `system/1` inside that body. A process has its own
60
+ memory snapshot. Attached media is harness memory, so a fresh `prompt/N` will
61
+ not see an image attached for a task.
62
+
63
+ ## Nested tools
64
+
65
+ Host registration is NOT nested-agent exposure. `exec(python(...), R)` calls a
66
+ host capability from DML. To offer a capability to a nested task, define the
67
+ predicate AND its thin annotation:
68
+
69
+ ```prolog
70
+ length_of(Text, N) :- string_length(Text, N).
71
+ tool(length_of(Text, N), "Count text characters.", [string]) :- length_of(Text, N).
72
+ inspect(Text, Reply) :-
73
+ with_tools([length_of], task("Use length_of on {Text}; report its result.", string(Reply))).
74
+ ```
75
+
76
+ The annotation and delegate share name AND arity. Exactly one output, LAST;
77
+ all earlier arguments are inputs. The optional type list describes input types
78
+ only (default string). A write capability needs e.g. `(Path, Content, Result)`,
79
+ not `(Path, Content)`. Several result fields belong in a dict.
80
+ Use names in `with_tools`, not indicators. `without_tools/2` excludes names.
81
+ Tool-free tasks can use `with_tools([], task(...))`; task result/finish machinery
82
+ is internal, not a harness tool you must write. Built-in form tools are otherwise
83
+ available to tasks, so scope non-form work.
84
+
85
+ Do not implement the work ONLY inside an annotation: DML callers invoke the real
86
+ predicate. Do not advertise an LLM step as the very tool offered inside its own
87
+ task; keep it a skill or explicitly exclude that tool to prevent self-delegation.
88
+ `shell.tools` is a DIFFERENT, explicit Work-agent interface; no annotation is
89
+ needed unless a nested task needs the same capability.
90
+
91
+ ## Data and evidence
92
+
93
+ Interpolate bound DML data with `{Var}` in task/prompt descriptions. Include the
94
+ actual input in every step; variable names alone do not supply their values.
95
+ Use typed extraction, then deterministic guards. A successful model response is
96
+ not evidence that a file was saved or an API action completed. Inspect the host
97
+ result, check `exitCode` for Python, and do not ask a model to fill missing data.
98
+ Use `dict_field/3,4` for varying model keys, `get_dict/3` for keys you control,
99
+ and `json_get/3,4` / `json_gets/3` for paths and projections.
100
+
101
+ ## Judgments and models
102
+
103
+ `choose(State, Question, Options, Choice)` returns an option atom.
104
+ `rate(State, Question, Levels, Level)` returns a supplied level.
105
+ `verify(State, Question, Truth)` returns `yes | no | unknown`; `probability/3`
106
+ returns a number; `holds/2` succeeds for yes. `judge(State, Specs)` batches
107
+ questions such as `choose(Question, Options)-Choice` in one request.
108
+ Judgments do not see task memory or images. Supply observed evidence as State;
109
+ `unknown` is not no, and neither is a failed goal.
110
+ `with_model(Spec, Goal)` changes task/prompt/llm model selection, not judgment
111
+ backend selection; use only model ids available in this session. Read the exact
112
+ scopes and backend capabilities in the language reference before relying on them.