Files
rose-ash/artdag/core/scripts/register_identity_effect.py
giles 1a74d811f7
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m33s
Incorporate art-dag-mono repo into artdag/ subfolder
Merges full history from art-dag/mono.git into the monorepo
under the artdag/ directory. Contains: core (DAG engine),
l1 (Celery rendering server), l2 (ActivityPub registry),
common (shared templates/middleware), client (CLI), test (e2e).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

git-subtree-dir: artdag
git-subtree-mainline: 1a179de547
git-subtree-split: 4c2e716558
2026-02-27 09:07:23 +00:00

84 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
Register the identity effect owned by giles.
"""
import hashlib
from pathlib import Path
import sys
# Add parent to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
from artdag.activitypub.ownership import OwnershipManager
def folder_hash(folder: Path) -> str:
"""
Compute SHA3-256 hash of an entire folder.
Hashes all files in sorted order for deterministic results.
Each file contributes: relative_path + file_contents
"""
hasher = hashlib.sha3_256()
# Get all files sorted by relative path
files = sorted(folder.rglob("*"))
for file_path in files:
if file_path.is_file():
# Include relative path in hash for structure
rel_path = file_path.relative_to(folder)
hasher.update(str(rel_path).encode())
# Include file contents
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(65536), b""):
hasher.update(chunk)
return hasher.hexdigest()
def main():
# Use .cache as the ownership data directory
base_dir = Path(__file__).parent.parent / ".cache" / "ownership"
manager = OwnershipManager(base_dir)
# Create or get giles actor
actor = manager.get_actor("giles")
if not actor:
actor = manager.create_actor("giles", "Giles Bradshaw")
print(f"Created actor: {actor.handle}")
else:
print(f"Using existing actor: {actor.handle}")
# Register the identity effect folder
effect_path = Path(__file__).parent.parent / "effects" / "identity"
cid = folder_hash(effect_path)
asset, activity = manager.register_asset(
actor=actor,
name="effect:identity",
cid=cid,
local_path=effect_path,
tags=["effect", "primitive", "identity"],
metadata={
"type": "effect",
"description": "The identity effect - returns input unchanged",
"signature": "identity(input) → input",
},
)
print(f"\nRegistered: {asset.name}")
print(f" Hash: {asset.cid}")
print(f" Path: {asset.local_path}")
print(f" Activity: {activity.activity_id}")
print(f" Owner: {actor.handle}")
# Verify ownership
verified = manager.verify_ownership(asset.name, actor)
print(f" Ownership verified: {verified}")
if __name__ == "__main__":
main()