zrb 1.15.3__py3-none-any.whl → 2.0.0a4__py3-none-any.whl

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.

Potentially problematic release.


This version of zrb might be problematic. Click here for more details.

Files changed (204) hide show
  1. zrb/__init__.py +118 -133
  2. zrb/attr/type.py +10 -7
  3. zrb/builtin/__init__.py +55 -1
  4. zrb/builtin/git.py +12 -1
  5. zrb/builtin/group.py +31 -15
  6. zrb/builtin/llm/chat.py +147 -0
  7. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +7 -7
  8. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +5 -5
  9. zrb/builtin/project/add/fastapp/fastapp_util.py +1 -1
  10. zrb/builtin/searxng/config/settings.yml +5671 -0
  11. zrb/builtin/searxng/start.py +21 -0
  12. zrb/builtin/shell/autocomplete/bash.py +4 -3
  13. zrb/builtin/shell/autocomplete/zsh.py +4 -3
  14. zrb/callback/callback.py +8 -1
  15. zrb/cmd/cmd_result.py +2 -1
  16. zrb/config/config.py +555 -169
  17. zrb/config/helper.py +84 -0
  18. zrb/config/web_auth_config.py +50 -35
  19. zrb/context/any_shared_context.py +20 -3
  20. zrb/context/context.py +39 -5
  21. zrb/context/print_fn.py +13 -0
  22. zrb/context/shared_context.py +17 -8
  23. zrb/group/any_group.py +3 -3
  24. zrb/group/group.py +3 -3
  25. zrb/input/any_input.py +5 -1
  26. zrb/input/base_input.py +18 -6
  27. zrb/input/option_input.py +41 -1
  28. zrb/input/text_input.py +7 -24
  29. zrb/llm/agent/__init__.py +9 -0
  30. zrb/llm/agent/agent.py +215 -0
  31. zrb/llm/agent/summarizer.py +20 -0
  32. zrb/llm/app/__init__.py +10 -0
  33. zrb/llm/app/completion.py +281 -0
  34. zrb/llm/app/confirmation/allow_tool.py +66 -0
  35. zrb/llm/app/confirmation/handler.py +178 -0
  36. zrb/llm/app/confirmation/replace_confirmation.py +77 -0
  37. zrb/llm/app/keybinding.py +34 -0
  38. zrb/llm/app/layout.py +117 -0
  39. zrb/llm/app/lexer.py +155 -0
  40. zrb/llm/app/redirection.py +28 -0
  41. zrb/llm/app/style.py +16 -0
  42. zrb/llm/app/ui.py +733 -0
  43. zrb/llm/config/__init__.py +4 -0
  44. zrb/llm/config/config.py +122 -0
  45. zrb/llm/config/limiter.py +247 -0
  46. zrb/llm/history_manager/__init__.py +4 -0
  47. zrb/llm/history_manager/any_history_manager.py +23 -0
  48. zrb/llm/history_manager/file_history_manager.py +91 -0
  49. zrb/llm/history_processor/summarizer.py +108 -0
  50. zrb/llm/note/__init__.py +3 -0
  51. zrb/llm/note/manager.py +122 -0
  52. zrb/llm/prompt/__init__.py +29 -0
  53. zrb/llm/prompt/claude_compatibility.py +92 -0
  54. zrb/llm/prompt/compose.py +55 -0
  55. zrb/llm/prompt/default.py +51 -0
  56. zrb/llm/prompt/markdown/file_extractor.md +112 -0
  57. zrb/llm/prompt/markdown/mandate.md +23 -0
  58. zrb/llm/prompt/markdown/persona.md +3 -0
  59. zrb/llm/prompt/markdown/repo_extractor.md +112 -0
  60. zrb/llm/prompt/markdown/repo_summarizer.md +29 -0
  61. zrb/llm/prompt/markdown/summarizer.md +21 -0
  62. zrb/llm/prompt/note.py +41 -0
  63. zrb/llm/prompt/system_context.py +46 -0
  64. zrb/llm/prompt/zrb.py +41 -0
  65. zrb/llm/skill/__init__.py +3 -0
  66. zrb/llm/skill/manager.py +86 -0
  67. zrb/llm/task/__init__.py +4 -0
  68. zrb/llm/task/llm_chat_task.py +316 -0
  69. zrb/llm/task/llm_task.py +245 -0
  70. zrb/llm/tool/__init__.py +39 -0
  71. zrb/llm/tool/bash.py +75 -0
  72. zrb/llm/tool/code.py +266 -0
  73. zrb/llm/tool/file.py +419 -0
  74. zrb/llm/tool/note.py +70 -0
  75. zrb/{builtin/llm → llm}/tool/rag.py +33 -37
  76. zrb/llm/tool/search/brave.py +53 -0
  77. zrb/llm/tool/search/searxng.py +47 -0
  78. zrb/llm/tool/search/serpapi.py +47 -0
  79. zrb/llm/tool/skill.py +19 -0
  80. zrb/llm/tool/sub_agent.py +70 -0
  81. zrb/llm/tool/web.py +97 -0
  82. zrb/llm/tool/zrb_task.py +66 -0
  83. zrb/llm/util/attachment.py +101 -0
  84. zrb/llm/util/prompt.py +104 -0
  85. zrb/llm/util/stream_response.py +178 -0
  86. zrb/runner/cli.py +21 -20
  87. zrb/runner/common_util.py +24 -19
  88. zrb/runner/web_route/task_input_api_route.py +5 -5
  89. zrb/runner/web_util/user.py +7 -3
  90. zrb/session/any_session.py +12 -9
  91. zrb/session/session.py +38 -17
  92. zrb/task/any_task.py +24 -3
  93. zrb/task/base/context.py +42 -22
  94. zrb/task/base/execution.py +67 -55
  95. zrb/task/base/lifecycle.py +14 -7
  96. zrb/task/base/monitoring.py +12 -7
  97. zrb/task/base_task.py +113 -50
  98. zrb/task/base_trigger.py +16 -6
  99. zrb/task/cmd_task.py +6 -0
  100. zrb/task/http_check.py +11 -5
  101. zrb/task/make_task.py +5 -3
  102. zrb/task/rsync_task.py +30 -10
  103. zrb/task/scaffolder.py +7 -4
  104. zrb/task/scheduler.py +7 -4
  105. zrb/task/tcp_check.py +6 -4
  106. zrb/util/ascii_art/art/bee.txt +17 -0
  107. zrb/util/ascii_art/art/cat.txt +9 -0
  108. zrb/util/ascii_art/art/ghost.txt +16 -0
  109. zrb/util/ascii_art/art/panda.txt +17 -0
  110. zrb/util/ascii_art/art/rose.txt +14 -0
  111. zrb/util/ascii_art/art/unicorn.txt +15 -0
  112. zrb/util/ascii_art/banner.py +92 -0
  113. zrb/util/attr.py +54 -39
  114. zrb/util/cli/markdown.py +32 -0
  115. zrb/util/cli/text.py +30 -0
  116. zrb/util/cmd/command.py +33 -10
  117. zrb/util/file.py +61 -33
  118. zrb/util/git.py +2 -2
  119. zrb/util/{llm/prompt.py → markdown.py} +2 -3
  120. zrb/util/match.py +78 -0
  121. zrb/util/run.py +3 -3
  122. zrb/util/string/conversion.py +1 -1
  123. zrb/util/truncate.py +23 -0
  124. zrb/util/yaml.py +204 -0
  125. zrb/xcom/xcom.py +10 -0
  126. {zrb-1.15.3.dist-info → zrb-2.0.0a4.dist-info}/METADATA +41 -27
  127. {zrb-1.15.3.dist-info → zrb-2.0.0a4.dist-info}/RECORD +129 -131
  128. {zrb-1.15.3.dist-info → zrb-2.0.0a4.dist-info}/WHEEL +1 -1
  129. zrb/attr/__init__.py +0 -0
  130. zrb/builtin/llm/chat_session.py +0 -311
  131. zrb/builtin/llm/history.py +0 -71
  132. zrb/builtin/llm/input.py +0 -27
  133. zrb/builtin/llm/llm_ask.py +0 -187
  134. zrb/builtin/llm/previous-session.js +0 -21
  135. zrb/builtin/llm/tool/__init__.py +0 -0
  136. zrb/builtin/llm/tool/api.py +0 -71
  137. zrb/builtin/llm/tool/cli.py +0 -38
  138. zrb/builtin/llm/tool/code.py +0 -254
  139. zrb/builtin/llm/tool/file.py +0 -626
  140. zrb/builtin/llm/tool/sub_agent.py +0 -137
  141. zrb/builtin/llm/tool/web.py +0 -195
  142. zrb/builtin/project/__init__.py +0 -0
  143. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/__init__.py +0 -0
  144. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/service/__init__.py +0 -0
  145. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/__init__.py +0 -0
  146. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/__init__.py +0 -0
  147. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/__init__.py +0 -0
  148. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/__init__.py +0 -0
  149. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/__init__.py +0 -0
  150. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/__init__.py +0 -0
  151. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/__init__.py +0 -0
  152. zrb/builtin/project/create/__init__.py +0 -0
  153. zrb/builtin/shell/__init__.py +0 -0
  154. zrb/builtin/shell/autocomplete/__init__.py +0 -0
  155. zrb/callback/__init__.py +0 -0
  156. zrb/cmd/__init__.py +0 -0
  157. zrb/config/default_prompt/file_extractor_system_prompt.md +0 -12
  158. zrb/config/default_prompt/interactive_system_prompt.md +0 -35
  159. zrb/config/default_prompt/persona.md +0 -1
  160. zrb/config/default_prompt/repo_extractor_system_prompt.md +0 -112
  161. zrb/config/default_prompt/repo_summarizer_system_prompt.md +0 -10
  162. zrb/config/default_prompt/summarization_prompt.md +0 -16
  163. zrb/config/default_prompt/system_prompt.md +0 -32
  164. zrb/config/llm_config.py +0 -243
  165. zrb/config/llm_context/config.py +0 -129
  166. zrb/config/llm_context/config_parser.py +0 -46
  167. zrb/config/llm_rate_limitter.py +0 -137
  168. zrb/content_transformer/__init__.py +0 -0
  169. zrb/context/__init__.py +0 -0
  170. zrb/dot_dict/__init__.py +0 -0
  171. zrb/env/__init__.py +0 -0
  172. zrb/group/__init__.py +0 -0
  173. zrb/input/__init__.py +0 -0
  174. zrb/runner/__init__.py +0 -0
  175. zrb/runner/web_route/__init__.py +0 -0
  176. zrb/runner/web_route/home_page/__init__.py +0 -0
  177. zrb/session/__init__.py +0 -0
  178. zrb/session_state_log/__init__.py +0 -0
  179. zrb/session_state_logger/__init__.py +0 -0
  180. zrb/task/__init__.py +0 -0
  181. zrb/task/base/__init__.py +0 -0
  182. zrb/task/llm/__init__.py +0 -0
  183. zrb/task/llm/agent.py +0 -243
  184. zrb/task/llm/config.py +0 -103
  185. zrb/task/llm/conversation_history.py +0 -128
  186. zrb/task/llm/conversation_history_model.py +0 -242
  187. zrb/task/llm/default_workflow/coding.md +0 -24
  188. zrb/task/llm/default_workflow/copywriting.md +0 -17
  189. zrb/task/llm/default_workflow/researching.md +0 -18
  190. zrb/task/llm/error.py +0 -95
  191. zrb/task/llm/history_summarization.py +0 -216
  192. zrb/task/llm/print_node.py +0 -101
  193. zrb/task/llm/prompt.py +0 -325
  194. zrb/task/llm/tool_wrapper.py +0 -220
  195. zrb/task/llm/typing.py +0 -3
  196. zrb/task/llm_task.py +0 -341
  197. zrb/task_status/__init__.py +0 -0
  198. zrb/util/__init__.py +0 -0
  199. zrb/util/cli/__init__.py +0 -0
  200. zrb/util/cmd/__init__.py +0 -0
  201. zrb/util/codemod/__init__.py +0 -0
  202. zrb/util/string/__init__.py +0 -0
  203. zrb/xcom/__init__.py +0 -0
  204. {zrb-1.15.3.dist-info → zrb-2.0.0a4.dist-info}/entry_points.txt +0 -0
