Skip to main content

workspace-metabolism

One policy file controls the whole life cycle of files in your workspace: classify, audit, clean into a recycle area (rollback anytime), purge, and verify — every step leaves a hash-chained audit trail. Python 3.11+, zero dependencies, Windows / Linux / macOS.

Terminal preview

Why this exists

Most disk tools either show you space (ncdu, duf) or delete things (rmlint). workspace-metabolism is different: a policy file defines what every path is worth (grades G1–G4), and the tool only ever does what the policy allows — nothing more.

  • G1 never touch / G2 keep / G3 approve + reference check / G4 auto
  • Deletion is never direct: items move to a recycle area, then rollback restores them after a per-file SHA-256 integrity check
  • Every action lands in a hash-chained journal; verify detects any edit
  • Read-only audit reports candidates, unregistered paths, disk alerts, growth trend and possible duplicates
  • Optional protected window (e.g. trading hours, business hours) during which marked entries are never touched
  • Scheduled runs are supported out of the box on Windows (Task Scheduler) and Linux/macOS (cron) via templates in examples/

🧬 Philosophy

workspace-metabolism treats your AI-generated workspace as a living system, inspired by biological metabolism: audit → clean → verify → rollback, with recyclable cleanup and a hash-chained audit trail. Cleanup is the means; metabolism is the frame. We call this framing Agentic Metabolic Engineering — managing the byproducts of agent-driven software workspaces. Full write-up: docs/philosophy.md · the story.

Quick start

# install from PyPI
pip install workspace-metabolism

# or run without installing anything:
#   PYTHONPATH=src python -m workspace_metabolism --help

# try it on a throwaway workspace (builds demo files, runs status/audit/clean)
python examples/demo.py

Point the tool at your own workspace:

wm --root /path/to/workspace --registry examples/registry.example.json status
wm --root /path/to/workspace --registry examples/registry.example.json audit
wm --root /path/to/workspace --registry examples/registry.example.json clean --grades G4 --yes
wm --root /path/to/workspace --registry examples/registry.example.json rollback <run_id>

Copy examples/registry.example.json, edit the paths and retention rules, and register every directory you want to manage. Nothing is cleaned unless it is registered in the policy file.

Commands

Command What it does
audit Read-only health check; writes a report and a journal entry
clean --grades G4 Move expired items to the recycle area (dry-run by default)
clean --grades G3 Same, but requires --approve + --approver
rollback <run_id> Restore one cleanup run after an integrity check
purge --older-than 30 Delete expired recycle batches (the only real delete)
verify Check the journal hash chain and run manifests
status Overview of workspace, recycle area and pending candidates

Global flags:

Flag Meaning
--root PATH Workspace to govern (default: current directory)
--state-dir PATH Journal / recycle / runs / reports (default: system cache directory, outside the workspace)
--registry PATH Policy registry JSON (required for audit / clean / status)
--protected-window HH:MM-HH:MM Weekday window; entries marked protected are skipped while active

The default state directory lives outside the workspace on purpose — a git add . in your project can never sweep the audit journal into version control.

Policy file

{
  "version": 1,
  "defaults": {
    "recycle_retention_days": 30,
    "max_item_mb": 2560,
    "disk_alert_free_gb": 20,
    "disk_alert_free_pct": 15,
    "dupe_scan_dirs": ["tmp", "cache"]
  },
  "never_clean": [".git", "README.md", "src"],
  "entries": [
    {"path": "logs", "grade": "G4", "cleanup": "auto", "retention_days": 30},
    {"path": "archive", "grade": "G3", "cleanup": "approve", "retention_days": 60},
    {"path": "**/__pycache__", "grade": "G4", "cleanup": "auto", "retention_days": 30}
  ]
}
Field Meaning
path Path or glob (*, **/) relative to --root
grade G1 never / G2 keep / G3 approve / G4 auto
cleanup never, auto or approve
retention_days Idle days before the item becomes a candidate (required unless cleanup=never)
scope Optional: files_only (top-level files of a directory)
protected Optional: skip while a --protected-window is active
remote_authoritative Optional: display marker for data with a remote source of truth
category Optional free-form label for your own classification

Safety model

  • clean is dry-run unless --yes is given.
  • G4 needs --yes; G3 needs --approve and --approver (audit trail).
  • Items move to the recycle area with per-file SHA-256 hashes; rollback verifies them before restoring and refuses to overwrite an existing path.
  • purge is the only command that truly deletes, and only inside the recycle area after retention.
  • The journal is a hash chain; verify detects any tampering.

Scheduled runs

Templates with {{PLACEHOLDERS}} are in examples/:

  • Windows — register_schedule.template.ps1: daily read-only audit (20:30), weekly G4 clean (Saturday 10:00), monthly purge (1st, 10:30).
  • Linux/macOS — register_cron.template.sh: same schedule via cron.

Replace {{WM_CMD}}, {{ROOT}}, {{REGISTRY}}, {{STATE_DIR}} (and {{USER}} in cron) with your values. The scripts deliberately do not auto-detect your environment — your paths, your call.

Development

python -m pip install -e . pytest
python -m pytest

CI runs the full test suite on Ubuntu, Windows and macOS with Python 3.11 and 3.12. Issues are handled on weekends; pull requests are welcome.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

workspace_metabolism-0.1.1.tar.gz (87.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

workspace_metabolism-0.1.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file workspace_metabolism-0.1.1.tar.gz.

File metadata

  • Download URL: workspace_metabolism-0.1.1.tar.gz
  • Upload date:
  • Size: 87.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for workspace_metabolism-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1f7426c960793a5f23a15eb874f5098b54106e06c7e946b6cfddd55c780ac36c
MD5 32f529fe57fc8fb57f1f9ce91df1cef0
BLAKE2b-256 15bd4d353f4c382f5ee9b6c979c3cd13206c634b2f906015cf6e5f8ddc7551ac

See more details on using hashes here.

File details

Details for the file workspace_metabolism-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for workspace_metabolism-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b6359efed17d0dac37dea51d381a756162eedade08b62fb2b6b1b286d23ed81
MD5 47e19490f595d2cbc6e594d9c83e3536
BLAKE2b-256 353ccac3f15954ad1eb64d9e2042e83eb0255d452feee9cfec54753da3b7e84c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page