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,548 @@
1
+ """Configuration schema. See `docs/design/coding-agent-architecture.md` section 7."""
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
4
+
5
+ from coderagent.core.capabilities import MODALITIES
6
+ from coderagent.core.os_sandbox import MODES
7
+ from coderagent.core.session import PERSISTENCES
8
+ from coderagent.core.shell_env import INHERITS
9
+ from coderagent.models.call import check_reserved
10
+ from coderagent.models.reasoning import EFFORTS
11
+ from coderagent.models.verbosity import VERBOSITIES
12
+ from coderagent.tools.permissions import NETWORK_POLICIES, PermissionMode, check_rule
13
+
14
+ DEFAULT_SYSTEM_PROMPT = (
15
+ "You are a coding agent working in a code repository. "
16
+ "Prefer the dedicated tools over shell commands: `read` to look at a file, `glob`/`grep`/`ls` to find code, "
17
+ "`edit`/`multi_edit`/`apply_patch` to change files, and `bash` for builds, tests and pipelines. "
18
+ "Call every tool with the argument names of its schema, exactly as they are written there (`path`), "
19
+ "never a translated or renamed variant. "
20
+ "Complete the task the user describes and summarize what you changed."
21
+ )
22
+
23
+ BUILTIN_TOOL_NAMES = [
24
+ "read",
25
+ "write",
26
+ "edit",
27
+ "multi_edit",
28
+ "apply_patch",
29
+ "glob",
30
+ "grep",
31
+ "ls",
32
+ "bash",
33
+ "bash_output",
34
+ "bash_kill",
35
+ "todo_write",
36
+ "task",
37
+ "skill",
38
+ ]
39
+
40
+ ENVIRONMENT_CLASSES = {
41
+ "docker": "coderagent.environments.docker.DockerEnvironment",
42
+ "singularity": "coderagent.environments.singularity.SingularityEnvironment",
43
+ "swerex_docker": "coderagent.environments.swerex_docker.SwerexDockerEnvironment",
44
+ "swerex_modal": "coderagent.environments.swerex_modal.SwerexModalEnvironment",
45
+ "bubblewrap": "coderagent.environments.bubblewrap.BubblewrapEnvironment",
46
+ "contree": "coderagent.environments.contree.ContreeEnvironment",
47
+ }
48
+ """The remote sandboxes: the name the user writes and the class that runs it.
49
+
50
+ The classes are imported only when the sandbox is used: the packages of the
51
+ remote sandboxes are an extra of their own.
52
+ """
53
+
54
+ ENVIRONMENT_TYPES = ("local", *ENVIRONMENT_CLASSES)
55
+ """The kinds of environment the commands of the agent may run in."""
56
+
57
+ HOOK_EVENTS = (
58
+ "PreToolUse",
59
+ "PostToolUse",
60
+ "UserPromptSubmit",
61
+ "Stop",
62
+ "SessionStart",
63
+ "SessionEnd",
64
+ "SubagentStop",
65
+ "PreCompact",
66
+ "PostCompact",
67
+ )
68
+ """The moments of a session a hook may hang on."""
69
+
70
+ PURPOSES = ("main", "cheap", "strong", "summarize", "reflect", "review")
71
+ """The jobs a model may be picked for."""
72
+
73
+ COMPARISONS = {
74
+ ">": lambda left, right: left > right,
75
+ ">=": lambda left, right: left >= right,
76
+ "<": lambda left, right: left < right,
77
+ "<=": lambda left, right: left <= right,
78
+ "==": lambda left, right: left == right,
79
+ "!=": lambda left, right: left != right,
80
+ }
81
+ """The operators a condition of the routing may use."""
82
+
83
+
84
+ def parse_condition(when: str) -> tuple[str, str, float] | None:
85
+ """The parts of a condition: a key, an operator and a number.
86
+
87
+ Nothing when the condition is not one: a condition that cannot be read is
88
+ a condition that never holds, and the user should hear about it.
89
+ """
90
+ parts = when.split()
91
+ if len(parts) != 3:
92
+ return None
93
+ key, operator, value = parts
94
+ if operator not in COMPARISONS:
95
+ return None
96
+ try:
97
+ return key, operator, float(value)
98
+ except ValueError:
99
+ return None
100
+
101
+
102
+ def check_routing_rule(rule: dict) -> None:
103
+ """Whether a routing rule is one the router can read. It raises when it is not.
104
+
105
+ The rule is checked without the model, so that the message is the one of
106
+ the rule and not a nest of field names.
107
+ """
108
+ when = rule.get("when")
109
+ if not isinstance(when, str) or parse_condition(when) is None:
110
+ raise ValueError(f"'{when}' is not a condition. A condition is a key, an operator and a number.")
111
+ purpose = rule.get("purpose")
112
+ if purpose not in PURPOSES:
113
+ raise ValueError(f"unknown purpose '{purpose}'. Use one of: {', '.join(PURPOSES)}.")
114
+
115
+
116
+ class RoutingRuleConfig(BaseModel):
117
+ model_config = ConfigDict(extra="forbid")
118
+
119
+ when: str
120
+ """A condition on the state of the session, like `tokens > 50000`."""
121
+ purpose: str
122
+ """The purpose the model is picked for when the condition holds."""
123
+
124
+ @field_validator("when")
125
+ @classmethod
126
+ def _known_condition(cls, value: str) -> str:
127
+ if parse_condition(value) is None:
128
+ raise ValueError(f"'{value}' is not a condition. A condition is a key, an operator and a number.")
129
+ return value
130
+
131
+ @field_validator("purpose")
132
+ @classmethod
133
+ def _known_purpose(cls, value: str) -> str:
134
+ if value not in PURPOSES:
135
+ raise ValueError(f"unknown purpose '{value}'. Use one of: {', '.join(PURPOSES)}.")
136
+ return value
137
+
138
+
139
+ class ModelConfig(BaseModel):
140
+ model_config = ConfigDict(extra="forbid")
141
+
142
+ model_name: str = ""
143
+ """Model name. Falls back to $MSWEA_MODEL_NAME and then to a built-in default."""
144
+ model_kwargs: dict = Field(default_factory=dict)
145
+ api_key: str = ""
146
+ """The key of the provider of the model. It belongs to the user."""
147
+ api_base: str = ""
148
+ """The address of the provider of the model."""
149
+ max_retries: int = Field(default=3, ge=0)
150
+ litellm_config: str = ""
151
+ """A litellm config file with the model list. Its aliases name the models."""
152
+ routing: dict[str, str] = Field(default_factory=dict)
153
+ """The model of a purpose: `main`, `cheap`, `summarize`, `reflect`, `strong`."""
154
+ routing_rules: list[RoutingRuleConfig] = Field(default_factory=list)
155
+ set_cache_control: str | None = None
156
+ reasoning_effort: str = ""
157
+ """How much the model thinks: minimal, low, medium, high. Empty is the default of the model."""
158
+ verbosity: str = ""
159
+ """How much the model says: low, medium, high. Empty is the habit of the model."""
160
+ review_model: str = ""
161
+ """The model that reviews the changes. Empty means: the model of the session."""
162
+ capabilities: dict[str, dict[str, bool]] = Field(default_factory=dict)
163
+ """What the models take: the name of a model and the kinds of content it takes.
164
+
165
+ The user says it for the models litellm does not know: `{"my/model": {"image": true}}`.
166
+ """
167
+
168
+ @field_validator("reasoning_effort")
169
+ @classmethod
170
+ def _known_effort(cls, value: str) -> str:
171
+ if value and value not in EFFORTS:
172
+ raise ValueError(f"unknown reasoning effort '{value}'. Use one of: {', '.join(EFFORTS)}.")
173
+ return value
174
+
175
+ @field_validator("model_kwargs")
176
+ @classmethod
177
+ def _no_reserved_parameters(cls, value: dict) -> dict:
178
+ check_reserved(value)
179
+ """The parameters of the call belong to the agent: a user may not set them."""
180
+ return value
181
+
182
+ @field_validator("verbosity")
183
+ @classmethod
184
+ def _known_verbosity(cls, value: str) -> str:
185
+ if value and value not in VERBOSITIES:
186
+ raise ValueError(f"unknown verbosity '{value}'. Use one of: {', '.join(VERBOSITIES)}.")
187
+ return value
188
+
189
+ @field_validator("routing")
190
+ @classmethod
191
+ def _known_purposes(cls, value: dict) -> dict:
192
+ for purpose in value:
193
+ if purpose not in PURPOSES:
194
+ raise ValueError(f"unknown purpose '{purpose}'. Use one of: {', '.join(PURPOSES)}.")
195
+ return value
196
+
197
+ @field_validator("capabilities")
198
+ @classmethod
199
+ def _known_capabilities(cls, value: dict) -> dict:
200
+ for model, takes in value.items():
201
+ for modality, supported in takes.items():
202
+ if modality not in MODALITIES:
203
+ raise ValueError(
204
+ f"unknown kind of content '{modality}' for the model '{model}'. "
205
+ f"Use one of: {', '.join(MODALITIES)}."
206
+ )
207
+ if not isinstance(supported, bool):
208
+ raise ValueError(f"what the model '{model}' takes for {modality} is not true or false.")
209
+ return value
210
+
211
+
212
+ class AgentConfig(BaseModel):
213
+ model_config = ConfigDict(extra="forbid")
214
+
215
+ system_prompt: str = DEFAULT_SYSTEM_PROMPT
216
+ max_turns: int = Field(default=100, ge=0)
217
+ """Maximum number of model calls per user turn. 0 means no limit."""
218
+ cost_limit: float = Field(default=0.0, ge=0)
219
+ """Stop after exceeding this cost. 0 means no limit."""
220
+ token_limit: int = Field(default=0, ge=0)
221
+ """Stop after exceeding this many tokens. 0 means no limit.
222
+
223
+ It is the budget of a model that has no price, where the money never moves.
224
+ """
225
+ subagent_max_turns: int = Field(default=0, ge=0)
226
+ """The ceiling of the turns of every sub agent. 0 means no ceiling.
227
+
228
+ A sub agent that asks for more turns than this is held down to it.
229
+ """
230
+ subagent_max_parallel: int = Field(default=2, ge=0)
231
+ """How many sub agents may run at the same time. 0 means no limit."""
232
+
233
+
234
+ class ToolConfig(BaseModel):
235
+ model_config = ConfigDict(extra="forbid")
236
+
237
+ enabled: list[str] = Field(default_factory=lambda: list(BUILTIN_TOOL_NAMES))
238
+ """Names of the tools the model may call."""
239
+ disabled: list[str] = Field(default_factory=list)
240
+ bash_timeout: int = Field(default=120, ge=0)
241
+ max_output_tokens: int = Field(default=8000, ge=0)
242
+ schema_budget_tokens: int = Field(default=0, ge=0)
243
+ """The tokens the schemas of the tools may take. 0 means a tenth of the context window."""
244
+
245
+ @field_validator("enabled", "disabled")
246
+ @classmethod
247
+ def _known_tools(cls, value: list[str]) -> list[str]:
248
+ for name in value:
249
+ if name not in BUILTIN_TOOL_NAMES:
250
+ raise ValueError(f"unknown tool '{name}'. Use one of: {', '.join(BUILTIN_TOOL_NAMES)}.")
251
+ return value
252
+
253
+
254
+ class ShellEnvironmentConfig(BaseModel):
255
+ model_config = ConfigDict(extra="forbid")
256
+
257
+ inherit: str = "all"
258
+ """One of all, core, none. How much of the environment of the user the agent sees."""
259
+ exclude: list[str] = Field(default_factory=list)
260
+ """Patterns of the names of the variables that never reach the agent."""
261
+ include: list[str] = Field(default_factory=list)
262
+ """Patterns of the names that reach the agent even when they look like a secret."""
263
+ set: dict[str, str] = Field(default_factory=dict)
264
+ """The variables the agent always sees."""
265
+
266
+ @field_validator("inherit")
267
+ @classmethod
268
+ def _known_inherit(cls, value: str) -> str:
269
+ if value not in INHERITS:
270
+ raise ValueError(f"unknown inheritance '{value}'. Use one of: {', '.join(INHERITS)}.")
271
+ return value
272
+
273
+
274
+ class PermissionConfig(BaseModel):
275
+ model_config = ConfigDict(extra="forbid")
276
+
277
+ mode: str = "default"
278
+ """One of default, acceptEdits, plan, bypass, readonly."""
279
+ rules: list[dict] = Field(default_factory=list)
280
+ deny_paths: list[str] = Field(default_factory=list)
281
+ include_dirs: list[str] = Field(default_factory=list)
282
+ """Directories outside the working directory that the agent may still touch."""
283
+ network: str = "allow"
284
+ """One of allow, deny. `deny` refuses the commands that reach the network."""
285
+
286
+ @field_validator("mode")
287
+ @classmethod
288
+ def _known_mode(cls, value: str) -> str:
289
+ if value not in {mode.value for mode in PermissionMode}:
290
+ raise ValueError(
291
+ f"unknown permission mode '{value}'. Use one of: {', '.join(m.value for m in PermissionMode)}."
292
+ )
293
+ return value
294
+
295
+ @field_validator("network")
296
+ @classmethod
297
+ def _known_network(cls, value: str) -> str:
298
+ if value not in NETWORK_POLICIES:
299
+ raise ValueError(f"unknown network policy '{value}'. Use one of: {', '.join(NETWORK_POLICIES)}.")
300
+ return value
301
+
302
+ @field_validator("rules")
303
+ @classmethod
304
+ def _known_rules(cls, value: list[dict]) -> list[dict]:
305
+ for number, rule in enumerate(value, start=1):
306
+ try:
307
+ check_rule(rule)
308
+ except ValueError as error:
309
+ raise ValueError(f"rule {number}: {error}") from None
310
+ """A rule that says something the policy does not know is a rule
311
+ that may not deny: it is refused at the start instead."""
312
+ return value
313
+
314
+
315
+ class ContextConfig(BaseModel):
316
+ model_config = ConfigDict(extra="forbid")
317
+
318
+ context_window: int = Field(default=200000, gt=0)
319
+ reserved_output: int = Field(default=8000, ge=0)
320
+ compact_threshold: float = Field(default=0.8, gt=0, le=1)
321
+ keep_recent_turns: int = Field(default=20, ge=0)
322
+ keep_recent_token_ratio: float = Field(default=0.4, ge=0, le=1)
323
+ compact_every_turns: int = Field(default=40, ge=0)
324
+ auto_compact: bool = True
325
+ summarize_model: str = ""
326
+ """Model used for summarization. Empty means the same model as the agent."""
327
+ summary_chunk_tokens: int = Field(default=0, ge=0)
328
+ """How many tokens one summarization prompt may take. Zero means: as much as the window allows."""
329
+ project_doc_max_bytes: int = Field(default=32768, ge=0)
330
+ """The bytes one instruction file may take. A longer file is cut short."""
331
+
332
+
333
+ class MemoryConfig(BaseModel):
334
+ model_config = ConfigDict(extra="forbid")
335
+
336
+ project_path: str = ".coderagent/memory"
337
+ user_path: str = "~/.coderagent/CLAUDE.md"
338
+ enabled: bool = True
339
+
340
+
341
+ class CheckpointConfig(BaseModel):
342
+ model_config = ConfigDict(extra="forbid")
343
+
344
+ enabled: bool = True
345
+ keep: int = Field(default=50, ge=0)
346
+
347
+
348
+ class MCPServerConfig(BaseModel):
349
+ model_config = ConfigDict(extra="forbid")
350
+
351
+ name: str
352
+ command: str = ""
353
+ """Command that starts the server, for the stdio transport."""
354
+ url: str = ""
355
+ """Address of the server, for the http transport."""
356
+ env: dict[str, str] = Field(default_factory=dict)
357
+ headers: dict[str, str] = Field(default_factory=dict)
358
+ enabled: bool = True
359
+ enabled_tools: list[str] = Field(default_factory=list)
360
+ """The tools of this server that the agent may call. Empty means: all of them."""
361
+ disabled_tools: list[str] = Field(default_factory=list)
362
+ """The tools of this server that the agent may not call."""
363
+ startup_timeout: int = Field(default=0, ge=0)
364
+ """The seconds the server may take to start. Zero means: the timeout of the section."""
365
+ tool_timeout: int = Field(default=0, ge=0)
366
+ """The seconds one call of this server may take. Zero means: the timeout of the section."""
367
+ supports_parallel_tool_calls: bool = True
368
+ """Whether two calls of this server may run at the same time."""
369
+
370
+
371
+ class MCPConfig(BaseModel):
372
+ model_config = ConfigDict(extra="forbid")
373
+
374
+ servers: list[MCPServerConfig] = Field(default_factory=list)
375
+ timeout: int = Field(default=30, ge=0)
376
+
377
+
378
+ class HookCommand(BaseModel):
379
+ model_config = ConfigDict(extra="forbid")
380
+
381
+ type: str = "command"
382
+ command: str
383
+ timeout: int = Field(default=10, ge=0)
384
+ strict: bool = False
385
+ """When the hook fails, block the action instead of letting it through."""
386
+
387
+
388
+ class HookMatcher(BaseModel):
389
+ model_config = ConfigDict(extra="forbid")
390
+
391
+ matcher: str = ""
392
+ """Regular expression of the tool names this hook applies to. Empty means all."""
393
+ hooks: list[HookCommand] = Field(default_factory=list)
394
+
395
+
396
+ class HookConfig(BaseModel):
397
+ model_config = ConfigDict(extra="forbid")
398
+
399
+ events: dict[str, list[HookMatcher]] = Field(default_factory=dict)
400
+
401
+ @field_validator("events")
402
+ @classmethod
403
+ def _known_events(cls, value: dict) -> dict:
404
+ for event in value:
405
+ if event not in HOOK_EVENTS:
406
+ raise ValueError(f"unknown hook event '{event}'. Use one of: {', '.join(HOOK_EVENTS)}.")
407
+ return value
408
+
409
+
410
+ class UIConfig(BaseModel):
411
+ model_config = ConfigDict(extra="forbid")
412
+
413
+ approval_timeout: int = Field(default=0, ge=0)
414
+ """Seconds to wait for an approval. 0 waits forever."""
415
+ notifications: bool = True
416
+ """Tell the terminal when a turn is over. The terminal may not show it."""
417
+ notify_command: str = ""
418
+ """A program that tells the user that the turn is over. It gets the title and the body."""
419
+ file_opener: str = ""
420
+ """The program that opens a file: vscode, cursor, windsurf, or a command with {file}."""
421
+ markdown: bool = True
422
+ """Render the answer of the agent as Markdown. The text stays plain while it arrives."""
423
+
424
+
425
+ class HistoryConfig(BaseModel):
426
+ model_config = ConfigDict(extra="forbid")
427
+
428
+ persistence: str = "save-all"
429
+ """One of save-all, save-none. Whether the history of the sessions is written to the disk."""
430
+ max_bytes: int = Field(default=0, ge=0)
431
+ """The bytes the history of all the sessions may take. 0 means no limit.
432
+
433
+ The oldest sessions are deleted when the history grows over it.
434
+ """
435
+
436
+ @field_validator("persistence")
437
+ @classmethod
438
+ def _known_persistence(cls, value: str) -> str:
439
+ if value not in PERSISTENCES:
440
+ raise ValueError(f"unknown persistence '{value}'. Use one of: {', '.join(PERSISTENCES)}.")
441
+ return value
442
+
443
+
444
+ class SandboxConfig(BaseModel):
445
+ model_config = ConfigDict(extra="allow")
446
+ """The options of the environment, like `image` for a container."""
447
+
448
+ type: str = "local"
449
+ """The kind of environment. `local` or one of the remote sandboxes."""
450
+ mode: str = "full-access"
451
+ """How much the commands of the agent may do on this machine.
452
+
453
+ One of `read-only`, `workspace-write` or `full-access`. The modes are
454
+ enforced by the operating system, so they hold whatever the permission
455
+ layer says.
456
+ """
457
+
458
+ @field_validator("mode")
459
+ @classmethod
460
+ def _known_mode(cls, value: str) -> str:
461
+ if value not in MODES:
462
+ raise ValueError(f"unknown sandbox mode '{value}'. Use one of: {', '.join(MODES)}.")
463
+ return value
464
+
465
+ @field_validator("type")
466
+ @classmethod
467
+ def _known_type(cls, value: str) -> str:
468
+ if value not in ENVIRONMENT_TYPES and "." not in value:
469
+ """A path to a class of the user is a kind of environment too."""
470
+ raise ValueError(f"unknown environment '{value}'. Use one of: {', '.join(ENVIRONMENT_TYPES)}.")
471
+ return value
472
+
473
+
474
+ class VerifyConfig(BaseModel):
475
+ model_config = ConfigDict(extra="forbid")
476
+
477
+ commands: list[str] = Field(default_factory=list)
478
+ """The commands that check the work of the agent. Empty means: no verification."""
479
+ max_rounds: int = Field(default=3, ge=0)
480
+ """How many times the agent may try to make the commands pass."""
481
+ timeout: int = Field(default=300, ge=0)
482
+ """The seconds one command may take."""
483
+
484
+
485
+ class TelemetryConfig(BaseModel):
486
+ model_config = ConfigDict(extra="forbid")
487
+
488
+ otel_endpoint: str = ""
489
+ """Where the trace of a session goes. Empty means: it stays in the local event log."""
490
+ otel_headers: dict[str, str] = Field(default_factory=dict)
491
+ """The headers that address wants, like the key it asks for."""
492
+ otel_timeout: float = Field(default=5.0, ge=0)
493
+ """The seconds one push may take."""
494
+
495
+
496
+ class SkillsConfig(BaseModel):
497
+ model_config = ConfigDict(extra="forbid")
498
+
499
+ enabled: bool = True
500
+ """Whether skills may be downloaded and installed."""
501
+ max_bytes: int = Field(default=8 * 1024 * 1024, ge=0)
502
+ """How many bytes a download may take."""
503
+ max_file_bytes: int = Field(default=1024 * 1024, ge=0)
504
+ """How many bytes one file of a skill may have."""
505
+ max_files: int = Field(default=2000, ge=0)
506
+ """How many files a skill may have."""
507
+ max_depth: int = Field(default=16, ge=0)
508
+ """How deep the directories of a skill may go."""
509
+ timeout: int = Field(default=30, ge=0)
510
+ """The seconds a download may take."""
511
+ registries: list[str] = Field(default_factory=list)
512
+ """The registries that are offered in the page of the skills."""
513
+ github_token: str = ""
514
+ """The token of GitHub. It only goes into the headers of a request."""
515
+ allow_insecure: bool = False
516
+ """Whether `http://` may be fetched. `https://` is the rule."""
517
+ allowed_hosts: list[str] = Field(default_factory=list)
518
+ """The hosts that may point inside the network. The others may not."""
519
+
520
+
521
+ class Config(BaseModel):
522
+ model_config = ConfigDict(extra="forbid", hide_input_in_errors=True)
523
+ """The values that went wrong are not shown: a key may be among them.
524
+
525
+ A section that is not known is refused: a name that is written wrong would
526
+ otherwise be a setting that does nothing.
527
+ """
528
+
529
+ model: ModelConfig = Field(default_factory=ModelConfig)
530
+ agent: AgentConfig = Field(default_factory=AgentConfig)
531
+ tools: ToolConfig = Field(default_factory=ToolConfig)
532
+ permissions: PermissionConfig = Field(default_factory=PermissionConfig)
533
+ shell_environment: ShellEnvironmentConfig = Field(default_factory=ShellEnvironmentConfig)
534
+ context: ContextConfig = Field(default_factory=ContextConfig)
535
+ memory: MemoryConfig = Field(default_factory=MemoryConfig)
536
+ checkpoint: CheckpointConfig = Field(default_factory=CheckpointConfig)
537
+ mcp: MCPConfig = Field(default_factory=MCPConfig)
538
+ hooks: HookConfig = Field(default_factory=HookConfig)
539
+ ui: UIConfig = Field(default_factory=UIConfig)
540
+ history: HistoryConfig = Field(default_factory=HistoryConfig)
541
+ sandbox: SandboxConfig = Field(default_factory=SandboxConfig)
542
+ verify: VerifyConfig = Field(default_factory=VerifyConfig)
543
+ telemetry: TelemetryConfig = Field(default_factory=TelemetryConfig)
544
+ skills: SkillsConfig = Field(default_factory=SkillsConfig)
545
+ profiles: dict[str, dict] = Field(default_factory=dict)
546
+ """Named presets of the configuration. `--profile` picks one of them."""
547
+ profile: str = ""
548
+ """The name of the profile that is in effect."""