zrb/__init__.py CHANGED
@@ -1,134 +1,119 @@
1
- import importlib
2
- from typing import TYPE_CHECKING, Any
1
+ from zrb import builtin
2
+ from zrb.attr.type import (
3
+ AnyAttr,
4
+ BoolAttr,
5
+ FloatAttr,
6
+ IntAttr,
7
+ StrAttr,
8
+ StrDictAttr,
9
+ fstring,
10
+ )
11
+ from zrb.callback.any_callback import AnyCallback
12
+ from zrb.callback.callback import Callback
13
+ from zrb.cmd.cmd_result import CmdResult
14
+ from zrb.cmd.cmd_val import Cmd, CmdPath
15
+ from zrb.config.config import CFG
16
+ from zrb.config.web_auth_config import web_auth_config
17
+ from zrb.content_transformer.any_content_transformer import AnyContentTransformer
18
+ from zrb.content_transformer.content_transformer import ContentTransformer
19
+ from zrb.context.any_context import AnyContext
20
+ from zrb.context.any_shared_context import AnySharedContext
21
+ from zrb.context.context import Context
22
+ from zrb.context.shared_context import SharedContext
23
+ from zrb.env.any_env import AnyEnv
24
+ from zrb.env.env import Env
25
+ from zrb.env.env_file import EnvFile
26
+ from zrb.env.env_map import EnvMap
27
+ from zrb.group.any_group import AnyGroup
28
+ from zrb.group.group import Group
29
+ from zrb.input.any_input import AnyInput
30
+ from zrb.input.base_input import BaseInput
31
+ from zrb.input.bool_input import BoolInput
32
+ from zrb.input.float_input import FloatInput
33
+ from zrb.input.int_input import IntInput
34
+ from zrb.input.option_input import OptionInput
35
+ from zrb.input.password_input import PasswordInput
36
+ from zrb.input.str_input import StrInput
37
+ from zrb.input.text_input import TextInput
38
+ from zrb.llm.config.config import LLMConfig, llm_config
39
+ from zrb.llm.config.limiter import LLMLimiter, llm_limiter
40
+ from zrb.llm.task.llm_chat_task import LLMChatTask
41
+ from zrb.llm.task.llm_task import LLMTask
42
+ from zrb.runner.cli import cli
43
+ from zrb.runner.web_schema.user import User
44
+ from zrb.session.session import Session
45
+ from zrb.task.any_task import AnyTask
46
+ from zrb.task.base_task import BaseTask
47
+ from zrb.task.base_trigger import BaseTrigger
48
+ from zrb.task.cmd_task import CmdTask
49
+ from zrb.task.http_check import HttpCheck
50
+ from zrb.task.make_task import make_task
51
+ from zrb.task.rsync_task import RsyncTask
52
+ from zrb.task.scaffolder import Scaffolder
53
+ from zrb.task.scheduler import Scheduler
54
+ from zrb.task.task import Task
55
+ from zrb.task.tcp_check import TcpCheck
56
+ from zrb.util.load import load_file, load_module
57
+ from zrb.xcom.xcom import Xcom
3
58
 
