deepclause-sdk 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +57 -0
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +5 -0
  5. package/dist/agent.js.map +1 -1
  6. package/dist/cli/agent-inbox.d.ts +25 -0
  7. package/dist/cli/agent-inbox.d.ts.map +1 -0
  8. package/dist/cli/agent-inbox.js +46 -0
  9. package/dist/cli/agent-inbox.js.map +1 -0
  10. package/dist/cli/config.d.ts +28 -28
  11. package/dist/cli/index.d.ts +1 -1
  12. package/dist/cli/index.js +7 -2
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/cli/repl.d.ts +7 -0
  15. package/dist/cli/repl.d.ts.map +1 -1
  16. package/dist/cli/repl.js +181 -13
  17. package/dist/cli/repl.js.map +1 -1
  18. package/dist/cli/run.d.ts +1 -0
  19. package/dist/cli/run.d.ts.map +1 -1
  20. package/dist/cli/run.js +3 -1
  21. package/dist/cli/run.js.map +1 -1
  22. package/dist/cli/serve.d.ts +3 -0
  23. package/dist/cli/serve.d.ts.map +1 -0
  24. package/dist/cli/serve.js +131 -0
  25. package/dist/cli/serve.js.map +1 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/judge/llm.d.ts.map +1 -1
  30. package/dist/judge/llm.js +9 -4
  31. package/dist/judge/llm.js.map +1 -1
  32. package/dist/judge/types.d.ts +10 -0
  33. package/dist/judge/types.d.ts.map +1 -1
  34. package/dist/judge/types.js.map +1 -1
  35. package/dist/prolog-src/deepclause_mi.pl +370 -54
  36. package/dist/repl/agent-inbox.d.ts +73 -0
  37. package/dist/repl/agent-inbox.d.ts.map +1 -0
  38. package/dist/repl/agent-inbox.js +168 -0
  39. package/dist/repl/agent-inbox.js.map +1 -0
  40. package/dist/repl/agent.d.ts +14 -1
  41. package/dist/repl/agent.d.ts.map +1 -1
  42. package/dist/repl/agent.js +25 -6
  43. package/dist/repl/agent.js.map +1 -1
  44. package/dist/repl/backend.d.ts +6 -0
  45. package/dist/repl/backend.d.ts.map +1 -1
  46. package/dist/repl/backend.js +17 -2
  47. package/dist/repl/backend.js.map +1 -1
  48. package/dist/repl/event-history.d.ts.map +1 -1
  49. package/dist/repl/event-history.js +3 -0
  50. package/dist/repl/event-history.js.map +1 -1
  51. package/dist/repl/harness-tools.d.ts +9 -2
  52. package/dist/repl/harness-tools.d.ts.map +1 -1
  53. package/dist/repl/harness-tools.js +38 -14
  54. package/dist/repl/harness-tools.js.map +1 -1
  55. package/dist/repl/history.d.ts +14 -3
  56. package/dist/repl/history.d.ts.map +1 -1
  57. package/dist/repl/history.js +62 -5
  58. package/dist/repl/history.js.map +1 -1
  59. package/dist/repl/index.d.ts +11 -0
  60. package/dist/repl/index.d.ts.map +1 -1
  61. package/dist/repl/index.js +6 -2
  62. package/dist/repl/index.js.map +1 -1
  63. package/dist/repl/process-backend.d.ts +1 -0
  64. package/dist/repl/process-backend.d.ts.map +1 -1
  65. package/dist/repl/process-executor.d.ts +4 -0
  66. package/dist/repl/process-executor.d.ts.map +1 -1
  67. package/dist/repl/process-executor.js +36 -1
  68. package/dist/repl/process-executor.js.map +1 -1
  69. package/dist/repl/process-worker.d.ts.map +1 -1
  70. package/dist/repl/process-worker.js +33 -8
  71. package/dist/repl/process-worker.js.map +1 -1
  72. package/dist/repl/processes.d.ts +14 -1
  73. package/dist/repl/processes.d.ts.map +1 -1
  74. package/dist/repl/processes.js +8 -2
  75. package/dist/repl/processes.js.map +1 -1
  76. package/dist/repl/reference.d.ts.map +1 -1
  77. package/dist/repl/reference.js +4 -3
  78. package/dist/repl/reference.js.map +1 -1
  79. package/dist/repl/render.d.ts.map +1 -1
  80. package/dist/repl/render.js +13 -0
  81. package/dist/repl/render.js.map +1 -1
  82. package/dist/repl/session.d.ts +72 -5
  83. package/dist/repl/session.d.ts.map +1 -1
  84. package/dist/repl/session.js +595 -42
  85. package/dist/repl/session.js.map +1 -1
  86. package/dist/repl/toolset.d.ts +8 -0
  87. package/dist/repl/toolset.d.ts.map +1 -1
  88. package/dist/repl/toolset.js +53 -4
  89. package/dist/repl/toolset.js.map +1 -1
  90. package/dist/repl/tui/renderer.d.ts.map +1 -1
  91. package/dist/repl/tui/renderer.js +3 -1
  92. package/dist/repl/tui/renderer.js.map +1 -1
  93. package/dist/repl/work-hooks.d.ts +29 -0
  94. package/dist/repl/work-hooks.d.ts.map +1 -0
  95. package/dist/repl/work-hooks.js +117 -0
  96. package/dist/repl/work-hooks.js.map +1 -0
  97. package/dist/repl/worker-host.d.ts +2 -0
  98. package/dist/repl/worker-host.d.ts.map +1 -1
  99. package/dist/repl/worker-host.js +48 -4
  100. package/dist/repl/worker-host.js.map +1 -1
  101. package/dist/repl/worker-protocol.d.ts +23 -2
  102. package/dist/repl/worker-protocol.d.ts.map +1 -1
  103. package/dist/repl/worker-protocol.js +1 -1
  104. package/dist/runner.d.ts +2 -2
  105. package/dist/runner.d.ts.map +1 -1
  106. package/dist/runner.js +19 -3
  107. package/dist/runner.js.map +1 -1
  108. package/dist/runtime-identity.json +6 -6
  109. package/dist/serve/agent-broadcast.d.ts +29 -0
  110. package/dist/serve/agent-broadcast.d.ts.map +1 -0
  111. package/dist/serve/agent-broadcast.js +28 -0
  112. package/dist/serve/agent-broadcast.js.map +1 -0
  113. package/dist/serve/agent-preferences.d.ts +16 -0
  114. package/dist/serve/agent-preferences.d.ts.map +1 -0
  115. package/dist/serve/agent-preferences.js +42 -0
  116. package/dist/serve/agent-preferences.js.map +1 -0
  117. package/dist/serve/api-docs.d.ts +61 -0
  118. package/dist/serve/api-docs.d.ts.map +1 -0
  119. package/dist/serve/api-docs.js +122 -0
  120. package/dist/serve/api-docs.js.map +1 -0
  121. package/dist/serve/backend.d.ts +12 -0
  122. package/dist/serve/backend.d.ts.map +1 -0
  123. package/dist/serve/backend.js +52 -0
  124. package/dist/serve/backend.js.map +1 -0
  125. package/dist/serve/capabilities.d.ts +6 -0
  126. package/dist/serve/capabilities.d.ts.map +1 -0
  127. package/dist/serve/capabilities.js +21 -0
  128. package/dist/serve/capabilities.js.map +1 -0
  129. package/dist/serve/example-agent.d.ts +5 -0
  130. package/dist/serve/example-agent.d.ts.map +1 -0
  131. package/dist/serve/example-agent.js +5 -0
  132. package/dist/serve/example-agent.js.map +1 -0
  133. package/dist/serve/files.d.ts +55 -0
  134. package/dist/serve/files.d.ts.map +1 -0
  135. package/dist/serve/files.js +249 -0
  136. package/dist/serve/files.js.map +1 -0
  137. package/dist/serve/harness.d.ts +3 -0
  138. package/dist/serve/harness.d.ts.map +1 -0
  139. package/dist/serve/harness.js +53 -0
  140. package/dist/serve/harness.js.map +1 -0
  141. package/dist/serve/previews.d.ts +40 -0
  142. package/dist/serve/previews.d.ts.map +1 -0
  143. package/dist/serve/previews.js +240 -0
  144. package/dist/serve/previews.js.map +1 -0
  145. package/dist/serve/protocol.d.ts +228 -0
  146. package/dist/serve/protocol.d.ts.map +1 -0
  147. package/dist/serve/protocol.js +2 -0
  148. package/dist/serve/protocol.js.map +1 -0
  149. package/dist/serve/schedules.d.ts +85 -0
  150. package/dist/serve/schedules.d.ts.map +1 -0
  151. package/dist/serve/schedules.js +249 -0
  152. package/dist/serve/schedules.js.map +1 -0
  153. package/dist/serve/server.d.ts +50 -0
  154. package/dist/serve/server.d.ts.map +1 -0
  155. package/dist/serve/server.js +1696 -0
  156. package/dist/serve/server.js.map +1 -0
  157. package/dist/serve/session-worker.d.ts +2 -0
  158. package/dist/serve/session-worker.d.ts.map +1 -0
  159. package/dist/serve/session-worker.js +291 -0
  160. package/dist/serve/session-worker.js.map +1 -0
  161. package/dist/serve/sessions.d.ts +178 -0
  162. package/dist/serve/sessions.d.ts.map +1 -0
  163. package/dist/serve/sessions.js +905 -0
  164. package/dist/serve/sessions.js.map +1 -0
  165. package/dist/serve/storage.d.ts +41 -0
  166. package/dist/serve/storage.d.ts.map +1 -0
  167. package/dist/serve/storage.js +211 -0
  168. package/dist/serve/storage.js.map +1 -0
  169. package/dist/serve/ui/api-docs.html +17 -0
  170. package/dist/serve/ui/api-docs.js +36 -0
  171. package/dist/serve/ui/app.js +958 -0
  172. package/dist/serve/ui/authoring.js +92 -0
  173. package/dist/serve/ui/deepclause-logo.png +0 -0
  174. package/dist/serve/ui/deepclause-mark.svg +1 -0
  175. package/dist/serve/ui/diff.js +16 -0
  176. package/dist/serve/ui/dompurify-LICENSE.txt +202 -0
  177. package/dist/serve/ui/features.css +15 -0
  178. package/dist/serve/ui/files.js +13 -0
  179. package/dist/serve/ui/ibm-plex-mono-latin.woff2 +0 -0
  180. package/dist/serve/ui/ibmplexmono-OFL.txt +93 -0
  181. package/dist/serve/ui/icons.js +30 -0
  182. package/dist/serve/ui/index.html +68 -0
  183. package/dist/serve/ui/manrope-OFL.txt +93 -0
  184. package/dist/serve/ui/manrope-latin.woff2 +0 -0
  185. package/dist/serve/ui/markdown.js +38 -0
  186. package/dist/serve/ui/marked-LICENSE.txt +44 -0
  187. package/dist/serve/ui/marked.js +88 -0
  188. package/dist/serve/ui/purify.js +2454 -0
  189. package/dist/serve/ui/style.css +249 -0
  190. package/dist/serve/ui/web-work.css +247 -0
  191. package/dist/serve/ui/web.css +1848 -0
  192. package/dist/serve/workflow-bundles.d.ts +8 -0
  193. package/dist/serve/workflow-bundles.d.ts.map +1 -0
  194. package/dist/serve/workflow-bundles.js +78 -0
  195. package/dist/serve/workflow-bundles.js.map +1 -0
  196. package/dist/serve/workflow-calls.d.ts +6 -0
  197. package/dist/serve/workflow-calls.d.ts.map +1 -0
  198. package/dist/serve/workflow-calls.js +13 -0
  199. package/dist/serve/workflow-calls.js.map +1 -0
  200. package/dist/serve/workflows.d.ts +93 -0
  201. package/dist/serve/workflows.d.ts.map +1 -0
  202. package/dist/serve/workflows.js +219 -0
  203. package/dist/serve/workflows.js.map +1 -0
  204. package/dist/system/assets/docs/AGENT_PROMPT.md +6 -6
  205. package/dist/system/assets/docs/DML_AUTHORING.md +80 -2
  206. package/dist/system/assets/docs/DML_PROCESSES.md +24 -0
  207. package/dist/system/assets/docs/DML_REFERENCE.md +98 -10
  208. package/dist/system/assets/docs/DML_SHELL.md +149 -7
  209. package/dist/system/assets/docs/DML_TASKS.md +10 -3
  210. package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +6 -6
  211. package/dist/system/environment.d.ts +5 -1
  212. package/dist/system/environment.d.ts.map +1 -1
  213. package/dist/system/environment.js +14 -8
  214. package/dist/system/environment.js.map +1 -1
  215. package/dist/system/runtime/agentvm-manager.d.ts +12 -1
  216. package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
  217. package/dist/system/runtime/agentvm-manager.js +136 -20
  218. package/dist/system/runtime/agentvm-manager.js.map +1 -1
  219. package/dist/system/runtime/shell-manager.d.ts +3 -0
  220. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  221. package/dist/system/runtime/shell-manager.js +1 -1
  222. package/dist/system/runtime/shell-manager.js.map +1 -1
  223. package/dist/system/timezone.d.ts +20 -0
  224. package/dist/system/timezone.d.ts.map +1 -0
  225. package/dist/system/timezone.js +37 -0
  226. package/dist/system/timezone.js.map +1 -0
  227. package/dist/types.d.ts +37 -1
  228. package/dist/types.d.ts.map +1 -1
  229. package/dist/work/index.d.ts +13 -3
  230. package/dist/work/index.d.ts.map +1 -1
  231. package/dist/work/index.js +80 -15
  232. package/dist/work/index.js.map +1 -1
  233. package/docs/DEEP_RESEARCH_EXAMPLE.md +127 -0
  234. package/docs/SERVE.md +664 -0
  235. package/docs/WORK_AGENT_HOOKS_PLAN.md +416 -0
  236. package/docs/WORK_AGENT_INBOX.md +140 -0
  237. package/docs/WORK_AGENT_INBOX_PLAN.md +91 -0
  238. package/docs/WORK_MODE.md +269 -0
  239. package/package.json +24 -2
  240. package/sdk-examples/deep-research.dml +144 -0
  241. package/sdk-examples/deep-research.py +502 -0
  242. package/sdk-examples/hooked-agent.dml +49 -0
  243. package/sdk-examples/subagent-inbox.dml +66 -0
  244. package/src/prolog-src/deepclause_mi.pl +370 -54
