scry-run 0.1.0__py3-none-any.whl

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.
scry_run/packages.py ADDED
@@ -0,0 +1,175 @@
1
+ """Package management utilities for per-app environments."""
2
+
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+ from scry_run.console import status, success, error, warning
9
+
10
+
11
+ def get_venv_python(app_dir: Path) -> Path:
12
+ """Get path to Python executable in venv, cross-platform.
13
+
14
+ Args:
15
+ app_dir: Path to the app directory
16
+
17
+ Returns:
18
+ Path to the Python executable in the app's venv
19
+ """
20
+ if sys.platform == "win32":
21
+ return app_dir / ".venv" / "Scripts" / "python.exe"
22
+ return app_dir / ".venv" / "bin" / "python"
23
+
24
+
25
+ def get_scry_run_source_path() -> Optional[Path]:
26
+ """Get the source path if scry-run is installed in development mode.
27
+
28
+ Returns:
29
+ Path to source directory if dev install, None if PyPI install
30
+ """
31
+ import scry_run
32
+ package_path = Path(scry_run.__file__).parent
33
+ # Go up to the project root (src/scry_run -> src -> project_root)
34
+ project_root = package_path.parent.parent
35
+
36
+ # Check if we're in development mode (can access pyproject.toml and src/)
37
+ if (project_root / "pyproject.toml").exists() and (project_root / "src" / "scry_run").exists():
38
+ return project_root
39
+
40
+ return None
41
+
42
+
43
+ def is_scry_run_installed(app_dir: Path) -> bool:
44
+ """Check if scry-run is installed in the app's venv.
45
+
46
+ Args:
47
+ app_dir: Path to the app directory
48
+
49
+ Returns:
50
+ True if scry-run is available in the app's venv
51
+ """
52
+ python_path = get_venv_python(app_dir)
53
+ if not python_path.exists():
54
+ return False
55
+
56
+ result = subprocess.run(
57
+ [str(python_path), "-c", "import scry_run"],
58
+ capture_output=True,
59
+ )
60
+ return result.returncode == 0
61
+
62
+
63
+ def ensure_scry_run_installed(app_dir: Path) -> None:
64
+ """Ensure scry-run is installed in the app's virtual environment.
65
+
66
+ In development mode (source install), installs from local path with -e.
67
+ In production mode (PyPI install), installs from PyPI.
68
+
69
+ Args:
70
+ app_dir: Path to the app directory
71
+ """
72
+ ensure_venv(app_dir)
73
+
74
+ if is_scry_run_installed(app_dir):
75
+ return
76
+
77
+ source_path = get_scry_run_source_path()
78
+ python_path = get_venv_python(app_dir)
79
+
80
+ if source_path:
81
+ # Development mode - editable install from source
82
+ status(f"Installing scry-run from source ({source_path.name})...")
83
+ cmd = ["uv", "pip", "install", "--python", str(python_path), "-e", str(source_path)]
84
+ else:
85
+ # Production mode - install from PyPI
86
+ status("Installing scry-run from PyPI...")
87
+ cmd = ["uv", "pip", "install", "--python", str(python_path), "scry-run"]
88
+
89
+ result = subprocess.run(cmd, capture_output=True, text=True)
90
+ if result.returncode != 0:
91
+ error(f"Failed to install scry-run: {result.stderr}")
92
+ raise RuntimeError(f"Failed to install scry-run: {result.stderr}")
93
+
94
+ success("Installed scry-run")
95
+
96
+
97
+ def ensure_venv(app_dir: Path) -> None:
98
+ """Ensure a virtual environment exists for the app.
99
+
100
+ Args:
101
+ app_dir: Path to the app directory
102
+ """
103
+ venv_path = app_dir / ".venv"
104
+ if venv_path.exists():
105
+ return
106
+
107
+ status(f"Creating virtual environment in {app_dir.name}...")
108
+ result = subprocess.run(
109
+ ["uv", "venv"],
110
+ cwd=app_dir,
111
+ capture_output=True,
112
+ text=True,
113
+ )
114
+ if result.returncode != 0:
115
+ error(f"Failed to create venv: {result.stderr}")
116
+ raise RuntimeError(f"uv venv failed: {result.stderr}")
117
+
118
+
119
+ def install_packages(app_dir: Path, packages: list[str]) -> None:
120
+ """Install packages into the app's virtual environment.
121
+
122
+ Args:
123
+ app_dir: Path to the app directory
124
+ packages: List of package specs (e.g., ["pygame", "requests>=2.0"])
125
+ """
126
+ if not packages:
127
+ return
128
+
129
+ # Ensure venv exists
130
+ ensure_venv(app_dir)
131
+
132
+ status(f"Installing packages: {', '.join(packages)}")
133
+ python_path = get_venv_python(app_dir)
134
+ result = subprocess.run(
135
+ ["uv", "pip", "install", "--python", str(python_path)] + packages,
136
+ capture_output=True,
137
+ text=True,
138
+ )
139
+ if result.returncode != 0:
140
+ error(f"Failed to install packages: {result.stderr}")
141
+ raise RuntimeError(f"uv pip install failed: {result.stderr}")
142
+
143
+ success(f"Installed {len(packages)} package(s)")
144
+
145
+
146
+ def get_installed_packages(app_dir: Path) -> list[str]:
147
+ """Get list of installed packages in the app's environment.
148
+
149
+ Args:
150
+ app_dir: Path to the app directory
151
+
152
+ Returns:
153
+ List of "package==version" strings
154
+ """
155
+ venv_path = app_dir / ".venv"
156
+ if not venv_path.exists():
157
+ return []
158
+
159
+ python_path = get_venv_python(app_dir)
160
+ result = subprocess.run(
161
+ ["uv", "pip", "list", "--format=freeze", "--python", str(python_path)],
162
+ capture_output=True,
163
+ text=True,
164
+ )
165
+ if result.returncode != 0:
166
+ warning(f"Failed to list packages in {app_dir.name}")
167
+ return []
168
+
169
+ packages = []
170
+ for line in result.stdout.strip().split("\n"):
171
+ line = line.strip()
172
+ if line and not line.startswith("#"):
173
+ packages.append(line)
174
+
175
+ return packages
@@ -0,0 +1,282 @@
1
+ Metadata-Version: 2.4
2
+ Name: scry-run
3
+ Version: 0.1.0
4
+ Summary: LLM-powered dynamic code generation via metaclasses. Define classes with docstrings, call any method—code generates automatically, caches persistently, and executes instantly.
5
+ Project-URL: Homepage, https://github.com/Tener/scry-run
6
+ Project-URL: Repository, https://github.com/Tener/scry-run
7
+ Author: Krzysztof Skrzętnicki
8
+ License: MIT
9
+ Keywords: ai,claude,code-generation,llm,metaclass
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Code Generators
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: claude-agent-sdk>=0.1.0
20
+ Requires-Dist: click>=8.0.0
21
+ Requires-Dist: jinja2>=3.0.0
22
+ Requires-Dist: rich>=13.0.0
23
+ Requires-Dist: tomli>=2.0.0; python_version < '3.11'
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
26
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
27
+ Requires-Dist: pytest-timeout>=2.0.0; extra == 'dev'
28
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # scry-run
32
+
33
+ **Write class definitions, get working code.** A Python library where any method call automatically generates its implementation via LLM.
34
+
35
+ Define your application as a class with a docstring, then call any method you want—`scry-run` generates the code on-demand, caches it, and executes it. No boilerplate, no implementation required.
36
+
37
+ ## Features
38
+
39
+ - **Zero-boilerplate coding**: Define intent via class docstrings, methods generate automatically
40
+ - **Intelligent caching**: Generated code persists across runs—pay once, use forever
41
+ - **Production-ready**: Bake apps into standalone packages with frozen, pre-generated code
42
+ - **CLI-first**: Manage apps, inspect cache, and export generated code via intuitive commands
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install scry-run
48
+ # or with uv
49
+ uv pip install scry-run
50
+ ```
51
+
52
+ ### Run without installing (uvx)
53
+
54
+ ```bash
55
+ # From PyPI
56
+ uvx scry-run --help
57
+ uvx scry-run init --name=myapp --description="My app"
58
+
59
+ # From GitHub (latest)
60
+ uvx --from git+https://github.com/scry-run/scry-run scry-run --help
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ### 1. Set up your backend
66
+
67
+ Requires Claude Code CLI to be installed.
68
+
69
+ ```bash
70
+ # Verify claude CLI is available
71
+ claude --version
72
+ ```
73
+
74
+ ### 2. Initialize a project
75
+
76
+ ```bash
77
+ # Non-interactive
78
+ scry-run init --name=todoist --description='minimal web todo app'
79
+
80
+ # Interactive
81
+ scry-run init
82
+ ```
83
+
84
+ ### 3. Run your app
85
+
86
+ ```bash
87
+ scry-run run todoist
88
+ ```
89
+
90
+ Or use it directly in Python:
91
+
92
+ ```python
93
+ from scry_run import ScryClass
94
+
95
+ class Todoist(ScryClass):
96
+ """A minimal web todo app with task management."""
97
+ pass
98
+
99
+ app = Todoist()
100
+
101
+ # These methods will be generated automatically!
102
+ app.add_task("Buy groceries")
103
+ app.list_tasks()
104
+ app.complete_task(0)
105
+ ```
106
+
107
+ ## Demos
108
+
109
+ ### Creating a simple Hello World app
110
+
111
+ ![Hello Demo](demos/hello.gif)
112
+
113
+ ### Building a maze game with PyGame
114
+
115
+ ![Maze Demo](demos/maze.gif)
116
+
117
+
118
+ ## How It Works
119
+
120
+ 1. When you access an undefined attribute on an `ScryClass` subclass, the metaclass intercepts it
121
+ 2. The library collects the full codebase context and builds a prompt
122
+ 3. The configured backend generates code with structured JSON output (code, type, docstring, dependencies)
123
+ 4. The code is validated with Python's `ast.parse()` to ensure it's syntactically correct
124
+ 5. Valid code is cached and executed
125
+ 6. On subsequent accesses, the cached code is used directly
126
+
127
+ ## Backend
128
+
129
+ Uses Claude Code CLI with `--print` flag for non-interactive output.
130
+
131
+ ```bash
132
+ # If claude CLI is installed, it's used automatically
133
+ scry-run run myapp
134
+
135
+ # Optionally specify a model
136
+ export SCRY_RUN_MODEL=opus
137
+ ```
138
+
139
+ ## Configuration
140
+
141
+ ### Environment Variables
142
+
143
+ | Variable | Description | Default |
144
+ |----------|-------------|---------|
145
+ | `SCRY_RUN_BACKEND` | Backend to use: `claude`, `frozen`, or `auto` | `auto` |
146
+ | `SCRY_RUN_MODEL` | Model override (e.g., `opus`) | (backend default) |
147
+ | `SCRY_RUN_MAX_GENERATIONS` | Max code generations per process | `100` |
148
+
149
+ ### Class-level options
150
+
151
+ ```python
152
+ class MyApp(ScryClass):
153
+ """My application."""
154
+
155
+ # Disable LLM generation (raises AttributeError for missing attrs)
156
+ _llm_enabled = False
157
+
158
+ # Use minimal context instead of full codebase (faster)
159
+ _llm_use_full_context = False
160
+
161
+ # Suppress generation messages
162
+ _llm_quiet = True
163
+
164
+ # Override model for this class
165
+ _llm_model = "opus"
166
+ ```
167
+
168
+ ## CLI Commands
169
+
170
+ ### App Management
171
+
172
+ ```bash
173
+ # Initialize a new app
174
+ scry-run init --name=NAME --description=DESC
175
+
176
+ # List all apps
177
+ scry-run list
178
+
179
+ # Get path to an app's main file
180
+ scry-run which myapp
181
+
182
+ # Run an app
183
+ scry-run run myapp [args...]
184
+
185
+ # Remove an app
186
+ scry-run rm myapp
187
+ scry-run rm myapp --force # Skip confirmation
188
+
189
+ # Reset an app (clear code & cache, keep name/description)
190
+ scry-run reset myapp
191
+ scry-run reset myapp --force # Skip confirmation
192
+ ```
193
+
194
+ ### Cache Management
195
+
196
+ ```bash
197
+ # List cached entries for an app
198
+ scry-run cache list myapp
199
+
200
+ # Show a specific entry
201
+ scry-run cache show myapp MyClass.my_method
202
+
203
+ # Export cache
204
+ scry-run cache export myapp --output=generated.py --format=python
205
+ scry-run cache export myapp --output=cache.json --format=json
206
+
207
+ # Remove a specific entry
208
+ scry-run cache rm myapp MyClass.my_method
209
+
210
+ # Prune cache entries
211
+ scry-run cache prune myapp --class=MyClass --attr=my_method
212
+ scry-run cache prune myapp --class=MyClass # All methods of a class
213
+ scry-run cache prune myapp --all # Everything
214
+
215
+ # Reset cache (clear all entries)
216
+ scry-run cache reset myapp --force
217
+ ```
218
+
219
+ ## API
220
+
221
+ ### ScryClass
222
+
223
+ Base class to inherit from for LLM-powered code generation.
224
+
225
+ ```python
226
+ from scry_run import ScryClass
227
+
228
+ class MyApp(ScryClass):
229
+ """Description of your app - the LLM uses this!"""
230
+
231
+ def existing_method(self):
232
+ """Existing methods are used as context."""
233
+ return "hello"
234
+
235
+ # Class methods
236
+ MyApp.llm_export_cache("output.py") # Export generated code
237
+ MyApp.llm_prune_cache("method_name") # Remove cached entry
238
+ MyApp.llm_disable() # Disable generation
239
+ MyApp.llm_enable() # Re-enable generation
240
+ ```
241
+
242
+ ### ScryCache
243
+
244
+ Manage the code cache programmatically.
245
+
246
+ ```python
247
+ from scry_run import ScryCache
248
+
249
+ cache = ScryCache()
250
+
251
+ # Get cached code
252
+ entry = cache.get("MyClass", "my_method")
253
+ print(entry.code)
254
+
255
+ # List all entries
256
+ for entry in cache.list_entries():
257
+ print(f"{entry.class_name}.{entry.attr_name}: {entry.docstring}")
258
+
259
+ # Export
260
+ cache.export_to_file("all_generated_code.py")
261
+
262
+ # Prune
263
+ cache.prune(class_name="MyClass", attr_name="my_method")
264
+ ```
265
+
266
+ ## Development
267
+
268
+ ```bash
269
+ # Clone the repo
270
+ git clone https://github.com/scry-run/scry-run
271
+ cd scry-run
272
+
273
+ # Install with dev dependencies
274
+ uv sync --dev
275
+
276
+ # Run tests
277
+ uv run pytest tests/ -v
278
+ ```
279
+
280
+ ## License
281
+
282
+ MIT
@@ -0,0 +1,26 @@
1
+ scry_run/__init__.py,sha256=uAFNmvmMzEpsFNJ3Uew4RUSgNPXvn_cFkTU2Bx8RmWo,2875
2
+ scry_run/cache.py,sha256=gzWNCRva4d1KOqrYx0eo0T9o8lbsBYmcxgnXPUfc9Dg,14163
3
+ scry_run/config.py,sha256=zBnxbzHKwWDpg0C1BmSm6SGv5PF7rq_cSctWIsm_oz0,4083
4
+ scry_run/console.py,sha256=r8IO8zw5A132Yqik3Y2K2IzbFLNW3hFcyhGo1bup2Yk,1695
5
+ scry_run/context.py,sha256=os3kdrYxcgzrkPPiPzIy9Lrlp4b964eishDb7KSCaCY,10256
6
+ scry_run/generator.py,sha256=KrlfdwwDyp5DRRTD9vPRUkweWGAMU85z2EnjznKLXj4,25023
7
+ scry_run/home.py,sha256=-ZOgvsaJ0udH_a0_A0YYBZHjtLzGMVaU_t5NqmcBNIQ,1364
8
+ scry_run/logging.py,sha256=zKB_-IgRT9GXVULaFJKepX4oUVXQlt3buqjzBoh9Uyo,5684
9
+ scry_run/meta.py,sha256=z71xDV91pEi2-SG3MD-_SFwkWEHdgDMvbaQyxYHgCR4,71310
10
+ scry_run/packages.py,sha256=U6HxWoEkFisKwLAeM_RtFvTt2qrCmxmZD38pJNVQt7g,5156
11
+ scry_run/backends/__init__.py,sha256=q52KwLy2KsJLxpUJKbLsCTH0ELLLQGOz_14OnhDYOig,245
12
+ scry_run/backends/base.py,sha256=bedYMpVL19dE_ei85wWRj8g5zsJsH607G8nAgsDpfwI,1693
13
+ scry_run/backends/claude.py,sha256=fqYK1F1PsqCM2-ssvmdduhwjrsVURcLeCTJLxTbAKPE,15038
14
+ scry_run/backends/frozen.py,sha256=DfPWpD0Yq5wV5-kQtEGAuRWfv1q4Z66MPpmPIs-ZbEw,2863
15
+ scry_run/backends/registry.py,sha256=pAOrZcaWHJhIn6ai-O6lBzb0QeICa3MV-kH5zcDcRrM,2180
16
+ scry_run/cli/__init__.py,sha256=Hje8gmqzBsbX5iW6lKVfv5ZOXamkUVx-fGnwRupgmuU,5385
17
+ scry_run/cli/apps.py,sha256=AP016GpSH4_mPpXq3k8r4hjBE5Kizxk9mDQNZpdAt0c,12609
18
+ scry_run/cli/cache.py,sha256=UkxSFZUqiyDxn2KrFojh8UT03d_lBxJmolsV7w7qTmU,10774
19
+ scry_run/cli/config_cmd.py,sha256=Ge8Xw8R3_LpEfCOrXgaeD-0KG4WrVslMpNdZhtReOp8,2436
20
+ scry_run/cli/env.py,sha256=Jxw5I6TY5sJ0Rsha86OZDPRHDS850FA4n30sg4yFKhQ,745
21
+ scry_run/cli/init.py,sha256=DsWyzE1qN6gYMwHhGljIhp-mpMn4xODFQ2bSLJt1ELM,13603
22
+ scry_run/cli/run.py,sha256=vH89DttVCQwNWWwvUNxo9IbjnCGU2F_1OeWrMxHsvc8,2327
23
+ scry_run-0.1.0.dist-info/METADATA,sha256=lVPhCXWZSZPuSZWt3hT83vSSgfqA3DPkxvri8WXRFF8,6969
24
+ scry_run-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
25
+ scry_run-0.1.0.dist-info/entry_points.txt,sha256=edV5nv1PT_pjWsOcLR3DMNkV-MUBsCY-jORR4dee-Ho,47
26
+ scry_run-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ scry-run = scry_run.cli:main