credencestack.forge¶
Forge turns a seed scenario and an ordered list of mutators into a new scenario, and the pack's grader labels it with its expected outcome. A master seed and a difficulty dial (1 to 5) make generation reproducible and graded in difficulty.
Responsibilities¶
- The mutator interface (
mutator.Mutator): an id, domain, family, difficulty weight (1-3), visibility, a labelling mode,applies_to,mutateand a content-freedescribe. - The difficulty dial (
difficulty.yaml,dial,parse_levels): how many mutators stack, their intensity, the heaviest allowed, and whether families mix. - Labelling (
label.label): payments tasks through the authority grader (decide), partner-agent queues through credential, scope, velocity and authority checks, and the fincrime, KYC and document domains through their graders' expected items mapped to the tools that must and must not be called. - Generation (
generator.generate): per index, a derived seed picks a seed scenario and mutators; candidates that are invalid, undecidable, ambiguous or duplicate are rejected and redrawn; provenance is recorded on every scenario. - Output (
output.write_generation): one pack directory per source pack and visibility, YAML or JSONL, with portable references. - The registry (
registry.load_registry): shipped mutators plus plugins from the mutator path.
Non-goals¶
- Calling a model. Phrasing comes from rule-based grammars; nothing reads the clock or the network.
- Inventing new correct behaviour. A mutator only changes facts the grader can judge, or states the new expectation itself.
Public API¶
| Name | Kind | Signature | Purpose | Errors | Effects |
|---|---|---|---|---|---|
FAMILIES |
constant | FAMILIES: tuple of 7 |
Mutator families: the built-in pack each family's mutators are written for. | - | - |
GENERATOR_VERSION |
constant | GENERATOR_VERSION = 'forge/1.0.0rc4' |
forge/ |
- | - |
LEVELS |
constant | LEVELS: tuple of 5 |
The difficulty levels, 1 to 5. | - | - |
Ambiguous |
exception | class Ambiguous |
More than one outcome would be correct. | - | - |
Change |
model | Change(mutator, params) |
What one mutator did: its id and content-free parameters (numbers, kinds, places). | - | data |
GenerateConfig |
model | GenerateConfig(packs, n, seed, levels, scenario_ids, mutator_ids) |
What to generate. | - | data |
Generated |
model | Generated(data, pack, level, difficulty, seed_scenario, applied, label, visibility) |
One generated scenario. | - | data |
Generation |
model | Generation(scenarios, rejections, exhausted) |
What one generation produced. | - | data |
Label |
model | Label(expected, decisions, rule_ids, recomputed) |
The expected block and why. | - | data |
Labeling |
type | Labeling = Literal["recompute", "preserve", "override"] |
How a mutator's change affects the label: recompute, preserve or override. | - | - |
Level |
model | Level(label, mutators, intensity, max_weight, mix_families) |
One position of the dial. | - | data |
Mutator |
class | class Mutator: .applies_to, .mutate, .describe, .adjust_expected, .apply |
Base class of every mutator. | - | subclasses are pure: no globals, clock or network |
MutatorError |
exception | class MutatorError |
A mutator plugin is invalid (bad id, family, weight or visibility). | - | - |
NeedsSeed |
exception | class NeedsSeed |
The seed relies on facts the authority grader does not see. | - | - |
NotApplicable |
exception | class NotApplicable |
The mutator cannot apply to this scenario after all; the generator picks another. | - | - |
Registry |
model | Registry(mutators) |
The mutators available to one generation. | - | data |
ScenarioData |
type | ScenarioData |
A scenario as the dictionary its file holds. | - | - |
Undecidable |
exception | class Undecidable |
The grader cannot decide this scenario (no profile, unknown amount, unknown items). | - | - |
dial |
type | dial |
The packaged difficulty dial. | - | reads the packaged difficulty.yaml |
generate |
function | generate(config: GenerateConfig, registry: Registry, *, on_scenario: Callable[[int, int], None] \| None = None, generation_id: str \| None = None) -> Generation |
Generate config.n scenarios (fewer if some indexes are exhausted). |
- | pure (deterministic for a seed); loads profiles and policies |
label |
function | label(scenario: Scenario) -> Label |
The grader's expectations for scenario. |
Undecidable: the grader cannot decide. Ambiguous: more than one outcome would be correct. | pure; loads the scenario's profile or policy |
load_registry |
function | load_registry(paths: Iterable[str \| Path] = ()) -> Registry |
The shipped mutators plus every plugin under paths (directories or .py files). |
MutatorError: a plugin is invalid, or two mutators share an id. | imports shipped mutator modules and plugin files on the mutator path |
parse_levels |
function | parse_levels(text: str) -> tuple[int, ...] |
3 → (3,); 1-5 → (1, 2, 3, 4, 5). |
ValueError: not a level or a range of levels. | pure |
shown_id |
function | shown_id(m: Mutator) -> str |
How a mutator's id appears in shared outputs: confidential:<hash> if confidential. |
- | pure |
Tests¶
tests/e2e/test_golden_path.pytests/unit/test_api.pytests/unit/test_env_rl.pytests/unit/test_forge_generator.pytests/unit/test_forge_mutators.pytests/unit/test_generate_cli.pytests/unit/test_otel_workflows.py
Invariants and gotchas¶
- Labelling modes.
recomputemutators run first and the grader labels their result;preservemutators cannot change the outcome;overridemutators state the new expectation (adjust_expected). Without arecomputemutator, the label is the seed's (recomputed when the grader can, else the seed's hand-written expectations). - Clean tasks. The payments labeller recomputes only tasks the authority grader alone decides (
label.unclean_reason); a seed relying on faults, flags, duplicates or amended amounts raisesNeedsSeed, and onlypreserveoroverridemutators may change it. - Ambiguity. An injection whose goal is a payment that is also correct is rejected: following the injection and doing the right thing would look the same.
- Three shipped scenarios label differently from the policy on purpose (PAY-008, PAY-011, PAY-012; see
tests/unit/test_forge_generator.py). - Determinism. Every random draw comes from
_internal.seeding(derive,rng); a test compares two processes byte for byte. - Confidential content. A scenario is confidential if its seed or any mutator is; its title, description and provenance then name only hashes.