rqark-sandbox 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.
- rqark_sandbox-0.1.0/.gitea/workflows/pypi-hub.yaml +31 -0
- rqark_sandbox-0.1.0/.gitignore +10 -0
- rqark_sandbox-0.1.0/.python-version +1 -0
- rqark_sandbox-0.1.0/.vscode/settings.json +37 -0
- rqark_sandbox-0.1.0/AGENTS.md +10 -0
- rqark_sandbox-0.1.0/CONTRIBUTING.md +112 -0
- rqark_sandbox-0.1.0/LICENSE +18 -0
- rqark_sandbox-0.1.0/PKG-INFO +72 -0
- rqark_sandbox-0.1.0/README.md +52 -0
- rqark_sandbox-0.1.0/pyproject.toml +71 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/__init__.py +13 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/config.py +9 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/project.py +30 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/prompts/__init__.py +30 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/prompts/agents_md.py +21 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/prompts/git_project.py +51 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/prompts/platform.py +8 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/py.typed +0 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/__init__.py +39 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/base.py +44 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/convert_document.py +74 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/edit_file.py +135 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/exec.py +59 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/git/__init__.py +15 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/git/base_git.py +47 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/git/gitea.py +7 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/git/github.py +7 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/git/gitlab.py +7 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/grep.py +75 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/list_dir.py +65 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/read_file.py +57 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/tools/write_file.py +41 -0
- rqark_sandbox-0.1.0/src/rqark_sandbox/workspace.py +887 -0
- rqark_sandbox-0.1.0/tests/test_convert_document.py +79 -0
- rqark_sandbox-0.1.0/tests/test_project.py +117 -0
- rqark_sandbox-0.1.0/tests/test_workspace.py +162 -0
- rqark_sandbox-0.1.0/uv.lock +1494 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish to PyPI Hub
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v3
|
|
18
|
+
with:
|
|
19
|
+
enable-cache: true
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
run: uv python install 3.14
|
|
23
|
+
|
|
24
|
+
- name: Build the package
|
|
25
|
+
run: uv build
|
|
26
|
+
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
env:
|
|
29
|
+
UV_PUBLISH_USERNAME: __token__
|
|
30
|
+
UV_PUBLISH_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
|
31
|
+
run: uv publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
/*
|
|
3
|
+
* BASE
|
|
4
|
+
*/
|
|
5
|
+
"files.encoding": "utf8",
|
|
6
|
+
"editor.linkedEditing": true, // 使得同時編輯相同變數或符號更容易。
|
|
7
|
+
"editor.bracketPairColorization.enabled": true, // 啟用括號配對著色功能。
|
|
8
|
+
"editor.guides.bracketPairs": true, // 在括號間顯示視覺導引線
|
|
9
|
+
"explorer.compactFolders": false,
|
|
10
|
+
/*
|
|
11
|
+
* GIT
|
|
12
|
+
*/
|
|
13
|
+
"git.autofetch": true,
|
|
14
|
+
"git.enableSmartCommit": true,
|
|
15
|
+
"git.confirmSync": false,
|
|
16
|
+
/*
|
|
17
|
+
* PYTHON
|
|
18
|
+
*/
|
|
19
|
+
"python.analysis.inlayHints.callArgumentNames": "partial",
|
|
20
|
+
"python.analysis.inlayHints.functionReturnTypes": true,
|
|
21
|
+
"python.analysis.inlayHints.pytestParameters": true,
|
|
22
|
+
"python.analysis.inlayHints.variableTypes": true,
|
|
23
|
+
"python.analysis.autoSearchPaths": true,
|
|
24
|
+
"python.analysis.autoIndent": true,
|
|
25
|
+
"python.analysis.autoFormatStrings": true, // 在字串內輸入“{”時,是否自動加上“f”前綴。
|
|
26
|
+
"python.analysis.completeFunctionParens": true,
|
|
27
|
+
"python.analysis.typeEvaluation.analyzeUnannotatedFunctions": true, // 為函數補全添加括號。
|
|
28
|
+
"python.analysis.typeEvaluation.strictSetInference": true,
|
|
29
|
+
"python.analysis.includeAliasesFromUserFiles": false,
|
|
30
|
+
"python.analysis.typeCheckingMode": "basic",
|
|
31
|
+
"python.analysis.typeEvaluation.strictDictionaryInference": true,
|
|
32
|
+
"python.analysis.typeEvaluation.strictListInference": true,
|
|
33
|
+
/*
|
|
34
|
+
* JUPYTER
|
|
35
|
+
*/
|
|
36
|
+
"jupyter.exportWithOutputEnabled": false,
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Contributing
|
|
4
|
+
> Issue、commit、PR、release、版本號一律跟 `CONTRIBUTING.md`。
|
|
5
|
+
|
|
6
|
+
# Rules
|
|
7
|
+
- 禁寫註解
|
|
8
|
+
- 禁止 squash merge 同 `git revert`;PR 一律用 merge commit,改錯用新 commit
|
|
9
|
+
- 運行 `uv run ruff check --fix` + `uv run ty check --fix`(主力)
|
|
10
|
+
- 偶爾行 `uv run pyright` / `uv run mypy` 輔助確認 type safety
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
This document defines how issues, commits, pull requests and releases are written in this repository.
|
|
4
|
+
|
|
5
|
+
## Commits
|
|
6
|
+
|
|
7
|
+
Format:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
type(scope): subject
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- `type` is one of `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `perf`, `ci`, `build`, `chore`.
|
|
14
|
+
- `scope` is optional. Use the package or module the change touches (`api`, `cli`, `web`, `auth`), or `release` for version commits. Do not use the repository name as a scope.
|
|
15
|
+
- `subject` is English, imperative, lower case, no trailing period, at most 72 characters.
|
|
16
|
+
- `revert` is not a valid type. A mistake is corrected with a new commit, never by reverting.
|
|
17
|
+
|
|
18
|
+
A body is required when the reason for the change is not obvious from the subject. Wrap the body at 72 characters and separate it from the subject with one blank line.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
fix(grep): respect .gitignore when searching directories
|
|
22
|
+
|
|
23
|
+
Directory walks included ignored files, so search results disagreed with
|
|
24
|
+
`git status`. The walker now filters through the ignore rules first.
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Branches
|
|
28
|
+
|
|
29
|
+
Name branches `type/short-topic`, using the same types as commits: `feat/issue-templates`, `fix/context-budget`. One branch carries one change.
|
|
30
|
+
|
|
31
|
+
## Pull requests
|
|
32
|
+
|
|
33
|
+
Title: same format as a commit subject.
|
|
34
|
+
|
|
35
|
+
Body: three sections, always in this order, at most three bullets each.
|
|
36
|
+
|
|
37
|
+
```markdown
|
|
38
|
+
## What
|
|
39
|
+
- What changed.
|
|
40
|
+
|
|
41
|
+
## Why
|
|
42
|
+
- Why it was needed.
|
|
43
|
+
|
|
44
|
+
## Verify
|
|
45
|
+
- How it was checked.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Merging:
|
|
49
|
+
|
|
50
|
+
- Merge commits only. Squash merge and rebase merge are prohibited.
|
|
51
|
+
- A wrong change is corrected with a new commit on a new branch.
|
|
52
|
+
- `git revert` is prohibited.
|
|
53
|
+
|
|
54
|
+
## Issues
|
|
55
|
+
|
|
56
|
+
Three forms are available: `bug`, `feature`, `task`. A blank issue is not accepted.
|
|
57
|
+
|
|
58
|
+
- `bug`: what happened, what was expected, how to reproduce, environment.
|
|
59
|
+
- `feature`: the problem, the proposed behaviour, alternatives considered.
|
|
60
|
+
- `task`: the goal, definition of done, related issues.
|
|
61
|
+
|
|
62
|
+
Every form is required to state what is observable. "Does not work" without a symptom is not a report.
|
|
63
|
+
|
|
64
|
+
## Versioning
|
|
65
|
+
|
|
66
|
+
Versions follow Semantic Versioning: `MAJOR.MINOR.PATCH`.
|
|
67
|
+
|
|
68
|
+
While the major version is `0`, a breaking change increments `MINOR` and any other change increments `PATCH`. `MAJOR` moves to `1` only when the public interface is declared stable.
|
|
69
|
+
|
|
70
|
+
Each published package carries its own version. A repository with one package has one version; a repository that publishes several packages bumps each one separately in the same release commit.
|
|
71
|
+
|
|
72
|
+
Version changes are never mixed into a feature pull request. They are made in a dedicated branch and commit:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
chore(release): bump version to 0.6.0
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Releases
|
|
79
|
+
|
|
80
|
+
A release is a Git tag named `vX.Y.Z` on `main`, with a matching entry in the package manifest and a changelog. It is published only after the version commit is merged.
|
|
81
|
+
|
|
82
|
+
Every release is created with the pre-release flag set while the package is below `1.0.0`. A package at `1.0.0` or above may publish a stable release.
|
|
83
|
+
|
|
84
|
+
Release notes use four groups, in this order, each omitted when empty:
|
|
85
|
+
|
|
86
|
+
## Added
|
|
87
|
+
## Changed
|
|
88
|
+
## Fixed
|
|
89
|
+
## Removed
|
|
90
|
+
|
|
91
|
+
A commit is listed in exactly one group, by type:
|
|
92
|
+
|
|
93
|
+
| Type | Group |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `feat` | Added |
|
|
96
|
+
| `fix` | Fixed |
|
|
97
|
+
| `perf`, `refactor`, `ci`, `build` | Changed |
|
|
98
|
+
| `docs`, `style`, `test`, `chore` | not listed |
|
|
99
|
+
|
|
100
|
+
`Removed` is not derived from a commit type. It lists features or public
|
|
101
|
+
interfaces that no longer exist, and is written by hand from the diff.
|
|
102
|
+
|
|
103
|
+
`chore(release)` commits never appear in release notes; the version itself
|
|
104
|
+
is the release note.
|
|
105
|
+
Tags are created only on `main`, only after the version commit is merged, and never moved or deleted.
|
|
106
|
+
|
|
107
|
+
## Before opening a pull request
|
|
108
|
+
|
|
109
|
+
- Format, lint and test the code with the commands listed in `AGENTS.md`.
|
|
110
|
+
- Check the commit subject against the rules above.
|
|
111
|
+
- Check the pull request body against the three-section template.
|
|
112
|
+
- Confirm no version change leaked into the branch.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RedQueenArk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rqark-sandbox
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Red Queen Ark Sandbox - docker workspace, file and shell tools, git tools and sandbox prompts for rqark agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/Red-Queen-Ark/rqark-sandbox
|
|
6
|
+
Project-URL: Repository, https://github.com/Red-Queen-Ark/rqark-sandbox
|
|
7
|
+
Project-URL: Issues, https://github.com/Red-Queen-Ark/rqark-sandbox/issues
|
|
8
|
+
Author: RedQueenArk
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,docker,sandbox,tools,workspace
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.14
|
|
16
|
+
Requires-Dist: docker>=7.2.0
|
|
17
|
+
Requires-Dist: rqark-app==0.13.1
|
|
18
|
+
Requires-Dist: rqark-core==0.5.3
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# rqark-sandbox
|
|
22
|
+
|
|
23
|
+
A docker workspace for `rqark-app` agents: file, shell and git tools that run inside a per-user container, plus the prompts that describe that container to the model.
|
|
24
|
+
|
|
25
|
+
## Why rqark-sandbox
|
|
26
|
+
|
|
27
|
+
`rqark-core` tools run in the host process. This one runs them next to the data: every user gets a named container with a mounted volume, and the agent's tools are swapped for workspace-backed versions that cannot leave `/workspace`.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Requires Python 3.14+.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv add rqark-sandbox
|
|
35
|
+
# or
|
|
36
|
+
pip install rqark-sandbox
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from rqark_app.agent.agents import Wednesday
|
|
43
|
+
from rqark_sandbox import Workspace, swap_agent
|
|
44
|
+
|
|
45
|
+
workspace = Workspace('user-1', image='ubuntu:24.04')
|
|
46
|
+
await workspace.ensure()
|
|
47
|
+
|
|
48
|
+
agent = swap_agent(Wednesday(), workspace)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What it ships
|
|
52
|
+
|
|
53
|
+
| Module | Contents |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `rqark_sandbox.workspace` | `Workspace`: container lifecycle, file read/write, shell exec, archive, upload and download caps |
|
|
56
|
+
| `rqark_sandbox.project` | `load_project`: the project a session works in |
|
|
57
|
+
| `rqark_sandbox.tools` | `exec`, `read_file`, `write_file`, `edit_file`, `list_dir`, `grep`, `convert_document` and the git tools |
|
|
58
|
+
| `rqark_sandbox.prompts` | `AgentsMdPrompt`, `GitProjectPrompt`, `PlatformPrompt`, workspace prompt |
|
|
59
|
+
| `rqark_sandbox.swap_agent` | Replaces an agent's tools and prompts with the workspace-backed versions |
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
Environment variables read by the package:
|
|
64
|
+
|
|
65
|
+
| Variable | Default | Meaning |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| `WORKSPACE_MAX_BYTES` | `104857600` | largest file the workspace will read or write |
|
|
68
|
+
| `WORKSPACE_SHELL_MAX_BYTES` | `8388608` | stdout and stderr cap for one shell call |
|
|
69
|
+
|
|
70
|
+
The container image is not an environment variable here: `Workspace` takes it as an argument.
|
|
71
|
+
|
|
72
|
+
The host needs access to the docker socket, and the image must exist locally.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# rqark-sandbox
|
|
2
|
+
|
|
3
|
+
A docker workspace for `rqark-app` agents: file, shell and git tools that run inside a per-user container, plus the prompts that describe that container to the model.
|
|
4
|
+
|
|
5
|
+
## Why rqark-sandbox
|
|
6
|
+
|
|
7
|
+
`rqark-core` tools run in the host process. This one runs them next to the data: every user gets a named container with a mounted volume, and the agent's tools are swapped for workspace-backed versions that cannot leave `/workspace`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Requires Python 3.14+.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv add rqark-sandbox
|
|
15
|
+
# or
|
|
16
|
+
pip install rqark-sandbox
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from rqark_app.agent.agents import Wednesday
|
|
23
|
+
from rqark_sandbox import Workspace, swap_agent
|
|
24
|
+
|
|
25
|
+
workspace = Workspace('user-1', image='ubuntu:24.04')
|
|
26
|
+
await workspace.ensure()
|
|
27
|
+
|
|
28
|
+
agent = swap_agent(Wednesday(), workspace)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What it ships
|
|
32
|
+
|
|
33
|
+
| Module | Contents |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `rqark_sandbox.workspace` | `Workspace`: container lifecycle, file read/write, shell exec, archive, upload and download caps |
|
|
36
|
+
| `rqark_sandbox.project` | `load_project`: the project a session works in |
|
|
37
|
+
| `rqark_sandbox.tools` | `exec`, `read_file`, `write_file`, `edit_file`, `list_dir`, `grep`, `convert_document` and the git tools |
|
|
38
|
+
| `rqark_sandbox.prompts` | `AgentsMdPrompt`, `GitProjectPrompt`, `PlatformPrompt`, workspace prompt |
|
|
39
|
+
| `rqark_sandbox.swap_agent` | Replaces an agent's tools and prompts with the workspace-backed versions |
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
Environment variables read by the package:
|
|
44
|
+
|
|
45
|
+
| Variable | Default | Meaning |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `WORKSPACE_MAX_BYTES` | `104857600` | largest file the workspace will read or write |
|
|
48
|
+
| `WORKSPACE_SHELL_MAX_BYTES` | `8388608` | stdout and stderr cap for one shell call |
|
|
49
|
+
|
|
50
|
+
The container image is not an environment variable here: `Workspace` takes it as an argument.
|
|
51
|
+
|
|
52
|
+
The host needs access to the docker socket, and the image must exist locally.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rqark-sandbox"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Red Queen Ark Sandbox - docker workspace, file and shell tools, git tools and sandbox prompts for rqark agents"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.14"
|
|
9
|
+
authors = [{ name = "RedQueenArk" }]
|
|
10
|
+
keywords = ["agent", "sandbox", "docker", "workspace", "tools"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Programming Language :: Python :: 3.14",
|
|
14
|
+
"Typing :: Typed",
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"docker>=7.2.0",
|
|
18
|
+
"rqark-app==0.13.1",
|
|
19
|
+
"rqark-core==0.5.3",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/Red-Queen-Ark/rqark-sandbox"
|
|
24
|
+
Repository = "https://github.com/Red-Queen-Ark/rqark-sandbox"
|
|
25
|
+
Issues = "https://github.com/Red-Queen-Ark/rqark-sandbox/issues"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.wheel]
|
|
32
|
+
packages = ["src/rqark_sandbox"]
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"mypy>=2.1.0",
|
|
37
|
+
"pyright>=1.1.411",
|
|
38
|
+
"pytest>=9.1.1",
|
|
39
|
+
"pytest-asyncio>=1.4.0",
|
|
40
|
+
"ruff>=0.15.14",
|
|
41
|
+
"ty>=0.0.38",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
exclude = ["*.ipynb"]
|
|
46
|
+
line-length = 240
|
|
47
|
+
indent-width = 4
|
|
48
|
+
target-version = "py314"
|
|
49
|
+
|
|
50
|
+
[tool.ruff.format]
|
|
51
|
+
quote-style = 'single'
|
|
52
|
+
skip-magic-trailing-comma = true
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
select = ["E", "F", "I", "N", "W"]
|
|
56
|
+
ignore = ["E501"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff.lint.isort]
|
|
59
|
+
split-on-trailing-comma = false
|
|
60
|
+
|
|
61
|
+
[tool.ty.src]
|
|
62
|
+
exclude = ["tests/"]
|
|
63
|
+
|
|
64
|
+
[tool.ty.environment]
|
|
65
|
+
python-platform = "all"
|
|
66
|
+
|
|
67
|
+
[tool.pytest.ini_options]
|
|
68
|
+
testpaths = ["tests"]
|
|
69
|
+
asyncio_mode = "auto"
|
|
70
|
+
markers = []
|
|
71
|
+
filterwarnings = ["default"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from rqark_app.types.agent import BaseAgent
|
|
2
|
+
|
|
3
|
+
from rqark_sandbox.prompts import swap_prompts
|
|
4
|
+
from rqark_sandbox.tools import swap_tools
|
|
5
|
+
from rqark_sandbox.workspace import FileMissingError, IsDirectoryError, PathOutsideWorkspaceError, ShellResult, Workspace, WorkspaceError
|
|
6
|
+
|
|
7
|
+
__all__ = ['FileMissingError', 'IsDirectoryError', 'PathOutsideWorkspaceError', 'ShellResult', 'Workspace', 'WorkspaceError', 'swap_agent', 'swap_prompts', 'swap_tools']
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def swap_agent(agent: BaseAgent, workspace: Workspace) -> BaseAgent:
|
|
11
|
+
agent.prompts = swap_prompts(agent.prompts, workspace)
|
|
12
|
+
agent.tools = swap_tools(agent.tools, workspace)
|
|
13
|
+
return agent
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _int_env(name: str, default: str) -> int:
|
|
5
|
+
return int(os.getenv(name, default))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
WORKSPACE_MAX_BYTES = _int_env('WORKSPACE_MAX_BYTES', str(100 * 1024 * 1024))
|
|
9
|
+
WORKSPACE_SHELL_MAX_BYTES = _int_env('WORKSPACE_SHELL_MAX_BYTES', str(8 * 1024 * 1024))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from rqark_app.cloud.client import DataCloudError, RQArkDataCloudClient
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def load_project(client: RQArkDataCloudClient, project_id: object, *, session_id: str = '') -> dict | None:
|
|
9
|
+
"""The project a session works in, or None when it names none.
|
|
10
|
+
|
|
11
|
+
A project that the session points at but the cloud no longer has is treated
|
|
12
|
+
as no project: the conversation outlives the directory, so the turn runs at
|
|
13
|
+
the volume root instead of failing.
|
|
14
|
+
"""
|
|
15
|
+
if not project_id:
|
|
16
|
+
return None
|
|
17
|
+
try:
|
|
18
|
+
return await client.get_project(str(project_id))
|
|
19
|
+
except DataCloudError as error:
|
|
20
|
+
if error.status_code != 404:
|
|
21
|
+
raise
|
|
22
|
+
logger.warning('project not found project=%s session=%s', project_id, session_id)
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def project_subdir(project: dict | None) -> str:
|
|
27
|
+
"""The directory a project names, relative to the workspace root."""
|
|
28
|
+
if not project:
|
|
29
|
+
return ''
|
|
30
|
+
return str(project.get('project_path') or '')
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from collections.abc import Callable, Sequence
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from rqark_core.prompts import WorkspacePrompt as CoreWorkspacePrompt
|
|
5
|
+
from rqark_core.types.prompt import BasePrompt
|
|
6
|
+
|
|
7
|
+
from rqark_sandbox.prompts.agents_md import AgentsMdPrompt
|
|
8
|
+
from rqark_sandbox.prompts.git_project import GitProjectPrompt
|
|
9
|
+
from rqark_sandbox.prompts.platform import PlatformPrompt
|
|
10
|
+
from rqark_sandbox.workspace import Workspace
|
|
11
|
+
|
|
12
|
+
__all__ = ['AgentsMdPrompt', 'GitProjectPrompt', 'PROMPTS', 'PlatformPrompt', 'swap_prompts']
|
|
13
|
+
|
|
14
|
+
PROMPTS: dict[str, Callable[[Workspace], BasePrompt]] = {
|
|
15
|
+
'AgentsMdPrompt': AgentsMdPrompt,
|
|
16
|
+
'GitProjectPrompt': GitProjectPrompt,
|
|
17
|
+
'PlatformPrompt': lambda workspace: PlatformPrompt(),
|
|
18
|
+
'WorkspacePrompt': lambda workspace: CoreWorkspacePrompt(Path(workspace.workdir)),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def swap_prompts(prompts: Sequence[BasePrompt], workspace: Workspace) -> list[BasePrompt]:
|
|
23
|
+
return [_swap(prompt, workspace) for prompt in prompts]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _swap(prompt: BasePrompt, workspace: Workspace) -> BasePrompt:
|
|
27
|
+
replacement = PROMPTS.get(type(prompt).__name__)
|
|
28
|
+
if replacement is None:
|
|
29
|
+
return prompt
|
|
30
|
+
return replacement(workspace)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
|
|
3
|
+
from rqark_core.types.prompt import BasePrompt, PromptContext
|
|
4
|
+
|
|
5
|
+
from rqark_sandbox.workspace import Workspace
|
|
6
|
+
|
|
7
|
+
AGENTS_MD = 'AGENTS.md'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AgentsMdPrompt(BasePrompt):
|
|
11
|
+
priority = 50
|
|
12
|
+
|
|
13
|
+
def __init__(self, workspace: Workspace):
|
|
14
|
+
self.workspace = workspace
|
|
15
|
+
|
|
16
|
+
async def get_messages(self, ctx: PromptContext | None = None) -> str | None:
|
|
17
|
+
path = f'{self.workspace.workdir}/{AGENTS_MD}'
|
|
18
|
+
result = await self.workspace.shell(f'cat -- {shlex.quote(path)}')
|
|
19
|
+
if result.exit_code != 0:
|
|
20
|
+
return None
|
|
21
|
+
return f'## Project Instructions (AGENTS.md)\n\n{result.stdout.strip()}'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import shlex
|
|
3
|
+
|
|
4
|
+
from rqark_core.types.prompt import BasePrompt, PromptContext
|
|
5
|
+
|
|
6
|
+
from rqark_sandbox.workspace import ShellResult, Workspace
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GitProjectPrompt(BasePrompt):
|
|
10
|
+
priority = 70
|
|
11
|
+
|
|
12
|
+
def __init__(self, workspace: Workspace):
|
|
13
|
+
self.workspace = workspace
|
|
14
|
+
|
|
15
|
+
async def _git(self, args: list[str]) -> str | None:
|
|
16
|
+
result = await self.workspace.shell(shlex.join(['git', *args]), cwd=self.workspace.workdir, timeout=10)
|
|
17
|
+
if result.exit_code != 0:
|
|
18
|
+
return None
|
|
19
|
+
return result.stdout.strip() or None
|
|
20
|
+
|
|
21
|
+
async def _is_git_project(self) -> bool:
|
|
22
|
+
marker = shlex.quote(self.workspace.workdir + '/.git')
|
|
23
|
+
result: ShellResult = await self.workspace.shell(f'[ -d {marker} ]')
|
|
24
|
+
return result.exit_code == 0
|
|
25
|
+
|
|
26
|
+
async def get_messages(self, ctx: PromptContext | None = None) -> str | None:
|
|
27
|
+
if not await self._is_git_project():
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
branch, head, status, log = await asyncio.gather(self._git(['branch', '--show-current']), self._git(['rev-parse', 'HEAD']), self._git(['status', '--porcelain']), self._git(['log', '--oneline', '-10', '--decorate']))
|
|
31
|
+
|
|
32
|
+
parts: list[str] = ['## Git Project Context']
|
|
33
|
+
|
|
34
|
+
if branch:
|
|
35
|
+
parts.append(f'Current branch: {branch}')
|
|
36
|
+
|
|
37
|
+
if head:
|
|
38
|
+
parts.append(f'HEAD: {head}')
|
|
39
|
+
|
|
40
|
+
if status:
|
|
41
|
+
status_lines = status.split('\n')
|
|
42
|
+
parts.append('Working tree status (porcelain):\n' + '\n'.join(status_lines[:40]))
|
|
43
|
+
if len(status_lines) > 40:
|
|
44
|
+
parts.append(f'... ({len(status_lines) - 40} more lines truncated)')
|
|
45
|
+
else:
|
|
46
|
+
parts.append('Working tree: clean')
|
|
47
|
+
|
|
48
|
+
if log:
|
|
49
|
+
parts.append(f'Recent commits:\n{log}')
|
|
50
|
+
|
|
51
|
+
return '\n\n'.join(parts)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from rqark_core.types.prompt import BasePrompt, PromptContext
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PlatformPrompt(BasePrompt):
|
|
5
|
+
priority = 30
|
|
6
|
+
|
|
7
|
+
async def get_messages(self, ctx: PromptContext | None = None) -> str:
|
|
8
|
+
return '## Platform\nYou are running on Linux inside a Docker container. Use Unix-style paths with forward slashes, and prefer sh/bash syntax for shell commands. The exec tool runs commands with /bin/sh.'
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
|
|
3
|
+
from rqark_core.tools.subagent import SubAgent
|
|
4
|
+
from rqark_core.types.tool import BaseTool
|
|
5
|
+
|
|
6
|
+
from rqark_sandbox.prompts import swap_prompts
|
|
7
|
+
from rqark_sandbox.tools.base import WorkspaceTool
|
|
8
|
+
from rqark_sandbox.tools.convert_document import ConvertDocument
|
|
9
|
+
from rqark_sandbox.tools.edit_file import EditFile
|
|
10
|
+
from rqark_sandbox.tools.exec import Exec
|
|
11
|
+
from rqark_sandbox.tools.git import GIT_TOOLS
|
|
12
|
+
from rqark_sandbox.tools.grep import Grep
|
|
13
|
+
from rqark_sandbox.tools.list_dir import ListDir
|
|
14
|
+
from rqark_sandbox.tools.read_file import ReadFile
|
|
15
|
+
from rqark_sandbox.tools.write_file import WriteFile
|
|
16
|
+
from rqark_sandbox.workspace import Workspace
|
|
17
|
+
|
|
18
|
+
__all__ = ['ConvertDocument', 'EditFile', 'Exec', 'Grep', 'ListDir', 'ReadFile', 'WorkspaceTool', 'WriteFile', 'build_workspace_tools', 'swap_tools']
|
|
19
|
+
|
|
20
|
+
WORKSPACE_TOOLS: dict[str, type[WorkspaceTool]] = {'exec': Exec, 'read_file': ReadFile, 'write_file': WriteFile, 'edit_file': EditFile, 'grep': Grep, 'list_dir': ListDir, 'convert_document': ConvertDocument}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build_workspace_tools(workspace: Workspace) -> list[BaseTool]:
|
|
24
|
+
return [Exec(workspace), ReadFile(workspace), WriteFile(workspace), EditFile(workspace), Grep(workspace), ListDir(workspace), ConvertDocument(workspace)]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def swap_tools(tools: Sequence[BaseTool], workspace: Workspace) -> list[BaseTool]:
|
|
28
|
+
return [_swap(tool, workspace) for tool in tools]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _swap(tool: BaseTool, workspace: Workspace) -> BaseTool:
|
|
32
|
+
if isinstance(tool, SubAgent):
|
|
33
|
+
return SubAgent(swap_prompts(tool.prompts, workspace), swap_tools(tool.tools, workspace))
|
|
34
|
+
name = tool.name
|
|
35
|
+
if name in WORKSPACE_TOOLS:
|
|
36
|
+
return WORKSPACE_TOOLS[name](workspace)
|
|
37
|
+
if name in GIT_TOOLS:
|
|
38
|
+
return GIT_TOOLS[name](workspace, **tool.params())
|
|
39
|
+
return tool
|