Policy Service Package Design
This document defines architecture boundaries for the policy service package at
src/mud_server/services/policy/.
Goals
Keep canonical policy operations DB/artifact-first.
Keep
mud_server.services.policy_serviceas a stable facade for canonical callers.Remove legacy world-file import/read pathways from runtime and service surfaces.
Canonical Invariants
Canonical policy identity is represented by policy object fields and stored in SQLite.
Activation (
policy_activation) and variant status (policy_variant.status) are distinct concerns.Runtime effective policy resolution is computed from activation mappings, not file paths.
Publish artifacts are deterministic exchange outputs, not runtime authority.
Artifact import is idempotent at policy identity + variant granularity.
Package Modules
types.pyDefines shared typed structures used across policy modules, including:
ActivationScope,EffectiveAxisBundle, andEffectiveImagePolicyBundle.errors.pyDefines canonical policy service exceptions consumed by facade and route layers.
constants.pyDefines canonical constants used by policy validation and import/publish paths.
utils.pyImplements normalization and shared utility helpers used across modules.
hashing.pyOwns deterministic content hashing helpers used by upsert and publish flows.
validation.pyOwns policy content validation and policy-type specific rules.
activation.pyOwns activation writes, activation listing, and effective activation overlays.
runtime_resolution.pyOwns runtime effective resolution for policy variants, prompt templates, axis bundles, and image-policy diagnostic bundles.
publish.pyOwns deterministic publish runs and manifest generation.
artifact_import.pyOwns canonical artifact ingestion into policy tables.
paths.pyOwns policy export root resolution used by artifact bootstrap/import flows.
Facade Contract
src/mud_server/services/policy_service.py provides compatibility wrappers for canonical APIs.
Supported canonical facade exports:
list_policiesget_policyget_policy_capabilitiesvalidate_policy_variantupsert_policy_variantset_policy_activationlist_policy_activationsresolve_effective_policy_activationsget_effective_policy_variantresolve_effective_prompt_templateresolve_effective_axis_bundleresolve_effective_image_policy_bundlepublish_scopeget_publish_runimport_published_artifactparse_scope
Compatibility aliases are also preserved for existing callers:
configpolicy_repoPolicyServiceError
Removed legacy exports are intentionally absent.
Legacy Removal Scope
Removed from service/CLI surface:
Legacy world-policy file import entry points.
Legacy path-to-policy mapping helpers.
Legacy runtime fallback assumptions that imply file-path canonicality.
Testing Expectations
Unit coverage for validation, activation overlays, runtime resolution, publish, and artifact import.
Integration coverage for policy API routes and retained CLI commands.
Regression coverage proving DB/runtime behavior does not depend on legacy world policy files.