@x-otto/tui 0.1.0-alpha.9 → 0.4.0-beta.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 +92 -137
- package/dist/build-revision.json +4 -0
- package/dist/index.d.ts +14713 -2051
- package/dist/index.js +69199 -115
- package/dist/select-rows-C8rsST7Q.js +975 -0
- package/dist/select-rows-plZKwIeW.d.ts +110 -0
- package/dist/select-rows.d.ts +2 -0
- package/dist/select-rows.js +3 -0
- package/package.json +32 -44
- package/dist/Tabable-BRz398OB.d.ts +0 -4129
- package/dist/Tabable-BRz398OB.d.ts.map +0 -1
- package/dist/WizardDialog-y3yLsmoV.js +0 -14
- package/dist/WizardDialog-y3yLsmoV.js.map +0 -1
- package/dist/compat.d.ts +0 -119
- package/dist/compat.d.ts.map +0 -1
- package/dist/compat.js +0 -3
- package/dist/compat.js.map +0 -1
- package/dist/i18n-CpUZSqYB.js +0 -76
- package/dist/i18n-CpUZSqYB.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/standalone.d.ts +0 -324
- package/dist/standalone.d.ts.map +0 -1
- package/dist/standalone.js +0 -2
- package/dist/standalone.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,153 +1,108 @@
|
|
|
1
|
-
# @x-otto/tui
|
|
1
|
+
# @x-otto/tui — 终端 UI 应用层
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> 权威架构见 [`docs/arch/tui.md`](../../docs/arch/tui.md)(终局形态,含行号、调用链、
|
|
4
|
+
> 流程图与可重跑校验)。本 README 是入口导航,不重复架构细节。
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
**一句话边界**:UI 是 Runtime 的**投影与交互入口,不是第二个 Runtime**。
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
- 终端资源宿主 + React 渲染 + 输入路由 + `ServiceEvent → UI` 投影。
|
|
9
|
+
- 只认两个外部契约:`ServiceClient`(会话内一切)与 `AppPorts`(非会话能力)。
|
|
10
|
+
- 会话内每一次人机交互都是协议消息,没有第二条通道;UI 只发意图(`chat.send` /
|
|
11
|
+
`approval.respond` / `hitl.respond` / `chat.interrupt`),编排与权限决策全在 runtime 侧。
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Quick Start
|
|
13
|
+
技术栈:React 19 + ink 7 + zustand(状态)。依赖 `@x-otto/service`(仅类型 + client 契约)
|
|
14
|
+
与下面几个 tui 基础包。
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
import { startTui } from '@x-otto/tui'
|
|
16
|
+
## 相关包
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
| 包 | 角色 | 依赖方向 |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| `@x-otto/tui`(本包) | 终端 UI 应用层(组件库 + AppShell + pages + stores) | 依赖 `tui-*` |
|
|
21
|
+
| `@x-otto/tui-focus` | 焦点树 + 键盘冒泡(FocusBus,浏览器 focus 模型的 TUI 投影) | 无 agent 依赖 |
|
|
22
|
+
| `@x-otto/tui-router` | 内存路由(history + matcher + Router/Route/Switch/hooks) | 无 agent 依赖 |
|
|
23
|
+
| `@x-otto/tui-screen` | alt screen 控制 + cell buffer diff(增量写出避免整屏闪烁) | 无 agent 依赖 |
|
|
24
|
+
| `@x-otto/tui-theme` | 主题 token(ThemeProvider + light/dark 调色板) | 无 agent 依赖 |
|
|
25
|
+
| `@x-otto/i18n` | i18n 共享库(i18next 单例收敛面) | 基础设施 |
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
依赖方向 `universal → kernel → 能力包 → composition → cli/plugin-tui → tui → tui-*`。
|
|
28
|
+
本包**不 import `@x-otto/kernel`**、不 `process.exit`、不自持业务状态(会话消息唯一写入方是
|
|
29
|
+
`applyServiceEvent` reducer)。把两侧(runtime 的 slot/hook 与 UI 的 AppPorts)粘起来的是
|
|
30
|
+
`extensions/plugin-tui`,不在本包。
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
```
|
|
32
|
+
## 依赖与运行
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
| ------------------ | ----------------------------- |
|
|
49
|
-
| TextInput | Text input (cursor/edit/paste) |
|
|
50
|
-
| PromptInput | Main prompt input box |
|
|
51
|
-
| QueuedCommands | Queued command display |
|
|
52
|
-
|
|
53
|
-
## Message Rendering
|
|
54
|
-
|
|
55
|
-
| Component | Function |
|
|
56
|
-
| ------------------ | ----------------------------- |
|
|
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 |
|
|
62
|
-
|
|
63
|
-
## Directory Overview
|
|
34
|
+
```sh
|
|
35
|
+
# 构建跨包依赖(下游经 dist 解析,改了下层包先 build 再跑本包)
|
|
36
|
+
pnpm --filter @x-otto/service build
|
|
37
|
+
pnpm --filter @x-otto/tui-focus build
|
|
38
|
+
pnpm --filter @x-otto/tui-theme build
|
|
64
39
|
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
40
|
+
pnpm --filter @x-otto/tui typecheck # tsc 严格检查
|
|
41
|
+
pnpm --filter @x-otto/tui build # tsdown 构建 dist
|
|
89
42
|
```
|
|
90
43
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```ts
|
|
94
|
-
// State management
|
|
95
|
-
export { useAppState, makeStore }
|
|
96
|
-
export type { Store }
|
|
97
|
-
|
|
98
|
-
// Terminal primitives
|
|
99
|
-
export { BracketedPasteHandler, parseExtendedKey }
|
|
100
|
-
export { osc8Hyperlink, osc8FilePath, osc52Write, beginSyncFrame, endSyncFrame, withSyncFrame }
|
|
101
|
-
export { insertHistory, preWrapLine, displayWidth, guardScrollbackStdout }
|
|
102
|
-
|
|
103
|
-
// Input stack
|
|
104
|
-
export { Cursor, MeasuredText, stringWidth }
|
|
105
|
-
export { createInputBuffer, createInputHistory, createPasteStore }
|
|
106
|
-
export { createCommandRegistry, getCommandSuggestions, applySlashCompletion }
|
|
107
|
-
export { TextInput, PromptInput, QueuedCommands }
|
|
108
|
-
export type { InputBuffer, BufferEntry }
|
|
109
|
-
|
|
110
|
-
// Message flow
|
|
111
|
-
export { safeCommitBoundary, initStreamCommit, streamCommitStep, makeCoalescer }
|
|
112
|
-
export { createQueryGuard, collapseMessages, toggleCollapse, expandCollapsed }
|
|
113
|
-
export { Message, REPLRegion }
|
|
114
|
-
export { renderMessageLines, renderMarkdownToLines, preloadHighlighter, highlightBlock }
|
|
115
|
-
export { registerPluginRenderers, clearPluginRenderers }
|
|
116
|
-
|
|
117
|
-
// Dialogs
|
|
118
|
-
export { createSelectState }
|
|
119
|
-
export { Select, PermissionDialogDialog, BashPermissionDialog, ConfirmDialog, AlertDialog, PromptDialog, MemoryDialog }
|
|
120
|
-
|
|
121
|
-
// Components
|
|
122
|
-
export { App, Home, Spinner, Button, DataList }
|
|
123
|
-
export type { ButtonProps, ButtonVariant, ButtonColor, DataListProps }
|
|
124
|
-
|
|
125
|
-
// Theme
|
|
126
|
-
export { THEME, PALETTE, STATUS, FIGURES, SPACING, LAYOUT, DIALOG_BORDER, PANEL_BORDER }
|
|
127
|
-
export { ThemeRegistry, createBuiltinThemeRegistry }
|
|
128
|
-
export type { ThemePreset, ThemePresetInput, ThemePresetSelection, ThemeAppearance }
|
|
129
|
-
|
|
130
|
-
// Search
|
|
131
|
-
export { rankCandidates, rankNamedItems, rankLabeledItems, createIncrementalSearcher }
|
|
132
|
-
|
|
133
|
-
// i18n
|
|
134
|
-
export { detectLanguage, t, i18next, initI18n }
|
|
135
|
-
export type { Lang, LangMode }
|
|
136
|
-
|
|
137
|
-
// Entry points
|
|
138
|
-
export { startTui }
|
|
139
|
-
export { printMessages }
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Development Commands
|
|
44
|
+
示例(`examples/service-chat`,最小 tui 对话应用,消费 `@x-otto/service` 协议):
|
|
143
45
|
|
|
144
|
-
```
|
|
145
|
-
pnpm --filter @x-otto/tui
|
|
146
|
-
pnpm --filter @x-otto/tui typecheck
|
|
147
|
-
pnpm --filter @x-otto/tui test
|
|
148
|
-
pnpm --filter @x-otto/tui clean
|
|
46
|
+
```sh
|
|
47
|
+
pnpm --filter @x-otto/tui example:service-chat
|
|
149
48
|
```
|
|
150
49
|
|
|
151
|
-
|
|
50
|
+
详见 `examples/service-chat/README.md`(生产形态 = 进程内 InProcessClient + mock 数据源,
|
|
51
|
+
dev 形态 = Service_URL 连 vite mock server)。
|
|
52
|
+
|
|
53
|
+
## 模块内部布局(`src/`)
|
|
54
|
+
|
|
55
|
+
| 目录 | 职责 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `components/primitives/` | 原子组件(Button/Dialog/Select/TextInput/Overlay/Toast/Diff 等 ~36 个) |
|
|
58
|
+
| `components/composite/` | 组合组件(Chat/PromptInput/AuthFlow/Choose/GrillUser/Permission/各浮层面板等) |
|
|
59
|
+
| `layouts/` | AppShell + 路由 + gate 系统(trust/auth/onboarding/locale/splash)+ panels + Intervention |
|
|
60
|
+
| `pages/` | `Home` / `Session` 两页 |
|
|
61
|
+
| `contracts/` | 纯类型契约(ports/command/draft/queue/shortcut/startup/task 等) |
|
|
62
|
+
| `libs/` | portal(渲染传送)/ cwd / app-ports / service-client / i18n / 纯算法(kernel) |
|
|
63
|
+
| `hooks/` | 功能 hooks(session-restore / session-stream-sync / physical-cursor / terminal-* 等) |
|
|
64
|
+
| `stores/` | zustand stores(session/retry/draft/paste/toast) |
|
|
65
|
+
| `render.tsx` | `createRenderer` — 终端资源唯一所有者 |
|
|
66
|
+
|
|
67
|
+
### 入口:`createRenderer` 与 `App`
|
|
68
|
+
|
|
69
|
+
- `createRenderer(options: RendererOptions): Promise<Renderer>`(`src/render.tsx`)
|
|
70
|
+
把「alt screen + cell buffer + ink 实例」打包成一个可 dispose 的资源句柄,返回
|
|
71
|
+
`Renderer{exited, requestExit, setRoot, dispose}` —— 终端资源**只有一个所有者**。
|
|
72
|
+
- `App`(`src/app.tsx`)`export { App } / AppProps`:应用根。装配 ServiceClient/AppPorts/
|
|
73
|
+
Portal/Cwd 等 Provider,声明路由表(`/session/:id`、`/`、`/panel/*` overlay 浮层),挂
|
|
74
|
+
`Intervention`(审批/HITL 弹窗,App 级而非页面级)。
|
|
75
|
+
- 生产装配链见 `docs/arch/tui.md` §2(`bin/otto.js → cli/start.ts → hooks.execute(uiBoot) →
|
|
76
|
+
plugin-tui claimUiBoot → assembly.mount(TuiUi)`)。
|
|
77
|
+
|
|
78
|
+
### 两个外部契约
|
|
79
|
+
|
|
80
|
+
- **`ServiceClient`**(会话内一切):UI 侧经 `chat.send` / `chat.interrupt` /
|
|
81
|
+
`approval.respond` / `hitl.respond` 发意图,经 `applyServiceEvent` 收 runtime 的
|
|
82
|
+
`prompt.start` / `stream.*` / `tool.*` / `approval.*` / `hitl.*` / `session.status` / `error`
|
|
83
|
+
事件折进 `session-store`(`use-session-stream-sync.tsx` 是唯一 reducer)。
|
|
84
|
+
- **`AppPorts`**(`contracts/ports.ts` 非会话能力):`commands` / `model` / `extension` /
|
|
85
|
+
`credential` / `memory` / `draft` / `queue` 七个端口。生产提供方在 plugin-tui
|
|
86
|
+
(`memory/draft/queue` 目前仍是 demo 空实现,见 `docs/arch/tui.md` §8)。
|
|
87
|
+
|
|
88
|
+
## 文档索引
|
|
89
|
+
|
|
90
|
+
- `docs/arch/tui.md` — **权威终局架构**(边界/布局/调用链/状态归属/生命周期/反思 + 可重跑校验)
|
|
91
|
+
- `docs/ui-ux.md` — UI/UX 规范(1:1 同步参考实现,组件 36 个、主题令牌 25 个)
|
|
92
|
+
- `docs/focus-model.md` — 焦点与键盘模型(浏览器等价物接线决策)
|
|
93
|
+
- `docs/command-palette.md` — 命令面板架构(`/` typeahead)
|
|
94
|
+
- `docs/text-input-cursor.md` — TextInput 光标架构(从逻辑光标到 IME 候选框)
|
|
95
|
+
- `examples/service-chat/README.md` — 最小对话应用演示
|
|
96
|
+
|
|
97
|
+
相关 RFC:`docs/rfc/tui-architecture-rfc/`(骨架成型)与 `docs/rfc/tui-endgame-audit-rfc/`
|
|
98
|
+
(终局整改)、`docs/rfc/plugin-tui-boot-hook-rfc/`(plugin-tui `ui.boot` 认领)、
|
|
99
|
+
`docs/rfc/overlay-portal-rfc/`(Portal 渲染传送 + 浮层路由化 + 退出清屏/IME 光标修复)、
|
|
100
|
+
`docs/rfc/promptinput-datasource-rfc/`(PromptInput 全架构对齐,M0–M6)。
|
|
101
|
+
|
|
102
|
+
## 测试
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
vitest run packages/tui extensions/plugin-tui
|
|
106
|
+
```
|
|
152
107
|
|
|
153
|
-
|
|
108
|
+
(注意:tui 与 plugin-tui 是同一 UI/runtime 边界的两侧,验证时一起跑。)
|