braid-coding-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 (192) hide show
  1. braid_coding_agent/__init__.py +13 -0
  2. braid_coding_agent/assembly.py +460 -0
  3. braid_coding_agent/cancellation.py +25 -0
  4. braid_coding_agent/checkpoint/__init__.py +106 -0
  5. braid_coding_agent/checkpoint/git.py +305 -0
  6. braid_coding_agent/checkpoint/settings.py +26 -0
  7. braid_coding_agent/checkpoint/store.py +1261 -0
  8. braid_coding_agent/checkpoint/workspace.py +220 -0
  9. braid_coding_agent/cli.py +2168 -0
  10. braid_coding_agent/commands/__init__.py +50 -0
  11. braid_coding_agent/commands/auth.py +161 -0
  12. braid_coding_agent/commands/config.py +180 -0
  13. braid_coding_agent/commands/doctor.py +511 -0
  14. braid_coding_agent/commands/mcp.py +928 -0
  15. braid_coding_agent/commands/models.py +95 -0
  16. braid_coding_agent/commands/setup.py +89 -0
  17. braid_coding_agent/commands/uninstall.py +277 -0
  18. braid_coding_agent/commands/upgrade.py +381 -0
  19. braid_coding_agent/compaction/__init__.py +174 -0
  20. braid_coding_agent/compaction/prepare.py +430 -0
  21. braid_coding_agent/compaction/summarize.py +542 -0
  22. braid_coding_agent/compaction/tokens.py +204 -0
  23. braid_coding_agent/compaction/tool_results.py +196 -0
  24. braid_coding_agent/compaction/utils.py +181 -0
  25. braid_coding_agent/config.py +2776 -0
  26. braid_coding_agent/config_files.py +191 -0
  27. braid_coding_agent/credentials.py +252 -0
  28. braid_coding_agent/discovery.py +415 -0
  29. braid_coding_agent/extensions/__init__.py +77 -0
  30. braid_coding_agent/extensions/api.py +480 -0
  31. braid_coding_agent/extensions/runner.py +553 -0
  32. braid_coding_agent/formatting/__init__.py +62 -0
  33. braid_coding_agent/formatting/settings.py +87 -0
  34. braid_coding_agent/formatting/tool.py +179 -0
  35. braid_coding_agent/lsp/__init__.py +105 -0
  36. braid_coding_agent/lsp/client.py +546 -0
  37. braid_coding_agent/lsp/manager.py +187 -0
  38. braid_coding_agent/lsp/model.py +316 -0
  39. braid_coding_agent/lsp/protocol.py +105 -0
  40. braid_coding_agent/lsp/settings.py +120 -0
  41. braid_coding_agent/lsp/tool.py +429 -0
  42. braid_coding_agent/mcp/__init__.py +101 -0
  43. braid_coding_agent/mcp/cache.py +230 -0
  44. braid_coding_agent/mcp/catalog.py +108 -0
  45. braid_coding_agent/mcp/config.py +664 -0
  46. braid_coding_agent/mcp/config_store.py +142 -0
  47. braid_coding_agent/mcp/inspector.py +85 -0
  48. braid_coding_agent/mcp/panel.py +254 -0
  49. braid_coding_agent/mcp/runtime.py +1060 -0
  50. braid_coding_agent/mcp/tools.py +579 -0
  51. braid_coding_agent/mcp/trust.py +150 -0
  52. braid_coding_agent/mcp/tui_panel.py +444 -0
  53. braid_coding_agent/messages.py +152 -0
  54. braid_coding_agent/models_view.py +105 -0
  55. braid_coding_agent/modes/__init__.py +64 -0
  56. braid_coding_agent/modes/json_mode.py +480 -0
  57. braid_coding_agent/modes/lifecycle.py +217 -0
  58. braid_coding_agent/modes/print_mode.py +257 -0
  59. braid_coding_agent/modes/repl.py +2687 -0
  60. braid_coding_agent/modes/repl_commands.py +263 -0
  61. braid_coding_agent/modes/rpc.py +953 -0
  62. braid_coding_agent/modes/skill_commands.py +88 -0
  63. braid_coding_agent/modes/tui.py +2226 -0
  64. braid_coding_agent/modes/tui_control.py +90 -0
  65. braid_coding_agent/modes/tui_model.py +1043 -0
  66. braid_coding_agent/modes/tui_render.py +327 -0
  67. braid_coding_agent/modes/tui_rich.py +751 -0
  68. braid_coding_agent/modes/tui_style.py +42 -0
  69. braid_coding_agent/modes/wire.py +81 -0
  70. braid_coding_agent/netsafe.py +82 -0
  71. braid_coding_agent/network/__init__.py +20 -0
  72. braid_coding_agent/network/cache.py +77 -0
  73. braid_coding_agent/network/fetch.py +311 -0
  74. braid_coding_agent/network/html_text.py +160 -0
  75. braid_coding_agent/network/search.py +347 -0
  76. braid_coding_agent/network/settings.py +103 -0
  77. braid_coding_agent/network/urls.py +89 -0
  78. braid_coding_agent/observability/__init__.py +101 -0
  79. braid_coding_agent/observability/audit.py +124 -0
  80. braid_coding_agent/observability/collector.py +314 -0
  81. braid_coding_agent/observability/exporter.py +74 -0
  82. braid_coding_agent/observability/logging_setup.py +149 -0
  83. braid_coding_agent/observability/redaction.py +96 -0
  84. braid_coding_agent/observability/settings.py +29 -0
  85. braid_coding_agent/observability/spans.py +239 -0
  86. braid_coding_agent/permissions/__init__.py +185 -0
  87. braid_coding_agent/permissions/command.py +586 -0
  88. braid_coding_agent/permissions/engine.py +522 -0
  89. braid_coding_agent/permissions/evaluate.py +309 -0
  90. braid_coding_agent/permissions/matching.py +233 -0
  91. braid_coding_agent/permissions/model.py +278 -0
  92. braid_coding_agent/permissions/policy.py +99 -0
  93. braid_coding_agent/permissions/readonly.py +236 -0
  94. braid_coding_agent/permissions/store.py +379 -0
  95. braid_coding_agent/project_init.py +313 -0
  96. braid_coding_agent/prompt/__init__.py +98 -0
  97. braid_coding_agent/prompt/context_files.py +253 -0
  98. braid_coding_agent/prompt/project_context.py +172 -0
  99. braid_coding_agent/prompt/system_prompt.py +378 -0
  100. braid_coding_agent/questions.py +71 -0
  101. braid_coding_agent/render/__init__.py +56 -0
  102. braid_coding_agent/render/batch.py +66 -0
  103. braid_coding_agent/render/history.py +143 -0
  104. braid_coding_agent/render/stream.py +823 -0
  105. braid_coding_agent/render/theme.py +243 -0
  106. braid_coding_agent/sandbox/__init__.py +89 -0
  107. braid_coding_agent/sandbox/backend.py +184 -0
  108. braid_coding_agent/sandbox/bubblewrap.py +96 -0
  109. braid_coding_agent/sandbox/operations.py +301 -0
  110. braid_coding_agent/sandbox/policy.py +221 -0
  111. braid_coding_agent/sandbox/proxy.py +320 -0
  112. braid_coding_agent/sandbox/seatbelt.py +222 -0
  113. braid_coding_agent/sdk/__init__.py +31 -0
  114. braid_coding_agent/sdk/async_client.py +366 -0
  115. braid_coding_agent/sdk/client.py +386 -0
  116. braid_coding_agent/sdk/errors.py +52 -0
  117. braid_coding_agent/sdk/events.py +162 -0
  118. braid_coding_agent/sdk/types.py +63 -0
  119. braid_coding_agent/sdk/wire.py +59 -0
  120. braid_coding_agent/server/__init__.py +54 -0
  121. braid_coding_agent/server/errors.py +52 -0
  122. braid_coding_agent/server/http_server.py +419 -0
  123. braid_coding_agent/server/hub.py +530 -0
  124. braid_coding_agent/server/openapi.py +157 -0
  125. braid_coding_agent/server/registry.py +354 -0
  126. braid_coding_agent/server/router.py +275 -0
  127. braid_coding_agent/server/run.py +148 -0
  128. braid_coding_agent/server/schema.py +194 -0
  129. braid_coding_agent/server/service.py +975 -0
  130. braid_coding_agent/session/__init__.py +293 -0
  131. braid_coding_agent/session/agent_session.py +2706 -0
  132. braid_coding_agent/session/context_breakdown.py +302 -0
  133. braid_coding_agent/session/discovery.py +212 -0
  134. braid_coding_agent/session/entries.py +809 -0
  135. braid_coding_agent/session/evidence.py +295 -0
  136. braid_coding_agent/session/lock.py +176 -0
  137. braid_coding_agent/session/manager.py +1185 -0
  138. braid_coding_agent/session/plan.py +243 -0
  139. braid_coding_agent/session/plan_mode.py +423 -0
  140. braid_coding_agent/session/projection.py +262 -0
  141. braid_coding_agent/session/rewind.py +257 -0
  142. braid_coding_agent/session/status.py +240 -0
  143. braid_coding_agent/settings.py +94 -0
  144. braid_coding_agent/skills/__init__.py +70 -0
  145. braid_coding_agent/skills/loader.py +681 -0
  146. braid_coding_agent/startup/__init__.py +76 -0
  147. braid_coding_agent/startup/cache.py +72 -0
  148. braid_coding_agent/startup/diagnostics.py +37 -0
  149. braid_coding_agent/startup/monitor.py +245 -0
  150. braid_coding_agent/startup/phases.py +79 -0
  151. braid_coding_agent/startup/project.py +165 -0
  152. braid_coding_agent/startup/report.py +560 -0
  153. braid_coding_agent/startup/scheduler.py +347 -0
  154. braid_coding_agent/statusline.py +163 -0
  155. braid_coding_agent/subagents/__init__.py +22 -0
  156. braid_coding_agent/subagents/contract.py +75 -0
  157. braid_coding_agent/subagents/definitions.py +583 -0
  158. braid_coding_agent/subagents/registry.py +277 -0
  159. braid_coding_agent/subagents/runtime.py +610 -0
  160. braid_coding_agent/subagents/settings.py +156 -0
  161. braid_coding_agent/subagents/worktree.py +63 -0
  162. braid_coding_agent/tools/__init__.py +327 -0
  163. braid_coding_agent/tools/args.py +87 -0
  164. braid_coding_agent/tools/bash.py +359 -0
  165. braid_coding_agent/tools/edit.py +298 -0
  166. braid_coding_agent/tools/edit_diff.py +344 -0
  167. braid_coding_agent/tools/find.py +158 -0
  168. braid_coding_agent/tools/grep.py +305 -0
  169. braid_coding_agent/tools/ignore.py +198 -0
  170. braid_coding_agent/tools/ls.py +127 -0
  171. braid_coding_agent/tools/mutation_queue.py +90 -0
  172. braid_coding_agent/tools/operations.py +274 -0
  173. braid_coding_agent/tools/output_accumulator.py +282 -0
  174. braid_coding_agent/tools/output_store.py +244 -0
  175. braid_coding_agent/tools/path_utils.py +91 -0
  176. braid_coding_agent/tools/plan.py +141 -0
  177. braid_coding_agent/tools/prompt_notes.py +52 -0
  178. braid_coding_agent/tools/question.py +180 -0
  179. braid_coding_agent/tools/read.py +223 -0
  180. braid_coding_agent/tools/submit_plan.py +102 -0
  181. braid_coding_agent/tools/truncate.py +423 -0
  182. braid_coding_agent/tools/write.py +100 -0
  183. braid_coding_agent/untrusted.py +50 -0
  184. braid_coding_agent/verify/__init__.py +78 -0
  185. braid_coding_agent/verify/runner.py +260 -0
  186. braid_coding_agent/verify/settings.py +64 -0
  187. braid_coding_agent/verify/tool.py +143 -0
  188. braid_coding_agent-0.1.0.dist-info/METADATA +19 -0
  189. braid_coding_agent-0.1.0.dist-info/RECORD +192 -0
  190. braid_coding_agent-0.1.0.dist-info/WHEEL +4 -0
  191. braid_coding_agent-0.1.0.dist-info/entry_points.txt +3 -0
  192. braid_coding_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,305 @@
