Skip to content

Commit e4dfdaa

Browse files
Kasper Jungeclaude
authored andcommitted
docs: add module and dataclass docstrings for contributors who want to understand the codebase
All 10 source modules now have module-level docstrings explaining their purpose. The 5 key dataclasses (Check, CheckResult, Context, ContextResult, Instruction) have docstrings documenting their fields and behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6ebdc77 commit e4dfdaa

10 files changed

Lines changed: 107 additions & 0 deletions

File tree

src/ralphify/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Ralphify — a minimal harness for running autonomous AI coding loops.
2+
3+
Exposes the ``ralph`` CLI entry point and the package version.
4+
"""
5+
16
from importlib.metadata import PackageNotFoundError, version
27

38
try:

src/ralphify/_frontmatter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""Parse YAML frontmatter from primitive markdown files and discover primitives.
2+
3+
All three primitive types (checks, contexts, instructions) store their
4+
configuration in markdown files with ``---``-delimited frontmatter.
5+
This module provides the shared parsing and directory-scanning logic.
6+
7+
HTML comments in the body are stripped so users can leave notes that
8+
don't leak into the assembled prompt.
9+
"""
10+
111
import re
212
from collections.abc import Iterator
313
from pathlib import Path

src/ralphify/_output.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Combine and truncate subprocess output for prompt injection.
2+
3+
Output from checks and contexts is capped at :data:`MAX_OUTPUT_LEN`
4+
characters (5 000) to avoid blowing up the agent's context window.
5+
"""
6+
17
from __future__ import annotations
28

39
MAX_OUTPUT_LEN = 5000

src/ralphify/_runner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Execute shell commands and scripts with timeout and output capture.
2+
3+
Used by checks and contexts to run their configured command or ``run.*``
4+
script. All commands run with ``cwd`` set to the project root, regardless
5+
of where the primitive directory is located.
6+
"""
7+
18
from __future__ import annotations
29

310
import shlex

src/ralphify/checks.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""Discover and run validation checks after each loop iteration.
2+
3+
Checks are scripts or commands in ``.ralph/checks/<name>/`` that validate
4+
the agent's work (tests, linters, type checkers). When a check fails its
5+
output and failure instruction are formatted for injection into the next
6+
iteration's prompt, creating a self-healing feedback loop.
7+
"""
8+
19
import warnings
210
from dataclasses import dataclass
311
from pathlib import Path
@@ -9,6 +17,13 @@
917

1018
@dataclass
1119
class Check:
20+
"""A validation check discovered from ``.ralph/checks/<name>/CHECK.md``.
21+
22+
Either *command* or *script* must be set. If both exist, *script* wins.
23+
The *failure_instruction* (body text from CHECK.md) is appended to the
24+
prompt when the check fails, guiding the agent toward a fix.
25+
"""
26+
1227
name: str
1328
path: Path
1429
command: str | None
@@ -20,6 +35,12 @@ class Check:
2035

2136
@dataclass
2237
class CheckResult:
38+
"""Outcome of running a single :class:`Check`.
39+
40+
*passed* is ``True`` when the command exits with code 0.
41+
*exit_code* is ``-1`` when the check timed out.
42+
"""
43+
2344
check: Check
2445
passed: bool
2546
exit_code: int

src/ralphify/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""CLI commands for ralphify — init, run, status, and scaffold new primitives.
2+
3+
This is the main module. The ``run`` command implements the core autonomous
4+
loop: read prompt, resolve contexts and instructions, pipe to the agent,
5+
run checks, and repeat.
6+
"""
7+
18
import shutil
29
import subprocess
310
import sys

src/ralphify/contexts.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Discover and run dynamic data contexts injected before each iteration.
2+
3+
Contexts live in ``.ralph/contexts/<name>/`` and provide fresh data to the
4+
prompt each loop — for example recent git history or current test status.
5+
A context can run a command/script, provide static text, or both.
6+
"""
7+
18
from dataclasses import dataclass
29
from pathlib import Path
310

@@ -9,6 +16,13 @@
916

1017
@dataclass
1118
class Context:
19+
"""A dynamic data context discovered from ``.ralph/contexts/<name>/CONTEXT.md``.
20+
21+
A context may have a *command* or *script* (whose stdout is captured),
22+
*static_content* (the body text from CONTEXT.md), or both. When both
23+
are present the static content appears first, followed by the command output.
24+
"""
25+
1226
name: str
1327
path: Path
1428
command: str | None = None
@@ -20,6 +34,13 @@ class Context:
2034

2135
@dataclass
2236
class ContextResult:
37+
"""Outcome of running a single :class:`Context`.
38+
39+
*output* contains the command's stdout (empty string for static-only
40+
contexts). *success* is ``True`` when the command exits with code 0
41+
or when no command was configured.
42+
"""
43+
2344
context: Context
2445
output: str
2546
success: bool

src/ralphify/detector.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""Auto-detect project type from manifest files.
2+
3+
Used during ``ralph init`` to report the detected language ecosystem.
4+
Checks for common manifest files (package.json, pyproject.toml, etc.)
5+
and returns a short label like "python" or "node".
6+
"""
7+
18
from pathlib import Path
29

310

src/ralphify/instructions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""Discover and resolve static instruction text injected into each prompt.
2+
3+
Instructions are reusable rules in ``.ralph/instructions/<name>/`` that get
4+
injected into the prompt every iteration — for example coding standards or
5+
git conventions. Unlike contexts, they have no command; their content is
6+
the body text of the INSTRUCTION.md file.
7+
"""
8+
19
from dataclasses import dataclass
210
from pathlib import Path
311

@@ -7,6 +15,12 @@
715

816
@dataclass
917
class Instruction:
18+
"""A static instruction discovered from ``.ralph/instructions/<name>/INSTRUCTION.md``.
19+
20+
The *content* is the body text below the frontmatter. Instructions with
21+
empty content are silently excluded from prompt injection even if enabled.
22+
"""
23+
1024
name: str
1125
path: Path
1226
enabled: bool = True

src/ralphify/resolver.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""Template placeholder resolution shared by contexts and instructions.
2+
3+
Handles three placement strategies:
4+
5+
1. **Named** — ``{{ kind.name }}`` inserts a specific primitive's content.
6+
2. **Bulk** — ``{{ kind }}`` inserts all remaining primitives (alphabetically).
7+
3. **Implicit** — when no placeholders exist, all content is appended to the end.
8+
"""
9+
110
import re
211

312

0 commit comments

Comments
 (0)