openreflex 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {openreflex-0.1.2/src/openreflex.egg-info → openreflex-0.1.3}/PKG-INFO +4 -3
  2. {openreflex-0.1.2 → openreflex-0.1.3}/README.md +3 -2
  3. {openreflex-0.1.2 → openreflex-0.1.3}/pyproject.toml +1 -1
  4. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/__init__.py +1 -1
  5. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/hooks.py +40 -2
  6. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/install.py +2 -1
  7. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/privacy.py +28 -4
  8. {openreflex-0.1.2 → openreflex-0.1.3/src/openreflex.egg-info}/PKG-INFO +4 -3
  9. {openreflex-0.1.2 → openreflex-0.1.3}/tests/test_engine.py +17 -0
  10. {openreflex-0.1.2 → openreflex-0.1.3}/tests/test_hooks.py +37 -0
  11. {openreflex-0.1.2 → openreflex-0.1.3}/tests/test_install_cli.py +19 -0
  12. {openreflex-0.1.2 → openreflex-0.1.3}/LICENSE +0 -0
  13. {openreflex-0.1.2 → openreflex-0.1.3}/setup.cfg +0 -0
  14. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/__main__.py +0 -0
  15. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/benchmark.py +0 -0
  16. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/cli.py +0 -0
  17. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/detect.py +0 -0
  18. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/engine.py +0 -0
  19. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/integrations/opencode.ts +0 -0
  20. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/learning.py +0 -0
  21. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/mcp_server.py +0 -0
  22. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/metrics.py +0 -0
  23. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/models.py +0 -0
  24. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/project.py +0 -0
  25. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/routing.py +0 -0
  26. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex/store.py +0 -0
  27. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex.egg-info/SOURCES.txt +0 -0
  28. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex.egg-info/dependency_links.txt +0 -0
  29. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex.egg-info/entry_points.txt +0 -0
  30. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex.egg-info/requires.txt +0 -0
  31. {openreflex-0.1.2 → openreflex-0.1.3}/src/openreflex.egg-info/top_level.txt +0 -0
  32. {openreflex-0.1.2 → openreflex-0.1.3}/tests/test_mcp_metrics_benchmark.py +0 -0
  33. {openreflex-0.1.2 → openreflex-0.1.3}/tests/test_stress.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openreflex
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Muscle memory for AI coding agents: learns from every task, advises the next one, and flags failure loops live
5
5
  Author: vishnu-77
6
6
  License-Expression: MIT
@@ -31,6 +31,7 @@ Requires-Dist: twine>=6; extra == "dev"
31
31
  Dynamic: license-file
32
32
 
33
33
  <div align="center">
34
+ <!-- mcp-name: io.github.vishnu-77/openreflex -->
34
35
 
35
36
  <a href="https://openreflex.cc" target="_blank">
36
37
  <picture>
@@ -124,8 +125,8 @@ OpenReflex installs per project with `openreflex install <agent>`, or as a plugi
124
125
  | Cursor | `openreflex install cursor` |
125
126
  | OpenCode | `openreflex install opencode` |
126
127
 
127
- With a plugin install, enable each project with `openreflex approve`. Claude Code is verified in live sessions;
128
- the Codex, Cursor, and OpenCode integrations follow each agent's documented hook protocol.
128
+ With a plugin install, enable each project with `openreflex approve`. Claude Code and Codex are verified in live
129
+ sessions; the Cursor and OpenCode integrations follow each agent's documented hook protocol.
129
130
 
130
131
  ## How it works
131
132
 
@@ -1,4 +1,5 @@
1
1
  <div align="center">
2
+ <!-- mcp-name: io.github.vishnu-77/openreflex -->
2
3
 
3
4
  <a href="https://openreflex.cc" target="_blank">
4
5
  <picture>
@@ -92,8 +93,8 @@ OpenReflex installs per project with `openreflex install <agent>`, or as a plugi
92
93
  | Cursor | `openreflex install cursor` |
93
94
  | OpenCode | `openreflex install opencode` |
