# Plant attunement

> Decide if a player's gesture in Verdant Resonance reaches the plant they face. The garden then answers the same walk the same way.

Inspired by afflom/verdant-resonance (https://github.com/afflom/verdant-resonance), live at https://afflom.github.io/verdant-resonance/. A first-person garden of acoustic biomes and plants that answer the player. Pattern: Decision table, OMG DMN 1.5, hit policy FIRST. To write one of your own, follow How to build a decision table app (../../guides/decision-table/index.md). The prompt below is data, quoted from the example.

**Figure: What the Plant attunement app does.** A request goes in, the rules decide, and the Lean kernel has already proved what the rules promise.

| Step | What happens |
| --- | --- |
| 1. Request | angle, distance, cooldown |
| 2. 3 rules | the first that matches wins |
| 3. Answer | attuned, dormant, distant |
| 4. Proved | 3 theorems, 42 tests |

Verified by prismpm verify in the pinned SDK. Fingerprint: 4a96ebe34311084cb81a5ab93c58ebaa990913efa57589c97954f749c39a1abe. Acceptance vectors: 42. Claims: 6.

## The prompt

```json
{
  "schema": "prism/prompt/1",
  "goal": "Decide if a player's gesture in Verdant Resonance reaches the plant they face. The garden then answers the same walk the same way.",
  "pattern": "decisionTable",
  "repository": "afflom/verdant-resonance",
  "app": {
    "name": "garden-attunement",
    "title": "Plant attunement",
    "purpose": "Decide whether an attune gesture attunes the focal plant, is ignored while the gesture rests, or misses a plant outside the forward gaze cone, from the angle to the plant, its distance and the attune cooldown left.",
    "fields": [
      {
        "name": "angle",
        "kind": "number",
        "min": 0,
        "means": "degrees between the player's gaze and the plant",
        "max": 180
      },
      {
        "name": "distance",
        "kind": "number",
        "min": 0,
        "means": "how far the plant is, in metres",
        "max": 100
      },
      {
        "name": "cooldown",
        "kind": "number",
        "min": 0,
        "means": "milliseconds of the attune refractory period left",
        "max": 1100
      }
    ],
    "outcomes": [
      "attuned",
      "dormant",
      "distant"
    ],
    "meanings": {
      "attuned": "the plant attunes and sings",
      "dormant": "the gesture is ignored during its refractory pause, the plant rests",
      "distant": "the plant is outside the forward gaze cone and is not activated"
    },
    "rules": [
      {
        "when": [
          {
            "field": "distance",
            "op": ">",
            "value": 22
          }
        ],
        "then": "distant",
        "why": "prism/src/Foundation/Humane/V1/Model.lex.tex evaluateGazeTargetInForwardCone: distMeters <= 22, maxInteractiveRangeMeters 22"
      },
      {
        "when": [
          {
            "field": "angle",
            "op": ">",
            "value": 62
          }
        ],
        "then": "distant",
        "why": "Humane Model.lex.tex: forwardFovHalfAngleDeg 62; GardenCanvas.tsx never activates elements behind the player"
      },
      {
        "when": [
          {
            "field": "cooldown",
            "op": ">=",
            "value": 1
          }
        ],
        "then": "dormant",
        "why": "Humane Model.lex.tex GestureHoldAndCooldownPolicy attuneRefractoryMs 1100: GardenCanvas.tsx ignores attune while it cools down"
      }
    ],
    "otherwise": "attuned",
    "otherwiseWhy": "in the forward gaze cone and rested: the focal plant attunes",
    "properties": [
      {
        "kind": "never",
        "when": [
          {
            "field": "distance",
            "op": ">",
            "value": 22
          }
        ],
        "then": "attuned",
        "why": "no plant answers a player out of reach"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "angle",
            "op": ">",
            "value": 62
          }
        ],
        "then": "attuned",
        "why": "behindPlayerActivationsCount is 0: nothing behind the player activates"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "cooldown",
            "op": ">=",
            "value": 1
          }
        ],
        "then": "attuned",
        "why": "mindful pacing: a repeated gesture never attunes during its refractory pause"
      }
    ],
    "examples": [
      {
        "request": "10 8 0",
        "response": "attuned"
      },
      {
        "request": "62 22 0",
        "response": "attuned"
      },
      {
        "request": "180 5 0",
        "response": "distant"
      },
      {
        "request": "0 23 0",
        "response": "distant"
      },
      {
        "request": "30 4 1100",
        "response": "dormant"
      },
      {
        "request": "30 4 1",
        "response": "dormant"
      }
    ]
  },
  "stakeholders": [
    {
      "name": "Player",
      "text": "Wanders the garden and needs each plant to answer the same way to the same walk.",
      "concerns": [
        "Correct answers"
      ]
    },
    {
      "name": "Sound designer",
      "text": "Places plants and tunes the humane pacing and needs plants outside the gaze cone, or a rushed gesture, to stay silent.",
      "concerns": [
        "Proved guarantees",
        "Calm interaction"
      ]
    }
  ],
  "concerns": [
    {
      "name": "Calm interaction",
      "text": "Gestures follow the Humane design standard: focal gaze-cone selection and refractory pauses, with no activation behind the player.",
      "model": "quality"
    }
  ],
  "components": [
    {
      "name": "Garden client",
      "text": "The browser game, src/components/GardenCanvas.tsx, which finds the focal plant and sends the gesture.",
      "kind": "staticSite"
    },
    {
      "name": "Soundscape engine",
      "text": "src/game/soundscapeEngine.ts, the Web Audio voices an attuned plant plays.",
      "kind": "service"
    }
  ],
  "threats": [
    {
      "name": "Key-repeat flood",
      "text": "Operating-system key repeat fires attune many times a second, so plants chatter.",
      "stride": "denialOfService",
      "asset": "request",
      "likelihood": "medium",
      "impact": "minor",
      "control": {
        "name": "Refractory pause",
        "text": "Attune is ignored for 1100 ms after a gesture, proved for every request, and OS key repeat is suppressed.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "GardenAttunementProofs::inv003Holds"
          },
          {
            "kind": "review",
            "reference": "prism/src/Foundation/Humane/V1/Model.lex.tex GestureHoldAndCooldownPolicy"
          }
        ]
      }
    },
    {
      "name": "Activation behind the player",
      "text": "A plant behind the player attunes, breaking the focal gaze law.",
      "stride": "elevationOfPrivilege",
      "asset": "answer",
      "likelihood": "low",
      "impact": "minor",
      "control": {
        "name": "Gaze cone proved",
        "text": "Beyond 62 degrees nothing attunes, proved for every request.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "GardenAttunementProofs::inv002Holds"
          },
          {
            "kind": "review",
            "reference": "src/game/prismModel.test.ts focalGazeSelection"
          }
        ]
      }
    },
    {
      "name": "Client range drift",
      "text": "The client finds focal plants up to 32 m away while the model allows 22 m, so the page and the model disagree.",
      "stride": "tampering",
      "asset": "source",
      "likelihood": "medium",
      "impact": "minor",
      "accepted": "The app follows the LexLean model, 22 m; src/game/prismModel.ts findNearestPlant uses 32 m, a drift for the repository to reconcile."
    }
  ],
  "quality": [
    {
      "characteristic": "Safety",
      "subcharacteristic": "Operational constraint",
      "requirement": "No activation behind the player",
      "text": "An attune gesture never activates a plant outside the forward gaze cone.",
      "measure": "Behind-player activations",
      "measureText": "Requests with an angle over 62 degrees answered attuned, behindPlayerActivationsCount in the model.",
      "threshold": 0
    }
  ],
  "journeys": [
    {
      "stakeholder": "Player",
      "steps": [
        "REQ-001",
        "REQ-002",
        "REQ-003",
        "otherwise"
      ]
    },
    {
      "stakeholder": "Sound designer",
      "steps": [
        "INV-001",
        "INV-002",
        "INV-003"
      ]
    }
  ],
  "license": "MIT OR Apache-2.0",
  "axioms": {}
}
```

## Claims

- GA-01: The app never answers attuned when distance is above 22
- GA-02: The app never answers attuned when angle is above 62
- GA-03: The app never answers attuned when cooldown is at least 1
- GA-04: The architecture description declares every stakeholder, concern, component, edge, viewpoint and view it references
- GA-05: The ISO/IEC 25010 quality model numbers every characteristic, subcharacteristic, requirement and measure, and every parent it names is declared
- GA-06: Every compliance obligation is numbered in order and names its evidence

## Pattern

Decision table: OMG DMN 1.5, hit policy FIRST. The rules are tried in order, and the first one that matches gives the answer. If none matches, the default answer applies. This is a DMN decision table with the FIRST hit policy.

| Pattern | Standard | Answers |
| --- | --- | --- |
| Decision table | OMG DMN 1.5, hit policy FIRST | attuned, dormant, distant |

**Figure: Rules for each answer.** Each bar counts the rules that give one answer. When no rule matches, the answer is attuned.

|  | rules |
| --- | --- |
| attuned | 0 |
| dormant | 1 |
| distant | 2 |

## Behavior

A request is angle, distance, cooldown, separated by spaces. The first rule that matches decides. If none matches, the answer is attuned. A request over 88 bytes, or in any other form, is answered invalid.

| Rule | When | Answer | Why |
| --- | --- | --- | --- |
| REQ-001 | distance is above 22 | distant | prism/src/Foundation/Humane/V1/Model.lex.tex evaluateGazeTargetInForwardCone: distMeters \<= 22, maxInteractiveRangeMeters 22 |
| REQ-002 | angle is above 62 | distant | Humane Model.lex.tex: forwardFovHalfAngleDeg 62; GardenCanvas.tsx never activates elements behind the player |
| REQ-003 | cooldown is at least 1 | dormant | Humane Model.lex.tex GestureHoldAndCooldownPolicy attuneRefractoryMs 1100: GardenCanvas.tsx ignores attune while it cools down |
| otherwise | no rule matches | attuned | in the forward gaze cone and rested: the focal plant attunes |

## Properties Lean proves

Each property is a theorem about the same definitions the app is built from. It is proved for every request, not only the tested ones.

| Property | Statement | Theorem | Why |
| --- | --- | --- | --- |
| INV-001 | It never answers attuned when distance is above 22. | GardenAttunementProofs::inv001Holds | no plant answers a player out of reach |
| INV-002 | It never answers attuned when angle is above 62. | GardenAttunementProofs::inv002Holds | behindPlayerActivationsCount is 0: nothing behind the player activates |
| INV-003 | It never answers attuned when cooldown is at least 1. | GardenAttunementProofs::inv003Holds | mindful pacing: a repeated gesture never attunes during its refractory pause |

## Architecture

Stakeholders and the concerns each one views the app through (ISO/IEC/IEEE 42010).

| Stakeholder | Who they are | Concerns |
| --- | --- | --- |
| Player | Wanders the garden and needs each plant to answer the same way to the same walk. | Correct answers |
| Sound designer | Places plants and tunes the humane pacing and needs plants outside the gaze cone, or a rushed gesture, to stay silent. | Proved guarantees, Calm interaction |
| Verifier | Anyone who loads the holo, checks its fingerprint and replays its acceptance vectors before trusting an answer. | Integrity of the published app, Refused malformed requests, Proved guarantees |

## Concerns

What the stakeholders care about, and the model each is viewed in.

| Concern | What it means | Model |
| --- | --- | --- |
| Calm interaction | Gestures follow the Humane design standard: focal gaze-cone selection and refractory pauses, with no activation behind the player. | quality |
| Correct answers | Every well-formed request is answered by the first rule that matches it, or attuned when none does, as the spec states. | quality |
| Integrity of the published app | What a visitor runs is the holo the build verified, with its fingerprint and signed provenance beside it. | security |
| Proved guarantees | Each of the 3 properties of the spec holds for every request, proved by the Lean kernel. | quality |
| Refused malformed requests | A request that is not the 3 fields in order, or is longer than 88 bytes, is answered invalid and never guessed. | security |

## Components

8 components and 11 edges between them.

| Component | Kind | What it is |
| --- | --- | --- |
| Browser | externalSystem | The visitor's web browser, which loads the page and runs the Plant attunement guest. |
| Garden client | staticSite | The browser game, src/components/GardenCanvas.tsx, which finds the focal plant and sends the gesture. |
| GitHub Pages | externalSystem | Serves the page and the holo from the repository Pages workflow. |
| Plant attunement guest | service | The Core-Wasm guest built from the model: it answers one request of at most 88 bytes with one answer of at most 64. |
| Plant attunement page | staticSite | The page the template publishes: the holo, its fingerprint, its provenance and its acceptance vectors. |
| Prism build | cliAdapter | prismpm verify in the SDK image prismpm.lock pins: it checks every theorem, builds the guest and replays every vector. |
| Soundscape engine | service | src/game/soundscapeEngine.ts, the Web Audio voices an attuned plant plays. |
| Source repository | externalSystem | The repository that holds the prompt, the model and its gate. |

## Design views

The SDK checks each view against the system model and draws it as OPL and PlantUML.

| View | Diagram | Viewpoint |
| --- | --- | --- |
| Deciding a Plant attunement request | opmObjectProcess | Player: Correct answers |
| Components of Plant attunement | umlComponent | Verifier: Integrity of the published app |
| Answering a Plant attunement request | umlSequence | Player: Correct answers |
| States of the Plant attunement guest | umlStateMachine | Verifier: Refused malformed requests |

## Features and journeys

8 features. Each names the definitions that do the work and the tests that accept it. Each stakeholder has one journey.

| Feature | Calls | Accepted by |
| --- | --- | --- |
| When distance is above 22, the answer is distant. | GardenAttunement::rule1, GardenAttunement::judge | GardenAttunement::application |
| When angle is above 62, the answer is distant. | GardenAttunement::rule2, GardenAttunement::judge | GardenAttunement::application |
| When cooldown is at least 1, the answer is dormant. | GardenAttunement::rule3, GardenAttunement::judge | GardenAttunement::application |
| When no rule matches, the answer is attuned. | GardenAttunement::judge | GardenAttunement::application |
| A request that is not angle, distance, cooldown in order, separated by single spaces, or is over 88 bytes, is answered invalid. | GardenAttunement::dispatch, GardenAttunement::decodeField1 | GardenAttunement::application |
| It never answers attuned when distance is above 22. | GardenAttunement::judge | GardenAttunementProofs::inv001Holds |
| It never answers attuned when angle is above 62. | GardenAttunement::judge | GardenAttunementProofs::inv002Holds |
| It never answers attuned when cooldown is at least 1. | GardenAttunement::judge | GardenAttunementProofs::inv003Holds |

## Journeys

The ordered features each stakeholder takes.

| Stakeholder | Steps |
| --- | --- |
| Player | REQ-001 → REQ-002 → REQ-003 → otherwise |
| Sound designer | INV-001 → INV-002 → INV-003 |
| Verifier | refuse → INV-001 → INV-002 → INV-003 |

## Security and threat model

12 threats against 4 assets. Each has a STRIDE category, and either a control with evidence or a risk that is accepted on purpose.

| Threat | STRIDE | Asset | Risk | Answered by |
| --- | --- | --- | --- | --- |
| Activation behind the player | elevationOfPrivilege | Answer | low likelihood, minor impact | Gaze cone proved: proof GardenAttunementProofs::inv002Holds; review src/game/prismModel.test.ts focalGazeSelection |
| Answer that breaks INV-001 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-001: proof GardenAttunementProofs::inv001Holds |
| Answer that breaks INV-002 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-002: proof GardenAttunementProofs::inv002Holds |
| Answer that breaks INV-003 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-003: proof GardenAttunementProofs::inv003Holds |
| Client range drift | tampering | Model source | medium likelihood, minor impact | accepted: The app follows the LexLean model, 22 m; src/game/prismModel.ts findNearestPlant uses 32 m, a drift for the repository to reconcile. |
| Granted capability | informationDisclosure | Answer | low likelihood, major impact | No capability granted: gate prism-code check refuses an ungranted guest import |
| Key-repeat flood | denialOfService | Request bytes | medium likelihood, minor impact | Refractory pause: proof GardenAttunementProofs::inv003Holds; review prism/src/Foundation/Humane/V1/Model.lex.tex GestureHoldAndCooldownPolicy |
| Malformed request | tampering | Request bytes | high likelihood, major impact | Strict decoder: gate malformed-request acceptance vectors, replayed in the compiled guest by prismpm verify |
| Oversized request | denialOfService | Request bytes | medium likelihood, minor impact | Bounded request: gate acceptance vectors at the request bound, one byte over it, and at the guest allocation bound, replayed by prismpm verify |
| Substituted holo | spoofing | Published holo | low likelihood, critical impact | Fingerprint and provenance: gate actions/attest-build-provenance in the pages workflow; gate prism-code check of the holo identities in the page |
| Substituted host | spoofing | Published holo | low likelihood, critical impact | accepted: A page cannot defend against its own host. The holo carries signed build provenance a visitor can check, and the app can be rebuilt from its prompt. |
| Tampered model | tampering | Model source | low likelihood, major impact | Regenerated from the prompt: gate prismpm verify in the SDK image prismpm.lock pins; review app/prompt.json |

## Quality

ISO/IEC 25010:2023 requirements. Each has a measure and a threshold that a theorem pins.

| Requirement | Characteristic | Measure | Threshold |
| --- | --- | --- | --- |
| Bounded allocation: The guest allocates at most 176 bytes for one request. | Performance efficiency: Resource utilization | Guest allocation bytes | 176 |
| Bounded request: A request over 88 bytes is refused before any field is read. | Performance efficiency: Time behaviour | Request bytes read | 88 |
| Every property proved: All 3 properties are theorems the Lean kernel checks. | Security: Integrity | Unproved properties | 0 |
| Every request answered: Every request gets an answer: a rule, attuned otherwise, or invalid. | Functional suitability: Functional completeness | Unanswered requests | 0 |
| Every vector replays: All 42 acceptance vectors replay in the compiled guest, the shortest 0 bytes long. | Reliability: Faultlessness | Failed vectors | 0 |
| Examples answered as stated: Every one of the 6 examples of the spec is answered as it states. | Functional suitability: Functional correctness | Example mismatches | 0 |
| No activation behind the player: An attune gesture never activates a plant outside the forward gaze cone. | Safety: Operational constraint | Behind-player activations | 0 |

## Compliance

One obligation per standard, each naming its evidence.

| Standard | Subject | Evidence |
| --- | --- | --- |
| ISO/IEC/IEEE 42010:2022 | Architecture description | Architecture::architectureDescriptionHolds |
| ISO/PAS 19450:2015 and OMG UML 2.5.1 | Design views | Design::viewOpmDecide, Design::viewUmlComponents, Design::viewUmlRequest, Design::viewUmlStates |
| ISO/IEC 25010:2023 | Product quality | Quality::qualityModelHolds |
| ISO/IEC 27034-1:2011 and ISO/IEC 27005:2022 | Application security and risk | Security::controlSet |
| OMG DMN 1.5, hit policy FIRST | Decision table | GardenAttunement::judge |
| OpenSpec | Requirements | GardenAttunement::application |
| SPDX MIT OR Apache-2.0 | Licensing | GardenAttunement::application |

## Rendered design views

Written by the SDK from the design records when it verified the app.

### design/Design.viewOpmDecide.opl

```
View: Design::viewOpmDecide
Title: Deciding a Plant attunement request
Viewpoint: Architecture::viewpointPlayerCorrectAnswers
Notation: ISO/PAS 19450:2015 OPM, Prism OPL profile

componentBrowser is an object.
componentPlantAttunementGuest is an object.
componentPlantAttunementGuest can be stateDeciding or stateIdle.
processDecide is a process.
processEncodeAnswer is a process.
processJudge is a process.
processParseRequest is a process.
componentPlantAttunementGuest handles processDecide.
processParseRequest requires componentBrowser.
processEncodeAnswer affects componentBrowser.
processJudge invokes processEncodeAnswer.
processParseRequest invokes processJudge.
processDecide zooms into processParseRequest, processJudge, and processEncodeAnswer, in that sequence.

```

### design/Design.viewUmlComponents.puml

```
@startuml
' UML 2.5.1 component diagram
' view: Design::viewUmlComponents
' viewpoint: Architecture::viewpointVerifierIntegrityOfThePublishedApp
title Components of Plant attunement
component "componentBrowser" as c0
component "componentGardenClient" as c1
component "componentGitHubPages" as c2
component "componentPlantAttunementGuest" as c3
component "componentPlantAttunementPage" as c4
component "componentPrismBuild" as c5
component "componentSoundscapeEngine" as c6
component "componentSourceRepository" as c7
c0 --> c3 : edgeBrowserToPlantAttunementGuest
c1 --> c3 : edgeGardenClientToPlantAttunementGuest
c2 --> c0 : edgeGitHubPagesToBrowser
c3 --> c0 : edgePlantAttunementGuestToBrowser
c3 --> c1 : edgePlantAttunementGuestToGardenClient
c3 --> c6 : edgePlantAttunementGuestToSoundscapeEngine
c4 --> c2 : edgePlantAttunementPageToGitHubPages
c5 --> c3 : edgePrismBuildToPlantAttunementGuest
c5 --> c4 : edgePrismBuildToPlantAttunementPage
c6 --> c3 : edgeSoundscapeEngineToPlantAttunementGuest
c7 --> c5 : edgeSourceRepositoryToPrismBuild
@enduml

```

### design/Design.viewUmlRequest.puml

```
@startuml
' UML 2.5.1 sequence diagram
' view: Design::viewUmlRequest
' viewpoint: Architecture::viewpointPlayerCorrectAnswers
title Answering a Plant attunement request
participant "componentBrowser" as p0
participant "componentPlantAttunementGuest" as p1
p0 -> p1 : processDecide
p1 --> p0 : processDecide
@enduml

```

### design/Design.viewUmlStates.puml

```
@startuml
' UML 2.5.1 state machine diagram
' view: Design::viewUmlStates
' viewpoint: Architecture::viewpointVerifierRefusedMalformedRequests
title States of the Plant attunement guest
state "stateAnsweredAttuned" as s0
state "stateAnsweredDistant" as s1
state "stateAnsweredDormant" as s2
state "stateDeciding" as s3
state "stateIdle" as s4
state "stateRefused" as s5
[*] --> s4
s4 --> s3 : processParseRequest
s4 --> s5 : processParseRequest
s3 --> s1 : processRule1
s3 --> s1 : processRule2
s3 --> s2 : processRule3
s3 --> s0 : processOtherwise
s0 --> s4 : processEncodeAnswer
s2 --> s4 : processEncodeAnswer
s1 --> s4 : processEncodeAnswer
s5 --> s4 : processEncodeAnswer
@enduml

```

## Prism source

Every file the builder wrote, laid out as a repository created from UOR-Foundation/template; the download prism-garden-attunement.zip has them all.

- app/src/Architecture.lex.tex (399 lines)
- app/src/Compliance.lex.tex (56 lines)
- app/src/Design.lex.tex (535 lines)
- app/src/Features.lex.tex (109 lines)
- app/src/Quality.lex.tex (361 lines)
- app/src/Security.lex.tex (551 lines)
- app/src/GardenAttunement.lex.tex (198 lines)
- app/src/GardenAttunementProofs.lex.tex (87 lines)
- app/lexlean.toml (43 lines)
- app/prompt.json (269 lines)
- model/ids.toml (59 lines)
- features/suites/garden\_attunement.feature (38 lines)
- crates/conformance/tests/garden\_attunement.rs (122 lines)
- site/app.json (102 lines)
- openspec/specs/garden-attunement/spec.md (147 lines)
