patch-code 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 (153) hide show
  1. patch/__init__.py +3 -0
  2. patch/__main__.py +4 -0
  3. patch/analytics.py +268 -0
  4. patch/args.py +949 -0
  5. patch/args_formatter.py +227 -0
  6. patch/coders/__init__.py +34 -0
  7. patch/coders/architect_coder.py +48 -0
  8. patch/coders/architect_prompts.py +40 -0
  9. patch/coders/ask_coder.py +9 -0
  10. patch/coders/ask_prompts.py +41 -0
  11. patch/coders/base_coder.py +2485 -0
  12. patch/coders/base_prompts.py +60 -0
  13. patch/coders/chat_chunks.py +64 -0
  14. patch/coders/context_coder.py +53 -0
  15. patch/coders/context_prompts.py +75 -0
  16. patch/coders/editblock_coder.py +657 -0
  17. patch/coders/editblock_fenced_coder.py +10 -0
  18. patch/coders/editblock_fenced_prompts.py +143 -0
  19. patch/coders/editblock_func_coder.py +141 -0
  20. patch/coders/editblock_func_prompts.py +27 -0
  21. patch/coders/editblock_prompts.py +172 -0
  22. patch/coders/editor_diff_fenced_coder.py +9 -0
  23. patch/coders/editor_diff_fenced_prompts.py +11 -0
  24. patch/coders/editor_editblock_coder.py +8 -0
  25. patch/coders/editor_editblock_prompts.py +18 -0
  26. patch/coders/editor_whole_coder.py +8 -0
  27. patch/coders/editor_whole_prompts.py +10 -0
  28. patch/coders/help_coder.py +16 -0
  29. patch/coders/help_prompts.py +46 -0
  30. patch/coders/patch_coder.py +706 -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 +429 -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 +1712 -0
  45. patch/copypaste.py +72 -0
  46. patch/deprecated.py +126 -0
  47. patch/diffs.py +128 -0
  48. patch/docs/__init__.py +1 -0
  49. patch/docs/analytics.md +28 -0
  50. patch/docs/config.md +43 -0
  51. patch/docs/git.md +22 -0
  52. patch/docs/install.md +54 -0
  53. patch/docs/models.md +59 -0
  54. patch/docs/troubleshooting.md +23 -0
  55. patch/docs/usage.md +47 -0
  56. patch/dump.py +29 -0
  57. patch/editor.py +147 -0
  58. patch/exceptions.py +113 -0
  59. patch/format_settings.py +26 -0
  60. patch/gui.py +545 -0
  61. patch/help.py +118 -0
  62. patch/history.py +143 -0
  63. patch/io.py +1191 -0
  64. patch/linter.py +304 -0
  65. patch/llm.py +47 -0
  66. patch/main.py +1274 -0
  67. patch/mdstream.py +243 -0
  68. patch/models.py +1338 -0
  69. patch/onboarding.py +428 -0
  70. patch/openrouter.py +128 -0
  71. patch/prompts.py +61 -0
  72. patch/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
  73. patch/queries/tree-sitter-language-pack/bash-tags.scm +8 -0
  74. patch/queries/tree-sitter-language-pack/c-tags.scm +9 -0
  75. patch/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
  76. patch/queries/tree-sitter-language-pack/clojure-tags.scm +7 -0
  77. patch/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
  78. patch/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
  79. patch/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
  80. patch/queries/tree-sitter-language-pack/d-tags.scm +26 -0
  81. patch/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
  82. patch/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
  83. patch/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
  84. patch/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
  85. patch/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
  86. patch/queries/tree-sitter-language-pack/go-tags.scm +42 -0
  87. patch/queries/tree-sitter-language-pack/java-tags.scm +20 -0
  88. patch/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
  89. patch/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
  90. patch/queries/tree-sitter-language-pack/matlab-tags.scm +10 -0
  91. patch/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
  92. patch/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
  93. patch/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
  94. patch/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
  95. patch/queries/tree-sitter-language-pack/python-tags.scm +14 -0
  96. patch/queries/tree-sitter-language-pack/r-tags.scm +21 -0
  97. patch/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
  98. patch/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
  99. patch/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
  100. patch/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
  101. patch/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
  102. patch/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
  103. patch/queries/tree-sitter-languages/bash-tags.scm +8 -0
  104. patch/queries/tree-sitter-languages/c-tags.scm +9 -0
  105. patch/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
  106. patch/queries/tree-sitter-languages/cpp-tags.scm +15 -0
  107. patch/queries/tree-sitter-languages/dart-tags.scm +91 -0
  108. patch/queries/tree-sitter-languages/elisp-tags.scm +8 -0
  109. patch/queries/tree-sitter-languages/elixir-tags.scm +54 -0
  110. patch/queries/tree-sitter-languages/elm-tags.scm +19 -0
  111. patch/queries/tree-sitter-languages/fortran-tags.scm +15 -0
  112. patch/queries/tree-sitter-languages/go-tags.scm +30 -0
  113. patch/queries/tree-sitter-languages/haskell-tags.scm +3 -0
  114. patch/queries/tree-sitter-languages/hcl-tags.scm +77 -0
  115. patch/queries/tree-sitter-languages/java-tags.scm +20 -0
  116. patch/queries/tree-sitter-languages/javascript-tags.scm +88 -0
  117. patch/queries/tree-sitter-languages/julia-tags.scm +60 -0
  118. patch/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
  119. patch/queries/tree-sitter-languages/matlab-tags.scm +10 -0
  120. patch/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
  121. patch/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
  122. patch/queries/tree-sitter-languages/php-tags.scm +26 -0
  123. patch/queries/tree-sitter-languages/python-tags.scm +12 -0
  124. patch/queries/tree-sitter-languages/ql-tags.scm +26 -0
  125. patch/queries/tree-sitter-languages/ruby-tags.scm +64 -0
  126. patch/queries/tree-sitter-languages/rust-tags.scm +60 -0
  127. patch/queries/tree-sitter-languages/scala-tags.scm +65 -0
  128. patch/queries/tree-sitter-languages/typescript-tags.scm +41 -0
  129. patch/queries/tree-sitter-languages/zig-tags.scm +3 -0
  130. patch/reasoning_tags.py +82 -0
  131. patch/repo.py +622 -0
  132. patch/repomap.py +867 -0
  133. patch/report.py +200 -0
  134. patch/resources/__init__.py +3 -0
  135. patch/resources/model-metadata.json +715 -0
  136. patch/resources/model-settings.yml +3128 -0
  137. patch/run_cmd.py +132 -0
  138. patch/scrape.py +284 -0
  139. patch/sendchat.py +61 -0
  140. patch/special.py +203 -0
  141. patch/urls.py +17 -0
  142. patch/utils.py +348 -0
  143. patch/versioncheck.py +130 -0
  144. patch/voice.py +187 -0
  145. patch/waiting.py +221 -0
  146. patch/watch.py +318 -0
  147. patch/watch_prompts.py +12 -0
  148. patch_code-0.1.0.dist-info/METADATA +467 -0
  149. patch_code-0.1.0.dist-info/RECORD +153 -0
  150. patch_code-0.1.0.dist-info/WHEEL +5 -0
  151. patch_code-0.1.0.dist-info/entry_points.txt +2 -0
  152. patch_code-0.1.0.dist-info/licenses/LICENSE.txt +202 -0
  153. patch_code-0.1.0.dist-info/top_level.txt +1 -0
