8000
Skip to content

CrazyFork/pi-mono

 
 

Repository files navigation

Reading Notes

TUI package

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

paste mode


// enable
process.stdout.write("\x1b[?2004h");

how key binding works

user press <C-c> on keyboard 
    --> terminal emulator -- [sends] --> special sequences 
    --> TUI parse special sequences

Mom Package

  • 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

files

.
├── 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

final thoughts

TUI package

  • the TUI part is too raw for my personal tastes, as this repo handles TUI directly. I would rather using open-tui to build everything up.

Futher Reading


Pi Monorepo

Packages

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

Contributing

See CONTRIBUTING.md for contribution guidelines and AGENTS.md for project-specific rules (for both humans and agents).

Development

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 check requires npm run build to be run first. The web-ui package uses tsc which needs compiled .d.ts files from dependencies.

License

MIT

About

AI agent toolkit: coding agent CLI, unified LLM API, TUI & web UI libraries, Slack bot, vLLM pods

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.7%
  • JavaScript 2.1%
  • Other 1.2%
0