Skip to main content

ashmatics-playbook-grammar

Version: 0.3.0 Last Updated: 2026-11-03

See CHANGELOG.md for version history.

The FORGE playbook interior grammar, its save and publish validators, and the content hash stamped at publish. One copy, imported at a pinned version by both services that need it: the KB runs it when Asher publishes a playbook template version, and FORGE (coreapp) runs it when it pins a copy and when a site authors its own playbook (coreapp ADR 070 D4).

Moved from coreapp with no change in behavior. Function names and error messages are coreapp's. Since 0.2.0 the package also holds the rules FORGE owns that the publish validator runs, so the KB publishes a template with exactly the checks coreapp runs, over the data the KB holds.

Install

One runtime dependency: pyyaml. Nothing here imports Azure, a database driver or Django.

pip install ashmatics-playbook-grammar      # from PyPI

The package lives in the framework repo at tools/playbook-grammar/. It has no git tags of its own; the framework's vX.Y.Z is the only tag. To work on it, use a checkout:

git clone https://gitlab.com/ashmatics/platform/ashmatics-aigov-framework.git
cd ashmatics-aigov-framework/tools/playbook-grammar
uv sync --extra dev        # or: pip install -e ".[dev]"
uv run pytest

ashmatics-aigov-tools depends on it and re-exports it as ashmatics_aigov_tools.playbook_grammar.

Use

import ashmatics_playbook_grammar as pg

pg.validate_template_document(document)          # save: raises InvalidPlaybookDocument
pg.validate_for_publish(document, base_practices,
                        playbook_class="governance",
                        lookups=my_lookups)       # publish: the CHAR reads come in lookups
pg.content_hash(document)                         # the hash stamped at publish
pg.load_grammar("1.2")                            # one grammar version, as a dict

# Grammar 1.3: org unit band and target tailoring points
pg.resolve(document, context)                     # the document every reader sees
done = pg.resolve_with_record(document, context)  # the same, and what it removed
done.document, done.stamp()                       # stamp() is what compile writes

context is coreapp's PlaybookContext.to_dict() (unit_level, level_source, band, target_ids, target_names). The resolver reads band and target_ids only.

Grammar 1.3 adds tailoring points (coreapp ADR-069 Amendment 1, A4). The terms:

  • A tailoring point is a marked place in a playbook template where the words, a default, who decides, or whether a step exists can change by org unit band or by target.
  • Tailored text is the version the author writes for one band or target, beside the enterprise text.
  • To tailor is what FORGE does: it applies the tailoring points from the context. The customer never sees or answers one.
  • A tailored playbook is the result for one unit.

Tailoring adapts one playbook. An overlay adds to it (ADR-069 D2, not built). A variant replaces it (ADR-069 D3).

In the document, a tailoring point is a choice step that FORGE applies from the context: answered_by: {"context": "org_unit_band"}, with the four org unit bands as outcomes, or {"context": "target:acr_arch_ai"}, with on and off. A node, a setting or a lane may carry by_choice: {<tailoring point id>: {<outcome>: {<field>: <value>}}}: that is its tailored text and defaults for an answer. The resolver prunes what each answer excludes, drops the settings a tailoring point hides, applies by_choice, then removes the tailoring points and joins their edges through. A document with no tailoring point comes back equal to its input. Publish resolves a document with tailoring points for every org unit band and every target on and off, and runs every publish rule on each result. The band set, the base outcomes and the fields by_choice may change are data in grammar-1.3.yaml. ACTIVE_GRAMMAR_VERSION is 1.3: new templates use the latest grammar. A 1.3 document with no tailoring point is the same as a 1.2 one.

lookups is any object with the nine data reads of PublishLookups: the four CHAR reads (known_sops, step_anchors, gate_ids, phases_of_sop) and, since 0.2.0, control_base_practices, harm_model, failure_mode_taxonomy, stakeholder_roles and risk_bands. lookups.py documents the shape each one returns and where coreapp reads it. It is required: there is no default that passes, because "cannot check" is not "checked".

A 0.1.0 lookups, which also answered six FORGE rules itself (LegacyPublishLookups), still works in 0.2.x: the validator calls each of those methods it finds instead of the package's rule. They go in 0.3.0.

Module What it holds Moved from (coreapp)
grammar the grammar files and their readers core/services/govflow_grammar.py, core/config/govflow/
validators save and publish validators, attr_is_shown, choice_answers_in_force, anchor patterns core/services/playbook_service.py
setup_shapes save-time shape rules for structured settings core/services/setup_lists.py
setup_lists publish rules for structured settings and the lists they name (0.2.0) core/services/setup_lists.py
controls the REALISES rules, claim_errors (0.2.0) core/services/playbook_controls_service.py
hazard gate_for_step, the per-record gates (0.2.0) core/services/hazard_run_service.py
triage questions_for_node (0.2.0) core/services/triage_service.py
registration REGISTRATION_SOP_STEP (0.2.0) core/services/registration_service.py
hashing content_hash core/services/playbook_service.py
tailoring grammar 1.3: resolve, resolve_with_record, the tailoring point save and publish rules (0.3.0) new
lookups PublishLookups, LegacyPublishLookups new

