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.
Files changed (163) hide show
  1. coder_agent-0.1.0.dist-info/METADATA +262 -0
  2. coder_agent-0.1.0.dist-info/RECORD +163 -0
  3. coder_agent-0.1.0.dist-info/WHEEL +5 -0
  4. coder_agent-0.1.0.dist-info/entry_points.txt +2 -0
  5. coder_agent-0.1.0.dist-info/licenses/LICENSE.md +21 -0
  6. coder_agent-0.1.0.dist-info/top_level.txt +1 -0
  7. coderagent/__init__.py +20 -0
  8. coderagent/compat/__init__.py +27 -0
  9. coderagent/compat/cache_control.py +69 -0
  10. coderagent/compat/config_spec.py +60 -0
  11. coderagent/compat/exceptions.py +20 -0
  12. coderagent/compat/retry.py +27 -0
  13. coderagent/compat/serialize.py +31 -0
  14. coderagent/config/__init__.py +1 -0
  15. coderagent/config/defaults.yaml +103 -0
  16. coderagent/config/loader.py +264 -0
  17. coderagent/config/schema.py +548 -0
  18. coderagent/config/writer.py +218 -0
  19. coderagent/core/__init__.py +1 -0
  20. coderagent/core/budget.py +47 -0
  21. coderagent/core/capabilities.py +136 -0
  22. coderagent/core/checkpoint.py +164 -0
  23. coderagent/core/content.py +156 -0
  24. coderagent/core/context.py +618 -0
  25. coderagent/core/events.py +83 -0
  26. coderagent/core/history.py +56 -0
  27. coderagent/core/instructions.py +99 -0
  28. coderagent/core/loop.py +702 -0
  29. coderagent/core/memory.py +56 -0
  30. coderagent/core/mentions.py +81 -0
  31. coderagent/core/os_sandbox.py +191 -0
  32. coderagent/core/otel.py +214 -0
  33. coderagent/core/protocols.py +38 -0
  34. coderagent/core/redact.py +49 -0
  35. coderagent/core/sandbox.py +82 -0
  36. coderagent/core/schema.py +107 -0
  37. coderagent/core/session.py +344 -0
  38. coderagent/core/shell_env.py +74 -0
  39. coderagent/core/subagent.py +474 -0
  40. coderagent/core/summarize.py +312 -0
  41. coderagent/core/telemetry.py +209 -0
  42. coderagent/core/tokens.py +132 -0
  43. coderagent/core/trust.py +301 -0
  44. coderagent/environments/__init__.py +11 -0
  45. coderagent/environments/bubblewrap.py +150 -0
  46. coderagent/environments/contree.py +146 -0
  47. coderagent/environments/docker.py +160 -0
  48. coderagent/environments/local.py +110 -0
  49. coderagent/environments/singularity.py +138 -0
  50. coderagent/environments/swerex_docker.py +79 -0
  51. coderagent/environments/swerex_modal.py +123 -0
  52. coderagent/eval/__init__.py +1 -0
  53. coderagent/eval/compare.py +190 -0
  54. coderagent/eval/report.py +141 -0
  55. coderagent/eval/runner.py +368 -0
  56. coderagent/eval/task.py +194 -0
  57. coderagent/extensions/__init__.py +1 -0
  58. coderagent/extensions/hooks.py +121 -0
  59. coderagent/extensions/plugins.py +217 -0
  60. coderagent/extensions/reflect.py +342 -0
  61. coderagent/models/__init__.py +33 -0
  62. coderagent/models/backends.py +218 -0
  63. coderagent/models/call.py +18 -0
  64. coderagent/models/check.py +139 -0
  65. coderagent/models/gateway.py +60 -0
  66. coderagent/models/litellm_config.py +70 -0
  67. coderagent/models/provider.py +98 -0
  68. coderagent/models/reasoning.py +28 -0
  69. coderagent/models/router.py +136 -0
  70. coderagent/models/settings.py +172 -0
  71. coderagent/models/streaming.py +122 -0
  72. coderagent/models/verbosity.py +14 -0
  73. coderagent/paths.py +31 -0
  74. coderagent/run.py +454 -0
  75. coderagent/skills/__init__.py +119 -0
  76. coderagent/skills/errors.py +11 -0
  77. coderagent/skills/install.py +340 -0
  78. coderagent/skills/presets/code-review/SKILL.md +35 -0
  79. coderagent/skills/presets/codebase-onboarding/SKILL.md +33 -0
  80. coderagent/skills/presets/data-analysis/SKILL.md +35 -0
  81. coderagent/skills/presets/deep-research/SKILL.md +38 -0
  82. coderagent/skills/presets/frontend-dev/SKILL.md +32 -0
  83. coderagent/skills/presets/long-document/SKILL.md +37 -0
  84. coderagent/skills/presets/long-document/scripts/pdf_text.py +37 -0
  85. coderagent/skills/presets/office-docx/SKILL.md +36 -0
  86. coderagent/skills/presets/office-docx/scripts/docx_text.py +36 -0
  87. coderagent/skills/presets/office-pptx/SKILL.md +32 -0
  88. coderagent/skills/presets/office-xlsx/SKILL.md +34 -0
  89. coderagent/skills/presets/office-xlsx/scripts/xlsx_text.py +72 -0
  90. coderagent/skills/presets/writing/SKILL.md +31 -0
  91. coderagent/skills/sandbox.py +269 -0
  92. coderagent/skills/sites.py +177 -0
  93. coderagent/skills/source.py +404 -0
  94. coderagent/testing/__init__.py +5 -0
  95. coderagent/testing/factory.py +59 -0
  96. coderagent/testing/scripted_model.py +54 -0
  97. coderagent/tools/__init__.py +1 -0
  98. coderagent/tools/base.py +54 -0
  99. coderagent/tools/bash_policy.py +486 -0
  100. coderagent/tools/builtin/__init__.py +35 -0
  101. coderagent/tools/builtin/fs.py +283 -0
  102. coderagent/tools/builtin/patch.py +279 -0
  103. coderagent/tools/builtin/search.py +242 -0
  104. coderagent/tools/builtin/shell.py +336 -0
  105. coderagent/tools/builtin/skill.py +41 -0
  106. coderagent/tools/builtin/task.py +53 -0
  107. coderagent/tools/builtin/todo.py +63 -0
  108. coderagent/tools/executor.py +243 -0
  109. coderagent/tools/mcp.py +317 -0
  110. coderagent/tools/permissions.py +472 -0
  111. coderagent/tools/registry.py +83 -0
  112. coderagent/tools/rules.py +138 -0
  113. coderagent/ui/__init__.py +1 -0
  114. coderagent/ui/cli.py +498 -0
  115. coderagent/ui/commands/__init__.py +109 -0
  116. coderagent/ui/commands/builtin.py +778 -0
  117. coderagent/ui/commands/compact.py +12 -0
  118. coderagent/ui/commands/resume.py +26 -0
  119. coderagent/ui/commands/review.py +73 -0
  120. coderagent/ui/commands/rewind.py +28 -0
  121. coderagent/ui/custom_commands.py +179 -0
  122. coderagent/ui/notify.py +46 -0
  123. coderagent/ui/open_file.py +48 -0
  124. coderagent/ui/render.py +62 -0
  125. coderagent/ui/spinner.py +68 -0
  126. coderagent/ui/tui.py +610 -0
  127. coderagent/ui/widgets/__init__.py +29 -0
  128. coderagent/ui/widgets/approval_prompt.py +129 -0
  129. coderagent/ui/widgets/diff_view.py +97 -0
  130. coderagent/ui/widgets/file_tree.py +105 -0
  131. coderagent/ui/widgets/markdown_message.py +44 -0
  132. coderagent/ui/widgets/markup.py +10 -0
  133. coderagent/ui/widgets/message_block.py +61 -0
  134. coderagent/ui/widgets/path_suggester.py +66 -0
  135. coderagent/ui/widgets/session_picker.py +49 -0
  136. coderagent/ui/widgets/status_bar.py +44 -0
  137. coderagent/ui/widgets/todo_panel.py +40 -0
  138. coderagent/ui/widgets/tool_card.py +104 -0
  139. coderagent/ui/widgets/working_dots.py +26 -0
  140. coderagent/version.py +7 -0
  141. coderagent/web/__init__.py +5 -0
  142. coderagent/web/api.py +449 -0
  143. coderagent/web/app.py +113 -0
  144. coderagent/web/approver.py +73 -0
  145. coderagent/web/config_api.py +53 -0
  146. coderagent/web/events.py +159 -0
  147. coderagent/web/files.py +115 -0
  148. coderagent/web/i18n.py +346 -0
  149. coderagent/web/server.py +100 -0
  150. coderagent/web/sessions.py +404 -0
  151. coderagent/web/skills_api.py +376 -0
  152. coderagent/web/static/app.css +283 -0
  153. coderagent/web/static/app.js +1466 -0
  154. coderagent/web/templates/en/base.html +31 -0
  155. coderagent/web/templates/en/chat.html +60 -0
  156. coderagent/web/templates/en/macros.html +9 -0
  157. coderagent/web/templates/en/settings.html +80 -0
  158. coderagent/web/templates/en/skills.html +64 -0
  159. coderagent/web/templates/zh/base.html +31 -0
  160. coderagent/web/templates/zh/chat.html +60 -0
  161. coderagent/web/templates/zh/macros.html +9 -0
  162. coderagent/web/templates/zh/settings.html +77 -0
  163. coderagent/web/templates/zh/skills.html +61 -0
