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.
- braid_coding_agent/__init__.py +13 -0
- braid_coding_agent/assembly.py +460 -0
- braid_coding_agent/cancellation.py +25 -0
- braid_coding_agent/checkpoint/__init__.py +106 -0
- braid_coding_agent/checkpoint/git.py +305 -0
- braid_coding_agent/checkpoint/settings.py +26 -0
- braid_coding_agent/checkpoint/store.py +1261 -0
- braid_coding_agent/checkpoint/workspace.py +220 -0
- braid_coding_agent/cli.py +2168 -0
- braid_coding_agent/commands/__init__.py +50 -0
- braid_coding_agent/commands/auth.py +161 -0
- braid_coding_agent/commands/config.py +180 -0
- braid_coding_agent/commands/doctor.py +511 -0
- braid_coding_agent/commands/mcp.py +928 -0
- braid_coding_agent/commands/models.py +95 -0
- braid_coding_agent/commands/setup.py +89 -0
- braid_coding_agent/commands/uninstall.py +277 -0
- braid_coding_agent/commands/upgrade.py +381 -0
- braid_coding_agent/compaction/__init__.py +174 -0
- braid_coding_agent/compaction/prepare.py +430 -0
- braid_coding_agent/compaction/summarize.py +542 -0
- braid_coding_agent/compaction/tokens.py +204 -0
- braid_coding_agent/compaction/tool_results.py +196 -0
- braid_coding_agent/compaction/utils.py +181 -0
- braid_coding_agent/config.py +2776 -0
- braid_coding_agent/config_files.py +191 -0
- braid_coding_agent/credentials.py +252 -0
- braid_coding_agent/discovery.py +415 -0
- braid_coding_agent/extensions/__init__.py +77 -0
- braid_coding_agent/extensions/api.py +480 -0
- braid_coding_agent/extensions/runner.py +553 -0
- braid_coding_agent/formatting/__init__.py +62 -0
- braid_coding_agent/formatting/settings.py +87 -0
- braid_coding_agent/formatting/tool.py +179 -0
- braid_coding_agent/lsp/__init__.py +105 -0
- braid_coding_agent/lsp/client.py +546 -0
- braid_coding_agent/lsp/manager.py +187 -0
- braid_coding_agent/lsp/model.py +316 -0
- braid_coding_agent/lsp/protocol.py +105 -0
- braid_coding_agent/lsp/settings.py +120 -0
- braid_coding_agent/lsp/tool.py +429 -0
- braid_coding_agent/mcp/__init__.py +101 -0
- braid_coding_agent/mcp/cache.py +230 -0
- braid_coding_agent/mcp/catalog.py +108 -0
- braid_coding_agent/mcp/config.py +664 -0
- braid_coding_agent/mcp/config_store.py +142 -0
- braid_coding_agent/mcp/inspector.py +85 -0
- braid_coding_agent/mcp/panel.py +254 -0
- braid_coding_agent/mcp/runtime.py +1060 -0
- braid_coding_agent/mcp/tools.py +579 -0
- braid_coding_agent/mcp/trust.py +150 -0
- braid_coding_agent/mcp/tui_panel.py +444 -0
- braid_coding_agent/messages.py +152 -0
- braid_coding_agent/models_view.py +105 -0
- braid_coding_agent/modes/__init__.py +64 -0
- braid_coding_agent/modes/json_mode.py +480 -0
- braid_coding_agent/modes/lifecycle.py +217 -0
- braid_coding_agent/modes/print_mode.py +257 -0
- braid_coding_agent/modes/repl.py +2687 -0
- braid_coding_agent/modes/repl_commands.py +263 -0
- braid_coding_agent/modes/rpc.py +953 -0
- braid_coding_agent/modes/skill_commands.py +88 -0
- braid_coding_agent/modes/tui.py +2226 -0
- braid_coding_agent/modes/tui_control.py +90 -0
- braid_coding_agent/modes/tui_model.py +1043 -0
- braid_coding_agent/modes/tui_render.py +327 -0
- braid_coding_agent/modes/tui_rich.py +751 -0
- braid_coding_agent/modes/tui_style.py +42 -0
- braid_coding_agent/modes/wire.py +81 -0
- braid_coding_agent/netsafe.py +82 -0
- braid_coding_agent/network/__init__.py +20 -0
- braid_coding_agent/network/cache.py +77 -0
- braid_coding_agent/network/fetch.py +311 -0
- braid_coding_agent/network/html_text.py +160 -0
- braid_coding_agent/network/search.py +347 -0
- braid_coding_agent/network/settings.py +103 -0
- braid_coding_agent/network/urls.py +89 -0
- braid_coding_agent/observability/__init__.py +101 -0
- braid_coding_agent/observability/audit.py +124 -0
- braid_coding_agent/observability/collector.py +314 -0
- braid_coding_agent/observability/exporter.py +74 -0
- braid_coding_agent/observability/logging_setup.py +149 -0
- braid_coding_agent/observability/redaction.py +96 -0
- braid_coding_agent/observability/settings.py +29 -0
- braid_coding_agent/observability/spans.py +239 -0
- braid_coding_agent/permissions/__init__.py +185 -0
- braid_coding_agent/permissions/command.py +586 -0
- braid_coding_agent/permissions/engine.py +522 -0
- braid_coding_agent/permissions/evaluate.py +309 -0
- braid_coding_agent/permissions/matching.py +233 -0
- braid_coding_agent/permissions/model.py +278 -0
- braid_coding_agent/permissions/policy.py +99 -0
- braid_coding_agent/permissions/readonly.py +236 -0
- braid_coding_agent/permissions/store.py +379 -0
- braid_coding_agent/project_init.py +313 -0
- braid_coding_agent/prompt/__init__.py +98 -0
- braid_coding_agent/prompt/context_files.py +253 -0
- braid_coding_agent/prompt/project_context.py +172 -0
- braid_coding_agent/prompt/system_prompt.py +378 -0
- braid_coding_agent/questions.py +71 -0
- braid_coding_agent/render/__init__.py +56 -0
- braid_coding_agent/render/batch.py +66 -0
- braid_coding_agent/render/history.py +143 -0
- braid_coding_agent/render/stream.py +823 -0
- braid_coding_agent/render/theme.py +243 -0
- braid_coding_agent/sandbox/__init__.py +89 -0
- braid_coding_agent/sandbox/backend.py +184 -0
- braid_coding_agent/sandbox/bubblewrap.py +96 -0
- braid_coding_agent/sandbox/operations.py +301 -0
- braid_coding_agent/sandbox/policy.py +221 -0
- braid_coding_agent/sandbox/proxy.py +320 -0
- braid_coding_agent/sandbox/seatbelt.py +222 -0
- braid_coding_agent/sdk/__init__.py +31 -0
- braid_coding_agent/sdk/async_client.py +366 -0
- braid_coding_agent/sdk/client.py +386 -0
- braid_coding_agent/sdk/errors.py +52 -0
- braid_coding_agent/sdk/events.py +162 -0
- braid_coding_agent/sdk/types.py +63 -0
- braid_coding_agent/sdk/wire.py +59 -0
- braid_coding_agent/server/__init__.py +54 -0
- braid_coding_agent/server/errors.py +52 -0
- braid_coding_agent/server/http_server.py +419 -0
- braid_coding_agent/server/hub.py +530 -0
- braid_coding_agent/server/openapi.py +157 -0
- braid_coding_agent/server/registry.py +354 -0
- braid_coding_agent/server/router.py +275 -0
- braid_coding_agent/server/run.py +148 -0
- braid_coding_agent/server/schema.py +194 -0
- braid_coding_agent/server/service.py +975 -0
- braid_coding_agent/session/__init__.py +293 -0
- braid_coding_agent/session/agent_session.py +2706 -0
- braid_coding_agent/session/context_breakdown.py +302 -0
- braid_coding_agent/session/discovery.py +212 -0
- braid_coding_agent/session/entries.py +809 -0
- braid_coding_agent/session/evidence.py +295 -0
- braid_coding_agent/session/lock.py +176 -0
- braid_coding_agent/session/manager.py +1185 -0
- braid_coding_agent/session/plan.py +243 -0
- braid_coding_agent/session/plan_mode.py +423 -0
- braid_coding_agent/session/projection.py +262 -0
- braid_coding_agent/session/rewind.py +257 -0
- braid_coding_agent/session/status.py +240 -0
- braid_coding_agent/settings.py +94 -0
- braid_coding_agent/skills/__init__.py +70 -0
- braid_coding_agent/skills/loader.py +681 -0
- braid_coding_agent/startup/__init__.py +76 -0
- braid_coding_agent/startup/cache.py +72 -0
- braid_coding_agent/startup/diagnostics.py +37 -0
- braid_coding_agent/startup/monitor.py +245 -0
- braid_coding_agent/startup/phases.py +79 -0
- braid_coding_agent/startup/project.py +165 -0
- braid_coding_agent/startup/report.py +560 -0
- braid_coding_agent/startup/scheduler.py +347 -0
- braid_coding_agent/statusline.py +163 -0
- braid_coding_agent/subagents/__init__.py +22 -0
- braid_coding_agent/subagents/contract.py +75 -0
- braid_coding_agent/subagents/definitions.py +583 -0
- braid_coding_agent/subagents/registry.py +277 -0
- braid_coding_agent/subagents/runtime.py +610 -0
- braid_coding_agent/subagents/settings.py +156 -0
- braid_coding_agent/subagents/worktree.py +63 -0
- braid_coding_agent/tools/__init__.py +327 -0
- braid_coding_agent/tools/args.py +87 -0
- braid_coding_agent/tools/bash.py +359 -0
- braid_coding_agent/tools/edit.py +298 -0
- braid_coding_agent/tools/edit_diff.py +344 -0
- braid_coding_agent/tools/find.py +158 -0
- braid_coding_agent/tools/grep.py +305 -0
- braid_coding_agent/tools/ignore.py +198 -0
- braid_coding_agent/tools/ls.py +127 -0
- braid_coding_agent/tools/mutation_queue.py +90 -0
- braid_coding_agent/tools/operations.py +274 -0
- braid_coding_agent/tools/output_accumulator.py +282 -0
- braid_coding_agent/tools/output_store.py +244 -0
- braid_coding_agent/tools/path_utils.py +91 -0
- braid_coding_agent/tools/plan.py +141 -0
- braid_coding_agent/tools/prompt_notes.py +52 -0
- braid_coding_agent/tools/question.py +180 -0
- braid_coding_agent/tools/read.py +223 -0
- braid_coding_agent/tools/submit_plan.py +102 -0
- braid_coding_agent/tools/truncate.py +423 -0
- braid_coding_agent/tools/write.py +100 -0
- braid_coding_agent/untrusted.py +50 -0
- braid_coding_agent/verify/__init__.py +78 -0
- braid_coding_agent/verify/runner.py +260 -0
- braid_coding_agent/verify/settings.py +64 -0
- braid_coding_agent/verify/tool.py +143 -0
- braid_coding_agent-0.1.0.dist-info/METADATA +19 -0
- braid_coding_agent-0.1.0.dist-info/RECORD +192 -0
- braid_coding_agent-0.1.0.dist-info/WHEEL +4 -0
- braid_coding_agent-0.1.0.dist-info/entry_points.txt +3 -0
- braid_coding_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"""TUI 的表现计划层:把只读快照翻成与终端无关的内容块。
|
|
2
|
+
|
|
3
|
+
这一层不导入 Rich,也不导入 prompt_toolkit:它只决定"显示哪些内容、每块属于
|
|
4
|
+
什么语义"。Rich 的具体渲染在 :mod:`tui_rich`,按键与布局在 :mod:`tui`。换成
|
|
5
|
+
Web 前端时,这一层可以原样复用。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import TYPE_CHECKING, Literal
|
|
12
|
+
|
|
13
|
+
from .tui_model import CompletionItem, StatusView, TuiSnapshot
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from braid_coding_agent.mcp.tui_panel import McpPanelView
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ActivityView",
|
|
20
|
+
"BlockKind",
|
|
21
|
+
"PromptView",
|
|
22
|
+
"RenderBlock",
|
|
23
|
+
"TuiRenderState",
|
|
24
|
+
"activity_block",
|
|
25
|
+
"format_elapsed",
|
|
26
|
+
"overlay_blocks",
|
|
27
|
+
"plan_block",
|
|
28
|
+
"status_block",
|
|
29
|
+
"transcript_blocks",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
type BlockKind = Literal[
|
|
33
|
+
"banner",
|
|
34
|
+
"user",
|
|
35
|
+
"thinking",
|
|
36
|
+
"tool",
|
|
37
|
+
"result",
|
|
38
|
+
"answer",
|
|
39
|
+
"notice",
|
|
40
|
+
"plain",
|
|
41
|
+
"diff",
|
|
42
|
+
"plan",
|
|
43
|
+
"status",
|
|
44
|
+
"activity",
|
|
45
|
+
"completion",
|
|
46
|
+
"select",
|
|
47
|
+
"rewind",
|
|
48
|
+
"prompt",
|
|
49
|
+
"mcp",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass(slots=True, frozen=True)
|
|
54
|
+
class RenderBlock:
|
|
55
|
+
"""一块待渲染的内容。
|
|
56
|
+
|
|
57
|
+
每个 ``kind`` 只使用其中一部分字段,含义由渲染层解释:
|
|
58
|
+
|
|
59
|
+
- ``lines``:多行内容(会话记录段落、计划步骤、横幅、候选、选项)
|
|
60
|
+
- ``selected``:高亮项下标;``checked``:多选项下标;``multiple``:是否多选
|
|
61
|
+
- ``completed`` / ``total``:进度;``revision``:计划版本
|
|
62
|
+
- ``state``:工具状态;``duration_ms``:工具耗时
|
|
63
|
+
- ``view``:结构化状态栏
|
|
64
|
+
|
|
65
|
+
所有字段可哈希,渲染层可以把它当作缓存键。
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
kind: BlockKind
|
|
69
|
+
text: str = ""
|
|
70
|
+
label: str = ""
|
|
71
|
+
detail: str = ""
|
|
72
|
+
level: str = "muted"
|
|
73
|
+
state: str = ""
|
|
74
|
+
duration_ms: int | None = None
|
|
75
|
+
lines: tuple[str, ...] = ()
|
|
76
|
+
options: tuple[str, ...] = ()
|
|
77
|
+
selected: int = 0
|
|
78
|
+
checked: tuple[int, ...] = ()
|
|
79
|
+
multiple: bool = False
|
|
80
|
+
completed: int = 0
|
|
81
|
+
total: int = 0
|
|
82
|
+
revision: int = 0
|
|
83
|
+
current: str = ""
|
|
84
|
+
view: StatusView | None = None
|
|
85
|
+
#: 计划面板的实施计划正文(Markdown 原文)与它的版本号。``lines`` 是执行步骤表。
|
|
86
|
+
document: str = ""
|
|
87
|
+
document_revision: int = 0
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(slots=True, frozen=True)
|
|
91
|
+
class PromptView:
|
|
92
|
+
"""浮层里的审批或提问。
|
|
93
|
+
|
|
94
|
+
``options`` 是可见选项的标签,``selected`` 是高亮项,``checked`` 是多选已选
|
|
95
|
+
项。``hint`` 写明可用按键。
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
kind: Literal["approval", "question"]
|
|
99
|
+
title: str
|
|
100
|
+
lines: tuple[str, ...]
|
|
101
|
+
options: tuple[str, ...] = ()
|
|
102
|
+
selected: int = 0
|
|
103
|
+
checked: tuple[int, ...] = ()
|
|
104
|
+
multiple: bool = False
|
|
105
|
+
hint: str = ""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@dataclass(slots=True, frozen=True)
|
|
109
|
+
class ActivityView:
|
|
110
|
+
"""执行中的活动标识:spinner 帧、阶段文案与已用时间。"""
|
|
111
|
+
|
|
112
|
+
frame: str
|
|
113
|
+
label: str
|
|
114
|
+
elapsed_seconds: float
|
|
115
|
+
hint: str = "Ctrl+C 中断"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def format_elapsed(seconds: float) -> str:
|
|
119
|
+
"""紧凑耗时:47s / 4m 07s / 1h 02m。"""
|
|
120
|
+
total = max(0, int(seconds))
|
|
121
|
+
if total < 60:
|
|
122
|
+
return f"{total}s"
|
|
123
|
+
minutes, secs = divmod(total, 60)
|
|
124
|
+
if minutes < 60:
|
|
125
|
+
return f"{minutes}m {secs:02d}s"
|
|
126
|
+
hours, minutes = divmod(minutes, 60)
|
|
127
|
+
return f"{hours}h {minutes:02d}m"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@dataclass(slots=True, frozen=True)
|
|
131
|
+
class TuiRenderState:
|
|
132
|
+
"""快照以外的界面状态:浮层、补全过程与终端颜色能力。"""
|
|
133
|
+
|
|
134
|
+
color: bool = False
|
|
135
|
+
overlay: str | None = None
|
|
136
|
+
completion: tuple[CompletionItem, ...] = ()
|
|
137
|
+
completion_selected: int = 0
|
|
138
|
+
#: 浮层最多显示的候选行数;选中项用居中窗口保证始终可见。
|
|
139
|
+
completion_capacity: int = 6
|
|
140
|
+
model_options: tuple[str, ...] = ()
|
|
141
|
+
session_options: tuple[str, ...] = ()
|
|
142
|
+
#: 回退清单的候选行与窗口容量。选中项居中,超过容量时只显示附近几条。
|
|
143
|
+
rewind_options: tuple[str, ...] = ()
|
|
144
|
+
rewind_capacity: int = 8
|
|
145
|
+
#: 选择浮层(模型 / 会话)的高亮项与当前值。
|
|
146
|
+
selection_selected: int = 0
|
|
147
|
+
selection_current: str = ""
|
|
148
|
+
notice: str = ""
|
|
149
|
+
#: 审批 / 提问浮层;非空时优先于补全与选择框显示。
|
|
150
|
+
prompt: PromptView | None = None
|
|
151
|
+
#: MCP 管理面板的当前一帧;``overlay == "mcp"`` 时使用。
|
|
152
|
+
mcp: McpPanelView | None = None
|
|
153
|
+
#: 启动横幅(版本、模型、快捷键),只在会话开始时的记录顶部出现。
|
|
154
|
+
banner: tuple[str, ...] = ()
|
|
155
|
+
#: 正在执行任务的标识;空闲时为 ``None``,对应的一行不占高度。
|
|
156
|
+
activity: ActivityView | None = None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def transcript_blocks(
|
|
160
|
+
snapshot: TuiSnapshot, *, banner: tuple[str, ...] = ()
|
|
161
|
+
) -> tuple[RenderBlock, ...]:
|
|
162
|
+
"""可滚动会话记录的内容块,按时间顺序。
|
|
163
|
+
|
|
164
|
+
工具条目按 ``call_id`` 关联到工具卡,展开状态与耗时才能显示在同一行;
|
|
165
|
+
找不到卡片的条目(例如历史会话回放)按纯文本渲染。思考条目带展开状态,
|
|
166
|
+
``Ctrl+T`` 只作用于最近的一条,历史思考保持折叠。
|
|
167
|
+
"""
|
|
168
|
+
blocks: list[RenderBlock] = []
|
|
169
|
+
if banner:
|
|
170
|
+
blocks.append(RenderBlock(kind="banner", lines=banner))
|
|
171
|
+
cards = {card.call_id: card for card in snapshot.tool_cards}
|
|
172
|
+
last_thinking = -1
|
|
173
|
+
for index, entry in enumerate(snapshot.transcript):
|
|
174
|
+
if entry.kind == "thinking":
|
|
175
|
+
last_thinking = index
|
|
176
|
+
for index, entry in enumerate(snapshot.transcript):
|
|
177
|
+
if entry.kind == "thinking":
|
|
178
|
+
expanded = snapshot.thinking_expanded and index == last_thinking
|
|
179
|
+
blocks.append(
|
|
180
|
+
RenderBlock(
|
|
181
|
+
kind="thinking",
|
|
182
|
+
text=entry.text,
|
|
183
|
+
state="expanded" if expanded else "collapsed",
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
continue
|
|
187
|
+
if entry.kind == "tool" and entry.detail in cards:
|
|
188
|
+
card = cards[entry.detail]
|
|
189
|
+
blocks.append(
|
|
190
|
+
RenderBlock(
|
|
191
|
+
kind="tool",
|
|
192
|
+
text=entry.text,
|
|
193
|
+
label=card.label,
|
|
194
|
+
state=card.status,
|
|
195
|
+
duration_ms=card.duration_ms,
|
|
196
|
+
detail=card.detail,
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
continue
|
|
200
|
+
blocks.append(
|
|
201
|
+
RenderBlock(
|
|
202
|
+
kind=entry.kind,
|
|
203
|
+
text=entry.text,
|
|
204
|
+
# 只有 diff 的 detail 是给人看的摘要;工具与结果的 detail 是
|
|
205
|
+
# call_id,属于关联键,不能当正文渲染。
|
|
206
|
+
detail=entry.detail if entry.kind == "diff" else "",
|
|
207
|
+
level=entry.level,
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
return tuple(blocks)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def plan_block(snapshot: TuiSnapshot) -> RenderBlock | None:
|
|
214
|
+
plan = snapshot.plan
|
|
215
|
+
if plan is None:
|
|
216
|
+
return None
|
|
217
|
+
return RenderBlock(
|
|
218
|
+
kind="plan",
|
|
219
|
+
lines=plan.lines,
|
|
220
|
+
completed=plan.completed,
|
|
221
|
+
total=plan.total,
|
|
222
|
+
revision=plan.revision,
|
|
223
|
+
label=plan.mode,
|
|
224
|
+
document="\n".join(plan.document),
|
|
225
|
+
document_revision=plan.document_revision,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def status_block(snapshot: TuiSnapshot) -> RenderBlock:
|
|
230
|
+
view = snapshot.status_view
|
|
231
|
+
return RenderBlock(kind="status", text=snapshot.status, view=view)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def activity_block(view: ActivityView) -> RenderBlock:
|
|
235
|
+
"""执行中的那一行:spinner、阶段、耗时与中断提示。"""
|
|
236
|
+
return RenderBlock(
|
|
237
|
+
kind="activity",
|
|
238
|
+
state=view.frame,
|
|
239
|
+
label=view.label,
|
|
240
|
+
text=format_elapsed(view.elapsed_seconds),
|
|
241
|
+
detail=view.hint,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def overlay_blocks(state: TuiRenderState) -> tuple[RenderBlock, ...]:
|
|
246
|
+
"""浮层内容:审批 / 提问优先,其次是 MCP 面板、模型、会话、回退与补全。"""
|
|
247
|
+
if state.prompt is not None:
|
|
248
|
+
prompt = state.prompt
|
|
249
|
+
return (
|
|
250
|
+
RenderBlock(
|
|
251
|
+
kind="prompt",
|
|
252
|
+
label=prompt.title,
|
|
253
|
+
lines=prompt.lines,
|
|
254
|
+
detail=prompt.hint,
|
|
255
|
+
options=prompt.options,
|
|
256
|
+
selected=prompt.selected,
|
|
257
|
+
checked=prompt.checked,
|
|
258
|
+
multiple=prompt.multiple,
|
|
259
|
+
),
|
|
260
|
+
)
|
|
261
|
+
if state.overlay == "mcp" and state.mcp is not None:
|
|
262
|
+
panel = state.mcp
|
|
263
|
+
return (
|
|
264
|
+
RenderBlock(
|
|
265
|
+
kind="mcp",
|
|
266
|
+
label=panel.title,
|
|
267
|
+
lines=panel.lines,
|
|
268
|
+
selected=panel.selected,
|
|
269
|
+
detail=panel.hint,
|
|
270
|
+
text=panel.message,
|
|
271
|
+
),
|
|
272
|
+
)
|
|
273
|
+
if state.overlay == "models":
|
|
274
|
+
return (
|
|
275
|
+
RenderBlock(
|
|
276
|
+
kind="select",
|
|
277
|
+
label="选择模型",
|
|
278
|
+
detail="↑↓ 选择 · Enter 确认 · Esc 取消",
|
|
279
|
+
lines=state.model_options,
|
|
280
|
+
selected=state.selection_selected,
|
|
281
|
+
current=state.selection_current,
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
if state.overlay == "sessions":
|
|
285
|
+
return (
|
|
286
|
+
RenderBlock(
|
|
287
|
+
kind="select",
|
|
288
|
+
label="选择会话",
|
|
289
|
+
detail="↑↓ 选择 · Enter 确认 · Esc 取消",
|
|
290
|
+
lines=state.session_options,
|
|
291
|
+
selected=state.selection_selected,
|
|
292
|
+
current=state.selection_current,
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
if state.overlay == "rewind":
|
|
296
|
+
capacity = max(1, state.rewind_capacity)
|
|
297
|
+
total = len(state.rewind_options)
|
|
298
|
+
start = state.selection_selected - capacity // 2
|
|
299
|
+
start = max(0, min(start, max(0, total - capacity)))
|
|
300
|
+
window = state.rewind_options[start : start + capacity]
|
|
301
|
+
return (
|
|
302
|
+
RenderBlock(
|
|
303
|
+
kind="rewind",
|
|
304
|
+
label="回退到哪一轮提问",
|
|
305
|
+
detail=f"↑↓ 选择 · Enter 确认 · Esc 取消 · 共 {total} 轮",
|
|
306
|
+
lines=window,
|
|
307
|
+
selected=state.selection_selected - start,
|
|
308
|
+
),
|
|
309
|
+
)
|
|
310
|
+
if state.completion:
|
|
311
|
+
capacity = max(1, state.completion_capacity)
|
|
312
|
+
total = len(state.completion)
|
|
313
|
+
start = state.completion_selected - capacity // 2
|
|
314
|
+
start = max(0, min(start, max(0, total - capacity)))
|
|
315
|
+
window = state.completion[start : start + capacity]
|
|
316
|
+
return (
|
|
317
|
+
RenderBlock(
|
|
318
|
+
kind="completion",
|
|
319
|
+
label="命令补全",
|
|
320
|
+
detail="Tab 接受 · ↑↓ 选择 · Esc 关闭",
|
|
321
|
+
lines=tuple(f"{item.usage} — {item.summary}" for item in window),
|
|
322
|
+
selected=state.completion_selected - start,
|
|
323
|
+
),
|
|
324
|
+
)
|
|
325
|
+
if state.notice:
|
|
326
|
+
return (RenderBlock(kind="notice", text=state.notice),)
|
|
327
|
+
return ()
|