Metadata-Version: 2.5
Name: vieforge
Version: 0.4.2
Summary: VieForge — Code First, Local LLM Second, Cloud Last. 3-Tier Hybrid AI Agent Harness for checkpointed, budget-guarded local execution.
Project-URL: Homepage, https://vieforge.dev
Project-URL: Repository, https://github.com/vieforge/vieforge
Project-URL: Issues, https://github.com/vieforge/vieforge/issues
Author: VieForge Contributors
License: MIT
License-File: LICENSE
Keywords: agent-harness,ai-agents,checkpointing,cost-control,local-llm,mcp,ollama
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: hatchling>=1.25.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: mcp
Requires-Dist: mcp>=1.2.0; extra == 'mcp'
Description-Content-Type: text/markdown

<p align="right">
  <strong>English</strong> | <a href="README.vi.md">Tiếng Việt</a>
</p>

# VieForge

**Code First, Local LLM Second, Cloud Last.**

[![VieForge CI](https://github.com/vieforge/vieforge/actions/workflows/ci.yml/badge.svg)](https://github.com/vieforge/vieforge/actions/workflows/ci.yml)
[![PyPI version](https://img.shields.io/pypi/v/vieforge.svg)](https://pypi.org/project/vieforge/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](pyproject.toml)
[![Core: 100% Stdlib](https://img.shields.io/badge/Core-100%25%20Python%20Stdlib-brightgreen.svg)](LEGAL_AND_COMPLIANCE.md)
[![OS: Windows | macOS | Linux](https://img.shields.io/badge/OS-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey.svg)](skills/three-tier-orchestrator/references/hardware-profiles.md)
[![Crafted in Vietnam](https://img.shields.io/badge/Crafted%20in-Vietnam%20%F0%9F%87%BB%F0%9F%87%B3-da251d.svg)](README.vi.md)
[![Website: vieforge.dev](https://img.shields.io/badge/Website-vieforge.dev-2563eb.svg)](https://vieforge.dev)

Turn any consumer workstation into a **checkpointed, budget-guarded, multi-project local AI worker** to cut Cloud Agent quota and API spend by **70–90%**. Built on open **MCP (Model Context Protocol)** + **Agent Skill (`SKILL.md` / `AGENTS.md`)** standards for **Antigravity, Claude Code, Cursor, Windsurf, and Codex CLI**.

---

## Zero-Knowledge Setup (Just Ask Your AI Agent)

New to Git, Python, or MCP? You do not need to touch a terminal manually. Open **Antigravity, Claude Code, Cursor, Windsurf, or Codex CLI** and paste this single message:

> *"Clone `https://github.com/vieforge/vieforge`, read `AGENT_INSTALL.md`, run `python scripts/quick_setup.py`, and show me the Savings Receipt in plain language."*

Your AI agent will automatically detect your hardware, install the TierForge skill for your IDE, generate exact absolute-path MCP configs, and run a `$0` live demo.

---

## 3-Tier Hybrid Architecture

```mermaid
flowchart LR
    U["User / Multi-Project Workspaces"] --> T1["Tier 1: Cloud Brain\n(Antigravity / Claude / Cursor / Codex)\nArchitecture, Reviews, Gates"]
    T1 -- "Compact JSON / MCP Calls" --> T2["Tier 2: Local Backbone ($0)\nPython + SQLite WAL Checkpoints\nOllama Local LLM (Lease-Managed)"]
    T2 -- "Trimmed Summaries (-85% to -95%)" --> T1
    T2 -- "Stage-by-Stage Handoff" --> T3["Tier 3: Isolated Muscle\nChild GPU Subprocess (Exclusive Lock)\nor Capped Paid APIs (--dry-run + Caps)"]
    T3 -- "Cost Ledger & Status" --> T2
```

| Tier | Executor | Responsibilities | Target Cost |
| :--- | :--- | :--- | :---: |
| **Tier 1 (Brain)** | Cloud Agent (Antigravity / Claude / Cursor / Windsurf / Codex) | Architecture, schema design, code review, Approval Gates, root-cause debugging | Cloud Quota |
| **Tier 2 (Backbone)** | Python Stdlib + SQLite WAL + Local LLM (Ollama / OpenAI-compat) | Per-item checkpoints, SHA-256 deduplication, bulk extraction/JSON formatting, log trimming | **`$0.00`** |
| **Tier 3 (Muscle)** | OS-Isolated Local GPU Subprocess / Capped External APIs | Heavy local inference, media/data batching, paid APIs under `--dry-run`, `MAX_RETRY <= 2`, `MAX_JOB_USD`, `DAILY_USD_CAP` | **`$0` or Capped** |

---

## 5-Minute Quickstart (`$0`, Zero Dependencies)

```bash
# Option A: Install directly from PyPI (recommended)
pip install vieforge
vieforge setup

# Option B: Clone the repository
git clone https://github.com/vieforge/vieforge.git
cd vieforge
python scripts/quick_setup.py

# Or run the offline demos directly (works even without Ollama via --mock-llm):
python examples/01_batch_doc_processor/run_demo.py --dry-run
python examples/01_batch_doc_processor/run_demo.py --reset --mock-llm --simulate-interrupt-after 2
python examples/01_batch_doc_processor/run_demo.py --mock-llm
python examples/03_ci_log_triage/run_ci_triage.py --mock-llm --reset
```

Example **Savings Receipt** printed at the end of the resumed run:

```text
=== TierForge Savings Receipt (demo_01_batch) ===
Items processed : 5
Actual cost     : $0.0000 USD
Cloud baseline  : $0.0405 USD (external/text-frontier)
Estimated saved : $0.0405 USD (100.0%)
Context trimmed : 2169 -> 108 chars (-95.0%)
```

---

## Reproducible Token Savings Benchmark (`$0`, 0.3s)

Verify exact Cloud Agent token burn on your own machine (`ceil(chars / 4)` estimator):

```bash
python scripts/benchmark_token_savings.py
```

| Real-World Workload | Cloud-Only Tokens | VieForge Cloud Tokens | Reduction Factor | Saved |
| :--- | ---: | ---: | ---: | ---: |
| One-time Session Overhead (`SKILL.md` 691 + `AGENTS.md` 448 + MCP 320) | 0 | 1,459 | — | Paid once |
| 100-Document Batch Classification & JSON Extraction | 23,662 | 200 | **118.3x** | **-99.2%** |
| Noisy CI / Pytest Log + Traceback Compression (390 lines) | 11,150 | 998 | **11.2x** | **-91.0%** |
| 50-Item Job Crashed at 30/50 + SQLite Checkpoint Resume | 17,920 | 457 | **39.2x** | **-97.4%** |
| **COMBINED NET (incl. 1,459-token session overhead)** | **52,732** | **3,114** | **16.9x** | **-94.1%** |

> **Break-even transparency:** VieForge pays off its 1,459-token one-time session overhead after just **1 noisy CI log** or **3–5 batch items**. For quick 1-turn Q&A or single-file edits, you do not need to invoke VieForge.

---

## Multi-Agent Ecosystem Support

Run `python scripts/install_skill.py --target all` to install the `three-tier-orchestrator` skill across every supported agent detected on your machine and generate absolute-path MCP snippets:

| AI Agent / IDE | Skill Path | MCP Config Format | Repo Instructions |
| :--- | :--- | :--- | :---: |
| **Antigravity** | `~/.gemini/config/skills/three-tier-orchestrator` | JSON (`data/mcp_config.generated.json`) | `AGENTS.md` + `SKILL.md` |
| **Claude Code** | `~/.claude/skills/three-tier-orchestrator` | JSON (`data/mcp_config.generated.json`) | `AGENTS.md` + `SKILL.md` |
| **Cursor** | `~/.cursor/skills/three-tier-orchestrator` | JSON (`data/mcp_config.generated.json`) | `AGENTS.md` + `SKILL.md` |
| **Windsurf** | `~/.codeium/windsurf/skills/three-tier-orchestrator` | JSON (`data/mcp_config.generated.json`) | `AGENTS.md` + `SKILL.md` |
| **Codex CLI** | `~/.agents/skills/three-tier-orchestrator` | TOML (`data/codex_mcp.generated.toml`) | `AGENTS.md` |

To start the MCP server, install the optional MCP extra (`pip install "mcp>=1.2.0"` or `uv sync --extra mcp`) and paste the generated snippet into your IDE settings.

---

## Multi-Project Concurrency Safety

Running 3+ projects simultaneously in Antigravity or Claude Code on one workstation? `core/concurrency.py` prevents cross-workspace race conditions using 100% stdlib OS advisory locks (`msvcrt` on Windows, `fcntl` on macOS/Linux):

- **Ref-Counted Ollama VRAM Lease (`OllamaLeaseManager`):** `LLMRouter.batch_session()` keeps your local model warm during a batch (avoiding 5–10x cold-start reloads) and only triggers `keep_alive=0` unload when the **last** active project releases its lease. Dead PIDs are pruned automatically.
- **Exclusive Tier 3 GPU Queue (`exclusive_gpu_lock`):** Heavy GPU subprocesses serialize cleanly across workspaces instead of colliding on an 8 GB VRAM card.
- **Atomic Daily Spend Ledger:** `CostTracker` wraps `daily_spend.json` in a cross-process lock + atomic `os.replace`, preventing lost spend records across parallel runs.
- **Project-Scoped Checkpoints:** `scoped_job_id(project_id, job_id)` + SQLite WAL (`busy_timeout=15000ms`) isolates job state when multiple workspaces share a database.

---

## Hardware Profiles & Zero OS-Mutation Policy

TierForge **never** modifies OS services, Windows Registry, network/IPv6 stacks, or system pagefiles. All memory hygiene runs strictly in application space.

| Profile | Recommended Local Model | Batch / VRAM Strategy | Min Free VRAM Guard |
| :--- | :--- | :--- | :---: |
| **CPU-Only (16–32 GB RAM)** | `qwen2.5:3b` / `llama3.2:3b` | `batch_session()` + JSON auto-retry (<= 2) | CPU fallback |
| **8 GB VRAM (RTX 3060 Ti / 4060)** | `qwen2.5:7b` (Q4_K_M) | Stage-by-stage isolation; unload Ollama before Tier 3 GPU | `4096 MB` |
| **12–16 GB VRAM (RTX 4070)** | `qwen2.5:7b` / `14b` | Subprocess isolation per stage | `6144 MB` |
| **24 GB+ VRAM (RTX 3090 / 4090)** | `qwen2.5:14b` / `32b` | High-throughput batching + `exclusive_gpu=True` | `10240 MB` |
| **Apple Silicon (16–64+ GB)** | `7b` (16 GB) / `14b–32b` (32 GB+) | Unified memory subprocess isolation | Leave >= 4 GB headroom |

---

## Clean-Room Comparison & Companion Synergy

TierForge's core is **100% MIT-licensed Python stdlib** with an automated clean-room auditor (`python -m core.license_audit`) that blocks `BUSL-1.1`, `AGPL-3.0`, and `CC-BY-NC` dependencies.

| Capability | TierForge Harness (`MIT`) | `rtk-oss` (`Apache-2.0`) | `ppgranger/token-saver` (`Apache-2.0`) |
| :--- | :---: | :---: | :---: |
| SQLite per-item checkpoint & `$0` resume | **Built-in** | No | No |
| Budget caps (`--dry-run`, job/daily USD) | **Built-in** | No | No |
| Multi-project GPU VRAM lease & subprocess isolation | **Built-in** | No | No |
| Worker stdout/traceback compression | **Built-in (`output_trimmer.py`)** | Companion CLI (shell proxy) | Companion CLI (context saver) |
| Commercial-safe clean-room license | **MIT (100% stdlib)** | Apache-2.0 *(avoid BUSL-1.1 std `rtk`)* | Apache-2.0 |

> **Companion Setup:** `scripts/preflight_check.py` detects optional `rtk-oss` (Apache-2.0) and `token-saver` (Apache-2.0) side-by-side without vendoring their source code.

---

## Zero-Cost Architect Handoff & Optional BYOA Companion

- **Pattern A — Zero-Dependency Prompt Handoff (100% Enterprise-Safe):** Export a compact spec/audit prompt (e.g., via `scripts/audit_step.py`), paste it into any Web AI to draft a Blueprint, and hand the Blueprint back to TierForge for local execution.
- **Pattern B — Optional Personal BYOA Browser Bridge:** For personal productivity on your own machine, `extensions/tierforge-bridge/` provides an auditable, localhost-only (`127.0.0.1:19876`) Manifest V3 bridge. See [LEGAL_AND_COMPLIANCE.md](LEGAL_AND_COMPLIANCE.md) — **enterprise/high-volume commercial workloads should use official paid APIs via Tier 3 budget guards rather than Web UI automation.**

---

## Verification & Cross-OS Quality Gate

VieForge is continuously verified across **Ubuntu Linux, macOS, and Windows** (Python 3.10 & 3.12) via a [2-Axis Cross-OS Quality Gate](docs/CROSS_OS_QUALITY_GATE.md) that tests clean wheel installation outside the repo, real multi-process OS locks (`fcntl` / `msvcrt`), and 100% token benchmark parity:

```bash
# Run full unit test suite (pytest)
uv run --extra dev pytest -v

# Run 2-Axis quality audit (5 Core Contracts + Performance/DX score + portability scan)
uv run python scripts/audit_step.py --step verify

# Run full clean-wheel E2E + multi-process OS lock check locally
uv run python scripts/verify_cross_os.py run --step local_check --out data/os_report_local.json
```

> **Local LLM Backends:** `LLMRouter` works natively with **Ollama** (`http://127.0.0.1:11434`, with `keep_alive=0` VRAM lease hygiene) and auto-detects **OpenAI-compatible** local servers (**LM Studio** `:1234/v1`, **llama.cpp** `:8080/v1`, **vLLM** `:8000/v1`) via `TIERFORGE_LLM_BASE_URL` / `TIERFORGE_LLM_API_STYLE=auto`.

### Open-Core Roadmap
- **MIT Core (Always Free & Open Source):** 3-Tier orchestration engine (`core/`), SQLite checkpointing, Ollama lease manager, clean-room output trimmer, budget guard, MCP server, multi-agent skill installer.
- **Pro / Team Extensions (Planned Commercial Add-ons):** Multi-node LAN worker pool, team-wide spend dashboards & RBAC approval webhooks, enterprise SSO/audit compliance packs.

See [LICENSE](LICENSE) and [LEGAL_AND_COMPLIANCE.md](LEGAL_AND_COMPLIANCE.md) for full licensing and compliance terms.
- **Website:** [https://vieforge.dev](https://vieforge.dev)
- **Contact:** `hello@vieforge.dev` | **Security:** `security@vieforge.dev`

---

### Support the Project
VieForge is **100% MIT-licensed and free forever**. If it saves you Cloud API budget, you can [buy the maintainer a coffee on Ko-fi](https://ko-fi.com/aivieforge) to help cover local test hardware and maintenance costs.

### Trademark Notice
The source code in this repository is licensed under the **MIT License**. The **VieForge** name, logo, and associated brand marks are not licensed under MIT and remain the property of **VieForge Contributors**. Forks and derivative works must use a distinct name and may not imply official endorsement.
