claudia-agent 1.4.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Irae Hueck Costa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: claudia-agent
3
+ Version: 1.4.0
4
+ Summary: Add your description here
5
+ Author-email: Irae Hueck Costa <mail@irae.me>
6
+ Requires-Python: >=3.13
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: llm>=0.31
10
+ Requires-Dist: prompt-toolkit>=3.0.52
11
+ Requires-Dist: tqdm>=4.67.3
12
+ Dynamic: license-file
13
+
14
+ # Claudia
15
+
16
+ Claudia is a command-line tool that uses DeepSeek's language models to implement code changes in your git repository based on natural language task descriptions.
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ export DEEPSEEK_API_KEY=your_key_here
22
+
23
+ uvx claudia "Add email verification to the login form"
24
+
25
+ # Interactive mode
26
+ uvx claudia
27
+ ```
28
+
29
+ ## Why?
30
+ Speed and cost. About two orders of magnitude cheaper than claude.
31
+
32
+
33
+ ## Requirements
34
+
35
+ - Python 3.10+
36
+ - A DeepSeek API key (`DEEPSEEK_API_KEY` environment variable)
37
+ - Git
38
+ - Universal Ctags (for project analysis)
@@ -0,0 +1,25 @@
1
+ # Claudia
2
+
3
+ Claudia is a command-line tool that uses DeepSeek's language models to implement code changes in your git repository based on natural language task descriptions.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ export DEEPSEEK_API_KEY=your_key_here
9
+
10
+ uvx claudia "Add email verification to the login form"
11
+
12
+ # Interactive mode
13
+ uvx claudia
14
+ ```
15
+
16
+ ## Why?
17
+ Speed and cost. About two orders of magnitude cheaper than claude.
18
+
19
+
20
+ ## Requirements
21
+
22
+ - Python 3.10+
23
+ - A DeepSeek API key (`DEEPSEEK_API_KEY` environment variable)
24
+ - Git
25
+ - Universal Ctags (for project analysis)
@@ -0,0 +1,17 @@
1
+ [project]
2
+ name = "claudia-agent"
3
+ version = "1.4.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Irae Hueck Costa", email = "mail@irae.me" }
8
+ ]
9
+ requires-python = ">=3.13"
10
+ dependencies = [
11
+ "llm>=0.31",
12
+ "prompt-toolkit>=3.0.52",
13
+ "tqdm>=4.67.3",
14
+ ]
15
+
16
+ [project.scripts]
17
+ claudia = "claudia:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .main import main
@@ -0,0 +1,46 @@
1
+ import re
2
+
3
+
4
+ CODEBLOCK = "\n```"
5
+ ESCAPED_CODEBLOCK = "\n ```"
6
+
7
+ # This is a marker used to detect files in llm output
8
+ DUMMY_DIR = "github_repository"
9
+
10
+ # Compiled regex for file path detection
11
+ FILE_PATH_PATTERN = re.compile(rf"({DUMMY_DIR}/[\w/.-]+)")
12
+
13
+
14
+ PROMPT_IMPLEMENT_TEMPLATE = """
15
+ # Persona
16
+ You are a senior software developer.
17
+
18
+ # Project overview
19
+ ```
20
+ {project_map}
21
+ ```
22
+
23
+ # Implement
24
+ {task}
25
+
26
+ # Notes
27
+ - Emit the whole file contents of files you want to edit as their content will be directly replaced with your content.
28
+ - Always emmit the full file path, even when you are editing only one file.
29
+ - Only emmit the file path and the file contents, don't reason.
30
+ """
31
+
32
+ PROMPT_CONTEXT_TEMPLATE = """
33
+ # Task
34
+ List files thath are relevant to the task.
35
+
36
+ ## Task
37
+ {task}
38
+
39
+ ## Project overview
40
+ ```
41
+ {project_map}
42
+ ```
43
+
44
+ ## Notes
45
+ - Emit the full file path including the '{dummy_dir}' prefix.
46
+ """
@@ -0,0 +1,195 @@
1
+ import sys
2
+ import re
3
+ import os
4
+ import tempfile
5
+ from collections import defaultdict
6
+ import subprocess
7
+
8
+ from tqdm import tqdm
9
+
10
+ from . import utils
11
+ from . import constants
12
+ from . import models
13
+
14
+
15
+ model = models.DeepSeekChat("deepseek-v4-flash")
16
+
17
+
18
+ class LineHandler:
19
+ """Handle streaming lines from LLM output, collecting file changes."""
20
+
21
+ def __init__(self):
22
+ self.current_file = None
23
+ self.contents = defaultdict(list)
24
+ self.pbar = None
25
+
26
+ def get_total_lines(self, fname):
27
+ try:
28
+ with open(fname, "r") as f:
29
+ return len(f.readlines())
30
+ except FileNotFoundError:
31
+ return 0
32
+
33
+ def __enter__(self):
34
+ return self
35
+
36
+ def __call__(self, line):
37
+ utils.debug(f"LineHandler: {repr(line)}")
38
+
39
+ # Does the line contain a filename containing the DUMMY_DIR?
40
+ if match := re.search(constants.FILE_PATH_PATTERN, line):
41
+ fname = utils.remove_filename_prefix(match.group(1))
42
+ if self.current_file:
43
+ self.finish_current_file()
44
+ self.current_file = fname
45
+ self.pbar = tqdm(
46
+ desc=fname,
47
+ unit=" lines",
48
+ position=0,
49
+ total=self.get_total_lines(fname),
50
+ )
51
+ return
52
+
53
+ if self.current_file:
54
+ self.contents[self.current_file].append(line)
55
+ self.pbar.update()
56
+
57
+ def finish_current_file(self):
58
+ """Close the current progress bar and reset state."""
59
+ if self.pbar:
60
+ self.pbar.close()
61
+ self.pbar = None
62
+ self.current_file = None
63
+
64
+ def write_changes(self, dir):
65
+ """Write accumulated changes to the specified directory."""
66
+ for fname, lines in self.contents.items():
67
+ fname = os.path.join(dir, fname)
68
+ if os.sep in fname:
69
+ os.makedirs(os.path.dirname(fname), exist_ok=True)
70
+ with open(fname, "w") as f:
71
+ content = "\n".join(lines)
72
+ content = utils.unescape_codeblocks(content)
73
+ content = utils.trim_code_blocks_magic(fname, content)
74
+ f.write(content)
75
+
76
+ def preview_changes(self):
77
+ tmpdir = tempfile.mkdtemp(
78
+ suffix=" .", # for better UX
79
+ )
80
+ self.write_changes(tmpdir)
81
+ subprocess.call(
82
+ [
83
+ "git",
84
+ "diff",
85
+ "--no-index",
86
+ ".",
87
+ tmpdir,
88
+ "--diff-filter=AM",
89
+ ]
90
+ )
91
+
92
+ def __exit__(self, exc_type, exc_val, exc_tb):
93
+ if exc_type is not None:
94
+ return False
95
+
96
+ # Finish any remaining progress bar
97
+ if self.pbar:
98
+ self.pbar.close()
99
+
100
+ if self.contents:
101
+ self.preview_changes()
102
+ tqdm.write("\nPress enter to write the files...")
103
+ input("")
104
+ self.write_changes(".")
105
+
106
+ tqdm.write(f"Files changed: {', '.join(self.contents.keys())}")
107
+ else:
108
+ tqdm.write("No changes")
109
+
110
+
111
+ def get_context_files(task):
112
+ """Get relevant context files for a given task from the LLM."""
113
+ prompt = constants.PROMPT_CONTEXT_TEMPLATE.format(
114
+ project_map=utils.get_project_map(),
115
+ task=task,
116
+ dummy_dir=constants.DUMMY_DIR,
117
+ )
118
+
119
+ response = model.prompt(prompt)
120
+
121
+ for chunk in tqdm(
122
+ response,
123
+ desc="Context files",
124
+ unit="tokens",
125
+ delay=5,
126
+ ):
127
+ pass
128
+
129
+ files = constants.FILE_PATH_PATTERN.findall(response.text())
130
+ fs_files = [utils.remove_filename_prefix(f) for f in files]
131
+ tqdm.write(f"Context: {', '.join(fs_files)}")
132
+ return files
133
+
134
+
135
+ def implement(task):
136
+ """Main implementation flow: get context, generate code, apply changes."""
137
+ files = get_context_files(task)
138
+ fragments = utils.files_to_fragments(sorted(files))
139
+
140
+ response = model.prompt(
141
+ constants.PROMPT_IMPLEMENT_TEMPLATE.format(
142
+ task=task, project_map=utils.get_project_map()
143
+ ),
144
+ fragments=fragments,
145
+ )
146
+
147
+ with LineHandler() as line_handler:
148
+ changes = ""
149
+ for chunk in response:
150
+ changes += chunk
151
+ while "\n" in changes:
152
+ line, newline, changes = changes.partition("\n")
153
+ line_handler(line)
154
+ if changes:
155
+ line_handler(changes)
156
+
157
+
158
+ def interactive_mode():
159
+ """Interactive REPL mode for continuous code generation."""
160
+ # Import here for better startup time
161
+ from prompt_toolkit import prompt
162
+ from prompt_toolkit.history import FileHistory
163
+
164
+ history = FileHistory("~/.klaus_history")
165
+
166
+ tqdm.write("Hi, specify your desired code changes (return with alt-enter)")
167
+ while True:
168
+ try:
169
+ user_input = prompt(
170
+ "> ",
171
+ multiline=True,
172
+ history=history,
173
+ prompt_continuation="... ",
174
+ )
175
+ implement(user_input)
176
+ except (EOFError, KeyboardInterrupt):
177
+ break
178
+
179
+
180
+ def main():
181
+ if not os.environ.get("DEEPSEEK_API_KEY"):
182
+ print(
183
+ "claudia error: Please set the environment variable DEEPSEEK_API_KEY to your DeepSeek API key.",
184
+ file=sys.stderr,
185
+ )
186
+ sys.exit(1)
187
+ if len(sys.argv) > 1:
188
+ task = " ".join(sys.argv[1:])
189
+ implement(task)
190
+ else:
191
+ interactive_mode()
192
+
193
+
194
+ if __name__ == "__main__":
195
+ main()
@@ -0,0 +1,20 @@
1
+ from llm.default_plugins.openai_models import Chat
2
+
3
+
4
+ class DeepSeekChat(Chat):
5
+ """Custom chat handler for DeepSeek API."""
6
+
7
+ needs_key = "deepseek"
8
+ key_env_var = "DEEPSEEK_API_KEY"
9
+
10
+ def build_kwargs(self, prompt, stream):
11
+ kwargs = super().build_kwargs(prompt, stream)
12
+ kwargs.setdefault("extra_body", {})["thinking"] = {"type": "disabled"}
13
+ return kwargs
14
+
15
+ def __init__(self, model_name):
16
+ super().__init__(
17
+ model_name=model_name,
18
+ model_id=model_name,
19
+ api_base="https://api.deepseek.com",
20
+ )
@@ -0,0 +1,109 @@
1
+ from tqdm import tqdm
2
+ import functools
3
+ import os
4
+ import sys
5
+ import subprocess
6
+ from io import StringIO
7
+
8
+ from .constants import DUMMY_DIR, CODEBLOCK, ESCAPED_CODEBLOCK
9
+
10
+
11
+ def debug(text):
12
+ if os.environ.get("CLAUDIA_DEBUG") in ["1", "true"]:
13
+ tqdm.write(text)
14
+
15
+
16
+ def escape_codeblocks(text):
17
+ return text.replace(CODEBLOCK, ESCAPED_CODEBLOCK)
18
+
19
+
20
+ def unescape_codeblocks(text):
21
+ return text.replace(ESCAPED_CODEBLOCK, CODEBLOCK)
22
+
23
+
24
+ def trim_code_blocks_magic(fname, content):
25
+ """Remove surrounding code block markers from content if present."""
26
+ content = content.rstrip("\n`")
27
+ content = content.lstrip("\n")
28
+
29
+ content_lines = content.splitlines()
30
+ if content_lines and content_lines[0].startswith("```"):
31
+ content = "\n".join(content_lines[1:])
32
+
33
+ if not content.endswith("\n"):
34
+ content += "\n"
35
+
36
+ return content
37
+
38
+
39
+ def remove_filename_prefix(filename):
40
+ """Remove the DUMMY_DIR prefix from a filename."""
41
+ if filename.startswith(f"{DUMMY_DIR}/"):
42
+ return filename[len(f"{DUMMY_DIR}/") :]
43
+ return filename
44
+
45
+
46
+ @functools.cache
47
+ def get_project_map():
48
+ """Generate a map of project files and their tags using ctags."""
49
+ files = {}
50
+ try:
51
+ all_git_files = (
52
+ subprocess.check_output(
53
+ [
54
+ "git",
55
+ "ls-files",
56
+ "--modified",
57
+ "--cached",
58
+ "--others",
59
+ "--exclude-standard",
60
+ ],
61
+ )
62
+ .decode("utf-8")
63
+ .splitlines()
64
+ )
65
+ except subprocess.CalledProcessError as exc:
66
+ print("claudia error:", exc)
67
+ sys.exit(1)
68
+
69
+ # Ctags fails if a file does not exist
70
+ for file in list(all_git_files):
71
+ if not os.path.exists(file):
72
+ all_git_files.remove(file)
73
+
74
+ try:
75
+ ctags = subprocess.check_output(
76
+ ["ctags", "-f-"] + all_git_files, stderr=subprocess.DEVNULL
77
+ ).decode("utf-8")
78
+ except subprocess.CalledProcessError as exc:
79
+ print("claudia error:", exc)
80
+ sys.exit(1)
81
+
82
+ for line in ctags.splitlines():
83
+ tag, filename, *rest = line.split("\t")
84
+ if "/migrations/" in filename:
85
+ continue
86
+ files.setdefault(filename, []).append(tag)
87
+
88
+ files_map = StringIO()
89
+ for filename, tags in files.items():
90
+ files_map.write(f"{DUMMY_DIR}/{filename}: ")
91
+ files_map.write(", ".join(tags))
92
+ files_map.write("\n")
93
+
94
+ files_map.seek(0)
95
+ return files_map.read()
96
+
97
+
98
+ def files_to_fragments(files):
99
+ """Read files and create fragments for the LLM."""
100
+ fragments = []
101
+ for file in files:
102
+ try:
103
+ with open(remove_filename_prefix(file), "r") as f:
104
+ content = f.read()
105
+ except FileNotFoundError:
106
+ fragments.append(f"# File not found: {file}")
107
+ else:
108
+ fragments.append(f"# {file}\n\n{escape_codeblocks(content)}")
109
+ return fragments
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: claudia-agent
3
+ Version: 1.4.0
4
+ Summary: Add your description here
5
+ Author-email: Irae Hueck Costa <mail@irae.me>
6
+ Requires-Python: >=3.13
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: llm>=0.31
10
+ Requires-Dist: prompt-toolkit>=3.0.52
11
+ Requires-Dist: tqdm>=4.67.3
12
+ Dynamic: license-file
13
+
14
+ # Claudia
15
+
16
+ Claudia is a command-line tool that uses DeepSeek's language models to implement code changes in your git repository based on natural language task descriptions.
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ export DEEPSEEK_API_KEY=your_key_here
22
+
23
+ uvx claudia "Add email verification to the login form"
24
+
25
+ # Interactive mode
26
+ uvx claudia
27
+ ```
28
+
29
+ ## Why?
30
+ Speed and cost. About two orders of magnitude cheaper than claude.
31
+
32
+
33
+ ## Requirements
34
+
35
+ - Python 3.10+
36
+ - A DeepSeek API key (`DEEPSEEK_API_KEY` environment variable)
37
+ - Git
38
+ - Universal Ctags (for project analysis)
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/claudia/__init__.py
5
+ src/claudia/constants.py
6
+ src/claudia/main.py
7
+ src/claudia/models.py
8
+ src/claudia/utils.py
9
+ src/claudia_agent.egg-info/PKG-INFO
10
+ src/claudia_agent.egg-info/SOURCES.txt
11
+ src/claudia_agent.egg-info/dependency_links.txt
12
+ src/claudia_agent.egg-info/entry_points.txt
13
+ src/claudia_agent.egg-info/requires.txt
14
+ src/claudia_agent.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ claudia = claudia:main
@@ -0,0 +1,3 @@
1
+ llm>=0.31
2
+ prompt-toolkit>=3.0.52
3
+ tqdm>=4.67.3