@x-otto/tui 0.0.1-alpha.2 → 0.0.1-alpha.21

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 CHANGED
@@ -1,16 +1,16 @@
1
1
  # @x-otto/tui
2
2
 
3
- ## 模块定位
3
+ ## Module Purpose
4
4
 
5
- 终端 UI 应用层:基于 React + Ink 的组件树,提供流式 Markdown 渲染、权限弹窗、输入栈、消息流等完整的终端交互体验。对接 npm `ink` v7 渲染引擎与 `@x-otto/keybindings` 按键系统。
5
+ The terminal UI application layer: a React + Ink component tree that provides streaming Markdown rendering, permission dialogs, input stack, message flow, and the full terminal interaction experience. Built on the npm `ink` v7 rendering engine, with keybinding, theme, and fuzzy-search systems living in-package (`src/keybindings`, `src/theme`, `src/search`).
6
6
 
7
- ## 安装
7
+ ## Installation
8
8
 
9
9
  ```bash
10
10
  pnpm add @x-otto/tui
11
11
  ```
12
12
 
13
- ## 快速开始
13
+ ## Quick Start
14
14
 
15
15
  ```ts
16
16
  import { startTui } from '@x-otto/tui'
@@ -18,125 +18,128 @@ import { startTui } from '@x-otto/tui'
18
18
  const tui = await startTui({
19
19
  stdin: process.stdin,
20
20
  stdout: process.stdout,
21
- onMessage: async (msg) => { /* 发送到 agent */ },
21
+ onSubmit: (text) => { /* send to agent */ },
22
22
  })
23
23
 
24
- tui.pushMessage({ role: 'assistant', content: 'Hello! I am otto.' })
25
- tui.showToast('Task completed')
24
+ tui.messages.pushMessage({ role: 'assistant', content: 'Hello! I am otto.' })
25
+ tui.info.showToast('Task completed', 'Done')
26
26
 
27
- await tui.dispose()
27
+ tui.lifecycle.stop()
28
28
  ```
29
29
 
30
- ## 核心功能
30
+ ## Core Features
31
31
 
32
- | 模块 | 功能 |
32
+ | Module | Function |
33
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
- | 组件 | 功能 |
34
+ | Store | Application state management (zustand-driven, useAppState / makeStore) |
35
+ | Input | Input stack: Cursor model + InputBuffer + History + Typeahead |
36
+ | Messages | Message flow: stream commit/coalesce + QueryGuard + Collapse + Diff |
37
+ | Dialogs | Dialog arbitration: routed permission dialogs + Select state machine + dialog components |
38
+ | Components | Common components: App / Welcome / StatusBar / Spinner / Button / DataList |
39
+ | Term | Terminal primitives: BracketedPaste / OSC 8/52 / SyncFrame |
40
+ | Theme | Color palette + icon glyphs + spinner frames + theme preset registry |
41
+ | i18n | Internationalization (i18next + react-i18next, zh/en) |
42
+ | startTui | Production entry point: launches the TUI main loop from stdin/WebSocket |
43
+ | printMessages | Non-interactive print mode (backward compatibility) |
44
+
45
+ ## Input Stack
46
+
47
+ | Component | Function |
48
48
  | ------------------ | ----------------------------- |
49
- | BaseTextInput | 基础文本输入(光标/编辑/粘贴)|
50
- | PromptInput | 主提示输入框 |
51
- | PromptInputFooter | 输入框底部状态栏 |
52
- | HistorySearchInput | 历史搜索输入 |
53
- | QueuedCommands | 排队命令显示 |
49
+ | TextInput | Text input (cursor/edit/paste) |
50
+ | PromptInput | Main prompt input box |
51
+ | QueuedCommands | Queued command display |
54
52
 
55
- ## 消息渲染
53
+ ## Message Rendering
56
54
 
57
- | 组件 | 功能 |
55
+ | Component | Function |
58
56
  | ------------------ | ----------------------------- |
59
- | Message | 消息容器(角色/折叠/分支) |
60
- | Markdown | Markdown 静态渲染 |
61
- | StreamingMarkdown | Markdown 流式渲染(防闪) |
62
- | StructuredDiff | 结构化 diff 渲染 |
63
- | HighlightedCode | 语法高亮代码块 |
64
- | ToolUseLoader | 工具调用加载动画 |
65
- | REPLRegion | REPL 消息区域容器 |
57
+ | Message | Message container (role/collapse/branch) |
58
+ | REPLRegion | REPL message region container |
59
+ | renderMessageLines | Line-based message rendering (streaming-aware) |
60
+ | renderMarkdownToLines | Markdown ANSI line rendering |
61
+ | preloadHighlighter / highlightBlock | Syntax-highlighted code blocks |
66
62
 
67
- ## 目录概览
63
+ ## Directory Overview
68
64
 