What stayed in coreapp: the data behind lookups (the CHAR mirror, the controls catalogue, the stakeholder roles mirror, the data contract), the organization's own roles, each list's version label, the owed reasons, freeze, and grammar_for_api with its gate titles, which read CHAR's lifecycle data.

Releasing

A version change in pyproject.toml, merged to main, publishes that version to PyPI from CI (.gitlab-ci.yml at the repo root, plan row AT-9). There is no token: PyPI trusted publishing (OIDC). The publish job runs only after the package's tests pass, playbook-grammar before aigov-tools, in the GitLab environment pypi. A version already on PyPI is skipped with a message, so a merge that does not move the version publishes nothing. Never upload by hand.

One-time setup on pypi.org, for each project (ashmatics-playbook-grammar and ashmatics-aigov-tools): the project's Manage page, Publishing, "Add a new publisher", GitLab:

Field Value
Namespace ashmatics/platform
Project name ashmatics-aigov-framework
Top-level pipeline file path .gitlab-ci.yml
Environment name pypi

On GitLab, first (before adding the publishers on pypi.org): protect the environment pypi (Settings, CI/CD, Protected environments; allowed to deploy: Maintainers, with an approval if wanted). PyPI checks the project, the pipeline file and the environment, but not the branch, and a merge request pipeline runs the branch's own .gitlab-ci.yml; so without the protection any Developer could add a job that publishes. The group is on GitLab Ultimate, which has protected environments; on 2026-11-02 none was set up and main is protected (Maintainers push and merge).

A playbook-grammar version bump also re-locks aigov-tools in the same merge request (uv lock in tools/aigov-tools): its uv.lock records the sibling's version, and aigov-tools-tests runs uv sync --locked, which fails on a stale lock.

Until a project has its publisher, its publish job fails at the token exchange for a new version, and nothing is uploaded. A merge request pipeline never publishes; its pypi-version-check job says which versions are already on PyPI.

Tests

The tests replay what coreapp's own functions returned (tests/fixtures/):

  • every published interior in coreapp's interiors-v0.25.0.json passes both validators and reproduces its published hash;
  • for the bundle and 64 broken documents, the moved functions return exactly what coreapp's returned, in the same order, and make exactly the CHAR reads coreapp made;
  • the publish validator over data reads alone (the 0.2.0 shape) returns the same, and every function and constant moved in 0.2.0 matches coreapp's, vector by vector (tests/test_moved_rules.py). The recorder reads the framework's stakeholder roles registry from this repo, at the commit coreapp's mirror was made from.

To re-record after a change on the coreapp side, run the recorder from coreapp's venv:

/path/to/ashmatics-coreapp/.venv/bin/python scripts/record_playbook_grammar_fixtures.py \
    --coreapp /path/to/ashmatics-coreapp

Metadata

Release files for ashmatics-playbook-grammar 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ashmatics-playbook-grammar 0.3.0
File Size Uploaded Provenance Actions
ashmatics_playbook_grammar-0.3.0.tar.gz 81.9 kB Without provenance Details for ashmatics_playbook_grammar-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ashmatics-playbook-grammar 0.3.0
File Interpreter ABI Platform Actions
ashmatics_playbook_grammar-0.3.0-py3-none-any.whl Python 3 none any Details for ashmatics_playbook_grammar-0.3.0-py3-none-any.whl

Total release size: 168.3 kB

Release files / ashmatics_playbook_grammar-0.3.0.tar.gz

Download URL ashmatics_playbook_grammar-0.3.0.tar.gz
Size 81.9 kB
Tags Source
SHA-256 checksum
How to use checksums
74bdc2bad982c0a3300b7cc7d5352767903dd967ad08ad8c59d1b5febe834a3e
BLAKE2b-256 checksum
How to use checksums
c677e0cd02f0bca876acc9ab23bcecd4a0ab35230e77c3268af21f1cf57edcd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ashmatics_playbook_grammar-0.3.0-py3-none-any.whl

Download URL ashmatics_playbook_grammar-0.3.0-py3-none-any.whl
Size 86.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e350aebce9e54a72f239a736cd1eca3fae27badf358e38319294bea549ef83e9
BLAKE2b-256 checksum
How to use checksums
672a63729266d0ee0a4c1c995c46a7b515fe0f4dfb9e18dcc9a96c0321a55b3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ashmatics-playbook-grammar 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page