Skip to content

Commit 1229cfa

Browse files
committed
feat: ph shell-hook + harness guard + docs restructure (v0.2.1)
1 parent fc85965 commit 1229cfa

9 files changed

Lines changed: 436 additions & 69 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [0.2.1] - 2026-04-09
8+
9+
### Added
10+
- `ph shell-hook install/uninstall/status` — zero-config auto-wrap for agent commands via shell preexec hook
11+
- Harness existence guard in orchestrator — clearer error when Proposer fails to generate `harness.py`
12+
- 8 new tests (173 total)
13+
14+
### Changed
15+
- README flow diagrams moved to their corresponding modules (Step 4 and Step 6) for better readability
16+
- CLI commands: 22 → 25
17+
718
## [0.2.0] - 2026-04-08
819

920
### Added

README.md

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
1717
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
18-
[![Tests](https://img.shields.io/badge/tests-165%20passing-brightgreen.svg)]()
18+
[![Tests](https://img.shields.io/badge/tests-173%20passing-brightgreen.svg)]()
1919
[![中文文档](https://img.shields.io/badge/文档-中文版-red.svg)](README_CN.md)
2020

2121
---
@@ -242,6 +242,34 @@ ph run
242242

243243
The orchestrator: copies your harness → asks the Proposer agent for a candidate change → evaluates the result → stores everything → repeats.
244244

245+
```
246+
┌──────────────────────────────────────────────────────────────┐
247+
│ │
248+
│ You PolyHarness │
249+
│ │ │ │
250+
│ ├── ph init ──────────────────→│ Creates workspace │
251+
│ │ (harness + tasks + eval) │ Copies files │
252+
│ │ │ Injects CLAUDE.md │
253+
│ │ │ │
254+
│ ├── ph run ───────────────────→│ Starts search loop: │
255+
│ │ │ │
256+
│ │ ┌──────────────────────────┤ │
257+
│ │ │ Step 1: SELECT parent │ Best or Tournament │
258+
│ │ │ Step 2: COPY harness │ From parent → candidate │
259+
│ │ │ Step 3: PROPOSE changes │ Agent reads all history │
260+
│ │ │ Step 4: EVALUATE │ Run tasks, get scores │
261+
│ │ │ Step 5: STORE results │ Code + scores + traces │
262+
│ │ │ Step 6: CHECK stopping │ Improved? Patience left? │
263+
│ │ └──────────┬───────────────┤ │
264+
│ │ └── loop ───────┘ │
265+
│ │ │ │
266+
│ ├── ph log ───────────────────→│ Shows search tree │
267+
│ ├── ph compare 0 5 ──────────→│ Score deltas + code diff │
268+
│ └── ph apply ─────────────────→│ Writes best back │
269+
│ │
270+
└──────────────────────────────────────────────────────────────┘
271+
```
272+
245273
### 5. Inspect and apply
246274

247275
```bash
@@ -325,7 +353,66 @@ ph evolve # trigger evolution manually
325353

326354
> **Tip:** Use `--no-record-output` if you don't want stdout/stderr saved (e.g., for sensitive output). Metadata is always recorded.
327355
328-
> **Tip:** Create a shell alias for even less typing: `alias cc="ph wrap --auto-evolve claude"`
356+
#### Zero-config auto-wrap: `ph shell-hook`
357+
358+
Don't want to type `ph wrap --auto-evolve` every time? Install a shell hook — it auto-intercepts agent commands:
359+
360+
```bash
361+
ph shell-hook install # one-time setup, writes to ~/.zshrc
362+
```
363+
364+
After that, just use your agent as usual:
365+
366+
```bash
367+
claude -p "Refactor auth to JWT" # automatically becomes: ph wrap --auto-evolve claude -p ...
368+
claw -p "Write payment tests" # same — auto-wrapped
369+
codex "Add retry logic" # same
370+
opencode -p "Fix flaky test" # same
371+
```
372+
373+
How it works: a `preexec` hook in your shell detects `claude`/`claw`/`codex`/`opencode` commands and transparently redirects them through `ph wrap --auto-evolve`. Your output is unchanged.
374+
375+
```bash
376+
ph shell-hook status # check if installed
377+
ph shell-hook uninstall # remove cleanly (restores original rc file)
378+
```
379+
380+
#### Auto-Evolution flow
381+
382+
```
383+
┌──────────────────────────────────────────────────────────────┐
384+
│ │
385+
│ You PolyHarness │
386+
│ │ │ │
387+
│ ├── ph shell-hook install ────→ │ Injects preexec hook │
388+
│ │ (one-time setup) │ into ~/.zshrc │
389+
│ │ │ │
390+
│ ├── claude -p "Fix bug" ──────→ │ Shell hook intercepts │
391+
│ │ (normal usage) │ │
392+
│ │ ├── Run agent │
393+
│ │ ┌─ output passes through ──┤ │
394+
│ │ │ ├── Record trace │
395+
│ │ │ │ (~/.polyharness/ │
396+
│ │ │ │ traces/) │
397+
│ │ │ │ │
398+
│ │ │ ├── Check threshold │
399+
│ │ │ │ traces < 50? │
400+
│ │ │ │ ├─ Yes: "7/50 traces" │
401+
│ │ │ │ └─ No: trigger ───┐ │
402+
│ │ │ │ │ │
403+
│ │ │ │ ┌─────────────────┘ │
404+
│ │ │ │ │ Evolution cycle │
405+
│ │ │ │ │ (same as ph run) │
406+
│ │ │ │ │ Propose → Evaluate │
407+
│ │ │ │ │ → Store → Repeat │
408+
│ │ │ │ └────────────────── │
409+
│ │ │ │ │
410+
│ └───┘ │ │
411+
│ │
412+
└──────────────────────────────────────────────────────────────┘
413+
```
414+
415+
The key difference: **you never run `ph run` manually.** You use your agent as always; PolyHarness silently collects data and triggers evolution when it has enough signal.
329416

330417
### Try it now (no API key needed)
331418

@@ -347,35 +434,7 @@ The score path above is the current measured result of the bundled `math-word-pr
347434

348435
## How It Works
349436

350-
PolyHarness runs a **Meta-Harness-style search loop** — an iterative process where an AI agent proposes, evaluates, and stores harness changes:
351-
352-
```
353-
┌──────────────────────────────────────────────────────────────┐
354-
│ │
355-
│ You PolyHarness │
356-
│ │ │ │
357-
│ ├── ph init ──────────────────→│ Creates workspace │
358-
│ │ (harness + tasks + eval) │ Copies files │
359-
│ │ │ Injects CLAUDE.md │
360-
│ │ │ │
361-
│ ├── ph run ───────────────────→│ Starts search loop: │
362-
│ │ │ │
363-
│ │ ┌──────────────────────────┤ │
364-
│ │ │ Step 1: SELECT parent │ Best or Tournament │
365-
│ │ │ Step 2: COPY harness │ From parent → candidate │
366-
│ │ │ Step 3: PROPOSE changes │ Agent reads all history │
367-
│ │ │ Step 4: EVALUATE │ Run tasks, get scores │
368-
│ │ │ Step 5: STORE results │ Code + scores + traces │
369-
│ │ │ Step 6: CHECK stopping │ Improved? Patience left? │
370-
│ │ └──────────┬───────────────┤ │
371-
│ │ └── loop ───────┘ │
372-
│ │ │ │
373-
│ ├── ph log ───────────────────→│ Shows search tree │
374-
│ ├── ph compare 0 5 ──────────→│ Score deltas + code diff │
375-
│ └── ph apply ─────────────────→│ Writes best back │
376-
│ │
377-
└──────────────────────────────────────────────────────────────┘
378-
```
437+
PolyHarness runs a **Meta-Harness-style search loop** — an iterative process where an AI agent proposes, evaluates, and stores harness changes. See the detailed flow diagrams above in [Step 4](#4-run-the-optimization-loop) and [Step 6](#6-auto-evolution).
379438

380439
### Why it works: non-Markovian search
381440

@@ -555,6 +614,9 @@ python -m polyharness --version
555614
| `ph traces stats` | Summary statistics: total traces, scored count, agent distribution |
556615
| `ph traces clear` | Remove collected traces (`--keep N` to retain newest, `-y` to skip confirm) |
557616
| `ph evolve` | Trigger an online evolution cycle using collected traces as context |
617+
| `ph shell-hook install` | Install shell hook to auto-wrap agent commands (claude, claw, codex, opencode) |
618+
| `ph shell-hook uninstall` | Remove the shell hook from your rc file |
619+
| `ph shell-hook status` | Check if the shell hook is installed |
558620
| `ph upgrade` | Upgrade PolyHarness to the latest version |
559621
| `ph uninstall` | Uninstall PolyHarness from the current environment (`-y` to skip confirm) |
560622

@@ -664,7 +726,7 @@ ph run --max-iterations 5
664726
```
665727
polyharness/
666728
├── src/polyharness/
667-
│ ├── cli.py # Click CLI — 22 commands/subcommands
729+
│ ├── cli.py # Click CLI — 25 commands/subcommands
668730
│ ├── config.py # Pydantic config models (+ EvolutionConfig)
669731
│ ├── collector.py # Trace collector for online evolution
670732
│ ├── orchestrator.py # Meta-Harness search loop + progress bar + error recovery
@@ -689,7 +751,7 @@ polyharness/
689751
│ ├── code-generation/
690752
│ ├── rag-qa/
691753
│ └── api-calling/
692-
├── tests/ # 165 tests (pytest)
754+
├── tests/ # 173 tests (pytest)
693755
├── bin/ # npm wrapper (ph.mjs, postinstall.mjs)
694756
├── docs/
695757
│ ├── development/ # Product roadmap & technical architecture

0 commit comments

Comments
 (0)