@@ -2383,6 +2383,10 @@ repl_shell_spec(SessionId, Spec) :-
2383
2383
  -> shell_from_one(One, Spec)
2384
2384
  ; clause(SessionId:shell(Agent, Workflows, Welcome), true)
2385
2385
  -> shell_from_parts(Agent, Workflows, Welcome, Spec)
2386
+ ; current_predicate(SessionId:workflow/1),
2387
+ findall(Entry, clause(SessionId:workflow(Entry),true), [Declared]),
2388
+ repl_workflow_literal(Declared),workflow_from(Declared,Workflow),
2389
+ Spec=shell_spec{kind:workflow,system:"Execute the declared workflow.",hostTools:[],tools:[],workflows:[Workflow],welcome:""}
2386
2390
  ).
2387
2391
 
2388
2392
  shell_from_one(workflow(Items), Spec) :-
@@ -2422,7 +2426,16 @@ shell_from_dict(Dict, Spec) :-
2422
2426
  ( get_dict(tools, Dict, ToolsList0) -> tools_term(ToolsList0, ToolSpecs) ; ToolSpecs = [] ),
2423
2427
  ( get_dict(workflows, Dict, Wfs0) -> workflows_term(Wfs0, Workflows) ; Workflows = [] ),
2424
2428
  ( get_dict(welcome, Dict, Welcome0) -> text_value(Welcome0, Welcome) ; Welcome = "" ),
