Metadata-Version: 2.4
Name: rh-cli
Version: 0.2.1
Summary: rh — orchestrate an AI research project end to end from the terminal
Author-email: Hitaishi V <hitaishi2222@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/hitaishi2222/research-helper
Project-URL: Repository, https://github.com/hitaishi2222/research-helper
Project-URL: Issues, https://github.com/hitaishi2222/research-helper/issues
Project-URL: Roadmap, https://github.com/hitaishi2222/research-helper/blob/main/ROADMAP.md
Keywords: research,cli,orchestration,agents,skill,literature
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich>=13
Requires-Dist: typer<1,>=0.12
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: pyflakes>=3; extra == "dev"
Dynamic: license-file

# research-helper

**`rh` — orchestrate an AI research project end to end from the terminal.**

[![CI](https://github.com/hitaishi2222/research-helper/actions/workflows/ci.yml/badge.svg)](https://github.com/hitaishi2222/research-helper/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/rh-cli.svg)](https://pypi.org/project/rh-cli/)
[![Python](https://img.shields.io/pypi/pyversions/rh-cli.svg)](https://pypi.org/project/rh-cli/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

`rh` turns a research idea into a gated pipeline — config → intake → environment →
literature → plan → state → implement → critique → manuscript → close — with every
artifact, task, and decision kept in files an agent can read.

The **CLI is the product**. The **skill is additive**: it teaches an AI agent (pi,
Claude, Codex, …) how to drive `rh`, ask the user the right questions, and respect the
gates. Install the CLI, then optionally install the skill globally.

---

## Install

```bash
# once published to PyPI (distribution name: rh-cli, command: rh)
uv tool install rh-cli

# or straight from git
uv tool install git+https://github.com/hitaishi2222/research-helper

# or from a clone
git clone https://github.com/hitaishi2222/research-helper
cd research-helper
uv tool install .
```

`pipx install rh-cli` and `pip install --user rh-cli` work too.
Verify with:

```bash
rh --version
rh describe
```

### Install the skill (optional)

```bash
rh skill install                 # ~/.agents/skills/research-helper/
rh skill install --dest ~/.pi/agent/skills/research-helper   # pi-specific location
```

Pi and other [Agent Skills](https://agentskills.io/specification) clients discover
`~/.agents/skills/` automatically. The skill is bundled in the wheel, so there is
nothing else to download.

---

## Quickstart

```bash
rh init                          # in the project directory; rich wizard with detected options (Enter keep, Tab next, s skip, q finish)
rh init --dry-run                # preview without writing anything, not even the prompt files
rh init --force                  # archive a copy of env.json/tasks.json to .rh/.bak/ before writing
rh init --clean                   # archive the whole .rh/ (event logs, notes) then recreate it
rh env set agents.count=2 agents.backend=tmux agents.cli=pi \
  agents.skills=research-helper,crw literature.search=crw \
  literature.library=papr project.git=true
rh env show                 # config as a table, validated
rh tasks phase 4            # gated: refuses to skip unmet exits
rh tasks phase              # what the current phase still needs
rh describe                 # the map an agent reads
rh resume --dry-run         # the exact command the orchestrator would start
rh spawn researcher "implement S07 of PLAN.md"
rh info PLAN.md             # what that file is for, its sections, its template
```

The Orchestrator (your agent) interviews you for the environment and writes
`.rh/ENVIRONMENT.md`; `rh` never probes or auto-fills binaries. `rh init` also
writes your role files and `.rh/CHECKLIST.md` — the Orchestrator's to-do list.
A tool on `PATH` does not mean this project should use it.

---

## Commands

| Command | What it does |
|---|---|
| `rh init [--force] [--clean] [--dry-run]` | create the `.rh/` workspace **here** — `env.json`, `.rh/agents/*.md`, `.rh/CHECKLIST.md`, an empty `.rh/HANDOFF.md` — non-destructively (archives before writing or removing); the project name is the directory, changeable with `rh env set project.name=` |
| `rh env show` | print config as a table + `.rh/ENVIRONMENT.md` notes, validate |
| `rh env set KEY=VALUE ...` | set any key from the §2 schema (`rh env list`) |
| `rh env list` | every settable key, type, choices, help |
| `rh add note <heading> [-m BODY] [--file NAME]` | create/append a note file |
| `rh add literature <DOI-or-heading> [-m BODY]` | append under that DOI/heading in `LITERATURE.md` |
| `rh add layout <heading> [-m BODY]` | append to `OUTPUT_LAYOUT.md` (patterns + our layout) |
| `rh add gaps\|problem\|plan\|status\|manuscript <heading> [-m BODY]` | same for the other artifacts |
| `rh add log --role R --title T [-m BODY]` | §7 log file |
| `rh add task "title" [--id S01] [--phase N] [--owner ROLE] [--state idle\|working\|complete\|cancelled] [--verify CMD] [--deliverable FILE] [--depends-on S01,S02] [--kind build\|spike]` | add a board task |
| `rh search <query> [--max N]` | rg-first local search over `.rh/` + artifacts |
| `rh tasks set <id> <idle\|working\|complete\|cancelled>` | change a task or subtask state (`cancelled` = plan killed by a later finding) |
| `rh tasks info <id> [--json]` | one task or subtask in full: phase, owner, state, deliverable, verify, risk, timebox, dependencies, subtasks, timestamps |
| `rh tasks rm <id> [--force]` | drop a task (with its subtasks) or one subtask; refuses `working` work and tasks others depend on unless `--force`; ids are never renumbered |
| `rh tasks reorder <id> (--before \| --after) <id>` | move a task inside its phase; list order is display order. Hand-editing `.rh/tasks.json` for removal/reordering is allowed after user approval (valid JSON, ids and `current_phase` untouched) |
| `rh tasks [--phase N] [--state S] [--cancelled]` | the board: every task + subtask, state, progress bars; cancelled tasks are counted in one footer line — `-c`/`--cancelled` shows them |
| `rh tasks phase [0-9]` | show the current phase and its exit gate, or set the phase — **gated**; `--force` records a waiver |
| `rh status` | header, phase rail, per-phase progress |
| `rh workflow` | display the agent-authored `.rh/workflow.mmd` as ASCII (`--tools`, `--example`, `--png`, `--svg`) |
| `rh resume` / `rh -r` | run the orchestrator **in this terminal** — command from `agents.commands.orchestrator` (wiring `.rh/agents/orchestrator.md` in as the system prompt), only `agents.skills` loaded; opens with the skill read and does not echo the prompt |
| `rh spawn <role> [prompt]` | open another role agent (`literature`, `researcher`, `reviewer`, `critique`, `writer` or your own) with the command written in `.rh/env.json`; `--inline`, `--dry-run`, `--prompt-file`, `--split` |
| `rh spawn terminal <cmd>` | open a plain shell terminal in a new pane (shell from `agents.shell`/`$SHELL`, layout from `agents.split`); `--dry-run`, `--split` |
| `rh agent list` / `rh agent info <role>` / `rh agent write [role]` | the per-role files in `.rh/agents/` (the only role description — no role info is hardcoded in `rh`); `info` renders the file, `write` creates missing starter roles without overwriting an edited one |
| `rh agent status` | who is running, on which model, from `.rh/logs/spawns.jsonl` |
| `rh handoff` / `rh handoff --clear` | show the handoff the Orchestrator wrote for the next session (`.rh/HANDOFF.md`), or empty it after reading; empty at `rh init`, never generated from `STATUS.md`/`PLAN.md` |
| `rh info [FILE]` | what that artifact is for: owner, phase, sections, template, rules (`--json`, `--template`) |
| `rh skill install [--dest DIR] [--force]` | install the bundled skill globally |
| `rh describe [--json]` | the AI map: layout, phases, env keys, artifacts, spawn, budget |

Global flags (before or after the subcommand): `--root DIR`, `--json`; `--version` prints the release.
`rh -t` is `rh tasks`; `rh -r` is `rh resume`.
A wrong command or flag prints the full `--help`, nothing else (exit 2).
Every command supports `--json` for agent reads — never parse the pretty UI.

---

## Launching agents (nothing hardcoded)

`rh` does not know any agent CLI's flags. The commands live in `.rh/env.json`, and
`rh` substitutes placeholders into them:

```bash
rh env set \
  'agents.roles.orchestrator={"provider":"pi","model":"glm-5","thinking":"high"}' \
  'agents.commands.orchestrator=pi --model {model} --thinking {thinking} --append-system-prompt {agent_file} {prompt}' \
  'agents.spawn=tmux new-window -n rh-{project}-{agent} -c {root} {command}'
rh resume            # → pi --model glm-5 --thinking high --append-system-prompt .rh/agents/orchestrator.md "Load the `research-helper` skill now…"
rh spawn researcher "read S07 and implement it"
```

Placeholders: `{role} {agent} {prompt} {prompt_file} {root} {name} {project} {provider}
{model} {thinking} {skills}`, plus `{command}` in `agents.spawn`. A template that
omits `{model}`/`{thinking}`/`{skills}` still runs — `rh` warns that your env.json
is not being honoured instead of guessing a flag.
`{project}` is the project-name slug: name every pane `rh-<project>-<role>`, so two
projects running at the same time never collide.

**Pane backends are data, not flags you have to know.** `agents.backend` picks
one, and `rh spawn` resolves the pane command in this order:

1. `agents.spawn` — your own template, always wins;
2. the backend's shipped template, when `agents.spawn` is blank:

| backend | template |
|---|---|
| `tmux` | `tmux new-window -n rh-{project}-{role} -c {root} {command}` (needs a running tmux server, i.e. call it from inside tmux) |
| `tuios` | `tuios new-window -s "$TUIOS_SESSION" rh-{project}-{role} --cwd {root} --no-focus --keep-open -- {command}` (inside a tuios pane; elsewhere replace `$TUIOS_SESSION` with `tuios ls`'s name) |
| `herdr` | `herdr pane split --json` then `herdr pane run <new pane> {command}` — herdr has no create-pane-with-command call, so the shipped line decodes the split's pane id with `python3`; edit it if your herdr differs |

3. otherwise a detached process whose output goes to `.rh/logs/`.

The templates live in `harnesses.json` inside the package, so correcting one is a
config/package edit, not a code change. `rh doctor` reports a missing backend
binary and whether the pane command will come from your template or the backend.
Ready-made scripts and per-role prompt templates live in [`examples/`](examples/README.md).


---

## How it works

```
0 CONFIG → 1 INTAKE → 2 ENVIRONMENT → 3 LITERATURE → 4 PLAN → 5 STATE
        → 6 IMPLEMENT → 7 CRITIQUE → 8 MANUSCRIPT → 9 CLOSE
                            ↑            │
                            └── replan ──┘
```

Each phase has an **exit gate**; `rh tasks phase` refuses to advance past an unmet one.
State lives in plain files, not a database:

```
<project>/
  .rh/                env.json, ENVIRONMENT.md, CHECKLIST.md, HANDOFF.md, agents/, logs, tasks
  src/                implementation
  results/            every number + the script that produced it
  papers/             downloaded PDFs (papr/Zotero or by hand; kept, never deleted by rh)
  PROBLEM.md          purpose, goal, scope, success criteria, falsifier
  OUTPUT_LAYOUT.md    output skeleton + patterns from comparable papers
  PLAN.md             approved steps
  STATUS.md           truth
  LITERATURE.md       paper takes with DOI
  GAPS.md             implementation sourcing + upstream gaps
  MANUSCRIPT.md       write-up
```

`.rh/env.json` is the single config file — `rh env set` writes it, `rh env show`
reads it. `.rh/ENVIRONMENT.md` holds the phase-2 environment notes, and
`.rh/CHECKLIST.md` is the Orchestrator's generated to-do list.

---

## The skill (additive)

`src/rh/skills/research-helper/SKILL.md` is the agent-facing half of the project.
It defines the phases, roles, gates, templates, and the ask-before list. The CLI
does not need it; the skill does not need to reimplement the CLI.

```bash
rh skill install
```

What the skill adds:

- **Roles** — Orchestrator (always the current runner), Literature, Researcher,
  Reviewer, Critique, Writer, with a budget mapping for 1–4 parallel agents, and
  `rh spawn <role>` to put one of them to work with the command from `env.json`.
- **Gates** — user approves the plan, critique veto, "no result without a file".
- **Templates** — `.rh/ENVIRONMENT.md`, `STATUS.md`, `OUTPUT_LAYOUT.md`, `PLAN.md` steps, logs —
  the same descriptions `rh info <FILE>` prints, so an agent can check before writing.
- **Reading discipline** — one layout, a pattern tally, DOI anchors, no paraphrasing
  unread papers.

---

## Development

```bash
uv sync --extra dev         # .venv with pytest, pyflakes and build
uv run pytest -q
uv run pyflakes src/rh tests
uv build                     # sdist + wheel in dist/
uv tool install dist/*.whl   # smoke-test the installed command
```

`uv run` uses the project `.venv`. If the dev extra is not synced, `uv run pytest`
falls back to a `pytest` on `PATH`, which can import an already-installed `rh`
instead of this checkout — a green run that tested the wrong code. Sync first, and
check `uv run python -c "import rh; print(rh.__file__)"` when in doubt.

Layout:

```
pyproject.toml
src/rh/                 the CLI package
src/rh/skills/          the bundled skill (package data)
tests/                  pytest smoke tests
examples/               agent-facing spawn scripts + role prompt templates
docs/IDEA.md            original design notes
ROADMAP.md              where this is going
```

---

## Roadmap

See [ROADMAP.md](ROADMAP.md). Short version: publish to PyPI, harden the CLI,
then add real agent orchestration.

## License

[MIT](LICENSE) © 2026 Hitaishi V
