determystic 0.1.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.
Files changed (39) hide show
  1. determystic-0.1.0/.github/workflows/ci.yml +46 -0
  2. determystic-0.1.0/.gitignore +210 -0
  3. determystic-0.1.0/.python-version +1 -0
  4. determystic-0.1.0/Makefile +12 -0
  5. determystic-0.1.0/PKG-INFO +114 -0
  6. determystic-0.1.0/README.md +96 -0
  7. determystic-0.1.0/determystic/__init__.py +0 -0
  8. determystic-0.1.0/determystic/__tests__/agents/__init__.py +1 -0
  9. determystic-0.1.0/determystic/__tests__/agents/test_create_validator.py +375 -0
  10. determystic-0.1.0/determystic/__tests__/cli/__init__.py +0 -0
  11. determystic-0.1.0/determystic/__tests__/configs/__init__.py +0 -0
  12. determystic-0.1.0/determystic/__tests__/configs/test_base.py +316 -0
  13. determystic-0.1.0/determystic/__tests__/configs/test_project.py +355 -0
  14. determystic-0.1.0/determystic/__tests__/configs/test_system.py +276 -0
  15. determystic-0.1.0/determystic/__tests__/validators/__init__.py +1 -0
  16. determystic-0.1.0/determystic/__tests__/validators/test_dynamic_ast.py +428 -0
  17. determystic-0.1.0/determystic/__tests__/validators/test_static_analysis.py +154 -0
  18. determystic-0.1.0/determystic/agents/__init__.py +0 -0
  19. determystic-0.1.0/determystic/agents/create_validator.py +485 -0
  20. determystic-0.1.0/determystic/cli/__init__.py +0 -0
  21. determystic-0.1.0/determystic/cli/configure.py +89 -0
  22. determystic-0.1.0/determystic/cli/list_validators.py +89 -0
  23. determystic-0.1.0/determystic/cli/new_validator.py +230 -0
  24. determystic-0.1.0/determystic/cli/validate.py +173 -0
  25. determystic-0.1.0/determystic/configs/base.py +70 -0
  26. determystic-0.1.0/determystic/configs/project.py +119 -0
  27. determystic-0.1.0/determystic/configs/system.py +61 -0
  28. determystic-0.1.0/determystic/disk_config.py +0 -0
  29. determystic-0.1.0/determystic/entrypoint.py +23 -0
  30. determystic-0.1.0/determystic/external.py +248 -0
  31. determystic-0.1.0/determystic/io.py +95 -0
  32. determystic-0.1.0/determystic/isolated_env.py +111 -0
  33. determystic-0.1.0/determystic/logging.py +3 -0
  34. determystic-0.1.0/determystic/validators/__init__.py +3 -0
  35. determystic-0.1.0/determystic/validators/base.py +45 -0
  36. determystic-0.1.0/determystic/validators/dynamic_ast.py +129 -0
  37. determystic-0.1.0/determystic/validators/static_analysis.py +42 -0
  38. determystic-0.1.0/pyproject.toml +29 -0
  39. determystic-0.1.0/uv.lock +1716 -0
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: '3.12'
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v3
22
+
23
+ - name: Install dependencies
24
+ run: uv sync
25
+
26
+ - name: Run lint validation
27
+ run: make lint-validate
28
+
29
+ test:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+
34
+ - name: Set up Python
35
+ uses: actions/setup-python@v5
36
+ with:
37
+ python-version: '3.12'
38
+
39
+ - name: Install uv
40
+ uses: astral-sh/setup-uv@v3
41
+
42
+ - name: Install dependencies
43
+ run: uv sync
44
+
45
+ - name: Run tests
46
+ run: make test
@@ -0,0 +1,210 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ example_project
210
+ .determystic
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,12 @@
1
+ .PHONY: lint
2
+
3
+ lint:
4
+ uv run ruff check --fix .
5
+ uv run ty check .
6
+
7
+ lint-validate:
8
+ uv run ruff check .
9
+ uv run ty check .
10
+
11
+ test:
12
+ uv run pytest -vvv
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: determystic
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: anthropic>=0.39.0
7
+ Requires-Dist: click>=8.1.0
8
+ Requires-Dist: pydantic-ai>=0.0.14
9
+ Requires-Dist: pydantic-settings>=2.0.0
10
+ Requires-Dist: pytest-asyncio>=0.24.0
11
+ Requires-Dist: pytest>=8.0.0
12
+ Requires-Dist: pyyaml>=6.0.0
13
+ Requires-Dist: rich>=13.0.0
14
+ Requires-Dist: ruff>=0.7.0
15
+ Requires-Dist: tomli-w>=1.0.0
16
+ Requires-Dist: ty
17
+ Description-Content-Type: text/markdown
18
+
19
+ # determystic
20
+
21
+ Determystic is a library that forces your agents to give you a coding style that you're happy with - _deterministically_ every time.
22
+
23
+ It works by creating validators for your coding conventions, using the AST of your programming language. If you see a bad piece of code and can describe why it's bad and why you never want to see code like that in the future, there's a good chance we can write a deterministic validator to make sure it never happens again.
24
+
25
+ ## Getting Started
26
+
27
+ We'll look into adding a MCP server in the future. But for the time being just asking Claude Code / Cursor to run our validation script is usually good enough to get the job done.
28
+
29
+ Append to your `.cursorrules` (Cursor) or `CLAUDE.md` (Claude Code).
30
+
31
+ ```
32
+ Before yielding results, you should ALWAYS call `uvx determystic validate`.
33
+ ```
34
+
35
+ Also setup your anthropic key for our global configuration. This will be accessible across projects so you should only have to do this once:
36
+
37
+ ```bash
38
+ uvx determystic configure
39
+ ```
40
+
41
+ When you have an issue, you can add a special validation case using:
42
+
43
+ ```bash
44
+ uvx determystic new-validator
45
+ ```
46
+
47
+ ## Example
48
+
49
+ Let's say your LLM generated some code that we don't like:
50
+
51
+ ```bash
52
+ from typing import Optional
53
+ from pydantic import BaseModel
54
+
55
+
56
+ class MyModel(BaseModel):
57
+ name: Optional[str] = None
58
+ age: int
59
+
60
+
61
+ def main():
62
+ model = MyModel(name="John", age=30)
63
+ print(model)
64
+
65
+ if __name__ == "__main__":
66
+ main()
67
+ ```
68
+
69
+ In this case, the fact that there's an Optional typehint instead of modern Python syntax (A | None = None). We can add this as a rule:
70
+
71
+ ```bash
72
+ Code: name: Optional[str] = None
73
+ Feedback: Don't use Optional - use A | None
74
+ ```
75
+
76
+ This will add a new .deterministic hidden folder in your current project that you can introspect. But usually the logic looks pretty good zero-shot (we add internal tests to try to ensure that reasonableness of the validator we just wrote) so we can then run the validation:
77
+
78
+ ```bash
79
+ $ uvx determystic validate example_project
80
+
81
+ Detailed Results:
82
+
83
+ ✗ Custom Validator
84
+ main.py:6: Use 'T | None' instead of 'Optional[T]' for type hints
85
+ 4 |
86
+ 5 | class MyModel(BaseModel):
87
+ >>> 6 | name: Optional = None
88
+ 7 | age: int
89
+ 8 |
90
+ ```
91
+
92
+ ## Background
93
+
94
+ Programming agents are getting _really good_. You're hard pressed to find a professional engineer these days that doesn't use Cursor or Claude Code for at least some part of their workflow.
95
+
96
+ My main annoyance in using these systems is when they output code that mostly works but is really messy, or against my own coding conventions. Typehinting in Python is especially egregious here. No matter how much I try to coerce my AGENT.md files, all of the SOTA models have a very strong preference to use List[] and Optional[]. I want to use the modern `list[]` and `A | None`.
97
+
98
+ It's a small thing but it's representative of a larger problem. The main control we have today over these systems today is in their system prompts: specifying a AGENT.md or .cursorrules file to try to guide their behavior over text alone. This certainly works for higher level instructions like describing a feature scope. But we lose precision over what we're looking for by having to describe programming goals and constructs in natural language instead of code. Adding in AST validation changes that - and it turns out that LLMs are actually very good at writing AST validators even though they're pretty annoying for people
99
+
100
+ ## How it works
101
+
102
+ When you see your LLMs outputting something that you know you never want in practice, you'll want to add a deterministic "validator". Copy some portion of your code file that exhibits the problem and run:
103
+
104
+ ```bash
105
+ uv run ...
106
+ ```
107
+
108
+ ## Random notes
109
+
110
+ - Targeting just Python for now. Other languages can follow the same convention pretty closely, but we need to support AST validating for their syntax & test whether LLMs will output better AST validators when written in the same language or if we can use Python as a bridge for control logic
111
+ - Using Anthropic's Claude to do the authoring of the AST validators and the testing files (although in theory it would be very easy to swap this out for any other coding model)
112
+ - We use .deterministic file extensions for our validation and validation test files. These are just python files but we prefer a different extension so they're not inadvertantly picked up by static analysis tools that just sniff for any .py extension. We might reconsider this in the future.
113
+ - Since determystic files are on disk, they should be portable across projects and usable by CI validation across a team
114
+ - Right now we don't support the editing case for existing validators - but this seems like an obvious extension in the future to try and make these more flexible given additional code that either incorrectly validates or does not validate
@@ -0,0 +1,96 @@
1
+ # determystic
2
+
3
+ Determystic is a library that forces your agents to give you a coding style that you're happy with - _deterministically_ every time.
4
+
5
+ It works by creating validators for your coding conventions, using the AST of your programming language. If you see a bad piece of code and can describe why it's bad and why you never want to see code like that in the future, there's a good chance we can write a deterministic validator to make sure it never happens again.
6
+
7
+ ## Getting Started
8
+
9
+ We'll look into adding a MCP server in the future. But for the time being just asking Claude Code / Cursor to run our validation script is usually good enough to get the job done.
10
+
11
+ Append to your `.cursorrules` (Cursor) or `CLAUDE.md` (Claude Code).
12
+
13
+ ```
14
+ Before yielding results, you should ALWAYS call `uvx determystic validate`.
15
+ ```
16
+
17
+ Also setup your anthropic key for our global configuration. This will be accessible across projects so you should only have to do this once:
18
+
19
+ ```bash
20
+ uvx determystic configure
21
+ ```
22
+
23
+ When you have an issue, you can add a special validation case using:
24
+
25
+ ```bash
26
+ uvx determystic new-validator
27
+ ```
28
+
29
+ ## Example
30
+
31
+ Let's say your LLM generated some code that we don't like:
32
+
33
+ ```bash
34
+ from typing import Optional
35
+ from pydantic import BaseModel
36
+
37
+
38
+ class MyModel(BaseModel):
39
+ name: Optional[str] = None
40
+ age: int
41
+
42
+
43
+ def main():
44
+ model = MyModel(name="John", age=30)
45
+ print(model)
46
+
47
+ if __name__ == "__main__":
48
+ main()
49
+ ```
50
+
51
+ In this case, the fact that there's an Optional typehint instead of modern Python syntax (A | None = None). We can add this as a rule:
52
+
53
+ ```bash
54
+ Code: name: Optional[str] = None
55
+ Feedback: Don't use Optional - use A | None
56
+ ```
57
+
58
+ This will add a new .deterministic hidden folder in your current project that you can introspect. But usually the logic looks pretty good zero-shot (we add internal tests to try to ensure that reasonableness of the validator we just wrote) so we can then run the validation:
59
+
60
+ ```bash
61
+ $ uvx determystic validate example_project
62
+
63
+ Detailed Results:
64
+
65
+ ✗ Custom Validator
66
+ main.py:6: Use 'T | None' instead of 'Optional[T]' for type hints
67
+ 4 |
68
+ 5 | class MyModel(BaseModel):
69
+ >>> 6 | name: Optional = None
70
+ 7 | age: int
71
+ 8 |
72
+ ```
73
+
74
+ ## Background
75
+
76
+ Programming agents are getting _really good_. You're hard pressed to find a professional engineer these days that doesn't use Cursor or Claude Code for at least some part of their workflow.
77
+
78
+ My main annoyance in using these systems is when they output code that mostly works but is really messy, or against my own coding conventions. Typehinting in Python is especially egregious here. No matter how much I try to coerce my AGENT.md files, all of the SOTA models have a very strong preference to use List[] and Optional[]. I want to use the modern `list[]` and `A | None`.
79
+
80
+ It's a small thing but it's representative of a larger problem. The main control we have today over these systems today is in their system prompts: specifying a AGENT.md or .cursorrules file to try to guide their behavior over text alone. This certainly works for higher level instructions like describing a feature scope. But we lose precision over what we're looking for by having to describe programming goals and constructs in natural language instead of code. Adding in AST validation changes that - and it turns out that LLMs are actually very good at writing AST validators even though they're pretty annoying for people
81
+
82
+ ## How it works
83
+
84
+ When you see your LLMs outputting something that you know you never want in practice, you'll want to add a deterministic "validator". Copy some portion of your code file that exhibits the problem and run:
85
+
86
+ ```bash
87
+ uv run ...
88
+ ```
89
+
90
+ ## Random notes
91
+
92
+ - Targeting just Python for now. Other languages can follow the same convention pretty closely, but we need to support AST validating for their syntax & test whether LLMs will output better AST validators when written in the same language or if we can use Python as a bridge for control logic
93
+ - Using Anthropic's Claude to do the authoring of the AST validators and the testing files (although in theory it would be very easy to swap this out for any other coding model)
94
+ - We use .deterministic file extensions for our validation and validation test files. These are just python files but we prefer a different extension so they're not inadvertantly picked up by static analysis tools that just sniff for any .py extension. We might reconsider this in the future.
95
+ - Since determystic files are on disk, they should be portable across projects and usable by CI validation across a team
96
+ - Right now we don't support the editing case for existing validators - but this seems like an obvious extension in the future to try and make these more flexible given additional code that either incorrectly validates or does not validate
File without changes
@@ -0,0 +1 @@
1
+ # Test package