1
+ """跑 git 子命令:argv 直传、环境隔离、可超时、可取消。
2
+
3
+ ## 为什么不用 shell
4
+
5
+ 命令里的路径可能带空格、中文或前缀 ``-``。走 ``bash -c`` 就要自己拼引号,而拼引号
6
+ 的错误只有在某个用户目录名叫 ``a b`` 时才暴露。这里一律 argv 直传:调用方给什么,
7
+ ``execve`` 收到什么。
8
+
9
+ ## 为什么要隔离环境
10
+
11
+ 检查点用的是**影子仓库**:``GIT_DIR`` 指向会话目录,``GIT_WORK_TREE`` 指向工作目录。
12
+ 如果不显式设置,git 会沿着 ``cwd`` 往上找到用户自己的仓库,快照就会写进他的 ``.git``
13
+ 里——那是不可接受的副作用。另外三项也要固定:
14
+
15
+ - ``GIT_TERMINAL_PROMPT=0``:需要凭据时立刻失败,不要卡在一个没有终端的提示上;
16
+ - ``LC_ALL=C``:错误文本与 porcelain 输出不随用户语言变化;
17
+ - ``GIT_PAGER=cat``:不给一个不存在的终端分页。
18
+
19
+ 行尾转换由影子仓库自己的 ``core.autocrlf = false`` 关掉(见 :meth:`Git.init`)。
20
+ 跟随用户的全局设置会让一次撤销把 LF 文件写回 CRLF,整篇文件的 diff 都会变脏。
21
+
22
+ ## 超时与取消
23
+
24
+ git 平常几十毫秒返回,但仓库很大、磁盘很慢、或者用户机器上有个卡住的 ``fsmonitor``
25
+ 时,一条命令可以挂很久。所有调用都带超时;取消走 ``CancelToken`` 轮询,与
26
+ :class:`~braid_coding_agent.tools.operations.LocalShellOperations` 同一套做法——
27
+ 杀进程组,不留下拿着管道的孤儿进程。
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ import asyncio
33
+ import os
34
+ import signal as signal_module
35
+ from collections.abc import Mapping, Sequence
36
+ from dataclasses import dataclass
37
+ from pathlib import Path
38
+ from types import MappingProxyType
39
+ from typing import Final
40
+
41
+ from braid_ai.cancel import CancelToken
42
+ from braid_coding_agent.tools.operations import OperationAborted
43
+
44
+ #: 等待子进程时的轮询间隔(秒)。20 次/秒的空转成本可以忽略。
45
+ _POLL: Final[float] = 0.05
46
+
47
+ #: 单条 git 命令的默认超时(秒)。大仓库上 ``add -A`` 也就几秒。
48
+ DEFAULT_TIMEOUT_SECONDS: Final[float] = 30.0
49
+
50
+ #: 影子仓库的固定配置。走 ``GIT_CONFIG_*`` 环境变量注入,不落盘也不需要额外进程。
51
+ SHADOW_CONFIG: Final[Mapping[str, str]] = MappingProxyType(
52
+ {
53
+ "core.bare": "false",
54
+ "core.autocrlf": "false",
55
+ "core.safecrlf": "false",
56
+ "core.fsmonitor": "false",
57
+ "core.quotePath": "false",
58
+ "gc.auto": "0",
59
+ }
60
+ )
61
+
62
+
63
+ class GitError(RuntimeError):
64
+ """git 命令返回非零退出码。``command`` 与 ``stderr`` 都在消息里,便于定位。"""
65
+
66
+ def __init__(self, command: str, returncode: int, stderr: str) -> None:
67
+ detail = stderr.strip() or "(没有错误输出)"
68
+ super().__init__(f"git {command} 失败(退出码 {returncode}):{detail}")
69
+ self.command = command
70
+ self.returncode = returncode
71
+ self.stderr = stderr
72
+
73
+
74
+ class GitUnavailableError(GitError):
75
+ """找不到 git 可执行文件。调用方据此关闭检查点并明确告知用户。"""
76
+
77
+ def __init__(self, executable: str) -> None:
78
+ RuntimeError.__init__(
79
+ self,
80
+ f"找不到 git 可执行文件 {executable!r};检查点需要 git,"
81
+ "安装 git 后重试,或用 --no-checkpoint 关闭检查点",
82
+ )
83
+ self.command = executable
84
+ self.returncode = 127
85
+ self.stderr = ""
86
+
87
+
88
+ class GitTimeout(GitError):
89
+ """命令超过时限,已被杀掉。"""
90
+
91
+ def __init__(self, command: str, timeout: float) -> None:
92
+ RuntimeError.__init__(self, f"git {command} 超时(超过 {timeout:g} 秒),已终止")
93
+ self.command = command
94
+ self.returncode = -signal_module.SIGKILL
95
+ self.stderr = ""
96
+
97
+
98
+ @dataclass(slots=True, frozen=True)
99
+ class GitResult:
100
+ """一条命令的完整结果。``stdout`` 保持字节,路径解析由调用方决定解码方式。"""
101
+
102
+ argv: tuple[str, ...]
103
+ returncode: int
104
+ stdout: bytes
105
+ stderr: bytes
106
+
107
+ @property
108
+ def ok(self) -> bool:
109
+ return self.returncode == 0
110
+
111
+ @property
112
+ def content(self) -> bytes:
113
+ return self.stdout
114
+
115
+ @property
116
+ def text(self) -> str:
117
+ return self.stdout.decode("utf-8", errors="replace")
118
+
119
+ @property
120
+ def error_text(self) -> str:
121
+ return self.stderr.decode("utf-8", errors="replace")
122
+
123
+
124
+ class Git:
125
+ """在一组固定的 ``GIT_DIR`` / ``GIT_WORK_TREE`` 上跑命令。
126
+
127
+ :param cwd: 子进程的工作目录。相对路径都相对它解释。
128
+ :param git_dir: ``GIT_DIR``。``None`` 表示"用用户自己的仓库",供
129
+ :class:`~braid_coding_agent.checkpoint.workspace.GitWorkspace` 使用。
130
+ :param work_tree: ``GIT_WORK_TREE``。影子仓库必须显式给出。
131
+ :param executable: git 可执行文件,测试可以指向一个不存在的路径。
132
+ :param config: 每条命令都生效的配置项。用 ``GIT_CONFIG_*`` 环境变量传,不写进
133
+ 仓库、也不多一次 ``git config`` 进程。
134
+ """
135
+
136
+ def __init__(
137
+ self,
138
+ *,
139
+ cwd: str,
140
+ git_dir: str | None = None,
141
+ work_tree: str | None = None,
142
+ executable: str = "git",
143
+ timeout: float = DEFAULT_TIMEOUT_SECONDS,
144
+ config: Mapping[str, str] | None = None,
145
+ ) -> None:
146
+ self._cwd = os.path.abspath(cwd)
147
+ self._git_dir = os.path.abspath(git_dir) if git_dir is not None else None
148
+ self._work_tree = os.path.abspath(work_tree) if work_tree is not None else None
149
+ self._executable = executable
150
+ self._timeout = timeout
151
+ self._config = dict(config) if config is not None else {}
152
+
153
+ # ---------------------------------------------------------------- 只读面
154
+
155
+ @property
156
+ def cwd(self) -> str:
157
+ return self._cwd
158
+
159
+ @property
160
+ def git_dir(self) -> str | None:
161
+ return self._git_dir
162
+
163
+ @property
164
+ def work_tree(self) -> str | None:
165
+ return self._work_tree
166
+
167
+ # ------------------------------------------------------------------ 生命周期
168
+
169
+ async def init(self, *, exclude: Sequence[str] = ()) -> None:
170
+ """建好影子仓库并写排除表。可重复调用。
171
+
172
+ :param exclude: 追加到 ``info/exclude`` 的模式。``.git/`` 总是写入:
173
+ 工作树里那个目录属于用户的项目仓库,不是快照对象。
174
+ """
175
+ assert self._git_dir is not None
176
+ assert self._work_tree is not None
177
+ os.makedirs(self._git_dir, exist_ok=True)
178
+ if not (Path(self._git_dir) / "HEAD").exists():
179
+ await self.out("init", "-q")
180
+ await self._ensure_config()
181
+ info = Path(self._git_dir) / "info"
182
+ info.mkdir(parents=True, exist_ok=True)
183
+ patterns = [".git/", *exclude]
184
+ (info / "exclude").write_text("\n".join(patterns) + "\n", encoding="utf-8")
185
+
186
+ async def _ensure_config(self) -> None:
187
+ """确认固定配置真的生效,没生效就逐条写进仓库。
188
+
189
+ ``GIT_CONFIG_*`` 是 git 2.31 起的特性。更老的 git 会**静默忽略**这几个变量,
190
+ 而它们当中 ``core.autocrlf`` 直接决定撤销会不会写坏行尾。所以这里查一次:
191
+ 生效就一次进程都不多花,不生效才退回六次 ``git config``。
192
+ """
193
+ if not self._config:
194
+ return
195
+ current = await self.run("config", "--get", "core.autocrlf")
196
+ if current.ok and current.text.strip() == self._config["core.autocrlf"]:
197
+ return
198
+ for key, value in self._config.items():
199
+ await self.out("config", key, value)
200
+
201
+ # -------------------------------------------------------------------- 执行
202
+
203
+ async def run(
204
+ self,
205
+ *args: str,
206
+ stdin: bytes | None = None,
207
+ timeout: float | None = None,
208
+ signal: CancelToken | None = None,
209
+ ) -> GitResult:
210
+ """跑一条命令,**不**检查退出码。超时与取消都抛异常。"""
211
+ argv = (self._executable, *args)
212
+ limit = self._timeout if timeout is None else timeout
213
+ try:
214
+ process = await asyncio.create_subprocess_exec(
215
+ *argv,
216
+ cwd=self._cwd,
217
+ env=self._env(),
218
+ stdin=asyncio.subprocess.PIPE if stdin is not None else asyncio.subprocess.DEVNULL,
219
+ stdout=asyncio.subprocess.PIPE,
220
+ stderr=asyncio.subprocess.PIPE,
221
+ start_new_session=True,
222
+ )
223
+ except FileNotFoundError as error:
224
+ raise GitUnavailableError(self._executable) from error
225
+ assert process.stdout is not None
226
+ assert process.stderr is not None
227
+ communicate = asyncio.create_task(process.communicate(stdin))
228
+ loop = asyncio.get_running_loop()
229
+ started = loop.time()
230
+ timed_out = False
231
+ cancelled = False
232
+ while not communicate.done():
233
+ if signal is not None and signal.cancelled:
234
+ cancelled = True
235
+ _kill_process_group(process.pid)
236
+ break
237
+ if loop.time() - started >= limit:
238
+ timed_out = True
239
+ _kill_process_group(process.pid)
240
+ break
241
+ await asyncio.sleep(_POLL)
242
+ stdout, stderr = await communicate
243
+ command = " ".join(args)
244
+ if cancelled:
245
+ raise OperationAborted(f"git {command} 已取消")
246
+ if timed_out:
247
+ raise GitTimeout(command, limit)
248
+ return GitResult(
249
+ argv=argv,
250
+ returncode=process.returncode if process.returncode is not None else 1,
251
+ stdout=stdout,
252
+ stderr=stderr,
253
+ )
254
+
255
+ async def out(
256
+ self,
257
+ *args: str,
258
+ stdin: bytes | None = None,
259
+ timeout: float | None = None,
260
+ signal: CancelToken | None = None,
261
+ ) -> str:
262
+ """跑一条命令,要求退出码为 0,返回去掉首尾空白的 stdout。"""
263
+ result = await self.run(*args, stdin=stdin, timeout=timeout, signal=signal)
264
+ if not result.ok:
265
+ raise GitError(" ".join(args), result.returncode, result.error_text or result.text)
266
+ return result.text.strip()
267
+
268
+ # -------------------------------------------------------------------- 环境
269
+
270
+ def _env(self) -> dict[str, str]:
271
+ """子进程环境:只加 git 需要的几项,其余继承(``HOME`` 影响全局配置)。"""
272
+ env = dict(os.environ)
273
+ if self._git_dir is not None:
274
+ env["GIT_DIR"] = self._git_dir
275
+ if self._work_tree is not None:
276
+ env["GIT_WORK_TREE"] = self._work_tree
277
+ env["GIT_TERMINAL_PROMPT"] = "0"
278
+ env["GIT_PAGER"] = "cat"
279
+ env["GIT_OPTIONAL_LOCKS"] = "0"
280
+ env["LC_ALL"] = "C"
281
+ if self._config:
282
+ env["GIT_CONFIG_COUNT"] = str(len(self._config))
283
+ for index, (key, value) in enumerate(self._config.items()):
284
+ env[f"GIT_CONFIG_KEY_{index}"] = key
285
+ env[f"GIT_CONFIG_VALUE_{index}"] = value
286
+ return env
287
+
288
+
289
+ def _kill_process_group(pid: int) -> None:
290
+ """杀掉以 ``pid`` 为组长的进程组。进程已退出是正常竞态。"""
291
+ try:
292
+ os.killpg(os.getpgid(pid), signal_module.SIGKILL)
293
+ except ProcessLookupError:
294
+ return
295
+
296
+
297
+ __all__ = [
298
+ "DEFAULT_TIMEOUT_SECONDS",
299
+ "SHADOW_CONFIG",
300
+ "Git",
301
+ "GitError",
302
+ "GitResult",
303
+ "GitTimeout",
304
+ "GitUnavailableError",
305
+ ]
@@ -0,0 +1,26 @@
1
+ """``[checkpoint]`` 配置的形状。
2
+
3
+ 单独放在这里,让配置加载不必为了一个 dataclass 拉进影子仓库、Git 子进程与
4
+ 会话条目模块。检查点实现从本模块导入这些类型。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass
10
+ from typing import Final
11
+
12
+ #: 单个文件进入快照的上限。超过它的文件只记一条跳过说明。
13
+ DEFAULT_MAX_FILE_BYTES: Final[int] = 2 * 1024 * 1024
14
+
15
+
16
+ @dataclass(slots=True, frozen=True)
17
+ class CheckpointSettings:
18
+ """``[checkpoint]`` 表。"""
19
+
20
+ enabled: bool = True
21
+ max_file_bytes: int = DEFAULT_MAX_FILE_BYTES
22
+ #: 追加到 ``snapshots/info/exclude`` 的模式,语义同 ``.gitignore``。
23
+ exclude: tuple[str, ...] = ()
24
+
25
+
26
+ __all__ = ["DEFAULT_MAX_FILE_BYTES", "CheckpointSettings"]