zrb 1.13.1__py3-none-any.whl → 1.21.17__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.
Files changed (105) hide show
  1. zrb/__init__.py +2 -6
  2. zrb/attr/type.py +8 -8
  3. zrb/builtin/__init__.py +2 -0
  4. zrb/builtin/group.py +31 -15
  5. zrb/builtin/http.py +7 -8
  6. zrb/builtin/llm/attachment.py +40 -0
  7. zrb/builtin/llm/chat_session.py +130 -144
  8. zrb/builtin/llm/chat_session_cmd.py +226 -0
  9. zrb/builtin/llm/chat_trigger.py +73 -0
  10. zrb/builtin/llm/history.py +4 -4
  11. zrb/builtin/llm/llm_ask.py +218 -110
  12. zrb/builtin/llm/tool/api.py +74 -62
  13. zrb/builtin/llm/tool/cli.py +35 -16
  14. zrb/builtin/llm/tool/code.py +49 -47
  15. zrb/builtin/llm/tool/file.py +262 -251
  16. zrb/builtin/llm/tool/note.py +84 -0
  17. zrb/builtin/llm/tool/rag.py +25 -18
  18. zrb/builtin/llm/tool/sub_agent.py +29 -22
  19. zrb/builtin/llm/tool/web.py +135 -143
  20. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +7 -7
  21. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +5 -5
  22. zrb/builtin/project/add/fastapp/fastapp_util.py +1 -1
  23. zrb/builtin/searxng/config/settings.yml +5671 -0
  24. zrb/builtin/searxng/start.py +21 -0
  25. zrb/builtin/setup/latex/ubuntu.py +1 -0
  26. zrb/builtin/setup/ubuntu.py +1 -1
  27. zrb/builtin/shell/autocomplete/bash.py +4 -3
  28. zrb/builtin/shell/autocomplete/zsh.py +4 -3
  29. zrb/config/config.py +255 -78
  30. zrb/config/default_prompt/file_extractor_system_prompt.md +109 -9
  31. zrb/config/default_prompt/interactive_system_prompt.md +24 -30
  32. zrb/config/default_prompt/persona.md +1 -1
  33. zrb/config/default_prompt/repo_extractor_system_prompt.md +31 -31
  34. zrb/config/default_prompt/repo_summarizer_system_prompt.md +27 -8
  35. zrb/config/default_prompt/summarization_prompt.md +8 -13
  36. zrb/config/default_prompt/system_prompt.md +36 -30
  37. zrb/config/llm_config.py +129 -24
  38. zrb/config/llm_context/config.py +127 -90
  39. zrb/config/llm_context/config_parser.py +1 -7
  40. zrb/config/llm_context/workflow.py +81 -0
  41. zrb/config/llm_rate_limitter.py +89 -45
  42. zrb/context/any_shared_context.py +7 -1
  43. zrb/context/context.py +8 -2
  44. zrb/context/shared_context.py +6 -8
  45. zrb/group/any_group.py +12 -5
  46. zrb/group/group.py +67 -3
  47. zrb/input/any_input.py +5 -1
  48. zrb/input/base_input.py +18 -6
  49. zrb/input/text_input.py +7 -24
  50. zrb/runner/cli.py +21 -20
  51. zrb/runner/common_util.py +24 -19
  52. zrb/runner/web_route/task_input_api_route.py +5 -5
  53. zrb/runner/web_route/task_session_api_route.py +1 -4
  54. zrb/runner/web_util/user.py +7 -3
  55. zrb/session/any_session.py +12 -6
  56. zrb/session/session.py +39 -18
  57. zrb/task/any_task.py +24 -3
  58. zrb/task/base/context.py +17 -9
  59. zrb/task/base/execution.py +15 -8
  60. zrb/task/base/lifecycle.py +8 -4
  61. zrb/task/base/monitoring.py +12 -7
  62. zrb/task/base_task.py +69 -5
  63. zrb/task/base_trigger.py +12 -5
  64. zrb/task/llm/agent.py +138 -52
  65. zrb/task/llm/config.py +45 -13
  66. zrb/task/llm/conversation_history.py +76 -6
  67. zrb/task/llm/conversation_history_model.py +0 -168
  68. zrb/task/llm/default_workflow/coding/workflow.md +41 -0
  69. zrb/task/llm/default_workflow/copywriting/workflow.md +68 -0
  70. zrb/task/llm/default_workflow/git/workflow.md +118 -0
  71. zrb/task/llm/default_workflow/golang/workflow.md +128 -0
  72. zrb/task/llm/default_workflow/html-css/workflow.md +135 -0
  73. zrb/task/llm/default_workflow/java/workflow.md +146 -0
  74. zrb/task/llm/default_workflow/javascript/workflow.md +158 -0
  75. zrb/task/llm/default_workflow/python/workflow.md +160 -0
  76. zrb/task/llm/default_workflow/researching/workflow.md +153 -0
  77. zrb/task/llm/default_workflow/rust/workflow.md +162 -0
  78. zrb/task/llm/default_workflow/shell/workflow.md +299 -0
  79. zrb/task/llm/file_replacement.py +206 -0
  80. zrb/task/llm/file_tool_model.py +57 -0
  81. zrb/task/llm/history_summarization.py +22 -35
  82. zrb/task/llm/history_summarization_tool.py +24 -0
  83. zrb/task/llm/print_node.py +182 -63
  84. zrb/task/llm/prompt.py +213 -153
  85. zrb/task/llm/tool_wrapper.py +210 -53
  86. zrb/task/llm/workflow.py +76 -0
  87. zrb/task/llm_task.py +98 -47
  88. zrb/task/make_task.py +2 -3
  89. zrb/task/rsync_task.py +25 -10
  90. zrb/task/scheduler.py +4 -4
  91. zrb/util/attr.py +50 -40
  92. zrb/util/cli/markdown.py +12 -0
  93. zrb/util/cli/text.py +30 -0
  94. zrb/util/file.py +27 -11
  95. zrb/util/{llm/prompt.py → markdown.py} +2 -3
  96. zrb/util/string/conversion.py +1 -1
  97. zrb/util/truncate.py +23 -0
  98. zrb/util/yaml.py +204 -0
  99. {zrb-1.13.1.dist-info → zrb-1.21.17.dist-info}/METADATA +40 -20
  100. {zrb-1.13.1.dist-info → zrb-1.21.17.dist-info}/RECORD +102 -79
  101. {zrb-1.13.1.dist-info → zrb-1.21.17.dist-info}/WHEEL +1 -1
  102. zrb/task/llm/default_workflow/coding.md +0 -24
  103. zrb/task/llm/default_workflow/copywriting.md +0 -17
  104. zrb/task/llm/default_workflow/researching.md +0 -18
  105. {zrb-1.13.1.dist-info → zrb-1.21.17.dist-info}/entry_points.txt +0 -0