2425
- Spec = shell_spec{kind: Kind, system: System, hostTools: Tools, tools: ToolSpecs, workflows: Workflows, welcome: Welcome}.
2429
+ Base = shell_spec{kind: Kind, system: System, hostTools: Tools, tools: ToolSpecs, workflows: Workflows, welcome: Welcome},
2430
+ ( get_dict(hooks, Dict, Hooks0)
2431
+ -> is_dict(Hooks0), dict_pairs(Hooks0, _, Pairs),
2432
+ maplist(shell_hook_pair, Pairs, HookPairs),
2433
+ dict_pairs(Hooks, hooks, HookPairs), put_dict(hooks, Base, Hooks, WithHooks)
2434
+ ; WithHooks = Base
2435
+ ),
2436
+ ( get_dict(inbox, Dict, Inbox) -> put_dict(inbox, WithHooks, Inbox, Spec) ; Spec = WithHooks ).
2437
+
2438
+ shell_hook_pair(Key-Value, Key-Text) :- text_value(Value, Text).
2426
2439
 
2427
2440
  shell_infer_kind(Dict, Kind) :-
2428
2441
  ( get_dict(system, Dict, _)
@@ -2483,7 +2496,8 @@ workflow_from(Dict, Workflow) :-
2483
2496
  is_dict(Dict),
2484
2497
  !,
2485
2498
  workflow_dict_parts(Dict, Name, Goal, Inputs, Outputs),
2486
- Workflow = shell_workflow{name: Name, goal: Goal, inputs: Inputs, outputs: Outputs}.
2499
+ Base = shell_workflow{name: Name, goal: Goal, inputs: Inputs, outputs: Outputs},
2500
+ (get_dict(description,Dict,Desc0) -> text_value(Desc0,Description),put_dict(description,Base,Description,Workflow) ; Workflow=Base).
2487
2501
 
2488
2502
  workflow_dict_parts(Dict, Name, Goal, Inputs, Outputs) :-
2489
2503
  ( get_dict(name, Dict, Name0) -> text_value(Name0, Name) ; Name = "" ),
@@ -2529,11 +2543,12 @@ workflow_arg(Type:Label, shell_arg{name: Name, type: TypeText}) :-
2529
2543
  !,
2530
2544
  text_value(Label, Name),
2531
2545
  text_value(Type, TypeText).
2532
- workflow_arg(Dict, shell_arg{name: Name, type: TypeText}) :-
2546
+ workflow_arg(Dict, Arg) :-
2533
2547
  is_dict(Dict),
2534
2548
  !,
2535
2549
  ( get_dict(name, Dict, N0) -> text_value(N0, Name) ; Name = "" ),
2536
- ( get_dict(type, Dict, T0) -> text_value(T0, TypeText) ; TypeText = "string" ).
2550
+ ( get_dict(type, Dict, T0) -> text_value(T0, TypeText) ; TypeText = "string" ),
2551
+ workflow_arg_metadata([description,required,default], Dict, shell_arg{name:Name,type:TypeText}, Arg).
2537
2552
  workflow_arg(arg(Name0, Type0), shell_arg{name: Name, type: TypeText}) :-
2538
2553
  !,
2539
2554
  text_value(Name0, Name),
@@ -2542,6 +2557,11 @@ workflow_arg(Value, shell_arg{name: Value, type: "string"}) :- atom(Value), !.
2542
2557
  workflow_arg(Value, shell_arg{name: Value, type: "string"}) :- string(Value), !.
2543
2558
  workflow_arg(_, shell_arg{name: "", type: "string"}).
2544
2559
 
2560
+ workflow_arg_metadata([], _, Arg, Arg).
2561
+ workflow_arg_metadata([Key|Keys], Dict, In, Out) :-
2562
+ ( get_dict(Key, Dict, Value) -> Next=In.put(Key,Value) ; Next=In ),
2563
+ workflow_arg_metadata(Keys, Dict, Next, Out).
2564
+
2545
2565
  text_value(Value, Text) :-
2546
2566
  ( string(Value) -> Text = Value
2547
2567
  ; atom(Value) -> atom_string(Value, Text)
@@ -2562,10 +2582,12 @@ repl_display_output(SessionId) :-
2562
2582
  export_tools(SessionId),
2563
2583
  repl_display_clauses(SessionId).
2564
2584
 
2565
- repl_display_clauses(SessionId) :-
2585
+ repl_display_clauses(SessionId) :- repl_display_clauses(SessionId, []).
2586
+ repl_display_clauses(SessionId, Excluded) :-
2566
2587
  findall(Name/Arity,
2567
2588
  ( current_predicate(SessionId:Name/Arity),
2568
- export_user_predicate(SessionId, Name, Arity)
2589
+ export_user_predicate(SessionId, Name, Arity),
2590
+ \+ memberchk(Name/Arity, Excluded)
2569
2591
  ),
2570
2592
  Preds0),
2571
2593
  sort(Preds0, Preds),
@@ -2878,6 +2900,44 @@ repl_set_prolog_snippets(SessionId, Text) :-
2878
2900
  retractall(session_prolog_snippets(SessionId, _)),
2879
2901
  assertz(session_prolog_snippets(SessionId, Text)).
2880
2902
 
2903
+ %% Host-scoped workflow authoring: inspect before any edit/load. Only trusted
2904
+ %% standard-library operator imports run during parsing; never arbitrary directives.
2905
+ %% Partial blocks are allowed for define; complete files require one literal interface.
2906
+ repl_validate_workflow_source(SessionId, Code, Complete, Result) :-
2907
+ catch((setup_call_cleanup(open_string(Code,Stream),repl_workflow_read_terms(Stream,SessionId,Terms),close(Stream)),
2908
+ forall(member(Term,Terms),repl_workflow_owned_term(SessionId,Term)),
2909
+ ( Complete==true -> findall(Entry,member(workflow(Entry),Terms),[Entry]),repl_workflow_literal(Entry),is_dict(Entry),
2910
+ dict_pairs(Entry,_,Pairs),forall(member(Key-_,Pairs),memberchk(Key,[name,goal,inputs,outputs,description])) ; true ),
2911
+ Result=ok),Error,format(atom(Result),'error(~w)',[Error])).
2912
+
2913
+ repl_workflow_read_terms(Stream,SessionId,Terms) :-
2914
+ read_term(Stream,Term,[module(SessionId)]),
2915
+ ( Term==end_of_file -> Terms=[]
2916
+ ; (nonvar(Term) -> true ; throw(error(instantiation_error,workflow))),
2917
+ ( Term=(:- use_module(library(Library))),ground(Library),memberchk(Library,[clpfd,clpq,clpr,lists,apply,dcg/basics]) -> catch(SessionId:use_module(library(Library)),_,true) ; true ),
2918
+ Terms=[Term|Rest],repl_workflow_read_terms(Stream,SessionId,Rest) ).
2919
+
2920
+ repl_workflow_literal(Value) :-
2921
+ nonvar(Value),
2922
+ ( is_dict(Value) -> dict_pairs(Value,_,Pairs),forall(member(_-Item,Pairs),repl_workflow_literal(Item))
2923
+ ; is_list(Value) -> maplist(repl_workflow_literal,Value)
2924
+ ; atomic(Value) ).
2925
+
2926
+ repl_workflow_owned_term(SessionId, (:- Directive)) :- !,
2927
+ ( ground(Directive),Directive=use_module(library(Library)),memberchk(Library,[clpfd,clpq,clpr,lists,apply,dcg/basics]) -> true
2928
+ ; ground(Directive),Directive=use_harness(Name,Imports),session_harness_module(SessionId,Name,_,_,_),is_list(Imports) -> true
2929
+ ; ground(Directive),Directive=use_harness(Name,version(Version),Imports),normalize_harness_version(Version,V),session_harness_module(SessionId,Name,V,_,_),is_list(Imports) -> true
2930
+ ; throw(error(permission_error(modify,workflow_dependency,Directive),workflow)) ).
2931
+ repl_workflow_owned_term(SessionId, (Head --> Body)) :- !,repl_workflow_owned_term(SessionId,(Head :- Body)).
2932
+ repl_workflow_owned_term(SessionId, '$dc_tool'(Term,_)) :- !,repl_workflow_owned_term(SessionId,Term).
2933
+ repl_workflow_owned_term(SessionId, (tool(Head,_) :- Body)) :- !,repl_workflow_owned_term(SessionId,(Head :- Body)).
2934
+ repl_workflow_owned_term(SessionId, (tool(Head,_,_) :- Body)) :- !,repl_workflow_owned_term(SessionId,(Head :- Body)).
2935
+ repl_workflow_owned_term(SessionId, Term) :-
2936
+ repl_head_of(Term,Head),
2937
+ ( Head=workflow(Entry) -> (Term=workflow(Entry),repl_workflow_literal(Entry),is_dict(Entry) -> true ; throw(error(domain_error(workflow_interface,Term),workflow)))
2938
+ ; callable(Head),Head\=(_: _),functor(Head,Name,_),Name\==shell,Name\==agent_main,Name\==term_expansion,Name\==goal_expansion,\+sub_atom(Name,0,3,_,bp_),\+sub_atom(Name,0,3,_,dc_),repl_require_committable(SessionId,Term) -> true
2939
+ ; throw(error(permission_error(modify,workflow_owned_source,Head),workflow)) ).
2940
+
2881
2941
  %% repl_parse_clauses(+SessionId, +ClausesText, -Terms)
2882
2942
  %% Parse and preprocess a block of DML clauses without asserting them.
2883
2943
  repl_parse_clauses(SessionId, ClausesText, Terms) :-
@@ -2933,21 +2993,24 @@ repl_store_source_views(SessionId, Views, Mode) :-
2933
2993
 
2934
2994
  repl_store_view_groups(_, [], _).
2935
2995
  repl_store_view_groups(SessionId, [Indicator-Source|Rest], Mode) :-
2936
- repl_same_indicator(Indicator, Rest, [Source], Sources, Remaining),
2937
- atomic_list_concat(Sources, '', NewText),
2996
+ % keysort/2 is stable: retain that order within each predicate. These
2997
+ % views are reloaded as executable snapshots, so rotating even one clause
2998
+ % changes cuts, fallback handlers, and coordinator lookup-before-spawn.
2999
+ repl_same_indicator(Indicator, Rest, Sources, Remaining),
3000
+ atomic_list_concat([Source|Sources], '', NewText),
2938
3001
  ( Mode == append,
2939
3002
  session_source_view(SessionId, Indicator, Existing)
2940
3003
  -> atomic_list_concat([Existing, NewText], '', Text)
2941
- ; retractall(session_source_view(SessionId, Indicator, _)),
2942
- Text = NewText
3004
+ ; Text = NewText
2943
3005
  ),
3006
+ retractall(session_source_view(SessionId, Indicator, _)),
2944
3007
  assertz(session_source_view(SessionId, Indicator, Text)),
2945
3008
  repl_store_view_groups(SessionId, Remaining, Mode).
2946
3009
 
2947
- repl_same_indicator(Indicator, [Indicator-Source|Rest], Acc, [Source|Same], Remaining) :-
3010
+ repl_same_indicator(Indicator, [Indicator-Source|Rest], [Source|Same], Remaining) :-
2948
3011
  !,
2949
- repl_same_indicator(Indicator, Rest, Acc, Same, Remaining).
2950
- repl_same_indicator(_, Rest, Acc, Acc, Rest).
3012
+ repl_same_indicator(Indicator, Rest, Same, Remaining).
3013
+ repl_same_indicator(_, Rest, [], Rest).
2951
3014
 
2952
3015
  %% repl_drop_source_view(+SessionId, +Indicator)
2953
3016
  repl_drop_source_view(SessionId, Indicator) :-
@@ -3836,47 +3899,80 @@ repl_predicate_arities(SessionId, Name, Arities) :-
3836
3899
  %% After a commit, the host may probe each changed pure predicate: if calling it
3837
3900
  %% with fresh variables yields more than a threshold of solutions, the predicate
3838
3901
  %% is probably missing a commit (`once/1` / `!`) and would flood an `execute`.
3839
- %% Side-effecting predicates are never run (see repl_impure_name/1), fact tables
3840
- %% are skipped, and the search is bounded by an inference limit.
3902
+ %% Only a conservative subset of pure logic is eligible. Unknown/native host
3903
+ %% capabilities and exception handlers are skipped, not assumed pure. A catch/3
3904
+ %% retry loop can swallow inference-limit exceptions, hanging this synchronous
3905
+ %% advisory and the entire Node event loop. JavaScript timers cannot preempt it.
3841
3906
  %% ============================================================
3842
3907
 
3843
- %% Functors with side effects: model calls, host tools, file IO, DB mutation.
3844
- repl_impure_name(task). repl_impure_name(prompt). repl_impure_name(exec).
3845
- repl_impure_name(system). repl_impure_name(user). repl_impure_name(answer).
3846
- repl_impure_name(input). repl_impure_name(output). repl_impure_name(read_media).
3847
- repl_impure_name(attach_media). repl_impure_name(save_image). repl_impure_name(gen_image).
3848
- repl_impure_name(judge). repl_impure_name(choose). repl_impure_name(rate).
3849
- repl_impure_name(verify). repl_impure_name(probability).
3850
- repl_impure_name(write_file). repl_impure_name(append_file). repl_impure_name(delete_file).
3851
- repl_impure_name(make_directory_path). repl_impure_name(open). repl_impure_name(close).
3852
- repl_impure_name(assert). repl_impure_name(assertz). repl_impure_name(asserta).
3853
- repl_impure_name(retract). repl_impure_name(retractall).
3854
- repl_impure_name(consult). repl_impure_name(use_module). repl_impure_name(load_files).
3855
-
3856
- %% repl_body_impure(+Goal) — true when the goal tree calls a side-effecting name.
3857
- repl_body_impure(Goal) :-
3858
- callable(Goal),
3859
- functor(Goal, Name, _),
3860
- repl_impure_name(Name),
3861
- !.
3862
- repl_body_impure((A, _)) :- repl_body_impure(A).
3863
- repl_body_impure((_, B)) :- repl_body_impure(B).
3864
- repl_body_impure((A ; B)) :- ( repl_body_impure(A) ; repl_body_impure(B) ).
3865
- repl_body_impure((A -> B)) :- ( repl_body_impure(A) ; repl_body_impure(B) ).
3866
- repl_body_impure(\+ Goal) :- repl_body_impure(Goal).
3867
- repl_body_impure(once(Goal)) :- repl_body_impure(Goal).
3868
- repl_body_impure(ignore(Goal)) :- repl_body_impure(Goal).
3869
- repl_body_impure(forall(Gen, Action)) :- ( repl_body_impure(Gen) ; repl_body_impure(Action) ).
3870
- repl_body_impure(catch(Goal, _, Recovery)) :- ( repl_body_impure(Goal) ; repl_body_impure(Recovery) ).
3871
- repl_body_impure(findall(_, Goal, _)) :- repl_body_impure(Goal).
3872
- repl_body_impure(findall(_, Goal, _, _)) :- repl_body_impure(Goal).
3873
- repl_body_impure(call_with_inference_limit(Goal, _, _)) :- repl_body_impure(Goal).
3874
- repl_body_impure(with_output_to(_, Goal)) :- repl_body_impure(Goal).
3875
- repl_body_impure(_:Goal) :- repl_body_impure(Goal).
3876
-
3877
3908
  repl_predicate_pure(SessionId, Name, Arity) :-
3878
- functor(Head, Name, Arity),
3879
- \+ ( clause(SessionId:Head, Body), repl_body_impure(Body) ).
3909
+ % Bound the static call-graph walk too (shared branches can grow exponentially).
3910
+ catch(call_with_inference_limit(
3911
+ once(repl_probe_safe_predicate(SessionId, Name, Arity, [])), 10000, Status),
3912
+ _, fail),
3913
+ memberchk(Status, [true, !]).
3914
+
3915
+ repl_probe_safe_predicate(SessionId, Name, Arity, Seen) :-
3916
+ ( memberchk(Name/Arity, Seen)
3917
+ -> true
3918
+ ; repl_user_predicate(SessionId, Name, Arity),
3919
+ functor(Head, Name, Arity),
3920
+ forall(clause(SessionId:Head, Body),
3921
+ repl_probe_safe_goal(SessionId, Body, [Name/Arity|Seen]))
3922
+ ).
3923
+
3924
+ %% Inspect data, never execute the inspected body. Recurse through *all* local
3925
+ %% delegates, so wrapping receive/2 or assertz/1 in a helper does not evade this.
3926
+ %% catch/3, call/N, budget overrides, module qualification and opaque libraries
3927
+ %% deliberately have no safe case. Skipping a warning is better than running a
3928
+ %% service, changing the DB, doing IO, or losing the probe's own stopping rule.
3929
+ repl_probe_safe_goal(_, Goal, _) :- var(Goal), !, fail.
3930
+ repl_probe_safe_goal(S, (A, B), Seen) :- !,
3931
+ repl_probe_safe_goal(S, A, Seen), repl_probe_safe_goal(S, B, Seen).
3932
+ repl_probe_safe_goal(S, (A ; B), Seen) :- !,
3933
+ repl_probe_safe_goal(S, A, Seen), repl_probe_safe_goal(S, B, Seen).
3934
+ repl_probe_safe_goal(S, (A -> B), Seen) :- !,
3935
+ repl_probe_safe_goal(S, A, Seen), repl_probe_safe_goal(S, B, Seen).
3936
+ repl_probe_safe_goal(S, \+ A, Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3937
+ repl_probe_safe_goal(S, once(A), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3938
+ repl_probe_safe_goal(S, ignore(A), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3939
+ repl_probe_safe_goal(S, forall(A, B), Seen) :- !,
3940
+ repl_probe_safe_goal(S, A, Seen), repl_probe_safe_goal(S, B, Seen).
3941
+ repl_probe_safe_goal(S, findall(_, A, _), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3942
+ repl_probe_safe_goal(S, findall(_, A, _, _), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3943
+ repl_probe_safe_goal(S, bagof(_, A, _), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3944
+ repl_probe_safe_goal(S, setof(_, A, _), Seen) :- !, repl_probe_safe_goal(S, A, Seen).
3945
+ repl_probe_safe_goal(S, Goal, Seen) :-
3946
+ callable(Goal), functor(Goal, Name, Arity),
3947
+ ( repl_user_predicate(S, Name, Arity)
3948
+ -> repl_probe_safe_predicate(S, Name, Arity, Seen)
3949
+ ; repl_probe_safe_builtin(Name/Arity),
3950
+ ( predicate_property(S:Goal, built_in)
3951
+ ; predicate_property(S:Goal, imported_from(Module)),
3952
+ memberchk(Module, [system, lists])
3953
+ )
3954
+ ).
3955
+
3956
+ %% Closed, non-meta leaves only. In particular, do not allow arbitrary built_in
3957
+ %% predicates: sleep/1, halt/0, assertz/1, IO and flag mutation are built-ins too.
3958
+ repl_probe_safe_builtin(Indicator) :-
3959
+ memberchk(Indicator, [
3960
+ true/0, fail/0, false/0, (!)/0,
3961
+ (=)/2, (\=)/2, (==)/2, (\==)/2, (=@=)/2, (\=@=)/2,
3962
+ is/2, (=:=)/2, (=\=)/2, (<)/2, (>)/2, (=<)/2, (>=)/2,
3963
+ var/1, nonvar/1, atom/1, string/1, integer/1, float/1, number/1,
3964
+ atomic/1, compound/1, callable/1, ground/1, is_list/1, acyclic_term/1,
3965
+ between/3, succ/2, plus/3, compare/3,
3966
+ functor/3, arg/3, (=..)/2, compound_name_arity/3, compound_name_arguments/3,
3967
+ term_variables/2, copy_term/2, sort/2, msort/2, keysort/2,
3968
+ member/2, memberchk/2, append/3, length/2, reverse/2, last/2,
3969
+ nth0/3, nth1/3, select/3, numlist/3,
3970
+ is_dict/1, is_dict/2, get_dict/3, put_dict/3, put_dict/4, dict_pairs/3,
3971
+ atom_length/2, string_length/2, atom_string/2, atom_chars/2, string_chars/2,
3972
+ atom_number/2, number_string/2, atom_concat/3, string_concat/3,
3973
+ sub_atom/5, sub_string/5, downcase_atom/2, upcase_atom/2,
3974
+ string_lower/2, string_upper/2, atomic_list_concat/2, atomic_list_concat/3
3975
+ ]).
3880
3976
 
3881
3977
  %% ============================================================
3882
3978
  %% Tool contract validation (end_turn advisory)
@@ -4502,6 +4598,80 @@ repl_execute_frame(SessionId, GoalText, FrameId, Error) :-
4502
4598
  format(atom(Error), '~w', [ExecuteError])
4503
4599
  ).
4504
4600
 
4601
+ %% A hook uses an owned frame: interpret its body once, then validate outputs
4602
+ %% natively rather than exposing reserved host helpers to interpreted DML.
4603
+ repl_hook_frame(SessionId, GoalText, FrameId, Error) :-
4604
+ catch((
4605
+ read_repl_goal(SessionId, GoalText, Goal, Names),
4606
+ memberchk('HookState'=HookState, Names), memberchk('HookDecision'=Decision, Names),
4607
+ repl_initial_state(SessionId, nested, State),
4608
+ create_frame_raw(SessionId, nested, 1,
4609
+ deepclause_mi:repl_hook_solve(SessionId, Goal, State, HookState, Decision), FrameId),
4610
+ Error = none
4611
+ ), E, format(atom(Error), '~w', [E])).
4612
+
4613
+ repl_hook_solve(SessionId, Goal, State, HookState, Decision) :-
4614
+ nb_setval(current_session_id, SessionId),
4615
+ once(mi_call(Goal, State, StateOut)),
4616
+ repl_hook_result(HookState, Decision, Json),
4617
+ store_memory_for_state(SessionId, StateOut),
4618
+ render_binding(Json, Text), engine_yield(solution(['HookJson'-Text], true)).
4619
+
4620
+ %% Work hook outputs are data, never serialized executable continuations.
4621
+ repl_hook_state(Text, Canonical) :-
4622
+ string_length(Text, Length), Length =< 65536,
4623
+ read_term_from_atom(Text, State, [syntax_errors(error)]),
4624
+ repl_hook_state_value(State),
4625
+ with_output_to(string(Canonical), write_term(State, [quoted(true), ignore_ops(true), max_depth(0)])).
4626
+
4627
+ repl_hook_state_value(State) :-
4628
+ ( ground(State), acyclic_term(State), hook_data(State, 32)
4629
+ -> true
4630
+ ; throw(error(domain_error(hook_state, 'expected bounded ground data'), _))
4631
+ ).
4632
+
4633
+ hook_data(Value, Depth) :-
4634
+ Depth > 0,
4635
+ ( atom(Value) -> true
4636
+ ; string(Value) -> true
4637
+ ; integer(Value) -> abs(Value) =< 9007199254740991
4638
+ ; float(Value) -> float_class(Value, Class), memberchk(Class, [normal, subnormal, zero])
4639
+ ; Next is Depth - 1,
4640
+ ( is_list(Value) -> maplist(hook_data_at(Next), Value)
4641
+ ; is_dict(Value), dict_pairs(Value, Tag, Pairs), atom(Tag),
4642
+ maplist(hook_pair_at(Next), Pairs)
4643
+ )
4644
+ ).
4645
+ hook_data_at(Depth, Value) :- hook_data(Value, Depth).
4646
+ hook_pair_at(Depth, _-Value) :- hook_data(Value, Depth).
4647
+
4648
+ repl_hook_result(State, Decision, Json) :-
4649
+ repl_hook_state_value(State),
4650
+ ( ground(Decision),
4651
+ ( Decision == continue -> Action = continue, Text = ""
4652
+ ; Decision == consume -> Action = consume, Text = ""
4653
+ ; Decision = reply(Text), string(Text) -> Action = reply
4654
+ ; Decision = reject(Text), string(Text) -> Action = reject
4655
+ )
4656
+ -> true
4657
+ ; throw(error(domain_error(hook_decision, 'expected continue, reply(Text), or reject(Reason)'), _))
4658
+ ),
4659
+ with_output_to(string(StateText), write_term(State, [quoted(true), ignore_ops(true), max_depth(0)])),
4660
+ string_length(StateText, Size),
4661
+ ( Size =< 65536 -> true ; throw(error(resource_error(hook_state_size), _)) ),
4662
+ atom_json_dict(Atom, _{state:StateText, action:Action, text:Text}, []), atom_string(Atom, Json).
4663
+
4664
+ repl_hook_memory(SessionId, Json) :-
4665
+ repl_get_memory(SessionId, harness, Memory),
4666
+ maplist(hook_memory_entry, Memory, Entries),
4667
+ atom_json_dict(Atom, Entries, []), atom_string(Atom, Json).
4668
+ hook_memory_entry(Message, Entry) :-
4669
+ get_dict(role, Message, Role), memberchk(Role, [system, user, assistant]),
4670
+ get_dict(content, Message, Content0), text_value(Content0, Content),
4671
+ Base = _{role:Role, content:Content},
4672
+ ( get_dict(hook_ref, Message, Ref) -> put_dict(ref, Base, Ref, WithRef) ; WithRef = Base ),
4673
+ ( get_dict(media, Message, Media) -> put_dict(media, WithRef, Media, Entry) ; Entry = WithRef ).
4674
+
4505
4675
  %% determine_agent_goal(+SessionId, +Args, -Goal)
4506
4676
  %% Args is a list of positional arguments - passed directly to agent_main
4507
4677
  %% Prefers arity that matches the number of arguments provided
@@ -4556,6 +4726,7 @@ step_engine(SessionId, Status, Content, Payload) :-
4556
4726
  process_engine_result(output(Text), output, Text, none) :- !.
4557
4727
  process_engine_result(media(Payload), media, '', Payload) :- is_dict(Payload), !.
4558
4728
  process_engine_result(html(Payload), html, '', Payload) :- is_dict(Payload), !.
4729
+ process_engine_result(download(Payload), download, '', Payload) :- is_dict(Payload), !.
4559
4730
  process_engine_result(log(Text), log, Text, none) :- !.
4560
4731
  process_engine_result(suspend(Continuation, Memory), suspend, '', payload{continuation: Continuation, memory: Memory}) :- !.
4561
4732
  process_engine_result(answer(Text), answer, Text, none) :- !.
@@ -4599,6 +4770,8 @@ process_engine_result(wait_form(FormId, Since, Timeout), wait_form, '',
4599
4770
  payload{formId: FormId, since: Since, timeout: Timeout}) :- !.
4600
4771
 
4601
4772
  %% proc_request_payload(+Request, -Payload)
4773
+ proc_request_payload(agent_self, payload{op: agent_self}) :- !.
4774
+ proc_request_payload(agent_post(To, Message), payload{op: agent_post, to: To, message: Message}) :- !.
4602
4775
  proc_request_payload(self, payload{op: self}) :- !.
4603
4776
  proc_request_payload(spawn(Goal), payload{op: spawn, goal: Goal}) :- !.
4604
4777
  proc_request_payload(spawn(Goal, Options), payload{op: spawn, goal: Goal, options: Options}) :- !.
@@ -5900,11 +6073,13 @@ mi_call_judgment(State, Specs, StateIn, StateOut) :-
5900
6073
  add_trace_entry(SessionId, llm_call, judgment, [Count], Depth),
5901
6074
  get_judge_backend(State1, Backend),
5902
6075
  get_required_judgments(State1, Requires),
6076
+ get_model_spec(State1, ModelSpec),
5903
6077
  engine_yield(request_judgment(payload{
5904
6078
  state: State,
5905
6079
  questions: Questions,
5906
6080
  backend: Backend,
5907
- requires: Requires
6081
+ requires: Requires,
6082
+ modelSpec: ModelSpec
5908
6083
  })),
5909
6084
  wait_judgment_signal(SessionId),
5910
6085
  ( session_judgment_result(SessionId, Result)
@@ -6321,7 +6496,7 @@ mi_call(exec(ToolCall, Output), StateIn, StateOut) :-
6321
6496
  % `\+` around `exec` keep working.
6322
6497
  ( catch(get_dict(result, Result, Reason0), _, fail),
6323
6498
  format(string(Reason), '~w', [Reason0]),
6324
- sub_string(Reason, _, _, _, "Tool not found")
6499
+ ( memberchk(ToolName, [agent_send,agent_recipients,agent_broadcast,run_workflow]) ; sub_string(Reason, _, _, _, "Tool not found") )
6325
6500
  -> throw(error(tool_error(ToolName, Reason), context(exec/2, Reason)))
6326
6501
  ; fail
6327
6502
  )
@@ -6406,6 +6581,36 @@ script_arg_string(Value, String) :-
6406
6581
  %% Goals and messages cross the boundary as canonical term strings, so a
6407
6582
  %% process never shares a variable with its spawner (invariant A).
6408
6583
 
6584
+ %% Work conversation references are distinct from process pids/mailboxes.
6585
+ mi_call(agent_self(Agent), StateIn, StateIn) :-
6586
+ !, get_session_id(SessionId), engine_yield(request_proc(agent_self)),
6587
+ get_next_signal(SessionId, _),
6588
+ retract(session_proc_result(SessionId, agent_self, Result)),
6589
+ ( Result = ok(Agent) -> true ; throw(error(agent_inbox(Result), agent_self/1)) ).
6590
+
6591
+ mi_call(agent_post(Agent, Message, Id), StateIn, StateIn) :-
6592
+ !,
6593
+ ( nonvar(Agent), Agent = agent_ref(Token), string(Token),
6594
+ acyclic_term(Message), is_dict(Message), repl_inbox_data(Message, 32)
6595
+ -> true ; throw(error(domain_error(agent_message, 'expected agent reference and data dict'), agent_post/3)) ),
6596
+ term_string(Agent, To),
6597
+ atom_json_dict(JsonAtom, Message, []), atom_string(JsonAtom, Json),
6598
+ get_session_id(SessionId), engine_yield(request_proc(agent_post(To, Json))),
6599
+ get_next_signal(SessionId, _),
6600
+ retract(session_proc_result(SessionId, agent_post, Result)),
6601
+ ( Result = ok(Id) -> true ; throw(error(agent_inbox(Result), agent_post/3)) ).
6602
+
6603
+ %% Anonymous dict tags are harmless; values/keys must still be data, never goals.
6604
+ repl_inbox_data(Value, Depth) :-
6605
+ Depth > 0,
6606
+ ( nonvar(Value), atomic(Value) -> hook_data(Value, Depth)
6607
+ ; nonvar(Value), Next is Depth - 1,
6608
+ ( is_list(Value) -> maplist(repl_inbox_data_at(Next), Value)
6609
+ ; is_dict(Value), dict_pairs(Value, _, Pairs), maplist(repl_inbox_pair(Next), Pairs) )
6610
+ ).
6611
+ repl_inbox_data_at(Depth, Value) :- repl_inbox_data(Value, Depth).
6612
+ repl_inbox_pair(Depth, Key-Value) :- atom(Key), repl_inbox_data(Value, Depth).
6613
+
6409
6614
  %% mi_call(self(?Pid), +StateIn, -StateOut)
6410
6615
  mi_call(self(Pid), StateIn, StateIn) :-
6411
6616
  !,
@@ -6651,6 +6856,72 @@ mi_call(now_ms(Milliseconds), StateIn, StateIn) :-
6651
6856
  get_time(Seconds),
6652
6857
  Milliseconds is round(Seconds * 1000).
6653
6858
 
6859
+ %% ============================================================
6860
+ %% Time zones
6861
+ %% ============================================================
6862
+ %%
6863
+ %% This engine is WebAssembly without tzdata: `stamp_date_time/3` understands
6864
+ %% 'UTC' and explicit integer offsets, but not IANA zone names (and not a
6865
+ %% 'Local' pseudo-zone). The host does have that database, so these predicates
6866
+ %% resolve a zone to the DST-correct integer offset for one instant and then
6867
+ %% reuse the ordinary date/time term. Nothing here reads the filesystem,
6868
+ %% network or a model, and no host permission is involved.
6869
+ %%
6870
+ %% get_time(Stamp), zone_date_time(Stamp, 'Asia/Shanghai', DT)
6871
+ %% get_time(Stamp), zone_date_time(Stamp, 'America/New_York', DT)
6872
+ %% get_time(Stamp), local_date_time(Stamp, DT)
6873
+ %%
6874
+ %% `stamp_date_time/3` remains the primitive: these predicates only supply the
6875
+ %% offset it is missing. Use an explicit zone for reports whose audience is in
6876
+ %% that market; 'Local' follows the server's own zone and can move with DST.
6877
+
6878
+ %% mi_call(zone_offset(+Zone, +Stamp, -OffsetSeconds), +StateIn, -StateOut)
6879
+ mi_call(zone_offset(Zone, _Stamp, 0), StateIn, StateIn) :-
6880
+ Zone == 'UTC',
6881
+ !.
6882
+ mi_call(zone_offset(Zone, _Stamp, Zone), StateIn, StateIn) :-
6883
+ integer(Zone),
6884
+ !.
6885
+ mi_call(zone_offset(Zone, Stamp, Offset), StateIn, StateOut) :-
6886
+ !,
6887
+ ( atom(Zone)
6888
+ -> true
6889
+ ; throw(error(type_error(atom, Zone),
6890
+ context(zone_offset/3, 'pass an IANA zone atom such as Asia/Shanghai, America/New_York or Local')))
6891
+ ),
6892
+ ( number(Stamp)
6893
+ -> true
6894
+ ; throw(error(type_error(number, Stamp),
6895
+ context(zone_offset/3, 'pass an epoch timestamp in seconds, normally from get_time/1')))
6896
+ ),
6897
+ mi_call(exec(dc_timezone(zone: Zone, stamp: Stamp), Result), StateIn, StateOut),
6898
+ ( is_dict(Result),
6899
+ get_dict(offset, Result, Found),
6900
+ integer(Found)
6901
+ -> Offset = Found
6902
+ ; ( get_dict(error, Result, Why)
6903
+ -> true
6904
+ ; Why = 'the host could not resolve that time zone'
6905
+ ),
6906
+ throw(error(domain_error(timezone, Zone), context(zone_offset/3, Why)))
6907
+ ).
6908
+
6909
+ %% mi_call(zone_date_time(+Stamp, +Zone, -DateTime), +StateIn, -StateOut)
6910
+ %%
6911
+ %% `zone_offset/3` reports seconds east of UTC (the IANA convention), while
6912
+ %% `stamp_date_time/3` takes its integer zone as seconds *west* of UTC, so the
6913
+ %% sign is flipped here. Callers never see that difference.
6914
+ mi_call(zone_date_time(Stamp, Zone, DateTime), StateIn, StateOut) :-
6915
+ !,
6916
+ mi_call(zone_offset(Zone, Stamp, East), StateIn, StateOut),
6917
+ West is -East,
6918
+ stamp_date_time(Stamp, DateTime, West).
6919
+
6920
+ %% mi_call(local_date_time(+Stamp, -DateTime), +StateIn, -StateOut)
6921
+ mi_call(local_date_time(Stamp, DateTime), StateIn, StateOut) :-
6922
+ !,
6923
+ mi_call(zone_date_time(Stamp, 'Local', DateTime), StateIn, StateOut).
6924
+
6654
6925
  %% mi_call(serve(+Name, +Goal), +StateIn, -StateOut)
6655
6926
  %% Spawn a session-scoped process and register it under Name. Sugar over
6656
6927
  %% spawn/2 + register/2; the goal decides the process's shape.
@@ -6921,7 +7192,8 @@ mi_call(with_reasoning(Goal, Effort), StateIn, StateOut) :-
6921
7192
  %% Run Goal with a specific model, and optionally a reasoning level. `Spec` is a
6922
7193
  %% string — "provider:model", "provider:model#reasoning", "model",
6923
7194
  %% "model#reasoning" — or a model{provider, id, temperature, maxTokens, reasoning}
6924
- %% dict. It applies to task/N, prompt/N and sample_token/N (not judgments).
7195
+ %% dict. It applies to task/N, prompt/N, sample_token/N and LLM-backed judgments.
7196
+ %% A judge backend with its own fixed model (for example Jev) keeps that model.
6925
7197
  mi_call(with_model(Spec, Goal), StateIn, StateOut) :-
6926
7198
  !,
6927
7199
  set_model_state(StateIn, Spec, ScopedState),
@@ -7125,6 +7397,41 @@ mi_call(output(Media), StateIn, StateIn) :-
7125
7397
  media_dict_keys(Dict) :-
7126
7398
  ( get_dict(mime, Dict, _) ; get_dict(svg, Dict, _) ; get_dict(path, Dict, _) ; get_dict(data, Dict, _) ).
7127
7399
 
7400
+ %% A file reference, not executable HTML or inline bytes. The host validates access.
7401
+ mi_call(output(file(Path)), StateIn, StateIn) :-
7402
+ !,
7403
+ ( string(Path) -> File=Path ; atom(Path) -> atom_string(Path,File)
7404
+ ; throw(error(type_error(file_path,Path),output/1)) ),
7405
+ engine_yield(download(download{path:File})).
7406
+
7407
+ %% Named workflow composition is a host capability. The host pins the catalog,
7408
+ %% validates types and applies depth/call/cancellation limits; drafts cannot call it.
7409
+ mi_call(run_workflow(Name, Inputs, Result), StateIn, StateOut) :-
7410
+ !,
7411
+ ( (string(Name);atom(Name)),is_dict(Inputs),dict_pairs(Inputs,_,Pairs),ground(Pairs) -> true
7412
+ ; throw(error(domain_error(workflow_call,Name-Inputs),run_workflow/3)) ),
7413
+ dict_pairs(Plain,_,Pairs),
7414
+ mi_call(exec(run_workflow(name:Name,inputs:Plain),Result),StateIn,StateOut).
7415
+
7416
+ %% Cross-Agent delivery is a host capability, separate from delegated process inbox refs.
7417
+ mi_call(agent_recipients(Agents), StateIn, StateOut) :-
7418
+ !, mi_call(exec(agent_recipients,Agents),StateIn,StateOut).
7419
+ mi_call(agent_broadcast(Message, Report), StateIn, StateOut) :-
7420
+ !,
7421
+ ( ground(Message),is_dict(Message) -> true ; throw(error(domain_error(agent_message,Message),agent_broadcast/2)) ),
7422
+ dict_pairs(Message,_,Pairs),dict_pairs(Plain,_,Pairs),
7423
+ mi_call(exec(agent_broadcast(message:Plain),Report),StateIn,StateOut).
7424
+ mi_call(agent_send(Target, Message, Receipt), StateIn, StateOut) :-
7425
+ !,
7426
+ ( Target == recipient -> To=_{kind:"recipient"}
7427
+ ; nonvar(Target), Target=existing(Id), (string(Id);atom(Id)) -> To=_{kind:"existing",id:Id}
7428
+ ; nonvar(Target), Target=new(Options), is_dict(Options) -> To=Options.put(kind,"new")
7429
+ ; throw(error(domain_error(agent_target,Target),agent_send/3)) ),
7430
+ ( ground(Message), is_dict(Message) -> true
7431
+ ; throw(error(domain_error(agent_message,Message),agent_send/3)) ),
7432
+ dict_pairs(Message,_,Pairs), dict_pairs(Plain,_,Pairs),
7433
+ mi_call(exec(agent_send(target:To,message:Plain),Receipt),StateIn,StateOut).
7434
+
7128
7435
  %% mi_call(output(html(Path)), +StateIn, -StateOut)
7129
7436
  %% Present a workspace HTML file as an interactive miniapp.
7130
7437
  mi_call(output(html(Path)), StateIn, StateIn) :-
@@ -8542,6 +8849,12 @@ is_mi_special_predicate(exec(_,_)).
8542
8849
  is_mi_special_predicate(run_script(_,_,_)).
8543
8850
  is_mi_special_predicate(spawn(_,_)).
8544
8851
  is_mi_special_predicate(spawn_opt(_,_,_)).
8852
+ is_mi_special_predicate(agent_self(_)).
8853
+ is_mi_special_predicate(agent_post(_,_,_)).
8854
+ is_mi_special_predicate(agent_send(_,_,_)).
8855
+ is_mi_special_predicate(run_workflow(_,_,_)).
8856
+ is_mi_special_predicate(agent_recipients(_)).
8857
+ is_mi_special_predicate(agent_broadcast(_,_)).
8545
8858
  is_mi_special_predicate(self(_)).
8546
8859
  is_mi_special_predicate(send(_,_)).
8547
8860
  is_mi_special_predicate(receive(_)).
@@ -8555,6 +8868,9 @@ is_mi_special_predicate(whereis(_,_)).
8555
8868
  is_mi_special_predicate(sleep(_)).
8556
8869
  is_mi_special_predicate(make_ref(_)).
8557
8870
  is_mi_special_predicate(now_ms(_)).
8871
+ is_mi_special_predicate(zone_offset(_,_,_)).
8872
+ is_mi_special_predicate(zone_date_time(_,_,_)).
8873
+ is_mi_special_predicate(local_date_time(_,_)).
8558
8874
  is_mi_special_predicate(serve(_,_)).
8559
8875
  is_mi_special_predicate(serve(_,_,_)).
8560
8876
  is_mi_special_predicate(service_cast(_,_)).