"""Publish operator guides in the unified setup tree; no active settings changed."""
import json
import os
from pathlib import Path
import shutil

assert os.geteuid()==0
stage=Path("/home/si/.local/share/contextra-offline-prep/20260928-r01")
target=Path("/workspace/contextra/setup/guides")
target.mkdir(mode=0o750,exist_ok=True)
os.chown(target,0,1001)
for source in (stage/"maintenance/OFFLINE_OPERATIONS.ko.md",stage/"maintenance/NETWORK_TRANSITION.ko.md",stage/"windows/WINDOWS_PREP.ko.md"):
    output=target/source.name
    if output.exists() and output.read_bytes()!=source.read_bytes():raise RuntimeError("Existing guide differs")
    shutil.copyfile(source,output)
    os.chown(output,0,1001)
    output.chmod(0o640)
workspace=Path("/workspace/contextra/setup/contextra.code-workspace")
config=dict(folders=[dict(path="/workspace/contextra/source/crowd-0f172d94")],settings={
    "search.followSymlinks":False,"search.useIgnoreFiles":True,
    "files.watcherExclude":{"**/__pycache__/**":True},"search.exclude":{"**/__pycache__":True}})
if not workspace.exists():
    workspace.write_text(json.dumps(config,indent=2))
    os.chown(workspace,0,1001)
    workspace.chmod(0o640)
print("Unified setup guides and source-only VSCode workspace ready")