94
95
 
95
- With a plugin install, enable each project with `openreflex approve`. Claude Code is verified in live sessions;
96
- the Codex, Cursor, and OpenCode integrations follow each agent's documented hook protocol.
96
+ With a plugin install, enable each project with `openreflex approve`. Claude Code and Codex are verified in live
97
+ sessions; the Cursor and OpenCode integrations follow each agent's documented hook protocol.
97
98
 
98
99
  ## How it works
99
100
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "openreflex"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "Muscle memory for AI coding agents: learns from every task, advises the next one, and flags failure loops live"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,3 +1,3 @@
1
1
  """Ambient, local execution intelligence."""
2
2
 
3
- __version__ = "0.1.2"
3
+ __version__ = "0.1.3"
@@ -21,6 +21,7 @@ import traceback
21
21
  from dataclasses import dataclass, field
22
22
 
23
23
  from .engine import Engine
24
+ from .privacy import categorize
24
25
  from .project import approval, log_error, project_root, should_notify_unapproved
25
26
 
26
27
  AGENTS = ("claude-code", "codex", "cursor", "opencode")
@@ -72,8 +73,42 @@ def response_failure(response: object) -> tuple[bool, str | None]:
72
73
  return False, None
73
74
  if isinstance(response, str):
74
75
  match = EXIT_CODE.search(response[:400])
75
- if match and int(match.group(1)) != 0:
76
- return True, response[:4000]
76
+ if match:
77
+ return int(match.group(1)) != 0, response[:4000] if int(match.group(1)) != 0 else None
78
+ return False, None
79
+
80
+
81
+ # Summary lines that tools print when a run fails. Codex reports shell results as plain output with no exit
82
+ # code, so for verification commands the output itself is the only failure signal.
83
+ OUTPUT_FAILURE = re.compile(
84
+ r"(?im)"
85
+ r"\b\d+ (failed|errors?)\b.*\bin \d" # pytest summary: "1 failed, 2 passed in 0.1s"
86
+ r"|^={3,} (FAILURES|ERRORS) ={3,}" # pytest sections
87
+ r"|^FAILED \((failures|errors)=" # unittest
88
+ r"|^Tests?:\s+\d+ failed" # jest / vitest
89
+ r"|^(--- )?FAIL\b" # go test, jest file lines
90
+ r"|test result: FAILED" # cargo test
91
+ r"|error(\[E\d+\])?: could not compile|^error\[E\d+\]" # rustc
92
+ r"|\berror TS\d+:" # tsc
93
+ r"|✖ \d+ problems?" # eslint
94
+ r"|^Found \d+ errors?\b" # ruff, mypy
95
+ r"|npm ERR!|ERR_PNPM_|Command failed with exit code [1-9]"
96
+ r"|BUILD FAILED|^FAILURE: Build failed" # ant, gradle
97
+ )
98
+ SHELL_FAILURE = re.compile(
99
+ r"(?i)is not recognized as (the name of a cmdlet|an internal or external command)"
100
+ r"|CommandNotFoundException|: command not found|No such file or directory"
101
+ )
102
+
103
+
104
+ def output_failure(category: str, output: str) -> tuple[bool, str | None]:
105
+ """Failure inferred from command output, for agents whose hook payloads carry no exit status."""
106
+ tail = output[-6000:]
107
+ # Only short outputs: a long listing or log that merely contains "not found" text is not a failed command.
108
+ if len(output) < 800 and SHELL_FAILURE.search(output):
109
+ return True, output
110
+ if category in {"test", "lint", "build"} and OUTPUT_FAILURE.search(tail):
111
+ return True, tail[-4000:]
77
112
  return False, None
78
113
 
79
114
 
@@ -119,6 +154,9 @@ def normalize(agent: str, name: str, payload: dict) -> Event:
119
154
  response = payload.get("tool_response")
120
155
  event.output_chars = _size(response)
121
156
  failed, error = response_failure(response)
