guoji 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.
- guoji-0.1.0/LICENSE +21 -0
- guoji-0.1.0/PKG-INFO +218 -0
- guoji-0.1.0/README.md +188 -0
- guoji-0.1.0/guoji/__init__.py +3 -0
- guoji-0.1.0/guoji/__main__.py +8 -0
- guoji-0.1.0/guoji/agents.py +80 -0
- guoji-0.1.0/guoji/changes.py +56 -0
- guoji-0.1.0/guoji/cli.py +406 -0
- guoji-0.1.0/guoji/diffing.py +96 -0
- guoji-0.1.0/guoji/errors.py +25 -0
- guoji-0.1.0/guoji/fsutil.py +80 -0
- guoji-0.1.0/guoji/paths.py +144 -0
- guoji-0.1.0/guoji/py.typed +0 -0
- guoji-0.1.0/guoji/restore.py +34 -0
- guoji-0.1.0/guoji/snapshot.py +78 -0
- guoji-0.1.0/guoji/templates.py +114 -0
- guoji-0.1.0/guoji/ui.py +86 -0
- guoji-0.1.0/guoji.egg-info/PKG-INFO +218 -0
- guoji-0.1.0/guoji.egg-info/SOURCES.txt +24 -0
- guoji-0.1.0/guoji.egg-info/dependency_links.txt +1 -0
- guoji-0.1.0/guoji.egg-info/entry_points.txt +2 -0
- guoji-0.1.0/guoji.egg-info/requires.txt +4 -0
- guoji-0.1.0/guoji.egg-info/top_level.txt +1 -0
- guoji-0.1.0/pyproject.toml +51 -0
- guoji-0.1.0/setup.cfg +4 -0
- guoji-0.1.0/tests/test_guoji.py +256 -0
guoji-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sukiop
|
|
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.
|
guoji-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guoji
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sandbox for AI agents: snapshot a project and roll changes back
|
|
5
|
+
Author: sukiop
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dev-overused/guoji
|
|
8
|
+
Project-URL: Repository, https://github.com/dev-overused/guoji
|
|
9
|
+
Project-URL: Issues, https://github.com/dev-overused/guoji/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/dev-overused/guoji/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: sandbox,ai,agents,snapshot,rollback,opencode,claude,codex
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
28
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# guoji
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/guoji/)
|
|
34
|
+
[](https://pypi.org/project/guoji/)
|
|
35
|
+
[](LICENSE)
|
|
36
|
+
[](https://github.com/dev-overused/guoji)
|
|
37
|
+
|
|
38
|
+
A sandbox for AI agents: before work starts the agent records the project state, and
|
|
39
|
+
later a single command either keeps the changes or rolls everything back.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
/guoji # start a sandbox (snapshot the project)
|
|
43
|
+
/guoji restore # leave: apply the changes or discard them
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Works with **OpenCode**, **Claude Code**, and **Codex**.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pip install guoji
|
|
52
|
+
guoji init
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`guoji init` asks which agents to set up:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Which agent(s) should I set up?
|
|
59
|
+
1) OpenCode .opencode/commands/guoji.md (detected)
|
|
60
|
+
2) Claude Code .claude/commands/guoji.md
|
|
61
|
+
3) Codex .codex/skills/guoji/SKILL.md
|
|
62
|
+
Selection [1,2,3, a=all] (Enter - opencode):
|
|
63
|
+
Install for the project or globally? [p] project / [g] global (Enter - project):
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Non-interactive:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
guoji init --agent opencode # one agent
|
|
70
|
+
guoji init --agent opencode,claude # several
|
|
71
|
+
guoji init --all # all three
|
|
72
|
+
guoji init --all --global # into the user's personal folders
|
|
73
|
+
guoji init --all --force # overwrite existing files
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
| Agent | Project file | Global |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| OpenCode | `.opencode/commands/guoji.md` | `~/.config/opencode/commands/guoji.md` |
|
|
79
|
+
| Claude Code | `.claude/commands/guoji.md` | `~/.claude/commands/guoji.md` |
|
|
80
|
+
| Codex | `.codex/skills/guoji/SKILL.md` | `~/.codex/skills/guoji/SKILL.md` |
|
|
81
|
+
|
|
82
|
+
`guoji install` is the legacy shortcut that only sets up OpenCode.
|
|
83
|
+
|
|
84
|
+
## How it works
|
|
85
|
+
|
|
86
|
+
`guoji` does not copy the project into a separate directory and does not swap the
|
|
87
|
+
working directory. Instead it takes a snapshot (baseline) inside the project:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
project/
|
|
91
|
+
.guoji/
|
|
92
|
+
baseline/ # copy of the files at start time
|
|
93
|
+
manifest.json # hashes and sizes of the files
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The agent keeps working in the normal project, and `restore` compares the current
|
|
97
|
+
files with the snapshot:
|
|
98
|
+
|
|
99
|
+
- `--apply` — keep everything as is and remove the sandbox;
|
|
100
|
+
- `--discard` — restore modified and deleted files from the snapshot, remove files
|
|
101
|
+
created after the start, and clean up `.guoji/`.
|
|
102
|
+
|
|
103
|
+
The list of changes and a unified diff are shown before the rollback.
|
|
104
|
+
|
|
105
|
+
## Commands
|
|
106
|
+
|
|
107
|
+
| Command | What it does |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `guoji start` | Snapshot the current project state |
|
|
110
|
+
| `guoji status` | Show when the snapshot was created and what changed |
|
|
111
|
+
| `guoji diff` | Change list + diff (`--name-only`, `--max-lines N`) |
|
|
112
|
+
| `guoji restore` | Show the changes and ask: apply or discard |
|
|
113
|
+
| `guoji restore --apply` | Keep the changes, remove the sandbox |
|
|
114
|
+
| `guoji restore --discard` | Restore the snapshot, remove the sandbox |
|
|
115
|
+
| `guoji restore --dry-run` | Show the plan, change nothing |
|
|
116
|
+
| `guoji init` | Set up the integration for OpenCode / Claude Code / Codex |
|
|
117
|
+
| `guoji install` | Install `/guoji` into OpenCode only |
|
|
118
|
+
| `guoji --version` | Print the version |
|
|
119
|
+
|
|
120
|
+
Global flags: `--root <dir>` (defaults to the current directory), `--no-color`.
|
|
121
|
+
|
|
122
|
+
Exit codes: `0` — success, `1` — error, `2` — a decision is required
|
|
123
|
+
(`restore` or `init` without the needed flags in a non-interactive session).
|
|
124
|
+
|
|
125
|
+
## What is ignored
|
|
126
|
+
|
|
127
|
+
By default the snapshot skips:
|
|
128
|
+
|
|
129
|
+
`.git`, `node_modules`, `.guoji`, `__pycache__`, `.venv`, `venv`,
|
|
130
|
+
`.mypy_cache`, `.pytest_cache`, `.ruff_cache`, `.DS_Store`, `Thumbs.db`.
|
|
131
|
+
|
|
132
|
+
Add your own rules in `guoji.json` at the project root:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"ignore": ["dist", "*.log", "coverage/"]
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
A pattern without `/` matches any path component (`node_modules`); a pattern with
|
|
141
|
+
`/` matches the whole relative path (`docs/generated`).
|
|
142
|
+
|
|
143
|
+
## Example
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
$ /guoji
|
|
147
|
+
Sandbox started.
|
|
148
|
+
project: C:\work\app
|
|
149
|
+
snapshot: C:\work\app\.guoji
|
|
150
|
+
files: 128
|
|
151
|
+
ignore: .git, node_modules, .guoji, ...
|
|
152
|
+
|
|
153
|
+
$ /guoji restore
|
|
154
|
+
guoji restore
|
|
155
|
+
Changed files: 3 (+1 ~2 -0)
|
|
156
|
+
A src/new.ts (1.2 KB)
|
|
157
|
+
M src/api.ts (3.4 KB -> 3.9 KB)
|
|
158
|
+
...
|
|
159
|
+
--- a/src/api.ts
|
|
160
|
+
+++ b/src/api.ts
|
|
161
|
+
@@ -1,3 +1,3 @@
|
|
162
|
+
-old
|
|
163
|
+
+new
|
|
164
|
+
|
|
165
|
+
What should we do with the changes?
|
|
166
|
+
[a] apply / [d] discard / [q] cancel:
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Limitations
|
|
170
|
+
|
|
171
|
+
- Rollback only covers project files that are not in the ignore list. Changes in
|
|
172
|
+
`.git`, `node_modules`, databases, running processes, and files outside the project
|
|
173
|
+
are not restored.
|
|
174
|
+
- Symbolic links and junction directories are skipped.
|
|
175
|
+
- Files larger than 2 MB are not rendered in the diff (they are still copied and
|
|
176
|
+
rolled back).
|
|
177
|
+
- The snapshot lives in `.guoji/` and is not protected from deletion: add `.guoji/`
|
|
178
|
+
to `.gitignore` and do not remove the directory by hand while working.
|
|
179
|
+
|
|
180
|
+
## Publishing to PyPI
|
|
181
|
+
|
|
182
|
+
The package follows modern packaging rules: `pyproject.toml`, `py.typed`, a console
|
|
183
|
+
script, and the version is read from `guoji/__init__.py`.
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
python -m pip install build twine
|
|
187
|
+
python -m build
|
|
188
|
+
python -m twine check dist/*
|
|
189
|
+
python -m twine upload dist/* # or: python -m twine upload --repository testpypi dist/*
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
GitHub Actions already has `.github/workflows/publish.yml` with trusted publishing:
|
|
193
|
+
|
|
194
|
+
1. On PyPI -> *Publishing*, add a trusted publisher for the repository
|
|
195
|
+
(workflow `publish.yml`, environment `pypi`).
|
|
196
|
+
2. Create a GitHub Release - the workflow builds and publishes the package.
|
|
197
|
+
|
|
198
|
+
Before a release:
|
|
199
|
+
|
|
200
|
+
- bump the version in `guoji/__init__.py`;
|
|
201
|
+
- update `CHANGELOG.md`;
|
|
202
|
+
- run the tests: `python -m unittest discover -s tests -v`.
|
|
203
|
+
|
|
204
|
+
## Development
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
python -m unittest discover -s tests -v
|
|
208
|
+
python -m guoji init --agent opencode --force
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT - see [LICENSE](LICENSE).
|
|
214
|
+
|
|
215
|
+
## Contributors
|
|
216
|
+
|
|
217
|
+
- [sukiop](https://github.com/dev-overused)
|
|
218
|
+
- [opencode-agent](https://github.com/opencode-agent)
|
guoji-0.1.0/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# guoji
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/guoji/)
|
|
4
|
+
[](https://pypi.org/project/guoji/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/dev-overused/guoji)
|
|
7
|
+
|
|
8
|
+
A sandbox for AI agents: before work starts the agent records the project state, and
|
|
9
|
+
later a single command either keeps the changes or rolls everything back.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
/guoji # start a sandbox (snapshot the project)
|
|
13
|
+
/guoji restore # leave: apply the changes or discard them
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Works with **OpenCode**, **Claude Code**, and **Codex**.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pip install guoji
|
|
22
|
+
guoji init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`guoji init` asks which agents to set up:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
Which agent(s) should I set up?
|
|
29
|
+
1) OpenCode .opencode/commands/guoji.md (detected)
|
|
30
|
+
2) Claude Code .claude/commands/guoji.md
|
|
31
|
+
3) Codex .codex/skills/guoji/SKILL.md
|
|
32
|
+
Selection [1,2,3, a=all] (Enter - opencode):
|
|
33
|
+
Install for the project or globally? [p] project / [g] global (Enter - project):
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Non-interactive:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
guoji init --agent opencode # one agent
|
|
40
|
+
guoji init --agent opencode,claude # several
|
|
41
|
+
guoji init --all # all three
|
|
42
|
+
guoji init --all --global # into the user's personal folders
|
|
43
|
+
guoji init --all --force # overwrite existing files
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Agent | Project file | Global |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| OpenCode | `.opencode/commands/guoji.md` | `~/.config/opencode/commands/guoji.md` |
|
|
49
|
+
| Claude Code | `.claude/commands/guoji.md` | `~/.claude/commands/guoji.md` |
|
|
50
|
+
| Codex | `.codex/skills/guoji/SKILL.md` | `~/.codex/skills/guoji/SKILL.md` |
|
|
51
|
+
|
|
52
|
+
`guoji install` is the legacy shortcut that only sets up OpenCode.
|
|
53
|
+
|
|
54
|
+
## How it works
|
|
55
|
+
|
|
56
|
+
`guoji` does not copy the project into a separate directory and does not swap the
|
|
57
|
+
working directory. Instead it takes a snapshot (baseline) inside the project:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
project/
|
|
61
|
+
.guoji/
|
|
62
|
+
baseline/ # copy of the files at start time
|
|
63
|
+
manifest.json # hashes and sizes of the files
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The agent keeps working in the normal project, and `restore` compares the current
|
|
67
|
+
files with the snapshot:
|
|
68
|
+
|
|
69
|
+
- `--apply` — keep everything as is and remove the sandbox;
|
|
70
|
+
- `--discard` — restore modified and deleted files from the snapshot, remove files
|
|
71
|
+
created after the start, and clean up `.guoji/`.
|
|
72
|
+
|
|
73
|
+
The list of changes and a unified diff are shown before the rollback.
|
|
74
|
+
|
|
75
|
+
## Commands
|
|
76
|
+
|
|
77
|
+
| Command | What it does |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `guoji start` | Snapshot the current project state |
|
|
80
|
+
| `guoji status` | Show when the snapshot was created and what changed |
|
|
81
|
+
| `guoji diff` | Change list + diff (`--name-only`, `--max-lines N`) |
|
|
82
|
+
| `guoji restore` | Show the changes and ask: apply or discard |
|
|
83
|
+
| `guoji restore --apply` | Keep the changes, remove the sandbox |
|
|
84
|
+
| `guoji restore --discard` | Restore the snapshot, remove the sandbox |
|
|
85
|
+
| `guoji restore --dry-run` | Show the plan, change nothing |
|
|
86
|
+
| `guoji init` | Set up the integration for OpenCode / Claude Code / Codex |
|
|
87
|
+
| `guoji install` | Install `/guoji` into OpenCode only |
|
|
88
|
+
| `guoji --version` | Print the version |
|
|
89
|
+
|
|
90
|
+
Global flags: `--root <dir>` (defaults to the current directory), `--no-color`.
|
|
91
|
+
|
|
92
|
+
Exit codes: `0` — success, `1` — error, `2` — a decision is required
|
|
93
|
+
(`restore` or `init` without the needed flags in a non-interactive session).
|
|
94
|
+
|
|
95
|
+
## What is ignored
|
|
96
|
+
|
|
97
|
+
By default the snapshot skips:
|
|
98
|
+
|
|
99
|
+
`.git`, `node_modules`, `.guoji`, `__pycache__`, `.venv`, `venv`,
|
|
100
|
+
`.mypy_cache`, `.pytest_cache`, `.ruff_cache`, `.DS_Store`, `Thumbs.db`.
|
|
101
|
+
|
|
102
|
+
Add your own rules in `guoji.json` at the project root:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"ignore": ["dist", "*.log", "coverage/"]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A pattern without `/` matches any path component (`node_modules`); a pattern with
|
|
111
|
+
`/` matches the whole relative path (`docs/generated`).
|
|
112
|
+
|
|
113
|
+
## Example
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
$ /guoji
|
|
117
|
+
Sandbox started.
|
|
118
|
+
project: C:\work\app
|
|
119
|
+
snapshot: C:\work\app\.guoji
|
|
120
|
+
files: 128
|
|
121
|
+
ignore: .git, node_modules, .guoji, ...
|
|
122
|
+
|
|
123
|
+
$ /guoji restore
|
|
124
|
+
guoji restore
|
|
125
|
+
Changed files: 3 (+1 ~2 -0)
|
|
126
|
+
A src/new.ts (1.2 KB)
|
|
127
|
+
M src/api.ts (3.4 KB -> 3.9 KB)
|
|
128
|
+
...
|
|
129
|
+
--- a/src/api.ts
|
|
130
|
+
+++ b/src/api.ts
|
|
131
|
+
@@ -1,3 +1,3 @@
|
|
132
|
+
-old
|
|
133
|
+
+new
|
|
134
|
+
|
|
135
|
+
What should we do with the changes?
|
|
136
|
+
[a] apply / [d] discard / [q] cancel:
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Limitations
|
|
140
|
+
|
|
141
|
+
- Rollback only covers project files that are not in the ignore list. Changes in
|
|
142
|
+
`.git`, `node_modules`, databases, running processes, and files outside the project
|
|
143
|
+
are not restored.
|
|
144
|
+
- Symbolic links and junction directories are skipped.
|
|
145
|
+
- Files larger than 2 MB are not rendered in the diff (they are still copied and
|
|
146
|
+
rolled back).
|
|
147
|
+
- The snapshot lives in `.guoji/` and is not protected from deletion: add `.guoji/`
|
|
148
|
+
to `.gitignore` and do not remove the directory by hand while working.
|
|
149
|
+
|
|
150
|
+
## Publishing to PyPI
|
|
151
|
+
|
|
152
|
+
The package follows modern packaging rules: `pyproject.toml`, `py.typed`, a console
|
|
153
|
+
script, and the version is read from `guoji/__init__.py`.
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
python -m pip install build twine
|
|
157
|
+
python -m build
|
|
158
|
+
python -m twine check dist/*
|
|
159
|
+
python -m twine upload dist/* # or: python -m twine upload --repository testpypi dist/*
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
GitHub Actions already has `.github/workflows/publish.yml` with trusted publishing:
|
|
163
|
+
|
|
164
|
+
1. On PyPI -> *Publishing*, add a trusted publisher for the repository
|
|
165
|
+
(workflow `publish.yml`, environment `pypi`).
|
|
166
|
+
2. Create a GitHub Release - the workflow builds and publishes the package.
|
|
167
|
+
|
|
168
|
+
Before a release:
|
|
169
|
+
|
|
170
|
+
- bump the version in `guoji/__init__.py`;
|
|
171
|
+
- update `CHANGELOG.md`;
|
|
172
|
+
- run the tests: `python -m unittest discover -s tests -v`.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
python -m unittest discover -s tests -v
|
|
178
|
+
python -m guoji init --agent opencode --force
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT - see [LICENSE](LICENSE).
|
|
184
|
+
|
|
185
|
+
## Contributors
|
|
186
|
+
|
|
187
|
+
- [sukiop](https://github.com/dev-overused)
|
|
188
|
+
- [opencode-agent](https://github.com/opencode-agent)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Supported AI agents and where their guoji integration lives."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Callable
|
|
9
|
+
|
|
10
|
+
from . import templates
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _global_base(kind: str) -> Path:
|
|
14
|
+
if kind == "config":
|
|
15
|
+
config_home = os.environ.get("XDG_CONFIG_HOME")
|
|
16
|
+
return Path(config_home) if config_home else Path.home() / ".config"
|
|
17
|
+
return Path.home()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Agent:
|
|
22
|
+
id: str
|
|
23
|
+
title: str
|
|
24
|
+
project_path: tuple[str, ...]
|
|
25
|
+
global_path: tuple[str, ...]
|
|
26
|
+
global_base: str
|
|
27
|
+
render: Callable[[], str]
|
|
28
|
+
|
|
29
|
+
def target(self, root: Path, global_: bool) -> Path:
|
|
30
|
+
if global_:
|
|
31
|
+
return _global_base(self.global_base).joinpath(*self.global_path)
|
|
32
|
+
return root.joinpath(*self.project_path)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
AGENTS: tuple[Agent, ...] = (
|
|
36
|
+
Agent(
|
|
37
|
+
id="opencode",
|
|
38
|
+
title="OpenCode",
|
|
39
|
+
project_path=(".opencode", "commands", "guoji.md"),
|
|
40
|
+
global_path=("opencode", "commands", "guoji.md"),
|
|
41
|
+
global_base="config",
|
|
42
|
+
render=templates.opencode_command,
|
|
43
|
+
),
|
|
44
|
+
Agent(
|
|
45
|
+
id="claude",
|
|
46
|
+
title="Claude Code",
|
|
47
|
+
project_path=(".claude", "commands", "guoji.md"),
|
|
48
|
+
global_path=(".claude", "commands", "guoji.md"),
|
|
49
|
+
global_base="home",
|
|
50
|
+
render=templates.claude_command,
|
|
51
|
+
),
|
|
52
|
+
Agent(
|
|
53
|
+
id="codex",
|
|
54
|
+
title="Codex",
|
|
55
|
+
project_path=(".codex", "skills", "guoji", "SKILL.md"),
|
|
56
|
+
global_path=(".codex", "skills", "guoji", "SKILL.md"),
|
|
57
|
+
global_base="home",
|
|
58
|
+
render=templates.codex_skill,
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def by_id(agent_id: str) -> Agent | None:
|
|
64
|
+
for agent in AGENTS:
|
|
65
|
+
if agent.id == agent_id:
|
|
66
|
+
return agent
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def parse_ids(raw: str) -> list[Agent] | None:
|
|
71
|
+
"""Parse ``"opencode,claude"`` into agents. Returns None on a bad token."""
|
|
72
|
+
|
|
73
|
+
chosen: list[Agent] = []
|
|
74
|
+
for token in raw.replace(",", " ").split():
|
|
75
|
+
agent = by_id(token.strip().lower())
|
|
76
|
+
if agent is None:
|
|
77
|
+
return None
|
|
78
|
+
if agent not in chosen:
|
|
79
|
+
chosen.append(agent)
|
|
80
|
+
return chosen
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Compare the current project tree with the baseline snapshot."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
from .fsutil import file_hash
|
|
8
|
+
from .paths import Config, Layout, iter_files
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Changes:
|
|
13
|
+
"""Files that differ from the snapshot."""
|
|
14
|
+
|
|
15
|
+
added: list[str] = field(default_factory=list)
|
|
16
|
+
modified: list[str] = field(default_factory=list)
|
|
17
|
+
deleted: list[str] = field(default_factory=list)
|
|
18
|
+
#: relative path -> (size before, size after); 0 means "did not exist".
|
|
19
|
+
sizes: dict[str, tuple[int, int]] = field(default_factory=dict)
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def total(self) -> int:
|
|
23
|
+
return len(self.added) + len(self.modified) + len(self.deleted)
|
|
24
|
+
|
|
25
|
+
def is_empty(self) -> bool:
|
|
26
|
+
return self.total == 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def scan(layout: Layout, config: Config, manifest: dict) -> Changes:
|
|
30
|
+
known: dict[str, dict] = manifest["files"]
|
|
31
|
+
changes = Changes()
|
|
32
|
+
seen: set[str] = set()
|
|
33
|
+
|
|
34
|
+
for relative, path in iter_files(layout, config):
|
|
35
|
+
seen.add(relative)
|
|
36
|
+
entry = known.get(relative)
|
|
37
|
+
try:
|
|
38
|
+
size = path.stat().st_size
|
|
39
|
+
except OSError:
|
|
40
|
+
continue
|
|
41
|
+
|
|
42
|
+
if entry is None:
|
|
43
|
+
changes.added.append(relative)
|
|
44
|
+
changes.sizes[relative] = (0, size)
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
if size != entry.get("size") or file_hash(path) != entry.get("sha256"):
|
|
48
|
+
changes.modified.append(relative)
|
|
49
|
+
changes.sizes[relative] = (int(entry.get("size", 0)), size)
|
|
50
|
+
|
|
51
|
+
changes.added.sort()
|
|
52
|
+
changes.modified.sort()
|
|
53
|
+
changes.deleted = sorted(relative for relative in known if relative not in seen)
|
|
54
|
+
for relative in changes.deleted:
|
|
55
|
+
changes.sizes[relative] = (int(known[relative].get("size", 0)), 0)
|
|
56
|
+
return changes
|