Files
rengine/tools/runner/models.py
T
Yogesh OjhaandClaude Opus 5 2cb8d73280 style: strip explanatory comments across the codebase
The comment rule in CLAUDE.md is one line maximum, never narration: no
multi-line blocks, no module-header explainers, no sentences that explain or
justify the code to the reader. The tree had drifted a long way from it, and
most of the drift is mine.

Removed:
  232  lines of multi-line comment blocks
  203  single-line comments that argued instead of stating
  154  comments joined by so/because/otherwise/rather-than
  143  narrating comments in the frontend
  112  test docstrings (the test name already says what it asserts)
   25  test module docstrings and 25 decorative section dividers

Collapsed:
  324  multi-line docstrings to one factual line
  271  one-line docstrings that had a justifying clause bolted on

Kept: functional directives, section dividers, short field labels, alembic
revision headers, and the eight FastAPI route docstrings that render in /docs.
Where a fact was load-bearing it is in CLAUDE.md, which is where it belongs.

284 python tests and 34 frontend tests pass, ruff and ruff-format clean across
ten packages, svelte-check 0 errors, prettier and eslint clean, app.main imports.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013dKUV96WkQQETZBMoAG98C
2026-09-11 14:11:23 +05:30

67 lines
1.5 KiB
Python

"""Tool-agnostic models for CLI tool execution results."""
from collections.abc import Iterator
from dataclasses import dataclass
from enum import Enum
from typing import Any, Protocol, runtime_checkable
from pydantic import BaseModel, Field
class OutputFormat(Enum):
"""Output format expected from the CLI tool."""
JSONL = "jsonl"
PLAIN = "plain"
@runtime_checkable
class CommandRecorder(Protocol):
"""Optional hook the executor calls to register a command and capture its log."""
def start(self, tool: str, command: str) -> Any: ...
def finish(
self,
handle: Any,
*,
return_code: int,
output: str,
error: str | None,
duration_seconds: float,
) -> None: ...
class ToolResult(BaseModel):
"""Result of a CLI tool execution."""
success: bool
stdout: str = ""
stderr: str = ""
exit_code: int = -1
output_lines: list[str] = Field(default_factory=list)
json_records: list[dict] = Field(default_factory=list)
duration_seconds: float = 0.0
command: str = ""
error: str | None = None
timed_out: bool = False
@property
def has_output(self) -> bool:
return bool(self.json_records or self.output_lines)
@dataclass
class StreamOutcome:
"""How a stream_json run ended."""
records: Iterator[dict]
return_code: int = -1
timed_out: bool = False
record_count: int = 0
stderr: str = ""
@property
def ok(self) -> bool:
return self.return_code == 0 and not self.timed_out