refactron 0.2.4__tar.gz → 0.3.0__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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
refactron-0.3.0/NOTICE ADDED
@@ -0,0 +1,21 @@
1
+ Refactron
2
+ Copyright 2024-2026 Refactron
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (the
5
+ "License"); you may not use this file except in compliance with the
6
+ License. A copy of the License is included in the LICENSE file in the
7
+ root of this repository, and may also be obtained at:
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ implied. See the License for the specific language governing
15
+ permissions and limitations under the License.
16
+
17
+ ---
18
+
19
+ Third-party dependencies retain their respective licenses. See the
20
+ package.json (npm) for the full dependency tree and individual
21
+ licenses.
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: refactron
3
+ Version: 0.3.0
4
+ Summary: Verification layer for AI code change: prove a diff preserved behavior (Python wrapper for the npm CLI)
5
+ Author-email: Om Sherikar <omsherikar0229@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Refactron-ai/Refactron_Lib_TS
8
+ Project-URL: Documentation, https://docs.refactron.dev
9
+ Project-URL: Changelog, https://github.com/Refactron-ai/Refactron_Lib_TS/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/Refactron-ai/Refactron_Lib_TS/issues
11
+ Keywords: verification,ai-agents,mcp,code-review,testing,ci,refactoring,python,typescript,ast,cli
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Quality Assurance
17
+ Classifier: Topic :: Software Development :: Testing
18
+ Classifier: Topic :: Software Development :: Code Generators
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: NOTICE
23
+ Dynamic: license-file
24
+
25
+ # refactron (Python wrapper)
26
+
27
+ **The verification layer for AI code change.** Refactron proves that a change,
28
+ your AI agent's, a codemod's, or your own, preserved behavior. It applies the
29
+ diff in an isolated shadow tree, runs your real test suite, and returns a
30
+ three-way verdict: `SAFE`, `UNSAFE`, or `UNPROVEN`. Your working tree is never
31
+ touched.
32
+
33
+ This package is a **thin Python shim** around the
34
+ [npm `refactron` package](https://npmjs.com/package/refactron). It exists so a
35
+ Python-first toolchain can put the `refactron` command on your PATH without
36
+ adding Node to your project manifest. All the real work happens in the Node
37
+ CLI.
38
+
39
+ ## Requirements
40
+
41
+ - **Node.js 18+ on your PATH.** This wrapper does not remove the Node
42
+ dependency; it only saves you from wiring the CLI in by hand.
43
+ - **Python 3.8+**, plus `coverage.py` in the environment your tests run in if
44
+ you want coverage-backed verdicts.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install refactron==0.3.0
50
+ npm install -g refactron@0.3.0
51
+ ```
52
+
53
+ Both lines matter. The pip package gives you the `refactron` entry point; the
54
+ npm package is what it runs. Keep the two versions equal: the wrapper prints a
55
+ warning to stderr when they disagree.
56
+
57
+ The wrapper **does not install the npm package for you**. A `pip install` that
58
+ silently ran `npm install -g` would write outside your Python environment and
59
+ would pull whatever version is `latest`, which is not necessarily the version
60
+ you pinned. If the Node CLI is missing, the wrapper tells you the exact command
61
+ to run and exits non-zero.
62
+
63
+ Prefer not to install globally? Skip the pip package and use
64
+ `npx refactron@0.3.0 <command>` directly.
65
+
66
+ ## Usage
67
+
68
+ Identical to the npm package. Every argument is passed straight through.
69
+
70
+ ```bash
71
+ refactron login # or set REFACTRON_TOKEN in CI
72
+ refactron verify-diff . --diff change.diff --test-cmd "python3 -m pytest -q"
73
+ refactron preflight ./my-sqlalchemy-app
74
+ refactron analyze .
75
+ refactron run --apply
76
+ ```
77
+
78
+ `verify-diff` exits `1` on `UNSAFE`, `2` on bad input, `7` when
79
+ unauthenticated, and `0` on both `SAFE` and `UNPROVEN`. `UNPROVEN` is a
80
+ warning, not a rejection: read the `verdict` field from `--json` if you want CI
81
+ to fail on it.
82
+
83
+ Coverage attestation is Python-only, via `coverage.py`. A TypeScript, mixed, or
84
+ otherwise non-Python diff caps at `UNPROVEN`; it never returns a false `SAFE`.
85
+
86
+ ## MCP server
87
+
88
+ The npm package also ships a `refactron-mcp` binary, a stdio MCP server
89
+ exposing a `verify_change` tool your agent calls before it lands a change. It
90
+ is not routed through this wrapper: point your MCP client at `refactron-mcp`
91
+ directly. See the [MCP docs](https://docs.refactron.dev/verification/mcp-server).
92
+
93
+ ## Environment variables
94
+
95
+ | Variable | Effect |
96
+ | ------------------------------ | --------------------------------------------------------- |
97
+ | `REFACTRON_TOKEN` | Authenticates non-interactive runs (CI). |
98
+ | `REFACTRON_SKIP_VERSION_CHECK` | Set to `1` to silence the wrapper's version-skew warning. |
99
+
100
+ ## License
101
+
102
+ Apache-2.0. See `LICENSE` and `NOTICE`.
103
+
104
+ Full docs: https://docs.refactron.dev
@@ -0,0 +1,80 @@
1
+ # refactron (Python wrapper)
2
+
3
+ **The verification layer for AI code change.** Refactron proves that a change,
4
+ your AI agent's, a codemod's, or your own, preserved behavior. It applies the
5
+ diff in an isolated shadow tree, runs your real test suite, and returns a
6
+ three-way verdict: `SAFE`, `UNSAFE`, or `UNPROVEN`. Your working tree is never
7
+ touched.
8
+
9
+ This package is a **thin Python shim** around the
10
+ [npm `refactron` package](https://npmjs.com/package/refactron). It exists so a
11
+ Python-first toolchain can put the `refactron` command on your PATH without
12
+ adding Node to your project manifest. All the real work happens in the Node
13
+ CLI.
14
+
15
+ ## Requirements
16
+
17
+ - **Node.js 18+ on your PATH.** This wrapper does not remove the Node
18
+ dependency; it only saves you from wiring the CLI in by hand.
19
+ - **Python 3.8+**, plus `coverage.py` in the environment your tests run in if
20
+ you want coverage-backed verdicts.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install refactron==0.3.0
26
+ npm install -g refactron@0.3.0
27
+ ```
28
+
29
+ Both lines matter. The pip package gives you the `refactron` entry point; the
30
+ npm package is what it runs. Keep the two versions equal: the wrapper prints a
31
+ warning to stderr when they disagree.
32
+
33
+ The wrapper **does not install the npm package for you**. A `pip install` that
34
+ silently ran `npm install -g` would write outside your Python environment and
35
+ would pull whatever version is `latest`, which is not necessarily the version
36
+ you pinned. If the Node CLI is missing, the wrapper tells you the exact command
37
+ to run and exits non-zero.
38
+
39
+ Prefer not to install globally? Skip the pip package and use
40
+ `npx refactron@0.3.0 <command>` directly.
41
+
42
+ ## Usage
43
+
44
+ Identical to the npm package. Every argument is passed straight through.
45
+
46
+ ```bash
47
+ refactron login # or set REFACTRON_TOKEN in CI
48
+ refactron verify-diff . --diff change.diff --test-cmd "python3 -m pytest -q"
49
+ refactron preflight ./my-sqlalchemy-app
50
+ refactron analyze .
51
+ refactron run --apply
52
+ ```
53
+
54
+ `verify-diff` exits `1` on `UNSAFE`, `2` on bad input, `7` when
55
+ unauthenticated, and `0` on both `SAFE` and `UNPROVEN`. `UNPROVEN` is a
56
+ warning, not a rejection: read the `verdict` field from `--json` if you want CI
57
+ to fail on it.
58
+
59
+ Coverage attestation is Python-only, via `coverage.py`. A TypeScript, mixed, or
60
+ otherwise non-Python diff caps at `UNPROVEN`; it never returns a false `SAFE`.
61
+
62
+ ## MCP server
63
+
64
+ The npm package also ships a `refactron-mcp` binary, a stdio MCP server
65
+ exposing a `verify_change` tool your agent calls before it lands a change. It
66
+ is not routed through this wrapper: point your MCP client at `refactron-mcp`
67
+ directly. See the [MCP docs](https://docs.refactron.dev/verification/mcp-server).
68
+
69
+ ## Environment variables
70
+
71
+ | Variable | Effect |
72
+ | ------------------------------ | --------------------------------------------------------- |
73
+ | `REFACTRON_TOKEN` | Authenticates non-interactive runs (CI). |
74
+ | `REFACTRON_SKIP_VERSION_CHECK` | Set to `1` to silence the wrapper's version-skew warning. |
75
+
76
+ ## License
77
+
78
+ Apache-2.0. See `LICENSE` and `NOTICE`.
79
+
80
+ Full docs: https://docs.refactron.dev
@@ -0,0 +1,54 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "refactron"
7
+ dynamic = ["version"]
8
+ description = "Verification layer for AI code change: prove a diff preserved behavior (Python wrapper for the npm CLI)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Om Sherikar", email = "omsherikar0229@gmail.com" }]
13
+ keywords = [
14
+ "verification",
15
+ "ai-agents",
16
+ "mcp",
17
+ "code-review",
18
+ "testing",
19
+ "ci",
20
+ "refactoring",
21
+ "python",
22
+ "typescript",
23
+ "ast",
24
+ "cli",
25
+ ]
26
+ classifiers = [
27
+ "Development Status :: 4 - Beta",
28
+ "Intended Audience :: Developers",
29
+ "License :: OSI Approved :: Apache Software License",
30
+ "Programming Language :: Python :: 3",
31
+ "Topic :: Software Development :: Quality Assurance",
32
+ "Topic :: Software Development :: Testing",
33
+ "Topic :: Software Development :: Code Generators",
34
+ ]
35
+ dependencies = []
36
+
37
+ [project.scripts]
38
+ refactron = "refactron.cli:main"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/Refactron-ai/Refactron_Lib_TS"
42
+ Documentation = "https://docs.refactron.dev"
43
+ Changelog = "https://github.com/Refactron-ai/Refactron_Lib_TS/blob/main/CHANGELOG.md"
44
+ Issues = "https://github.com/Refactron-ai/Refactron_Lib_TS/issues"
45
+
46
+ # Single source of truth for the version: the literal in refactron/__init__.py.
47
+ # setuptools reads it statically, so the packaged metadata and the runtime
48
+ # __version__ can never disagree.
49
+ [tool.setuptools.dynamic]
50
+ version = { attr = "refactron.__version__" }
51
+
52
+ [tool.setuptools]
53
+ packages = ["refactron"]
54
+ license-files = ["LICENSE", "NOTICE"]
@@ -0,0 +1,19 @@
1
+ """Python wrapper around the Refactron npm CLI.
2
+
3
+ Refactron is the verification layer for AI code change: it applies a diff in
4
+ an isolated shadow tree, runs your real test suite, and returns a `SAFE`,
5
+ `UNSAFE`, or `UNPROVEN` verdict.
6
+
7
+ This package is a thin shim. All real work happens in the npm `refactron`
8
+ package, so Node.js 18+ must be on your PATH. Installing this gives Python-first
9
+ toolchains the `refactron` command without adding a Node dependency to their
10
+ project manifest.
11
+
12
+ `__version__` is the single source of truth for this package's version:
13
+ pyproject.toml reads it statically via `[tool.setuptools.dynamic]`, so the
14
+ distribution metadata and the runtime value cannot drift apart.
15
+ """
16
+
17
+ __version__ = "0.3.0"
18
+
19
+ __all__ = ["__version__"]
@@ -0,0 +1,215 @@
1
+ """Locate the Refactron Node CLI and exec it.
2
+
3
+ This wrapper never installs anything. It resolves the `refactron` binary that
4
+ npm provides, warns if that binary's version disagrees with this package's,
5
+ and hands the process over. If the Node CLI is missing it prints the exact
6
+ command that installs the matching version and exits non-zero.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import shutil
12
+ import subprocess
13
+ import sys
14
+ import sysconfig
15
+
16
+ from . import __version__
17
+
18
+ REQUIRED_NODE_MAJOR = 18
19
+ NPM_PACKAGE = "refactron"
20
+ NPM_BIN = "refactron"
21
+
22
+ # Set on the child environment before exec. If it is already set when we start,
23
+ # we resolved ourselves instead of the Node CLI and would otherwise exec in a
24
+ # loop forever.
25
+ _REENTRY_ENV = "_REFACTRON_PY_SHIM"
26
+
27
+ # Opt out of the one-shot `refactron --version` skew check.
28
+ _SKIP_VERSION_CHECK_ENV = "REFACTRON_SKIP_VERSION_CHECK"
29
+
30
+ _VERSION_CHECK_TIMEOUT_SECONDS = 10
31
+
32
+
33
+ def _have(cmd: str) -> bool:
34
+ return shutil.which(cmd) is not None
35
+
36
+
37
+ def _node_version_ok() -> bool:
38
+ try:
39
+ out = subprocess.check_output(["node", "--version"], text=True).strip()
40
+ # "v20.11.1" -> 20
41
+ major = int(out.lstrip("v").split(".")[0])
42
+ return major >= REQUIRED_NODE_MAJOR
43
+ except (subprocess.SubprocessError, ValueError, OSError):
44
+ return False
45
+
46
+
47
+ def _realpath(path: str) -> str:
48
+ try:
49
+ return os.path.realpath(path)
50
+ except OSError:
51
+ return path
52
+
53
+
54
+ def _own_entry_points() -> set:
55
+ """Paths that would re-enter this wrapper instead of reaching the Node CLI.
56
+
57
+ pip installs a console script named `refactron`, and in a virtualenv that
58
+ directory sits ahead of npm's global bin on PATH. Resolving the name
59
+ naively finds our own script and execs it, forever.
60
+ """
61
+ paths = set()
62
+
63
+ argv0 = sys.argv[0] if sys.argv else ""
64
+ if argv0:
65
+ paths.add(_realpath(argv0))
66
+
67
+ for scheme_arg in (None, "posix_user", "nt_user"):
68
+ try:
69
+ scripts_dir = (
70
+ sysconfig.get_path("scripts")
71
+ if scheme_arg is None
72
+ else sysconfig.get_path("scripts", scheme=scheme_arg)
73
+ )
74
+ except (KeyError, ValueError):
75
+ continue
76
+ if not scripts_dir:
77
+ continue
78
+ for name in (NPM_BIN, NPM_BIN + ".exe"):
79
+ paths.add(_realpath(os.path.join(scripts_dir, name)))
80
+
81
+ return paths
82
+
83
+
84
+ def _is_python_script(path: str) -> bool:
85
+ """True when `path` is a Python console script rather than the Node CLI."""
86
+ try:
87
+ with open(path, "rb") as handle:
88
+ head = handle.read(256)
89
+ except OSError:
90
+ return False
91
+ if not head.startswith(b"#!"):
92
+ return False
93
+ shebang = head.split(b"\n", 1)[0].lower()
94
+ return b"python" in shebang
95
+
96
+
97
+ def _find_node_cli() -> str | None:
98
+ """Return the npm-provided `refactron` binary, skipping our own shim."""
99
+ own = _own_entry_points()
100
+ for directory in os.environ.get("PATH", "").split(os.pathsep):
101
+ if not directory:
102
+ continue
103
+ candidate = shutil.which(NPM_BIN, path=directory)
104
+ if not candidate:
105
+ continue
106
+ if _realpath(candidate) in own:
107
+ continue
108
+ if _is_python_script(candidate):
109
+ continue
110
+ return candidate
111
+ return None
112
+
113
+
114
+ def _missing_cli_message() -> str:
115
+ return (
116
+ "refactron: the Node CLI that does the real work is not installed.\n"
117
+ "\n"
118
+ "Install the version that matches this Python package:\n"
119
+ f" npm install -g {NPM_PACKAGE}@{__version__}\n"
120
+ "\n"
121
+ "Or run it without installing:\n"
122
+ f" npx {NPM_PACKAGE}@{__version__} --help\n"
123
+ "\n"
124
+ f"This wrapper (refactron {__version__}) is a thin shim and deliberately\n"
125
+ "does not install npm packages for you."
126
+ )
127
+
128
+
129
+ def _cli_version(cli: str) -> str | None:
130
+ """Best-effort `refactron --version`. Never raises, never blocks for long."""
131
+ try:
132
+ completed = subprocess.run(
133
+ [cli, "--version"],
134
+ stdout=subprocess.PIPE,
135
+ stderr=subprocess.DEVNULL,
136
+ timeout=_VERSION_CHECK_TIMEOUT_SECONDS,
137
+ )
138
+ except (OSError, subprocess.SubprocessError):
139
+ return None
140
+ if completed.returncode != 0:
141
+ return None
142
+ try:
143
+ reported = completed.stdout.decode("utf-8", "replace").strip()
144
+ except (AttributeError, UnicodeError):
145
+ return None
146
+ return reported.lstrip("vV") or None
147
+
148
+
149
+ def _warn_on_version_skew(cli: str) -> None:
150
+ if os.environ.get(_SKIP_VERSION_CHECK_ENV):
151
+ return
152
+ found = _cli_version(cli)
153
+ if found is None or found == __version__:
154
+ return
155
+ print(
156
+ f"refactron: version skew. This Python wrapper is {__version__} but the "
157
+ f"Node CLI on your PATH is {found}.\n"
158
+ f" Align them with `npm install -g {NPM_PACKAGE}@{__version__}`, "
159
+ f"or set {_SKIP_VERSION_CHECK_ENV}=1 to silence this.",
160
+ file=sys.stderr,
161
+ )
162
+
163
+
164
+ def main() -> int | None:
165
+ if os.environ.get(_REENTRY_ENV):
166
+ print(
167
+ "refactron: the Python wrapper resolved itself instead of the Node "
168
+ "CLI, so it stopped rather than loop.\n"
169
+ f"Install the Node CLI with `npm install -g {NPM_PACKAGE}@{__version__}` "
170
+ "and make sure npm's global bin directory is on your PATH.",
171
+ file=sys.stderr,
172
+ )
173
+ return 1
174
+
175
+ if not _have("node"):
176
+ print(
177
+ "refactron: Node.js 18+ is required. Install Node from https://nodejs.org "
178
+ "or use a version manager like nvm.",
179
+ file=sys.stderr,
180
+ )
181
+ return 1
182
+ if not _node_version_ok():
183
+ print(
184
+ f"refactron: Node.js {REQUIRED_NODE_MAJOR}+ required (you have an older version).",
185
+ file=sys.stderr,
186
+ )
187
+ return 1
188
+
189
+ cli = _find_node_cli()
190
+ if cli is None:
191
+ print(_missing_cli_message(), file=sys.stderr)
192
+ return 1
193
+
194
+ # Set the sentinel before anything spawns `cli`, not just before the exec.
195
+ # If resolution ever handed back our own script despite the filtering above,
196
+ # the version probe would fork-bomb rather than merely loop. The child sees
197
+ # the sentinel and exits immediately.
198
+ os.environ[_REENTRY_ENV] = __version__
199
+
200
+ _warn_on_version_skew(cli)
201
+
202
+ # exec replaces this process so signals (Ctrl+C) and exit codes pass
203
+ # through cleanly. On Windows os.execvp is shimmed; if it fails we fall
204
+ # back to subprocess.run so the user still gets a usable CLI.
205
+ args = [cli, *sys.argv[1:]]
206
+ try:
207
+ os.execvp(cli, args)
208
+ except OSError:
209
+ completed = subprocess.run(args)
210
+ return completed.returncode
211
+ return None
212
+
213
+
214
+ if __name__ == "__main__":
215
+ sys.exit(main() or 0)
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: refactron
3
+ Version: 0.3.0
4
+ Summary: Verification layer for AI code change: prove a diff preserved behavior (Python wrapper for the npm CLI)
5
+ Author-email: Om Sherikar <omsherikar0229@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Refactron-ai/Refactron_Lib_TS
8
+ Project-URL: Documentation, https://docs.refactron.dev
9
+ Project-URL: Changelog, https://github.com/Refactron-ai/Refactron_Lib_TS/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/Refactron-ai/Refactron_Lib_TS/issues
11
+ Keywords: verification,ai-agents,mcp,code-review,testing,ci,refactoring,python,typescript,ast,cli
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Quality Assurance
17
+ Classifier: Topic :: Software Development :: Testing
18
+ Classifier: Topic :: Software Development :: Code Generators
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: NOTICE
23
+ Dynamic: license-file
24
+
25
+ # refactron (Python wrapper)
26
+
27
+ **The verification layer for AI code change.** Refactron proves that a change,
28
+ your AI agent's, a codemod's, or your own, preserved behavior. It applies the
29
+ diff in an isolated shadow tree, runs your real test suite, and returns a
30
+ three-way verdict: `SAFE`, `UNSAFE`, or `UNPROVEN`. Your working tree is never
31
+ touched.
32
+
33
+ This package is a **thin Python shim** around the
34
+ [npm `refactron` package](https://npmjs.com/package/refactron). It exists so a
35
+ Python-first toolchain can put the `refactron` command on your PATH without
36
+ adding Node to your project manifest. All the real work happens in the Node
37
+ CLI.
38
+
39
+ ## Requirements
40
+
41
+ - **Node.js 18+ on your PATH.** This wrapper does not remove the Node
42
+ dependency; it only saves you from wiring the CLI in by hand.
43
+ - **Python 3.8+**, plus `coverage.py` in the environment your tests run in if
44
+ you want coverage-backed verdicts.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install refactron==0.3.0
50
+ npm install -g refactron@0.3.0
51
+ ```
52
+
53
+ Both lines matter. The pip package gives you the `refactron` entry point; the
54
+ npm package is what it runs. Keep the two versions equal: the wrapper prints a
55
+ warning to stderr when they disagree.
56
+
57
+ The wrapper **does not install the npm package for you**. A `pip install` that
58
+ silently ran `npm install -g` would write outside your Python environment and
59
+ would pull whatever version is `latest`, which is not necessarily the version
60
+ you pinned. If the Node CLI is missing, the wrapper tells you the exact command
61
+ to run and exits non-zero.
62
+
63
+ Prefer not to install globally? Skip the pip package and use
64
+ `npx refactron@0.3.0 <command>` directly.
65
+
66
+ ## Usage
67
+
68
+ Identical to the npm package. Every argument is passed straight through.
69
+
70
+ ```bash
71
+ refactron login # or set REFACTRON_TOKEN in CI
72
+ refactron verify-diff . --diff change.diff --test-cmd "python3 -m pytest -q"
73
+ refactron preflight ./my-sqlalchemy-app
74
+ refactron analyze .
75
+ refactron run --apply
76
+ ```
77
+
78
+ `verify-diff` exits `1` on `UNSAFE`, `2` on bad input, `7` when
79
+ unauthenticated, and `0` on both `SAFE` and `UNPROVEN`. `UNPROVEN` is a
80
+ warning, not a rejection: read the `verdict` field from `--json` if you want CI
81
+ to fail on it.
82
+
83
+ Coverage attestation is Python-only, via `coverage.py`. A TypeScript, mixed, or
84
+ otherwise non-Python diff caps at `UNPROVEN`; it never returns a false `SAFE`.
85
+
86
+ ## MCP server
87
+
88
+ The npm package also ships a `refactron-mcp` binary, a stdio MCP server
89
+ exposing a `verify_change` tool your agent calls before it lands a change. It
90
+ is not routed through this wrapper: point your MCP client at `refactron-mcp`
91
+ directly. See the [MCP docs](https://docs.refactron.dev/verification/mcp-server).
92
+
93
+ ## Environment variables
94
+
95
+ | Variable | Effect |
96
+ | ------------------------------ | --------------------------------------------------------- |
97
+ | `REFACTRON_TOKEN` | Authenticates non-interactive runs (CI). |
98
+ | `REFACTRON_SKIP_VERSION_CHECK` | Set to `1` to silence the wrapper's version-skew warning. |
99
+
100
+ ## License
101
+
102
+ Apache-2.0. See `LICENSE` and `NOTICE`.
103
+
104
+ Full docs: https://docs.refactron.dev
@@ -1,4 +1,5 @@
1
1
  LICENSE
2
+ NOTICE
2
3
  README.md
3
4
  pyproject.toml
4
5
  refactron/__init__.py
refactron-0.2.4/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Refactron AI
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
refactron-0.2.4/PKG-INFO DELETED
@@ -1,46 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: refactron
3
- Version: 0.2.4
4
- Summary: Safety-first refactoring CLI for Python and TypeScript (Python wrapper around the npm package)
5
- Author-email: Om Sherikar <omsherikar0229@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/Refactron-ai/Refactron_Lib_TS
8
- Project-URL: Documentation, https://docs.refactron.dev
9
- Project-URL: Issues, https://github.com/Refactron-ai/Refactron_Lib_TS/issues
10
- Keywords: refactoring,python,typescript,ast,cli
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Topic :: Software Development :: Code Generators
16
- Requires-Python: >=3.8
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Dynamic: license-file
20
-
21
- # refactron (Python wrapper)
22
-
23
- This is a thin Python wrapper around the [npm `refactron` package](https://npmjs.com/package/refactron).
24
- It exists so users with a Python-first toolchain can `pip install refactron`
25
- and get the CLI on their PATH without manually installing Node.
26
-
27
- ## Install
28
-
29
- ```bash
30
- pip install refactron
31
- ```
32
-
33
- Requires Node.js 18+ on your PATH. If `refactron` isn't already installed
34
- via npm, this wrapper will run `npm install -g refactron` on first use.
35
-
36
- ## Usage
37
-
38
- Identical to the npm package:
39
-
40
- ```bash
41
- refactron analyze .
42
- refactron run --apply
43
- refactron document --apply
44
- ```
45
-
46
- Full docs: https://docs.refactron.dev
refactron-0.2.4/README.md DELETED
@@ -1,26 +0,0 @@
1
- # refactron (Python wrapper)
2
-
3
- This is a thin Python wrapper around the [npm `refactron` package](https://npmjs.com/package/refactron).
4
- It exists so users with a Python-first toolchain can `pip install refactron`
5
- and get the CLI on their PATH without manually installing Node.
6
-
7
- ## Install
8
-
9
- ```bash
10
- pip install refactron
11
- ```
12
-
13
- Requires Node.js 18+ on your PATH. If `refactron` isn't already installed
14
- via npm, this wrapper will run `npm install -g refactron` on first use.
15
-
16
- ## Usage
17
-
18
- Identical to the npm package:
19
-
20
- ```bash
21
- refactron analyze .
22
- refactron run --apply
23
- refactron document --apply
24
- ```
25
-
26
- Full docs: https://docs.refactron.dev
@@ -1,29 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "refactron"
7
- version = "0.2.4"
8
- description = "Safety-first refactoring CLI for Python and TypeScript (Python wrapper around the npm package)"
9
- readme = "README.md"
10
- requires-python = ">=3.8"
11
- license = { text = "MIT" }
12
- authors = [{ name = "Om Sherikar", email = "omsherikar0229@gmail.com" }]
13
- keywords = ["refactoring", "python", "typescript", "ast", "cli"]
14
- classifiers = [
15
- "Development Status :: 4 - Beta",
16
- "Intended Audience :: Developers",
17
- "License :: OSI Approved :: MIT License",
18
- "Programming Language :: Python :: 3",
19
- "Topic :: Software Development :: Code Generators",
20
- ]
21
- dependencies = []
22
-
23
- [project.scripts]
24
- refactron = "refactron.cli:main"
25
-
26
- [project.urls]
27
- Homepage = "https://github.com/Refactron-ai/Refactron_Lib_TS"
28
- Documentation = "https://docs.refactron.dev"
29
- Issues = "https://github.com/Refactron-ai/Refactron_Lib_TS/issues"
@@ -1,7 +0,0 @@
1
- """Python wrapper around the Refactron npm CLI.
2
-
3
- This package is a thin shim — all real work happens in the npm @refactron
4
- package. Installing this gives you the `refactron` command on your PATH
5
- even if you only have Python tooling.
6
- """
7
- __version__ = "0.2.0"
@@ -1,76 +0,0 @@
1
- """Detect Node.js, ensure the npm refactron CLI is available, then exec it."""
2
- from __future__ import annotations
3
-
4
- import os
5
- import shutil
6
- import subprocess
7
- import sys
8
-
9
-
10
- REQUIRED_NODE_MAJOR = 18
11
- NPM_PACKAGE = "refactron"
12
-
13
-
14
- def _have(cmd: str) -> bool:
15
- return shutil.which(cmd) is not None
16
-
17
-
18
- def _node_version_ok() -> bool:
19
- try:
20
- out = subprocess.check_output(["node", "--version"], text=True).strip()
21
- # "v20.11.1" -> 20
22
- major = int(out.lstrip("v").split(".")[0])
23
- return major >= REQUIRED_NODE_MAJOR
24
- except (subprocess.SubprocessError, ValueError, OSError):
25
- return False
26
-
27
-
28
- def _ensure_npm_cli() -> str:
29
- """Return the absolute path to the `refactron` CLI executable.
30
-
31
- If `refactron` is on PATH, use it. Otherwise install via `npm install -g`
32
- (best-effort) and re-check. If still missing, raise."""
33
- if _have("refactron"):
34
- return shutil.which("refactron") # type: ignore[return-value]
35
-
36
- # Try a one-shot global install via npm.
37
- if _have("npm"):
38
- subprocess.check_call(["npm", "install", "-g", NPM_PACKAGE], stdout=sys.stderr)
39
- if _have("refactron"):
40
- return shutil.which("refactron") # type: ignore[return-value]
41
-
42
- raise SystemExit(
43
- "refactron: the underlying Node CLI is not installed. "
44
- "Run `npm install -g refactron` or use `npx refactron` directly."
45
- )
46
-
47
-
48
- def main() -> "int | None":
49
- if not _have("node"):
50
- print(
51
- "refactron: Node.js 18+ is required. Install Node from https://nodejs.org "
52
- "or use a version manager like nvm.",
53
- file=sys.stderr,
54
- )
55
- return 1
56
- if not _node_version_ok():
57
- print(
58
- f"refactron: Node.js {REQUIRED_NODE_MAJOR}+ required (you have an older version).",
59
- file=sys.stderr,
60
- )
61
- return 1
62
-
63
- cli = _ensure_npm_cli()
64
- # exec replaces this process so signals (Ctrl+C) and exit codes pass
65
- # through cleanly. On Windows os.execvp is shimmed; if it fails we fall
66
- # back to subprocess.run so the user still gets a usable CLI.
67
- args = [cli, *sys.argv[1:]]
68
- try:
69
- os.execvp(cli, args)
70
- except OSError:
71
- completed = subprocess.run(args)
72
- return completed.returncode
73
-
74
-
75
- if __name__ == "__main__":
76
- sys.exit(main() or 0)
@@ -1,46 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: refactron
3
- Version: 0.2.4
4
- Summary: Safety-first refactoring CLI for Python and TypeScript (Python wrapper around the npm package)
5
- Author-email: Om Sherikar <omsherikar0229@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/Refactron-ai/Refactron_Lib_TS
8
- Project-URL: Documentation, https://docs.refactron.dev
9
- Project-URL: Issues, https://github.com/Refactron-ai/Refactron_Lib_TS/issues
10
- Keywords: refactoring,python,typescript,ast,cli
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Topic :: Software Development :: Code Generators
16
- Requires-Python: >=3.8
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Dynamic: license-file
20
-
21
- # refactron (Python wrapper)
22
-
23
- This is a thin Python wrapper around the [npm `refactron` package](https://npmjs.com/package/refactron).
24
- It exists so users with a Python-first toolchain can `pip install refactron`
25
- and get the CLI on their PATH without manually installing Node.
26
-
27
- ## Install
28
-
29
- ```bash
30
- pip install refactron
31
- ```
32
-
33
- Requires Node.js 18+ on your PATH. If `refactron` isn't already installed
34
- via npm, this wrapper will run `npm install -g refactron` on first use.
35
-
36
- ## Usage
37
-
38
- Identical to the npm package:
39
-
40
- ```bash
41
- refactron analyze .
42
- refactron run --apply
43
- refactron document --apply
44
- ```
45
-
46
- Full docs: https://docs.refactron.dev
File without changes