Imported from dev-hann/radartui (
AGENTS.md). Install upstream withnpx skills add dev-hann/radartui. Copyright stays with the author.
RadarTUI - AI Development Guide
Flutter-like TUI framework for Dart. See CHANGELOG.md for history.
0. Development Workflow: TDD
See TESTING.md for full TDD cycle, enforcement tiers, and rules.
TDD is MANDATORY. Enforcement varies by code tier:
| Tier | Scope | TDD Cycle | Applies To |
|---|---|---|---|
| S (Strict) | Per test case | RED→GREEN per individual test case | Foundation (Size, Offset, BoxConstraints), Services (KeyParser, OutputBuffer) |
| A (Per-class) | Per class | RED→GREEN per class | RenderObject, Widget (Stateless/Stateful/RenderObjectWidget), Binding |
| B (Per-layer) | Per layer | Write tests then impl, no RED required | Animation, Enums, Typedefs, Color |
CRITICAL: Every implementation step MUST be followed by dart test.
Skipping dart test between steps is a PROHIBITED ACTION.
1. Mandatory Checks Before Committing
dart format .
dart analyze # Must return: No issues found!
dart test # All tests must pass
All three must pass with zero errors. No exceptions.
2. Flutter Reference Principle
CRITICAL: All implementations MUST reference Flutter's design patterns.
Before implementing any widget:
- Check Flutter source: https://github.com/flutter/flutter/tree/master/packages/flutter/lib/src/widgets
- Match constructor parameters and method signatures
- Use identical class/parameter names unless technically impossible
Flutter → RadarTUI Adaptation
| Flutter | RadarTUI | Reason |
|---|---|---|
double coordinates |
int coordinates |
Terminal cells are discrete |
Color(0xFFRRGGBB) |
Color(value) |
ANSI 16-color palette |
| Mouse/Touch events | Keyboard only | Terminal limitation |
super.key in constructors |
super.key is OK |
Key reconciliation (GlobalKey/ValueKey matching) not yet implemented |
When to deviate: terminal limitations, performance (simplified algorithms OK), missing dependencies.
3. Project Structure
lib/src/
├── foundation/ # Size, Offset, Color, EdgeInsets, BoxConstraints
├── services/ # Terminal I/O, key parsing, logging
├── rendering/ # RenderObject tree, layout, RenderBox
├── scheduler/ # Frame scheduling, binding
└── widgets/
├── framework.dart # Widget, Element, State base classes
├── focus_manager.dart # Focus management
├── navigation.dart # Navigator, Route
└── basic/ # Concrete widgets (Text, Button, etc.)
test/
├── unit/ # Foundation, Services logic
├── widgets/ # Widget rendering, lifecycle
├── integration/ # Full app behavior
└── pty/ # PTY golden tests (ANSI output → text grid comparison)
├── examples/ # Example app Dart files (one per widget)
└── golden/ # Golden .txt files (expected rendering)
Dependency flow: Application → radartui.dart → widgets/ → scheduler/ → rendering/ → services/ → foundation/
See doc/ARCHITECTURE.md for full layer details.
4. Coding Standards
See doc/CONVENTIONS.md for full details.
Key constraints:
- No
var— use explicit types orfinal constfor all immutable objects (const Text('hello'))- Explicit public API types (
Size layout(BoxConstraints c)) - One public class per file (except Flutter core framework files:
framework.dart,navigation.dart,render_object.dart,render_box.dartwhich mirror Flutter's multi-class-per-file pattern) - Functions: MAX 30 lines, prefer < 20
- Nesting: MAX 3 levels
- Class member order (Flutter convention): constructors → instance fields → static methods → instance methods → override methods
- File naming:
snake_case.dart, static constants:SCREAMING_SNAKE_CASE(except Flutter-parity constants likeSize.zero,Color.redwhich usecamelCase) - No inline comments. Doc comments (
///) on public API are allowed and encouraged.
5. Widget Implementation
See doc/widget-templates.md for StatelessWidget, StatefulWidget, and RenderObjectWidget templates.
Key pattern: all widgets follow Flutter's Widget → Element → RenderObject architecture. Use RenderObjectWithChildMixin<C> for single-child render objects.
6. Testing
See TESTING.md for full TDD tiers, test levels, templates, and bug-prone areas.
dart test # All tests
dart test test/unit/ # Unit tests only
dart test test/integration/ # Integration tests only
dart test test/pty/ # PTY golden tests (visual rendering verification)
Bug-Prone Areas
| Area | Risk | Detail |
|---|---|---|
isTight in box_constraints.dart |
HIGH | Used >= instead of == |
deflate in box_constraints.dart |
HIGH | Negative values handling |
F-key parsing in key_parser.dart |
HIGH | Complex escape sequences |
ShortcutActionsHandler placement |
HIGH | Must be INSIDE Shortcuts/Actions tree, not outside |
FfiWrite UTF-8 encoding |
HIGH | Must use utf8.encode() not code unit truncation |
FfiWrite isatty check |
MEDIUM | Must skip /dev/tty when stdout is piped |
7. MANDATORY: Git Worktree Workflow
All AI work MUST use worktrees. Never edit the main directory directly.
git worktree add ../.worktrees/<branch> -b <branch> # Create
git worktree list # Check
git worktree remove ../.worktrees/<branch> # Cleanup
| Type | Pattern | Example |
|---|---|---|
| Feature | feat/xxx |
feat/add-gridview |
| Fix | fix/xxx |
fix/memory-leak-focus |
| Refactor | refactor/xxx |
refactor/simplify-layout |
| Docs | doc/xxx |
doc/update-readme |
8. Feature Implementation Checklist
Follow this checklist IN ORDER when adding a new widget or significant feature. Each step is a complete TDD cycle. Do NOT proceed to step N+1 until step N is fully GREEN.
Step 1: Foundation Layer (Tier B — Per-layer)
- Write Foundation types if needed (e.g., new
EdgeInsets,BoxConstraintsvariant) - Write tests for all of the above
- Run
dart test test/unit/foundation/→ Confirm GREEN
Step 2: Services Layer (Tier S/A — Per class or per test case)
- Write ALL failing service tests (e.g.,
KeyParser,OutputBufferchanges) - Run
dart test test/unit/services/→ Confirm RED - Write minimum service implementation
- Run
dart test test/unit/services/→ Confirm GREEN
Step 3: RenderObject (Tier A — Per-class)
- Write ALL failing RenderObject tests
- Run
dart test test/unit/rendering/→ Confirm RED - Write minimum RenderObject implementation (
performLayout,paint) - Run
dart test test/unit/rendering/→ Confirm GREEN
Step 4: Widget (Tier A — Per-class)
- Write ALL failing Widget tests
- Run
dart test test/unit/widgets/→ Confirm RED - Write minimum Widget implementation
- Run
dart test test/unit/widgets/→ Confirm GREEN
Step 5: Integration Test
- Write integration test wiring real layers
- Run
dart test test/integration/→ Confirm GREEN
Step 6: PTY Golden Test
- Create example app in
test/pty/examples/<widget>_app.dart - Add test case in
test/pty/pty_golden_test.dart - Run
dart test test/pty/→ Confirm GREEN (auto-creates golden)
Step 7: Example App
- Create example in
example/src/<widget>_example.dart - Export in
example/src/exports.dart - Verify manually if needed
Step 8: Final Check
- Run
dart format .→ No changes - Run
dart analyze→ Zero issues - Run
dart test→ All pass - Update ROADMAP.md if feature status changed
- Update CHANGELOG.md with new feature
- Commit only when all pass
RULE: Every dart test run in steps 1-7 is MANDATORY.
Skipping any of them is a PROHIBITED ACTION.
9. Commit Convention
Use Conventional Commits:
feat: add DataTable widget with sorting
fix: correct BoxConstraints.deflate negative values
refactor: simplify Flex performLayout
test: add PTY golden tests for Stack widget
docs: update architecture diagram
chore: upgrade ffi dependency
perf: cache TextStyle in RenderDropdownMenu
style: add missing const to Text widgets
10. Prohibited Actions
- Writing implementation code without tests
- Writing test and implementation in the same tool call batch — they MUST be separate steps
- Proceeding to the next component before the current component is GREEN
- Writing multiple test files before writing any implementation code
- Skipping
dart testverification between RED and GREEN phases - Using
varinstead of explicit types orfinal - Adding comments unless explicitly requested
- Committing code with failing tests
- Skipping
dart analyzebefore committing - Deviating from Flutter's Widget → Element → RenderObject pattern without documented reason
11. Pre-Commit Document Update (MANDATORY)
Code changes before commit, check if changes affect related documents and update if needed:
| Change Type | Document to Update | Check Items |
|---|---|---|
| Widget added/removed/modified | ROADMAP.md §Widget Catalog | Widget status, Flutter parity |
| Architecture change | doc/ARCHITECTURE.md | Layers, Data Flow, Design Decisions |
| Test added/removed/modified | TESTING.md | Test counts, known failures |
| New file created | doc/CONVENTIONS.md | Directory structure, naming |
| New dependency | pubspec.yaml + doc/ARCHITECTURE.md |
Dependency list |
| Coding standard change | doc/CONVENTIONS.md | Rules, naming |
| Widget template change | doc/widget-templates.md | Templates |
Check Method
git diff --statto see changed files- Identify affected documents from the table above
- Read document → reflect changes → save
- Include document updates in the commit
12. Known Gotchas
Element.parentreturnsElement?— always null-check- Cast to
BuildContextwithelement as BuildContext List.map()returnsIterable, notList— use.toList()or for-loops- Container has no
border/borderColorparameters - Text widget uses
dataproperty (nottext) for string content Shortcuts.lookup()traverses UP the tree —ShortcutActionsHandlermust be a descendant ofShortcuts- PTY golden test example apps MUST guard
initializeServices()withif (!isPtyTest)to avoid stdin.echoMode crash when stdin is piped FfiWrite.writeString()MUST useutf8.encode()for proper multi-byte character handling
13. Current Limitations
| Feature | Status |
|---|---|
| Mouse events | N/A (terminal limitation) |
| Scrolling | Basic (limited ListView) |
| Animations | Full animation system (AnimationController, Tween, CurvedAnimation, Curves) |
| Key system | No super.key support yet |
Reference Documents
- TESTING.md — TDD tiers, test levels, bug-prone areas, templates
- ROADMAP.md — Feature matrix, milestones, widget catalog
- doc/ARCHITECTURE.md — System architecture, layers, rendering pipeline
- doc/CONVENTIONS.md — Coding rules, naming, file placement
- doc/widget-templates.md — Widget implementation templates
- doc/testing-guide.md — PTY golden test guide, test commands
- CHANGELOG.md — Version history