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,87 @@
1
+ """格式化命令的配置与 ``format`` 工具。
2
+
3
+ ## 为什么是一个工具,而不是"保存后自动格式化"的钩子
4
+
5
+ 钩子会在模型看不到的地方改文件:``write`` 写进 100 个字符的缩进,钩子把它重排成
6
+ 80,模型下一回合读到的内容与它自己写的不一样,diff 也解释不清。工具则是可审计的:
7
+ 模型说"我要格式化这个文件",权限引擎按 ``format`` 这个名字与路径判定,结果里写明
8
+ 跑了哪条命令、文件有没有被改动。
9
+
10
+ ## 命令是 argv 数组,必须含 ``{path}``
11
+
12
+ ```json
13
+ {
14
+ "format": {
15
+ "commands": {
16
+ ".py": ["ruff", "format", "{path}"],
17
+ ".ts": ["npx", "prettier", "--write", "{path}"]
18
+ }
19
+ }
20
+ }
21
+ ```
22
+
23
+ 要求 ``{path}`` 是刻意的:没有占位符的命令(``prettier --write`` 不带文件)会去格式化
24
+ stdin 或者整个仓库,两种都不是"格式化我刚写的这个文件"。配置读取时就拒绝这种写法,
25
+ 比在第一次调用时格式化半个仓库便宜得多。
26
+
27
+ 同一个扩展名只配一条命令。需要串两条(先 ``isort`` 再 ``black``)时,把它写成项目脚本
28
+ (``./scripts/fmt.sh``)由 ``format.commands`` 调用,不要在工具里引入"步骤数组"——
29
+ 那等于在配置里重写一遍 shell。
30
+ """
31
+
32
+ from __future__ import annotations
33
+
34
+ import os
35
+ import shlex
36
+ from collections.abc import Mapping
37
+ from dataclasses import dataclass, field
38
+
39
+ #: 单次格式化的默认超时(秒)。
40
+ DEFAULT_FORMAT_TIMEOUT_SECONDS = 30.0
41
+ #: 命令里代表目标文件的占位符。
42
+ PATH_PLACEHOLDER = "{path}"
43
+
44
+
45
+ @dataclass(slots=True, frozen=True)
46
+ class FormatSettings:
47
+ """扩展名 → 格式化命令。键是归一化后的扩展名(带前导点、小写)。"""
48
+
49
+ enabled: bool = True
50
+ timeout_seconds: float = DEFAULT_FORMAT_TIMEOUT_SECONDS
51
+ commands: Mapping[str, tuple[str, ...]] = field(default_factory=dict[str, tuple[str, ...]])
52
+
53
+ @property
54
+ def has_commands(self) -> bool:
55
+ """有配置时才给会话装 ``format`` 工具。"""
56
+ return self.enabled and bool(self.commands)
57
+
58
+ def command_for(self, path: str) -> tuple[str, ...] | None:
59
+ return self.commands.get(os.path.splitext(path)[1].lower())
60
+
61
+ def extensions(self) -> tuple[str, ...]:
62
+ return tuple(self.commands)
63
+
64
+ def describe(self) -> str:
65
+ if not self.commands:
66
+ return "未配置格式化命令"
67
+ pairs = (f"{extension}={shlex.join(argv)}" for extension, argv in self.commands.items())
68
+ return " ".join(pairs)
69
+
70
+
71
+ def build_argv(template: tuple[str, ...], path: str) -> list[str]:
72
+ """把 ``{path}`` 换成绝对路径。配置读取时已保证占位符存在。"""
73
+ return [token.replace(PATH_PLACEHOLDER, path) for token in template]
74
+
75
+
76
+ def build_shell_command(template: tuple[str, ...], path: str) -> str:
77
+ """交给 shell 执行的完整命令。argv 用 ``shlex.join`` 引号化,路径里有空格也安全。"""
78
+ return shlex.join(build_argv(template, path))
79
+
80
+
81
+ __all__ = [
82
+ "DEFAULT_FORMAT_TIMEOUT_SECONDS",
83
+ "PATH_PLACEHOLDER",
84
+ "FormatSettings",
85
+ "build_argv",
86
+ "build_shell_command",
87
+ ]
@@ -0,0 +1,179 @@
1
+ """``format`` 工具:按项目配置跑一次格式化,并如实报告文件有没有变。
2
+
3
+ 工具只做三件事:找到这个扩展名对应的命令、执行、比较执行前后的内容。它不判断
4
+ "格式对不对"——那是格式化工具自己的事;也不在失败时回退到别的命令——项目配了哪条
5
+ 就只跑哪条,换个工具重排一遍会让 diff 变成两种风格的混合。
6
+
7
+ 结果里必须包含 ``changed``:模型经常在格式化之后继续 ``edit`` 同一个文件,它需要
8
+ 知道自己手上那份内容是不是已经被重排过。
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import asyncio
14
+ import hashlib
15
+ import os
16
+ import time
17
+
18
+ from braid_agent.tools import AgentTool, AgentToolResult, ToolUpdateSink
19
+ from braid_ai.cancel import CancelToken
20
+ from braid_ai.types import JsonValue, TextContent
21
+ from braid_coding_agent.formatting.settings import (
22
+ FormatSettings,
23
+ build_argv,
24
+ build_shell_command,
25
+ )
26
+ from braid_coding_agent.tools.args import string_arg
27
+ from braid_coding_agent.tools.operations import (
28
+ CommandTimedOut,
29
+ LocalShellOperations,
30
+ ShellOperations,
31
+ )
32
+ from braid_coding_agent.tools.path_utils import relative_posix, resolve_to_cwd
33
+ from braid_coding_agent.tools.prompt_notes import FORMAT_GUIDELINES, FORMAT_SNIPPET
34
+ from braid_coding_agent.tools.truncate import clip_tail
35
+
36
+ #: 展示的命令输出上限。格式化工具的报错通常只有几行。
37
+ OUTPUT_MAX_LINES = 20
38
+ OUTPUT_MAX_BYTES = 4 * 1024
39
+
40
+ FORMAT_PARAMETERS: dict[str, JsonValue] = {
41
+ "type": "object",
42
+ "properties": {
43
+ "path": {
44
+ "type": "string",
45
+ "description": "File to format (relative or absolute)",
46
+ }
47
+ },
48
+ "required": ["path"],
49
+ "additionalProperties": False,
50
+ }
51
+
52
+
53
+ def create_format_tool(
54
+ settings: FormatSettings,
55
+ *,
56
+ cwd: str,
57
+ shell: ShellOperations | None = None,
58
+ env: dict[str, str] | None = None,
59
+ ) -> AgentTool:
60
+ """构造 ``format``。``shell`` 决定命令在哪里跑(本机或沙箱)。"""
61
+ ops: ShellOperations = shell if shell is not None else LocalShellOperations()
62
+
63
+ async def execute(
64
+ tool_call_id: str,
65
+ args: dict[str, JsonValue],
66
+ signal: CancelToken | None,
67
+ on_update: ToolUpdateSink,
68
+ ) -> AgentToolResult:
69
+ del tool_call_id, on_update
70
+ path = resolve_to_cwd(string_arg(args, "path"), cwd)
71
+ if not os.path.isfile(path):
72
+ return _failure(f"文件不存在或不是普通文件:{path}", {"path": path})
73
+ template = settings.command_for(path)
74
+ if template is None:
75
+ configured = ", ".join(settings.extensions()) or "(无)"
76
+ return _failure(
77
+ f"没有为 {os.path.splitext(path)[1] or '无扩展名文件'} 配置格式化命令"
78
+ f"(已配置:{configured})。可以用 bash 跑项目自己的格式化命令,"
79
+ "或在 format.commands 里加一条。",
80
+ {"path": path, "error": "no_formatter"},
81
+ )
82
+
83
+ before = await asyncio.to_thread(_digest, path)
84
+ command = build_shell_command(template, path)
85
+ chunks: list[bytes] = []
86
+ started = time.monotonic()
87
+ try:
88
+ exit_code = await ops.exec(
89
+ command,
90
+ cwd,
91
+ on_data=chunks.append,
92
+ timeout=settings.timeout_seconds,
93
+ signal=signal,
94
+ env=env,
95
+ )
96
+ timed_out = False
97
+ except CommandTimedOut:
98
+ exit_code = None
99
+ timed_out = True
100
+ duration = round(time.monotonic() - started, 1)
101
+ after = await asyncio.to_thread(_digest, path)
102
+ changed = before != after
103
+ output = clip_tail(
104
+ b"".join(chunks).decode("utf-8", errors="replace"),
105
+ max_lines=OUTPUT_MAX_LINES,
106
+ max_bytes=OUTPUT_MAX_BYTES,
107
+ )
108
+ relative = relative_posix(path, cwd)
109
+ if timed_out:
110
+ return _failure(
111
+ f"format: {relative} — {build_argv(template, path)[0]} 在 "
112
+ f"{settings.timeout_seconds:g} 秒后超时,文件内容未确认",
113
+ {"path": path, "error": "timeout", "changed": changed},
114
+ )
115
+ status = "changed" if changed else "unchanged"
116
+ head = f"format: {relative} — {command} → exit {exit_code} ({duration:g}s), {status}"
117
+ text = head if not output else f"{head}\n{output}"
118
+ structured: dict[str, JsonValue] = {
119
+ "path": path,
120
+ "command": command,
121
+ "exit_code": exit_code,
122
+ "changed": changed,
123
+ "duration_seconds": duration,
124
+ }
125
+ if exit_code != 0:
126
+ return AgentToolResult(
127
+ content=[TextContent(text=text)],
128
+ details={"path": path, "changed": changed, "exit_code": exit_code},
129
+ structured_content=structured,
130
+ is_error=True,
131
+ )
132
+ return AgentToolResult(
133
+ content=[TextContent(text=text)],
134
+ details={"path": path, "changed": changed, "exit_code": exit_code},
135
+ structured_content=structured,
136
+ )
137
+
138
+ description = (
139
+ "Format one file with the project's configured formatter "
140
+ f"({settings.describe()}). Reports the command, its exit code and whether the file "
141
+ "changed. Run it after editing a file when the project has a formatter configured."
142
+ )
143
+ return AgentTool(
144
+ name="format",
145
+ label="format",
146
+ description=description,
147
+ parameters=FORMAT_PARAMETERS,
148
+ execute=execute,
149
+ )
150
+
151
+
152
+ def _digest(path: str) -> str:
153
+ with open(path, "rb") as handle:
154
+ return hashlib.sha256(handle.read()).hexdigest()
155
+
156
+
157
+ def _failure(text: str, details: dict[str, JsonValue]) -> AgentToolResult:
158
+ return AgentToolResult(
159
+ content=[TextContent(text=text)],
160
+ details=details,
161
+ is_error=True,
162
+ )
163
+
164
+
165
+ #: 系统提示词里这一行怎么介绍 ``format``。
166
+ PROMPT_SNIPPET = FORMAT_SNIPPET
167
+
168
+ #: 只有 ``format`` 可执行时才出现的规则条目。
169
+ PROMPT_GUIDELINES: tuple[str, ...] = FORMAT_GUIDELINES
170
+
171
+
172
+ __all__ = [
173
+ "FORMAT_PARAMETERS",
174
+ "OUTPUT_MAX_BYTES",
175
+ "OUTPUT_MAX_LINES",
176
+ "PROMPT_GUIDELINES",
177
+ "PROMPT_SNIPPET",
178
+ "create_format_tool",
179
+ ]
@@ -0,0 +1,105 @@
1
+ """LSP 接入:语言服务器的配置、连接、路由与 ``lsp`` 工具。
2
+
3
+ 分四层,每层只依赖下一层:
4
+
5
+ - :mod:`.settings` —— 配置文件里 ``lsp.<name>`` 的形状与路由规则(纯数据);
6
+ - :mod:`.protocol` —— ``Content-Length`` 分帧与四类失败(纯函数 + 异常);
7
+ - :mod:`.client` —— 一台服务器的进程、握手、文档同步与诊断等待;
8
+ - :mod:`.manager` —— 按扩展名路由、按根复用、失败后重启;
9
+ - :mod:`.tool` —— 模型看到的那个工具,负责格式化与错误措辞。
10
+
11
+ 导入包本身零 I/O:不探测可执行文件、不 spawn 进程。服务器在第一次调用 ``lsp`` 工具
12
+ 时才启动,因此"配置了但这次没用到"不会付出任何启动成本。
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import importlib
18
+ from typing import TYPE_CHECKING
19
+
20
+ if TYPE_CHECKING:
21
+ from braid_coding_agent.lsp.client import LspClient
22
+ from braid_coding_agent.lsp.manager import LspManager
23
+ from braid_coding_agent.lsp.model import Diagnostic, Location, Severity, Symbol
24
+ from braid_coding_agent.lsp.protocol import (
25
+ LspError,
26
+ LspProtocolError,
27
+ LspResponseError,
28
+ LspServerGone,
29
+ LspTimeout,
30
+ )
31
+ from braid_coding_agent.lsp.settings import (
32
+ DEFAULT_LSP_TIMEOUT_SECONDS,
33
+ LspServerSettings,
34
+ LspSettings,
35
+ merge_extensions,
36
+ normalize_extension,
37
+ )
38
+ from braid_coding_agent.lsp.tool import (
39
+ LSP_ACTION_NAMES,
40
+ LSP_PARAMETERS,
41
+ PROMPT_GUIDELINES,
42
+ PROMPT_SNIPPET,
43
+ create_lsp_tool,
44
+ )
45
+
46
+ #: 导出名 → 定义它的模块。只读配置时不会加载语言服务器客户端。
47
+ _LAZY_EXPORTS: dict[str, str] = {
48
+ "LspClient": "braid_coding_agent.lsp.client",
49
+ "LspManager": "braid_coding_agent.lsp.manager",
50
+ "Diagnostic": "braid_coding_agent.lsp.model",
51
+ "Location": "braid_coding_agent.lsp.model",
52
+ "Severity": "braid_coding_agent.lsp.model",
53
+ "Symbol": "braid_coding_agent.lsp.model",
54
+ "LspError": "braid_coding_agent.lsp.protocol",
55
+ "LspProtocolError": "braid_coding_agent.lsp.protocol",
56
+ "LspResponseError": "braid_coding_agent.lsp.protocol",
57
+ "LspServerGone": "braid_coding_agent.lsp.protocol",
58
+ "LspTimeout": "braid_coding_agent.lsp.protocol",
59
+ "DEFAULT_LSP_TIMEOUT_SECONDS": "braid_coding_agent.lsp.settings",
60
+ "LspServerSettings": "braid_coding_agent.lsp.settings",
61
+ "LspSettings": "braid_coding_agent.lsp.settings",
62
+ "merge_extensions": "braid_coding_agent.lsp.settings",
63
+ "normalize_extension": "braid_coding_agent.lsp.settings",
64
+ "LSP_ACTION_NAMES": "braid_coding_agent.lsp.tool",
65
+ "LSP_PARAMETERS": "braid_coding_agent.lsp.tool",
66
+ "PROMPT_GUIDELINES": "braid_coding_agent.lsp.tool",
67
+ "PROMPT_SNIPPET": "braid_coding_agent.lsp.tool",
68
+ "create_lsp_tool": "braid_coding_agent.lsp.tool",
69
+ }
70
+
71
+
72
+ def __getattr__(name: str) -> object:
73
+ """按需导入导出名。"""
74
+ module_name = _LAZY_EXPORTS.get(name)
75
+ if module_name is None:
76
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
77
+ module = importlib.import_module(module_name)
78
+ value = getattr(module, name)
79
+ globals()[name] = value
80
+ return value
81
+
82
+
83
+ __all__ = [
84
+ "DEFAULT_LSP_TIMEOUT_SECONDS",
85
+ "LSP_ACTION_NAMES",
86
+ "LSP_PARAMETERS",
87
+ "PROMPT_GUIDELINES",
88
+ "PROMPT_SNIPPET",
89
+ "Diagnostic",
90
+ "Location",
91
+ "LspClient",
92
+ "LspError",
93
+ "LspManager",
94
+ "LspProtocolError",
95
+ "LspResponseError",
96
+ "LspServerGone",
97
+ "LspServerSettings",
98
+ "LspSettings",
99
+ "LspTimeout",
100
+ "Severity",
101
+ "Symbol",
102
+ "create_lsp_tool",
103
+ "merge_extensions",
104
+ "normalize_extension",
105
+ ]