ya-agent-environment 0.74.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,140 @@
1
+ docs/source
2
+
3
+ # From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
4
+
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
90
+ __pypackages__/
91
+
92
+ # Celery stuff
93
+ celerybeat-schedule
94
+ celerybeat.pid
95
+
96
+ # SageMath parsed files
97
+ *.sage.py
98
+
99
+ # Environments
100
+ .env
101
+ .venv
102
+ env/
103
+ venv/
104
+ ENV/
105
+ env.bak/
106
+ venv.bak/
107
+
108
+ # Spyder project settings
109
+ .spyderproject
110
+ .spyproject
111
+
112
+ # Rope project settings
113
+ .ropeproject
114
+
115
+ # mkdocs documentation
116
+ /site
117
+
118
+ # mypy
119
+ .mypy_cache/
120
+ .dmypy.json
121
+ dmypy.json
122
+
123
+ # Pyre type checker
124
+ .pyre/
125
+
126
+ # pytype static type analyzer
127
+ .pytype/
128
+
129
+ # Cython debug symbols
130
+ cython_debug/
131
+
132
+ # Vscode config files
133
+ # .vscode/
134
+
135
+ # PyCharm
136
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
137
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
138
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
139
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
140
+ #.idea/
@@ -0,0 +1,31 @@
1
+ # Contributing to `ya-agent-environment`
2
+
3
+ `ya-agent-environment` is maintained inside the `ya-mono` workspace.
4
+
5
+ ## Local Development
6
+
7
+ ```bash
8
+ git clone https://github.com/wh1isper/ya-mono.git
9
+ cd ya-mono
10
+ make install
11
+ ```
12
+
13
+ Run package tests:
14
+
15
+ ```bash
16
+ uv run python -m pytest packages/ya-agent-environment/tests -vv
17
+ ```
18
+
19
+ Run repository checks before a pull request:
20
+
21
+ ```bash
22
+ make lint
23
+ make check
24
+ make test
25
+ ```
26
+
27
+ ## Guidelines
28
+
29
+ - Keep the import package name `ya_agent_environment` for compatibility.
30
+ - Put relay protocol work in the sibling `packages/ya-environment-relay` package.
31
+ - Update tests and docs when changing public protocols, environment interfaces, shell behavior, file operations, or resource state.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, wh1isper
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: ya-agent-environment
3
+ Version: 0.74.0
4
+ Summary: Environment abstractions for general agents
5
+ Project-URL: Repository, https://github.com/wh1isper/ya-mono
6
+ Author-email: wh1isper <jizhongsheng957@gmail.com>
7
+ License-File: LICENSE
8
+ Keywords: agent,environment,python
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: <3.14,>=3.11
17
+ Requires-Dist: anyio>=4.0.0
18
+ Requires-Dist: pathspec>=0.12.0
19
+ Requires-Dist: pydantic>=2.0.0
20
+ Description-Content-Type: text/markdown
21
+
22
+ # ya-agent-environment
23
+
24
+ Environment abstractions for general agents.
25
+
26
+ `ya-agent-environment` provides the shared base interfaces used by YA agents:
27
+
28
+ - `Environment`
29
+ - `FileOperator`
30
+ - `Shell`
31
+ - `ResourceRegistry`
32
+ - resumable resources
33
+ - `TmpFileOperator`
34
+
35
+ The Python import package is `ya_agent_environment`.
36
+
37
+ Relay protocol work lives in the sibling [`ya-environment-relay`](../ya-environment-relay) package.
38
+
39
+ ## Development
40
+
41
+ This package is maintained as a workspace member in `ya-mono`.
42
+
43
+ ```bash
44
+ uv run python -m pytest packages/ya-agent-environment/tests -vv
45
+ uv run python -m pyright
46
+ uv build --package ya-agent-environment -o dist
47
+ ```
@@ -0,0 +1,26 @@
1
+ # ya-agent-environment
2
+
3
+ Environment abstractions for general agents.
4
+
5
+ `ya-agent-environment` provides the shared base interfaces used by YA agents:
6
+
7
+ - `Environment`
8
+ - `FileOperator`
9
+ - `Shell`
10
+ - `ResourceRegistry`
11
+ - resumable resources
12
+ - `TmpFileOperator`
13
+
14
+ The Python import package is `ya_agent_environment`.
15
+
16
+ Relay protocol work lives in the sibling [`ya-environment-relay`](../ya-environment-relay) package.
17
+
18
+ ## Development
19
+
20
+ This package is maintained as a workspace member in `ya-mono`.
21
+
22
+ ```bash
23
+ uv run python -m pytest packages/ya-agent-environment/tests -vv
24
+ uv run python -m pyright
25
+ uv build --package ya-agent-environment -o dist
26
+ ```
@@ -0,0 +1,57 @@
1
+ [project]
2
+ name = "ya-agent-environment"
3
+ dynamic = ["version"]
4
+ description = "Environment abstractions for general agents"
5
+ authors = [{ name = "wh1isper", email = "jizhongsheng957@gmail.com" }]
6
+ readme = "README.md"
7
+ keywords = ["python", "agent", "environment"]
8
+ requires-python = ">=3.11,<3.14"
9
+ classifiers = [
10
+ "Intended Audience :: Developers",
11
+ "Programming Language :: Python",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.11",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Topic :: Software Development :: Libraries :: Python Modules",
17
+ ]
18
+
19
+ dependencies = [
20
+ "anyio>=4.0.0",
21
+ "pathspec>=0.12.0",
22
+ "pydantic>=2.0.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ Repository = "https://github.com/wh1isper/ya-mono"
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "pytest>=7.2.0",
31
+ "pre-commit>=2.20.0",
32
+ "pytest-asyncio>=0.25.3",
33
+ "deptry>=0.22.0",
34
+ "pyright>=1.1.0",
35
+ "pytest-cov>=4.0.0",
36
+ "ruff>=0.9.2",
37
+ ]
38
+
39
+ [build-system]
40
+ requires = ["hatchling", "uv-dynamic-versioning>=0.7.0"]
41
+ build-backend = "hatchling.build"
42
+
43
+ [tool.hatch.version]
44
+ source = "uv-dynamic-versioning"
45
+
46
+ [tool.uv-dynamic-versioning]
47
+ vcs = "git"
48
+ style = "pep440"
49
+ bump = true
50
+
51
+ [tool.hatch.build.targets.wheel]
52
+ packages = ["ya_agent_environment"]
53
+
54
+ [tool.deptry]
55
+ ignore = ["DEP001", "DEP002"]
56
+ package_module_name_map = { "anyio" = "anyio", "pathspec" = "pathspec", "pydantic" = "pydantic", "ya-agent-environment" = "ya_agent_environment" }
57
+ per_rule_ignores = { DEP004 = ["pytest"] }
@@ -0,0 +1 @@
1
+ # Tests for ya_agent_environment
@@ -0,0 +1,241 @@
1
+ """Shared test fixtures and mock classes for ya_agent_environment tests."""
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ from ya_agent_environment import (
7
+ BaseResource,
8
+ Environment,
9
+ FileOperator,
10
+ FileStat,
11
+ Shell,
12
+ )
13
+ from ya_agent_environment.shell import ExecutionHandle
14
+
15
+ # --- Test fixtures and helpers ---
16
+
17
+
18
+ class SimpleResource:
19
+ """A simple resource that only has close()."""
20
+
21
+ def __init__(self) -> None:
22
+ self.closed = False
23
+ self.setup_called = False
24
+
25
+ def close(self) -> None:
26
+ self.closed = True
27
+
28
+ async def setup(self) -> None:
29
+ self.setup_called = True
30
+
31
+ def get_toolsets(self) -> list[Any]:
32
+ return []
33
+
34
+
35
+ class ResumableMockResource:
36
+ """A resumable resource for testing."""
37
+
38
+ def __init__(self, initial_data: str = "") -> None:
39
+ self.data = initial_data
40
+ self.closed = False
41
+ self.setup_called = False
42
+ self._restored_state: dict[str, Any] | None = None
43
+
44
+ async def setup(self) -> None:
45
+ self.setup_called = True
46
+
47
+ async def export_state(self) -> dict[str, Any]:
48
+ return {"data": self.data}
49
+
50
+ async def restore_state(self, state: dict[str, Any]) -> None:
51
+ self.data = state.get("data", "")
52
+ self._restored_state = state
53
+
54
+ def close(self) -> None:
55
+ self.closed = True
56
+
57
+ def get_toolsets(self) -> list[Any]:
58
+ return []
59
+
60
+
61
+ class MockBaseResource(BaseResource):
62
+ """A BaseResource subclass for testing."""
63
+
64
+ def __init__(self, value: str = "") -> None:
65
+ self.value = value
66
+ self.closed = False
67
+
68
+ async def close(self) -> None:
69
+ self.closed = True
70
+
71
+ async def export_state(self) -> dict[str, Any]:
72
+ return {"value": self.value}
73
+
74
+ async def restore_state(self, state: dict[str, Any]) -> None:
75
+ self.value = state.get("value", "")
76
+
77
+
78
+ class MinimalBaseResource(BaseResource):
79
+ """A minimal BaseResource subclass with default export/restore."""
80
+
81
+ def __init__(self) -> None:
82
+ self.closed = False
83
+
84
+ async def close(self) -> None:
85
+ self.closed = True
86
+
87
+
88
+ class ResourceWithInstructions(BaseResource):
89
+ """A BaseResource subclass with context instructions."""
90
+
91
+ def __init__(self, instructions: str) -> None:
92
+ self._instructions = instructions
93
+ self.closed = False
94
+
95
+ async def close(self) -> None:
96
+ self.closed = True
97
+
98
+ async def get_context_instructions(self) -> str | None:
99
+ return self._instructions
100
+
101
+
102
+ class ResourceWithEnvAccess(BaseResource):
103
+ """A resource that captures environment references during creation."""
104
+
105
+ def __init__(
106
+ self,
107
+ file_operator: FileOperator,
108
+ shell: Shell,
109
+ ) -> None:
110
+ self.file_operator = file_operator
111
+ self.shell = shell
112
+ self.closed = False
113
+
114
+ async def close(self) -> None:
115
+ self.closed = True
116
+
117
+
118
+ # --- Mock Environment for integration tests ---
119
+
120
+
121
+ class MockFileOperator(FileOperator):
122
+ """Mock FileOperator for testing."""
123
+
124
+ def __init__(self) -> None:
125
+ super().__init__(
126
+ default_path=Path("/tmp/mock"),
127
+ allowed_paths=[Path("/tmp/mock")],
128
+ )
129
+
130
+ async def _read_file_impl(
131
+ self, path: str, *, encoding: str = "utf-8", offset: int = 0, length: int | None = None
132
+ ) -> str:
133
+ return ""
134
+
135
+ async def _read_bytes_impl(self, path: str, *, offset: int = 0, length: int | None = None) -> bytes:
136
+ return b""
137
+
138
+ async def _write_file_impl(self, path: str, content: str | bytes, *, encoding: str = "utf-8") -> None:
139
+ pass
140
+
141
+ async def _append_file_impl(self, path: str, content: str | bytes, *, encoding: str = "utf-8") -> None:
142
+ pass
143
+
144
+ async def _delete_impl(self, path: str) -> None:
145
+ pass
146
+
147
+ async def _list_dir_impl(self, path: str) -> list[str]:
148
+ return []
149
+
150
+ async def _exists_impl(self, path: str) -> bool:
151
+ return False
152
+
153
+ async def _is_file_impl(self, path: str) -> bool:
154
+ return False
155
+
156
+ async def _is_dir_impl(self, path: str) -> bool:
157
+ return False
158
+
159
+ async def _mkdir_impl(self, path: str, *, parents: bool = False) -> None:
160
+ pass
161
+
162
+ async def _move_impl(self, src: str, dst: str) -> None:
163
+ pass
164
+
165
+ async def _copy_impl(self, src: str, dst: str) -> None:
166
+ pass
167
+
168
+ async def _stat_impl(self, path: str) -> FileStat:
169
+ return FileStat(size=0, mtime=0, is_file=False, is_dir=False)
170
+
171
+ async def _glob_impl(self, pattern: str) -> list[str]:
172
+ return []
173
+
174
+
175
+ class MockShell(Shell):
176
+ """Mock Shell for testing."""
177
+
178
+ def __init__(self) -> None:
179
+ super().__init__(default_cwd=Path("/tmp/mock"))
180
+
181
+ async def execute(
182
+ self,
183
+ command: str,
184
+ *,
185
+ timeout: float | None = None,
186
+ env: dict[str, str] | None = None,
187
+ cwd: str | None = None,
188
+ ) -> tuple[int, str, str]:
189
+ return (0, "", "")
190
+
191
+ async def _create_process(
192
+ self,
193
+ command: str,
194
+ *,
195
+ env: dict[str, str] | None = None,
196
+ cwd: str | None = None,
197
+ ) -> ExecutionHandle:
198
+ import asyncio
199
+ import contextlib
200
+
201
+ stdout_stream = asyncio.StreamReader()
202
+ stderr_stream = asyncio.StreamReader()
203
+
204
+ async def _execute() -> int:
205
+ exit_code, stdout, stderr = await self.execute(command, timeout=None, env=env, cwd=cwd)
206
+ if stdout:
207
+ stdout_stream.feed_data(stdout.encode("utf-8"))
208
+ stdout_stream.feed_eof()
209
+ if stderr:
210
+ stderr_stream.feed_data(stderr.encode("utf-8"))
211
+ stderr_stream.feed_eof()
212
+ return exit_code
213
+
214
+ exec_task = asyncio.create_task(_execute())
215
+
216
+ async def _wait() -> int:
217
+ return await exec_task
218
+
219
+ async def _kill() -> None:
220
+ exec_task.cancel()
221
+ with contextlib.suppress(asyncio.CancelledError):
222
+ await exec_task
223
+
224
+ return ExecutionHandle(
225
+ stdout=stdout_stream,
226
+ stderr=stderr_stream,
227
+ wait=_wait,
228
+ kill=_kill,
229
+ )
230
+
231
+
232
+ class MockEnvironment(Environment):
233
+ """Mock Environment for testing."""
234
+
235
+ async def _setup(self) -> None:
236
+ self._file_operator = MockFileOperator()
237
+ self._shell = MockShell()
238
+
239
+ async def _teardown(self) -> None:
240
+ self._file_operator = None
241
+ self._shell = None