groundcrew 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.
- groundcrew/__init__.py +22 -0
- groundcrew/api.py +110 -0
- groundcrew/cli.py +113 -0
- groundcrew/codec.py +85 -0
- groundcrew/mcp_server.py +154 -0
- groundcrew/oracle.py +92 -0
- groundcrew/py.typed +0 -0
- groundcrew/report.py +67 -0
- groundcrew/snapshot.py +131 -0
- groundcrew-0.1.0.dist-info/METADATA +327 -0
- groundcrew-0.1.0.dist-info/RECORD +14 -0
- groundcrew-0.1.0.dist-info/WHEEL +4 -0
- groundcrew-0.1.0.dist-info/entry_points.txt +3 -0
- groundcrew-0.1.0.dist-info/licenses/LICENSE +21 -0
groundcrew/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""groundcrew — Deterministic state oracle and semantic action codec for computer-use agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import version as _version
|
|
6
|
+
|
|
7
|
+
from groundcrew.codec import ActionReceipt, ActionSpec
|
|
8
|
+
from groundcrew.oracle import Oracle, ReceiptStore
|
|
9
|
+
from groundcrew.snapshot import FileState, SnapshotDiff, StateSnapshot
|
|
10
|
+
|
|
11
|
+
__version__ = _version("groundcrew")
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"ActionReceipt",
|
|
15
|
+
"ActionSpec",
|
|
16
|
+
"FileState",
|
|
17
|
+
"Oracle",
|
|
18
|
+
"ReceiptStore",
|
|
19
|
+
"SnapshotDiff",
|
|
20
|
+
"StateSnapshot",
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
groundcrew/api.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""FastAPI REST wrapper for groundcrew.
|
|
2
|
+
|
|
3
|
+
Start: uvicorn groundcrew.api:app --reload
|
|
4
|
+
Install: pip install "groundcrew[api]"
|
|
5
|
+
Docs: http://localhost:8000/docs
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import shlex
|
|
12
|
+
import subprocess
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from fastapi import FastAPI, HTTPException
|
|
17
|
+
from pydantic import BaseModel, Field
|
|
18
|
+
except ImportError as exc:
|
|
19
|
+
raise ImportError("API server requires: pip install 'groundcrew[api]'") from exc
|
|
20
|
+
|
|
21
|
+
from groundcrew import __version__
|
|
22
|
+
from groundcrew.codec import ActionSpec
|
|
23
|
+
from groundcrew.oracle import Oracle, ReceiptStore
|
|
24
|
+
|
|
25
|
+
_DEFAULT_DB = ".groundcrew/receipts.db"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _db_path() -> str:
|
|
29
|
+
return os.environ.get("GROUNDCREW_DB", _DEFAULT_DB)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
app = FastAPI(
|
|
33
|
+
title="groundcrew API",
|
|
34
|
+
description="Deterministic state oracle and semantic action codec for computer-use agents",
|
|
35
|
+
version=__version__,
|
|
36
|
+
license_info={
|
|
37
|
+
"name": "MIT",
|
|
38
|
+
"url": "https://github.com/sandeep-alluru/groundcrew/blob/main/LICENSE",
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class CaptureRequest(BaseModel):
|
|
44
|
+
"""Request body for POST /capture."""
|
|
45
|
+
|
|
46
|
+
root: str = Field(".", description="Directory to snapshot.")
|
|
47
|
+
verb: str = Field(..., description="Semantic verb for the action.")
|
|
48
|
+
target: str = Field(..., description="Target the action acts upon.")
|
|
49
|
+
params: dict = Field(default_factory=dict)
|
|
50
|
+
run_cmd: str | None = Field(None, description="Optional shell command to execute.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class HealthResponse(BaseModel):
|
|
54
|
+
"""Response body for GET /health."""
|
|
55
|
+
|
|
56
|
+
status: str
|
|
57
|
+
version: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@app.get("/health", response_model=HealthResponse)
|
|
61
|
+
async def health() -> dict[str, str]:
|
|
62
|
+
"""Liveness probe."""
|
|
63
|
+
return {"status": "ok", "version": __version__}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@app.post("/capture")
|
|
67
|
+
async def capture(request: CaptureRequest) -> Any:
|
|
68
|
+
"""Capture before/after state around an action and persist a receipt."""
|
|
69
|
+
spec = ActionSpec(verb=request.verb, target=request.target, params=request.params)
|
|
70
|
+
with Oracle(request.root, spec) as oracle:
|
|
71
|
+
if request.run_cmd:
|
|
72
|
+
result = subprocess.run(shlex.split(request.run_cmd), cwd=request.root, check=False) # noqa: S603
|
|
73
|
+
if result.returncode != 0:
|
|
74
|
+
oracle._success = False
|
|
75
|
+
receipt = oracle.record(spec)
|
|
76
|
+
store = ReceiptStore(_db_path())
|
|
77
|
+
store.save(receipt)
|
|
78
|
+
store.close()
|
|
79
|
+
return receipt.to_dict()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.get("/receipt/{receipt_id}")
|
|
83
|
+
async def get_receipt(receipt_id: str) -> Any:
|
|
84
|
+
"""Return a single receipt by ID."""
|
|
85
|
+
store = ReceiptStore(_db_path())
|
|
86
|
+
receipt = store.get(receipt_id)
|
|
87
|
+
store.close()
|
|
88
|
+
if receipt is None:
|
|
89
|
+
raise HTTPException(status_code=404, detail=f"Receipt not found: {receipt_id}")
|
|
90
|
+
return receipt.to_dict()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@app.get("/receipts")
|
|
94
|
+
async def list_receipts() -> Any:
|
|
95
|
+
"""Return all stored receipts."""
|
|
96
|
+
store = ReceiptStore(_db_path())
|
|
97
|
+
receipts = store.list_receipts()
|
|
98
|
+
store.close()
|
|
99
|
+
return {"receipts": [r.to_dict() for r in receipts]}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@app.get("/diff/{receipt_id}")
|
|
103
|
+
async def get_diff(receipt_id: str) -> Any:
|
|
104
|
+
"""Return the snapshot diff for a stored receipt."""
|
|
105
|
+
store = ReceiptStore(_db_path())
|
|
106
|
+
receipt = store.get(receipt_id)
|
|
107
|
+
store.close()
|
|
108
|
+
if receipt is None:
|
|
109
|
+
raise HTTPException(status_code=404, detail=f"Receipt not found: {receipt_id}")
|
|
110
|
+
return receipt.diff.to_dict()
|
groundcrew/cli.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Command-line interface for groundcrew."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from groundcrew.codec import ActionSpec
|
|
10
|
+
from groundcrew.oracle import Oracle, ReceiptStore
|
|
11
|
+
from groundcrew.report import print_diff, print_receipt, to_markdown
|
|
12
|
+
|
|
13
|
+
_DEFAULT_DB = ".groundcrew/receipts.db"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.group()
|
|
17
|
+
@click.version_option(package_name="groundcrew")
|
|
18
|
+
@click.option(
|
|
19
|
+
"--db",
|
|
20
|
+
default=_DEFAULT_DB,
|
|
21
|
+
show_default=True,
|
|
22
|
+
help="Path to the groundcrew receipt store.",
|
|
23
|
+
envvar="GROUNDCREW_DB",
|
|
24
|
+
)
|
|
25
|
+
@click.pass_context
|
|
26
|
+
def main(ctx: click.Context, db: str) -> None:
|
|
27
|
+
"""Deterministic state oracle and semantic action codec for computer-use agents.
|
|
28
|
+
|
|
29
|
+
groundcrew captures the filesystem state before and after an action,
|
|
30
|
+
and emits a verifiable, content-addressed receipt of what changed.
|
|
31
|
+
"""
|
|
32
|
+
ctx.ensure_object(dict)
|
|
33
|
+
ctx.obj["db"] = db
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@main.command()
|
|
37
|
+
@click.option("--root", default=".", show_default=True, help="Directory to snapshot.")
|
|
38
|
+
@click.option("--verb", required=True, help="Semantic verb for the action.")
|
|
39
|
+
@click.option("--target", required=True, help="Target the action acts upon.")
|
|
40
|
+
@click.option("--run", "run_cmd", default=None, help="Shell command to execute and capture.")
|
|
41
|
+
@click.pass_context
|
|
42
|
+
def capture(ctx: click.Context, root: str, verb: str, target: str, run_cmd: str | None) -> None:
|
|
43
|
+
"""Capture before/after state around an action and store a receipt.
|
|
44
|
+
|
|
45
|
+
\b
|
|
46
|
+
Examples:
|
|
47
|
+
groundcrew capture --root . --verb write --target out.txt --run "echo hi > out.txt"
|
|
48
|
+
"""
|
|
49
|
+
spec = ActionSpec(verb=verb, target=target, params={"run": run_cmd} if run_cmd else {})
|
|
50
|
+
with Oracle(root, spec) as oracle:
|
|
51
|
+
if run_cmd:
|
|
52
|
+
result = subprocess.run(run_cmd, shell=True, cwd=root) # noqa: S602
|
|
53
|
+
if result.returncode != 0:
|
|
54
|
+
oracle._success = False
|
|
55
|
+
receipt = oracle.record(spec)
|
|
56
|
+
store = ReceiptStore(ctx.obj["db"])
|
|
57
|
+
store.save(receipt)
|
|
58
|
+
store.close()
|
|
59
|
+
click.echo(f"Captured receipt {receipt.id} {verb} -> {target}")
|
|
60
|
+
print_receipt(receipt)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@main.command()
|
|
64
|
+
@click.argument("receipt_id")
|
|
65
|
+
@click.pass_context
|
|
66
|
+
def diff(ctx: click.Context, receipt_id: str) -> None:
|
|
67
|
+
"""Show the diff for a stored receipt.
|
|
68
|
+
|
|
69
|
+
\b
|
|
70
|
+
Examples:
|
|
71
|
+
groundcrew diff abc123def456
|
|
72
|
+
"""
|
|
73
|
+
store = ReceiptStore(ctx.obj["db"])
|
|
74
|
+
receipt = store.get(receipt_id)
|
|
75
|
+
store.close()
|
|
76
|
+
if receipt is None:
|
|
77
|
+
raise click.ClickException(f"Receipt not found: {receipt_id}")
|
|
78
|
+
print_diff(receipt.diff)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@main.command()
|
|
82
|
+
@click.pass_context
|
|
83
|
+
def log(ctx: click.Context) -> None:
|
|
84
|
+
"""List all stored receipts.
|
|
85
|
+
|
|
86
|
+
\b
|
|
87
|
+
Examples:
|
|
88
|
+
groundcrew log
|
|
89
|
+
"""
|
|
90
|
+
store = ReceiptStore(ctx.obj["db"])
|
|
91
|
+
receipts = store.list_receipts()
|
|
92
|
+
store.close()
|
|
93
|
+
click.echo(to_markdown(receipts))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@main.command()
|
|
97
|
+
@click.option("--root", default=".", show_default=True, help="Directory to inspect.")
|
|
98
|
+
@click.pass_context
|
|
99
|
+
def status(ctx: click.Context, root: str) -> None:
|
|
100
|
+
"""Show the current staging state (a live snapshot of the root)."""
|
|
101
|
+
from groundcrew.snapshot import StateSnapshot
|
|
102
|
+
|
|
103
|
+
snap = StateSnapshot.capture(root)
|
|
104
|
+
store = ReceiptStore(ctx.obj["db"])
|
|
105
|
+
count = len(store.list_receipts())
|
|
106
|
+
store.close()
|
|
107
|
+
click.echo(f"Root {snap.root}")
|
|
108
|
+
click.echo(f"Snapshot {snap.id} ({len(snap.files)} files)")
|
|
109
|
+
click.echo(f"Receipts {count} stored")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if __name__ == "__main__":
|
|
113
|
+
main()
|
groundcrew/codec.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Semantic action codec: content-addressed action specs and verifiable receipts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
|
|
9
|
+
from groundcrew.snapshot import SnapshotDiff
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ActionSpec:
|
|
14
|
+
"""A semantic description of an action: a verb applied to a target with params."""
|
|
15
|
+
|
|
16
|
+
verb: str
|
|
17
|
+
target: str
|
|
18
|
+
params: dict
|
|
19
|
+
id: str = field(init=False)
|
|
20
|
+
|
|
21
|
+
def __post_init__(self):
|
|
22
|
+
payload = f"{self.verb}|{self.target}|{json.dumps(self.params, sort_keys=True)}"
|
|
23
|
+
self.id = hashlib.sha256(payload.encode()).hexdigest()[:16]
|
|
24
|
+
|
|
25
|
+
def to_dict(self) -> dict:
|
|
26
|
+
return {
|
|
27
|
+
"id": self.id,
|
|
28
|
+
"verb": self.verb,
|
|
29
|
+
"target": self.target,
|
|
30
|
+
"params": self.params,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def from_dict(cls, d) -> ActionSpec:
|
|
35
|
+
return cls(verb=d["verb"], target=d["target"], params=d["params"])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class ActionReceipt:
|
|
40
|
+
"""A verifiable record pairing an action spec with the state change it produced."""
|
|
41
|
+
|
|
42
|
+
spec: ActionSpec
|
|
43
|
+
before_id: str
|
|
44
|
+
after_id: str
|
|
45
|
+
diff: SnapshotDiff
|
|
46
|
+
success: bool
|
|
47
|
+
timestamp: float
|
|
48
|
+
id: str = field(init=False)
|
|
49
|
+
|
|
50
|
+
def __post_init__(self):
|
|
51
|
+
payload = json.dumps(
|
|
52
|
+
{
|
|
53
|
+
"spec_id": self.spec.id,
|
|
54
|
+
"before_id": self.before_id,
|
|
55
|
+
"after_id": self.after_id,
|
|
56
|
+
"success": self.success,
|
|
57
|
+
"timestamp": self.timestamp,
|
|
58
|
+
},
|
|
59
|
+
sort_keys=True,
|
|
60
|
+
)
|
|
61
|
+
self.id = hashlib.sha256(payload.encode()).hexdigest()[:16]
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> dict:
|
|
64
|
+
return {
|
|
65
|
+
"id": self.id,
|
|
66
|
+
"spec": self.spec.to_dict(),
|
|
67
|
+
"before_id": self.before_id,
|
|
68
|
+
"after_id": self.after_id,
|
|
69
|
+
"diff": self.diff.to_dict(),
|
|
70
|
+
"success": self.success,
|
|
71
|
+
"timestamp": self.timestamp,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def from_dict(cls, d) -> ActionReceipt:
|
|
76
|
+
spec = ActionSpec.from_dict(d["spec"])
|
|
77
|
+
diff = SnapshotDiff.from_dict(d["diff"])
|
|
78
|
+
return cls(
|
|
79
|
+
spec=spec,
|
|
80
|
+
before_id=d["before_id"],
|
|
81
|
+
after_id=d["after_id"],
|
|
82
|
+
diff=diff,
|
|
83
|
+
success=d["success"],
|
|
84
|
+
timestamp=d["timestamp"],
|
|
85
|
+
)
|
groundcrew/mcp_server.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""MCP server for groundcrew.
|
|
2
|
+
|
|
3
|
+
Start: python -m groundcrew.mcp_server
|
|
4
|
+
Or: groundcrew-mcp
|
|
5
|
+
|
|
6
|
+
Add to Claude Desktop (~/.config/claude/claude_desktop_config.json):
|
|
7
|
+
{
|
|
8
|
+
"mcpServers": {
|
|
9
|
+
"groundcrew": {
|
|
10
|
+
"command": "groundcrew-mcp"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
import shlex
|
|
21
|
+
import subprocess
|
|
22
|
+
import sys
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
from groundcrew.codec import ActionSpec
|
|
26
|
+
from groundcrew.oracle import Oracle, ReceiptStore
|
|
27
|
+
|
|
28
|
+
_DEFAULT_DB = ".groundcrew/receipts.db"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _db_path() -> str:
|
|
32
|
+
return os.environ.get("GROUNDCREW_DB", _DEFAULT_DB)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _require_mcp() -> Any:
|
|
36
|
+
try:
|
|
37
|
+
import mcp.server.stdio
|
|
38
|
+
import mcp.types as types
|
|
39
|
+
from mcp.server import Server
|
|
40
|
+
|
|
41
|
+
return mcp, types, Server
|
|
42
|
+
except ImportError:
|
|
43
|
+
print(
|
|
44
|
+
"MCP server requires: pip install 'groundcrew[mcp]'",
|
|
45
|
+
file=sys.stderr,
|
|
46
|
+
)
|
|
47
|
+
sys.exit(1)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _capture_state(arguments: str) -> str:
|
|
51
|
+
args = json.loads(arguments) if arguments else {}
|
|
52
|
+
root = args.get("root", ".")
|
|
53
|
+
verb = args.get("verb", "act")
|
|
54
|
+
target = args.get("target", "")
|
|
55
|
+
params = args.get("params", {})
|
|
56
|
+
run_cmd = args.get("run_cmd")
|
|
57
|
+
spec = ActionSpec(verb=verb, target=target, params=params)
|
|
58
|
+
with Oracle(root, spec) as oracle:
|
|
59
|
+
if run_cmd:
|
|
60
|
+
result = subprocess.run(shlex.split(run_cmd), cwd=root, check=False) # noqa: S603
|
|
61
|
+
if result.returncode != 0:
|
|
62
|
+
oracle._success = False
|
|
63
|
+
receipt = oracle.record(spec)
|
|
64
|
+
store = ReceiptStore(_db_path())
|
|
65
|
+
store.save(receipt)
|
|
66
|
+
store.close()
|
|
67
|
+
return json.dumps(receipt.to_dict())
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _get_receipt(arguments: str) -> str:
|
|
71
|
+
args = json.loads(arguments) if arguments else {}
|
|
72
|
+
receipt_id = args.get("receipt_id", "")
|
|
73
|
+
store = ReceiptStore(_db_path())
|
|
74
|
+
receipt = store.get(receipt_id)
|
|
75
|
+
store.close()
|
|
76
|
+
if receipt is None:
|
|
77
|
+
return json.dumps({"error": f"Receipt not found: {receipt_id}"})
|
|
78
|
+
return json.dumps(receipt.to_dict())
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _list_receipts(arguments: str) -> str:
|
|
82
|
+
store = ReceiptStore(_db_path())
|
|
83
|
+
receipts = store.list_receipts()
|
|
84
|
+
store.close()
|
|
85
|
+
return json.dumps({"receipts": [r.to_dict() for r in receipts]})
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def run_server() -> None:
|
|
89
|
+
"""Start the MCP server on stdio."""
|
|
90
|
+
mcp_mod, types, server_cls = _require_mcp()
|
|
91
|
+
|
|
92
|
+
server = server_cls("groundcrew")
|
|
93
|
+
|
|
94
|
+
@server.list_tools()
|
|
95
|
+
async def list_tools() -> list[types.Tool]:
|
|
96
|
+
return [
|
|
97
|
+
types.Tool(
|
|
98
|
+
name="capture_state",
|
|
99
|
+
description=(
|
|
100
|
+
"Capture before/after filesystem state around an action and "
|
|
101
|
+
"store a verifiable receipt. Argument is a JSON string with "
|
|
102
|
+
"keys: root, verb, target, params, run_cmd."
|
|
103
|
+
),
|
|
104
|
+
inputSchema={
|
|
105
|
+
"type": "object",
|
|
106
|
+
"properties": {"arguments": {"type": "string"}},
|
|
107
|
+
"required": ["arguments"],
|
|
108
|
+
},
|
|
109
|
+
),
|
|
110
|
+
types.Tool(
|
|
111
|
+
name="get_receipt",
|
|
112
|
+
description=(
|
|
113
|
+
"Fetch a stored receipt by ID. Argument is a JSON string with key: receipt_id."
|
|
114
|
+
),
|
|
115
|
+
inputSchema={
|
|
116
|
+
"type": "object",
|
|
117
|
+
"properties": {"arguments": {"type": "string"}},
|
|
118
|
+
"required": ["arguments"],
|
|
119
|
+
},
|
|
120
|
+
),
|
|
121
|
+
types.Tool(
|
|
122
|
+
name="list_receipts",
|
|
123
|
+
description="List all stored receipts. Argument is an (ignored) JSON string.",
|
|
124
|
+
inputSchema={
|
|
125
|
+
"type": "object",
|
|
126
|
+
"properties": {"arguments": {"type": "string"}},
|
|
127
|
+
},
|
|
128
|
+
),
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
@server.call_tool()
|
|
132
|
+
async def call_tool(name: str, arguments: dict[str, Any]) -> list[types.TextContent]:
|
|
133
|
+
raw = arguments.get("arguments", "{}")
|
|
134
|
+
if name == "capture_state":
|
|
135
|
+
result = _capture_state(raw)
|
|
136
|
+
elif name == "get_receipt":
|
|
137
|
+
result = _get_receipt(raw)
|
|
138
|
+
elif name == "list_receipts":
|
|
139
|
+
result = _list_receipts(raw)
|
|
140
|
+
else:
|
|
141
|
+
raise ValueError(f"Unknown tool: {name}")
|
|
142
|
+
return [types.TextContent(type="text", text=result)]
|
|
143
|
+
|
|
144
|
+
import asyncio
|
|
145
|
+
|
|
146
|
+
async def _main() -> None:
|
|
147
|
+
async with mcp_mod.server.stdio.stdio_server() as (read_stream, write_stream):
|
|
148
|
+
await server.run(read_stream, write_stream, server.create_initialization_options())
|
|
149
|
+
|
|
150
|
+
asyncio.run(_main())
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if __name__ == "__main__":
|
|
154
|
+
run_server()
|
groundcrew/oracle.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""The Oracle: captures before/after state around actions and persists receipts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import sqlite3
|
|
7
|
+
import time
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from groundcrew.codec import ActionReceipt, ActionSpec
|
|
12
|
+
from groundcrew.snapshot import StateSnapshot, diff_snapshots
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Oracle:
|
|
16
|
+
"""Context manager that snapshots a root before and after a block of work."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, root, spec=None):
|
|
19
|
+
self.root = Path(root)
|
|
20
|
+
self.spec = spec
|
|
21
|
+
self._before: StateSnapshot | None = None
|
|
22
|
+
self._after: StateSnapshot | None = None
|
|
23
|
+
self._success = True
|
|
24
|
+
|
|
25
|
+
def __enter__(self):
|
|
26
|
+
self._before = StateSnapshot.capture(self.root)
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
30
|
+
self._after = StateSnapshot.capture(self.root)
|
|
31
|
+
if exc_type is not None:
|
|
32
|
+
self._success = False
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
def record(self, spec: ActionSpec) -> ActionReceipt:
|
|
36
|
+
"""Build an ActionReceipt for ``spec`` from the captured before/after state."""
|
|
37
|
+
if self._after is None:
|
|
38
|
+
self._after = StateSnapshot.capture(self.root)
|
|
39
|
+
diff = diff_snapshots(self._before, self._after)
|
|
40
|
+
return ActionReceipt(
|
|
41
|
+
spec=spec,
|
|
42
|
+
before_id=self._before.id if self._before else "",
|
|
43
|
+
after_id=self._after.id,
|
|
44
|
+
diff=diff,
|
|
45
|
+
success=self._success,
|
|
46
|
+
timestamp=time.time(),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@contextmanager
|
|
51
|
+
def capture(root, spec):
|
|
52
|
+
"""Convenience context manager wrapping :class:`Oracle`."""
|
|
53
|
+
oracle = Oracle(root, spec)
|
|
54
|
+
oracle.__enter__()
|
|
55
|
+
try:
|
|
56
|
+
yield oracle
|
|
57
|
+
except Exception:
|
|
58
|
+
oracle._success = False
|
|
59
|
+
raise
|
|
60
|
+
finally:
|
|
61
|
+
oracle.__exit__(None, None, None)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ReceiptStore:
|
|
65
|
+
"""A SQLite-backed store for persisting and retrieving action receipts."""
|
|
66
|
+
|
|
67
|
+
def __init__(self, path):
|
|
68
|
+
self._path = Path(path)
|
|
69
|
+
self._path.parent.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
self._conn = sqlite3.connect(str(self._path))
|
|
71
|
+
self._conn.execute("CREATE TABLE IF NOT EXISTS receipts (id TEXT PRIMARY KEY, data TEXT)")
|
|
72
|
+
self._conn.commit()
|
|
73
|
+
|
|
74
|
+
def save(self, receipt: ActionReceipt) -> None:
|
|
75
|
+
self._conn.execute(
|
|
76
|
+
"INSERT OR REPLACE INTO receipts (id, data) VALUES (?, ?)",
|
|
77
|
+
(receipt.id, json.dumps(receipt.to_dict())),
|
|
78
|
+
)
|
|
79
|
+
self._conn.commit()
|
|
80
|
+
|
|
81
|
+
def get(self, receipt_id: str) -> ActionReceipt | None:
|
|
82
|
+
row = self._conn.execute("SELECT data FROM receipts WHERE id = ?", (receipt_id,)).fetchone()
|
|
83
|
+
if row is None:
|
|
84
|
+
return None
|
|
85
|
+
return ActionReceipt.from_dict(json.loads(row[0]))
|
|
86
|
+
|
|
87
|
+
def list_receipts(self) -> list:
|
|
88
|
+
rows = self._conn.execute("SELECT data FROM receipts").fetchall()
|
|
89
|
+
return [ActionReceipt.from_dict(json.loads(r[0])) for r in rows]
|
|
90
|
+
|
|
91
|
+
def close(self) -> None:
|
|
92
|
+
self._conn.close()
|
groundcrew/py.typed
ADDED
|
File without changes
|
groundcrew/report.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Human- and machine-readable formatters for receipts and diffs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from groundcrew.codec import ActionReceipt
|
|
8
|
+
from groundcrew.snapshot import SnapshotDiff
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def print_receipt(receipt: ActionReceipt, console=None) -> None:
|
|
12
|
+
"""Pretty-print a receipt to the console (falls back to plain text)."""
|
|
13
|
+
try:
|
|
14
|
+
from rich.console import Console
|
|
15
|
+
from rich.table import Table
|
|
16
|
+
|
|
17
|
+
c = console or Console()
|
|
18
|
+
t = Table(title=f"Receipt {receipt.id}")
|
|
19
|
+
t.add_column("Field")
|
|
20
|
+
t.add_column("Value")
|
|
21
|
+
t.add_row("Action", f"{receipt.spec.verb} -> {receipt.spec.target}")
|
|
22
|
+
t.add_row("Before", receipt.before_id)
|
|
23
|
+
t.add_row("After", receipt.after_id)
|
|
24
|
+
t.add_row("Success", str(receipt.success))
|
|
25
|
+
t.add_row("Changes", str(len(receipt.diff.changed_paths)))
|
|
26
|
+
c.print(t)
|
|
27
|
+
except ImportError:
|
|
28
|
+
print(f"Receipt {receipt.id}: {receipt.spec.verb} -> {receipt.spec.target}")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def print_diff(diff: SnapshotDiff, console=None) -> None:
|
|
32
|
+
"""Pretty-print a snapshot diff to the console (falls back to plain text)."""
|
|
33
|
+
try:
|
|
34
|
+
from rich.console import Console
|
|
35
|
+
|
|
36
|
+
c = console or Console()
|
|
37
|
+
c.print(f"[bold]Diff[/bold] {diff.snapshot_a_id} -> {diff.snapshot_b_id}")
|
|
38
|
+
for f in diff.added:
|
|
39
|
+
c.print(f" [green]+[/green] {f.path}")
|
|
40
|
+
for f in diff.removed:
|
|
41
|
+
c.print(f" [red]-[/red] {f.path}")
|
|
42
|
+
for before, _after in diff.modified:
|
|
43
|
+
c.print(f" [yellow]~[/yellow] {before.path}")
|
|
44
|
+
except ImportError:
|
|
45
|
+
print(f"Diff: +{len(diff.added)} -{len(diff.removed)} ~{len(diff.modified)}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def to_json(receipt: ActionReceipt | None, diff: SnapshotDiff | None = None) -> str:
|
|
49
|
+
"""Serialize a receipt or diff to a JSON string."""
|
|
50
|
+
if receipt is not None:
|
|
51
|
+
return json.dumps(receipt.to_dict(), indent=2)
|
|
52
|
+
if diff is not None:
|
|
53
|
+
return json.dumps(diff.to_dict(), indent=2)
|
|
54
|
+
return "{}"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def to_markdown(receipts: list) -> str:
|
|
58
|
+
"""Render a list of receipts as a Markdown table."""
|
|
59
|
+
lines = ["# Groundcrew Action Log", ""]
|
|
60
|
+
lines.append("| ID | Verb | Target | Success | Changes |")
|
|
61
|
+
lines.append("|---|---|---|---|---|")
|
|
62
|
+
for r in receipts:
|
|
63
|
+
lines.append(
|
|
64
|
+
f"| `{r.id}` | {r.spec.verb} | {r.spec.target} | "
|
|
65
|
+
f"{r.success} | {len(r.diff.changed_paths)} |"
|
|
66
|
+
)
|
|
67
|
+
return "\n".join(lines)
|
groundcrew/snapshot.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Deterministic filesystem state snapshots and content-addressed diffs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import time
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class FileState:
|
|
15
|
+
"""The recorded state of a single file: relative path, size, and digest."""
|
|
16
|
+
|
|
17
|
+
path: str # relative to root
|
|
18
|
+
size: int
|
|
19
|
+
sha256: str # full hex digest
|
|
20
|
+
|
|
21
|
+
def to_dict(self) -> dict:
|
|
22
|
+
return {"path": self.path, "size": self.size, "sha256": self.sha256}
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def from_dict(cls, d) -> FileState:
|
|
26
|
+
return cls(path=d["path"], size=d["size"], sha256=d["sha256"])
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class StateSnapshot:
|
|
31
|
+
"""A content-addressed snapshot of every file beneath a root directory."""
|
|
32
|
+
|
|
33
|
+
id: str # SHA-256[:16] of sorted file-state JSON
|
|
34
|
+
timestamp: float
|
|
35
|
+
root: str
|
|
36
|
+
files: dict # path -> FileState
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def capture(cls, root) -> StateSnapshot:
|
|
40
|
+
root = Path(root)
|
|
41
|
+
files = {}
|
|
42
|
+
for dirpath, _, filenames in os.walk(root):
|
|
43
|
+
for fname in filenames:
|
|
44
|
+
fpath = Path(dirpath) / fname
|
|
45
|
+
rel = str(fpath.relative_to(root))
|
|
46
|
+
try:
|
|
47
|
+
data = fpath.read_bytes()
|
|
48
|
+
h = hashlib.sha256(data).hexdigest()
|
|
49
|
+
files[rel] = FileState(path=rel, size=len(data), sha256=h)
|
|
50
|
+
except PermissionError:
|
|
51
|
+
pass
|
|
52
|
+
# content-address: SHA-256[:16] of sorted JSON of file states
|
|
53
|
+
payload = json.dumps({k: v.to_dict() for k, v in sorted(files.items())}, sort_keys=True)
|
|
54
|
+
snap_id = hashlib.sha256(payload.encode()).hexdigest()[:16]
|
|
55
|
+
return cls(id=snap_id, timestamp=time.time(), root=str(root), files=files)
|
|
56
|
+
|
|
57
|
+
def to_dict(self) -> dict:
|
|
58
|
+
return {
|
|
59
|
+
"id": self.id,
|
|
60
|
+
"timestamp": self.timestamp,
|
|
61
|
+
"root": self.root,
|
|
62
|
+
"files": {k: v.to_dict() for k, v in self.files.items()},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def from_dict(cls, d) -> StateSnapshot:
|
|
67
|
+
files = {k: FileState.from_dict(v) for k, v in d["files"].items()}
|
|
68
|
+
return cls(id=d["id"], timestamp=d["timestamp"], root=d["root"], files=files)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class SnapshotDiff:
|
|
73
|
+
"""The structural delta between two snapshots: added, removed, modified files."""
|
|
74
|
+
|
|
75
|
+
snapshot_a_id: str | None
|
|
76
|
+
snapshot_b_id: str
|
|
77
|
+
added: list # list[FileState]
|
|
78
|
+
removed: list # list[FileState]
|
|
79
|
+
modified: list # list[tuple[FileState, FileState]]
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def changed_paths(self) -> set:
|
|
83
|
+
paths = set()
|
|
84
|
+
for f in self.added:
|
|
85
|
+
paths.add(f.path)
|
|
86
|
+
for f in self.removed:
|
|
87
|
+
paths.add(f.path)
|
|
88
|
+
for before, _after in self.modified:
|
|
89
|
+
paths.add(before.path)
|
|
90
|
+
return paths
|
|
91
|
+
|
|
92
|
+
def to_dict(self) -> dict:
|
|
93
|
+
return {
|
|
94
|
+
"snapshot_a_id": self.snapshot_a_id,
|
|
95
|
+
"snapshot_b_id": self.snapshot_b_id,
|
|
96
|
+
"added": [f.to_dict() for f in self.added],
|
|
97
|
+
"removed": [f.to_dict() for f in self.removed],
|
|
98
|
+
"modified": [[b.to_dict(), a.to_dict()] for b, a in self.modified],
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def from_dict(cls, d) -> SnapshotDiff:
|
|
103
|
+
return cls(
|
|
104
|
+
snapshot_a_id=d["snapshot_a_id"],
|
|
105
|
+
snapshot_b_id=d["snapshot_b_id"],
|
|
106
|
+
added=[FileState.from_dict(f) for f in d["added"]],
|
|
107
|
+
removed=[FileState.from_dict(f) for f in d["removed"]],
|
|
108
|
+
modified=[(FileState.from_dict(b), FileState.from_dict(a)) for b, a in d["modified"]],
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def diff_snapshots(snap_a: StateSnapshot | None, snap_b: StateSnapshot) -> SnapshotDiff:
|
|
113
|
+
"""Compute the added/removed/modified delta from ``snap_a`` to ``snap_b``."""
|
|
114
|
+
a_files = snap_a.files if snap_a else {}
|
|
115
|
+
b_files = snap_b.files
|
|
116
|
+
a_paths = set(a_files.keys())
|
|
117
|
+
b_paths = set(b_files.keys())
|
|
118
|
+
added = [b_files[p] for p in b_paths - a_paths]
|
|
119
|
+
removed = [a_files[p] for p in a_paths - b_paths]
|
|
120
|
+
modified = [
|
|
121
|
+
(a_files[p], b_files[p])
|
|
122
|
+
for p in a_paths & b_paths
|
|
123
|
+
if a_files[p].sha256 != b_files[p].sha256
|
|
124
|
+
]
|
|
125
|
+
return SnapshotDiff(
|
|
126
|
+
snapshot_a_id=snap_a.id if snap_a else None,
|
|
127
|
+
snapshot_b_id=snap_b.id,
|
|
128
|
+
added=added,
|
|
129
|
+
removed=removed,
|
|
130
|
+
modified=modified,
|
|
131
|
+
)
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: groundcrew
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic state oracle and semantic action codec for computer-use agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/sandeep-alluru/groundcrew
|
|
6
|
+
Project-URL: Repository, https://github.com/sandeep-alluru/groundcrew
|
|
7
|
+
Project-URL: Documentation, https://sandeep-alluru.github.io/groundcrew
|
|
8
|
+
Project-URL: Changelog, https://github.com/sandeep-alluru/groundcrew/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/sandeep-alluru/groundcrew/issues
|
|
10
|
+
Author-email: Sandeep Alluru <onepuncchh@gmail.com>
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2026 Sandeep Alluru
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Keywords: action-codec,agents,ai,computer-use,llm,llmops,mcp,observability,state-oracle,verification
|
|
34
|
+
Classifier: Development Status :: 3 - Alpha
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
42
|
+
Classifier: Typing :: Typed
|
|
43
|
+
Requires-Python: >=3.10
|
|
44
|
+
Requires-Dist: click>=8.0
|
|
45
|
+
Requires-Dist: rich>=13.0
|
|
46
|
+
Provides-Extra: api
|
|
47
|
+
Requires-Dist: fastapi>=0.110; extra == 'api'
|
|
48
|
+
Requires-Dist: uvicorn>=0.29; extra == 'api'
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: fastapi>=0.110; extra == 'dev'
|
|
51
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
52
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
53
|
+
Requires-Dist: pre-commit>=3.0; extra == 'dev'
|
|
54
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
55
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
56
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
57
|
+
Provides-Extra: mcp
|
|
58
|
+
Requires-Dist: mcp>=1.0; extra == 'mcp'
|
|
59
|
+
Description-Content-Type: text/markdown
|
|
60
|
+
|
|
61
|
+
# groundcrew
|
|
62
|
+
|
|
63
|
+
**Deterministic state oracle and semantic action codec for computer-use agents.**
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
[](https://github.com/sandeep-alluru/groundcrew/actions/workflows/ci.yml)
|
|
68
|
+
[](https://pypi.org/project/groundcrew/)
|
|
69
|
+
[](https://pypi.org/project/groundcrew/)
|
|
70
|
+
[](https://pypi.org/project/groundcrew/)
|
|
71
|
+
[](LICENSE)
|
|
72
|
+
[](https://codecov.io/gh/sandeep-alluru/groundcrew)
|
|
73
|
+
[](https://mypy-lang.org/)
|
|
74
|
+
|
|
75
|
+
[Quick Start](#quick-start) · [How It Works](#how-it-works) · [CLI Reference](#cli-reference) · [GitHub Action](#github-action) · [vs. Alternatives](#vs-alternatives) · [Contributing](CONTRIBUTING.md)
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Why
|
|
80
|
+
|
|
81
|
+
Computer-use agents act on real software: they write files, call APIs, run scripts. But how do you know what they *actually* did vs. what they were *supposed* to do?
|
|
82
|
+
|
|
83
|
+
Screenshot-based LLM judges give you a visual approximation at best. They miss side effects — the extra file written, the config silently overwritten, the database row changed. And they cannot replay, diff, or audit what happened.
|
|
84
|
+
|
|
85
|
+
groundcrew inverts the architecture: instead of watching from the outside, it snapshots the filesystem **before and after every action** and produces a content-addressed **ActionReceipt** — a tamper-evident record of exactly what changed. No guessing. No LLM judge. Just a deterministic diff.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
groundcrew capture --root . --verb write --target config.json --run "agent.py"
|
|
89
|
+
# → ActionReceipt: 3 files added, 1 modified, diff stored in .groundcrew/receipts.db
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## How It Works
|
|
95
|
+
|
|
96
|
+
```mermaid
|
|
97
|
+
flowchart LR
|
|
98
|
+
A[Agent declares\nActionSpec\nverb · target · params] --> B[Oracle captures\nStateSnapshot BEFORE\nSHA-256 of file tree]
|
|
99
|
+
B --> C[Agent runs\nthe action]
|
|
100
|
+
C --> D[Oracle captures\nStateSnapshot AFTER]
|
|
101
|
+
D --> E[SnapshotDiff\nadded · removed · modified]
|
|
102
|
+
E --> F[ActionReceipt\nspec + before_id + after_id + diff]
|
|
103
|
+
F --> G[ReceiptStore\nSQLite persistence]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Core primitives:**
|
|
107
|
+
|
|
108
|
+
- **FileState** — a content-addressed snapshot of a single file: path, size, SHA-256.
|
|
109
|
+
- **StateSnapshot** — a content-addressed snapshot of a directory tree. ID = SHA-256[:16] of sorted file states.
|
|
110
|
+
- **SnapshotDiff** — the structural delta between two snapshots: added, removed, modified files.
|
|
111
|
+
- **ActionSpec** — a semantic, content-addressed action description: `(verb, target, params)`. ID = SHA-256[:16] of the spec. The same action on the same target always produces the same ID.
|
|
112
|
+
- **ActionReceipt** — binds an ActionSpec to a before-snapshot ID, after-snapshot ID, and SnapshotDiff. Stored permanently as an audit trail.
|
|
113
|
+
- **ReceiptStore** — SQLite-backed store. Save receipts, retrieve by ID, list history.
|
|
114
|
+
|
|
115
|
+
Snapshots are computed by walking the directory tree with `os.walk`, hashing each file with SHA-256, and content-addressing the whole collection. This is purely Python standard-library code — no kernel hooks, no elevated privileges, no platform-specific APIs required.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Features
|
|
120
|
+
|
|
121
|
+
| Feature | Details |
|
|
122
|
+
|---------|---------|
|
|
123
|
+
| Content-addressed snapshots | Same file tree always produces the same snapshot ID |
|
|
124
|
+
| Deterministic diffs | Added, removed, and modified files — no approximation |
|
|
125
|
+
| Semantic action codec | `ActionSpec` is portable, content-addressed, version-robust |
|
|
126
|
+
| Tamper-evident receipts | `ActionReceipt` binds intent to effect, stored permanently |
|
|
127
|
+
| SQLite receipt store | Single-file persistence, no server, works offline |
|
|
128
|
+
| Rich terminal output | Color diff tables, receipt summaries |
|
|
129
|
+
| JSON output | Machine-readable for downstream automation |
|
|
130
|
+
| Markdown output | Ready-to-paste audit reports |
|
|
131
|
+
| FastAPI REST server | `/capture`, `/receipt/{id}`, `/receipts`, `/diff/{id}` |
|
|
132
|
+
| MCP server | Model Context Protocol integration for Claude and other agents |
|
|
133
|
+
| 69 tests | Comprehensive test suite covering all layers |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Quick Start
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install groundcrew # core library + CLI
|
|
141
|
+
pip install "groundcrew[api]" # + FastAPI REST server
|
|
142
|
+
pip install "groundcrew[mcp]" # + MCP server
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from groundcrew import Oracle, ActionSpec, ReceiptStore
|
|
147
|
+
|
|
148
|
+
# Declare what you're about to do
|
|
149
|
+
spec = ActionSpec(verb="write", target="config.json", params={"key": "value"})
|
|
150
|
+
|
|
151
|
+
# Capture before/after state around the action
|
|
152
|
+
with Oracle(".", spec) as oracle:
|
|
153
|
+
import json, pathlib
|
|
154
|
+
pathlib.Path("config.json").write_text(json.dumps({"key": "value"}))
|
|
155
|
+
|
|
156
|
+
receipt = oracle.record(spec)
|
|
157
|
+
print(receipt.diff.changed_paths) # {'config.json'}
|
|
158
|
+
print(receipt.id) # content-addressed ID
|
|
159
|
+
|
|
160
|
+
# Persist for auditing
|
|
161
|
+
store = ReceiptStore(".groundcrew/receipts.db")
|
|
162
|
+
store.save(receipt)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## CLI Reference
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
groundcrew [--db PATH] COMMAND [OPTIONS]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Command | Description | Key options |
|
|
174
|
+
|---------|-------------|-------------|
|
|
175
|
+
| `capture` | Snapshot before/after a shell command | `--root DIR`, `--verb VERB`, `--target TARGET`, `--run CMD` |
|
|
176
|
+
| `diff RECEIPT_ID` | Show the SnapshotDiff for a stored receipt | — |
|
|
177
|
+
| `log` | List all stored receipts | — |
|
|
178
|
+
| `status` | Show database info | — |
|
|
179
|
+
|
|
180
|
+
**Global options:**
|
|
181
|
+
|
|
182
|
+
| Option | Default | Env var |
|
|
183
|
+
|--------|---------|---------|
|
|
184
|
+
| `--db PATH` | `.groundcrew/receipts.db` | `GROUNDCREW_DB` |
|
|
185
|
+
|
|
186
|
+
**Examples:**
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Capture what an agent script does to the current directory
|
|
190
|
+
groundcrew capture --root . --verb run --target agent.py --run "python agent.py"
|
|
191
|
+
|
|
192
|
+
# Show what changed
|
|
193
|
+
groundcrew diff abc123de
|
|
194
|
+
|
|
195
|
+
# List all receipts
|
|
196
|
+
groundcrew log
|
|
197
|
+
|
|
198
|
+
# Status
|
|
199
|
+
groundcrew status
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## GitHub Action
|
|
205
|
+
|
|
206
|
+
Add groundcrew auditing to your CI pipeline:
|
|
207
|
+
|
|
208
|
+
```yaml
|
|
209
|
+
# .github/workflows/groundcrew.yml
|
|
210
|
+
name: groundcrew audit
|
|
211
|
+
on: [push, pull_request]
|
|
212
|
+
|
|
213
|
+
jobs:
|
|
214
|
+
audit:
|
|
215
|
+
runs-on: ubuntu-latest
|
|
216
|
+
steps:
|
|
217
|
+
- uses: actions/checkout@v4
|
|
218
|
+
- uses: sandeep-alluru/groundcrew@main
|
|
219
|
+
with:
|
|
220
|
+
root: .
|
|
221
|
+
db: .groundcrew/receipts.db
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## vs. Alternatives
|
|
227
|
+
|
|
228
|
+
| | groundcrew | Screenshot judges | AgentSight | OSWorld verifiers |
|
|
229
|
+
|---|---|---|---|---|
|
|
230
|
+
| **Verification method** | Filesystem diff | Vision LLM | eBPF syscall trace | Per-task custom code |
|
|
231
|
+
| **Deterministic** | Yes — content-addressed | No — probabilistic | Partial | Yes (per app) |
|
|
232
|
+
| **No per-app code** | Yes | Yes | Yes | No — 33 apps manually |
|
|
233
|
+
| **Production runtime** | Yes | Yes | Linux-only | VM/sandbox only |
|
|
234
|
+
| **Audit trail** | SQLite receipts | None | Log files | None |
|
|
235
|
+
| **Action codec** | Portable ActionSpec | None | None | None |
|
|
236
|
+
| **Open source** | MIT | N/A | MIT | Research |
|
|
237
|
+
| **Python package** | Yes | N/A | No | No |
|
|
238
|
+
|
|
239
|
+
groundcrew is not a replacement for security-layer tools like AgentSight. It is specifically designed for agent developers who need a simple, deterministic record of what their agent changed on disk — suitable for testing, auditing, and CI/CD gating.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Claude / MCP integration
|
|
244
|
+
|
|
245
|
+
groundcrew ships a Model Context Protocol server that lets Claude and other MCP-compatible agents record and query action receipts directly:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Start the MCP server
|
|
249
|
+
python -m groundcrew.mcp_server
|
|
250
|
+
|
|
251
|
+
# In your Claude Code project's .claude/settings.json:
|
|
252
|
+
{
|
|
253
|
+
"mcpServers": {
|
|
254
|
+
"groundcrew": {
|
|
255
|
+
"command": "python",
|
|
256
|
+
"args": ["-m", "groundcrew.mcp_server"]
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Once connected, Claude can call `groundcrew/capture_state`, `groundcrew/get_receipt`, and `groundcrew/list_receipts` as tools. See [docs/mcp.md](docs/mcp.md) for the full tool schema.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## OpenAI integration
|
|
267
|
+
|
|
268
|
+
groundcrew exposes a FastAPI REST server compatible with OpenAI's function-calling format. The tool definitions are in [`tools/openai-tools.json`](tools/openai-tools.json) and the full API spec is in [`openapi.yaml`](openapi.yaml).
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Start the REST server
|
|
272
|
+
uvicorn groundcrew.api:app --reload
|
|
273
|
+
|
|
274
|
+
# Pass to Codex CLI or any OpenAI-compatible agent
|
|
275
|
+
codex --tools tools/openai-tools.json "Capture what this script does to the filesystem"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Endpoints: `GET /health`, `POST /capture`, `GET /receipt/{id}`, `GET /receipts`, `GET /diff/{id}`. See [docs/openai.md](docs/openai.md) for details.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Repository structure
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
groundcrew/
|
|
286
|
+
├── src/
|
|
287
|
+
│ └── groundcrew/
|
|
288
|
+
│ ├── snapshot.py # FileState, StateSnapshot, SnapshotDiff
|
|
289
|
+
│ ├── codec.py # ActionSpec, ActionReceipt (content-addressed)
|
|
290
|
+
│ ├── oracle.py # Oracle context manager, capture(), ReceiptStore
|
|
291
|
+
│ ├── report.py # print_receipt(), print_diff(), to_json(), to_markdown()
|
|
292
|
+
│ ├── cli.py # Click CLI (capture, diff, log, status)
|
|
293
|
+
│ ├── api.py # FastAPI REST server
|
|
294
|
+
│ └── mcp_server.py # MCP server
|
|
295
|
+
├── tests/
|
|
296
|
+
│ ├── test_snapshot.py # StateSnapshot, SnapshotDiff unit tests
|
|
297
|
+
│ ├── test_codec.py # ActionSpec, ActionReceipt unit tests
|
|
298
|
+
│ ├── test_oracle.py # Oracle context manager, ReceiptStore tests
|
|
299
|
+
│ ├── test_report.py # Formatter tests
|
|
300
|
+
│ ├── test_cli.py # CLI subprocess integration tests
|
|
301
|
+
│ ├── test_cli_runner.py # Click CliRunner tests
|
|
302
|
+
│ └── test_api.py # FastAPI TestClient tests
|
|
303
|
+
├── examples/
|
|
304
|
+
│ └── demo.py # Standalone demo script
|
|
305
|
+
├── docs/ # MkDocs documentation
|
|
306
|
+
├── tools/
|
|
307
|
+
│ └── openai-tools.json # OpenAI function-calling tool definitions
|
|
308
|
+
├── assets/
|
|
309
|
+
│ ├── hero.png # README hero image
|
|
310
|
+
│ └── logo.png # Project logo
|
|
311
|
+
├── action.yml # GitHub Action
|
|
312
|
+
├── openapi.yaml # OpenAPI 3.1 spec
|
|
313
|
+
├── pyproject.toml # Package metadata + dependencies
|
|
314
|
+
└── CONTRIBUTING.md # Contribution guide
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## GitHub Topics
|
|
320
|
+
|
|
321
|
+
Suggested topics for discoverability:
|
|
322
|
+
|
|
323
|
+
`ai-agents` `computer-use` `state-oracle` `action-codec` `filesystem-diff` `verification` `observability` `mcp` `openai` `llm-tools` `audit-trail` `ci-cd` `python`
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
[](https://star-history.com/#sandeep-alluru/groundcrew&Date)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
groundcrew/__init__.py,sha256=CcAxNJcJ4q4j8k2DNbeJ6sVr_rbpN4FLQN3Emrkp6sE,568
|
|
2
|
+
groundcrew/api.py,sha256=AbSyZt_bcsVdBc17wr245vplZzGD30AXTviPNJ6YoSg,3340
|
|
3
|
+
groundcrew/cli.py,sha256=GKbS143lew__IhRwvrBOP9U_OLi-jkUrzEUHGY24dSA,3445
|
|
4
|
+
groundcrew/codec.py,sha256=XjK78ZlBcwaFu6TDqypVOaE12kJHnR_CgvGx1Z1n_Zg,2333
|
|
5
|
+
groundcrew/mcp_server.py,sha256=EY3FqUmdGVStVWc0Kts0CeWJFvf1-FF3lm0yvq259B0,4677
|
|
6
|
+
groundcrew/oracle.py,sha256=oIxbMJYSFX1hqwsDMyM7ojoec8djOj34OUA0Ku2uTrU,2992
|
|
7
|
+
groundcrew/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
groundcrew/report.py,sha256=oD7BXwfgKqzKEDySLBtwVmnF3hMxXFYfvIFezhrnbRw,2450
|
|
9
|
+
groundcrew/snapshot.py,sha256=1fHL3kauVaZt3EoJwgZUjZ0ei6REgsf8LcND1lvvZo8,4335
|
|
10
|
+
groundcrew-0.1.0.dist-info/METADATA,sha256=ohF4qhKVywamA5pMZTC8rfL1L8_AeA7LD62fxqlEqTs,13642
|
|
11
|
+
groundcrew-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
12
|
+
groundcrew-0.1.0.dist-info/entry_points.txt,sha256=vbFGKnuLjB3oHcS-16cFUz3w1MLl-N7Vu3T4KR5NU5I,101
|
|
13
|
+
groundcrew-0.1.0.dist-info/licenses/LICENSE,sha256=XwBxPnLzQtV19xccU-wMkDrInqQ90nvdsBtUYsJsuDM,1071
|
|
14
|
+
groundcrew-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sandeep Alluru
|
|
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.
|