Skip to content

[limen RESOLVE-organvm-i-theoria-rules-system-bound-8] resolve rules-system-bound#8 (UNSTABLE) - #9

Merged
4444J99 merged 3 commits into
mainfrom
limen/resolve-organvm-i-theoria-rules-system-bound-8-29bc
Jul 6, 2026
Merged

4444J99 merged 3 commits into
mainfrom
limen/resolve-organvm-i-theoria-rules-system-bound-8-29bc

Conversation

@4444J99

@4444J99 4444J99 commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Autonomous limen dispatch of task RESOLVE-organvm-i-theoria-rules-system-bound-8.

Resolve blocked PR #8 ('[limen GH-organvm-i-theoria-rules-system-bound-2] ACTIVATION'), state=UNSTABLE. Branch=limen/gh-organvm-i-theoria-rules-system-bound-2-26b9, base=main. In the worktree: git fetch origin limen/gh-organvm-i-theoria-rules-system-bound-2-26b9 main; git checkout -B limen/gh-organvm-i-theoria-rules-system-bound-2-26b9 origin/limen/gh-organvm-i-theoria-rules-system-bound-2-26b9; git rebase origin/main then address the failing checks / unresolved review threads; run the build/tests; git push --force-with-lease origin limen/gh-organvm-i-theoria-rules-system-bound-2-26b9. If the branch is unrecoverable, instead REBUILD the same feature cleanly off origin/main as a fresh PR. Goal: make it mergeable.

Produced in an isolated worktree off origin — review before merge.

Summary by Sourcery

Introduce a runnable command-line interface and improve configuration handling for the rules-system-bound package.

New Features:

  • Add a command-line interface with demo, audit, and version subcommands, including module execution via python -m rules_system_bound.
  • Expose a demo routine that exercises containment, interaction, and idealization paths and an activation audit report describing the package release surface.

Bug Fixes:

  • Ensure configuration values loaded from environment variables are coerced to the correct types instead of remaining as strings.

Enhancements:

  • Document project URLs and define a console script entry point in pyproject.toml for the rules-system-bound CLI.
  • Configure pytest to include the src directory on PYTHONPATH for test discovery and execution.

Tests:

  • Add tests to verify environment-based configuration preserves field types.
  • Add tests covering the CLI activation report, demo report behavior, and top-level CLI commands, including default invocation behavior.

@sourcery-ai

sourcery-ai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Adds a typed environment configuration coercion helper and corresponding tests, introduces a fully featured CLI (with activation and demo commands) and main entry point, and wires the package up as a console script with pytest configuration and project metadata updates.

Sequence diagram for the new CLI command handling in main

sequenceDiagram
    actor User
    participant Console as rules-system-bound
    participant Module as __main__
    participant CLI as main
    participant Parser as build_parser
    participant Activation as build_activation_report
    participant Demo as build_demo_report

    User->>Console: invoke (demo|audit|version|no command)
    Console->>Module: python -m rules_system_bound
    Module->>CLI: main(argv)
    CLI->>Parser: build_parser()
    Parser-->>CLI: argparse.ArgumentParser
    CLI->>CLI: parse_args(argv)

    alt command == version
        CLI->>CLI: print(__version__)
        CLI-->>Console: exit 0
    else command == audit
        CLI->>Activation: build_activation_report()
        Activation-->>CLI: activation_report
        CLI->>CLI: _print_activation_report(activation_report, args.json)
        CLI-->>Console: exit 0
    else command in {None, demo}
        CLI->>Demo: build_demo_report()
        Demo-->>CLI: demo_report
        CLI->>CLI: _print_report(demo_report, args.json)
        CLI-->>Console: exit 0
    else unknown command
        CLI->>CLI: parser.error(...)
        CLI-->>Console: exit 2
    end
Loading

File-Level Changes

Change Details Files
Ensure configuration values loaded from the environment are coerced to the types of their defaults instead of remaining raw strings.
  • Introduce a _coerce_env_value helper that converts string env values into bool, float, int, or leaves them as strings based on the default value type.
  • Update Config.from_env to read raw environment values and apply the coercion helper, falling back to defaults when no env var is set.
  • Add a test that verifies containment_function_weight becomes a float and level_names_emerge becomes a bool when set via environment variables.