@@ -0,0 +1,83 @@
1
+ """Event system: the single source of truth for everything that happens in a session."""
2
+
3
+ import logging
4
+ from collections.abc import Callable
5
+ from dataclasses import dataclass, field
6
+ from enum import Enum
7
+ from typing import Any
8
+
9
+ logger = logging.getLogger("coderagent.events")
10
+
11
+
12
+ class EventType(str, Enum):
13
+ USER_MESSAGE = "user_message"
14
+ ASSISTANT_MESSAGE = "assistant_message"
15
+ TEXT_DELTA = "text_delta"
16
+ """A piece of the answer as it arrives. Not written to the event log."""
17
+ REASONING = "reasoning"
18
+ TOOL_CALL = "tool_call"
19
+ TOOL_RESULT = "tool_result"
20
+ APPROVAL_REQUEST = "approval_request"
21
+ APPROVAL_RESPONSE = "approval_response"
22
+ STATE_CHANGE = "state_change"
23
+ TURN_END = "turn_end"
24
+ """Why a turn ended. Without it the log cannot say how a round stopped."""
25
+ VERIFY = "verify"
26
+ """The commands that check the work of the agent, and what they said."""
27
+ COMPACTION = "compaction"
28
+ RECAP = "recap"
29
+ """A summary of the conversation for the user. Nothing was dropped."""
30
+ SIDE_CONVERSATION = "side_conversation"
31
+ """A question that was answered in a session of its own."""
32
+ REFLECTION = "reflection"
33
+ """What the model thought was worth remembering at the end of the session."""
34
+ REVERTED = "reverted_to"
35
+ ERROR = "error"
36
+
37
+
38
+ @dataclass
39
+ class Event:
40
+ type: EventType
41
+ session_id: str
42
+ timestamp: float
43
+ payload: dict[str, Any] = field(default_factory=dict)
44
+
45
+ def to_dict(self) -> dict[str, Any]:
46
+ return {
47
+ "type": self.type.value,
48
+ "session_id": self.session_id,
49
+ "timestamp": self.timestamp,
50
+ "payload": self.payload,
51
+ }
52
+
53
+ @classmethod
54
+ def from_dict(cls, data: dict[str, Any]) -> "Event | None":
55
+ """Build an event from its serialized form. Unknown types are skipped (return None)."""
56
+ try:
57
+ event_type = EventType(data["type"])
58
+ except (KeyError, ValueError):
59
+ logger.debug("Skipping event with unknown type: %s", data.get("type"))
60
+ return None
61
+ return cls(
62
+ type=event_type,
63
+ session_id=data.get("session_id", ""),
64
+ timestamp=data.get("timestamp", 0.0),
65
+ payload=data.get("payload") or {},
66
+ )
67
+
68
+
69
+ class EventBus:
70
+ """Synchronous publish/subscribe. UI subscribes, the core publishes."""
71
+
72
+ def __init__(self) -> None:
73
+ self._subscribers: dict[EventType, list[Callable[[Event], None]]] = {}
74
+
75
+ def subscribe(self, event_type: EventType, callback: Callable[[Event], None]) -> None:
76
+ self._subscribers.setdefault(event_type, []).append(callback)
77
+
78
+ def publish(self, event: Event) -> None:
79
+ for callback in list(self._subscribers.get(event.type, [])):
80
+ try:
81
+ callback(event)
82
+ except Exception:
83
+ logger.exception("Event subscriber failed for %s", event.type)
@@ -0,0 +1,56 @@
1
+ """The conversation history, split into turns.
2
+
3
+ A turn is one user message plus everything the model did in response: its assistant
4
+ message and the tool results that followed. Cutting a history on a turn boundary is
5
+ what keeps the tool messages attached to the assistant message that asked for them.
6
+ """
7
+
8
+ from coderagent.core.tokens import estimate_tokens
9
+
10
+
11
+ class History:
12
+ def __init__(self, messages: list[dict] | None = None) -> None:
13
+ self.messages: list[dict] = list(messages or [])
14
+
15
+ def __len__(self) -> int:
16
+ return len(self.messages)
17
+
18
+ def __iter__(self):
19
+ return iter(self.messages)
20
+
21
+ def append(self, message: dict) -> None:
22
+ self.messages.append(message)
23
+
24
+ def extend(self, messages: list[dict]) -> None:
25
+ self.messages.extend(messages)
26
+
27
+ def turn_starts(self) -> list[int]:
28
+ """Indices where a new turn begins."""
29
+ return [index for index, message in enumerate(self.messages) if message.get("role") == "user"]
30
+
31
+ def turn_count(self) -> int:
32
+ return len(self.turn_starts())
33
+
34
+ def recent_turns(self, turns: int) -> list[dict]:
35
+ """The last `turns` turns, oldest first."""
36
+ if turns <= 0:
37
+ return []
38
+ starts = self.turn_starts()
39
+ if not starts:
40
+ return list(self.messages)
41
+ index = starts[max(0, len(starts) - turns)]
42
+ return list(self.messages[index:])
43
+
44
+ def split_at(self, index: int) -> tuple[list[dict], list[dict]]:
45
+ """Split into (older, newer). The two halves concatenate back to the original."""
46
+ return list(self.messages[:index]), list(self.messages[index:])
47
+
48
+ def token_count(self, tools: list[dict] | None = None) -> int:
49
+ return estimate_tokens(self.messages, tools)
50
+
51
+ def tail_from_turn(self, turns: int) -> int:
52
+ """Index where the last `turns` turns start."""
53
+ starts = self.turn_starts()
54
+ if not starts:
55
+ return 0
56
+ return starts[max(0, len(starts) - turns)]
@@ -0,0 +1,99 @@
1
+ """Instruction files: the AGENTS.md / CLAUDE.md files that tell the agent how to work here.
2
+
3
+ The user level comes first, then the project level. Files in subdirectories are
4
+ loaded lazily, when a tool touches something inside them.
5
+ """
6
+
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+
10
+ from coderagent.paths import config_home
11
+
12
+ USER_FILE = "CLAUDE.md"
13
+
14
+
15
+ @dataclass
16
+ class InstructionBlock:
17
+ source: str
18
+ content: str
19
+ path: Path
20
+
21
+ def render(self) -> str:
22
+ return f'<project_instructions source="{self.source}">\n{self.content.strip()}\n</project_instructions>'
23
+
24
+
25
+ def read_block(path: Path, max_bytes: int = 0) -> InstructionBlock | None:
26
+ """The instructions of a file. A file that is too long is cut short."""
27
+ if not path.exists():
28
+ return None
29
+ raw = path.read_bytes()
30
+ if max_bytes and len(raw) > max_bytes:
31
+ raw = raw[:max_bytes]
32
+ content = raw.decode("utf-8", errors="replace").strip()
33
+ content = f"{content}\n\n[the file is longer than {max_bytes} bytes, the rest of it is not shown]"
34
+ else:
35
+ content = raw.decode("utf-8", errors="replace").strip()
36
+ if not content:
37
+ return None
38
+ return InstructionBlock(source=path.name, content=content, path=path)
39
+
40
+
41
+ def once_per_file(blocks: list[InstructionBlock]) -> list[InstructionBlock]:
42
+ """The blocks, one per file. The last one of a file wins.
43
+
44
+ A file can be an instruction and a memory at the same time, and then it is
45
+ read twice but shown once.
46
+ """
47
+ by_path: dict[Path, InstructionBlock] = {}
48
+ for block in blocks:
49
+ by_path[block.path] = block
50
+ return list(by_path.values())
51
+
52
+
53
+ def project_root(cwd: Path) -> Path:
54
+ """The root of the repository the directory belongs to.
55
+
56
+ A directory that is not in a repository is its own root.
57
+ """
58
+ directory = Path(cwd).resolve()
59
+ for candidate in (directory, *directory.parents):
60
+ if (candidate / ".git").exists():
61
+ """A worktree has a file there, a clone has a directory. Both count."""
62
+ return candidate
63
+ return directory
64
+
65
+
66
+ def load_instructions(cwd: Path, user_home: Path | None = None, max_bytes: int = 0) -> list[InstructionBlock]:
67
+ """The user level and the project level instructions, in that order.
68
+
69
+ The rules of the repository come before the rules of the directory, so that
70
+ the ones of the directory win when they are read.
71
+ """
72
+ blocks = []
73
+ home = Path(user_home) if user_home else config_home()
74
+ root = project_root(cwd)
75
+ paths = [home / USER_FILE]
76
+ if root != Path(cwd).resolve():
77
+ paths += [root / "AGENTS.md", root / "CLAUDE.md"]
78
+ paths += [Path(cwd) / "AGENTS.md", Path(cwd) / "CLAUDE.md"]
79
+ for path in paths:
80
+ block = read_block(path, max_bytes)
81
+ if block:
82
+ blocks.append(block)
83
+ return blocks
84
+
85
+
86
+ def subdirectory_instructions(path: Path, cwd: Path, max_bytes: int = 0) -> list[InstructionBlock]:
87
+ """The instruction files of the directories between `cwd` and `path`, deepest first."""
88
+ try:
89
+ relative = Path(path).resolve().relative_to(Path(cwd).resolve())
90
+ except ValueError:
91
+ return []
92
+ blocks = []
93
+ directories = list(relative.parts[:-1]) if relative.name else list(relative.parts)
94
+ for index in range(len(directories), 0, -1):
95
+ directory = Path(cwd).joinpath(*directories[:index])
96
+ block = read_block(directory / "AGENTS.md", max_bytes)
97
+ if block:
98
+ blocks.append(block)
99
+ return blocks