Metadata-Version: 2.5
Name: rw-style
Version: 0.4.0
Summary: Add and safely update Python project guidance with uv.
Requires-Python: >=3.11
Requires-Dist: platformdirs>=4.0
Description-Content-Type: text/markdown

# rw-style

A Python CLI for adding and safely updating project guidance. Choose Python,
scripts, dbt, component, and report conventions, with Editorial Reports or
Decision Desk styling and risk-focused verification.

Requires Python 3.11+. [uv](https://docs.astral.sh/uv/) provides the usual isolated
CLI workflow. `platformdirs` supplies portable per-user library paths.

## Start here

Run directly from PyPI:

```sh
uvx rw-style init ../my-project
```

In an interactive terminal, `init` and `add` open a **TUI picker** by default:

- Arrow keys (or j/k) navigate; Space selects; Enter applies.
- Escape or q cancels without changing files.
- Press **?**, **h**, or **F1** for scrollable help; Enter/Escape returns to the
  picker without applying anything. `rw-style help` shows the same content
  without requiring a terminal.
- Core and verification guidance are always included.
- `init` selects a stack, additional guides, a visual profile, and optional tooling.
- `add` shows installed guides and lets you select more without removing them.

The default bundle is **rw-data-stack**: Python + uv, Bun, Playwright, and GitHub
guidance, without requiring React, FastAPI, or another framework. GitHub defaults
recommend private repositories, worktrees for new features, and focused PRs;
they never create repositories or change visibility automatically. Stack defaults
stay checked in the picker. Choose stack `none` for individual guide selections.
dbt and report-specific guides remain opt-in. A stack selects instructions; it
does not install its tools or generate application code.

The picker needs a terminal with curses support (typically Linux/macOS), at least
40 columns × 10 rows. Explicit selection flags or `--no-interactive` skip it.
Non-TTY and `TERM=dumb` runs never prompt.

For a persistent installation, use `uv tool install rw-style`. To pin this
release, use `uvx rw-style@0.4.0 ...`.

From a checkout, use `uv run rw-style` or
`uvx --no-cache --from . rw-style ...`; `--no-cache` avoids reusing an earlier
local tool environment after source edits. Building the repository does not
publish anything automatically.

## Agent-friendly commands

```sh
# Default rw-data-stack guidance, with no prompt or tool changes
uvx rw-style init ../my-project --no-interactive

# Minimal core/testing, plus selected guidance without the default stack
uvx rw-style init ../minimal-project --stack none --guide python

# Explicit choices also bypass the picker
uvx rw-style init ../research-project \
  --guide scripts --guide dbt --guide components --guide reports \
  --profile editorial \
  --style "Keep raw source data unchanged." \
  --verify "uv run pytest tests/reporting -q"

# Add guides later; without --guide, a terminal opens the picker
uvx rw-style add ../my-project --guide scripts --guide dbt

# Refresh installed guidance and change only explicitly supplied settings
uvx rw-style update ../my-project \
  --style "Use type hints on public functions." \
  --verify "uv run pytest -q"

# Switch visual profile without losing the other guides
uvx rw-style update ../research-project --profile decision-desk
```

The path defaults to the current directory. Built-in guide choices are `python`,
`bun`, `playwright`, `github`, `scripts`, `dbt`, `components`, and `reports`; imported guides
use `local:NAME`. Profiles are `editorial` and `decision-desk`.
`add` requires at least one guide when the picker is not used.

Repeat `--style` or `--verify` for multiple entries. On `update`, supplying an
option replaces that entire list; omitted settings are preserved. Verification
commands are **documented, never executed**. Style prose does not configure tools.
Custom commands may need separately installed tools.

`add` preserves installed guide versions; `update` refreshes them from the version
of rw-style being run. Identical additions and unchanged updates are no-ops.

## Local guides and reusable stacks

Import a **trusted, self-contained UTF-8 Markdown file** into a per-user library:

```sh
uvx rw-style guides import ~/Documents/team-style.md --name team-style
uvx rw-style guides list
uvx rw-style init ../team-project --guide local:team-style
uvx rw-style add ../my-project --guide local:team-style
uvx rw-style help
```

There is no upload/server step. `platformdirs.user_data_path("rw-stylizer",
appauthor=False)` stores library data outside uvx's disposable environments.
`guides list` prints the exact path (typically `~/.local/share/rw-stylizer/guides`
on Linux). New library directories/files use private permissions on POSIX.
The public package and command are `rw-style`; the Python module, library paths,
project directory `.rw-stylizer/`, and managed markers retain their legacy names
so existing imports and project setups continue to work without migration.

Imports copy the file; editing the original source does not update the library.
Re-importing the same name refuses to overwrite it. Edit the stored Markdown
instead, then explicitly run `update` in projects that should receive the change.
Projects contain independent, committed copies and no machine-specific paths.
Adding other guides works even without an existing custom guide's source;
refreshing that custom guide requires it to be available under the same local name.
Local guide and project-side edit conflicts are checked before project writes.

Names use lowercase letters/digits/hyphens, start with a letter, and are at most
64 characters. Imports are limited to 1 MiB. Common relative Markdown/HTML links
and file/unsafe URL schemes are rejected: use self-contained text, same-document
anchors, or explicit http/https/mailto links. No assets are copied. These are
portability checks, not a full HTML/CSS/JS sanitizer or renderer. Only import
instructions you trust; agents may follow them.

To define another stack, import its guides first, then a TOML preset:

```toml
description = "Our Rust tooling conventions"
guides = ["local:rust-style"]
```

```sh
uvx rw-style stacks import ~/Documents/rust-stack.toml --name rust
uvx rw-style stacks list
uvx rw-style init ../rust-project --stack local:rust
```

Preset files accept only `description` and `guides`; they cannot execute commands
or install dependencies. They live beside the guide library in `stacks/`.
`local:` names cannot collide with built-ins. Presets are **initial selections**:
their later edits do not silently alter project selections, and project updates
do not require the original preset. Use `add` for more guides; stack migration
and guide removal are not implemented.

## What it changes

Guidance-only mode creates:

```text
AGENTS.md                         # Only a marked section is managed
CLAUDE.md                         # `@AGENTS.md` import; created only if absent
.rw-stylizer/
  state.json                      # Selections and ownership hashes
  testing-strategy.md
  guides/
    core.md
    python.md
    bun.md
    playwright.md
    github.md
    ...selected modules/profile...
    local/
      ...selected custom guides...
```

The managed section opens with a few hard rules (uv-only Python when the Python
guide is selected, data preservation, no hand-edited generated files, a gitignored
`sandbox/`, honest verification) and then links the guides. A new `AGENTS.md`
also gets project-owned Overview, Commands, Layout, Data and secrets, and
Decisions and gotchas headings below the section for agents and people to fill in.

Claude Code reads `CLAUDE.md`, not `AGENTS.md`, so `init` creates a `CLAUDE.md`
containing `@AGENTS.md` when none exists. An existing `CLAUDE.md` (or symlink) is
never modified; the CLI prints a note when it lacks that import.

An existing `AGENTS.md` is retained and receives a managed section. Subsequent
commands preserve all bytes outside that section. Existing tool settings,
dependencies, lockfiles, Git metadata, and application code stay untouched.
Selecting dbt/components/reports does not install their associated tools.

### Optional starter tooling

```sh
uvx rw-style init ../new-project --tooling
# Or add starter tooling to an already initialized project:
uvx rw-style update ../my-project --tooling
```

This explicitly uses uv to initialize a bare Python project if needed, adds Ruff
and pytest as development dependencies, and creates `ruff.toml`/`pytest.ini`.
Ruff uses an 88-character line-length setting and import sorting.
`uv add --dev --frozen ruff pytest` does not sync an environment or resolve a
lockfile. Run `uv sync` in the target afterwards.
The Python guide must be selected; tooling setup does not install Bun or Playwright.

Existing Ruff/pytest configuration causes tooling setup to stop rather than
overwrite or shadow it—even if it came from an earlier rw-stylizer run.
Guidance updates without `--tooling` still work normally.

## Update safety and recovery

- Commit `AGENTS.md` and `.rw-stylizer/`, including `state.json`, with your project.
- Put handwritten rules outside the managed AGENTS section, or supply them through
  `--style`/`--verify`. Do not put secrets in either instructions or metadata.
- Ownership record format 1 is supported and upgraded on update. Existing projects
  retain their guide choices; they do not silently acquire new stack defaults.
  To add GitHub guidance to an older project, use `add --guide github`.
- Direct edits to managed guide files, missing files, or malformed metadata/markers
  block updates. The CLI reports conflicts rather than overwriting or merging.
- To reconcile a local edit, save its useful project-specific rules outside the
  managed section, restore the affected managed files from your known-good project
  revision, then retry. Do not edit ownership hashes just to bypass the check.
- Symlinks at generated output paths are refused. Unknown project files are not
  adopted or removed.
- Run one mutating command per project at a time. Existing files are replaced
  atomically, but the complete operation is not a cross-file transaction. On an
  I/O/uv failure, inspect the reported attempted paths and restore a consistent
  known-good setup before retrying. uv may already have updated `pyproject.toml`.

Exit codes: `0` success/no-op, `1` setup/conflict failure, `2` argument error,
`130` cancellation. Guides are instructions for cooperating agents, not automatic
enforcement. This CLI does not run tests, generate an application, or configure CI.

## Guides and specification

These files are included in the source distribution:

- Guide catalog: `docs/guides/README.md`
- Accepted testing strategy: `docs/testing-strategy.md`
- CLI behavior specification: `docs/cli-spec.md`
- Release notes: `CHANGELOG.md`

The guide files are canonical Markdown sources, packaged into both distribution
formats. Generated project copies are not duplicate templates maintained in Python.

## Develop and verify

```sh
uv sync --locked
uv run rw-style --help
uv run ruff format --check .
uv run ruff check .
uv run pytest -q
uv build
```

The tests include isolated real-uv setup checks without downloads or paid calls.
Packaging verification should also run the built wheel through uvx outside this
checkout. TUI changes require actual terminal inspection; this CLI has no web UI,
so Playwright is for the generated guidance's web/report workflows, not its picker.