src/rules_system_bound/config.py
tests/test_core.py
Add a command-line interface that exposes activation audit and demo runs, plus a main entry point, and test coverage.
  • Create cli module implementing build_activation_report and build_demo_report that exercise core container, interaction, and idealization logic and format results as JSON or human-readable text.
  • Define an argparse-based CLI with subcommands demo, audit, and version, where demo is the default when no subcommand is provided, and implement main() to dispatch and return exit codes.
  • Add tests for activation report contents, demo report behavior over containment/interaction/idealization, JSON audit output, and default demo execution.
  • Add a main module that delegates to cli.main for python -m rules_system_bound execution.
src/rules_system_bound/cli.py
src/rules_system_bound/__main__.py
tests/test_cli.py
Expose the package as an installable console script and document repository metadata while adjusting test configuration for local src imports.
  • Extend pyproject.toml with project.urls metadata and a rules-system-bound console script entry pointing at rules_system_bound.cli:main.
  • Configure pytest to include src in pythonpath so tests can import rules_system_bound without installation.
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@4444J99, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b231331-328e-424e-8285-8ccc6afef6c0

📥 Commits

Reviewing files that changed from the base of the PR and between bf80987 and 14039af.

📒 Files selected for processing (7)
  • .github/workflows/ci-python.yml
  • pyproject.toml
  • src/rules_system_bound/__main__.py
  • src/rules_system_bound/cli.py
  • src/rules_system_bound/config.py
  • tests/test_cli.py
  • tests/test_core.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch limen/resolve-organvm-i-theoria-rules-system-bound-8-29bc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In Config.from_env, _coerce_env_value can raise ValueError without indicating which environment variable was problematic; consider catching and re-raising with the env var name included to make misconfiguration easier to diagnose in deployment.
  • In cli.main, the return 2 after parser.error(...) is unreachable because parser.error exits via SystemExit; you can drop the explicit return (or raise directly) to make the control flow clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Config.from_env`, `_coerce_env_value` can raise `ValueError` without indicating which environment variable was problematic; consider catching and re-raising with the env var name included to make misconfiguration easier to diagnose in deployment.
- In `cli.main`, the `return 2` after `parser.error(...)` is unreachable because `parser.error` exits via `SystemExit`; you can drop the explicit return (or raise directly) to make the control flow clearer.

## Individual Comments

### Comment 1
<location path="src/rules_system_bound/cli.py" line_range="188-192" />
<code_context>
+        _print_activation_report(build_activation_report(), args.json)
+        return 0
+
+    if args.command in {None, "demo"}:
+        _print_report(build_demo_report(), getattr(args, "json", False))
+        return 0
+
+    parser.error(f"unknown command: {args.command}")
+    return 2
</code_context>
<issue_to_address>
**suggestion:** The `parser.error` call already exits, so the subsequent `return 2` is dead code and the explicit unknown-command branch may never be hit in normal CLI use.

Given that `argparse` already treats unknown subcommands as `invalid choice` before reaching this point, this branch only matters if `main()` is called programmatically with a custom `Namespace`. If that’s not a supported scenario, you can remove the branch entirely. If it is, consider replacing `parser.error(...)` with a direct `print(..., file=sys.stderr)` plus `return 2` to make the behavior explicit and avoid additional `SystemExit` handling.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +188 to +192
if args.command in {None, "demo"}:
_print_report(build_demo_report(), getattr(args, "json", False))
return 0

parser.error(f"unknown command: {args.command}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The parser.error call already exits, so the subsequent return 2 is dead code and the explicit unknown-command branch may never be hit in normal CLI use.

Given that argparse already treats unknown subcommands as invalid choice before reaching this point, this branch only matters if main() is called programmatically with a custom Namespace. If that’s not a supported scenario, you can remove the branch entirely. If it is, consider replacing parser.error(...) with a direct print(..., file=sys.stderr) plus return 2 to make the behavior explicit and avoid additional SystemExit handling.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a command-line interface for the package, adds module execution entry points, and implements environment variable type coercion for configuration loading. The review feedback suggests improving the robustness of environment variable parsing by gracefully handling empty or whitespace-only values, expanding test coverage to verify this fallback behavior, and simplifying the CLI's command dispatch logic by removing redundant checks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +76 to +77
value = os.getenv(env_key)
config[key] = default if value is None else _coerce_env_value(value, default)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When loading configuration from environment variables, empty or whitespace-only values (e.g., KEY=) can cause _coerce_env_value to raise a ValueError (for example, when trying to parse an empty string as a float or boolean). Gracefully falling back to the default value when the environment variable is empty or whitespace-only improves robustness, especially in containerized or CI/CD environments where variables are often defined but left empty.

Suggested change
value = os.getenv(env_key)
config[key] = default if value is None else _coerce_env_value(value, default)
value = os.getenv(env_key)
if value is None or value.strip() == "":
config[key] = default
else:
config[key] = _coerce_env_value(value, default)

Comment thread tests/test_core.py
Comment on lines +203 to +211
def test_config_from_env_preserves_types(self, monkeypatch):
"""Environment values are coerced into config field types."""
monkeypatch.setenv("CONTAINMENT_FUNCTION_WEIGHT", "0.7")
monkeypatch.setenv("LEVEL_NAMES_EMERGE", "false")

config = Config.from_env()

assert config.containment_function_weight == 0.7
assert config.level_names_emerge is False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Expand the environment configuration test to verify that empty or whitespace-only environment variables are ignored and correctly fall back to their default values.

Suggested change
def test_config_from_env_preserves_types(self, monkeypatch):
"""Environment values are coerced into config field types."""
monkeypatch.setenv("CONTAINMENT_FUNCTION_WEIGHT", "0.7")
monkeypatch.setenv("LEVEL_NAMES_EMERGE", "false")
config = Config.from_env()
assert config.containment_function_weight == 0.7
assert config.level_names_emerge is False
def test_config_from_env_preserves_types(self, monkeypatch):
"""Environment values are coerced into config field types."""
monkeypatch.setenv("CONTAINMENT_FUNCTION_WEIGHT", "0.7")
monkeypatch.setenv("LEVEL_NAMES_EMERGE", "false")
monkeypatch.setenv("CONTAINER_FUNCTION", " ")
config = Config.from_env()
assert config.containment_function_weight == 0.7
assert config.level_names_emerge is False
assert config.container_function == "function"

Comment on lines +188 to +193
if args.command in {None, "demo"}:
_print_report(build_demo_report(), getattr(args, "json", False))
return 0

parser.error(f"unknown command: {args.command}")
return 2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since argparse subparsers restrict the command choices to only the registered subparsers, args.command is guaranteed to be either "version", "audit", "demo", or None. Since "version" and "audit" are already handled and return early, any execution reaching this point is guaranteed to be "demo" or None. We can simplify this block and remove the redundant check and unreachable code.

    _print_report(build_demo_report(), getattr(args, "json", False))
    return 0

@llamapreview llamapreview Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review by LlamaPReview

🎯 TL;DR & Recommendation

Recommendation: Request Changes.

This PR introduces a critical launch blocker: the CLI imports __version__ from the package's __init__.py, but that module does not define it, causing an ImportError at runtime for source‑tree execution. Additionally, there are minor maintainability issues in environment variable coercion.

📄 Documentation Diagram

This diagram documents the new CLI activation smoke path, exercising containment, interaction, and idealization flows.

sequenceDiagram
    actor Developer
    participant CLI as rules_system_bound.cli
    participant Containers as Container/ContainmentRules
    participant Interactions as InteractionEmergence
    participant Idealization as IdealizationManager
    participant Config as Config
    Developer->>CLI: main(["--json"])
    CLI->>CLI: build_parser()
    CLI->>CLI: parser.parse_args(argv)
    CLI->>CLI: activation_report()
    activate CLI
    CLI->>Containers: ContainmentRules.compute_containment_score(root, bounded)
    CLI->>Containers: root.can_contain(bounded, rules)
    CLI->>Containers: root.add_child(bounded)
    CLI->>Interactions: InteractionEmergence.register_system(processor)
    CLI->>Interactions: InteractionEmergence.register_system(store)
    CLI->>Interactions: InteractionEmergence.discover_interactions(processor, store)
    CLI->>Idealization: IdealizationManager.create_form(form_id, form_type, name, real_system)
    CLI->>Idealization: IdealizationManager.relate(ideal, root)
    CLI->>Config: Config()
    deactivate CLI
    CLI-->>CLI: report
    CLI->>CLI: json.dumps(report, indent=2, sort_keys=True)
    CLI-->>Developer: JSON activation evidence
    note over CLI: PR introduces deterministic CLI smoke path
Loading
Priority File Category Impact Summary (≤12 words) Anchors
P0 src/rules_system_bound/cli.py Bug CLI crashes at import due to missing __version__. path:src/rules_system_bound/init.py
P2 src/rules_system_bound/config.py Maintainability Bare ValueError on env coercion lacks context. method:Config.from_env
P2 src/rules_system_bound/config.py Maintainability Env variable name not passed to coerce function. -

🔍 Notable Themes

  • Config error handling: Both P2 findings relate to environment variable coercion—errors are unhelpful and hard to debug. A unified fix (passing the key and wrapping exceptions) would strengthen the configuration module.

📈 Risk Diagram

This diagram illustrates the risk that the CLI crashes at import due to missing version in init.py.

sequenceDiagram
    actor Developer
    participant CLI as rules_system_bound.cli
    participant Init as rules_system_bound.__init__
    Developer->>CLI: python -m rules_system_bound demo
    activate CLI
    CLI->>Init: from . import __version__
    Init-->>CLI: ImportError: name '__version__' not defined
    deactivate CLI
    note over CLI,Init: R1(P0): Missing __version__ definition causes ImportError at import time
Loading

💡 Have feedback? We'd love to hear it in our GitHub Discussions.
✨ This review was generated by LlamaPReview Advanced, which is free for all open-source projects. Learn more.

Comment on lines +10 to +11
from . import __version__
from .container import Container, ContainmentRules

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 | Confidence: High

The new cli.py imports __version__ from the parent package (from . import __version__). However, __init__.py does not define __version__. Hatchling does not automatically inject it for source imports, so ImportError is raised at import time. This blocks the entire CLI and any imports of cli.py. Fix by defining __version__ in __init__.py or using importlib.metadata.

Code Suggestion:

__version__ = "0.1.0"

Evidence: path:src/rules_system_bound/init.py

}


def _coerce_env_value(value: str, default: Any) -> Any:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

When an environment variable is present but cannot be coerced to the expected type, _coerce_env_value raises a bare ValueError. This propagates uncaught out of Config.from_env(), causing a non‑descriptive stack trace. Consider catching the exception and re‑raising with a more informative message, or falling back to the default with a warning.

Suggested change
def _coerce_env_value(value: str, default: Any) -> Any:
def _coerce_env_value(key: str, value: str, default: Any) -> Any:
try:
if isinstance(default, bool):
normalized = value.strip().lower()
if normalized in {"1", "true", "yes", "on"}:
return True
if normalized in {"0", "false", "no", "off"}:
return False
raise ValueError(f"Invalid boolean value: {value!r}")
if isinstance(default, float):
return float(value)
if isinstance(default, int):
return int(value)
return value
except ValueError as exc:
raise ConfigError(
f"Environment variable '{key.upper()}' = {value!r} "
f"cannot be coerced to type {type(default).__name__}. "
f"Expected a {type(default).__name__} value."
) from exc

Evidence: method:Config.from_env

Comment on lines +76 to +77
value = os.getenv(env_key)
config[key] = default if value is None else _coerce_env_value(value, default)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: Medium

The _coerce_env_value function currently receives only the string value and the default; it does not receive the environment variable name. When coercion fails, the error message cannot mention which variable caused the problem. Pass the key as well (as suggested in the previous finding) and add a test for the error path.

Code Suggestion:

def test_config_env_coercion_failure_raises_meaningful_error(monkeypatch):
    monkeypatch.setenv("LEVEL_NAMES_EMERGE", "not_a_bool")
    with pytest.raises(ValueError, match="LEVEL_NAMES_EMERGE"):
        Config.from_env()

@4444J99
4444J99 enabled auto-merge (squash) June 19, 2026 13:18
4444J99 and others added 3 commits July 6, 2026 16:47
limen task RESOLVE-organvm-i-theoria-rules-system-bound-8
Adds .github/workflows/ci-python.yml with test job matrix (3.10/3.11/3.12).
Required branch protection checks are test(3.10), test(3.11), test(3.12).
Actions pinned to commit SHAs per org policy:
  actions/checkout@v4 -> 11bd71901bbe5b1630ceea73d27597364c9af683 (v4.2.2)
  actions/setup-python@v5 -> a26af69be951a213d495a4c3e4e4022e16d87065 (v5.6.0)
@4444J99
4444J99 force-pushed the limen/resolve-organvm-i-theoria-rules-system-bound-8-29bc branch from 14039af to 6ceb92d Compare July 6, 2026 20:48
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@4444J99
4444J99 merged commit e45411d into main Jul 6, 2026
8 checks passed
@4444J99
4444J99 deleted the limen/resolve-organvm-i-theoria-rules-system-bound-8-29bc branch July 6, 2026 20:49
4444J99 added a commit that referenced this pull request Jul 6, 2026
limen task HEAL-rebase-organvm-rules-system-bound-9

Co-authored-by: 4444J99 <4444J99@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant