# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-scoped-capability-token-attenuation-has-silently-widened-during-multi-hop-agent-delegation.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-scoped-capability-token-attenuation-has-silently-widened-during-multi-hop-agent-delegation.warrant.json
# Markdown SHA-256:   36f10386d6d156fbbbef9ae799bcc35bf36779e6806cdd61eca01dd765e66833
# Code AST SHA-256:   1ede1773b5247fa859d5af1af4f5fee81c5da6f2fdf184d827a8c769142701ec
# Verified Classes:   AttenuationWidened, ResolvedScope
# Defensive Guards:   3 fail-closed invariants (zero external deps)

from dataclasses import dataclass, field
from typing import FrozenSet

class AttenuationWidened(RuntimeError):
    """Raised when a delegated token's *resolved* scope is not a subset of its parent's."""
    pass

@dataclass(frozen=True)
class ResolvedScope:
    paths: FrozenSet[str]
    resolution_flags: FrozenSet[str] = field(default_factory=frozenset)

def resolve(declared_paths, flags):
    # Toy resolver: a union-style suffix caveat plus no-normalization flag widens the set.
    out = set(declared_paths)
    if "suffix:*.csv" in flags:
        out |= {"/data/hr/salaries.csv", "/data/reports/q3/2024/x.csv",
                "/data/reports/q3/2024/../../hr/salaries.csv"}
    if "normalize_before_check=false" in flags:
        pass  # traversal forms survive un-collapsed
    return ResolvedScope(frozenset(out), frozenset(flags))

def assert_attenuated(parent: ResolvedScope, child: ResolvedScope) -> None:
    if not child.paths.issubset(parent.paths):
        widened = child.paths - parent.paths
        raise AttenuationWidened(
            f"child resolved scope exceeds parent by {len(widened)} path(s): "
            f"{sorted(widened)[:3]}"
        )
    new_flags = child.resolution_flags - parent.resolution_flags
    if new_flags:
        raise AttenuationWidened(
            f"child introduced resolution flags absent from parent: {sorted(new_flags)}"
        )

def delegate(parent_declared, parent_flags, child_declared, child_flags):
    parent = resolve(parent_declared, parent_flags)
    child = resolve(child_declared, child_flags)
    # Declared-subset check (the insufficient proxy the delegator normally runs):
    assert set(child_declared).issubset(set(parent_declared)), "declared subset ok"
    # Resolved-subset check (the real invariant):
    assert_attenuated(parent, child)
    return child

if __name__ == "__main__":
    delegate(
        parent_declared={"/data/reports/*"},
        parent_flags=frozenset(),
        child_declared={"/data/reports/q3/2024/*"},
        child_flags=frozenset({"suffix:*.csv", "normalize_before_check=false"}),
    )
