system-spec-ref 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. system_spec_ref-0.1.0/.github/skills/alloy/SKILL.md +49 -0
  2. system_spec_ref-0.1.0/.github/skills/modelable/SKILL.md +61 -0
  3. system_spec_ref-0.1.0/.github/skills/tla/SKILL.md +49 -0
  4. system_spec_ref-0.1.0/.github/workflows/metamodel.yml +51 -0
  5. system_spec_ref-0.1.0/.gitignore +9 -0
  6. system_spec_ref-0.1.0/BROWNFIELD.md +81 -0
  7. system_spec_ref-0.1.0/CONSTITUTION.md +205 -0
  8. system_spec_ref-0.1.0/GREENFIELD.md +86 -0
  9. system_spec_ref-0.1.0/LICENSE +21 -0
  10. system_spec_ref-0.1.0/PACKAGING.md +120 -0
  11. system_spec_ref-0.1.0/PKG-INFO +35 -0
  12. system_spec_ref-0.1.0/PLAN.md +85 -0
  13. system_spec_ref-0.1.0/PYPI.md +14 -0
  14. system_spec_ref-0.1.0/README.md +77 -0
  15. system_spec_ref-0.1.0/WIRING.md +49 -0
  16. system_spec_ref-0.1.0/archive/BENCHMARK.md +67 -0
  17. system_spec_ref-0.1.0/archive/README.md +8 -0
  18. system_spec_ref-0.1.0/archive/REVIEW.md +321 -0
  19. system_spec_ref-0.1.0/archive/feedback/modelable-onboarding.md +119 -0
  20. system_spec_ref-0.1.0/archive/feedback/observable-onboarding.md +52 -0
  21. system_spec_ref-0.1.0/build_support.py +42 -0
  22. system_spec_ref-0.1.0/examples/brownfield/README.md +93 -0
  23. system_spec_ref-0.1.0/examples/brownfield/level0.yaml +12 -0
  24. system_spec_ref-0.1.0/examples/brownfield/level1.yaml +58 -0
  25. system_spec_ref-0.1.0/examples/brownfield/old.yaml +65 -0
  26. system_spec_ref-0.1.0/examples/brownfield/spec.yaml +85 -0
  27. system_spec_ref-0.1.0/examples/greenfield/Inventory.als +72 -0
  28. system_spec_ref-0.1.0/examples/greenfield/Inventory.cfg +7 -0
  29. system_spec_ref-0.1.0/examples/greenfield/Inventory.tla +49 -0
  30. system_spec_ref-0.1.0/examples/greenfield/README.md +79 -0
  31. system_spec_ref-0.1.0/examples/greenfield/spec.yaml +91 -0
  32. system_spec_ref-0.1.0/hatch_build.py +13 -0
  33. system_spec_ref-0.1.0/packaging.yaml +294 -0
  34. system_spec_ref-0.1.0/pyproject.toml +79 -0
  35. system_spec_ref-0.1.0/reference-implementation/.dockerignore +3 -0
  36. system_spec_ref-0.1.0/reference-implementation/.gitignore +3 -0
  37. system_spec_ref-0.1.0/reference-implementation/Dockerfile +7 -0
  38. system_spec_ref-0.1.0/reference-implementation/README.md +44 -0
  39. system_spec_ref-0.1.0/reference-implementation/corpus.yaml +86 -0
  40. system_spec_ref-0.1.0/reference-implementation/example.yaml +89 -0
  41. system_spec_ref-0.1.0/reference-implementation/metamodel.als +133 -0
  42. system_spec_ref-0.1.0/reference-implementation/metamodel.py +614 -0
  43. system_spec_ref-0.1.0/reference-implementation/old.yaml +63 -0
  44. system_spec_ref-0.1.0/reference-implementation/pyproject.toml +16 -0
  45. system_spec_ref-0.1.0/reference-implementation/schema.json +1087 -0
  46. system_spec_ref-0.1.0/reference-implementation/test_metamodel.py +251 -0
  47. system_spec_ref-0.1.0/reference-implementation/test_onboarding.py +142 -0
  48. system_spec_ref-0.1.0/reference-implementation/uv.lock +284 -0
  49. system_spec_ref-0.1.0/spec.md +299 -0
  50. system_spec_ref-0.1.0/system_spec_ref/__init__.py +1 -0
  51. system_spec_ref-0.1.0/system_spec_ref/cli.py +117 -0
  52. system_spec_ref-0.1.0/system_spec_ref/metamodel.py +614 -0
  53. system_spec_ref-0.1.0/system_spec_ref/toolkit/.github/skills/alloy/SKILL.md +49 -0
  54. system_spec_ref-0.1.0/system_spec_ref/toolkit/.github/skills/modelable/SKILL.md +61 -0
  55. system_spec_ref-0.1.0/system_spec_ref/toolkit/.github/skills/tla/SKILL.md +49 -0
  56. system_spec_ref-0.1.0/system_spec_ref/toolkit/.github/workflows/metamodel.yml +51 -0
  57. system_spec_ref-0.1.0/system_spec_ref/toolkit/BROWNFIELD.md +81 -0
  58. system_spec_ref-0.1.0/system_spec_ref/toolkit/CONSTITUTION.md +205 -0
  59. system_spec_ref-0.1.0/system_spec_ref/toolkit/GREENFIELD.md +86 -0
  60. system_spec_ref-0.1.0/system_spec_ref/toolkit/LICENSE +21 -0
  61. system_spec_ref-0.1.0/system_spec_ref/toolkit/PACKAGING.md +120 -0
  62. system_spec_ref-0.1.0/system_spec_ref/toolkit/PLAN.md +85 -0
  63. system_spec_ref-0.1.0/system_spec_ref/toolkit/README.md +77 -0
  64. system_spec_ref-0.1.0/system_spec_ref/toolkit/WIRING.md +49 -0
  65. system_spec_ref-0.1.0/system_spec_ref/toolkit/archive/BENCHMARK.md +67 -0
  66. system_spec_ref-0.1.0/system_spec_ref/toolkit/archive/README.md +8 -0
  67. system_spec_ref-0.1.0/system_spec_ref/toolkit/archive/REVIEW.md +321 -0
  68. system_spec_ref-0.1.0/system_spec_ref/toolkit/archive/feedback/modelable-onboarding.md +119 -0
  69. system_spec_ref-0.1.0/system_spec_ref/toolkit/archive/feedback/observable-onboarding.md +52 -0
  70. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/brownfield/README.md +93 -0
  71. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/brownfield/level0.yaml +12 -0
  72. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/brownfield/level1.yaml +58 -0
  73. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/brownfield/old.yaml +65 -0
  74. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/brownfield/spec.yaml +85 -0
  75. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/greenfield/Inventory.als +72 -0
  76. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/greenfield/Inventory.cfg +7 -0
  77. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/greenfield/Inventory.tla +49 -0
  78. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/greenfield/README.md +79 -0
  79. system_spec_ref-0.1.0/system_spec_ref/toolkit/examples/greenfield/spec.yaml +91 -0
  80. system_spec_ref-0.1.0/system_spec_ref/toolkit/packaging.yaml +294 -0
  81. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/.dockerignore +3 -0
  82. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/.gitignore +3 -0
  83. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/Dockerfile +7 -0
  84. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/README.md +44 -0
  85. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/corpus.yaml +86 -0
  86. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/example.yaml +89 -0
  87. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/metamodel.als +133 -0
  88. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/metamodel.py +614 -0
  89. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/old.yaml +63 -0
  90. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/pyproject.toml +16 -0
  91. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/schema.json +1087 -0
  92. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/test_metamodel.py +251 -0
  93. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/test_onboarding.py +142 -0
  94. system_spec_ref-0.1.0/system_spec_ref/toolkit/reference-implementation/uv.lock +284 -0
  95. system_spec_ref-0.1.0/system_spec_ref/toolkit/spec.md +299 -0
  96. system_spec_ref-0.1.0/system_spec_ref/toolkit/templates/BROWNFIELD-INTAKE.md +109 -0
  97. system_spec_ref-0.1.0/templates/BROWNFIELD-INTAKE.md +109 -0
  98. system_spec_ref-0.1.0/toolkit_manifest.txt +44 -0
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: alloy
3
+ description: Formally verify a capability's structural invariants with Alloy and record the result as metamodel Evidence. Use when the constitution's formal verification assessment flags a component whose risk lies in data models, relations, references, permissions or configuration rather than interleaving (prefer the tla skill for concurrency and protocols).
4
+ ---
5
+
6
+ # Alloy Formal Verification
7
+
8
+ Rules: [constitution § Formal Verification](../../../CONSTITUTION.md#formal-verification). Format: [`spec.md`](../../../spec.md) §§ 4, 8.
9
+
10
+ ## Inputs
11
+
12
+ - Target capability: `preconditions`, `postconditions`, `invariants`, `failure_modes`.
13
+ - Requirement(s) to verify, with `criteria`.
14
+ - Entities and relations owned by the component.
15
+
16
+ ## Steps
17
+
18
+ 1. **Model**: one module per capability, e.g. [`Inventory.als`](../../../examples/greenfield/Inventory.als) (metamodel example: [`metamodel.als`](../../../reference-implementation/metamodel.als)).
19
+ - `sig`s and fields: only entities and relations named by the contract.
20
+ - `fact`s: structural rules the system enforces; never encode properties under check as facts.
21
+ - One `pred` per operation over pre/post state (`s, s'` or Alloy 6 `var` fields); guard with `preconditions`; model `failure_modes` as explicit outcomes.
22
+ 2. **Properties**: one `assert` per contract clause, named after it.
23
+ - `invariants` → `assert StockNeverNegative { all s: State | s.stock >= 0 }`.
24
+ - `postconditions` → `assert ReservePost { all s, s': State, q: Int | reserve[s, s', q] => s'.stock = minus[s.stock, q] }`.
25
+ - One `run` per operation to show it is satisfiable (guards against vacuous checks).
26
+ 3. **Scope**: e.g. `check StockNeverNegative for 5 but 4 Int`; small, explicit scopes and bitwidth; record them as assumptions.
27
+ 4. **Check**: `java -jar org.alloytools.alloy.dist.jar exec Inventory.als`.
28
+ 5. **Review**: confirm the model corresponds to the contract and implementation; on counterexample, fix spec or design, never silently weaken the assertion or add a fact to hide it.
29
+
30
+ ## Evidence
31
+
32
+ ```yaml
33
+ evidence:
34
+ - id: ev-reserve-alloy
35
+ requirement_id: req-reserve
36
+ requirement_version: "1.0"
37
+ method: model-check
38
+ bounds: { scope: 5 }
39
+ passed: true
40
+ provenance: alloy::Inventory.als
41
+ ```
42
+
43
+ - `provenance` identifies the model; keep scopes, bitwidth, solver, Alloy version, assumptions and output with it ([`spec.md` § 8](../../../spec.md#8-verification)).
44
+ - A bounded `check` is a `model-check` (`bounds` required, e.g. the scope), not an unbounded proof (`method: proof`).
45
+ - Contract changes invalidate the evidence; rerun after `--impact <capability>`.
46
+
47
+ ## Prompt
48
+
49
+ "Write an Alloy model of `<capability>` from its contract; one named `assert` per invariant/postcondition and a `run` per operation; give scopes and list assumptions."
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: modelable
3
+ description: Derive Modelable `.mdl` from a component's metamodel data_models to generate typed artifacts and check field-level version compatibility, recording results as metamodel Evidence. Use at implementation (greenfield phase 9) and before publishing a new data model version (incl. brownfield Level 2); not for specification, where data_models are authoritative.
4
+ ---
5
+
6
+ # Modelable Data Contracts
7
+
8
+ Rules: [constitution § Data Contracts](../../../CONSTITUTION.md#data-contracts). Format: [`spec.md`](../../../spec.md) §§ 5, 8. Tool: [Modelable](https://github.com/ktjn/modelable).
9
+
10
+ `data_models` in the metamodel YAML are the source of truth; `.mdl` is a derived implementation artifact kept with the component's code.
11
+
12
+ ## Inputs
13
+
14
+ - Target `data_models` entries (validated with `metamodel.py`): `id`, `version`, `owner`, `fields`, `classification`, `derived_from`.
15
+ - Requirement(s) to verify, with `criteria`.
16
+ - Brownfield: existing schemas or DDL (`modelable import`) to compare against `data_models`.
17
+
18
+ ## Mapping
19
+
20
+ | Metamodel | `.mdl` |
21
+ |---|---|
22
+ | `owner` (component ID) | `domain` with `owner: "<component>"` |
23
+ | `id`, `version` `"N.0"` | `entity`/`event`/`value` `<Name> @ N` |
24
+ | `fields` | Typed fields; exactly one `@key` for entities |
25
+ | `classification` | `@classification("…")`/`@pii` on fields; model level = strictest field. `open` → `public`; `secret` → `restricted` |
26
+ | `derived_from` | `projection … from <src> @ N` / `join <src> @ N`; fields use `<-` or `=` |
27
+
28
+ ## Steps
29
+
30
+ 1. **Derive**: one `domain` per owning component; exactly the fields of `data_models`, never more.
31
+ - Annotate `@pii`/`@classification` explicitly on every projection field; it is not inherited by generated artifacts.
32
+ 2. **Validate**: `modelable validate <dir> --strict`.
33
+ 3. **Lineage**: `modelable lineage <domain>.<Projection>@N --path <dir>`; sources must match `derived_from`, otherwise fix the metamodel first.
34
+ 4. **Compatibility** (new version): `modelable diff <ref>@N <ref>@N+1 --path <dir>` and `modelable validate-compat --from <old> --to <new> --target <json-schema|protobuf|openapi|…>`. Exit `1` = breaking; bump the `data_models` major version and run `metamodel.py --impact <id>`.
35
+ 5. **Generate**: `modelable compile <dir> --target <target> --out <dir>`; keep `modelable-artifact-manifest.json`.
36
+ 6. **Drift**: any change starts in `data_models`; regenerate `.mdl` and artifacts, never edit them first.
37
+
38
+ ## Evidence
39
+
40
+ ```yaml
41
+ evidence:
42
+ - id: ev-order-compat
43
+ requirement_id: req-order-contract
44
+ requirement_version: "2.0"
45
+ method: analysis
46
+ passed: true
47
+ provenance: modelable::validate-compat --from v1 --to v2 --target json-schema
48
+ ```
49
+
50
+ - `diff`/`validate-compat` → `analysis`; generated serializer tests → `test`.
51
+ - `provenance` identifies the command and sources; keep tool version and output with it ([`spec.md` § 8](../../../spec.md#8-verification)).
52
+ - Model changes invalidate the evidence; rerun after `--impact <data-model>`.
53
+
54
+ ## Notes
55
+
56
+ - Requires Python 3.14: `uvx modelable`. If import fails on `selectolax`, use `uvx --with 'selectolax<1' modelable`.
57
+ - `(additive)` versions reject removals; declare breaking versions explicitly.
58
+
59
+ ## Prompt
60
+
61
+ "Derive `.mdl` for `<data-model>` from its `data_models` entry; one domain per owner, no invented fields, explicit `@pii`/`@classification` on every field and projection field; then compile to `<target>`."
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: tla
3
+ description: Formally verify a capability's invariants with TLA+ and TLC, and record the result as metamodel Evidence. Use when the constitution's formal verification assessment flags a component (concurrency, distributed state, financial transactions, safety-critical logic, complex state machines, protocols).
4
+ ---
5
+
6
+ # TLA+ Formal Verification
7
+
8
+ Rules: [constitution § Formal Verification](../../../CONSTITUTION.md#formal-verification). Format: [`spec.md`](../../../spec.md) §§ 4, 8.
9
+
10
+ ## Inputs
11
+
12
+ - Target capability: `preconditions`, `postconditions`, `invariants`, `failure_modes`.
13
+ - Requirement(s) to verify, with `criteria`.
14
+ - Consistency boundary of the owning component.
15
+
16
+ ## Steps
17
+
18
+ 1. **Model**: one module per capability, e.g. [`Inventory.tla`](../../../examples/greenfield/Inventory.tla) (config: [`Inventory.cfg`](../../../examples/greenfield/Inventory.cfg)).
19
+ - `VARIABLES`: only state named by the contract.
20
+ - `Init`, one action per operation; guard actions with `preconditions`; model `failure_modes` as explicit actions or outcomes.
21
+ - Model concurrency and retries at the component's consistency boundary.
22
+ 2. **Properties**: one per contract clause, named after it.
23
+ - `invariants` → `INVARIANT` (e.g. `StockNeverNegative == stock >= 0`).
24
+ - `postconditions` → action properties (e.g. `[][Reserve => stock' = stock - qty]_vars`).
25
+ - Liveness only when a requirement demands it; state fairness explicitly.
26
+ 3. **Config** (`.cfg`): small constants, explicit bounds; record them as assumptions.
27
+ 4. **Check**: `java -cp tla2tools.jar tlc2.TLC -config Inventory.cfg Inventory.tla`.
28
+ 5. **Review**: confirm the model corresponds to the contract and implementation; on violation, fix spec or design, never silently weaken the property.
29
+
30
+ ## Evidence
31
+
32
+ ```yaml
33
+ evidence:
34
+ - id: ev-reserve-tla
35
+ requirement_id: req-reserve
36
+ requirement_version: "1.0"
37
+ method: model-check
38
+ bounds: { products: 2, max_qty: 3 }
39
+ passed: true
40
+ provenance: tla+::Inventory.tla
41
+ ```
42
+
43
+ - `provenance` identifies the model; keep the `.cfg`, TLC version, bounds, assumptions and output with it ([`spec.md` § 8](../../../spec.md#8-verification)).
44
+ - A bounded TLC run is a `model-check` (`bounds` required), not an unbounded proof (`method: proof`).
45
+ - Contract changes invalidate the evidence; rerun after `--impact <capability>`.
46
+
47
+ ## Prompt
48
+
49
+ "Write a TLA+ model of `<capability>` from its contract; one named property per invariant/postcondition; give the `.cfg` with bounds and list assumptions."
@@ -0,0 +1,51 @@
1
+ name: metamodel
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+ inputs:
8
+ script:
9
+ description: Script to run
10
+ type: choice
11
+ options: [metamodel.py, pytest]
12
+ default: metamodel.py
13
+ args:
14
+ description: "Arguments, paths relative to reference-implementation/ (e.g. 'example.yaml --json', '--impact order', '--schema'); empty validates example.yaml / runs all tests"
15
+ default: ""
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ run:
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - uses: actions/checkout@v5
25
+ - name: Build image
26
+ run: docker build -t metamodel reference-implementation
27
+ - name: Run
28
+ env:
29
+ SCRIPT: ${{ inputs.script }}
30
+ ARGS: ${{ inputs.args }}
31
+ run: |
32
+ run() { docker run --rm -v "$PWD:/repo" -w /repo/reference-implementation metamodel "$@" 2>&1 | tee -a out.txt; return "${PIPESTATUS[0]}"; }
33
+ status=0
34
+ if [ -n "$SCRIPT" ]; then
35
+ read -ra A <<< "$ARGS"
36
+ [ "$SCRIPT" = pytest ] && cmd=(pytest -p no:cacheprovider) || cmd=(python metamodel.py)
37
+ run "${cmd[@]}" "${A[@]}" || status=$?
38
+ else
39
+ for c in "pytest -p no:cacheprovider" \
40
+ "python metamodel.py example.yaml" \
41
+ "python metamodel.py ../examples/greenfield/spec.yaml --stage release" \
42
+ "python metamodel.py ../examples/brownfield/level0.yaml --stage inventory" \
43
+ "python metamodel.py ../examples/brownfield/level1.yaml --stage architecture" \
44
+ "python metamodel.py ../examples/brownfield/old.yaml --stage verification" \
45
+ "python metamodel.py ../examples/brownfield/spec.yaml --stage release --compat ../examples/brownfield/old.yaml"; do
46
+ read -ra cmd <<< "$c"
47
+ run "${cmd[@]}" || status=$?
48
+ done
49
+ fi
50
+ { echo '```'; cat out.txt; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
51
+ exit "$status"
@@ -0,0 +1,9 @@
1
+ /system_spec_ref/metamodel.py
2
+ /system_spec_ref/toolkit/
3
+ /dist/
4
+ /build/
5
+ /*.egg-info/
6
+ /.venv/
7
+ __pycache__/
8
+ *.pyc
9
+ .pytest_cache/
@@ -0,0 +1,81 @@
1
+ # Brownfield: Onboarding Existing Systems
2
+
3
+ Incremental sequencing for existing systems. Artifact rules: [constitution](CONSTITUTION.md). Load this document together with the constitution only.
4
+
5
+ Overrides the [greenfield](GREENFIELD.md) ordering: existing code is the discovery input, so architecture may be described before capabilities, and implementation precedes verification.
6
+
7
+ ## Adoption Levels
8
+
9
+ Each level targets a `--stage` ([`spec.md` § 11](spec.md#11-metamodel-validation)); known violations are allowed below `release` as risk waivers ([`spec.md` § 7](spec.md#7-risks)). Level 0 advances directly to Level 1 (`architecture`), skipping standalone `discovery` because existing code supplies architecture and contracts together. Validate with `metamodel.py <spec> --stage <stage>`.
10
+
11
+ | Level | Goal | Stage |
12
+ |---|---|---|
13
+ | 0 — Inventory | `system`, `external_sources`, deployable units, coarse module boundaries (`status: draft`); identity and syntax only | `inventory` |
14
+ | 1 — Dependency & data mapping | Observed `provides`/`requires`, data ownership, classification, lineage (`status: specified`); layer/cycle/ownership/budget violations recorded as waivers | `architecture` |
15
+ | 2 — Behavioral pinning | As-is contracts and characterization tests (`Evidence`); missing verification categories covered by waivers; external contracts frozen before refactoring | `verification` |
16
+ | 3 — Full conformance | All waivers remediated; layer and context budget rules enforced without exception; all 10 verification categories satisfied (`status: verified`) | `release` |
17
+
18
+ For each adoption level, use the [shared decision record](CONSTITUTION.md#gate-decision-record): review observed artifacts against the level's criteria, record discrepancies and decide whether to pass, defer via an allowed waiver or rework.
19
+
20
+ | Level | Bring to review | Decision required before proceeding |
21
+ |---|---|---|
22
+ | 0 — Inventory | Entrypoints, jobs, external sources, deployable units and candidate component boundaries | All active runtime units and external dependencies are registered; unknown boundaries are flagged for discovery |
23
+ | 1 — Dependency & data mapping | Observed capability wiring, data schemas/owners/lineage, and discovered architecture violations with proposed waivers | Observed dependencies and data ownership match the running code; every violation is either remediated or deferred under a scoped, non-expired waiver |
24
+ | 2 — Behavioral pinning | As-is contracts, characterization test results for external/cross-component behavior, compatibility baseline and remaining coverage waivers | External and cross-component behavior is pinned by passing characterization evidence; unverified categories have bounded waivers expiring by release |
25
+ | 3 — Full conformance | Remediated architecture, compatibility results (`--compat`), requirement-linked evidence across all ten categories and risk dispositions | All waivers are closed, contracts and invariants hold without exception, and release evidence is current and reviewed |
26
+
27
+ If a level review fails (for example, an unrecorded dependency, a characterization test that contradicts the drafted contract, or an expired waiver), keep the level open: correct the specification to match observed behavior or complete the remediation before advancing. Do not hide discrepancies by inventing idealized contracts during discovery.
28
+
29
+ Worked progression from Level 0 to Level 3: [`examples/brownfield/`](examples/brownfield/README.md).
30
+
31
+ Real onboarding feedback: [Modelable](archive/feedback/modelable-onboarding.md) records bounded adoption, existing authority/tool mapping, evidence revision binding and unresolved model gaps; it is not a full-conformance example. [Observable](archive/feedback/observable-onboarding.md) records complete brownfield onboarding across all 6 milestones to Level 3 release conformance, covering multi-schema database isolation, schema compatibility matrices, and automated evidence provenance.
32
+
33
+ ## Reverse Discovery
34
+
35
+ Start with the [intake and gate template](templates/BROWNFIELD-INTAKE.md): record the repository root, exact source revision, adoption scope, existing authorities, product/validator tool map, validator/schema pin and native gates. Use separate whole-product and slice decisions; a slice pass does not advance excluded components. Record external/deferred/unknown boundaries explicitly; an unresolved required provider keeps architecture open. Imported schemas and capability catalogs are discovery inputs, not acceptance evidence.
36
+
37
+ For local multi-step operations, record transitions, actual Python/Rust/etc. interfaces, confirmation/freshness checks, durable writes and recovery. Distinguish failed-before-commit from committed-with-cleanup-error. Keep transaction ownership intact when choosing context budgets. The template supplies the protocol review record without inventing a new transport or claiming executable state-machine verification.
38
+
39
+ 1. **Boundaries & entrypoints**: APIs, jobs, events, external sources → `system`, capability stubs, `external_sources`.
40
+ 2. **Data & state**: schemas, migrations, ORM/DTO models (use [`modelable`](.github/skills/modelable/SKILL.md) `import` where helpful) → `data_models`, owners, classification, lineage.
41
+ 3. **Components & dependencies**: cluster modules by transaction/consistency boundaries → `components`, layers, wiring.
42
+ 4. **Invariants & failures**: domain guards, error handlers, existing tests → capability contracts, `Requirement.criteria`, initial `Evidence` (use [`tla`](.github/skills/tla/SKILL.md) / [`alloy`](.github/skills/alloy/SKILL.md) for concurrency or relational invariants).
43
+ 5. **Gaps & risks**: missing verification categories, unverified mitigations, architecture violations → `risks` and `requirements` backlog.
44
+
45
+ Rules:
46
+
47
+ - Record observed behavior, not intended behavior; never invent contracts or fields.
48
+ - Separate **as-is discrepancies** (bugs, coupling, undocumented side effects observed in code) from **target changes** (remediation or modernization requirements).
49
+ - Validate with `metamodel.py` after each step and review the underlying code and test evidence before recording a level decision.
50
+ - Unknown/provisional classification uses `classification: unknown` plus an active `classification_review` requirement and conservative handling policy. Resolve it before architecture; do not allow an implicit public classification.
51
+ - Bind implementation evidence to contract versions and source revisions with `subject_bindings`/`subject_version`; preserve file hashes, execution conditions and explicit `skipped` checks. Run optional `--check-artifacts --root <repository>` for local source/schema/evidence integrity, then retain native semantic and acceptance gates.
52
+ - Evidence paths are relative to that repository root, even when the specification lives in a nested directory. Use one provenance file with an optional `::selector`; declare additional logs and environment records separately in `artifacts`. Preserve the original schema, capture and decisions when migrating validator versions.
53
+ - Attribute skips to the requirements they leave unverified. Separate passing records may cover genuinely independent, executed checks; a suite's passing count does not establish a skipped criterion. Check release diagnostics for binding errors without treating their absence as release acceptance.
54
+ - When components share relational storage or streaming buses, enforce dedicated schema namespaces, eliminate cross-schema foreign keys, and back idempotency guarantees with formal models (`TelemetryDelivery.tla`) and concrete deduplication mechanisms.
55
+ - Require transitional boundary allowlists to monotonically ratchet downward to zero before Level 3 acceptance.
56
+
57
+ ## Waivers
58
+
59
+ - Known violations (`layer-violation`, `dependency-cycle`, `shared-data-ownership`, `context-budget`, `verification-category`) are linked to a `Risk` (`waives`) with `treatment: mitigation` or `acceptance`.
60
+ - Each waiver requires a remediation requirement in `mitigated_by` and an `expires` bound (ISO date `YYYY-MM-DD` or target stage).
61
+ - Expired waivers fail validation at every stage; no waivers are allowed at `--stage release` (Level 3).
62
+
63
+ ## Characterization, Migration and Acceptance Loop
64
+
65
+ 1. **Pin baseline (Levels 1–2)**: capture observed contracts and run characterization tests before changing internal structure. Record any deferred violations or coverage gaps as scoped waivers with remediation requirements.
66
+ 2. **Scope one migration step**: run `--impact <id>` against the pinned baseline to identify affected components, data models, requirements and evidence. Prepare a bounded [implementation handoff](CONSTITUTION.md#implementation-handoff) (`--context <component-id>`) containing the pinned contract, target remediation requirement, allowed boundary changes and characterization suite.
67
+ 3. **Refactor or extract**: implement the strangler or boundary change within the handoff scope. If hidden coupling or an undocumented failure mode surfaces, stop and reopen the Level 1 or Level 2 review to update the observed baseline first.
68
+ 4. **Verify compatibility and remediation**: check `--compat <pinned-baseline>` for capability and data contracts, rerun invalidated characterization and remediation tests, and update evidence revisions. If a waiver expires or a check fails, recover by completing the remediation or rolling back the step before proceeding.
69
+ 5. **Close waivers and accept (Level 3)**: remove remediated waivers once their mitigating requirements have passing, current evidence. Complete all ten verification categories and record the release decision ([`CONSTITUTION.md` § Acceptance](CONSTITUTION.md#acceptance)).
70
+
71
+ ## Prompts
72
+
73
+ Ask for observed evidence and explicit discrepancy decisions. When serializing the reference format, validate against [`reference-implementation/schema.json`](reference-implementation/schema.json) (`metamodel.py --schema`) and [`spec.md` § 11](spec.md#11-metamodel-validation) invariants; prose findings and review records remain part of the process. Per step:
74
+
75
+ - **1** (`REF-01`, `DATA-01`): "List entrypoints of `<repo>` as draft `capabilities`, `components` and `external_sources` (`REF-01`, `DATA-01`); record observed behavior only."
76
+ - **2** (`DATA-01`–`DATA-04`): "Extract `data_models` from `<schemas>` with `owner`, `classification` and `derived_from` (`DATA-01`, `DATA-02`, `DATA-03`, `DATA-04`); do not invent fields."
77
+ - **3** (`STAT-02`, `COMP-01`–`COMP-07`): "Cluster `<modules>` into `components` by consistency boundary; list observed `provides`/`requires` and violations (`STAT-02`, `COMP-01`, `COMP-02`, `COMP-03`, `COMP-04`, `COMP-05`, `COMP-06`, `COMP-07`)."
78
+ - **4** (`STAT-01`, `CAP-01`–`CAP-04`): "Derive `preconditions`, `postconditions`, `invariants`, `failure_modes` and `interface` for `<capability>` from guards, handlers and tests (`STAT-01`, `CAP-01`, `CAP-02`, `CAP-03`, `CAP-04`)."
79
+ - **5** (`REQ-01`, `REQ-07`, `RISK-01`–`RISK-08`): "List missing verification categories and architecture violations as `risks` (`waives`, `mitigated_by`, `expires`) and `requirements` (`REQ-01`, `REQ-07`, `RISK-01`, `RISK-02`, `RISK-03`, `RISK-04`, `RISK-08`)."
80
+ - **Level & waiver review** (`EV-04`, `RISK-01`, `RISK-02`, `RISK-08`): "Compare these spec revisions against the observed code/tests and this level's criteria (`EV-04`, `RISK-01`, `RISK-02`, `RISK-08`). Separate observed behavior from intended fixes, verify waiver scope/expiry and record pass, defer or rework."
81
+ - **Migration handoff** (`COMPAT-01`–`COMPAT-09`): "Refactor `<component>` within this bounded `--context` handoff while preserving the pinned contracts (`COMPAT-01`, `COMPAT-02`, `COMPAT-03`, `COMPAT-04`, `COMPAT-05`, `COMPAT-06`, `COMPAT-07`, `COMPAT-08`, `COMPAT-09`) and characterization tests. Report affected revisions, compatibility findings and any newly discovered facts, coupling or model gaps ([self-improvement](CONSTITUTION.md#self-improvement-and-model-feedback))."
@@ -0,0 +1,205 @@
1
+ # AI System Development Constitution
2
+
3
+ Shared fundamentals for all work. Track-specific sequencing: [greenfield](GREENFIELD.md) (new systems), [brownfield](BROWNFIELD.md) (existing systems). Metamodel: [`spec.md`](spec.md).
4
+
5
+ This document defines shared obligations; tracks define sequencing. Tools may check parts of an artifact, but gate decisions require review of its meaning and evidence.
6
+
7
+ ## Fundamental Principle
8
+
9
+ Implementations are not the source of truth. The source of truth is:
10
+
11
+ 1. Capabilities
12
+ 2. Business rules
13
+ 3. Invariants
14
+ 4. Data contracts
15
+ 5. API contracts
16
+ 6. Verification specifications
17
+ 7. Formal models (where applicable)
18
+
19
+ Code is one possible implementation of a verified specification.
20
+
21
+ ## Why
22
+
23
+ - AI quality degrades as context grows: requirement interpretation, architecture discipline, cross-component consistency and traceability suffer.
24
+ - Small components, explicit contracts and layering bound the context each task needs.
25
+ - Tests, not code, are the executable specification:
26
+
27
+ ```text
28
+ Capability → Contract → Data model → Tests → Code
29
+ ```
30
+
31
+ ---
32
+
33
+ # Artifact Rules
34
+
35
+ ## Capabilities
36
+
37
+ - Format: [`spec.md` § 4](spec.md#4-capabilities).
38
+ - `Purpose`, `Consumers`, `Producers` and `Business value` are discovery context, not fields.
39
+ - Acceptance criteria → `Requirement.criteria`; verification results → `Evidence`.
40
+ - As long as the contract holds, the implementation may change freely.
41
+
42
+ ## Invariants
43
+
44
+ - A condition that must always hold, e.g. inventory never negative; an order paid at most once; customer email unique.
45
+ - All architectural decisions must preserve invariants.
46
+
47
+ ## Components
48
+
49
+ - Derived from invariants and consistency requirements, not technology categories.
50
+ - Bad: `Database`, `REST`, `Kafka` components.
51
+ - Good: `Customer Management`, `Inventory Management`, `Payments`.
52
+ - Strong consistency inside a component; eventual consistency between components.
53
+
54
+ ```yaml
55
+ components:
56
+ - id: customer-management
57
+ version: "1.0"
58
+ layer: domain
59
+ consistency: strong
60
+ provides: [manage-customer]
61
+ requires: [customer-repository]
62
+ owns_data: [customer]
63
+ ```
64
+
65
+ - Contracts and invariants belong to `capabilities`; requirements target capabilities, components or data models.
66
+ - No implementation details in component specifications.
67
+
68
+ ## Data Contracts
69
+
70
+ - Every externally visible structure is explicitly defined.
71
+ - No implicit schemas; never infer or invent fields.
72
+ - `data_models` are authoritative; at implementation or version change, see skill [`modelable`](.github/skills/modelable/SKILL.md).
73
+
74
+ ```yaml
75
+ Customer:
76
+ id: UUID
77
+ email: String
78
+ status: [ACTIVE, BLOCKED]
79
+ ```
80
+
81
+ ## API Contracts
82
+
83
+ Every API defines: endpoint, version, request, response, failure conditions, status codes, idempotency, security. All APIs comply with organizational API guidelines.
84
+
85
+ ## Verification
86
+
87
+ No implementation is accepted until all categories are addressed:
88
+
89
+ | Category | Covers | `Requirement.kind` | `Evidence.method` |
90
+ |---|---|---|---|
91
+ | Functional | Expected behaviors | `functional` | `test` |
92
+ | Semantic | Business meaning (e.g. `BLOCKED` denies purchase) | `functional` | `test`, `model-check` or `proof` |
93
+ | Contract | API compatibility, status codes, versioning | `functional` | `test` or `inspection` |
94
+ | Serialization | JSON/XML/protobuf correctness, payload limits | `functional` | `test` |
95
+ | Concurrency | Races, lost updates, duplicate requests | `functional` | `test`, `model-check` or `proof` |
96
+ | Performance | Latency, throughput, resource limits | `non-functional` | `test` or `analysis` |
97
+ | Scalability | Expected load and data volumes | `non-functional` | `test` or `analysis` |
98
+ | Resilience | Timeouts, retries, partial failures | `non-functional` | `test` or `analysis` |
99
+ | Security | Authentication, authorization, input validation | `non-functional` | `test` or `inspection` |
100
+ | Observability | Metrics, tracing, logging, correlation IDs | `non-functional` | `test` or `inspection` |
101
+
102
+ ## Formal Verification
103
+
104
+ - Assess per component. Indicators: concurrency, distributed state, financial transactions, safety-critical logic, complex state machines, protocols.
105
+ - If applicable, produce TLA+/Alloy models or state machines; see skills [`tla`](.github/skills/tla/SKILL.md) (concurrency, protocols) and [`alloy`](.github/skills/alloy/SKILL.md) (structure, relations).
106
+ - Record bounded checks as `method: model-check` with explicit `bounds` and unbounded proofs as `method: proof` ([`spec.md` § 8](spec.md#8-verification)).
107
+
108
+ ## Layering
109
+
110
+ ```text
111
+ Experience → Application → Domain → Infrastructure
112
+ ```
113
+
114
+ - Higher layers may depend on lower layers, never the reverse.
115
+ - Domain logic must not depend on infrastructure details.
116
+
117
+ ## Context Budget
118
+
119
+ - A component's complete specification fits on 1–2 pages (defaults: `max_provides: 5`, `max_requires: 8`, `max_owns_data: 4`); otherwise split it.
120
+ - Each AI task receives only the minimum necessary context: these fundamentals, one track document, the applicable skill (if any) and the target component's spec slice (`metamodel.py <spec> --context <component-id>`).
121
+
122
+ ### Implementation Handoff
123
+
124
+ For each bounded change, give the implementer:
125
+
126
+ - The capability and expected outcome; accepted contract and data-model versions; affected invariants.
127
+ - For local multi-step APIs, the state transitions, confirmation/freshness obligations, committed writes and recovery for each failure outcome. An exception after commit does not imply rollback.
128
+ - The component boundary, permitted dependencies and relevant consumer/provider contracts.
129
+ - Requirement IDs, measurable acceptance criteria, verification procedures and expected failure cases.
130
+ - Applicable formal-model conclusions, assumptions, open risks and active waivers.
131
+ - Allowed change scope and the evidence to return. Include neighboring contracts without importing unrelated implementation context.
132
+
133
+ Resolve missing behavior or contradictory contracts before dependent implementation. If the packet cannot fit the context budget, split the work or revisit the component boundary. The implementer returns the change, requirement-linked results, affected revisions and any unmet criteria; it does not silently redefine the contract to fit the code.
134
+
135
+ ## Traceability
136
+
137
+ ```text
138
+ Capability → Requirement → Invariant → Component → Contract → Test → Implementation
139
+ ```
140
+
141
+ - Every test traces to a requirement; every implementation element traces to a capability.
142
+
143
+ ## Acceptance
144
+
145
+ A system is complete only when capabilities, invariants, components, contracts, data models and APIs are specified; verification is complete; formal models are reviewed; performance and concurrency goals are met; traceability is established; and architecture constraints are preserved.
146
+
147
+ Implementation completion, verification completion and release acceptance are separate states. Record each only when its obligations have been met.
148
+
149
+ ### Gate Decision Record
150
+
151
+ Keep a short decision record alongside the specification; no particular tool or file format is required:
152
+
153
+ | Record | Content |
154
+ |---|---|
155
+ | Scope | Gate/level, capability or change, and exact artifact revisions reviewed |
156
+ | Adoption boundary | Whole product or bounded slice; existing authorities/tool map, repository root, validator/schema pin, native gates and external/deferred/unknown units |
157
+ | Responsibility | Who prepared the artifacts, reviewed the evidence and owns the acceptance decision; one person may hold several roles |
158
+ | Findings | Criteria checked, supporting artifacts, unresolved questions and affected consumers |
159
+ | Outcome | Pass, rework, or defer within an allowed adoption-level waiver; identify the requirements/risks that justify any deferral |
160
+ | Follow-up | Remediation owner, expiry, next action and which gate must be revisited |
161
+
162
+ - **Pass** permits the next step for the recorded scope. A passing schema or validator result is supporting evidence only.
163
+ - **Rework** keeps the affected gate open. Repair the earliest invalid assumption or artifact, then review dependent outputs again.
164
+ - **Defer** preserves visible debt through an allowed, bounded waiver. It does not mark the waived property verified. Release permits no waiver deferrals.
165
+
166
+ Review criteria for meaning, not merely presence: failure behavior, measurable thresholds, consumer obligations and formal-model assumptions must match the intended system. Inspect the linked execution artifacts before accepting a claimed result.
167
+
168
+ Boundary allowlists or transitional dependency waivers (e.g., `component-boundary-allowlist.txt`) are permitted only below Level 3 (`release`) and must follow a monotonic ratcheting rule (entries may only decrease or stay equal; CI fails on additions) until completely zeroed. Multi-schema relational databases must enforce explicit schema namespace ownership and schema-scoped user roles, with zero cross-schema foreign keys.
169
+
170
+ Use the [brownfield intake template](templates/BROWNFIELD-INTAKE.md) for existing systems. Separate observed classification from provisional handling policy; retain skips and missing provider/data mappings as open obligations. Contract/source bindings and local file hashes support review but do not replace source authenticity, build correspondence or native acceptance gates.
171
+
172
+ ### Change and Reverification Loop
173
+
174
+ 1. Identify the requested behavior change and the last reviewed baseline. Trace affected capabilities, components, data models, consumers and requirements, including transitive dependencies (`--impact <id>`).
175
+ 2. Decide whether the contract stays compatible (`--compat`). If it breaks, define consumer migration and recovery before implementation; a version bump alone does not establish compatibility.
176
+ 3. Reopen the earliest affected gate. Update its artifacts and verification criteria, then issue a bounded implementation handoff.
177
+ 4. Treat evidence affected by changed requirements, subjects or dependencies as historical until rerun. Record requirement version, subject revision and the relevant dependency versions with the new results; preserve earlier failures and justify any supersession.
178
+ 5. Review new results against all affected obligations, including risk mitigations and consumer behavior. Record the gate decision and remaining work.
179
+
180
+ ### Self-Improvement and Model Feedback
181
+
182
+ When discovery, implementation, verification, formal modeling or incident review reveals new facts (undocumented failure modes, hidden coupling, violated assumptions, unmodeled domain constraints or gaps in the metamodel/process itself):
183
+
184
+ 1. **Surface the finding immediately** in the handoff return or [gate decision record](#gate-decision-record); never mask a missing contract clause, invariant or dependency with an ad-hoc code workaround.
185
+ 2. **Update the system model**: feed discovered facts back into `capabilities`, `components`, `data_models`, `requirements`, `risks` or formal models, run `--impact`, and reopen the earliest affected gate.
186
+ 3. **Improve the metamodel and tooling**: when a finding exposes an uncheckable rule or recurring blind spot in [`spec.md`](spec.md), track workflows or [`metamodel.py`](reference-implementation/metamodel.py), propose a minimal update to `spec.md` § 11, `INVARIANTS`, `schema.json` and `corpus.yaml`.
187
+
188
+ ---
189
+
190
+ # Metamodel Mapping
191
+
192
+ | Artifact | Metamodel (`spec.md`) |
193
+ |---|---|
194
+ | Capabilities | `capabilities` (`version`, `preconditions`, `postconditions`, `invariants`, `failure_modes`, `status`) |
195
+ | Invariants | `capabilities.invariants` |
196
+ | Components | `components` (`provides`, `requires`, `owns_data`, `status`, `source_paths`) |
197
+ | Data contracts | `data_models` (`schema_path`, `declassified_by`) |
198
+ | API contracts | Capability contracts, `requirements` and `data_models` (`capabilities.interface`) |
199
+ | Verification | `requirements` (`status`, `category`, `resolved_by`), `evidence` (`subject_revision`, `supersedes`) |
200
+ | Formal verification | `evidence.method: model-check` (with `bounds`) or `proof`; formal models in `provenance` |
201
+ | Layering | `system.layers`, `components.layer` |
202
+ | Context budget | `system.context_budget` (`max_provides`, `max_requires`, `max_owns_data`); per-component override `components.context_budget` |
203
+ | Waivers | `risks` (`mitigated_by`, `waives`, `expires`) |
204
+ | Traceability | Capability, component, requirement, data model and evidence references |
205
+ | Acceptance | `metamodel.py <spec> --stage release` (see [`spec.md` § 11](spec.md#11-metamodel-validation)) |
@@ -0,0 +1,86 @@
1
+ # Greenfield: Creating New Systems
2
+
3
+ Contract-first sequencing for new systems. Artifact rules: [constitution](CONSTITUTION.md). Load this document together with the constitution only.
4
+
5
+ ## Phases
6
+
7
+ | # | Phase | Output | Gate |
8
+ |---|---|---|---|
9
+ | 1 | Capability discovery | Capabilities with contracts and failure modes | 1 |
10
+ | 2 | Invariant discovery | Invariants per capability | 1 |
11
+ | 3 | Component identification | Components derived from invariants and consistency boundaries | 2 |
12
+ | 4 | Component specification | Component definitions; no implementation details | 2 |
13
+ | 5 | Data contracts | Data models with owners | 2 |
14
+ | 6 | API contracts | API contracts per capability | 2 |
15
+ | 7 | Verification specification | Requirements covering all 10 categories | 3 |
16
+ | 8 | Formal verification assessment | Formal models where indicated | 3 |
17
+ | 9 | Layering | Layers assigned; rules hold | 2 |
18
+ | 10 | Context budget | Oversized components split | 2 |
19
+ | 11 | Traceability | All artifacts linked | 4 |
20
+ | 12 | Acceptance | Passing, current evidence for all mandatory requirements | 4 |
21
+
22
+ Rules:
23
+
24
+ - Do not discuss technical architecture before capabilities are identified.
25
+ - Phase numbers identify work products; execution follows gate order: **1–2 → 3–6 and 9–10 → 7–8 → implementation → 11–12**.
26
+ - Begin implementation only after the discovery, architecture and verification gates pass for the change's scope.
27
+
28
+ ## Gates (`--stage`, see [`spec.md` § 11](spec.md#11-metamodel-validation))
29
+
30
+ 1. **Discovery** (`--stage discovery`): Phases 1–2; capabilities `specified` with non-empty contract clauses.
31
+ 2. **Architecture** (`--stage architecture`): Phases 3–6, 9–10; components `specified`, dependencies resolved, layer rules, data models, interface contracts and context budgets satisfied.
32
+ 3. **Verification** (`--stage verification`): Phases 7–8; requirements `specified` across all 10 categories; formal models checked with [`tla`](.github/skills/tla/SKILL.md) or [`alloy`](.github/skills/alloy/SKILL.md) where indicated.
33
+ 4. **Release** (`--stage release`): Phases 11–12; all active entities `verified`, passing current `Evidence` for all mandatory and mitigating requirements, all risks disposed, zero waivers.
34
+
35
+ For each gate, use the [shared decision record](CONSTITUTION.md#gate-decision-record): review the artifacts, record findings and decide whether to proceed or rework.
36
+
37
+ | Gate | Bring to review | Decision required before proceeding |
38
+ |---|---|---|
39
+ | Discovery | User/business outcome, consumers, capability contracts, invariants and failure cases | The scope and observable success/failure behavior are understood; material questions are resolved |
40
+ | Architecture | Component boundaries, dependency/layer map, ownership, data/API contracts and context budget | The composition can preserve the invariants; every dependency has an explicit contract and owner |
41
+ | Verification | Requirement-to-criterion mapping across all ten categories, planned tests/inspections, formal assessment and assumptions | Each obligation has a meaningful way to establish pass/fail; applicable formal checks are reviewed before implementation |
42
+ | Release | Requirement-linked execution results for current revisions, traceability, consumer compatibility/migration results and risk dispositions | All mandatory and mitigating obligations are satisfied, unresolved failures are addressed and no waiver remains |
43
+
44
+ If a gate fails, return to the earliest affected phase; do not advance by relabeling an incomplete artifact. Validate each gate with `metamodel.py <spec> --stage <gate>` and pass only the target component's slice (`--context <component-id>`) to the coding agent. At implementation (AI Execution Rule step 9), derive `.mdl` and typed data artifacts with [`modelable`](.github/skills/modelable/SKILL.md).
45
+
46
+ ## Implementation and Acceptance Loop
47
+
48
+ 1. Select one capability change whose first three gates have passed. Prepare the [implementation handoff](CONSTITUTION.md#implementation-handoff).
49
+ 2. Make verification executable before implementing the intended behavior; confirm a meaningful failing case where behavior is missing. Reused passing checks still need reviewed coverage of the change.
50
+ 3. Implement within the accepted component boundary. Return to the affected gate if a contract, ownership or dependency must change.
51
+ 4. Run the specified verification and inspect results. Record failures as well as successes with requirement IDs and applicable revisions.
52
+ 5. Review traceability, compatibility, evidence freshness and risk treatment at release. Close the scope only after recording the acceptance decision; carry unresolved work explicitly.
53
+
54
+ Worked example traced through Phases 1–12: [`examples/greenfield/`](examples/greenfield/README.md).
55
+
56
+ ## AI Execution Rule
57
+
58
+ When asked to design or implement any feature, produce artifacts in this order:
59
+
60
+ ```text
61
+ 1. Capability
62
+ 2. Invariants
63
+ 3. Component definition
64
+ 4. Contracts
65
+ 5. Data model
66
+ 6. Verification specification
67
+ 7. Formal model (if applicable)
68
+ 8. Architecture impact analysis (--impact)
69
+ 9. Implementation
70
+ 10. Verification results
71
+ ```
72
+
73
+ - For each step, produce the artifact or cite the reviewed artifact being reused with an impact justification.
74
+ - Never generate implementation before verification has been specified.
75
+ - Treat architecture as provable constraints, not a collection of code files.
76
+
77
+ ## Prompts
78
+
79
+ Ask for the artifact and the decisions it supports. When serializing the reference format, validate against [`reference-implementation/schema.json`](reference-implementation/schema.json) (`metamodel.py --schema`) and [`spec.md` § 11](spec.md#11-metamodel-validation) invariants; prose decisions and review evidence remain part of the process. Per phase:
80
+
81
+ - **1–2** (`STAT-01`, `CAP-01`): "List capabilities of `<domain>` (`status: specified`) with non-empty `preconditions` or `postconditions`, `invariants` and `failure_modes` (`STAT-01`, `CAP-01`); no architecture."
82
+ - **3–4** (`STAT-02`, `COMP-01`–`COMP-07`): "Derive components (`status: specified`) from these invariants and consistency boundaries; assign `layer`, `provides`, `requires` and `owns_data` within `context_budget` (`STAT-02`, `COMP-01`, `COMP-02`, `COMP-03`, `COMP-04`, `COMP-05`, `COMP-06`, `COMP-07`)."
83
+ - **5–6** (`DATA-01`–`DATA-04`, `CAP-02`–`CAP-03`): "Define `data_models` and capability `interface` contracts for `<capability>` mapping every failure mode in `errors` (`DATA-01`, `DATA-02`, `DATA-03`, `DATA-04`, `CAP-02`, `CAP-03`); do not invent fields."
84
+ - **7–8** (`STAT-03`, `CAP-04`, `REQ-01`–`REQ-03`, `REQ-07`, `EV-01`): "Write `requirements` (`status: specified`, `category`, matching `kind`) for all 10 verification categories of `<capability>` (`STAT-03`, `CAP-04`, `REQ-01`, `REQ-02`, `REQ-03`, `REQ-07`); flag formal verification candidates (`EV-01`)."
85
+ - **Gate review** (`STAT-04`, `EV-04`, `REQ-04`–`REQ-06`, `RISK-01`–`RISK-08`): "Review these artifact revisions against this gate's criteria and invariants (`STAT-04`, `EV-04`, `REQ-04`, `REQ-05`, `REQ-06`, `RISK-01`, `RISK-02`, `RISK-08`). Identify contradictions and missing evidence; record pass or rework with the next action. Do not infer acceptance from validator output."
86
+ - **Implementation** (`COMPAT-01`–`COMPAT-09`): "Implement this bounded `--context` handoff against the accepted contracts and tests (`COMPAT-01`, `COMPAT-02`, `COMPAT-03`, `COMPAT-04`, `COMPAT-05`, `COMPAT-06`, `COMPAT-07`, `COMPAT-08`, `COMPAT-09`). Return requirement-linked results, affected revisions and any newly discovered facts or model gaps ([self-improvement](CONSTITUTION.md#self-improvement-and-model-feedback)); surface contract changes before implementing dependent behavior."
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tommy Alander
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.