teabag 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.
- teabag-0.1.0/PKG-INFO +423 -0
- teabag-0.1.0/README.md +415 -0
- teabag-0.1.0/pyproject.toml +20 -0
- teabag-0.1.0/setup.cfg +4 -0
- teabag-0.1.0/teabag/__init__.py +4 -0
- teabag-0.1.0/teabag/cli.py +261 -0
- teabag-0.1.0/teabag/config.py +123 -0
- teabag-0.1.0/teabag/env.py +100 -0
- teabag-0.1.0/teabag/experiments.py +90 -0
- teabag-0.1.0/teabag/history.py +603 -0
- teabag-0.1.0/teabag/orchestrator.py +68 -0
- teabag-0.1.0/teabag/semantic.py +46 -0
- teabag-0.1.0/teabag/workspace.py +113 -0
- teabag-0.1.0/teabag.egg-info/PKG-INFO +423 -0
- teabag-0.1.0/teabag.egg-info/SOURCES.txt +17 -0
- teabag-0.1.0/teabag.egg-info/dependency_links.txt +1 -0
- teabag-0.1.0/teabag.egg-info/entry_points.txt +2 -0
- teabag-0.1.0/teabag.egg-info/top_level.txt +1 -0
- teabag-0.1.0/tests/test_phase1_workflow.py +61 -0
teabag-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: teabag
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-native version control CLI for safe AI-assisted development.
|
|
5
|
+
Author-email: teaBag <devnull@example.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# teaBag — How to Use
|
|
10
|
+
|
|
11
|
+
teaBag is a CLI for **AI-native version control**: it keeps your main codebase safe while AI tools edit code in isolated workspaces, and it records every run (prompt, intent, and diff) so you can review, compare, and merge changes in a structured way.
|
|
12
|
+
|
|
13
|
+
The CLI command is **`tb`**.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
From the teaBag project root:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install -e .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This installs the `tb` command. Requires **Python 3.10+** and a **git** repository (recommended) for diff capture.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd /path/to/your/project
|
|
33
|
+
|
|
34
|
+
# 1. Initialize teaBag (creates .teabag/, workspaces/, .ai_history/, env_store/)
|
|
35
|
+
tb init
|
|
36
|
+
|
|
37
|
+
# 2. Create a workspace for an AI agent
|
|
38
|
+
tb spawn agent_1
|
|
39
|
+
|
|
40
|
+
# 3. Human fills prompt.json (tb spawn creates a default with _teabag section)
|
|
41
|
+
# AI reads prompt.json and writes intent.json (only intent.json first)
|
|
42
|
+
# 4. Point your AI at workspaces/agent_1 to edit code, then record the run
|
|
43
|
+
tb run agent_1
|
|
44
|
+
|
|
45
|
+
# 5. List runs
|
|
46
|
+
tb list-runs
|
|
47
|
+
|
|
48
|
+
# 6. When done, remove the workspace
|
|
49
|
+
tb delete-workspace agent_1
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Your main project files stay untouched; all AI edits live under `workspaces/agent_1/`. Each `tb run` creates a snapshot under `.ai_history/run_001/`, `run_002/`, and so on.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Directory Layout
|
|
57
|
+
|
|
58
|
+
After `tb init`, your repo looks like this:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
your_project/
|
|
62
|
+
├── .teabag/ # Config and metadata
|
|
63
|
+
│ ├── config.json
|
|
64
|
+
│ ├── experiments.json
|
|
65
|
+
│ └── snapshots/ # Workspace snapshots (see below)
|
|
66
|
+
├── .ai_history/ # Recorded runs (immutable: intent.json and all artifacts are read-only after creation)
|
|
67
|
+
│ └── run_001/
|
|
68
|
+
│ ├── prompt.json # or prompt.md (human prompt; _teabag section in .json)
|
|
69
|
+
│ ├── intent.json
|
|
70
|
+
│ ├── diff.patch
|
|
71
|
+
│ ├── metadata.json
|
|
72
|
+
│ ├── environment.json # Python version, packages
|
|
73
|
+
│ ├── tests.json # If teabag.json test_command is set
|
|
74
|
+
│ └── metrics.json # If teabag.json metrics_script is set
|
|
75
|
+
├── workspaces/ # One directory per agent
|
|
76
|
+
│ └── agent_1/
|
|
77
|
+
│ ├── venv # Symlink to shared env (or ENV_PATH file)
|
|
78
|
+
│ ├── prompt.json # default from tb spawn; human fills "prompt"; AI reads and writes intent.json
|
|
79
|
+
│ └── intent.json # written by AI from prompt.json
|
|
80
|
+
├── env_store/ # Shared virtualenvs (keyed by Python + requirements.txt)
|
|
81
|
+
└── src/ # Your real code (unchanged until you accept a run)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Workspaces and Shared Environments
|
|
87
|
+
|
|
88
|
+
### Creating a workspace
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
tb spawn agent_1
|
|
92
|
+
tb spawn agent_2
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Each workspace gets a directory under `workspaces/` and a **shared Python virtualenv** (same Python version and repo-root `requirements.txt` share one env). The env is created under `env_store/<hash>/` and linked as `workspaces/<name>/venv`.
|
|
96
|
+
|
|
97
|
+
### Installing or changing packages
|
|
98
|
+
|
|
99
|
+
Use the workspace’s venv so all agents sharing that env see the same packages:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# From project root — no need to activate
|
|
103
|
+
workspaces/agent_1/venv/bin/pip install requests
|
|
104
|
+
workspaces/agent_1/venv/bin/pip install -r requirements.txt
|
|
105
|
+
workspaces/agent_1/venv/bin/pip uninstall -y some-package
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Or activate first (Linux/macOS):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
source workspaces/agent_1/venv/bin/activate
|
|
112
|
+
pip install requests
|
|
113
|
+
deactivate
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
If you change `requirements.txt` at the repo root, existing workspaces keep their current env until you delete and re-spawn them; new workspaces will use a new env hash.
|
|
117
|
+
|
|
118
|
+
### Listing and pruning environments
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
tb env list # List registered shared envs
|
|
122
|
+
tb env prune # Remove missing envs from the registry
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Recording a Run
|
|
128
|
+
|
|
129
|
+
Flow: **prompt.json → AI writes intent.json → apply only those changes → then run the rest.**
|
|
130
|
+
|
|
131
|
+
1. **`tb spawn`** creates a default **`prompt.json`** in the workspace with a **`_teabag`** section so the AI always knows to produce **`intent.json`**.
|
|
132
|
+
2. **Human** fills the **`prompt`** field in `prompt.json` (the task for the model).
|
|
133
|
+
3. **AI** reads `prompt.json`, writes **`intent.json`** (with at least `intent.goal`; optionally `intent.files_to_modify`, `parent_experiment`). The `_teabag` section ensures the AI generates intent.json before editing other files.
|
|
134
|
+
4. Then run **`tb run agent_1`** to record the run (and optionally run tests/metrics).
|
|
135
|
+
|
|
136
|
+
Default **`prompt.json`** (created by `tb spawn`; human fills `"prompt"`):
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"_teabag": {
|
|
141
|
+
"version": 1,
|
|
142
|
+
"instructions": "Read this prompt and write intent.json in this workspace. intent.json must have: \"intent\" object with \"goal\" (string, required), and optionally \"files_to_modify\" (array of file paths), \"parent_experiment\" (string). Do not modify any other files until intent.json is written.",
|
|
143
|
+
"required_intent_fields": ["intent.goal"],
|
|
144
|
+
"optional_intent_fields": ["intent.files_to_modify", "parent_experiment", "prompt"]
|
|
145
|
+
},
|
|
146
|
+
"prompt": "Optimize the database queries in db/query.py to reduce the N+1 problem."
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Example **`intent.json`** (AI-written from that prompt):
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"parent_experiment": "exp_001",
|
|
155
|
+
"prompt": "optimize database queries",
|
|
156
|
+
"intent": {
|
|
157
|
+
"files_to_modify": ["db/query.py"],
|
|
158
|
+
"goal": "reduce N+1 query problem"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You can use **`prompt.md`** instead of `prompt.json` (no default template); the AI must still write `intent.json`.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
tb run agent_1
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
This creates a new run (e.g. `.ai_history/run_002/`) with copies of the prompt file, `intent.json`, `diff.patch`, `metadata.json`, and `environment.json` (and optionally `tests.json` / `metrics.json` from `teabag.json`). **intent.json and all run artifacts are made read-only** so the record cannot be modified after creation.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Inspecting and Comparing Runs
|
|
174
|
+
|
|
175
|
+
List all runs:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
tb list-runs
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Show full details for one run (metadata, intent, environment, tests/metrics summary):
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
tb runs show run_002
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Compare two runs (diff size, test exit code, metrics):
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
tb runs compare run_001 run_002
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Rank runs by test result, time, or diff size:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
tb runs rank # Prefer passing tests, then newest
|
|
197
|
+
tb runs rank --by time # Newest first
|
|
198
|
+
tb runs rank --by diff # Smallest diff first
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Applying Changes to the Main Repo
|
|
204
|
+
|
|
205
|
+
### Accept a single run
|
|
206
|
+
|
|
207
|
+
Apply a run’s diff to the repo and mark its experiment as accepted:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
tb runs accept run_002
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Check first without modifying files:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
tb runs accept run_002 --dry-run
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Requires the `patch` command (e.g. `brew install patch` on macOS).
|
|
220
|
+
|
|
221
|
+
### Merge the best runs automatically
|
|
222
|
+
|
|
223
|
+
Apply the top runs (ranked by tests, then time) that do not touch the same files as already-accepted runs:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
tb merge best # Apply the single best non-conflicting run
|
|
227
|
+
tb merge best --limit 3 # Apply up to 3
|
|
228
|
+
tb merge best --limit 2 --dry-run # Only print what would be applied
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### See a merge plan for one run
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
tb merge plan run_002
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Shows the run’s goal, touched files, test result, and whether it conflicts (overlapping files) with any already-accepted run.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Automation: Tests and Metrics
|
|
242
|
+
|
|
243
|
+
Put a **`teabag.json`** file in the **repository root** to run tests and an optional metrics script every time you run `tb run <agent_name>`.
|
|
244
|
+
|
|
245
|
+
Example:
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"test_command": "pytest -q",
|
|
250
|
+
"test_timeout": 120,
|
|
251
|
+
"metrics_script": "scripts/collect_metrics.sh"
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
| Field | Description |
|
|
256
|
+
|-------|-------------|
|
|
257
|
+
| `test_command` | Shell command run from the **workspace** directory. Exit code and output are stored in `tests.json`. |
|
|
258
|
+
| `test_timeout` | Timeout in seconds (default: 300). |
|
|
259
|
+
| `metrics_script` | Path (relative to repo root) to a script run from the workspace. Output is stored in `metrics.json`. |
|
|
260
|
+
|
|
261
|
+
If `test_command` is omitted, no tests run and `tests.json` is not created. If `metrics_script` is omitted or the file is missing, no metrics run. `environment.json` is always written for every run.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Snapshots and Multi-Agent Workflows
|
|
266
|
+
|
|
267
|
+
### Workspace snapshot
|
|
268
|
+
|
|
269
|
+
Save a copy of a workspace (excluding venv) for later use or as a template:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
tb workspace snapshot agent_1
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
This creates `.teabag/snapshots/agent_1_<ISO8601>/`.
|
|
276
|
+
|
|
277
|
+
### Spawn many agents at once
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
# Create 5 workspaces: agent_1 .. agent_5
|
|
281
|
+
tb agents spawn 5
|
|
282
|
+
|
|
283
|
+
# Create 5 workspaces from a snapshot (use the snapshot directory name)
|
|
284
|
+
tb agents spawn 5 --template agent_1_20250116T120000Z
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Task: create a task and spawn agents
|
|
288
|
+
|
|
289
|
+
Create a task and spawn N workspaces in one step:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
tb task run "optimize database layer" --agents 3
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
This creates a task, spawns `agent_1`, `agent_2`, `agent_3`, and associates them with the task. Then run your AI in each workspace and record with `tb run agent_1`, etc.
|
|
296
|
+
|
|
297
|
+
List tasks:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
tb task list
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Command Reference
|
|
306
|
+
|
|
307
|
+
| Command | Description |
|
|
308
|
+
|--------|-------------|
|
|
309
|
+
| `tb init` | Initialize teaBag in the current repo. |
|
|
310
|
+
| `tb spawn <agent_name>` | Create a workspace and link shared venv. |
|
|
311
|
+
| `tb run <agent_name>` | Record a run (prompt.json with _teabag + human prompt; AI must have written intent.json). |
|
|
312
|
+
| `tb list-runs` | List all recorded runs. |
|
|
313
|
+
| `tb runs show <run_id>` | Show full run details. |
|
|
314
|
+
| `tb runs compare <run_a> <run_b>` | Compare two runs. |
|
|
315
|
+
| `tb runs rank [--by tests\|time\|diff]` | Rank runs. |
|
|
316
|
+
| `tb runs accept <run_id> [--dry-run]` | Apply run’s diff to the repo. |
|
|
317
|
+
| `tb merge best [--limit K] [--dry-run]` | Apply best K non-conflicting runs. |
|
|
318
|
+
| `tb merge plan <run_id>` | Show merge plan and conflicts. |
|
|
319
|
+
| `tb workspace snapshot <agent_name>` | Snapshot workspace to .teabag/snapshots/. |
|
|
320
|
+
| `tb agents spawn <n> [--template NAME]` | Spawn n workspaces (agent_1 .. agent_n). |
|
|
321
|
+
| `tb task run "desc" [--agents N] [--template NAME]` | Create task and spawn N agents. |
|
|
322
|
+
| `tb task list` | List tasks. |
|
|
323
|
+
| `tb delete-workspace <agent_name>` | Remove a workspace. |
|
|
324
|
+
| `tb env list` | List shared environments. |
|
|
325
|
+
| `tb env prune` | Prune missing envs from registry. |
|
|
326
|
+
|
|
327
|
+
You can pass `--repo-root /path/to/repo` to any command (except `init`) to run from another directory.
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Examples
|
|
332
|
+
|
|
333
|
+
### Example 1: Single agent, then accept
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
tb init
|
|
337
|
+
tb spawn agent_1
|
|
338
|
+
# ... You fill prompt.json, AI writes intent.json and edits workspaces/agent_1/ ...
|
|
339
|
+
tb run agent_1
|
|
340
|
+
tb list-runs
|
|
341
|
+
tb runs show run_001
|
|
342
|
+
tb runs accept run_001 --dry-run
|
|
343
|
+
tb runs accept run_001
|
|
344
|
+
tb delete-workspace agent_1
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Example 2: Multiple runs, compare and pick one
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
tb init
|
|
351
|
+
tb spawn agent_1
|
|
352
|
+
# First experiment
|
|
353
|
+
# Human fills "prompt" in workspaces/agent_1/prompt.json; AI writes intent.json (here, manual for demo)
|
|
354
|
+
echo '{"intent":{"goal":"add caching"}}' > workspaces/agent_1/intent.json
|
|
355
|
+
tb run agent_1
|
|
356
|
+
# Second experiment (new prompt in prompt.json, AI writes new intent.json)
|
|
357
|
+
echo '{"intent":{"goal":"use Redis"}}' > workspaces/agent_1/intent.json
|
|
358
|
+
tb run agent_1
|
|
359
|
+
|
|
360
|
+
tb runs compare run_001 run_002
|
|
361
|
+
tb runs rank
|
|
362
|
+
tb merge plan run_002
|
|
363
|
+
tb runs accept run_002
|
|
364
|
+
tb delete-workspace agent_1
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Example 3: Parallel agents and merge best
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
tb init
|
|
371
|
+
tb task run "refactor auth module" --agents 3
|
|
372
|
+
# ... run AI in workspaces/agent_1, agent_2, agent_3; add intent + prompt in each ...
|
|
373
|
+
tb run agent_1
|
|
374
|
+
tb run agent_2
|
|
375
|
+
tb run agent_3
|
|
376
|
+
|
|
377
|
+
tb runs rank
|
|
378
|
+
tb merge best --limit 1 --dry-run
|
|
379
|
+
tb merge best --limit 1
|
|
380
|
+
tb delete-workspace agent_1
|
|
381
|
+
tb delete-workspace agent_2
|
|
382
|
+
tb delete-workspace agent_3
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Example 4: Snapshot as template for more agents
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
tb init
|
|
389
|
+
tb spawn agent_1
|
|
390
|
+
# ... set up workspace with baseline code, intent, prompt ...
|
|
391
|
+
tb workspace snapshot agent_1
|
|
392
|
+
# Snapshot created: .teabag/snapshots/agent_1_20250116T120000Z
|
|
393
|
+
|
|
394
|
+
tb agents spawn 4 --template agent_1_20250116T120000Z
|
|
395
|
+
# Now agent_1, agent_2, agent_3, agent_4 all start from that snapshot
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Troubleshooting
|
|
401
|
+
|
|
402
|
+
- **"intent.json not found"**
|
|
403
|
+
AI must read `prompt.json` (or `prompt.md`) and write `intent.json` with `intent.goal` before `tb run`.
|
|
404
|
+
- **"Neither prompt.json nor prompt.md found"**
|
|
405
|
+
Run `tb spawn` to get a default `prompt.json`, or add `prompt.json` / `prompt.md` and fill the human prompt.
|
|
406
|
+
|
|
407
|
+
- **"Workspace for agent X does not exist"**
|
|
408
|
+
Run `tb spawn <agent_name>` first.
|
|
409
|
+
|
|
410
|
+
- **"patch failed" / "patch: command not found"**
|
|
411
|
+
Install `patch` (e.g. `brew install patch`). Required for `tb runs accept` and `tb merge best`.
|
|
412
|
+
|
|
413
|
+
- **Symlinks not supported (e.g. some Windows setups)**
|
|
414
|
+
teaBag writes `workspaces/<agent_name>/ENV_PATH` with the absolute path to the env. Use that path to call pip or activate.
|
|
415
|
+
|
|
416
|
+
- **merge best applies nothing**
|
|
417
|
+
All runs may already be accepted, or every candidate conflicts (touches the same files as an accepted run). Use `tb runs rank` and `tb merge plan <run_id>` to inspect.
|
|
418
|
+
|
|
419
|
+
- **Template snapshot not found**
|
|
420
|
+
Use the snapshot directory name under `.teabag/snapshots/` (e.g. `agent_1_20250116T120000Z`), not a full path.
|
|
421
|
+
|
|
422
|
+
- **Diff is empty**
|
|
423
|
+
Diff uses `git diff` when the repo has a `.git` directory. For non-git projects, runs are still recorded but `diff.patch` may be a placeholder.
|