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
@@ -1,38 +0,0 @@
1
- import json
2
- import subprocess
3
-
4
-
5
- def run_shell_command(command: str) -> str:
6
- """
7
- Executes a shell command on the user's local machine and returns the output.
8
-
9
- This tool is powerful and should be used for tasks that require interacting
10
- with the command line, such as running scripts, managing system processes,
11
- or using command-line tools.
12
-
13
- **Security Warning:** This tool executes commands with the same permissions
14
- as the user running the assistant. Before executing any command that could
15
- modify files or system state (e.g., `git`, `npm`, `pip`, `docker`), you
16
- MUST explain what the command does and ask the user for confirmation.
17
-
18
- Args:
19
- command (str): The exact shell command to execute.
20
-
21
- Returns:
22
- str: A JSON string containing return code, standard output (stdout),
23
- and standard error (stderr) from the command.
24
- Example: {"return_code": 0, "stdout": "ok", "stderr": ""}
25
- """
26
- result = subprocess.run(
27
- command,
28
- shell=True,
29
- capture_output=True,
30
- text=True,
31
- )
32
- return json.dumps(
33
- {
34
- "return_code": result.returncode,
35
- "stdout": result.stdout,
36
- "stderr": result.stderr,
37
- }
38
- )
@@ -1,254 +0,0 @@
1
- import json
2
- import os
3
-
4
- from zrb.builtin.llm.tool.file import DEFAULT_EXCLUDED_PATTERNS, is_excluded
5
- from zrb.builtin.llm.tool.sub_agent import create_sub_agent_tool
6
- from zrb.config.config import CFG
7
- from zrb.config.llm_rate_limitter import llm_rate_limitter
8
- from zrb.context.any_context import AnyContext
9
-
10
- _DEFAULT_EXTENSIONS = [
11
- "py",
12
- "go",
13
- "java",
14
- "ts",
15
- "js",
16
- "rs",
17
- "rb",
18
- "php",
19
- "sh",
20
- "bash",
21
- "c",
22
- "cpp",
23
- "h",
24
- "hpp",
25
- "cs",
26
- "swift",
27
- "kt",
28
- "scala",
29
- "m",
30
- "pl",
31
- "lua",
32
- "sql",
33
- "html",
34
- "css",
35
- "scss",
36
- "less",
37
- "json",
38
- "yaml",
39
- "yml",
40
- "toml",
41
- "ini",
42
- "xml",
43
- "md",
44
- "rst",
45
- "txt",
46
- ]
47
-
48
-
49
- async def analyze_repo(
50
- ctx: AnyContext,
51
- path: str,
52
- goal: str,
53
- extensions: list[str] = _DEFAULT_EXTENSIONS,
54
- exclude_patterns: list[str] = DEFAULT_EXCLUDED_PATTERNS,
55
- extraction_token_threshold: int | None = None,
56
- summarization_token_threshold: int | None = None,
57
- ) -> str:
58
- """
59
- Performs a deep, goal-oriented analysis of a code repository or directory.
60
-
61
- This powerful tool recursively reads all relevant files in a directory,
62
- extracts key information, and then summarizes that information in relation
63
- to a specific goal. It uses intelligent sub-agents for extraction and
64
- summarization, making it ideal for complex tasks that require a holistic
65
- understanding of a codebase.
66
-
67
- To ensure a focused and effective analysis, it is crucial to provide a
68
- clear and specific goal. Vague goals will result in a vague analysis and
69
- may cause the tool to run for a long time.
70
-
71
- Use this tool for:
72
- - Understanding a large or unfamiliar codebase.
73
- - Generating high-level summaries of a project's architecture.
74
- - Performing a preliminary code review.
75
- - Creating documentation or diagrams (e.g., "Generate a Mermaid C4 diagram
76
- for this service").
77
- - Answering broad questions like "How does the authentication in this
78
- project work?".
79
-
80
- Args:
81
- path (str): The path to the directory or repository to analyze.
82
- goal (str): A clear and specific description of what you want to
83
- achieve. A good goal is critical for getting a useful result.
84
- - Good goal: "Understand the database schema by analyzing all the
85
- .sql files"
86
- - Good goal: "Create a summary of all the API endpoints defined in
87
- the 'api' directory"
88
- - Bad goal: "Analyze the repo"
89
- - Bad goal: "Tell me about the code"
90
- extensions (list[str], optional): A list of file extensions to include
91
- in the analysis. Defaults to a comprehensive list of common code
92
- and configuration files.
93
- exclude_patterns (list[str], optional): A list of glob patterns for
94
- files and directories to exclude from the analysis. Defaults to
95
- common patterns like '.git', 'node_modules', and '.venv'.
96
- extraction_token_threshold (int, optional): The maximum token
97
- threshold for the extraction sub-agent.
98
- summarization_token_threshold (int, optional): The maximum token
99
- threshold for the summarization sub-agent.
100
-
101
- Returns:
102
- str: A detailed, markdown-formatted analysis and summary of the
103
- repository, tailored to the specified goal.
104
- Raises:
105
- Exception: If an error occurs during the analysis.
106
- """
107
- if extraction_token_threshold is None:
108
- extraction_token_threshold = CFG.LLM_REPO_ANALYSIS_EXTRACTION_TOKEN_THRESHOLD
109
- if summarization_token_threshold is None:
110
- summarization_token_threshold = (
111
- CFG.LLM_REPO_ANALYSIS_SUMMARIZATION_TOKEN_THRESHOLD
112
- )
113
- abs_path = os.path.abspath(os.path.expanduser(path))
114
- file_metadatas = _get_file_metadatas(abs_path, extensions, exclude_patterns)
115
- ctx.print("Extraction")
116
- extracted_infos = await _extract_info(
117
- ctx,
118
- file_metadatas=file_metadatas,
119
- goal=goal,
120
- token_limit=extraction_token_threshold,
121
- )
122
- if len(extracted_infos) == 1:
123
- return extracted_infos[0]
124
- ctx.print("Summarization")
125
- summarized_infos = extracted_infos
126
- while len(summarized_infos) > 1:
127
- ctx.print("Summarization")
128
- summarized_infos = await _summarize_info(
129
- ctx,
130
- extracted_infos=summarized_infos,
131
- goal=goal,
132
- token_limit=summarization_token_threshold,
133
- )
134
- return summarized_infos[0]
135
-
136
-
137
- def _get_file_metadatas(
138
- dir_path: str,
139
- extensions: list[str],
140
- exclude_patterns: list[str],
141
- ) -> list[dict[str, str]]:
142
- metadata_list = []
143
- for root, _, files in os.walk(dir_path):
144
- files.sort()
145
- for file in files:
146
- if not any(file.endswith(f".{ext}") for ext in extensions):
147
- continue
148
- file_path = os.path.join(root, file)
149
- if is_excluded(file_path, exclude_patterns):
150
- continue
151
- try:
152
- with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
153
- rel_path = os.path.relpath(file_path, dir_path)
154
- metadata_list.append({"path": rel_path, "content": f.read()})
155
- except Exception as e:
156
- print(f"Error reading file {file_path}: {e}")
157
- metadata_list.sort(key=lambda m: m["path"])
158
- return metadata_list
159
-
160
-
161
- async def _extract_info(
162
- ctx: AnyContext,
163
- file_metadatas: list[dict[str, str]],
164
- goal: str,
165
- token_limit: int,
166
- ) -> list[str]:
167
- extract = create_sub_agent_tool(
168
- tool_name="extract",
169
- tool_description="extract",
170
- system_prompt=CFG.LLM_REPO_EXTRACTOR_SYSTEM_PROMPT,
171
- )
172
- extracted_infos = []
173
- content_buffer = []
174
- current_token_count = 0
175
- for metadata in file_metadatas:
176
- path = metadata.get("path", "")
177
- content = metadata.get("content", "")
178
- file_obj = {"path": path, "content": content}
179
- file_str = json.dumps(file_obj)
180
- if current_token_count + llm_rate_limitter.count_token(file_str) > token_limit:
181
- if content_buffer:
182
- prompt = _create_extract_info_prompt(goal, content_buffer)
183
- extracted_info = await extract(
184
- ctx, llm_rate_limitter.clip_prompt(prompt, token_limit)
185
- )
186
- extracted_infos.append(extracted_info)
187
- content_buffer = [file_obj]
188
- current_token_count = llm_rate_limitter.count_token(file_str)
189
- else:
190
- content_buffer.append(file_obj)
191
- current_token_count += llm_rate_limitter.count_token(file_str)
192
-
193
- # Process any remaining content in the buffer
194
- if content_buffer:
195
- prompt = _create_extract_info_prompt(goal, content_buffer)
196
- extracted_info = await extract(
197
- ctx, llm_rate_limitter.clip_prompt(prompt, token_limit)
198
- )
199
- extracted_infos.append(extracted_info)
200
- return extracted_infos
201
-
202
-
203
- def _create_extract_info_prompt(goal: str, content_buffer: list[dict]) -> str:
204
- return json.dumps(
205
- {
206
- "main_assistant_goal": goal,
207
- "files": content_buffer,
208
- }
209
- )
210
-
211
-
212
- async def _summarize_info(
213
- ctx: AnyContext,
214
- extracted_infos: list[str],
215
- goal: str,
216
- token_limit: int,
217
- ) -> list[str]:
218
- summarize = create_sub_agent_tool(
219
- tool_name="extract",
220
- tool_description="extract",
221
- system_prompt=CFG.LLM_REPO_SUMMARIZER_SYSTEM_PROMPT,
222
- )
223
- summarized_infos = []
224
- content_buffer = ""
225
- for extracted_info in extracted_infos:
226
- new_prompt = content_buffer + extracted_info
227
- if llm_rate_limitter.count_token(new_prompt) > token_limit:
228
- if content_buffer:
229
- prompt = _create_summarize_info_prompt(goal, content_buffer)
230
- summarized_info = await summarize(
231
- ctx, llm_rate_limitter.clip_prompt(prompt, token_limit)
232
- )
233
- summarized_infos.append(summarized_info)
234
- content_buffer = extracted_info
235
- else:
236
- content_buffer += extracted_info + "\n"
237
-
238
- # Process any remaining content in the buffer
239
- if content_buffer:
240
- prompt = _create_summarize_info_prompt(goal, content_buffer)
241
- summarized_info = await summarize(
242
- ctx, llm_rate_limitter.clip_prompt(prompt, token_limit)
243
- )
244
- summarized_infos.append(summarized_info)
245
- return summarized_infos
246
-
247
-
248
- def _create_summarize_info_prompt(goal: str, content_buffer: str) -> str:
249
- return json.dumps(
250
- {
251
- "main_assistant_goal": goal,
252
- "extracted_info": content_buffer,
253
- }
254
- )