05.2 REPL 与屏幕组合
关注源码
src/replLauncher.tsxsrc/components/App.tsxsrc/screens/REPL.tsx
REPL.tsx 是前台运行时外壳
这一个文件本身就反映了产品形态:它不是简单聊天框,而是一个把多种能力编排到一起的控制台。
在 REPL.tsx 中汇合的能力包括:
- query loop
- 消息列表与 transcript 搜索
- PromptInput
- permissions / elicitation / prompt dialog
- MCP 连接管理
- IDE 集成
- 远端会话
- teammate / task 面板
- prompt suggestion / speculation
- notification / survey / updater / onboarding
层次结构
replLauncher.tsx
只做一件事:懒加载 App 和 REPL,然后交给 renderAndRun()。
components/App.tsx
负责最外层 provider 装配:
FpsMetricsProviderStatsProviderAppStateProvider
screens/REPL.tsx
负责真实的页面级编排和 hook 聚合。
为什么 REPL.tsx 会这么大
因为它承载的是“产品壳层”而不是单一页面组件。这里要同时协调:
- 输入
- 渲染
- query 生命周期
- 任务导航
- 远端模式
- IDE / bridge / sandbox
也就是说,它更接近 application shell。
这层与核心运行时的关系
REPL.tsx 不实现底层 agent 能力,但负责把下面这些东西穿起来:
messagesToolUseContextAppStatequery()tasks- 各类 notifications/dialogs
如果说 query.ts 是 agent runtime 内核,那么 REPL.tsx 就是交互式操作系统外壳。
设计上的关键点
1. REPL 只组合,不重写底层能力
它主要通过 hooks、contexts、services 来拿能力,而不是在页面里复制实现。
2. provider 层次很薄,壳层很厚
components/App.tsx 很薄,真正复杂度集中在 REPL.tsx。这说明团队刻意把“状态提供”和“业务编排”分开。
3. TUI 是运行时视图,不是附属展示
任务、权限、远端桥接、MCP、speculation 都是第一类 UI 对象,而不是后加的弹窗。