knowledge-interaction-surfaces-terminal-ui
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "knowledge-interaction-surfaces-terminal-ui" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-d5eface3ea19282ab2eb20ea4a8cc86e3028077ac48a49a78a3a59ec1fdec7e0. Verify the upstream source and version against https://github.com/echoVic/blade-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Covers Blade’s React + Ink terminal UI: initialization, input protocol, message and tool rendering, confirmation queue, session switching, streaming buffering, and runtime cleanup. Trigger scenarios: changing terminal keyboard behavior, paste, Ctrl+C, approvals and Q&A, streaming output, Static layout, session restoration, or slash command display. Excludes headless/print output and Web React state. Keywords: AppWrapper, BladeInterface, MessageArea, useCommandHandler, useAgent, useConfirmation, parseTerminalInput, Static, rawStreamRenderer.
Introduction source: third_party · echoVic · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: knowledge-interaction-surfaces-terminal-ui
description: >
覆盖 Blade React + Ink TUI 的初始化、输入协议、消息与工具渲染、确认队列、Session
切换、流式缓冲和 Runtime 清理。进入时机:修改终端键盘行为、粘贴、Ctrl+C、审批与
问答、流式输出、Static 布局、会话恢复或 slash command 展示。 不包含:Headless/Print
输出(见 ../cli-bootstrap-headless-and-print/)、Web React 状态(见 ../web-client/)。
关键词:AppWrapper, BladeInterface, MessageArea, useCommandHandler, useAgent,
useConfirmation, parseTerminalInput, Static, rawStreamRenderer。Module Structure
TUI 以单个 vanilla Zustand Store 投影当前 Session,React Hook 只持有活动 Agent/Runtime 和输入交互生命周期;durable 消息、权限模式与恢复数据仍由 Session 服务管理。
Directory Layout
packages/cli/src/ui/App.tsx— 版本提示、Workspace Trust、资源与 Hook 初始化packages/cli/src/ui/components/BladeInterface.tsx— 主界面、阻塞弹窗与 Session 启动路由packages/cli/src/ui/components/MessageArea.tsx— 单 Static 根、流式块和 raw tail 渲染packages/cli/src/ui/components/— 输入、确认、问答、状态和工具展示组件packages/cli/src/ui/hooks/— Agent、命令、输入、确认、Ctrl+C 与缓冲生命周期packages/cli/src/ui/input/terminalInput.ts— bracketed paste 与终端控制序列解析packages/cli/src/ui/utils/— LoopEvent 投影、Session 激活、Markdown 和工具格式化packages/cli/src/store/— React 与非 React 代码共享的当前进程状态packages/cli/src/slash-commands/— TUI 内置与自定义命令路由
Key Entry Points
AppWrapperinpackages/cli/src/ui/App.tsx— 完成信任判断后挂载主界面BladeInterfaceinpackages/cli/src/ui/components/BladeInterface.tsx— 组合输入、弹窗、消息与状态区useCommandHandler()inpackages/cli/src/ui/hooks/useCommandHandler.ts— 单轮命令、取消和恢复编排useAgent()inpackages/cli/src/ui/hooks/useAgent.ts— Agent/SessionRuntime 的唯一 React 所有者createLoopEventHandler()inpackages/cli/src/ui/utils/loopEventHandler.ts— LoopEvent 到 TUI Store 的投影
Gotchas
- 取消顺序不可交换:先
dismissAll()释放阻塞审批,再排空流式缓冲,再 abort,最后 finalize;先 abort 会把审批拒绝误判为普通 permission denial,晚到stream_end还可能重复提交 (packages/cli/src/ui/hooks/useCommandHandler.ts,packages/cli/src/ui/hooks/useConfirmation.ts) createAbortController()会主动中止并替换已有 controller;命令下层必须复用外层 controller,否则 finally 的所有权检查失败并让isProcessing永久卡住 (packages/cli/src/ui/hooks/useCommandHandler.ts,packages/cli/src/store/slices/commandSlice.ts)MessageArea只能有一个 InkStatic根;条件挂载第二个 Static 曾让 Ink 保留已释放 Yoga 节点并在后续 commit 崩溃 (packages/cli/src/ui/components/MessageArea.tsx,docs/testing/tui-single-static-root-ownership-evidence.md,git:c68977b7)- 高频 Markdown tail 绕过 React 直接写 stdout;在 Static 增长、finalize、清屏、resize 或历史展开前必须先清理 raw renderer,否则终端会残留或错位 (
packages/cli/src/ui/components/MessageArea.tsx,packages/cli/src/ui/utils/rawStreamRenderer.ts) clearCount是 Static 的唯一强制重挂边界,finalize 时还必须先eraseScreen + cursorTo(0,0);仅清屏不归位会在顶部留下大段空白 (packages/cli/src/ui/components/MessageArea.tsx)- 一次 stdin 回调可能是完整 IME 文本或批量自动化输入,不能逐字符假设;bracketed paste marker 还可能被 Ink 去掉 ESC 或跨 chunk 到达 (
packages/cli/src/ui/input/terminalInput.ts,docs/reference/tui-terminal-input.md) - 未闭合 paste 会留在 parser buffer,超过消息字符预算后一直丢弃到 end marker;不要把半段 paste 当普通输入提交 (
packages/cli/src/ui/input/terminalInput.ts) - 第一次 Ctrl+C 在执行中只取消任务并显示二次退出提示,3 秒内第二次才走 GracefulShutdown;直接恢复 Ink 的默认
exitOnCtrlC会跳过资源释放 (packages/cli/src/ui/hooks/useCtrlCHandler.ts,packages/cli/src/blade.tsx) - Session 激活必须先完成 fork/load 和 UI-safe 转换,再
cleanupAgent(),最后一次性恢复新 Store;清理失败时不能提前切换界面身份 (packages/cli/src/ui/utils/sessionActivation.ts) - fork 提示是 UI-only assistant message,不进入恢复的 model context;把 visible messages 重建为上下文会污染后续模型输入 (
packages/cli/src/ui/utils/sessionActivation.ts,packages/cli/src/ui/utils/sessionContext.ts) - 阻塞弹窗通过
display="none"隐藏主界面而不卸载,目的是保留 Static 和输入状态;改成条件卸载会重复打印历史并丢失输入组件状态 (packages/cli/src/ui/components/BladeInterface.tsx)
Architecture
AppWrapper先处理版本提示和 Workspace Trust,再解析可信资源与 Hooks;选择“安全继续”只跳过信任授予,不跳过应用初始化 (packages/cli/src/ui/App.tsx)useAgent同时拥有 Agent 和 SessionRuntime 引用;Session ID 或 workspace 改变时先幂等销毁旧 Agent,再 dispose 整个 Runtime 边界 (packages/cli/src/ui/hooks/useAgent.ts,git:959149a8)- TUI Store 不做持久化:会话写入 JSONL、配置写入 ConfigService;Store 只保存当前进程投影和渲染缓冲 (
packages/cli/src/store/vanilla.ts) createLoopEventHandler为每轮创建闭包,以streamFinalized隔离 abort、fallback 和正常stream_end;跨轮复用 handler 会让上一轮终态污染下一轮 (packages/cli/src/ui/utils/loopEventHandler.ts)- 流式内容有 Hook 层批缓冲、Store 外模块级 chunks、Markdown 增量缓存和 raw tail 四层状态,正常结束与取消都必须按所有权逐层排空或丢弃 (
packages/cli/src/ui/hooks/useStreamingBuffer.ts,packages/cli/src/store/slices/sessionSlice.ts,packages/cli/src/ui/utils/markdownIncremental.ts) - Confirmation Hook 把请求串成单活动项队列,并为每项绑定 AbortSignal;工具执行并不直接依赖某个具体 Ink 组件 (
packages/cli/src/ui/hooks/useConfirmation.ts)
Decisions
- React 与 Agent/工具共享 vanilla Zustand 实例,但只暴露 actions 和 selectors,以避免非 React 路径另建状态源 (
packages/cli/src/store/vanilla.ts,packages/cli/src/store/selectors/index.ts) - 已完成历史使用 Ink Static,最高频 tail 使用 raw renderer,是为兼顾原生 scrollback 与流式性能;这两条路径通过 message ID 和 finalize 标记去重 (
packages/cli/src/ui/components/MessageArea.tsx) - TUI 启用 bracketed paste 并显式关闭 focus reporting,退出时重复恢复终端模式,避免异常关闭把宿主 shell 留在特殊输入状态 (
packages/cli/src/ui/hooks/useTerminalInputModes.ts,docs/reference/tui-terminal-input.md)
Patterns
- Session 级模型、reasoning、service tier、verbosity 和 communication style 都先刷新 Runtime、再持久化 metadata;持久化失败会回滚 Runtime,避免界面与重启状态分叉 (
packages/cli/src/ui/hooks/useAgent.ts) - 恢复 Session 时同时保存 UI-safe messages 与原始 model context,后续只把恢复边界后的新 UI 消息追加到原始上下文 (
packages/cli/src/store/slices/sessionSlice.ts,packages/cli/src/ui/utils/sessionContext.ts) - 用户输入在 slash command、Hook 改写和 Agent 输入之间保留不同表示:Hook 可改写模型输入,但不能回写已经提交的用户可见消息 (
packages/cli/src/ui/hooks/useCommandHandler.ts) - 工具进度、Provider 恢复和 MCP 事件通过统一 LoopEvent handler 投影;新增事件必须保持 exhaustive switch,并避免把结构化输出保留工具渲染成普通工具卡 (
packages/cli/src/ui/utils/loopEventHandler.ts) - 主题、权限、Session 选择等弹窗共享焦点状态,主输入仅在没有阻塞弹窗时接管键盘;组件自己的
useInput必须检查对应 FocusId (packages/cli/src/ui/components/BladeInterface.tsx,packages/cli/src/ui/components/ConfirmationPrompt.tsx)
Dependencies
- TUI 使用 React、Ink、Yoga 与 Zustand;
ink-text-input只处理编辑行为,终端 framing 和批量输入由项目自己的 parser 补齐 (packages/cli/src/ui/components/CustomTextInput.tsx,packages/cli/src/ui/input/terminalInput.ts)
Version history
-
v0.11.23
GitHub ↗
Original release notes
**Full Changelog**: https://github.com/echoVic/blade-code/compare/v0.11.22...v0.11.23
-
v0.11.22
GitHub ↗
Original release notes
**Full Changelog**: https://github.com/echoVic/blade-code/compare/v0.11.21...v0.11.22
-
v0.11.21
GitHub ↗
Original release notes
**Full Changelog**: https://github.com/echoVic/blade-code/compare/v0.11.20...v0.11.21
-
v0.11.20
GitHub ↗
Original release notes
**Full Changelog**: https://github.com/echoVic/blade-code/compare/v0.11.19...v0.11.20
-
v0.11.19
GitHub ↗
Original release notes
**Full Changelog**: https://github.com/echoVic/blade-code/compare/v0.11.18...v0.11.19
Only the five most recent versions are shown. View full version history at the source ↗
Current listing version
0.0.1
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 Blade React + Ink TUI 的完整实现架构文档
- 包含关键避坑指南和实现约束
Highlights
- 触发词覆盖全面,包含多种终端交互场景
- 边界定义清晰,明确排除不相关领域
Areas to improve
-
缺少 When to Use 显式章节 Reported severity: Minor
虽有进入时机描述但未独立成节
Recommendation: 建议增加独立的 When to Use 章节以提升可读性
Highlights
- 结构层次清晰,涵盖架构、决策、模式等关键维度
- 引用具体文件路径和代码提交,增强可信度
Highlights
- 详细描述错误处理顺序和资源清理机制
- 覆盖高频异常场景如未闭合 paste 和 Static 根冲突
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.