patch/history.py ADDED
@@ -0,0 +1,143 @@
1
+ import argparse
2
+
3
+ from patch import models, prompts
4
+ from patch.dump import dump # noqa: F401
5
+
6
+
7
+ class ChatSummary:
8
+ def __init__(self, models=None, max_tokens=1024):
9
+ if not models:
10
+ raise ValueError("At least one model must be provided")
11
+ self.models = models if isinstance(models, list) else [models]
12
+ self.max_tokens = max_tokens
13
+ self.token_count = self.models[0].token_count
14
+
15
+ def too_big(self, messages):
16
+ sized = self.tokenize(messages)
17
+ total = sum(tokens for tokens, _msg in sized)
18
+ return total > self.max_tokens
19
+
20
+ def tokenize(self, messages):
21
+ sized = []
22
+ for msg in messages:
23
+ tokens = self.token_count(msg)
24
+ sized.append((tokens, msg))
25
+ return sized
26
+
27
+ def summarize(self, messages, depth=0):
28
+ messages = self.summarize_real(messages)
29
+ if messages and messages[-1]["role"] != "assistant":
30
+ messages.append(dict(role="assistant", content="Ok."))
31
+ return messages
32
+
33
+ def summarize_real(self, messages, depth=0):
34
+ if not self.models:
35
+ raise ValueError("No models available for summarization")
36
+
37
+ sized = self.tokenize(messages)
38
+ total = sum(tokens for tokens, _msg in sized)
39
+ if total <= self.max_tokens and depth == 0:
40
+ return messages
41
+
42
+ min_split = 4
43
+ if len(messages) <= min_split or depth > 3:
44
+ return self.summarize_all(messages)
45
+
46
+ tail_tokens = 0
47
+ split_index = len(messages)
48
+ half_max_tokens = self.max_tokens // 2
49
+
50
+ # Iterate over the messages in reverse order
51
+ for i in range(len(sized) - 1, -1, -1):
52
+ tokens, _msg = sized[i]
53
+ if tail_tokens + tokens < half_max_tokens:
54
+ tail_tokens += tokens
55
+ split_index = i
56
+ else:
57
+ break
58
+
59
+ # Ensure the head ends with an assistant message
60
+ while messages[split_index - 1]["role"] != "assistant" and split_index > 1:
61
+ split_index -= 1
62
+
63
+ if split_index <= min_split:
64
+ return self.summarize_all(messages)
65
+
66
+ # Split head and tail
67
+ tail = messages[split_index:]
68
+
69
+ # Only size the head once
70
+ sized_head = sized[:split_index]
71
+
72
+ # Precompute token limit (fallback to 4096 if undefined)
73
+ model_max_input_tokens = self.models[0].info.get("max_input_tokens") or 4096
74
+ model_max_input_tokens -= 512 # reserve buffer for safety
75
+
76
+ keep = []
77
+ total = 0
78
+
79
+ # Iterate in original order, summing tokens until limit
80
+ for tokens, msg in sized_head:
81
+ total += tokens
82
+ if total > model_max_input_tokens:
83
+ break
84
+ keep.append(msg)
85
+ # No need to reverse lists back and forth
86
+
87
+ summary = self.summarize_all(keep)
88
+
89
+ # If the combined summary and tail still fits, return directly
90
+ summary_tokens = self.token_count(summary)
91
+ tail_tokens = sum(tokens for tokens, _ in sized[split_index:])
92
+ if summary_tokens + tail_tokens < self.max_tokens:
93
+ return summary + tail
94
+
95
+ # Otherwise recurse with increased depth
96
+ return self.summarize_real(summary + tail, depth + 1)
97
+
98
+ def summarize_all(self, messages):
99
+ content = ""
100
+ for msg in messages:
101
+ role = msg["role"].upper()
102
+ if role not in ("USER", "ASSISTANT"):
103
+ continue
104
+ content += f"# {role}\n"
105
+ content += msg["content"]
106
+ if not content.endswith("\n"):
107
+ content += "\n"
108
+
109
+ summarize_messages = [
110
+ dict(role="system", content=prompts.summarize),
111
+ dict(role="user", content=content),
112
+ ]
113
+
114
+ for model in self.models:
115
+ try:
116
+ summary = model.simple_send_with_retries(summarize_messages)
117
+ if summary is not None:
118
+ summary = prompts.summary_prefix + summary
119
+ return [dict(role="user", content=summary)]
120
+ except Exception as e:
121
+ print(f"Summarization failed for model {model.name}: {str(e)}")
122
+
123
+ raise ValueError("summarizer unexpectedly failed for all models")
124
+
125
+
126
+ def main():
127
+ parser = argparse.ArgumentParser()
128
+ parser.add_argument("filename", help="Markdown file to parse")
129
+ args = parser.parse_args()
130
+
131
+ model_names = ["gpt-3.5-turbo", "gpt-4"] # Add more model names as needed
132
+ model_list = [models.Model(name) for name in model_names]
133
+ summarizer = ChatSummary(model_list)
134
+
135
+ with open(args.filename, "r") as f:
136
+ text = f.read()
137
+
138
+ summary = summarizer.summarize_chat_history_markdown(text)
139
+ dump(summary)
140
+
141
+
142
+ if __name__ == "__main__":
143
+ main()