157
+ if agent == "codex" and not failed and isinstance(response, str) and not EXIT_CODE.search(response[:400]):
158
+ # Codex shell results are plain output without an exit status (verified live on codex-cli 0.154).
159
+ failed, error = output_failure(categorize(event.tool, event.arguments), response)
122
160
  event.success, event.error = not failed, error
123
161
  return event
124
162
 
@@ -81,7 +81,8 @@ def install(agent: str, project: Path, dry_run: bool = False) -> list[str]:
81
81
  config = project / ".codex" / "config.toml"
82
82
  text = config.read_text(encoding="utf-8") if config.exists() else ""
83
83
  if not re.search(r"^\[mcp_servers\.openreflex\]", text, re.MULTILINE):
84
- block = '[mcp_servers.openreflex]\ncommand = "openreflex"\nargs = ["mcp"]\n'
84
+ # Codex starts MCP servers with a filtered environment, so a data-directory override must be forwarded.
85
+ block = '[mcp_servers.openreflex]\ncommand = "openreflex"\nargs = ["mcp"]\nenv_vars = ["OPENREFLEX_HOME"]\n'
85
86
  _write(config, (text.rstrip() + "\n\n" if text.strip() else "") + block, dry_run, changes)
86
87
  elif agent == "cursor":
87
88
  hooks = project / ".cursor" / "hooks.json"
