@x-otto/tui 0.0.1-alpha.0

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.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # @x-otto/tui
2
+
3
+ ## 模块定位
4
+
5
+ 终端 UI 应用层:基于 React + Ink 的组件树,提供流式 Markdown 渲染、权限弹窗、输入栈、消息流等完整的终端交互体验。对接 npm `ink` v7 渲染引擎与 `@x-otto/keybindings` 按键系统。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @x-otto/tui
11
+ ```
12
+
13
+ ## 快速开始
14
+
15
+ ```ts
16
+ import { startTui } from '@x-otto/tui'
17
+
18
+ const tui = await startTui({
19
+ stdin: process.stdin,
20
+ stdout: process.stdout,
21
+ onMessage: async (msg) => { /* 发送到 agent */ },
22
+ })
23
+
24
+ tui.pushMessage({ role: 'assistant', content: 'Hello! I am otto.' })
25
+ tui.showToast('Task completed')
26
+
27
+ await tui.dispose()
28
+ ```
29
+
30
+ ## 核心功能
31
+
32
+ | 模块 | 功能 |
33
+ | --------------- | ------------------------------------------------------- |
34
+ | Store | 应用状态管理(zustand 驱动,useAppState / createStore) |
35
+ | Input | 输入栈:Cursor 模型 + InputBuffer + History + Typeahead |
36
+ | Messages | 消息流:StreamState + QueryGuard + Collapse + Diff |
37
+ | Dialogs | 对话框仲裁:权限队列 + Select 状态机 + 弹窗组件 |
38
+ | Components | 通用组件:App / Welcome / StatusBar / Spinner / Button / DataList |
39
+ | Term | 终端原语:BracketedPaste / OSC 8/52 / SyncFrame |
40
+ | Theme | 调色板 + 图标字符 + Spinner 帧 + 主题预设注册表 |
41
+ | i18n | 国际化(i18next + react-i18next,中/英文) |
42
+ | startTui | 生产入口:从 stdin/WebSocket 启动 TUI 主循环 |
43
+ | printMessages | 非交互 print 模式(向后兼容) |
44
+
45
+ ## 输入栈
46
+
47
+ | 组件 | 功能 |
48
+ | ------------------ | ----------------------------- |
49
+ | BaseTextInput | 基础文本输入(光标/编辑/粘贴)|
50
+ | PromptInput | 主提示输入框 |
51
+ | PromptInputFooter | 输入框底部状态栏 |
52
+ | HistorySearchInput | 历史搜索输入 |
53
+ | QueuedCommands | 排队命令显示 |
54
+
55
+ ## 消息渲染
56
+
57
+ | 组件 | 功能 |
58
+ | ------------------ | ----------------------------- |
59
+ | Message | 消息容器(角色/折叠/分支) |
60
+ | Markdown | Markdown 静态渲染 |
61
+ | StreamingMarkdown | Markdown 流式渲染(防闪) |
62
+ | StructuredDiff | 结构化 diff 渲染 |
63
+ | HighlightedCode | 语法高亮代码块 |
64
+ | ToolUseLoader | 工具调用加载动画 |
65
+ | REPLRegion | REPL 消息区域容器 |
66
+
67
+ ## 目录概览
68
+
69
+ ```
70
+ src/
71
+ types.ts # TUI 本地类型桩(不依赖 @x-otto/ai)
72
+ theme.ts # THEME / PALETTE / FIGURES / SPINNER_FRAMES
73
+ startTui.tsx # 生产入口
74
+ print-messages.ts # print 模式
75
+ compat.ts # 向后兼容(旧 API shim)
76
+ index.ts # barrel 导出
77
+ store/ # 应用状态管理
78
+ term/ # 终端原语(paste/keys/OSC)
79
+ input/ # 输入栈(Cursor/Buffer/History/Typeahead)
80
+ messages/ # 消息流(Stream/QueryGuard/Collapse/Diff)
81
+ dialogs/ # 对话框(Permission/Select/Arbiter)
82
+ components/ # 通用组件(App/Welcome/StatusBar/Spinner)
83
+ tests/ # 20 个测试文件
84
+ ```
85
+
86
+ ## 公开导出
87
+
88
+ ```ts
89
+ // 状态管理
90
+ export { createStore, useAppState }
91
+ export type { Store }
92
+
93
+ // 终端原语
94
+ export { BracketedPasteHandler, parseExtendedKey }
95
+ export { osc8Hyperlink, osc8FilePath, osc52Write, beginSyncFrame, endSyncFrame, withSyncFrame }
96
+ export { insertHistory, preWrapLine, displayWidth, guardScrollbackStdout }
97
+
98
+ // 输入栈
99
+ export { Cursor, MeasuredText, stringWidth }
100
+ export { createInputBuffer, createInputHistory, createPasteStore }
101
+ export { createCommandRegistry, getCommandSuggestions, applySlashCompletion }
102
+ export { TextInput, PromptInput, QueuedCommands, HistorySearchInput }
103
+ export type { InputBuffer, BufferEntry }
104
+
105
+ // 消息流
106
+ export { createStreamState, reduceStreamEvent, reduceStreamEvents }
107
+ export { createQueryGuard, collapseMessages, toggleCollapse, expandCollapsed }
108
+ export { Markdown, Message, REPLRegion, StructuredDiff, ToolUseLoader, StreamingMarkdown }
109
+ export { registerPluginRenderers, clearPluginRenderers }
110
+
111
+ // 对话框
112
+ export { createDialogArbiter, createPermissionQueue, createSelectState }
113
+ export { Select, PermissionDialogDialog, BashPermissionDialog, ConfirmDialog, AlertDialog, PromptDialog, MemoryDialog }
114
+
115
+ // 组件
116
+ export { App, Home, Spinner, Button, DataList }
117
+ export type { ButtonProps, ButtonVariant, ButtonColor, DataListProps }
118
+
119
+ // 主题
120
+ export { THEME, PALETTE, STATUS, FIGURES, SPACING, LAYOUT, DIALOG_BORDER, PANEL_BORDER }
121
+ export { ThemeRegistry, createBuiltinThemeRegistry }
122
+ export type { ThemePreset, ThemePresetInput, ThemePresetSelection, ThemeAppearance }
123
+
124
+ // 搜索
125
+ export { rankCandidates, rankNamedItems, rankLabeledItems, createIncrementalSearcher }
126
+
127
+ // Inspect
128
+ export { createInspectorStore, InspectorPane, buildEventTree, buildToolList }
129
+
130
+ // i18n
131
+ export { detectLanguage, t, i18next, initI18n }
132
+ export type { Lang, LangMode }
133
+
134
+ // 入口
135
+ export { startTui }
136
+ export { printMessages }
137
+ ```
138
+
139
+ ## 开发命令
140
+
141
+ ```bash
142
+ pnpm --filter @x-otto/tui build
143
+ pnpm --filter @x-otto/tui typecheck
144
+ pnpm --filter @x-otto/tui test
145
+ pnpm --filter @x-otto/tui clean
146
+ ```
147
+
148
+ ## 关联包
149
+
150
+ `@x-otto/keybindings`