hcchengithub/peforth
Acerca de
v2 - You describe what you want. AI writes the Forth. Powered by Python and Project K.
IA y aprendizaje automáticoCrecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
Originalpeforth v2.1.0
peforth is an AI-first Forth programming environment hosted by Python.
"Forth drives Forth; Python provides host primitives."
In peforth 2.1.0, the environment shifts from a Python-centric monolithic supervisor to a pure Forth-driven architecture:
- Minimal Bootloader (
main.py): A tiny 9-line bootstrap shim. - Dependency-Free Micro-Kernel (
projectk.py): Zero external dependencies, strictly 2 seed words (codeandend-code), uniformKernelError, and generator coroutines. - Forth-Level REPL (
repl.f): Multiline interactive input accumulation and dual-mode switching (chat>and>). - Word-Oriented Security (
ai.py): Fine-grained task security where vocabulary words carrysafe=Trueannotations. Pure Forth words run freely without friction; only unsafe words trigger the interactive security approval review workflow. - Integrated AI Assistant: Conversational answers stream directly to the terminal; Forth code execution is delegated to
peforth_run_forth. - SQLite Diagnostics & Live Monitoring: Comprehensive event tracking in
ai-diagnostics.sqlite3with terminal emoji live streaming (peforth-monitor/tools/peforth_logging_monitor.py) and watchdog progress supervision (tools/peforth_watchdog.py).
Architecture: Repo vs. Runtime
peforth distinguishes between the development repository and runtime execution environments:
- Repository (
.../peforth): Used solely for codebase development, Git version control, and running the contract test suite (test_all.py). - Runtimes (
~/.peforthor$HOME\.peforth): Dedicated, standalone checkouts and virtual environments where peforth runs day-to-day. Windows and Ubuntu/WSL runtimes are kept strictly separate.
Requirements
- Python 3.10 or newer
- Git
- uv (recommended for fast virtual environment management)
- An OpenAI-compatible API key (optional; only needed for AI chat and pair programming)
Runtime Installation
1. Ubuntu / WSL Runtime
For WSL, keep this Linux checkout inside its native Linux filesystem (~/.peforth), not under /mnt/c:
git clone https://github.com/hcchengithub/peforth.git ~/.peforth
cd ~/.peforth
uv venv
uv pip install --python .venv -e .
~/.peforth/.venv/bin/f
To invoke f by name from anywhere in your shell:
export PATH="$HOME/.peforth/.venv/bin:$PATH"
f
2. Windows PowerShell Runtime
git clone https://github.com/hcchengithub/peforth.git "$HOME\.peforth"
Set-Location "$HOME\.peforth"
uv venv
uv pip install --python .venv -e .
& "$HOME\.peforth\.venv\Scripts\f.exe"
To invoke f by name from anywhere in PowerShell:
$env:PATH = "$HOME\.peforth\.venv\Scripts;$env:PATH"
f
Note for managed corporate networks: If
uvreports certificate errors, use native Windows certificate handling:uv --native-tls pip install -e .
Configuration (.env & providers.yaml)
Copy .env.example to .env in your runtime directory (Windows: $HOME\.peforth\.env, Ubuntu/WSL: ~/.peforth/.env):
# Start from the repository's .env.example and fill in required credentials.
OPENAI_API_KEY=your_openai_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_here
Multi-Provider Configuration (providers.yaml)
peforth separates Stateful (OpenAI Agents API sessions) and Stateless (OpenAI-compatible /chat/completions) profiles in providers.yaml.
You can inspect available profiles or switch providers dynamically using the /provider command or natural language:
chat> /provider
Current provider: gpt-6-luna (Stateful)
Available profiles: gpt-6-luna, gemini-flash, groq-llama-3.3-70b
chat> /provider gpt-6-luna
Switched to provider profile: gpt-6-luna
chat> please switch LLM to Gemini Flash
Switched to provider profile: gemini-flash
Quick Start
Launch f (or python main.py) to start peforth:
peforth enters in conversational Chat mode (chat>) by default. You can talk to AI directly, or run Forth commands using the / prefix:
chat> tell me a joke
chat> /help
chat> /1 2 + . cr
Switch to Forth mode anytime with /forth, or return to chat mode with chat:
chat> /forth
Switched to Forth mode (>). Type 'chat' to return to chat mode.
> 1 2 + . cr
> : square dup * ;
> 5 square . cr
> help \ Interactive user guide & tutorial
> words py >> \ Filter word names
> chat
Switched to chat mode (chat>). Type '/forth' to return to Forth mode.
chat>
In Forth mode, you can still ask the AI directly using ai: (or aside: to borrow context read-only without modifying the session):
ai: calculate 355 113 / in Forth
Command-Line Execution (-e)
Run Forth words, one-off AI turns, or read-only batch reuse directly from the shell:
f -e run-monitor
f -e ai: Tell me a joke.
f -e ai-use local_... aside: Why is that funny?
When -e runs an AI turn, stderr outputs SESSION_ID=<id> for mainstream turns (local_<id> or sess_<id>), ASIDE_FROM=<id> and ASIDE_ID=aside_<id> for aside turns, or FORK_FROM=<id> and FORK_ID=fork_<id> for forked branches (ai-fork / (ai-fork)). For quiet batch scripts, prepend : nokia2 ; s" local_..." (ai-use) (or (ai-fork) for multi-turn branches).
To exit peforth:
chat> /bye
Diagnostics & Watchdog Monitoring
In a separate terminal or Herdr pane, launch the live diagnostic monitor:
peforth-monitor
# or:
python tools/peforth_logging_monitor.py
The monitor connects to ~/.peforth/ai-diagnostics.sqlite3 in read-only mode and displays live emoji events:
- 🚀
runtime started/ 🏁runtime finished - 🌐
HTTP request started/ ✅HTTP response received - 📡
SSE stream opened/ 📨SSE event received - 🛠️
tool call started/ 📤tool result submitted - 🙋
approval requested/ 👍approval received - ▶️
Forth execution started/ ⏹️Forth execution finished
The embedded Watchdog alerts with a Windows Message Box if an active AI turn makes no objective progress for 5 minutes.
Testing & Quality Assurance
To verify architectural contracts, kernel purity, security approval flow, and diagnostics:
python test_all.py
Explorar proyectos relacionados
Cargando…