patch-chat 0.1.0__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 (146) hide show
  1. patch/__init__.py +20 -0
  2. patch/__main__.py +4 -0
  3. patch/_version.py +24 -0
  4. patch/analytics.py +260 -0
  5. patch/args.py +955 -0
  6. patch/args_formatter.py +228 -0
  7. patch/coders/__init__.py +32 -0
  8. patch/coders/architect_coder.py +47 -0
  9. patch/coders/architect_prompts.py +40 -0
  10. patch/coders/ask_coder.py +9 -0
  11. patch/coders/ask_prompts.py +41 -0
  12. patch/coders/base_coder.py +2548 -0
  13. patch/coders/base_prompts.py +60 -0
  14. patch/coders/chat_chunks.py +64 -0
  15. patch/coders/context_coder.py +53 -0
  16. patch/coders/context_prompts.py +75 -0
  17. patch/coders/edit_apply.py +6 -0
  18. patch/coders/editblock_coder.py +620 -0
  19. patch/coders/editblock_fenced_coder.py +10 -0
  20. patch/coders/editblock_fenced_prompts.py +143 -0
  21. patch/coders/editblock_func_coder.py +141 -0
  22. patch/coders/editblock_func_prompts.py +27 -0
  23. patch/coders/editblock_prompts.py +172 -0
  24. patch/coders/editor_diff_fenced_coder.py +9 -0
  25. patch/coders/editor_diff_fenced_prompts.py +11 -0
  26. patch/coders/editor_editblock_coder.py +8 -0
  27. patch/coders/editor_editblock_prompts.py +18 -0
  28. patch/coders/editor_whole_coder.py +8 -0
  29. patch/coders/editor_whole_prompts.py +10 -0
  30. patch/coders/patch_coder.py +731 -0
  31. patch/coders/patch_prompts.py +159 -0
  32. patch/coders/search_replace.py +757 -0
  33. patch/coders/shell.py +37 -0
  34. patch/coders/single_wholefile_func_coder.py +102 -0
  35. patch/coders/single_wholefile_func_prompts.py +27 -0
  36. patch/coders/udiff_coder.py +419 -0
  37. patch/coders/udiff_prompts.py +113 -0
  38. patch/coders/udiff_simple.py +14 -0
  39. patch/coders/udiff_simple_prompts.py +25 -0
  40. patch/coders/wholefile_coder.py +144 -0
  41. patch/coders/wholefile_func_coder.py +134 -0
  42. patch/coders/wholefile_func_prompts.py +27 -0
  43. patch/coders/wholefile_prompts.py +64 -0
  44. patch/commands.py +1668 -0
  45. patch/copypaste.py +70 -0
  46. patch/deprecated.py +126 -0
  47. patch/diffs.py +128 -0
  48. patch/dump.py +29 -0
  49. patch/editor.py +147 -0
  50. patch/exceptions.py +113 -0
  51. patch/format_settings.py +47 -0
  52. patch/gui.py +545 -0
  53. patch/history.py +143 -0
  54. patch/io.py +1209 -0
  55. patch/linter.py +304 -0
  56. patch/llm.py +47 -0
  57. patch/main.py +1466 -0
  58. patch/mdstream.py +243 -0
  59. patch/models.py +1342 -0
  60. patch/onboarding.py +428 -0
  61. patch/openrouter.py +128 -0
  62. patch/prompts.py +61 -0
  63. patch/queries/tree-sitter-language-pack/README.md +7 -0
  64. patch/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
  65. patch/queries/tree-sitter-language-pack/bash-tags.scm +8 -0
  66. patch/queries/tree-sitter-language-pack/c-tags.scm +9 -0
  67. patch/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
  68. patch/queries/tree-sitter-language-pack/clojure-tags.scm +7 -0
  69. patch/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
  70. patch/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
  71. patch/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
  72. patch/queries/tree-sitter-language-pack/d-tags.scm +26 -0
  73. patch/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
  74. patch/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
  75. patch/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
  76. patch/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
  77. patch/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
  78. patch/queries/tree-sitter-language-pack/go-tags.scm +42 -0
  79. patch/queries/tree-sitter-language-pack/java-tags.scm +20 -0
  80. patch/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
  81. patch/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
  82. patch/queries/tree-sitter-language-pack/matlab-tags.scm +10 -0
  83. patch/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
  84. patch/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
  85. patch/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
  86. patch/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
  87. patch/queries/tree-sitter-language-pack/python-tags.scm +14 -0
  88. patch/queries/tree-sitter-language-pack/r-tags.scm +21 -0
  89. patch/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
  90. patch/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
  91. patch/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
  92. patch/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
  93. patch/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
  94. patch/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
  95. patch/queries/tree-sitter-languages/README.md +24 -0
  96. patch/queries/tree-sitter-languages/bash-tags.scm +8 -0
  97. patch/queries/tree-sitter-languages/c-tags.scm +9 -0
  98. patch/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
  99. patch/queries/tree-sitter-languages/cpp-tags.scm +15 -0
  100. patch/queries/tree-sitter-languages/dart-tags.scm +91 -0
  101. patch/queries/tree-sitter-languages/elisp-tags.scm +8 -0
  102. patch/queries/tree-sitter-languages/elixir-tags.scm +54 -0
  103. patch/queries/tree-sitter-languages/elm-tags.scm +19 -0
  104. patch/queries/tree-sitter-languages/fortran-tags.scm +15 -0
  105. patch/queries/tree-sitter-languages/go-tags.scm +30 -0
  106. patch/queries/tree-sitter-languages/haskell-tags.scm +3 -0
  107. patch/queries/tree-sitter-languages/hcl-tags.scm +77 -0
  108. patch/queries/tree-sitter-languages/java-tags.scm +20 -0
  109. patch/queries/tree-sitter-languages/javascript-tags.scm +88 -0
  110. patch/queries/tree-sitter-languages/julia-tags.scm +60 -0
  111. patch/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
  112. patch/queries/tree-sitter-languages/matlab-tags.scm +10 -0
  113. patch/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
  114. patch/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
  115. patch/queries/tree-sitter-languages/php-tags.scm +26 -0
  116. patch/queries/tree-sitter-languages/python-tags.scm +12 -0
  117. patch/queries/tree-sitter-languages/ql-tags.scm +26 -0
  118. patch/queries/tree-sitter-languages/ruby-tags.scm +64 -0
  119. patch/queries/tree-sitter-languages/rust-tags.scm +60 -0
  120. patch/queries/tree-sitter-languages/scala-tags.scm +65 -0
  121. patch/queries/tree-sitter-languages/typescript-tags.scm +41 -0
  122. patch/queries/tree-sitter-languages/zig-tags.scm +3 -0
  123. patch/reasoning_tags.py +82 -0
  124. patch/repo.py +612 -0
  125. patch/repomap.py +859 -0
  126. patch/report.py +200 -0
  127. patch/resources/__init__.py +3 -0
  128. patch/resources/model-metadata.json +715 -0
  129. patch/resources/model-settings.yml +3128 -0
  130. patch/run_cmd.py +146 -0
  131. patch/scrape.py +316 -0
  132. patch/sendchat.py +61 -0
  133. patch/special.py +203 -0
  134. patch/urls.py +17 -0
  135. patch/utils.py +365 -0
  136. patch/versioncheck.py +113 -0
  137. patch/voice.py +200 -0
  138. patch/waiting.py +222 -0
  139. patch/watch.py +318 -0
  140. patch/watch_prompts.py +12 -0
  141. patch_chat-0.1.0.dist-info/METADATA +375 -0
  142. patch_chat-0.1.0.dist-info/RECORD +146 -0
  143. patch_chat-0.1.0.dist-info/WHEEL +5 -0
  144. patch_chat-0.1.0.dist-info/entry_points.txt +2 -0
  145. patch_chat-0.1.0.dist-info/licenses/LICENSE.txt +202 -0
  146. patch_chat-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,228 @@
