#!/usr/bin/env python3
"""Add a directory to Claude's trusted projects in ~/.claude.json.

Usage: trust-dir <directory>

Ensures the workspace trust dialog won't block headless claude sessions.
Only trusts directories under /workspace/wolts/ — everything else is a no-op.
Safe because we're inside a container; the user accepted that on setup.

Reads the existing .claude.json (preserving Claude's runtime state),
merges in the trust entry, and writes it back. Idempotent.
"""

import json
import sys
from pathlib import Path

def main():
    if len(sys.argv) < 2:
        print("usage: trust-dir <directory>", file=sys.stderr)
        sys.exit(1)

    work_dir = sys.argv[1]

    # Only auto-trust directories under /workspace/wolts/
    if not work_dir.startswith("/workspace/wolts"):
        sys.exit(0)

    config_path = Path.home() / ".claude.json"
    data = json.loads(config_path.read_text()) if config_path.exists() else {}
    projects = data.setdefault("projects", {})

    if work_dir not in projects or not projects[work_dir].get("hasTrustDialogAccepted"):
        projects.setdefault(work_dir, {}).update({
            "hasTrustDialogAccepted": True,
            "hasCompletedProjectOnboarding": True,
        })
        config_path.write_text(json.dumps(data, indent=2))


if __name__ == "__main__":
    main()
