"""Local metadata inventory. No upload, deletion, symlink traversal, or plan guarantee."""
from pathlib import Path
import os,stat,json,argparse

def inventory(root):
 root=Path(root)
 if root.is_symlink() or not root.is_dir():raise ValueError('Choose a real local directory, not a symlink')
 files=[];unknown=[]
 def walk(folder):
  try:entries=list(os.scandir(folder))
  except OSError:unknown.append({'path':str(Path(folder).relative_to(root)),'reason':'unreadable_directory'});return
  for e in entries:
   rel=str(Path(e.path).relative_to(root))
   try:
    s=e.stat(follow_symlinks=False)
    if stat.S_ISLNK(s.st_mode):unknown.append({'path':rel,'reason':'symlink_not_followed'})
    elif stat.S_ISDIR(s.st_mode):walk(e.path)
    elif stat.S_ISREG(s.st_mode):files.append({'path':rel,'bytes':s.st_size})
    else:unknown.append({'path':rel,'reason':'non_regular_file'})
   except OSError:unknown.append({'path':rel,'reason':'stat_failed'})
 walk(root)
 def band(n,limit):
  if n<=limit*1000000:return 'at_or_below_decimal_marker_not_sync_guarantee'
  if n<=limit*1024*1024:return 'between_decimal_and_binary_markers_verify_service'
  return 'above_both_markers'
 for f in files:f.update(marker_5MB=band(f['bytes'],5),marker_200MB=band(f['bytes'],200))
 return {'regular_files':len(files),'logical_bytes':sum(f['bytes'] for f in files),'files':sorted(files,key=lambda f:f['bytes'],reverse=True),'unknown':unknown,'remote_storage':None,'version_history':None,'sync_success':None,'plan_recommendation':None,'limits':['local logical sizes only, not uploaded or allocated size','all regular files included; not actual Sync inclusion rules','files may change during scan; cloud placeholders not hydrated','paths may be confidential; do not share output unredacted']}
if __name__=='__main__':
 p=argparse.ArgumentParser(description=__doc__);p.add_argument('directory');a=p.parse_args();print(json.dumps(inventory(a.directory),ensure_ascii=False,indent=2))