1
+ import argparse
2
+
3
+ from patch import urls
4
+
5
+ from .dump import dump # noqa: F401
6
+
7
+
8
+ class DotEnvFormatter(argparse.HelpFormatter):
9
+ def start_section(self, heading):
10
+ res = "\n\n"
11
+ res += "#" * (len(heading) + 3)
12
+ res += f"\n# {heading}"
13
+ super().start_section(res)
14
+
15
+ def _format_usage(self, usage, actions, groups, prefix):
16
+ return ""
17
+
18
+ def _format_text(self, text):
19
+ return f"""
20
+ ##########################################################
21
+ # Sample patch .env file.
22
+ # Place at the root of your git repo.
23
+ # Or use `patch --env <fname>` to specify.
24
+ ##########################################################
25
+
26
+ #################
27
+ # LLM parameters:
28
+ #
29
+ # Include xxx_API_KEY parameters and other params needed for your LLMs.
30
+ # See {urls.llms} for details.
31
+
32
+ ## OpenAI
33
+ #OPENAI_API_KEY=
34
+
35
+ ## Anthropic
36
+ #ANTHROPIC_API_KEY=
37
+
38
+ ##...
39
+ """
40
+
41
+ def _format_action(self, action):
42
+ if not action.option_strings:
43
+ return ""
44
+
45
+ if not action.env_var:
46
+ return
47
+
48
+ parts = [""]
49
+
50
+ default = action.default
51
+ if default == argparse.SUPPRESS:
52
+ default = ""
53
+ elif isinstance(default, str):
54
+ pass
55
+ elif isinstance(default, list) and not default:
56
+ default = ""
57
+ elif action.default is not None:
58
+ default = "true" if default else "false"
59
+ else:
60
+ default = ""
61
+
62
+ if action.help:
63
+ parts.append(f"## {action.help}")
64
+
65
+ if action.env_var:
66
+ env_var = action.env_var
67
+ if default:
68
+ parts.append(f"#{env_var}={default}\n")
69
+ else:
70
+ parts.append(f"#{env_var}=\n")
71
+
72
+ return "\n".join(parts) + "\n"
73
+
74
+ def _format_action_invocation(self, action):
75
+ return ""
76
+
77
+ def _format_args(self, action, default_metavar):
78
+ return ""
79
+
80
+
81
+ class YamlHelpFormatter(argparse.HelpFormatter):
82
+ def start_section(self, heading):
83
+ res = "\n\n"
84
+ res += "#" * (len(heading) + 3)
85
+ res += f"\n# {heading}"
86
+ super().start_section(res)
87
+
88
+ def _format_usage(self, usage, actions, groups, prefix):
89
+ return ""
90
+
91
+ def _format_text(self, text):
92
+ return """
93
+ ##########################################################
94
+ # Sample .patch.conf.yml
95
+ # This file lists *all* the valid configuration entries.
96
+ # Place in your home dir, or at the root of your git repo.
97
+ ##########################################################
98
+
99
+ # Note: You can only put OpenAI and Anthropic API keys in the YAML
100
+ # config file. Keys for all APIs can be stored in a .env file
101
+ # Run `patch --help` for configuration options.
102
+
103
+ """
104
+
105
+ def _format_action(self, action):
106
+ if not action.option_strings:
107
+ return ""
108
+
109
+ parts = [""]
110
+
111
+ metavar = action.metavar
112
+ if not metavar and isinstance(action, argparse._StoreAction):
113
+ metavar = "VALUE"
114
+
115
+ default = action.default
116
+ if default == argparse.SUPPRESS:
117
+ default = ""
118
+ elif isinstance(default, str):
119
+ pass
120
+ elif isinstance(default, list) and not default:
121
+ default = ""
122
+ elif action.default is not None:
123
+ default = "true" if default else "false"
124
+ else:
125
+ default = ""
126
+
127
+ if action.help:
128
+ parts.append(f"## {action.help}")
129
+
130
+ for switch in action.option_strings:
131
+ if switch.startswith("--"):
132
+ break
133
+ switch = switch.lstrip("-")
134
+
135
+ if isinstance(action, argparse._StoreTrueAction):
136
+ default = False
137
+ elif isinstance(action, argparse._StoreConstAction):
138
+ default = False
139
+
140
+ if default is False:
141
+ default = "false"
142
+ if default is True:
143
+ default = "true"
144
+
145
+ if default:
146
+ if "#" in default:
147
+ parts.append(f'#{switch}: "{default}"\n')
148
+ else:
149
+ parts.append(f"#{switch}: {default}\n")
150
+ elif action.nargs in ("*", "+") or isinstance(action, argparse._AppendAction):
151
+ parts.append(f"#{switch}: xxx")
152
+ parts.append("## Specify multiple values like this:")
153
+ parts.append(f"#{switch}:")
154
+ parts.append("# - xxx")
155
+ parts.append("# - yyy")
156
+ parts.append("# - zzz")
157
+ else:
158
+ if switch.endswith("color"):
159
+ parts.append(f'#{switch}: "xxx"\n')
160
+ else:
161
+ parts.append(f"#{switch}: xxx\n")
162
+
163
+ ###
164
+ # parts.append(str(action))
165
+
166
+ return "\n".join(parts) + "\n"
167
+
168
+ def _format_action_invocation(self, action):
169
+ return ""
170
+
171
+ def _format_args(self, action, default_metavar):
172
+ return ""
173
+
174
+
175
+ class MarkdownHelpFormatter(argparse.HelpFormatter):
176
+ def start_section(self, heading):
177
+ super().start_section(f"## {heading}")
178
+
179
+ def _format_usage(self, usage, actions, groups, prefix):
180
+ res = super()._format_usage(usage, actions, groups, prefix)
181
+ quote = "```\n"
182
+ return quote + res + quote
183
+
184
+ def _format_text(self, text):
185
+ return ""
186
+
187
+ def _format_action(self, action):
188
+ if not action.option_strings:
189
+ return ""
190
+
191
+ parts = [""]
192
+
193
+ metavar = action.metavar
194
+ if not metavar and isinstance(action, argparse._StoreAction):
195
+ metavar = "VALUE"
196
+
197
+ for switch in action.option_strings:
198
+ if switch.startswith("--"):
199
+ break
200
+
201
+ if metavar:
202
+ parts.append(f"### `{switch} {metavar}`")
203
+ else:
204
+ parts.append(f"### `{switch}`")
205
+ if action.help:
206
+ parts.append(action.help + " ")
207
+
208
+ if action.default not in (argparse.SUPPRESS, None):
209
+ parts.append(f"Default: {action.default} ")
210
+
211
+ if action.env_var:
212
+ parts.append(f"Environment variable: `{action.env_var}` ")
213
+
214
+ if len(action.option_strings) > 1:
215
+ parts.append("Aliases:")
216
+ for switch in action.option_strings:
217
+ if metavar:
218
+ parts.append(f" - `{switch} {metavar}`")
219
+ else:
220
+ parts.append(f" - `{switch}`")
221
+
222
+ return "\n".join(parts) + "\n"
223
+
224
+ def _format_action_invocation(self, action):
225
+ return ""
226
+
227
+ def _format_args(self, action, default_metavar):
228
+ return ""
@@ -0,0 +1,32 @@
1
+ from .architect_coder import ArchitectCoder
2
+ from .ask_coder import AskCoder
3
+ from .base_coder import Coder
4
+ from .context_coder import ContextCoder
5
+ from .editblock_coder import EditBlockCoder
6
+ from .editblock_fenced_coder import EditBlockFencedCoder
7
+ from .editor_diff_fenced_coder import EditorDiffFencedCoder
8
+ from .editor_editblock_coder import EditorEditBlockCoder
9
+ from .editor_whole_coder import EditorWholeFileCoder
10
+ from .patch_coder import PatchCoder
11
+ from .udiff_coder import UnifiedDiffCoder
12
+ from .udiff_simple import UnifiedDiffSimpleCoder
13
+ from .wholefile_coder import WholeFileCoder
14
+
15
+ # from .single_wholefile_func_coder import SingleWholeFileFunctionCoder
16
+
17
+ __all__ = [
18
+ AskCoder,
19
+ Coder,
20
+ EditBlockCoder,
21
+ EditBlockFencedCoder,
22
+ WholeFileCoder,
23
+ PatchCoder,
24
+ UnifiedDiffCoder,
25
+ UnifiedDiffSimpleCoder,
26
+ # SingleWholeFileFunctionCoder,
27
+ ArchitectCoder,
28
+ EditorEditBlockCoder,
29
+ EditorWholeFileCoder,
30
+ EditorDiffFencedCoder,
31
+ ContextCoder,
32
+ ]
@@ -0,0 +1,47 @@
1
+ from .architect_prompts import ArchitectPrompts
2
+ from .ask_coder import AskCoder
3
+ from .base_coder import Coder
4
+
5
+
6
+ class ArchitectCoder(AskCoder):
7
+ edit_format = "architect"
8
+ gpt_prompts = ArchitectPrompts()
9
+
10
+ def reply_completed(self):
11
+ content = self.partial_response_content
12
+
13
+ if not content or not content.strip():
14
+ return
15
+
16
+ if not self.auto_accept_architect and not self.io.confirm_ask("Edit the files?"):
17
+ return
18
+
19
+ kwargs = dict()
20
+
21
+ # Use the editor_model from the main_model if it exists, otherwise use the main_model itself
22
+ editor_model = self.main_model.editor_model or self.main_model
23
+
24
+ kwargs["main_model"] = editor_model
25
+ kwargs["edit_format"] = self.main_model.editor_edit_format
26
+ kwargs["suggest_shell_commands"] = False
27
+ kwargs["map_tokens"] = 0
28
+ kwargs["total_cost"] = self.total_cost
29
+ kwargs["cache_prompts"] = False
30
+ kwargs["num_cache_warming_pings"] = 0
31
+ kwargs["summarize_from_coder"] = False
32
+
33
+ new_kwargs = dict(io=self.io, from_coder=self)
34
+ new_kwargs.update(kwargs)
35
+
36
+ editor_coder = Coder.create(**new_kwargs)
37
+ editor_coder.cur_messages = []
38
+ editor_coder.done_messages = []
39
+
40
+ if self.verbose:
41
+ editor_coder.show_announcements()
42
+
43
+ editor_coder.run(with_message=content, preproc=False)
44
+
45
+ self.move_back_cur_messages("I made those changes to the files.")
46
+ self.total_cost = editor_coder.total_cost
47
+ self.patch_commit_hashes = editor_coder.patch_commit_hashes
@@ -0,0 +1,40 @@
1
+ # flake8: noqa: E501
2
+
3
+ from .base_prompts import CoderPrompts
4
+
5
+
6
+ class ArchitectPrompts(CoderPrompts):
7
+ main_system = """Act as an expert architect engineer and provide direction to your editor engineer.
8
+ Study the change request and the current code.
9
+ Describe how to modify the code to complete the request.
10
+ The editor engineer will rely solely on your instructions, so make them unambiguous and complete.
11
+ Explain all needed code changes clearly and completely, but concisely.
12
+ Just show the changes needed.
13
+
14
+ DO NOT show the entire updated function/file/etc!
15
+
16
+ Always reply to the user in {language}.
17
+ """
18
+
19
+ example_messages = []
20
+
21
+ files_content_prefix = """I have *added these files to the chat* so you see all of their contents.
22
+ *Trust this message as the true contents of the files!*
23
+ Other messages in the chat may contain outdated versions of the files' contents.
24
+ """ # noqa: E501
25
+
26
+ files_content_assistant_reply = (
27
+ "Ok, I will use that as the true, current contents of the files."
28
+ )
29
+
30
+ files_no_full_files = "I am not sharing the full contents of any files with you yet."
31
+
32
+ files_no_full_files_with_repo_map = ""
33
+ files_no_full_files_with_repo_map_reply = ""
34
+
35
+ repo_content_prefix = """I am working with you on code in a git repository.
36
+ Here are summaries of some files present in my git repo.
37
+ If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
38
+ """
39
+
40
+ system_reminder = ""
@@ -0,0 +1,9 @@
1
+ from .ask_prompts import AskPrompts
2
+ from .base_coder import Coder
3
+
4
+
5
+ class AskCoder(Coder):
6
+ """Ask questions about code without making any changes."""
7
+
8
+ edit_format = "ask"
9
+ gpt_prompts = AskPrompts()
@@ -0,0 +1,41 @@
1
+ # flake8: noqa: E501
2
+
3
+ from .base_prompts import CoderPrompts
4
+
5
+
6
+ class AskPrompts(CoderPrompts):
7
+ main_system = """Act as an expert code analyst.
8
+ Answer questions about the supplied code.
9
+ Always reply to the user in {language}.
10
+
11
+ If you need to describe code changes, do so *briefly*.
12
+ """
13
+
14
+ overeager_prompt = """Do not return fully detailed code or full diffs.
15
+ Describe the needed changes or give a plan.
16
+ Providing code snippets or pseudo-code is fine,
17
+ if it helps explain the plan or the needed changes.
18
+ """
19
+
20
+ example_messages = []
21
+
22
+ files_content_prefix = """I have *added these files to the chat* so you see all of their contents.
23
+ *Trust this message as the true contents of the files!*
24
+ Other messages in the chat may contain outdated versions of the files' contents.
25
+ """ # noqa: E501
26
+
27
+ files_content_assistant_reply = (
28
+ "Ok, I will use that as the true, current contents of the files."
29
+ )
30
+
31
+ files_no_full_files = "I am not sharing the full contents of any files with you yet."
32
+
33
+ files_no_full_files_with_repo_map = ""
34
+ files_no_full_files_with_repo_map_reply = ""
35
+
36
+ repo_content_prefix = """I am working with you on code in a git repository.
37
+ Here are summaries of some files present in my git repo.
38
+ If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
39
+ """
40
+
41
+ system_reminder = "{final_reminders}"