TypeDialog/README.md

508 lines
17 KiB
Markdown
Raw Normal View History

2025-12-18 01:04:07 +00:00
<div align="center">
2025-12-24 03:11:32 +00:00
<img src="assets/typedialog_logo_h_s.svg" alt="TypeDialog Logo" width="600" />
2025-12-18 01:04:07 +00:00
</div>
![Coverage](https://img.shields.io/badge/coverage-tracking-blue)
2025-12-18 01:04:07 +00:00
# TypeDialog
2025-12-24 03:11:32 +00:00
> ▲ Create Type-Safe Interactive Dialogs.
>
2025-12-24 03:11:32 +00:00
> Prompts, forms, schemas definition, use backends (CLI, TUI, Web, AI).
>
> Extended with LLM agents, IaC generation, and [Nickel](https://nickel-lang.org) validation.
2025-12-18 01:04:07 +00:00
## Features Implemented
2025-12-18 01:04:07 +00:00
### Core
2025-12-24 03:11:32 +00:00
- **6 Backends**: CLI (inquire), TUI (ratatui), Web (axum), AI (RAG/embeddings), Agent (LLM execution), Prov-gen (IaC generation)
- **8 Prompt Types**: text, confirm, select, multi-select, password, date, editor, custom
- **Declarative Forms**: TOML-based definitions with fragments & composition
- **4 Output Formats**: JSON, YAML, TOML, Nickel with roundtrip conversion
- **Zero Runtime Dependencies**: Core library works standalone
### Advanced
- **Type-Safe Schemas**: Bidirectional [Nickel](https://nickel-lang.org) integration for validation & serialization
- **Dynamic Logic**: Conditional fields, smart defaults, real-time validation, repeating groups
- **i18n**: Fluent (.ftl) translations with automatic locale detection
- **Encryption**: Field-level encryption with external service integration
- **Contracts**: Pre/post-conditions and business rule enforcement
### Infrastructure
- **3,818 Tests**: Comprehensive coverage (503% growth during development)
- **CI/CD**: GitHub Actions + Woodpecker pipelines with automated testing
- **Docker**: Multi-stage builds with optimization for deployment
- **Cross-compilation**: Linux, macOS, Windows; x86_64, ARM targets
- **Cargo Integration**: Full Rust ecosystem support and toolchain integration
[Full feature breakdown →](./docs/features.md)
2025-12-18 01:04:07 +00:00
## Quick Start
### Installation
2025-12-24 03:11:32 +00:00
See [docs/installation.md](docs/installation.md) for detailed setup.
2025-12-18 01:04:07 +00:00
Requirements:
2025-12-18 01:04:07 +00:00
- **Rust 1.70+** - [Install](https://rustup.rs/)
- **just** - `cargo install just` (or `brew install just`)
### Build & Run
```bash
# Clone
git clone https://github.com/anthropics/typedialog.git
cd typedialog
# Build
just build::default
# Test
just test::all
# Run example
cargo run --example form
# Run with defaults pre-loaded
typedialog form config.toml --defaults defaults.json
2025-12-18 01:04:07 +00:00
```
2025-12-18 01:58:49 +00:00
## Backends at a Glance
### CLI Backend (inquire)
2025-12-18 01:58:49 +00:00
Interactive terminal prompts for scripting and automation.
2025-12-18 01:04:07 +00:00
```bash
# Simple prompt
typedialog text "Enter your name"
# With options
typedialog select "Choose role" Admin User Guest
# Output as JSON
typedialog text "Email" --format json
# Pre-populate form with defaults
typedialog form schema.toml --defaults config.json --format json
2025-12-18 01:04:07 +00:00
```
2025-12-18 01:58:49 +00:00
**Use for:** Scripts, CI/CD pipelines, server tools, piping between tools
**See:** [`examples/04-backends/cli/`](examples/04-backends/cli/)
2025-12-18 01:04:07 +00:00
2025-12-18 01:58:49 +00:00
### TUI Backend (ratatui)
2025-12-18 01:58:49 +00:00
Full terminal UI with keyboard navigation and mouse support.
2025-12-18 01:04:07 +00:00
```bash
cargo run -p typedialog-tui --example form_with_autocompletion
```
2025-12-18 01:58:49 +00:00
**Use for:** Interactive dashboards, system administration tools, complex forms
**See:** [`examples/04-backends/tui/`](examples/04-backends/tui/)
2025-12-18 01:04:07 +00:00
2025-12-18 01:58:49 +00:00
### Web Backend (axum)
2025-12-18 01:58:49 +00:00
HTTP server with browser-based forms.
2025-12-18 01:04:07 +00:00
```bash
cargo run -p typedialog-web -- --config config/web/dev.toml
# Open http://localhost:3000
```
2025-12-18 01:58:49 +00:00
**Use for:** SaaS platforms, public forms, mobile-friendly interfaces
**See:** [`examples/04-backends/web/`](examples/04-backends/web/)
2025-12-24 03:11:32 +00:00
### AI Backend (typedialog-ai)
2025-12-24 03:11:32 +00:00
Retrieval-Augmented Generation (RAG) system with semantic search and embeddings.
```bash
# Query knowledge base
typedialog-ai --config config/ai/dev.toml --query "How do I configure encryption?"
# Build knowledge graph
typedialog-ai --config config/ai/production.toml --build-graph ./docs
```
**Use for:** Documentation search, context-aware assistance, knowledge retrieval, semantic search
**Features:**
2025-12-24 03:11:32 +00:00
- Multi-provider embeddings (OpenAI, Ollama)
- Vector store (in-memory, Redis)
- Knowledge graph generation
- Context retrieval for LLMs
**Learn more:** [AI Backend Documentation](docs/ai/)
2025-12-18 01:58:49 +00:00
**Complete backend guide:** [Backend-Specific Examples](examples/04-backends/)
2025-12-24 03:11:32 +00:00
## TypeDialog Agent (typedialog-ag)
**AI agent execution from markdown files** with multi-provider LLM support.
Execute AI agents defined as `.agent.mdx` files with template variables, file imports, shell integration, and output validation.
### Quick Example
Create `hello.agent.mdx`:
2025-12-24 03:11:32 +00:00
```yaml
---
@agent {
role: friendly assistant,
llm: claude-3-5-haiku-20241022
}
@input name: String
---
Say hello to {{name}} in a warm and friendly way!
```
Run it:
2025-12-24 03:11:32 +00:00
```bash
typedialog-ag hello.agent.mdx
# Prompts: name (String): Alice
# Output: Hello Alice! It's wonderful to meet you! ...
```
### Supported LLM Providers
| Provider | Models | Best For | Privacy |
| ---------- | -------------------------------- | ------------------------- | ----------------- |
| **Claude** | Haiku, Sonnet, Opus | Code, reasoning, analysis | Cloud |
| **OpenAI** | GPT-4o, GPT-4o-mini, o1, o3 | Code, general tasks | Cloud |
| **Gemini** | 2.0 Flash, 1.5 Pro | Creative, multi-modal | Cloud (free tier) |
| **Ollama** | llama2, mistral, codellama, etc. | Privacy, offline, free | Local |
2025-12-24 03:11:32 +00:00
### Features
- **Template System**: Variables (`{{var}}`), conditionals (`{% if %}`), file imports (`@import`) - Tera/Jinja2
- **Context Injection**: Load files with glob patterns, execute shell commands
- **Output Validation**: Format, content, and length validation
- **Streaming**: Real-time token-by-token responses
- **Multi-Provider**: Switch between Claude, OpenAI, Gemini, or local Ollama
### Examples
```bash
# Code review with Claude Sonnet
typedialog-ag examples/12-agent-execution/code-review.agent.mdx
# Creative writing with Gemini
typedialog-ag examples/12-agent-execution/creative-writer.agent.mdx
# Privacy-first analysis with Ollama (local)
typedialog-ag examples/12-agent-execution/local-privacy.agent.mdx
```
**Learn more:**
2025-12-24 03:11:32 +00:00
- [Agent Documentation](docs/agent/) - Complete guide
- [Getting Started](docs/agent/getting_started.md) - Installation and first agent
- [LLM Providers](docs/agent/llm_providers.md) - Provider comparison
- [Examples](examples/12-agent-execution/) - 8 practical use cases
## Provisioning Generator (typedialog-prov-gen)
**Infrastructure as Code generation** from TypeDialog forms with multi-cloud support.
Generate infrastructure configurations for AWS, GCP, Azure, Hetzner, UpCloud, and LXD from interactive forms or declarative specifications.
### Provisioning Example
2025-12-24 03:11:32 +00:00
```bash
# Generate infrastructure with interactive prompts
typedialog-prov-gen --name myproject --output ./provisioning
# Use specific providers
typedialog-prov-gen --name myproject --providers aws,hetzner --ai-assist
# Dry run (preview without generating)
typedialog-prov-gen --name myproject --dry-run
```
### Provisioning Features
2025-12-24 03:11:32 +00:00
- **Multi-Cloud Support**: AWS, GCP, Azure, Hetzner, UpCloud, LXD
- **7-Layer Validation**: Forms → Constraints → Values → Validators → Schemas → Defaults → JSON
- **Nickel Integration**: Type-safe configuration contracts with schema validation
- **AI-Assisted Generation**: Optional Claude/Ollama assistance for complex configurations
- **Template Fragments**: Reusable provider-specific configuration blocks
- **Environment Profiles**: Development, staging, production presets
### Supported Providers
| Provider | Type | Best For |
| ----------- | --------------- | ----------------------------------------------------------- |
| **AWS** | Cloud | Enterprise, scalability, full service catalog |
| **GCP** | Cloud | Data analytics, ML workloads |
| **Azure** | Cloud | Enterprise integration, hybrid cloud, Microsoft ecosystem |
| **Hetzner** | Cloud/Dedicated | Cost-effective European hosting |
| **UpCloud** | Cloud | High-performance SSD, flexible pricing |
| **LXD** | Local/Private | Development, on-premise, containers |
2025-12-24 03:11:32 +00:00
**Learn more:**
2025-12-24 03:11:32 +00:00
- [Prov-gen Documentation](docs/prov-gen/) - Complete guide
- [Examples](examples/11-prov-gen/) - Multi-cloud configurations
- [Templates](crates/typedialog-prov-gen/templates/) - Provider fragments
2025-12-18 01:58:49 +00:00
## Nickel Integration
**Type-safe configuration management** with bidirectional Nickel schema support.
Generate interactive forms from Nickel schemas, collect user input, and produce validated configuration output:
```bash
# 1. Define schema in Nickel
nickel eval config.ncl > schema.toml
# 2. Run interactive form
typedialog form schema.toml --backend tui
# 3. Get validated output in any format
# JSON, YAML, TOML, or back to Nickel with type preservation
```
**Benefits:**
2025-12-18 01:58:49 +00:00
- Schema validation before/after collection
- Type contracts enforced throughout pipeline
- Documentation embedded in schemas
- Deterministic configuration generation
**Learn more:**
2025-12-24 03:11:32 +00:00
- [Nickel Integration Guide](docs/configuration.md#nickel-integration)
2025-12-18 01:58:49 +00:00
- [Examples: 06-integrations/nickel/](examples/06-integrations/nickel/)
- [Nickel Lang Documentation](https://nickel-lang.org/)
2025-12-18 01:04:07 +00:00
## Documentation
Complete documentation in [`docs/`](docs/):
| Document | Purpose |
| ------------------------------------------------- | ------------------------------ |
| [**installation.md**](docs/installation.md) | Prerequisites & setup |
| [**development.md**](docs/development.md) | Development workflows |
| [**build.md**](docs/build.md) | Building & cross-compilation |
| [**release.md**](docs/release.md) | Release process |
| [**configuration.md**](docs/configuration.md) | Backend & Nickel configuration |
2025-12-18 01:04:07 +00:00
## Project Examples
2025-12-18 01:04:07 +00:00
Complete working examples in [`examples/`](examples/):
| Category | Path | Contents |
| --------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------- |
| **Getting Started** | [01-basic](examples/01-basic/) | Form syntax, sections, validation |
| **Advanced Features** | [02-advanced](examples/02-advanced/) | Conditional logic, dynamic fields |
| **Styling** | [03-styling](examples/03-styling/) | Themes, borders, visual design |
| **Backends** | [04-backends](examples/04-backends/) | CLI, TUI, Web implementations |
| **Composition** | [05-fragments](examples/05-fragments/) | Reusable components |
| **Integrations** | [06-integrations](examples/06-integrations/) | [Nickel](examples/06-integrations/nickel/), [i18n](examples/06-integrations/i18n/) |
| **Production** | [09-templates](examples/09-templates/) | Real-world use cases |
| **Provisioning** | [11-prov-gen](examples/11-prov-gen/) | Infrastructure generation, multi-cloud |
| **Agent Execution** | [12-agent-execution](examples/12-agent-execution/) | LLM agents, AI workflows |
2025-12-18 01:04:07 +00:00
2025-12-18 01:58:49 +00:00
**Quick start:** [examples/README.md](examples/README.md)
2025-12-18 01:04:07 +00:00
## Development
Use `just` for all development tasks:
```bash
# Show available commands
just --list
# Format, lint, test
just check-all
# Build & package
just distro::build-release
just distro::create-package
# Full CI/CD
just ci::full
```
2025-12-24 03:11:32 +00:00
See [docs/development.md](docs/development.md) for details.
2025-12-18 01:04:07 +00:00
## Building & Distribution
### Build from Source
```bash
just build::release
```
Binaries in `target/release/`
### Create Distribution Package
```bash
just distro::build-release
just distro::create-package
just distro::create-checksums
```
Package includes binaries, configs, and installers.
2025-12-24 03:11:32 +00:00
See [docs/build.md](docs/build.md) for complete guide.
2025-12-18 01:04:07 +00:00
### Install Distributed Release
```bash
# Linux/macOS
curl -fsSL https://github.com/anthropics/typedialog/releases/download/latest/install.sh | bash
# Windows PowerShell
irm https://github.com/anthropics/typedialog/releases/download/latest/install.ps1 | iex
```
2025-12-24 03:11:32 +00:00
See [docs/release.md](docs/release.md) for release workflow.
2025-12-18 01:04:07 +00:00
## Configuration
Pre-configured settings for each backend and environment:
```text
2025-12-18 01:04:07 +00:00
config/
├── cli/ # default, dev, production
├── tui/ # default, dev, production
2025-12-24 03:11:32 +00:00
├── web/ # default, dev, production
├── ai/ # default, dev, production (RAG/embeddings)
├── ag/ # default, dev, production (Agent/LLM)
└── prov-gen/ # default, dev, production (IaC generation)
2025-12-18 01:04:07 +00:00
```
2025-12-24 03:11:32 +00:00
See [docs/configuration.md](docs/configuration.md) and [config/README.md](config/README.md) for all options.
2025-12-18 01:04:07 +00:00
## Project Structure
```text
2025-12-18 01:04:07 +00:00
typedialog/
├── crates/
2025-12-24 03:11:32 +00:00
│ ├── typedialog-core/ # Core library (forms, validation)
2025-12-18 01:04:07 +00:00
│ ├── typedialog/ # CLI binary
│ ├── typedialog-tui/ # TUI binary
2025-12-24 03:11:32 +00:00
│ ├── typedialog-web/ # Web binary
│ ├── typedialog-ai/ # AI backend (RAG, embeddings)
│ ├── typedialog-ag-core/ # Agent core library
│ ├── typedialog-ag/ # Agent CLI binary
│ ├── typedialog-ag-server/ # Agent HTTP server
│ └── typedialog-prov-gen/ # Provisioning generator
├── config/ # Configuration files (6 backends × 3 envs)
├── examples/ # Working examples (12 categories)
2025-12-18 01:04:07 +00:00
├── scripts/ # Build automation
├── installers/ # Installation scripts
├── docs/ # Documentation
├── justfile # Command orchestration
└── Cargo.toml # Workspace manifest
```
## Key Technologies
2025-12-24 03:11:32 +00:00
**Core:**
2025-12-18 01:58:49 +00:00
- **Rust** - Type-safe systems language
- **Nickel** - Type-safe configuration language (schema integration)
- **TOML** - Form and configuration language
- **Fluent** - Multi-language translation system
- **just** - Command orchestration
2025-12-18 01:04:07 +00:00
2025-12-24 03:11:32 +00:00
**Backends:**
2025-12-24 03:11:32 +00:00
- **inquire** - Interactive prompt library (CLI backend)
- **Ratatui** - Terminal UI framework (TUI backend)
- **Axum** - Web framework (Web backend)
**AI & Agent:**
2025-12-24 03:11:32 +00:00
- **Tera** - Template engine (Jinja2-compatible) for agent files
- **Claude API** - Anthropic's language models
- **OpenAI API** - GPT models
- **Gemini API** - Google's language models
- **Ollama** - Local LLM runtime
**Infrastructure:**
2025-12-24 03:11:32 +00:00
- **Nickel contracts** - Type-safe IaC validation
- **AWS/GCP/Hetzner/UpCloud APIs** - Multi-cloud provisioning
2025-12-18 01:04:07 +00:00
## Commands at a Glance
```bash
# Development
just fmt # Format code
just lint # Lint code
just test::all # Run tests
just dev::watch # Watch & rebuild
just dev::docs # Generate docs
# Building
just build::default # Debug build
just build::release # Release build
just distro::cross # Cross-compile
# CI/CD
just ci::full # Complete pipeline
just check-all # Format + lint + test
# Distribution
just distro::build-release # Release build
just distro::create-package # Package
just distro::create-checksums # Checksums
just distro::package-release # Prepare release
```
## System Requirements
### Minimum
2025-12-18 01:04:07 +00:00
- Rust 1.70+
- 4GB RAM
- 2GB disk space
### For Cross-Compilation
2025-12-18 01:04:07 +00:00
- Docker (or cargo-cross)
### Optional Tools
2025-12-18 01:58:49 +00:00
- **Nickel CLI** - For developing type-safe Nickel schemas (used with `06-integrations/nickel/` examples)
- **cargo-watch** - For hot-reload during development
- **cargo-cross** - For cross-compilation to other platforms
2025-12-18 01:04:07 +00:00
2025-12-24 03:11:32 +00:00
See [docs/installation.md](docs/installation.md) for setup.
2025-12-18 01:04:07 +00:00
## License & Compliance
- **Project License**: [MIT](LICENSE)
2025-12-18 01:58:49 +00:00
- **Dependency SBOM (SPDX)**: [SBOM.spdx.json](SBOM.spdx.json) - ISO/IEC 5962:2021
- **Dependency SBOM (CycloneDX)**: [SBOM.cyclonedx.json](SBOM.cyclonedx.json) - ECMA standard
- **Regenerate SBOMs**: `just distro::generate-sbom`
2025-12-18 01:04:07 +00:00
2025-12-18 01:58:49 +00:00
All dependencies are compatible with MIT license. Audit vulnerabilities: `just ci::audit`
2025-12-18 01:04:07 +00:00
## Getting Help
1. **Documentation** - Start with [docs/README.md](docs/)
2. **Examples** - Check [examples/README.md](examples/)
3. **Issues** - Open on [GitHub](https://github.com/anthropics/typedialog/issues)
## Contributing
Contributions welcome! See documentation for setup and guidelines.
---
2025-12-24 03:11:32 +00:00
**Ready to get started?** → [docs/installation.md](docs/installation.md)