@@ -38,6 +38,7 @@ COMMAND_CATEGORIES = [
38
38
  VERIFICATION = {"test", "lint", "build"}
39
39
  PROGRESS = VERIFICATION | {"edit"}
40
40
  NOISE_LINE = re.compile(r"^(Traceback|File \"|\s*at |[-=~^]{3,}|\s*$)")
41
+ RUN_SUMMARY = re.compile(r"^(?:(?:Tests?|Test Suites|Test Files):\s*)?\d+ (?:failed|passed|errors?)\b", re.I)
41
42
 
42
43
 
43
44
  def redact(value: str, limit: int = 2000) -> str:
@@ -61,11 +62,32 @@ def categorize(name: str, arguments: object) -> str:
61
62
  command = str(command or "")
62
63
  if PATCH_FILE.search(command) or "apply_patch" in command:
63
64
  return "edit"
65
+ return _command_category(command)
66
+ return CATEGORY_BY_TOOL.get(lowered, "other")
67
+
68
+
69
+ # Commands that only set up context (location, echo) and say nothing about what the call is for.
70
+ NEUTRAL_COMMAND = re.compile(r"^\s*(cd|pushd|popd|Set-Location|Get-Location|pwd|echo|Write-Output|Write-Host|clear|cls)\b", re.I)
71
+ LOOKUP_CATEGORIES = {"search", "read", "vcs"}
72
+
73
+
74
+ def _command_category(command: str) -> str:
75
+ """Classify a possibly compound command by the program each segment runs, not by words in its arguments.
76
+
77
+ `Get-Location; rg --files -g '*test*' -g pytest.ini` is a search, even though "pytest" appears in an argument.
78
+ """
79
+ segments = [s for s in re.split(r"\s*(?:;|&&|\|\||\n)\s*", command) if s.strip() and not NEUTRAL_COMMAND.match(s)]
80
+ first_lookup = None
81
+ for segment in segments:
82
+ head = next((category for category, pattern in COMMAND_CATEGORIES
83
+ if category in LOOKUP_CATEGORIES and pattern.search(segment)), None)
84
+ if head:
85
+ first_lookup = first_lookup or head
86
+ continue # a search or read never becomes a test just because its arguments mention one
64
87
  for category, pattern in COMMAND_CATEGORIES:
65
- if pattern.search(command):
88
+ if category not in LOOKUP_CATEGORIES and pattern.search(segment):
66
89
  return category
67
- return "shell"
68
- return CATEGORY_BY_TOOL.get(lowered, "other")
90
+ return first_lookup or "shell"
69
91
 
70
92
 
71
93
  def error_signature(error: str | None) -> str | None:
@@ -77,11 +99,13 @@ def error_signature(error: str | None) -> str | None:
77
99
  lines = [line for line in stripped if not NOISE_LINE.match(line)]
78
100
  # Python/JS put the exception last; most CLIs put it first. Prefer a line that names an error.
79
101
  named = [line for line in lines if re.search(r"(?i)error|exception|fail|denied|not found|cannot", line)]
102
+ # A test runner's closing tally ("2 failed in 0.03s") says less than the failing test line above it.
103
+ named = [line for line in named if not RUN_SUMMARY.match(line)] or named
80
104
  line = (named or lines or [""])[-1 if named else 0]
81
105
  if len(line) < 4:
82
106
  return None
83
107
  line = re.sub(r"(?:[A-Za-z]:)?[\\/][^\s:'\"]+", "<path>", line)
84
- line = re.sub(r"0x[0-9a-fA-F]+|\b\d+(?:\.\d+)?\b", "<n>", line)
108
+ line = re.sub(r"0x[0-9a-fA-F]+|\b\d+(?:\.\d+)?(?:ms|s)?\b", "<n>", line)
85
109
  line = re.sub(r"(['\"]).{1,80}?\1", "<str>", line)
86
110
  return line[:160]
87
111
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openreflex
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Muscle memory for AI coding agents: learns from every task, advises the next one, and flags failure loops live
5
5
  Author: vishnu-77
6
6
  License-Expression: MIT
@@ -31,6 +31,7 @@ Requires-Dist: twine>=6; extra == "dev"
31
31
  Dynamic: license-file
32
32
 
33
33
  <div align="center">
34
+ <!-- mcp-name: io.github.vishnu-77/openreflex -->
34
35
 
35
36
  <a href="https://openreflex.cc" target="_blank">
36
37
  <picture>
@@ -124,8 +125,8 @@ OpenReflex installs per project with `openreflex install <agent>`, or as a plugi
124
125
  | Cursor | `openreflex install cursor` |
125
126
  | OpenCode | `openreflex install opencode` |
126
127
 
127
- With a plugin install, enable each project with `openreflex approve`. Claude Code is verified in live sessions;
128
- the Codex, Cursor, and OpenCode integrations follow each agent's documented hook protocol.
128
+ With a plugin install, enable each project with `openreflex approve`. Claude Code and Codex are verified in live
129
+ sessions; the Cursor and OpenCode integrations follow each agent's documented hook protocol.
129
130
 
130
131
  ## How it works
131
132
 
@@ -145,3 +145,20 @@ def test_choose_path_accepts_custom_strategy(engine, clock):
145
145
  execution = engine.store.latest("claude-code", "s1")
146
146
  assert execution.chosen_path_id == path.id and not execution.chosen_inferred
147
147
  assert path.uncertainty == 1.0
148
+
149
+
150
+ def test_compound_commands_are_categorized_by_the_program_they_run():
151
+ from openreflex.privacy import categorize
152
+ assert categorize("Bash", {"command": "Get-Location; rg --files -g '*test*' -g pytest.ini"}) == "search"
153
+ assert categorize("Bash", {"command": "rg pytest; python -m pytest tests -q"}) == "test"
154
+ assert categorize("Bash", {"command": "cd web && npm run lint"}) == "lint"
155
+ assert categorize("Bash", {"command": "Get-Content dates.py; Get-Content tests/test_dates.py"}) == "read"
156
+
157
+
158
+ def test_error_signature_prefers_the_failing_test_over_the_run_tally():
159
+ from openreflex.privacy import error_signature
160
+ output = ("E assert (2024, 2, 15) == (2024, 3, 15)\n"
161
+ "FAILED tests/test_dates.py::test_parse_date - assert (2024, 2, 15) == (2024, 3, 15)\n"
162
+ "1 failed in {}\n")
163
+ assert "test_parse_date" in error_signature(output.format("0.12s"))
164
+ assert error_signature(output.format("0.12s")) == error_signature(output.format("1.08s"))
@@ -130,3 +130,40 @@ def test_safe_handle_never_raises(project):
130
130
  ])