4
- _LAZY_LOAD = {
5
- "AnyAttr": "zrb.attr.type",
6
- "BoolAttr": "zrb.attr.type",
7
- "FloatAttr": "zrb.attr.type",
8
- "IntAttr": "zrb.attr.type",
9
- "StrAttr": "zrb.attr.type",
10
- "StrDictAttr": "zrb.attr.type",
11
- "fstring": "zrb.attr.type",
12
- "AnyCallback": "zrb.callback.any_callback",
13
- "Callback": "zrb.callback.callback",
14
- "CmdResult": "zrb.cmd.cmd_result",
15
- "Cmd": "zrb.cmd.cmd_val",
16
- "CmdPath": "zrb.cmd.cmd_val",
17
- "CFG": "zrb.config.config",
18
- "AnyContentTransformer": "zrb.content_transformer.any_content_transformer",
19
- "ContentTransformer": "zrb.content_transformer.content_transformer",
20
- "AnyContext": "zrb.context.any_context",
21
- "AnySharedContext": "zrb.context.any_shared_context",
22
- "Context": "zrb.context.context",
23
- "SharedContext": "zrb.context.shared_context",
24
- "AnyEnv": "zrb.env.any_env",
25
- "Env": "zrb.env.env",
26
- "EnvFile": "zrb.env.env_file",
27
- "EnvMap": "zrb.env.env_map",
28
- "AnyGroup": "zrb.group.any_group",
29
- "Group": "zrb.group.group",
30
- "AnyInput": "zrb.input.any_input",
31
- "BaseInput": "zrb.input.base_input",
32
- "BoolInput": "zrb.input.bool_input",
33
- "FloatInput": "zrb.input.float_input",
34
- "IntInput": "zrb.input.int_input",
35
- "OptionInput": "zrb.input.option_input",
36
- "PasswordInput": "zrb.input.password_input",
37
- "StrInput": "zrb.input.str_input",
38
- "TextInput": "zrb.input.text_input",
39
- "llm_config": "zrb.config.llm_config",
40
- "llm_rate_limitter": "zrb.config.llm_rate_limitter",
41
- "cli": "zrb.runner.cli",
42
- "web_auth_config": "zrb.config.web_auth_config",
43
- "User": "zrb.runner.web_schema.user",
44
- "Session": "zrb.session.session",
45
- "AnyTask": "zrb.task.any_task",
46
- "BaseTask": "zrb.task.base_task",
47
- "BaseTrigger": "zrb.task.base_trigger",
48
- "CmdTask": "zrb.task.cmd_task",
49
- "HttpCheck": "zrb.task.http_check",
50
- "ConversationHistory": "zrb.task.llm.conversation_history",
51
- "LLMTask": "zrb.task.llm_task",
52
- "make_task": "zrb.task.make_task",
53
- "RsyncTask": "zrb.task.rsync_task",
54
- "Scaffolder": "zrb.task.scaffolder",
55
- "Scheduler": "zrb.task.scheduler",
56
- "Task": "zrb.task.task",
57
- "TcpCheck": "zrb.task.tcp_check",
58
- "load_file": "zrb.util.load",
59
- "load_module": "zrb.util.load",
60
- "Xcom": "zrb.xcom.xcom",
61
- }
62
-
63
- if TYPE_CHECKING:
64
- from zrb.attr.type import (
65
- AnyAttr,
66
- BoolAttr,
67
- FloatAttr,
68
- IntAttr,
69
- StrAttr,
70
- StrDictAttr,
71
- fstring,
72
- )
73
- from zrb.callback.any_callback import AnyCallback
74
- from zrb.callback.callback import Callback
75
- from zrb.cmd.cmd_result import CmdResult
76
- from zrb.cmd.cmd_val import Cmd, CmdPath
77
- from zrb.config.config import CFG
78
- from zrb.config.llm_config import llm_config
79
- from zrb.config.llm_rate_limitter import llm_rate_limitter
80
- from zrb.config.web_auth_config import web_auth_config
81
- from zrb.content_transformer.any_content_transformer import AnyContentTransformer
82
- from zrb.content_transformer.content_transformer import ContentTransformer
83
- from zrb.context.any_context import AnyContext
84
- from zrb.context.any_shared_context import AnySharedContext
85
- from zrb.context.context import Context
86
- from zrb.context.shared_context import SharedContext
87
- from zrb.env.any_env import AnyEnv
88
- from zrb.env.env import Env
89
- from zrb.env.env_file import EnvFile
90
- from zrb.env.env_map import EnvMap
91
- from zrb.group.any_group import AnyGroup
92
- from zrb.group.group import Group
93
- from zrb.input.any_input import AnyInput
94
- from zrb.input.base_input import BaseInput
95
- from zrb.input.bool_input import BoolInput
96
- from zrb.input.float_input import FloatInput
97
- from zrb.input.int_input import IntInput
98
- from zrb.input.option_input import OptionInput
99
- from zrb.input.password_input import PasswordInput
100
- from zrb.input.str_input import StrInput
101
- from zrb.input.text_input import TextInput
102
- from zrb.runner.cli import cli
103
- from zrb.runner.web_schema.user import User
104
- from zrb.session.session import Session
105
- from zrb.task.any_task import AnyTask
106
- from zrb.task.base_task import BaseTask
107
- from zrb.task.base_trigger import BaseTrigger
108
- from zrb.task.cmd_task import CmdTask
109
- from zrb.task.http_check import HttpCheck
110
- from zrb.task.llm.conversation_history import ConversationHistory
111
- from zrb.task.llm_task import LLMTask
112
- from zrb.task.make_task import make_task
113
- from zrb.task.rsync_task import RsyncTask
114
- from zrb.task.scaffolder import Scaffolder
115
- from zrb.task.scheduler import Scheduler
116
- from zrb.task.task import Task
117
- from zrb.task.tcp_check import TcpCheck
118
- from zrb.util.load import load_file, load_module
119
- from zrb.xcom.xcom import Xcom
120
-
121
-
122
- def __getattr__(name: str) -> Any:
123
- if name in _LAZY_LOAD:
124
- module = importlib.import_module(_LAZY_LOAD[name])
125
- return getattr(module, name)
126
- raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
127
-
128
-
129
- # Eager load CFG
130
- CFG = __getattr__("CFG")
131
- if CFG.LOAD_BUILTIN:
132
- from zrb import builtin
133
-
134
- assert builtin
59
+ __all__ = [
60
+ "builtin",
61
+ "AnyAttr",
62
+ "BoolAttr",
63
+ "FloatAttr",
64
+ "IntAttr",
65
+ "StrAttr",
66
+ "StrDictAttr",
67
+ "fstring",
68
+ "AnyCallback",
69
+ "Callback",
70
+ "CmdResult",
71
+ "Cmd",
72
+ "CmdPath",
73
+ "CFG",
74
+ "web_auth_config",
75
+ "AnyContentTransformer",
76
+ "ContentTransformer",
77
+ "AnyContext",
78
+ "AnySharedContext",
79
+ "Context",
80
+ "SharedContext",
81
+ "AnyEnv",
82
+ "Env",
83
+ "EnvFile",
84
+ "EnvMap",
85
+ "AnyGroup",
86
+ "Group",
87
+ "AnyInput",
88
+ "BaseInput",
89
+ "BoolInput",
90
+ "FloatInput",
91
+ "IntInput",
92
+ "OptionInput",
93
+ "PasswordInput",
94
+ "StrInput",
95
+ "TextInput",
96
+ "cli",
97
+ "User",
98
+ "Session",
99
+ "AnyTask",
100
+ "BaseTask",
101
+ "BaseTrigger",
102
+ "CmdTask",
103
+ "HttpCheck",
104
+ "make_task",
105
+ "RsyncTask",
106
+ "Scaffolder",
107
+ "Scheduler",
108
+ "Task",
109
+ "TcpCheck",
110
+ "load_file",
111
+ "load_module",
112
+ "Xcom",
113
+ "LLMTask",
114
+ "LLMChatTask",
115
+ "LLMConfig",
116
+ "llm_config",
117
+ "LLMLimiter",
118
+ "llm_limiter",
119
+ ]
zrb/attr/type.py CHANGED
@@ -1,12 +1,15 @@
1
1
  from typing import Any, Callable
