Metadata-Version: 2.4
Name: ashmatics-playbook-grammar
Version: 0.1.0
Summary: FORGE playbook interior grammar, save and publish validators, and content hash (ADR 070 D4)
Author-email: JF Kalafut <john@asherinformatics.com>, Asher Informatics PBC <info@ashmatics.com>
License: Apache-2.0
Project-URL: Homepage, https://gitlab.com/ashmatics/platform/ashmatics-aigov-framework/-/tree/main/tools/playbook-grammar
Project-URL: Repository, https://gitlab.com/ashmatics/platform/ashmatics-aigov-framework
Project-URL: Bug Tracker, https://gitlab.com/ashmatics/platform/ashmatics-aigov-framework/-/issues
Keywords: ashmatics,forge,playbook,ai-governance,healthcare-ai
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Healthcare Industry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: pyyaml>=6.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"

# ashmatics-playbook-grammar

**Version:** 0.1.0
**Last Updated:** 2026-11-02

> See [CHANGELOG.md](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.

## Install

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

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. It is not on a package index yet. Until it is,
install it from a checkout:

```bash
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

```python
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
```

`lookups` is any object with the ten methods of `PublishLookups`. `lookups.py` names the coreapp
function each one stands for. It is required: there is no default that passes, because "cannot
check" is not "checked".

| 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` |
| `hashing` | `content_hash` | `core/services/playbook_service.py` |
| `lookups` | `PublishLookups` | new |

What stayed in coreapp: the reads behind `lookups` (CHAR mirror data, and constants and rules
that sit in coreapp modules that import Django), and `grammar_for_api` with its gate titles,
which read CHAR's lifecycle data.

## 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.

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

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