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.
- patch/__init__.py +3 -0
- patch/__main__.py +4 -0
- patch/analytics.py +268 -0
- patch/args.py +949 -0
- patch/args_formatter.py +227 -0
- patch/coders/__init__.py +34 -0
- patch/coders/architect_coder.py +48 -0
- patch/coders/architect_prompts.py +40 -0
- patch/coders/ask_coder.py +9 -0
- patch/coders/ask_prompts.py +41 -0
- patch/coders/base_coder.py +2485 -0
- patch/coders/base_prompts.py +60 -0
- patch/coders/chat_chunks.py +64 -0
- patch/coders/context_coder.py +53 -0
- patch/coders/context_prompts.py +75 -0
- patch/coders/editblock_coder.py +657 -0
- patch/coders/editblock_fenced_coder.py +10 -0
- patch/coders/editblock_fenced_prompts.py +143 -0
- patch/coders/editblock_func_coder.py +141 -0
- patch/coders/editblock_func_prompts.py +27 -0
- patch/coders/editblock_prompts.py +172 -0
- patch/coders/editor_diff_fenced_coder.py +9 -0
- patch/coders/editor_diff_fenced_prompts.py +11 -0
- patch/coders/editor_editblock_coder.py +8 -0
- patch/coders/editor_editblock_prompts.py +18 -0
- patch/coders/editor_whole_coder.py +8 -0
- patch/coders/editor_whole_prompts.py +10 -0
- patch/coders/help_coder.py +16 -0
- patch/coders/help_prompts.py +46 -0
- patch/coders/patch_coder.py +706 -0
- patch/coders/patch_prompts.py +159 -0
- patch/coders/search_replace.py +757 -0
- patch/coders/shell.py +37 -0
- patch/coders/single_wholefile_func_coder.py +102 -0
- patch/coders/single_wholefile_func_prompts.py +27 -0
- patch/coders/udiff_coder.py +429 -0
- patch/coders/udiff_prompts.py +113 -0
- patch/coders/udiff_simple.py +14 -0
- patch/coders/udiff_simple_prompts.py +25 -0
- patch/coders/wholefile_coder.py +144 -0
- patch/coders/wholefile_func_coder.py +134 -0
- patch/coders/wholefile_func_prompts.py +27 -0
- patch/coders/wholefile_prompts.py +64 -0
- patch/commands.py +1712 -0
- patch/copypaste.py +72 -0
- patch/deprecated.py +126 -0
- patch/diffs.py +128 -0
- patch/docs/__init__.py +1 -0
- patch/docs/analytics.md +28 -0
- patch/docs/config.md +43 -0
- patch/docs/git.md +22 -0
- patch/docs/install.md +54 -0
- patch/docs/models.md +59 -0
- patch/docs/troubleshooting.md +23 -0
- patch/docs/usage.md +47 -0
- patch/dump.py +29 -0
- patch/editor.py +147 -0
- patch/exceptions.py +113 -0
- patch/format_settings.py +26 -0
- patch/gui.py +545 -0
- patch/help.py +118 -0
- patch/history.py +143 -0
- patch/io.py +1191 -0
- patch/linter.py +304 -0
- patch/llm.py +47 -0
- patch/main.py +1274 -0
- patch/mdstream.py +243 -0
- patch/models.py +1338 -0
- patch/onboarding.py +428 -0
- patch/openrouter.py +128 -0
- patch/prompts.py +61 -0
- patch/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
- patch/queries/tree-sitter-language-pack/bash-tags.scm +8 -0
- patch/queries/tree-sitter-language-pack/c-tags.scm +9 -0
- patch/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
- patch/queries/tree-sitter-language-pack/clojure-tags.scm +7 -0
- patch/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
- patch/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
- patch/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
- patch/queries/tree-sitter-language-pack/d-tags.scm +26 -0
- patch/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
- patch/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
- patch/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
- patch/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
- patch/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
- patch/queries/tree-sitter-language-pack/go-tags.scm +42 -0
- patch/queries/tree-sitter-language-pack/java-tags.scm +20 -0
- patch/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
- patch/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
- patch/queries/tree-sitter-language-pack/matlab-tags.scm +10 -0
- patch/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
- patch/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
- patch/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
- patch/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
- patch/queries/tree-sitter-language-pack/python-tags.scm +14 -0
- patch/queries/tree-sitter-language-pack/r-tags.scm +21 -0
- patch/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
- patch/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
- patch/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
- patch/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
- patch/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
- patch/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
- patch/queries/tree-sitter-languages/bash-tags.scm +8 -0
- patch/queries/tree-sitter-languages/c-tags.scm +9 -0
- patch/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
- patch/queries/tree-sitter-languages/cpp-tags.scm +15 -0
- patch/queries/tree-sitter-languages/dart-tags.scm +91 -0
- patch/queries/tree-sitter-languages/elisp-tags.scm +8 -0
- patch/queries/tree-sitter-languages/elixir-tags.scm +54 -0
- patch/queries/tree-sitter-languages/elm-tags.scm +19 -0
- patch/queries/tree-sitter-languages/fortran-tags.scm +15 -0
- patch/queries/tree-sitter-languages/go-tags.scm +30 -0
- patch/queries/tree-sitter-languages/haskell-tags.scm +3 -0
- patch/queries/tree-sitter-languages/hcl-tags.scm +77 -0
- patch/queries/tree-sitter-languages/java-tags.scm +20 -0
- patch/queries/tree-sitter-languages/javascript-tags.scm +88 -0
- patch/queries/tree-sitter-languages/julia-tags.scm +60 -0
- patch/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
- patch/queries/tree-sitter-languages/matlab-tags.scm +10 -0
- patch/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
- patch/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
- patch/queries/tree-sitter-languages/php-tags.scm +26 -0
- patch/queries/tree-sitter-languages/python-tags.scm +12 -0
- patch/queries/tree-sitter-languages/ql-tags.scm +26 -0
- patch/queries/tree-sitter-languages/ruby-tags.scm +64 -0
- patch/queries/tree-sitter-languages/rust-tags.scm +60 -0
- patch/queries/tree-sitter-languages/scala-tags.scm +65 -0
- patch/queries/tree-sitter-languages/typescript-tags.scm +41 -0
- patch/queries/tree-sitter-languages/zig-tags.scm +3 -0
- patch/reasoning_tags.py +82 -0
- patch/repo.py +622 -0
- patch/repomap.py +867 -0
- patch/report.py +200 -0
- patch/resources/__init__.py +3 -0
- patch/resources/model-metadata.json +715 -0
- patch/resources/model-settings.yml +3128 -0
- patch/run_cmd.py +132 -0
- patch/scrape.py +284 -0
- patch/sendchat.py +61 -0
- patch/special.py +203 -0
- patch/urls.py +17 -0
- patch/utils.py +348 -0
- patch/versioncheck.py +130 -0
- patch/voice.py +187 -0
- patch/waiting.py +221 -0
- patch/watch.py +318 -0
- patch/watch_prompts.py +12 -0
- patch_code-0.1.0.dist-info/METADATA +467 -0
- patch_code-0.1.0.dist-info/RECORD +153 -0
- patch_code-0.1.0.dist-info/WHEEL +5 -0
- patch_code-0.1.0.dist-info/entry_points.txt +2 -0
- patch_code-0.1.0.dist-info/licenses/LICENSE.txt +202 -0
- 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()
|