2
2
 
3
+ from zrb.context.any_context import AnyContext
3
4
  from zrb.context.any_shared_context import AnySharedContext
4
5
 
5
6
  fstring = str
6
- AnyAttr = Any | fstring | Callable[[AnySharedContext], Any]
7
- StrAttr = str | fstring | Callable[[AnySharedContext], str]
8
- BoolAttr = bool | fstring | Callable[[AnySharedContext], bool]
9
- IntAttr = int | fstring | Callable[[AnySharedContext], int]
10
- FloatAttr = float | fstring | Callable[[AnySharedContext], float]
11
- StrDictAttr = dict[str, StrAttr] | Callable[[AnySharedContext], dict[str, Any]]
12
- StrListAttr = list[StrAttr] | Callable[[AnySharedContext], list[str]]
7
+ AnyAttr = Any | fstring | Callable[[AnyContext | AnySharedContext], Any]
8
+ StrAttr = str | fstring | Callable[[AnyContext | AnySharedContext], str | None]
9
+ BoolAttr = bool | fstring | Callable[[AnyContext | AnySharedContext], bool | None]
10
+ IntAttr = int | fstring | Callable[[AnyContext | AnySharedContext], int | None]
11
+ FloatAttr = float | fstring | Callable[[AnyContext | AnySharedContext], float | None]
12
+ StrDictAttr = (
13
+ dict[str, StrAttr] | Callable[[AnyContext | AnySharedContext], dict[str, Any]]
14
+ )
15
+ StrListAttr = list[StrAttr] | Callable[[AnyContext | AnySharedContext], list[str]]
zrb/builtin/__init__.py CHANGED
@@ -9,12 +9,13 @@ from zrb.builtin.git import (
9
9
  from zrb.builtin.git_subtree import git_add_subtree, git_pull_subtree, git_push_subtree
10
10
  from zrb.builtin.http import generate_curl, http_request
11
11
  from zrb.builtin.jwt import decode_jwt, encode_jwt, validate_jwt
12
- from zrb.builtin.llm.llm_ask import llm_ask
12
+ from zrb.builtin.llm.chat import llm_chat
13
13
  from zrb.builtin.md5 import hash_md5, sum_md5, validate_md5
14
14
  from zrb.builtin.project.add.fastapp.fastapp_task import add_fastapp_to_project
15
15
  from zrb.builtin.project.create.project_task import create_project
16
16
  from zrb.builtin.python import format_python_code
17
17
  from zrb.builtin.random import shuffle_values, throw_dice
18
+ from zrb.builtin.searxng.start import start_searxng
18
19
  from zrb.builtin.setup.asdf.asdf import setup_asdf
19
20
  from zrb.builtin.setup.latex.ubuntu import setup_latex_on_ubuntu
20
21
  from zrb.builtin.setup.tmux.tmux import setup_tmux
@@ -43,3 +44,56 @@ from zrb.builtin.uuid import (
43
44
  validate_uuid_v4,
44
45
  validate_uuid_v5,
45
46
  )
47
+
48
+ __all__ = [
49
+ "decode_base64",
50
+ "encode_base64",
51
+ "validate_base64",
52
+ "get_git_diff",
53
+ "git_commit",
54
+ "git_pull",
55
+ "git_push",
56
+ "prune_local_branches",
57
+ "git_add_subtree",
58
+ "git_pull_subtree",
59
+ "git_push_subtree",
60
+ "generate_curl",
61
+ "http_request",
62
+ "decode_jwt",
63
+ "encode_jwt",
64
+ "validate_jwt",
65
+ "llm_chat",
66
+ "hash_md5",
67
+ "sum_md5",
68
+ "validate_md5",
69
+ "add_fastapp_to_project",
70
+ "create_project",
71
+ "format_python_code",
72
+ "shuffle_values",
73
+ "throw_dice",
74
+ "start_searxng",
75
+ "setup_asdf",
76
+ "setup_latex_on_ubuntu",
77
+ "setup_tmux",
78
+ "setup_ubuntu",
79
+ "setup_zsh",
80
+ "make_bash_autocomplete",
81
+ "get_shell_subcommands",
82
+ "make_zsh_autocomplete",
83
+ "add_todo",
84
+ "archive_todo",
85
+ "complete_todo",
86
+ "edit_todo",
87
+ "list_todo",
88
+ "log_todo",
89
+ "show_todo",
90
+ "generate_uuid_v1",
91
+ "generate_uuid_v3",
92
+ "generate_uuid_v4",
93
+ "generate_uuid_v5",
94
+ "validate_uuid",
95
+ "validate_uuid_v1",
96
+ "validate_uuid_v3",
97
+ "validate_uuid_v4",
98
+ "validate_uuid_v5",
99
+ ]
zrb/builtin/git.py CHANGED
@@ -82,6 +82,12 @@ async def get_git_diff(ctx: AnyContext):
82
82
 
83
83
  @make_task(
84
84
  name="prune-local-git-branches",
85
+ input=StrInput(
86
+ name="preserved-branch",
87
+ description="Branches to be preserved",
88
+ prompt="Branches to be preserved, comma separated",
89
+ default="master,main,dev,develop",
90
+ ),
85
91
  description="🧹 Prune local branches",
86
92
  group=git_branch_group,
87
93
  alias="prune",
@@ -93,8 +99,13 @@ async def prune_local_branches(ctx: AnyContext):
93
99
  branches = await get_branches(repo_dir, print_method=ctx.print)
94
100
  ctx.print(stylize_faint("Get current branch"))
95
101
  current_branch = await get_current_branch(repo_dir, print_method=ctx.print)
102
+ preserved_branches = [
103
+ branch.strip()
104
+ for branch in ctx.input.preserved_branch.split(",")
105
+ if branch.strip() != ""
106
+ ]
96
107
  for branch in branches:
97
- if branch == current_branch or branch == "main" or branch == "master":
108
+ if branch == current_branch or branch in preserved_branches:
98
109
  continue
99
110
  ctx.print(stylize_faint(f"Removing local branch: {branch}"))
100
111
  try:
zrb/builtin/group.py CHANGED
@@ -1,39 +1,51 @@
1
+ from zrb.config.config import CFG
1
2
  from zrb.group.group import Group
2
3
  from zrb.runner.cli import cli
3
4
 
4
- base64_group = cli.add_group(Group(name="base64", description="📄 Base64 operations"))
5
- uuid_group = cli.add_group(Group(name="uuid", description="🆔 UUID operations"))
5
+
6
+ def _maybe_add_group(group: Group):
7
+ if CFG.LOAD_BUILTIN:
8
+ cli.add_group(group)
9
+ return group
10
+
11
+
12
+ base64_group = _maybe_add_group(
13
+ Group(name="base64", description="📄 Base64 operations")
14
+ )
15
+ uuid_group = _maybe_add_group(Group(name="uuid", description="🆔 UUID operations"))
6
16
  uuid_v1_group = uuid_group.add_group(Group(name="v1", description="UUID V1 operations"))
7
17
  uuid_v3_group = uuid_group.add_group(Group(name="v3", description="UUID V3 operations"))
8
18
  uuid_v4_group = uuid_group.add_group(Group(name="v4", description="UUID V4 operations"))
9
19
  uuid_v5_group = uuid_group.add_group(Group(name="v5", description="UUID V5 operations"))
10
- ulid_group = cli.add_group(Group(name="ulid", description="🔢 ULID operations"))
11
- jwt_group = cli.add_group(Group(name="jwt", description="🔒 JWT encode/decode"))
12
- http_group = cli.add_group(Group(name="http", description="🌐 HTTP request operations"))
20
+ ulid_group = _maybe_add_group(Group(name="ulid", description="🔢 ULID operations"))
21
+ jwt_group = _maybe_add_group(Group(name="jwt", description="🔒 JWT encode/decode"))
22
+ http_group = _maybe_add_group(
23
+ Group(name="http", description="🌐 HTTP request operations")
24
+ )
13
25
 
14
- random_group = cli.add_group(Group(name="random", description="🔀 Random operation"))
15
- git_group = cli.add_group(Group(name="git", description="🌱 Git related commands"))
26
+ random_group = _maybe_add_group(Group(name="random", description="🔀 Random operation"))
27
+ git_group = _maybe_add_group(Group(name="git", description="🌱 Git related commands"))
16
28
  git_branch_group = git_group.add_group(
17
29
  Group(name="branch", description="🌿 Git branch related commands")
18
30
  )
19
31
  git_subtree_group = git_group.add_group(
20
32
  Group(name="subtree", description="🌳 Git subtree related commands")
21
33
  )
22
- llm_group = cli.add_group(Group(name="llm", description="🤖 LLM operations"))
23
- md5_group = cli.add_group(Group(name="md5", description="🔢 Md5 operations"))
24
- python_group = cli.add_group(
34
+ llm_group = _maybe_add_group(Group(name="llm", description="🤖 LLM operations"))
35
+ md5_group = _maybe_add_group(Group(name="md5", description="🔢 Md5 operations"))
36
+ python_group = _maybe_add_group(
25
37
  Group(name="python", description="🐍 Python related commands")
26
38
  )
27
- todo_group = cli.add_group(Group(name="todo", description="✅ Todo management"))
39
+ todo_group = _maybe_add_group(Group(name="todo", description="✅ Todo management"))
28
40
 
29
- shell_group = cli.add_group(
41
+ shell_group = _maybe_add_group(
30
42
  Group(name="shell", description="💬 Shell related commands")
31
43
  )
32
- shell_autocomplete_group: Group = shell_group.add_group(
44
+ shell_autocomplete_group = shell_group.add_group(
33
45
  Group(name="autocomplete", description="⌨️ Shell autocomplete related commands")
34
46
  )
35
47
 
36
- project_group = cli.add_group(
48
+ project_group = _maybe_add_group(
37
49
  Group(name="project", description="📁 Project related commands")
38
50
  )
39
51
  add_to_project_group = project_group.add_group(
@@ -43,7 +55,11 @@ add_fastapp_to_project_group = add_to_project_group.add_group(
43
55
  Group(name="fastapp", description="🚀 Add Fastapp resources")
44
56
  )
45
57
 
46
- setup_group = cli.add_group(Group(name="setup", description="🔧 Setup"))
58
+ setup_group = _maybe_add_group(Group(name="setup", description="🔧 Setup"))
47
59
  setup_latex_group = setup_group.add_group(
48
60
  Group(name="latex", description="✍️ Setup LaTeX")
49
61
  )
62
+
63
+ searxng_group = _maybe_add_group(
64
+ Group(name="searxng", description="🔎 Searxng related command")
65
+ )
@@ -0,0 +1,147 @@
1
+ from zrb.builtin.group import llm_group
2
+ from zrb.config.config import CFG
3
+ from zrb.input.bool_input import BoolInput
4
+ from zrb.input.str_input import StrInput
5
+ from zrb.llm.app.confirmation.replace_confirmation import replace_confirmation
6
+ from zrb.llm.history_processor.summarizer import create_summarizer_history_processor
7
+ from zrb.llm.note.manager import NoteManager
8
+ from zrb.llm.prompt.claude_compatibility import (
9
+ create_claude_compatibility_prompt,
10
+ )
11
+ from zrb.llm.prompt.compose import PromptManager, new_prompt
12
+ from zrb.llm.prompt.default import (
13
+ get_mandate_prompt,
14
+ get_persona_prompt,
15
+ )
16
+ from zrb.llm.prompt.note import create_note_prompt
17
+ from zrb.llm.prompt.system_context import system_context
18
+ from zrb.llm.prompt.zrb import create_zrb_prompt
19
+ from zrb.llm.skill.manager import SkillManager
20
+ from zrb.llm.task.llm_chat_task import LLMChatTask
21
+ from zrb.llm.tool.bash import run_shell_command
22
+ from zrb.llm.tool.code import analyze_code
23
+ from zrb.llm.tool.file import (
24
+ analyze_file,
25
+ list_files,
26
+ read_file,
27
+ read_files,
28
+ replace_in_file,
29
+ search_files,
30
+ write_file,
31
+ write_files,
32
+ )
33
+ from zrb.llm.tool.note import create_note_tools
34
+ from zrb.llm.tool.skill import create_activate_skill_tool
35
+ from zrb.llm.tool.sub_agent import create_sub_agent_tool
36
+ from zrb.llm.tool.web import open_web_page, search_internet
37
+ from zrb.llm.tool.zrb_task import create_list_zrb_task_tool, create_run_zrb_task_tool
38
+ from zrb.runner.cli import cli
39
+
40
+ skill_manager = SkillManager()
41
+ note_manager = NoteManager()
42
+
43
+ llm_chat = LLMChatTask(
44
+ name="chat",
45
+ description="🤖 Chat with your AI Assistant",
46
+ input=[
47
+ StrInput("message", "Message", allow_empty=True, always_prompt=False),
48
+ StrInput(
49
+ "session", "Conversation Session", allow_empty=True, always_prompt=False
50
+ ),
51
+ BoolInput(
52
+ "yolo", "YOLO Mode", default=False, allow_empty=True, always_prompt=False
53
+ ),
54
+ StrInput("attach", "Attachments", allow_empty=True, always_prompt=False),
55
+ BoolInput(
56
+ "interactive",
57
+ "Interactive Mode",
58
+ default=True,
59
+ allow_empty=True,
60
+ always_prompt=False,
61
+ ),
62
+ ],
63
+ yolo="{ctx.input.yolo}",
64
+ message="{ctx.input.message}",
65
+ conversation_name="{ctx.input.session}",
66
+ interactive="{ctx.input.interactive}",
67
+ history_processors=[
68
+ create_summarizer_history_processor(
69
+ token_threshold=CFG.LLM_HISTORY_SUMMARIZATION_TOKEN_THRESHOLD,
70
+ summary_window=CFG.LLM_HISTORY_SUMMARIZATION_WINDOW,
71
+ )
72
+ ],
73
+ prompt_manager=PromptManager(),
74
+ ui_ascii_art=lambda ctx: CFG.LLM_ASSISTANT_ASCII_ART,
75
+ ui_assistant_name=lambda ctx: CFG.LLM_ASSISTANT_NAME,
76
+ ui_greeting=lambda ctx: f"{CFG.LLM_ASSISTANT_NAME}\n{CFG.LLM_ASSISTANT_JARGON}",
77
+ ui_jargon=lambda ctx: CFG.LLM_ASSISTANT_JARGON,
78
+ ui_summarize_commands=["/compress", "/compact"],
79
+ ui_attach_commands=["/attach"],
80
+ ui_exit_commands=["/q", "/bye", "/quit", "/exit"],
81
+ ui_info_commands=["/info", "/help"],
82
+ ui_save_commands=["/save"],
83
+ ui_load_commands=["/load"],
84
+ ui_yolo_toggle_commands=["/yolo"],
85
+ ui_redirect_output_commands=[">", "/redirect"],
86
+ ui_exec_commands=["!", "/exec"],
87
+ )
88
+ llm_group.add_task(llm_chat)
89
+ cli.add_task(llm_chat)
90
+
91
+
92
+ async def roll_dice() -> str:
93
+ """Roll a six-sided die and return the result."""
94
+ import asyncio
95
+ import random
96
+
97
+ await asyncio.sleep(3)
98
+ return str(random.randint(1, 6))
99
+
100
+
101
+ async def get_current_time() -> str:
102
+ """Get the current time."""
103
+ from datetime import datetime
104
+
105
+ return datetime.now().strftime("%H:%M:%S")
106
+
107
+
108
+ joke_agent = create_sub_agent_tool(
109
+ name="joke_agent",
110
+ description="Generates jokes about the current directory content.",
111
+ system_prompt=(
112
+ "You are a comedian. Use the 'run_shell_command' tool to list files "
113
+ "(ls -la) and make a funny joke about the project structure."
114
+ ),
115
+ tools=[run_shell_command],
116
+ )
117
+
118
+ llm_chat.prompt_manager.add_middleware(
119
+ new_prompt(get_persona_prompt(CFG.LLM_ASSISTANT_NAME)),
120
+ new_prompt(get_mandate_prompt()),
121
+ system_context,
122
+ create_note_prompt(note_manager),
123
+ create_claude_compatibility_prompt(skill_manager),
124
+ create_zrb_prompt(),
125
+ )
126
+ llm_chat.add_confirmation_middleware(replace_confirmation)
127
+ llm_chat.add_tool(
128
+ roll_dice,
129
+ joke_agent,
130
+ run_shell_command,
131
+ list_files,
132
+ read_file,
133
+ read_files,
134
+ write_file,
135
+ write_files,
136
+ replace_in_file,
137
+ search_files,
138
+ analyze_file,
139
+ analyze_code,
140
+ search_internet,
141
+ open_web_page,
142
+ create_list_zrb_task_tool(),
143
+ create_run_zrb_task_tool(),
144
+ create_activate_skill_tool(skill_manager),
145
+ *create_note_tools(note_manager),
146
+ )
147
+ llm_chat.add_tool(get_current_time)
@@ -204,7 +204,7 @@ def update_migration_metadata_file(ctx: AnyContext, migration_metadata_file_path
204
204
  app_name = os.path.basename(APP_DIR)
205
205
  existing_migration_metadata_code = read_file(migration_metadata_file_path)
206
206
  write_file(
207
- file_path=migration_metadata_file_path,
207
+ abs_file_path=migration_metadata_file_path,
208
208
  content=[
209
209
  _get_migration_import_schema_code(
210
210
  existing_migration_metadata_code, app_name, ctx.input.entity
@@ -251,7 +251,7 @@ def update_client_file(ctx: AnyContext, client_file_path: str):
251
251
  snake_plural_entity_name = to_snake_case(ctx.input.plural)
252
252
  pascal_entity_name = to_pascal_case(ctx.input.entity)
253
253
  write_file(
254
- file_path=client_file_path,
254
+ abs_file_path=client_file_path,
255
255
  content=[
256
256
  _get_import_schema_for_client_code(
257
257
  existing_code=existing_client_code, entity_name=ctx.input.entity
@@ -305,7 +305,7 @@ def update_api_client_file(ctx: AnyContext, api_client_file_path: str):
305
305
  snake_module_name = to_snake_case(ctx.input.module)
306
306
  pascal_module_name = to_pascal_case(ctx.input.module)
307
307
  write_file(
308
- file_path=api_client_file_path,
308
+ abs_file_path=api_client_file_path,
309
309
  content=[
310
310
  f"from {app_name}.module.{snake_module_name}.service.{snake_entity_name}.{snake_entity_name}_service_factory import {snake_entity_name}_service", # noqa
311
311
  prepend_code_to_module(
@@ -327,7 +327,7 @@ def update_direct_client_file(ctx: AnyContext, direct_client_file_path: str):
327
327
  snake_module_name = to_snake_case(ctx.input.module)
328
328
  pascal_module_name = to_pascal_case(ctx.input.module)
329
329
  write_file(
330
- file_path=direct_client_file_path,
330
+ abs_file_path=direct_client_file_path,
331
331
  content=[
332
332
  f"from {app_name}.module.{snake_module_name}.service.{snake_entity_name}.{snake_entity_name}_service_factory import {snake_entity_name}_service", # noqa
333
333
  prepend_code_to_module(
@@ -348,7 +348,7 @@ def update_route_file(ctx: AnyContext, route_file_path: str):
348
348
  app_name = os.path.basename(APP_DIR)
349
349
  module_name = to_snake_case(ctx.input.module)
350
350
  write_file(
351
- file_path=route_file_path,
351
+ abs_file_path=route_file_path,
352
352
  content=[
353
353
  f"from {app_name}.module.{module_name}.service.{entity_name}.{entity_name}_service_factory import {entity_name}_service", # noqa
354
354
  append_code_to_function(
@@ -370,7 +370,7 @@ def update_gateway_subroute_file(ctx: AnyContext, module_gateway_subroute_path:
370
370
  pascal_entity_name = to_pascal_case(ctx.input.entity)
371
371
  existing_gateway_subroute_code = read_file(module_gateway_subroute_path)
372
372
  write_file(
373
- file_path=module_gateway_subroute_path,
373
+ abs_file_path=module_gateway_subroute_path,
374
374
  content=[
375
375
  _get_import_client_for_gateway_subroute_code(
376
376
  existing_gateway_subroute_code, module_name=ctx.input.module
@@ -456,7 +456,7 @@ def update_gateway_navigation_config_file(
456
456
  },
457
457
  ).strip()
458
458
  write_file(
459
- file_path=gateway_navigation_config_file_path,
459
+ abs_file_path=gateway_navigation_config_file_path,
460
460
  content=[
461
461
  existing_gateway_navigation_config_code,
462
462
  new_navigation_config_code,