69
65
  ```
70
66
  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 个测试文件
67
+ types.ts # TUI-local type stubs (no dependency on @x-otto/ai)
68
+ theme.ts # THEME / PALETTE / FIGURES / SPINNER_FRAMES
69
+ main.ts # production entry point (startTui)
70
+ compat.ts # backward-compatibility (legacy API shim)
71
+ index.ts # barrel export
72
+ stores/ # application state (zustand: message/stream/task/context/...)
73
+ term/ # terminal primitives (paste/keys/OSC/sync/scrollback)
74
+ input/ # input stack (Cursor/Buffer/History/Typeahead)
75
+ messages/ # message flow (commit/QueryGuard/Collapse/Diff)
76
+ dialogs/ # dialogs (Permission/Select/Confirm/Alert/...)
77
+ components/ # common components (App/Welcome/StatusBar/Spinner)
78
+ panes/ # side panes (Context/Task/Subagents/Sigil/Schedule/...)
79
+ router/ + routes/ # router-driven views & modal routes (FocusBus/Router/Tabable)
80
+ overlays/ # overlay components
81
+ status-bar/ # status bar widgets (provider usage badge, background tasks)
82
+ keybindings/ # keybinding parsing & overrides
83
+ history/ # shell history parsing (zsh/bash/fish)
84
+ search/ # fuzzy search
85
+ sigil/ # #/@ sigil input completion
86
+ bootstrap/ # TuiHandle/TuiOptions types + session data-source bridges
87
+ app/ # App shell assembly (input/dialog/panel/status regions)
88
+ tests/ # 385 test files
84
89
  ```
85
90
 
86
- ## 公开导出
91
+ ## Public Exports
87
92
 
88
93
  ```ts
89
- // 状态管理
90
- export { createStore, useAppState }
94
+ // State management
95
+ export { useAppState, makeStore }
91
96
  export type { Store }
92
97
 
93
- // 终端原语
98
+ // Terminal primitives
94
99
  export { BracketedPasteHandler, parseExtendedKey }
95
100
  export { osc8Hyperlink, osc8FilePath, osc52Write, beginSyncFrame, endSyncFrame, withSyncFrame }
96
101
  export { insertHistory, preWrapLine, displayWidth, guardScrollbackStdout }
97
102
 
98
- // 输入栈
103
+ // Input stack
99
104
  export { Cursor, MeasuredText, stringWidth }
100
105
  export { createInputBuffer, createInputHistory, createPasteStore }
101
106
  export { createCommandRegistry, getCommandSuggestions, applySlashCompletion }
102
- export { TextInput, PromptInput, QueuedCommands, HistorySearchInput }
107
+ export { TextInput, PromptInput, QueuedCommands }
103
108
  export type { InputBuffer, BufferEntry }
104
109
 
105
- // 消息流
106
- export { createStreamState, reduceStreamEvent, reduceStreamEvents }
110
+ // Message flow
111
+ export { safeCommitBoundary, initStreamCommit, streamCommitStep, makeCoalescer }
107
112
  export { createQueryGuard, collapseMessages, toggleCollapse, expandCollapsed }
108
- export { Markdown, Message, REPLRegion, StructuredDiff, ToolUseLoader, StreamingMarkdown }
113
+ export { Message, REPLRegion }
114
+ export { renderMessageLines, renderMarkdownToLines, preloadHighlighter, highlightBlock }
109
115
  export { registerPluginRenderers, clearPluginRenderers }
110
116
 
111
- // 对话框
112
- export { createDialogArbiter, createPermissionQueue, createSelectState }
117
+ // Dialogs
118
+ export { createSelectState }
113
119
  export { Select, PermissionDialogDialog, BashPermissionDialog, ConfirmDialog, AlertDialog, PromptDialog, MemoryDialog }
114
120
 
115
- // 组件
121
+ // Components
116
122
  export { App, Home, Spinner, Button, DataList }
117
123
  export type { ButtonProps, ButtonVariant, ButtonColor, DataListProps }
118
124
 
119
- // 主题
125
+ // Theme
120
126
  export { THEME, PALETTE, STATUS, FIGURES, SPACING, LAYOUT, DIALOG_BORDER, PANEL_BORDER }
121
127
  export { ThemeRegistry, createBuiltinThemeRegistry }
122
128
  export type { ThemePreset, ThemePresetInput, ThemePresetSelection, ThemeAppearance }
123
129
 
124
- // 搜索
130
+ // Search
125
131
  export { rankCandidates, rankNamedItems, rankLabeledItems, createIncrementalSearcher }
126
132
 
127
- // Inspect
128
- export { createInspectorStore, InspectorPane, buildEventTree, buildToolList }
129
-
130
133
  // i18n
131
134
  export { detectLanguage, t, i18next, initI18n }
132
135
  export type { Lang, LangMode }
133
136
 
134
- // 入口
137
+ // Entry points
135
138
  export { startTui }
136
139
  export { printMessages }
137
140
  ```
138
141
 
139
- ## 开发命令
142
+ ## Development Commands
140
143
 
141
144
  ```bash
142
145
  pnpm --filter @x-otto/tui build
@@ -145,6 +148,6 @@ pnpm --filter @x-otto/tui test
145
148
  pnpm --filter @x-otto/tui clean
146
149
  ```
147
150
 
148
- ## 关联包
151
+ ## Related Packages
149
152
 
150
- `@x-otto/keybindings`
153
+ `@x-otto/interchange`, `@x-otto/session-contract`, `@x-otto/shared`, `@x-otto/env`