StateCLI - Python Client
State Replay & Self-Debugging for AI Agents.
Installation
pip install statecli
Quick Start
from statecli import StateCLI
# Initialize
cli = StateCLI()
# Track state changes
cli.track("order", "7421", {"status": "pending"}, actor="ai-agent")
cli.track("order", "7421", {"status": "processing"}, actor="ai-agent")
# Replay to see what happened
replay = cli.replay("order:7421")
print(f"Found {len(replay.changes)} changes")
for change in replay.changes:
print(f" Step {change.step}: {change.before} -> {change.after}")
# Create checkpoint before risky operation
cli.checkpoint("order:7421", "before-refund")
# Make risky change
cli.track("order", "7421", {"status": "refunded", "amount": 0})
# Undo if something went wrong
result = cli.undo("order:7421", steps=1)
print(f"Undid {result.steps_undone} step(s)")
# View history
log = cli.log("order:7421")
for change in log.changes:
print(f"{change.timestamp}: {change.actor} -> {change.after}")
Self-Debugging Pattern
from statecli import StateCLI
class SelfHealingAgent:
def __init__(self):
self.cli = StateCLI()
async def execute(self, task):
entity = f"task:{task.id}"
# Checkpoint before risky operation
self.cli.checkpoint(entity, "before-execution")
try:
await self.run_task(task)
except Exception as e:
# Replay to see what happened
replay = self.cli.replay(entity)
print(f"Task failed. Replay: {replay.changes}")
# Undo and retry
self.cli.undo(entity)
await self.retry_with_fix(task, replay)
API Reference
StateCLI(db_path=None)
Initialize client. Uses ~/.statecli/state.db by default.
track(entity_type, entity_id, state, actor="ai-agent")
Track a state change.
replay(entity, actor=None)
Replay state changes for an entity.
undo(entity, steps=1)
Undo the last N state changes.
checkpoint(entity, name)
Create a named checkpoint.
log(entity, since=None, actor=None)
View state change history.
restore_checkpoint(entity, name)
Restore to a named checkpoint.
Links
- GitHub: https://github.com/statecli/mcp-server
- NPM (Node.js): https://www.npmjs.com/package/statecli-mcp-server
- MCP Registry: io.github.charo360/statecli
License
MIT
Metadata
Release files for statecli 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| statecli-0.5.0.tar.gz | 12.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| statecli-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.2 kB
Release files / statecli-0.5.0.tar.gz
| Download URL | statecli-0.5.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fb937bad2ea7e5dbd31ca54fa4b0e33dda3b55cd127d5f200ca4c3618aafc55
|
|
BLAKE2b-256 checksum How to use checksums |
8fa32a81923cf0a5fc29c862ad3ba568d84d63e73e8edf535783a50a3772dfa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / statecli-0.5.0-py3-none-any.whl
| Download URL | statecli-0.5.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
958e65c399dec160bc945d13397a625be483d157364daefc87556cef221c5c2b
|
|
BLAKE2b-256 checksum How to use checksums |
83ba507ece81e611f9c772fb034a83fce8222d6ff0ab3a27f3dfdfb0b9676e31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|