Metadata-Version: 2.4
Name: frontierharness
Version: 0.1.1
Summary: High-speed, zero-dependency core tool execution and safety engine for frontier AI agents.
Author-email: FrontierHarness Core Team <core@frontierharness.dev>
Maintainer-email: FrontierHarness Core Team <core@frontierharness.dev>
License: MIT
Project-URL: Homepage, https://github.com/VikasPatel22/frontierharness
Project-URL: Repository, https://github.com/VikasPatel22/frontierharness
Project-URL: Issues, https://github.com/VikasPatel22/frontierharness/issues
Keywords: frontier-harness,agent-harness,tool-use,tool-execution,agent-runtime,safe-filesystem,surgical-diff,context-protection,subprocess-supervisor,ai-agents,antigravity,claude-code,docker-sandbox,llm-safety
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: governor
Requires-Dist: loopcircuit>=0.1.0; extra == "governor"
Provides-Extra: grounding
Requires-Dist: groundanchor>=0.1.0; extra == "grounding"
Provides-Extra: all
Requires-Dist: loopcircuit>=0.1.0; extra == "all"
Requires-Dist: groundanchor>=0.1.0; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"

# frontierharness

[![PyPI Version](https://img.shields.io/badge/pypi-v0.1.1-blue.svg)](https://pypi.org/project/frontierharness/)
[![Python](https://img.shields.io/badge/python-3.10%2B-brightgreen.svg)](https://python.org)
[![License](https://img.shields.io/badge/license-MIT-purple.svg)](LICENSE)
[![Dependencies](https://img.shields.io/badge/dependencies-zero-success.svg)](#)

**frontierharness** is an industry-grade, zero-dependency core tool execution, safety, and cognitive orchestration engine for autonomous AI agents. Built to power frontier agent harnesses like Antigravity and Claude Code, it provides the low-level nervous system and guardrails: path-isolated filesystem manipulation, surgical diffing, process supervision, context compaction, a specialized subagent triad (`Explorer`, `Implementer`, `Verifier`), and automated self-healing loops.

---

## Architecture Overview

```mermaid
flowchart TD
    User["User Goal / Task"] --> Session["SessionManager<br/>(JSONL Persistence & Token Compaction)"]
    Session --> Orchestrator["AdaptiveOrchestrator<br/>(Role RBAC & Self-Healing Loop)"]
    
    subgraph Subagents ["Specialized Subagent Triad"]
        Explorer["1. Explorer Subagent<br/>(Read-only search & index)"]
        Implementer["2. Implementer Subagent<br/>(Surgical diffs & writes)"]
        Verifier["3. Verifier Subagent<br/>(Syntax check & test gate)"]
    end
    
    Orchestrator --> Explorer
    Explorer --> Implementer
    Implementer --> Verifier
    
    subgraph Engine ["agentharness Core Engine"]
        FS["SafeFilesystem<br/>(Path Traversal Guard)"]
        Proc["SubprocessManager<br/>(Timeouts & Background Tasks)"]
        Loop["loopcircuit Hook<br/>(Anti-Thrash Circuit Breaker)"]
    end
    
    Implementer --> FS
    Verifier --> Proc
    Proc --> Loop
    Verifier -->|Verification Failed| Orchestrator
    Verifier -->|Verification Passed| Done["Complete & Verified"]
```

---

## Key Capabilities

1. **Path Traversal Protection**: Enforces strict workspace root boundaries, preventing unauthorized path escapes and system tampering.
2. **Surgical Diff Engine**: Replaces exact character sequences rather than rewriting entire files, eliminating hallucinated line drifts.
3. **Subagent Triad & Security RBAC**: Specialized subagent roles with enforced tool permissions (`Explorer` read-only, `Implementer` modifying, `Verifier` test-only).
4. **Self-Healing Verification Gate**: Automatically validates code syntax and executes automated test suites on modified files, injecting recovery steps if tests fail.
5. **Interactive Diff Viewer & Approval Gate**: Displays color-coded terminal diffs (`+6 -1`) with line numbers and human confirmation prompts (`Accept this file edit? [y/n/a]`) before committing changes to disk.
6. **Live Plan Checklist Renderer**: Visualizes task progress in the terminal (`L ✓`, `●`, `○`) matching frontier standards.
7. **Time-Travel Checkpoint & Rewind**: Automatically snapshots pre-mutation file states, allowing instant `undo` or rollback of both physical files and agent memory back to any checkpoint.
8. **Docker Container Sandboxing**: Optional isolated container execution with network isolation (`--network none`) and memory/CPU limits.
9. **Session Persistence & Smart Compaction**: Incrementally records sessions to `.harness/sessions/<id>.jsonl` with automatic context compaction when approaching context limits.
10. **Zero External Dependencies**: Built 100% on Python 3.10+ standard library. Optional hooks for `loopcircuit` and `groundanchor`.

---

## Installation

```bash
pip install frontierharness
```

Optional safety integrations:
```bash
pip install "frontierharness[all]"
```

---

## Quickstart

### 1. High-Level Adaptive Orchestrator with Subagents

```python
from frontierharness import ToolEngine, SessionManager, AdaptiveOrchestrator

# Initialize core engine and session persistence
engine = ToolEngine(workspace_roots=["./workspace"])
session = SessionManager(session_id="build_feature_01")
orchestrator = AdaptiveOrchestrator(engine=engine, session=session)

# 1. Define adaptive plan
orchestrator.set_plan([
    {"title": "Explore existing codebase", "role": "explorer"},
    {"title": "Implement feature code", "role": "implementer"},
    {"title": "Run automated verification", "role": "verifier"},
])

# 2. Explorer reads files safely (Explorer cannot modify files)
explore_res = orchestrator.execute_as_role(
    role="explorer",
    tool_name="read_file",
    args={"path": "./workspace/main.py"},
)

# 3. Implementer performs surgical exact edit
edit_res = orchestrator.execute_as_role(
    role="implementer",
    tool_name="edit_file",
    args={
        "path": "./workspace/main.py",
        "target": "return 100",
        "replacement": "return 200",
    },
)

# 4. Verifier gate checks syntax and runs test suite
report = orchestrator.verify_and_heal(test_command="pytest ./workspace/tests")
if not report.passed:
    print("Verification failed! Self-healing step injected:", orchestrator.plan[-1].title)
else:
    print("Task verified and complete!")
```

### 2. Standalone Core Tool Engine

```python
from frontierharness import ToolEngine

engine = ToolEngine(workspace_roots=["./workspace"])

# Atomic write
engine.execute("write_file", {
    "path": "./workspace/app.py",
    "content": "def run():\n    return True\n",
    "overwrite": True,
})

# Supervised command execution
cmd = engine.execute("run_command", {
    "command": "python ./workspace/app.py",
    "timeout_seconds": 15.0,
})
print("Output:", cmd.output)
```

### 3. Interactive CLI with Live Diffs & Approval Prompts

Run tools interactively in the terminal with human-in-the-loop approval:

```bash
python -m frontierharness run edit_file '{"path": "./main.py", "target": "port = 8080", "replacement": "port = 9000"}' --interactive
```

Output:
```text
Pending edit
main.py  +1 -1
  41 - port = 8080
  41 + port = 9000
Reason: Surgical string edit

Accept this file edit? [y]es / [n]o / [a]lways allow:
```

### 4. Time-Travel Undo & Rewind

Instant rollback of file changes and newly created files to a clean checkpoint:

```bash
# Instant undo of the last step
python -m frontierharness undo

# Rewind to a specific checkpoint ID
python -m frontierharness rewind cp_002_a1b2c3
```

### 5. Configurable Agent Skill System

Manage modular operational skills across your machine. Developers can configure custom machine paths where skills are discovered and saved:

```python
from frontierharness import SkillManager, ToolEngine

# 1. Initialize skill manager with a custom directory on your machine
skills = SkillManager(custom_storage_path="D:/my-agent-skills")

# Or reconfigure dynamically
skills.set_skills_directory("C:/Users/dev/.gemini/config/skills")

# 2. Automatically bind all skill scripts into ToolEngine as callable tools
engine = ToolEngine(skill_manager=skills)

# 3. Generate LLM system prompt addon listing active skills
prompt_context = skills.get_system_prompt_addon()
```

Or manage skills directly via the CLI:

```bash
# List all discovered skills across default or custom paths
python -m frontierharness skills list --path "D:/my-skills"

# Install a new skill folder into machine storage
python -m frontierharness skills install ./new-skill --target "D:/my-skills"
```

---

## Empirical Benchmarks

Measured on Windows 11 / Python 3.11 over 500 iterations:

| Operation | Metric | Latency |
| :--- | :--- | :--- |
| `read_file` (windowed slice) | P50 | ~1.0 ms |
| `write_file` (atomic commit) | P50 | ~2.1 ms |
| `edit_file` (surgical diff) | P50 | ~8.0 ms |
| Dispatch & RBAC overhead | P50 | < 0.05 ms |

Run benchmarks locally:
```bash
python -m frontierharness benchmark
```

---

## License

Licensed under the MIT License. Open-source runtime infrastructure for autonomous AI agents.
