coder-agent 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.
- coder_agent-0.1.0.dist-info/METADATA +262 -0
- coder_agent-0.1.0.dist-info/RECORD +163 -0
- coder_agent-0.1.0.dist-info/WHEEL +5 -0
- coder_agent-0.1.0.dist-info/entry_points.txt +2 -0
- coder_agent-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- coder_agent-0.1.0.dist-info/top_level.txt +1 -0
- coderagent/__init__.py +20 -0
- coderagent/compat/__init__.py +27 -0
- coderagent/compat/cache_control.py +69 -0
- coderagent/compat/config_spec.py +60 -0
- coderagent/compat/exceptions.py +20 -0
- coderagent/compat/retry.py +27 -0
- coderagent/compat/serialize.py +31 -0
- coderagent/config/__init__.py +1 -0
- coderagent/config/defaults.yaml +103 -0
- coderagent/config/loader.py +264 -0
- coderagent/config/schema.py +548 -0
- coderagent/config/writer.py +218 -0
- coderagent/core/__init__.py +1 -0
- coderagent/core/budget.py +47 -0
- coderagent/core/capabilities.py +136 -0
- coderagent/core/checkpoint.py +164 -0
- coderagent/core/content.py +156 -0
- coderagent/core/context.py +618 -0
- coderagent/core/events.py +83 -0
- coderagent/core/history.py +56 -0
- coderagent/core/instructions.py +99 -0
- coderagent/core/loop.py +702 -0
- coderagent/core/memory.py +56 -0
- coderagent/core/mentions.py +81 -0
- coderagent/core/os_sandbox.py +191 -0
- coderagent/core/otel.py +214 -0
- coderagent/core/protocols.py +38 -0
- coderagent/core/redact.py +49 -0
- coderagent/core/sandbox.py +82 -0
- coderagent/core/schema.py +107 -0
- coderagent/core/session.py +344 -0
- coderagent/core/shell_env.py +74 -0
- coderagent/core/subagent.py +474 -0
- coderagent/core/summarize.py +312 -0
- coderagent/core/telemetry.py +209 -0
- coderagent/core/tokens.py +132 -0
- coderagent/core/trust.py +301 -0
- coderagent/environments/__init__.py +11 -0
- coderagent/environments/bubblewrap.py +150 -0
- coderagent/environments/contree.py +146 -0
- coderagent/environments/docker.py +160 -0
- coderagent/environments/local.py +110 -0
- coderagent/environments/singularity.py +138 -0
- coderagent/environments/swerex_docker.py +79 -0
- coderagent/environments/swerex_modal.py +123 -0
- coderagent/eval/__init__.py +1 -0
- coderagent/eval/compare.py +190 -0
- coderagent/eval/report.py +141 -0
- coderagent/eval/runner.py +368 -0
- coderagent/eval/task.py +194 -0
- coderagent/extensions/__init__.py +1 -0
- coderagent/extensions/hooks.py +121 -0
- coderagent/extensions/plugins.py +217 -0
- coderagent/extensions/reflect.py +342 -0
- coderagent/models/__init__.py +33 -0
- coderagent/models/backends.py +218 -0
- coderagent/models/call.py +18 -0
- coderagent/models/check.py +139 -0
- coderagent/models/gateway.py +60 -0
- coderagent/models/litellm_config.py +70 -0
- coderagent/models/provider.py +98 -0
- coderagent/models/reasoning.py +28 -0
- coderagent/models/router.py +136 -0
- coderagent/models/settings.py +172 -0
- coderagent/models/streaming.py +122 -0
- coderagent/models/verbosity.py +14 -0
- coderagent/paths.py +31 -0
- coderagent/run.py +454 -0
- coderagent/skills/__init__.py +119 -0
- coderagent/skills/errors.py +11 -0
- coderagent/skills/install.py +340 -0
- coderagent/skills/presets/code-review/SKILL.md +35 -0
- coderagent/skills/presets/codebase-onboarding/SKILL.md +33 -0
- coderagent/skills/presets/data-analysis/SKILL.md +35 -0
- coderagent/skills/presets/deep-research/SKILL.md +38 -0
- coderagent/skills/presets/frontend-dev/SKILL.md +32 -0
- coderagent/skills/presets/long-document/SKILL.md +37 -0
- coderagent/skills/presets/long-document/scripts/pdf_text.py +37 -0
- coderagent/skills/presets/office-docx/SKILL.md +36 -0
- coderagent/skills/presets/office-docx/scripts/docx_text.py +36 -0
- coderagent/skills/presets/office-pptx/SKILL.md +32 -0
- coderagent/skills/presets/office-xlsx/SKILL.md +34 -0
- coderagent/skills/presets/office-xlsx/scripts/xlsx_text.py +72 -0
- coderagent/skills/presets/writing/SKILL.md +31 -0
- coderagent/skills/sandbox.py +269 -0
- coderagent/skills/sites.py +177 -0
- coderagent/skills/source.py +404 -0
- coderagent/testing/__init__.py +5 -0
- coderagent/testing/factory.py +59 -0
- coderagent/testing/scripted_model.py +54 -0
- coderagent/tools/__init__.py +1 -0
- coderagent/tools/base.py +54 -0
- coderagent/tools/bash_policy.py +486 -0
- coderagent/tools/builtin/__init__.py +35 -0
- coderagent/tools/builtin/fs.py +283 -0
- coderagent/tools/builtin/patch.py +279 -0
- coderagent/tools/builtin/search.py +242 -0
- coderagent/tools/builtin/shell.py +336 -0
- coderagent/tools/builtin/skill.py +41 -0
- coderagent/tools/builtin/task.py +53 -0
- coderagent/tools/builtin/todo.py +63 -0
- coderagent/tools/executor.py +243 -0
- coderagent/tools/mcp.py +317 -0
- coderagent/tools/permissions.py +472 -0
- coderagent/tools/registry.py +83 -0
- coderagent/tools/rules.py +138 -0
- coderagent/ui/__init__.py +1 -0
- coderagent/ui/cli.py +498 -0
- coderagent/ui/commands/__init__.py +109 -0
- coderagent/ui/commands/builtin.py +778 -0
- coderagent/ui/commands/compact.py +12 -0
- coderagent/ui/commands/resume.py +26 -0
- coderagent/ui/commands/review.py +73 -0
- coderagent/ui/commands/rewind.py +28 -0
- coderagent/ui/custom_commands.py +179 -0
- coderagent/ui/notify.py +46 -0
- coderagent/ui/open_file.py +48 -0
- coderagent/ui/render.py +62 -0
- coderagent/ui/spinner.py +68 -0
- coderagent/ui/tui.py +610 -0
- coderagent/ui/widgets/__init__.py +29 -0
- coderagent/ui/widgets/approval_prompt.py +129 -0
- coderagent/ui/widgets/diff_view.py +97 -0
- coderagent/ui/widgets/file_tree.py +105 -0
- coderagent/ui/widgets/markdown_message.py +44 -0
- coderagent/ui/widgets/markup.py +10 -0
- coderagent/ui/widgets/message_block.py +61 -0
- coderagent/ui/widgets/path_suggester.py +66 -0
- coderagent/ui/widgets/session_picker.py +49 -0
- coderagent/ui/widgets/status_bar.py +44 -0
- coderagent/ui/widgets/todo_panel.py +40 -0
- coderagent/ui/widgets/tool_card.py +104 -0
- coderagent/ui/widgets/working_dots.py +26 -0
- coderagent/version.py +7 -0
- coderagent/web/__init__.py +5 -0
- coderagent/web/api.py +449 -0
- coderagent/web/app.py +113 -0
- coderagent/web/approver.py +73 -0
- coderagent/web/config_api.py +53 -0
- coderagent/web/events.py +159 -0
- coderagent/web/files.py +115 -0
- coderagent/web/i18n.py +346 -0
- coderagent/web/server.py +100 -0
- coderagent/web/sessions.py +404 -0
- coderagent/web/skills_api.py +376 -0
- coderagent/web/static/app.css +283 -0
- coderagent/web/static/app.js +1466 -0
- coderagent/web/templates/en/base.html +31 -0
- coderagent/web/templates/en/chat.html +60 -0
- coderagent/web/templates/en/macros.html +9 -0
- coderagent/web/templates/en/settings.html +80 -0
- coderagent/web/templates/en/skills.html +64 -0
- coderagent/web/templates/zh/base.html +31 -0
- coderagent/web/templates/zh/chat.html +60 -0
- coderagent/web/templates/zh/macros.html +9 -0
- coderagent/web/templates/zh/settings.html +77 -0
- coderagent/web/templates/zh/skills.html +61 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""The content of a message: the text, and the images that go with it.
|
|
2
|
+
|
|
3
|
+
A message that carries an image has a list of parts instead of a string:
|
|
4
|
+
that is the shape the providers expect. `text_of` and `images_of` read that
|
|
5
|
+
shape, so the rest of the code does not have to care.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import base64
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
IMAGE_TYPES = {
|
|
12
|
+
"png": "image/png",
|
|
13
|
+
"jpg": "image/jpeg",
|
|
14
|
+
"jpeg": "image/jpeg",
|
|
15
|
+
"gif": "image/gif",
|
|
16
|
+
"webp": "image/webp",
|
|
17
|
+
}
|
|
18
|
+
"""The image types a provider takes, by the suffix of the file."""
|
|
19
|
+
|
|
20
|
+
MAX_IMAGE_BYTES = 5 * 1024 * 1024
|
|
21
|
+
"""How big an image may be. A bigger one is refused instead of being sent."""
|
|
22
|
+
|
|
23
|
+
TOKENS_PER_PIXEL = 1 / 750
|
|
24
|
+
"""What a pixel of an image costs. The estimate only drives decisions."""
|
|
25
|
+
|
|
26
|
+
MODALITY_PARTS = {
|
|
27
|
+
"image_url": "image",
|
|
28
|
+
"input_audio": "audio",
|
|
29
|
+
"video_url": "video",
|
|
30
|
+
}
|
|
31
|
+
"""The parts of a message that carry something else than text."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def text_of(content) -> str:
|
|
35
|
+
"""The text of a message, whatever shape its content has."""
|
|
36
|
+
if not content:
|
|
37
|
+
return ""
|
|
38
|
+
if isinstance(content, str):
|
|
39
|
+
return content
|
|
40
|
+
return "\n".join(str(part.get("text", "")) for part in content if part.get("type") == "text")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def images_of(content) -> list[str]:
|
|
44
|
+
"""The images of a message, as the data urls the providers take."""
|
|
45
|
+
if not content or isinstance(content, str):
|
|
46
|
+
return []
|
|
47
|
+
return [
|
|
48
|
+
str(part["image_url"]["url"])
|
|
49
|
+
for part in content
|
|
50
|
+
if part.get("type") == "image_url" and (part.get("image_url") or {}).get("url")
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parts(text: str, images: list[str]) -> list[dict]:
|
|
55
|
+
"""The parts of a message: the text and the images."""
|
|
56
|
+
result = [{"type": "text", "text": text}] if text else []
|
|
57
|
+
result.extend({"type": "image_url", "image_url": {"url": url}} for url in images)
|
|
58
|
+
return result
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def with_text(content, text: str) -> list[dict]:
|
|
62
|
+
"""The message with its text replaced. The images stay."""
|
|
63
|
+
if isinstance(content, str):
|
|
64
|
+
return text
|
|
65
|
+
return [{"type": "text", "text": text}, *[part for part in content if part.get("type") != "text"]]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def describe_message(content) -> str:
|
|
69
|
+
"""The content of a message, as it is shown to the user."""
|
|
70
|
+
text = text_of(content)
|
|
71
|
+
images = images_of(content)
|
|
72
|
+
if not images:
|
|
73
|
+
return text
|
|
74
|
+
note = f"[{len(images)} image{'s' if len(images) > 1 else ''} attached]"
|
|
75
|
+
return f"{text}\n{note}".strip()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def modalities_of(content) -> set[str]:
|
|
79
|
+
"""The kinds of content that are not text in a message."""
|
|
80
|
+
if not content or isinstance(content, str):
|
|
81
|
+
return set()
|
|
82
|
+
return {MODALITY_PARTS[part["type"]] for part in content if part.get("type") in MODALITY_PARTS}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def data_url(path: Path) -> str:
|
|
86
|
+
"""The image of a file, as the data url a provider takes."""
|
|
87
|
+
suffix = path.suffix.lower().lstrip(".")
|
|
88
|
+
if suffix not in IMAGE_TYPES:
|
|
89
|
+
raise ValueError(f"{path.name} is not an image a provider takes: {', '.join(IMAGE_TYPES)}")
|
|
90
|
+
data = path.read_bytes()
|
|
91
|
+
if len(data) > MAX_IMAGE_BYTES:
|
|
92
|
+
raise ValueError(f"{path.name} is too big: {len(data) // 1024} KB, the limit is {MAX_IMAGE_BYTES // 1024} KB")
|
|
93
|
+
return f"data:{IMAGE_TYPES[suffix]};base64,{base64.b64encode(data).decode('ascii')}"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def check_image(url: str) -> str:
|
|
97
|
+
"""The image of a data url, when a provider takes it.
|
|
98
|
+
|
|
99
|
+
The url comes from the outside, so it is checked before it reaches the model:
|
|
100
|
+
only the types of `IMAGE_TYPES` and only up to `MAX_IMAGE_BYTES`.
|
|
101
|
+
"""
|
|
102
|
+
head, _, payload = url.partition(",")
|
|
103
|
+
if not payload or not head.startswith("data:"):
|
|
104
|
+
raise ValueError("the image is not a data url")
|
|
105
|
+
if "base64" not in head:
|
|
106
|
+
raise ValueError("the image is not base64")
|
|
107
|
+
if head.split(";")[0].removeprefix("data:") not in IMAGE_TYPES.values():
|
|
108
|
+
raise ValueError(f"the image is not a type a provider takes: {', '.join(IMAGE_TYPES)}")
|
|
109
|
+
if len(payload) * 3 // 4 > MAX_IMAGE_BYTES:
|
|
110
|
+
raise ValueError(f"the image is too big: the limit is {MAX_IMAGE_BYTES // 1024} KB")
|
|
111
|
+
return url
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def image_tokens(content) -> int:
|
|
115
|
+
"""What the images of a message cost. An estimate, like the rest of the counting."""
|
|
116
|
+
return sum(max(1, _tokens_of_url(url)) for url in images_of(content))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _tokens_of_url(url: str) -> int:
|
|
120
|
+
"""The tokens of one image, from its size in pixels when that is known."""
|
|
121
|
+
if not url.startswith("data:"):
|
|
122
|
+
return 1
|
|
123
|
+
encoded = url.partition(",")[2]
|
|
124
|
+
size = _size_of(encoded)
|
|
125
|
+
if size:
|
|
126
|
+
return int(size[0] * size[1] * TOKENS_PER_PIXEL)
|
|
127
|
+
return max(1, len(encoded) * 3 // 4 // 1024)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _size_of(encoded: str) -> tuple[int, int] | None:
|
|
131
|
+
"""The size of an image in pixels, read from its header."""
|
|
132
|
+
head = encoded[:128]
|
|
133
|
+
try:
|
|
134
|
+
data = base64.b64decode(head + "=" * (-len(head) % 4))
|
|
135
|
+
except Exception:
|
|
136
|
+
return None
|
|
137
|
+
if data[:8] == b"\x89PNG\r\n\x1a\n" and len(data) >= 24:
|
|
138
|
+
return int.from_bytes(data[16:20], "big"), int.from_bytes(data[20:24], "big")
|
|
139
|
+
if data[:6] in (b"GIF87a", b"GIF89a") and len(data) >= 10:
|
|
140
|
+
return int.from_bytes(data[6:8], "little"), int.from_bytes(data[8:10], "little")
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
__all__ = [
|
|
145
|
+
"IMAGE_TYPES",
|
|
146
|
+
"MAX_IMAGE_BYTES",
|
|
147
|
+
"check_image",
|
|
148
|
+
"data_url",
|
|
149
|
+
"describe_message",
|
|
150
|
+
"image_tokens",
|
|
151
|
+
"images_of",
|
|
152
|
+
"modalities_of",
|
|
153
|
+
"parts",
|
|
154
|
+
"text_of",
|
|
155
|
+
"with_text",
|
|
156
|
+
]
|