131
131
  def test_response_failure(response, failed):
132
132
  assert hooks.response_failure(response)[0] is failed
133
+
134
+
135
+ # Payload shapes below were captured from live codex-cli 0.154 sessions: shell results carry no exit code.
136
+ CODEX_FAILED_PYTEST = (
137
+ "FF [100%]\r\n"
138
+ "================================== FAILURES ===================================\r\n"
139
+ "E assert (2024, 2, 15) == (2024, 3, 15)\r\n"
140
+ "2 failed in 0.03s\r\n"
141
+ )
142
+
143
+
144
+ @pytest.mark.parametrize("command, response, success", [
145
+ ("python -m pytest -q", CODEX_FAILED_PYTEST, False),
146
+ ("python -m pytest -q", ".. [100%]\r\n2 passed in 0.01s\r\n", True),
147
+ ("Get-Content tests/test_dates.py", "def test_x():\n assert parse('x') == 1 # 2 failed in 3 tries\n", True),
148
+ ("pytset -q", "pytset : The term 'pytset' is not recognized as the name of a cmdlet, function", False),
149
+ ("npm test", "Tests: 1 failed, 3 passed, 4 total", False),
150
+ ])
151
+ def test_codex_shell_failures_are_read_from_output(command, response, success):
152
+ event = hooks.normalize("codex", "PostToolUse", {"session_id": "s", "tool_name": "Bash",
153
+ "tool_input": {"command": command}, "tool_response": response})
154
+ assert event.success is success
155
+
156
+
157
+ def test_claude_code_post_tool_use_output_is_not_reinterpreted():
158
+ event = hooks.normalize("claude-code", "PostToolUse", {"session_id": "s", "tool_name": "Bash",
159
+ "tool_input": {"command": "python -m pytest -q"},
160
+ "tool_response": CODEX_FAILED_PYTEST})
161
+ assert event.success is True, "Claude Code reports failures through PostToolUseFailure"
162
+
163
+
164
+ def test_codex_apply_patch_exit_code_zero_is_success():
165
+ response = "Exit code: 0\nWall time: 2 seconds\nOutput:\nSuccess. Updated the following files:\nM dates.py\n"
166
+ event = hooks.normalize("codex", "PostToolUse", {"session_id": "s", "tool_name": "apply_patch",
167
+ "tool_input": {"command": "*** Begin Patch\n*** Update File: dates.py\n"},
168
+ "tool_response": response})
169
+ assert event.success is True
@@ -95,3 +95,22 @@ def test_cli_end_to_end_capture_via_subprocess(isolated_home, project):
95
95
  preview = _run(["context", "Fix unicode filename handling in uploads", "--project", str(project)], env_home=isolated_home)
96
96
  assert "src/upload.py" in preview.stdout.decode()
97
97
  assert not (isolated_home / "logs" / "errors.log").exists()
98
+
99
+
100
+ def test_codex_mcp_server_receives_the_data_directory_override(project):
101
+ install.install("codex", project)
102
+ assert 'env_vars = ["OPENREFLEX_HOME"]' in (project / ".codex/config.toml").read_text()
103
+
104
+
105
+ def test_release_versions_agree():
106
+ import tomllib
107
+
108
+ import openreflex
109
+ version = tomllib.loads((PLUGIN.parents[1] / "pyproject.toml").read_text())["project"]["version"]
110
+ server = json.loads((PLUGIN.parents[1] / "server.json").read_text())
111
+ manifests = [json.loads((PLUGIN / folder / "plugin.json").read_text())["version"]
112
+ for folder in (".claude-plugin", ".codex-plugin", ".cursor-plugin")]
113
+ assert openreflex.__version__ == version
114
+ assert server["version"] == version and [p["version"] for p in server["packages"]] == [version]
115
+ assert manifests == [version] * 3
116
+ assert f"mcp-name: {server['name']}" in (PLUGIN.parents[1] / "README.md").read_text(encoding="utf-8")
File without changes
File without changes