@@ -1,18 +1,45 @@
1
1
  import json
2
+ import os
2
3
  from collections.abc import Callable
3
4
  from copy import deepcopy
4
5
  from typing import Any
5
6
 
6
7
  from zrb.attr.type import StrAttr
8
+ from zrb.config.llm_context.config import llm_context_config
7
9
  from zrb.context.any_context import AnyContext
8
- from zrb.context.any_shared_context import AnySharedContext
9
10
  from zrb.task.llm.conversation_history_model import ConversationHistory
10
11
  from zrb.task.llm.typing import ListOfDict
11
12
  from zrb.util.attr import get_str_attr
12
- from zrb.util.file import write_file
13
+ from zrb.util.file import read_file, write_file
14
+ from zrb.util.markdown import make_markdown_section
13
15
  from zrb.util.run import run_async
14
16
 
15
17
 
18
+ def inject_conversation_history_notes(conversation_history: ConversationHistory):
19
+ conversation_history.long_term_note = _fetch_long_term_note(
20
+ conversation_history.project_path
21
+ )
22
+ conversation_history.contextual_note = _fetch_contextual_note(
23
+ conversation_history.project_path
24
+ )
25
+
26
+
27
+ def _fetch_long_term_note(project_path: str) -> str:
28
+ contexts = llm_context_config.get_notes(cwd=project_path)
29
+ return contexts.get("/", "")
30
+
31
+
32
+ def _fetch_contextual_note(project_path: str) -> str:
33
+ contexts = llm_context_config.get_notes(cwd=project_path)
34
+ return "\n".join(
35
+ [
36
+ make_markdown_section(header, content)
37
+ for header, content in contexts.items()
38
+ if header != "/"
39
+ ]
40
+ )
41
+
42
+
16
43
  def get_history_file(
17
44
  ctx: AnyContext,
18
45
  conversation_history_file_attr: StrAttr | None,
@@ -27,16 +54,59 @@ def get_history_file(
27
54
  )
28
55
 
29
56
 
57
+ async def _read_from_source(
58
+ ctx: AnyContext,
59
+ reader: Callable[[AnyContext], dict[str, Any] | list | None] | None,
60
+ file_path: str | None,
61
+ ) -> "ConversationHistory | None":
62
+ # Priority 1: Reader function
63
+ if reader:
64
+ try:
65
+ raw_data = await run_async(reader(ctx))
66
+ if raw_data:
67
+ instance = ConversationHistory.parse_and_validate(
68
+ ctx, raw_data, "reader"
69
+ )
70
+ if instance:
71
+ return instance
72
+ except Exception as e:
73
+ ctx.log_warning(
74
+ f"Error executing conversation history reader: {e}. Ignoring."
75
+ )
76
+ # Priority 2: History file
77
+ if file_path and os.path.isfile(file_path):
78
+ try:
79
+ content = read_file(file_path)
80
+ raw_data = json.loads(content)
81
+ instance = ConversationHistory.parse_and_validate(
82
+ ctx, raw_data, f"file '{file_path}'"
83
+ )
84
+ if instance:
85
+ return instance
86
+ except json.JSONDecodeError:
87
+ ctx.log_warning(
88
+ f"Could not decode JSON from history file '{file_path}'. "
89
+ "Ignoring file content."
90
+ )
91
+ except Exception as e:
92
+ ctx.log_warning(
93
+ f"Error reading history file '{file_path}': {e}. "
94
+ "Ignoring file content."
95
+ )
96
+ # Fallback: Return default value
97
+ return None
98
+
99
+
30
100
  async def read_conversation_history(
31
101
  ctx: AnyContext,
32
102
  conversation_history_reader: (
33
- Callable[[AnySharedContext], ConversationHistory | dict | list | None] | None
103
+ Callable[[AnyContext], ConversationHistory | dict | list | None] | None
34
104
  ),
35
105
  conversation_history_file_attr: StrAttr | None,
36
106
  render_history_file: bool,
37
107
  conversation_history_attr: (
38
108
  ConversationHistory
39
- | Callable[[AnySharedContext], ConversationHistory | dict | list]
109
+ | Callable[[AnyContext], ConversationHistory | dict | list]
40
110
  | dict
41
111
  | list
42
112
  ),
@@ -46,7 +116,7 @@ async def read_conversation_history(
46
116
  ctx, conversation_history_file_attr, render_history_file
47
117
  )
48
118
  # Use the class method defined above
49
- history_data = await ConversationHistory.read_from_source(
119
+ history_data = await _read_from_source(
50
120
  ctx=ctx,
51
121
  reader=conversation_history_reader,
52
122
  file_path=history_file,
@@ -80,7 +150,7 @@ async def write_conversation_history(
80
150
  ctx: AnyContext,
81
151
  history_data: ConversationHistory,
82
152
  conversation_history_writer: (
83
- Callable[[AnySharedContext, ConversationHistory], None] | None
153
+ Callable[[AnyContext, ConversationHistory], None] | None
84
154
  ),
85
155
  conversation_history_file_attr: StrAttr | None,
86
156
  render_history_file: bool,
@@ -1,14 +1,9 @@
1
1
  import json
2
2
  import os
3
- from collections.abc import Callable
4
3
  from typing import Any
5
4
 
6
- from zrb.config.llm_context.config import llm_context_config
7
5
  from zrb.context.any_context import AnyContext
8
6
  from zrb.task.llm.typing import ListOfDict
9
- from zrb.util.file import read_file
10
- from zrb.util.llm.prompt import make_prompt_section
11
- from zrb.util.run import run_async
12
7
 
13
8
 
14
9
  class ConversationHistory:
@@ -41,50 +36,6 @@ class ConversationHistory:
41
36
  def model_dump_json(self, indent: int = 2) -> str:
42
37
  return json.dumps(self.to_dict(), indent=indent)
43
38
 
44
- @classmethod
45
- async def read_from_source(
46
- cls,
47
- ctx: AnyContext,
48
- reader: Callable[[AnyContext], dict[str, Any] | list | None] | None,
49
- file_path: str | None,
50
- ) -> "ConversationHistory | None":
51
- # Priority 1: Reader function
52
- if reader:
53
- try:
54
- raw_data = await run_async(reader(ctx))
55
- if raw_data:
56
- instance = cls.parse_and_validate(ctx, raw_data, "reader")
57
- if instance:
58
- return instance
59
- except Exception as e:
60
- ctx.log_warning(
61
- f"Error executing conversation history reader: {e}. Ignoring."
62
- )
63
- # Priority 2: History file
64
- if file_path and os.path.isfile(file_path):
65
- try:
66
- content = read_file(file_path)
67
- raw_data = json.loads(content)
68
- instance = cls.parse_and_validate(ctx, raw_data, f"file '{file_path}'")
69
- if instance:
70
- return instance
71
- except json.JSONDecodeError:
72
- ctx.log_warning(
73
- f"Could not decode JSON from history file '{file_path}'. "
74
- "Ignoring file content."
75
- )
76
- except Exception as e:
77
- ctx.log_warning(
78
- f"Error reading history file '{file_path}': {e}. "
79
- "Ignoring file content."
80
- )
81
- # Fallback: Return default value
82
- return None
83
-
84
- def fetch_newest_notes(self):
85
- self._fetch_long_term_note()
86
- self._fetch_contextual_note()
87
-
88
39
  @classmethod
89
40
  def parse_and_validate(
90
41
  cls, ctx: AnyContext, data: Any, source: str
@@ -121,122 +72,3 @@ class ConversationHistory:
121
72
  f"Error validating/parsing history data from {source}: {e}. Ignoring."
122
73
  )
123
74
  return cls()
124
-
125
- def write_past_conversation_summary(self, past_conversation_summary: str):
126
- """
127
- Write or update the past conversation summary.
128
-
129
- Use this tool to store or update a summary of previous conversations for
130
- future reference. This is useful for providing context to LLMs or other tools
131
- that need a concise history.
132
-
133
- Args:
134
- past_conversation_summary (str): The summary text to store.
135
-
136
- Returns:
137
- str: A JSON object indicating the success or failure of the operation.
138
-
139
- Raises:
140
- Exception: If the summary cannot be written.
141
- """
142
- self.past_conversation_summary = past_conversation_summary
143
- return json.dumps({"success": True})
144
-
145
- def write_past_conversation_transcript(self, past_conversation_transcript: str):
146
- """
147
- Write or update the past conversation transcript.
148
-
149
- Use this tool to store or update the full transcript of previous conversations.
150
- This is useful for providing detailed context to LLMs or for record-keeping.
151
-
152
- Args:
153
- past_conversation_transcript (str): The transcript text to store.
154
-
155
- Returns:
156
- str: A JSON object indicating the success or failure of the operation.
157
-
158
- Raises:
159
- Exception: If the transcript cannot be written.
160
- """
161
- self.past_conversation_transcript = past_conversation_transcript
162
- return json.dumps({"success": True})
163
-
164
- def read_long_term_note(self) -> str:
165
- """
166
- Read the content of the long-term references.
167
-
168
- This tool helps you retrieve knowledge or notes stored for long-term reference.
169
- If the note does not exist, you may want to create it using the write tool.
170
-
171
- Returns:
172
- str: JSON with content of the notes.
173
-
174
- Raises:
175
- Exception: If the note cannot be read.
176
- """
177
- return json.dumps({"content": self._fetch_long_term_note()})
178
-
179
- def write_long_term_note(self, content: str) -> str:
180
- """
181
- Write the entire content of the long-term references.
182
- This will overwrite any existing long-term notes.
183
-
184
- Args:
185
- content (str): The full content of the long-term notes.
186
-
187
- Returns:
188
- str: JSON indicating success.
189
- """
190
- llm_context_config.write_context(content, context_path="/")
191
- return json.dumps({"success": True})
192
-
193
- def read_contextual_note(self) -> str:
194
- """
195
- Read the content of the contextual references for the current project.
196
-
197
- This tool helps you retrieve knowledge or notes stored for contextual reference.
198
- If the note does not exist, you may want to create it using the write tool.
199
-
200
- Returns:
201
- str: JSON with content of the notes.
202
-
203
- Raises:
204
- Exception: If the note cannot be read.
205
- """
206
- return json.dumps({"content": self._fetch_contextual_note()})
207
-
208
- def write_contextual_note(
209
- self, content: str, context_path: str | None = None
210
- ) -> str:
211
- """
212
- Write the entire content of the contextual references for a specific path.
213
- This will overwrite any existing contextual notes for that path.
214
-
215
- Args:
216
- content (str): The full content of the contextual notes.
217
- context_path (str, optional): The directory path for the context.
218
- Defaults to the current project path.
219
-
220
- Returns:
221
- str: JSON indicating success.
222
- """
223
- if context_path is None:
224
- context_path = self.project_path
225
- llm_context_config.write_context(content, context_path=context_path)
226
- return json.dumps({"success": True})
227
-
228
- def _fetch_long_term_note(self):
229
- contexts = llm_context_config.get_contexts(cwd=self.project_path)
230
- self.long_term_note = contexts.get("/", "")
231
- return self.long_term_note
232
-
233
- def _fetch_contextual_note(self):
234
- contexts = llm_context_config.get_contexts(cwd=self.project_path)
235
- self.contextual_note = "\n".join(
236
- [
237
- make_prompt_section(header, content)
238
- for header, content in contexts.items()
239
- if header != "/"
240
- ]
241
- )
242
- return self.contextual_note
@@ -0,0 +1,41 @@
1
+ ---
2
+ description: "A comprehensive workflow for software engineering tasks, including writing, modifying, and debugging code, as well as creating new applications. ALWAYS activate this workflow whenever you need to deal with software engineering tasks."
3
+ ---
4
+
5
+ This workflow provides a structured approach to software engineering tasks. Adhere to these guidelines to deliver high-quality, idiomatic code that respects the project's existing patterns and conventions.
6
+
7
+ # Workflow Loading Strategy
8
+
9
+ This is a general-purpose coding workflow. For tasks involving specific languages or tools, you **MUST** load the relevant specialized workflows.
10
+
11
+ - **If the task involves Python:** Load the `python` workflow.
12
+ - **If the task involves Git:** Load the `git` workflow.
13
+ - **If the task involves shell scripting:** Load the `shell` workflow.
14
+ - **If the task involves Go:** Load the `golang` workflow.
15
+ - **If the task involves Java:** Load the `java` workflow.
16
+ - **If the task involves Javascript/Typescript:** Load the `javascript` workflow.
17
+ - **If the task involves HTML/CSS:** Load the `html-css` workflow.
18
+ - **If the task involves Rust:** Load the `rust` workflow.
19
+
20
+ Always consider if a more specific workflow is available and appropriate for the task at hand.
21
+
22
+ # Core Mandates
23
+
24
+ - **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
25
+ - **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project (check imports, configuration files like 'package.json', 'Cargo.toml', 'requirements.txt', 'build.gradle', etc., or observe neighboring files) before employing it.
26
+ - **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
27
+ - **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
28
+ - **Comments:** Add code comments sparingly. Focus on *why* something is done, especially for complex logic, rather than *what* is done. Only add high-value comments if necessary for clarity or if requested by the user. Do not edit comments that are separate from the code you are changing. *NEVER* talk to the user or describe your changes through comments.
29
+ - **Proactiveness:** Fulfill the user's request thoroughly. When adding features or fixing bugs, this includes adding tests to ensure quality. Consider all created files, especially tests, to be permanent artifacts unless the user says otherwise.
30
+ - **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it.
31
+ - **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked.
32
+ - **Do Not revert changes:** Do not revert changes to the codebase unless asked to do so by the user. Only revert changes made by you if they have resulted in an error or if the user has explicitly asked you to revert the changes.
33
+
34
+ # Software Engineering Tasks
35
+ When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
36
+ 1. **Understand & Strategize:** Think about the user's request and the relevant codebase context. When the task involves **complex refactoring, codebase exploration or system-wide analysis**, your **first and primary tool** must be 'codebase_investigator'. Use it to build a comprehensive understanding of the code, its structure, and dependencies. For **simple, targeted searches** (like finding a specific function name, file path, or variable declaration), you should use 'search_file_content' or 'glob' directly.
37
+ 2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution.
38
+ 3. **Implement:** Use the available tools (e.g., 'replace_in_file', 'write_to_file' 'run_shell_command' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates').
39
+ 4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands.
40
+ 5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards. If unsure about these commands, you can ask the user if they'd like you to run them and if so how to.
41
+ 6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction.
@@ -0,0 +1,68 @@
1
+ ---
2
+ description: "A workflow for creating, refining, and organizing textual content."
3
+ ---
4
+ Follow this workflow to produce content that is not just correct, but compelling, clear, and perfectly suited to its purpose.
5
+
6
+ # Core Mandates
7
+
8
+ - **Audience-First:** Always understand who you're writing for and what they need to know
9
+ - **Purpose-Driven:** Every piece of content must serve a clear objective
10
+ - **Quality Standards:** Deliver polished, professional content that meets the highest standards
11
+ - **Iterative Refinement:** Content improves through multiple rounds of review and editing
12
+
13
+ # Tool Usage Guideline
14
+ - Use `read_from_file` to analyze existing content and style guides
15
+ - Use `write_to_file` for creating new content drafts
16
+ - Use `replace_in_file` for targeted edits and refinements
17
+
18
+ # Step 1: Understand Intent and Audience
19
+
20
+ 1. **Define the Goal:** What is this text supposed to achieve? (e.g., persuade, inform, entertain, sell). If the user is vague, ask for clarification.
21
+ 2. **Identify the Audience:** Who are you writing for? (e.g., experts, beginners, customers). This dictates your tone, vocabulary, and level of detail.
22
+ 3. **Determine the Tone:** Choose a voice that serves the goal and resonates with the audience (e.g., formal, witty, technical, urgent).
23
+ 4. **Analyze Existing Content:** Review any provided examples, style guides, or reference materials to understand established patterns.
24
+
25
+ # Step 2: Plan and Outline
26
+
27
+ 1. **Create Logical Structure:** Develop an outline that flows naturally from introduction to conclusion
28
+ 2. **Key Sections:** Identify main talking points and supporting arguments
29
+ 3. **Call-to-Action:** Define what you want the reader to do or think after reading
30
+ 4. **Get Approval:** Present the outline to the user for confirmation before proceeding
31
+
32
+ # Step 3: Draft with Purpose
33
+
34
+ 1. **Hook the Reader:** Start with a strong opening that grabs attention
35
+ 2. **Use Active Voice:** Make your writing direct and energetic
36
+ 3. **Show, Don't Just Tell:** Use examples, stories, and data to illustrate your points
37
+ 4. **Maintain Consistency:** Stick to the established tone and style throughout
38
+
39
+ # Step 4: Refine and Polish
40
+
41
+ 1. **Read Aloud:** Catch awkward phrasing and grammatical errors
42
+ 2. **Cut Mercilessly:** Remove anything that doesn't serve the goal
43
+ 3. **Enhance Readability:** Use short paragraphs, headings, bullet points, and bold text
44
+ 4. **Verify Accuracy:** Ensure all facts, figures, and claims are correct
45
+
46
+ # Step 5: Task-Specific Execution
47
+
48
+ ## Summarization
49
+ - Distill the essence while preserving key information
50
+ - Be objective and ruthless in cutting fluff
51
+ - Maintain the original meaning and context
52
+
53
+ ## Proofreading
54
+ - Correct grammar, spelling, and punctuation
55
+ - Improve sentence flow and clarity
56
+ - Preserve the original meaning and voice
57
+
58
+ ## Refining/Editing
59
+ - Sharpen the author's message
60
+ - Strengthen arguments and improve clarity
61
+ - Ensure consistent tone while respecting the original voice
62
+
63
+ # Step 6: Finalize and Deliver
64
+
65
+ - Present the final content to the user
66
+ - Be prepared to make additional refinements based on feedback
67
+ - Ensure the content meets all stated objectives
68
+ - Confirm the content is ready for its intended use
@@ -0,0 +1,118 @@
1
+ ---
2
+ description: "A workflow for managing version control with git."
3
+ ---
4
+ Follow this workflow for safe, consistent, and effective version control operations.
5
+
6
+ # Core Mandates
7
+
8
+ - **Safety First:** Never force operations that could lose data
9
+ - **Atomic Commits:** One logical change per commit
10
+ - **Descriptive Messages:** Explain the "why" in imperative mood
11
+ - **Clean History:** Maintain a readable and useful commit history
12
+
13
+ # Tool Usage Guideline
14
+ - Use `run_shell_command` for all git operations
15
+ - Use `read_from_file` to examine git configuration files
16
+ - Use `search_files` to find specific commit messages or patterns
17
+
18
+ # Step 1: Pre-Operation Safety Check
19
+
20
+ 1. **Check Status:** Always run `git status` before operations
21
+ 2. **Verify Working Directory:** Ensure the working directory is clean before destructive operations
22
+ 3. **Review Changes:** Use `git diff` and `git diff --staged` to understand what will be committed
23
+ 4. **Backup Important Changes:** Consider stashing or creating a backup branch for risky operations
24
+
25
+ # Step 2: Standard Development Workflow
26
+
27
+ 1. **Create Feature Branch:** `git checkout -b <branch-name>`
28
+ 2. **Make Changes:** Implement features or fixes
29
+ 3. **Stage Changes:** Use `git add -p` for precision staging
30
+ 4. **Commit with Description:** Write clear, descriptive commit messages
31
+ 5. **Review and Amend:** Use `git log -1` to review, amend if needed
32
+ 6. **Push to Remote:** `git push origin <branch-name>`
33
+
34
+ # Step 3: Commit Message Standards
35
+
36
+ ```
37
+ feat: Add user authentication endpoint
38
+
39
+ Implement the /login endpoint using JWT for token-based auth.
40
+ This resolves issue #123 by providing a mechanism for users to
41
+ log in and receive an access token.
42
+ ```
43
+
44
+ - **Type Prefix:** feat, fix, docs, style, refactor, test, chore
45
+ - **Imperative Mood:** "Add feature" not "Added feature"
46
+ - **50/72 Rule:** 50 character subject, 72 character body lines
47
+
48
+ # Step 4: Branch Management
49
+
50
+ ## Safe Branch Operations
51
+ - **Create:** `git checkout -b <name>` or `git switch -c <name>`
52
+ - **Switch:** `git switch <name>`
53
+ - **Update:** `git rebase main` (use with care)
54
+ - **Merge:** `git merge --no-ff <branch>` for explicit merge commits
55
+
56
+ ## Remote Branch Operations
57
+ - **Fetch Updates:** `git fetch origin`
58
+ - **Push:** `git push origin <branch>`
59
+ - **Delete Remote:** `git push origin --delete <branch>`
60
+
61
+ # Step 5: Advanced Operations (Use with Caution)
62
+
63
+ ## Rebasing
64
+ - **Update Branch:** `git rebase main`
65
+ - **Interactive:** `git rebase -i <commit>` for history editing
66
+ - **Safety:** Never rebase shared/public branches
67
+
68
+ ## Stashing
69
+ - **Save Changes:** `git stash push -m "message"`
70
+ - **List Stashes:** `git stash list`
71
+ - **Apply:** `git stash pop` or `git stash apply`
72
+
73
+ ## Cherry-picking
74
+ - **Apply Specific Commit:** `git cherry-pick <commit-hash>`
75
+ - **Use Case:** Only when absolutely necessary to avoid duplicate commits
76
+
77
+ # Step 6: Verification and Cleanup
78
+
79
+ 1. **Verify Operations:** Check `git status` and `git log` after operations
80
+ 2. **Run Tests:** Ensure all tests pass after changes
81
+ 3. **Clean Up:** Remove temporary branches and stashes when no longer needed
82
+ 4. **Document:** Update documentation if workflow changes affect team processes
83
+
84
+ # Risk Assessment Guidelines
85
+
86
+ ## Low Risk (Proceed Directly)
87
+ - `git status`, `git log`, `git diff`
88
+ - Creating new branches
89
+ - Stashing changes
90
+
91
+ ## Moderate Risk (Explain and Confirm)
92
+ - `git rebase` operations
93
+ - `git push --force-with-lease`
94
+ - Deleting branches
95
+
96
+ ## High Risk (Refuse and Explain)
97
+ - `git push --force` (use --force-with-lease instead)
98
+ - Operations that could lose commit history
99
+ - Modifying shared/public branches
100
+
101
+ # Common Commands Reference
102
+
103
+ ## Status & History
104
+ - `git status`: Check working directory status
105
+ - `git diff`: See uncommitted changes to tracked files
106
+ - `git diff --staged`: See staged changes
107
+ - `git log --oneline --graph -10`: View recent commit history
108
+ - `git blame <file>`: See who changed what in a file
109
+
110
+ ## Branch Operations
111
+ - `git branch -a`: List all branches (local and remote)
112
+ - `git branch -d <branch>`: Delete a local branch
113
+ - `git remote prune origin`: Clean up remote tracking branches
114
+
115
+ ## Configuration
116
+ - `git config --list`: View current configuration
117
+ - `git config user.name "Your Name"`: Set user name
118
+ - `git config user.email "your.email@example.com"`: Set user email
@@ -0,0 +1,128 @@
1
+ ---
2
+ description: "A workflow for developing with Go, including project analysis and best practices."
3
+ ---
4
+ Follow this workflow to deliver high-quality, idiomatic Go code that respects project conventions.
5
+
6
+ # Core Mandates
7
+
8
+ - **Simplicity First:** Write clear, simple, and readable code
9
+ - **Idiomatic Go:** Follow Go conventions and community standards
10
+ - **Tool Integration:** Leverage Go's excellent tooling ecosystem
11
+ - **Safety and Reliability:** Write robust, well-tested code
12
+
13
+ # Tool Usage Guideline
14
+ - Use `read_from_file` to analyze Go modules and configuration
15
+ - Use `search_files` to find Go patterns and conventions
16
+ - Use `run_shell_command` for Go toolchain operations
17
+ - Use `list_files` to understand project structure
18
+
19
+ # Step 1: Project Analysis
20
+
21
+ 1. **Module Information:** Examine `go.mod` for module path and dependencies
22
+ 2. **Workspace:** Check for `go.work` for multi-module workspace configuration
23
+ 3. **Tooling:** Look for `Makefile` with build, test, and lint commands
24
+ 4. **CI/CD Configuration:** Check `.github/workflows/go.yml` for verification commands
25
+ 5. **Linting Config:** Examine `.golangci.yml` for linting rules
26
+ 6. **Package Structure:** Analyze `pkg/`, `internal/`, and `cmd/` directories
27
+
28
+ # Step 2: Understand Conventions
29
+
30
+ 1. **Formatting:** `go fmt` is mandatory for all code
31
+ 2. **Linting:** Adhere to project's `golangci-lint` configuration
32
+ 3. **Package Naming:** Use short, concise, all-lowercase package names
33
+ 4. **Error Handling:** Match existing error handling patterns
34
+ 5. **Testing:** Follow established test structure and patterns
35
+
36
+ # Step 3: Implementation Planning
37
+
38
+ 1. **File Structure:** Plan where new code should be placed based on project conventions
39
+ 2. **Dependencies:** Identify if new dependencies are needed and verify they're appropriate
40
+ 3. **API Design:** Consider how new code integrates with existing APIs
41
+ 4. **Testing Strategy:** Plan comprehensive tests for new functionality
42
+
43
+ # Step 4: Write Code
44
+
45
+ ## Code Quality Standards
46
+ - **Formatting:** All code must be `go fmt` compliant
47
+ - **Linting:** Address all `golangci-lint` warnings
48
+ - **Naming:** Follow Go naming conventions (camelCase for variables, PascalCase for exports)
49
+ - **Documentation:** Add godoc comments for exported functions and types
50
+
51
+ ## Implementation Patterns
52
+ - **Error Handling:** Use appropriate error wrapping based on project patterns
53
+ - **Concurrency:** Follow existing goroutine and channel usage patterns
54
+ - **Interfaces:** Define small, focused interfaces
55
+ - **Composition:** Prefer composition over inheritance
56
+
57
+ # Step 5: Testing and Verification
58
+
59
+ 1. **Write Tests:** Create comprehensive tests for all new functionality
60
+ 2. **Run Tests:** Execute `go test ./...` to verify functionality
61
+ 3. **Format Code:** Run `go fmt ./...` to ensure proper formatting
62
+ 4. **Lint Code:** Run `golangci-lint run` to catch issues
63
+ 5. **Build Verification:** Run `go build ./...` to ensure code compiles
64
+
65
+ # Step 6: Quality Assurance
66
+
67
+ ## Testing Standards
68
+ - **Table-Driven Tests:** Use for comprehensive test coverage
69
+ - **Test Files:** Place tests in `_test.go` files within the same package
70
+ - **Benchmarks:** Add benchmarks for performance-critical code
71
+ - **Examples:** Include example code in documentation
72
+
73
+ ## Code Review Checklist
74
+ - [ ] Code follows project formatting standards
75
+ - [ ] All tests pass
76
+ - [ ] No linting warnings
77
+ - [ ] Error handling is appropriate
78
+ - [ ] Documentation is complete
79
+ - [ ] Performance considerations addressed
80
+
81
+ # Step 7: Finalize and Deliver
82
+
83
+ 1. **Verify Dependencies:** Run `go mod tidy` to clean up dependencies
84
+ 2. **Run Full Test Suite:** Ensure all existing tests still pass
85
+ 3. **Document Changes:** Update relevant documentation
86
+ 4. **Prepare for Review:** Ensure code is ready for team review
87
+
88
+ # Common Commands Reference
89
+
90
+ ## Development
91
+ - `go fmt ./...`: Format all Go code
92
+ - `go vet ./...`: Report suspicious constructs
93
+ - `go build ./...`: Build all packages
94
+ - `go run ./cmd/my-app`: Run a specific application
95
+
96
+ ## Testing
97
+ - `go test ./...`: Run all tests
98
+ - `go test -v ./...`: Run tests with verbose output
99
+ - `go test -race ./...`: Run tests with race detector
100
+ - `go test -bench=. ./...`: Run benchmarks
101
+
102
+ ## Dependency Management
103
+ - `go mod tidy`: Add missing and remove unused modules
104
+ - `go mod download`: Download modules to local cache
105
+ - `go list -m all`: List all dependencies
106
+ - `go get package@version`: Add or update a dependency
107
+
108
+ ## Debugging
109
+ - `dlv debug`: Debug with Delve
110
+ - `go tool pprof`: Performance profiling
111
+ - `go tool trace`: Execution tracing
112
+
113
+ # Risk Assessment Guidelines
114
+
115
+ ## Low Risk (Proceed Directly)
116
+ - Reading configuration files
117
+ - Running tests and linters
118
+ - Adding tests to existing packages
119
+
120
+ ## Moderate Risk (Explain and Confirm)
121
+ - Adding new dependencies
122
+ - Modifying core business logic
123
+ - Changing public API interfaces
124
+
125
+ ## High Risk (Refuse and Explain)
126
+ - Modifying critical system paths
127
+ - Operations that could break the build
128
+ - Changes that affect multiple teams