this package is very informative on how to build a TUI application from ground up.
-
packages/tui/src/keys.ts # how user key are parsed and mapped
-
packages/tui/src/fuzzy.ts # fuzzy search algorithms
-
packages/tui/src/components/editor.ts # a text editor in the TUI, how to layout text
-
packages/tui/src/autocomplete.ts # how autocomplete is done, slash commands,
@<file_path>etc -
packages/tui/src/stdin-buffer.ts # how to buffer stdio input, and handle
paste mode -
packages/tui/src/tui.ts # TUI layout algorithms, IME cursor positioning by
-
tui.ts vs terminal.ts
用户交互 → tui.ts(UI层) → terminal.ts(终端驱动层) → 操作系统终端
-
TUI topics - see
tui.ts- raw mode
- hidden cursor (APC -Application Program Command) for IME support
- batch update
// enable
process.stdout.write("\x1b[?2004h");
user press <C-c> on keyboard
--> terminal emulator -- [sends] --> special sequences
--> TUI parse special sequences
- this package demos how to write a custom agent.
- a slack bot
- using docker (alphine linux image) as sandbox
core file
- packages/mom/src/agent.ts
- a customized agent
- memory / system prompt
.
├── agent.ts # ! a customized LLM agent for slack
├── context.ts
├── download.ts
├── events.ts # cron job are run, a file based using fs.watch
├── log.ts
├── main.ts
├── sandbox.ts # docker as sandbox to run shell
├── slack.ts # slack bot
├── store.ts
└── tools # llm tools
├── attach.ts
└── write.ts
- the TUI part is too raw for my personal tastes, as this repo handles TUI directly. I would rather using
open-tuito build everything up.
- How to Build a Custom Agent Framework with PI: The Agent Stack Powering OpenClaw
- https://mariozechner.at/posts/2025-11-30-pi-coding-agent/
| Package | Description |
|---|---|
| @mariozechner/pi-ai | Unified multi-provider LLM API (OpenAI, Anthropic, Google, etc.) |
| @mariozechner/pi-agent-core | Agent runtime with tool calling and state management |
| @mariozechner/pi-coding-agent | Interactive coding agent CLI |
| @mariozechner/pi-mom | Slack bot that delegates messages to the pi coding agent |
| @mariozechner/pi-tui | Terminal UI library with differential rendering |
| @mariozechner/pi-web-ui | Web components for AI chat interfaces |
| @mariozechner/pi-pods | CLI for managing vLLM deployments on GPU pods |
See CONTRIBUTING.md for contribution guidelines and AGENTS.md for project-specific rules (for both humans and agents).
npm install # Install all dependencies
npm run build # Build all packages
npm run check # Lint, format, and type check
./test.sh # Run tests (skips LLM-dependent tests without API keys)
./pi-test.sh # Run pi from sources (must be run from repo root)Note:
npm run checkrequiresnpm run buildto be run first. The web-ui package usestscwhich needs compiled.d.tsfiles from dependencies.
MIT