diff --git a/Makefile b/Makefile index 453b046..7b083a2 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ -.PHONY: test lint typecheck doctor package-check ci clean +.PHONY: test test-statechart lint typecheck doctor package-check ci clean test: uv run pytest -v --timeout=60 tests/ cd skills/poteto-mode/scripts && bun test +test-statechart: + node --test skills/statechart/scripts/test/pipeline.test.ts skills/statechart/scripts/test/messages.test.ts skills/statechart/scripts/test/chart.test.ts skills/statechart/scripts/test/cli.test.ts + lint: uv run ruff check . bash -n scripts/package-plugin.sh skills/poteto-mode/scripts/worktree-audit.sh skills/show-me-your-work/scripts/log.sh diff --git a/README.md b/README.md index fa9c6fc..d84f089 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ Or trigger `/cloud-swarm` right in chat: | [`/ketchup`](./skills/ketchup/SKILL.md) | you want a status brief under 100 words on an autonomous run or background task, with artifact links and selectable picks. | | [`/create-verification-skill`](./skills/create-verification-skill/SKILL.md) | your project has no scripted way to prove app behavior. generates a project-local verify skill with a feature map, for any language or platform. | | [`/create-formal-verification-skill`](./skills/create-formal-verification-skill/SKILL.md) | you need formal model checking (TLA+, Alloy, Dafny) for high-consequence concurrency, consensus, complex state machines, or critical parsers. | +| [`/maintain-formal-verification-skill`](./skills/maintain-formal-verification-skill/SKILL.md) | your project's formal verification model or harness has drifted from the code. diffs covered commits, updates from code, and proves with a scratch break. | | [`/maintain-verification-skill`](./skills/maintain-verification-skill/SKILL.md) | your verify skill's feature map has drifted from the app. source wave + one live pass, at most one PR of proven corrections. | | [`/benchmark-checklist`](./skills/benchmark-checklist/SKILL.md) | you are reporting performance numbers or speedups and want to check them against the Seven Performance Verification Questions first. | | [`/unslop`](./skills/unslop/SKILL.md) | you're cleaning up writing. removes AI tells. | diff --git a/scripts/package-plugin.sh b/scripts/package-plugin.sh index ae9a2db..7750a0c 100755 --- a/scripts/package-plugin.sh +++ b/scripts/package-plugin.sh @@ -104,7 +104,9 @@ build_archive() { -x "*.venv*" \ -x "*node_modules*" \ -x "*.test.ts" \ - -x "*.test-helper.ts" + -x "*.test-helper.ts" \ + -x "*/scripts/test/*" \ + -x "*/scripts/test/" printf '%s\n' "${archive}" } @@ -124,17 +126,24 @@ required = [ "agystack-models.md", "agystack-runtime.json.example", "hooks.json.example", + "skills/statechart/scripts/statechart", + "skills/statechart/scripts/statechart.ts", + "skills/statechart/scripts/pipeline.ts", ] missing = [r for r in required if r not in names] if missing: raise SystemExit(f"Error: archive missing required files: {missing}") -forbidden = [ - n for n in names - if n.endswith(".test.ts") - or n.endswith(".test-helper.ts") - or "__pycache__" in n.split("/") - or "node_modules" in n.split("/") -] +def is_forbidden(name: str) -> bool: + parts = name.split("/") + return ( + name.endswith(".test.ts") + or name.endswith(".test-helper.ts") + or "__pycache__" in parts + or "node_modules" in parts + or any(parts[i : i + 2] == ["scripts", "test"] for i in range(len(parts) - 1)) + ) + +forbidden = [n for n in names if is_forbidden(n)] if forbidden: raise SystemExit(f"Error: archive contains forbidden entries: {forbidden[:10]}") ' "${archive}" diff --git a/skills/create-formal-verification-skill/SKILL.md b/skills/create-formal-verification-skill/SKILL.md index 34748a5..882bf17 100644 --- a/skills/create-formal-verification-skill/SKILL.md +++ b/skills/create-formal-verification-skill/SKILL.md @@ -1,41 +1,69 @@ --- name: create-formal-verification-skill -description: "Generate and apply formal specification models (TLA+, Alloy, Dafny, or state-machine model checkers) strictly for high-consequence concurrency, distributed consensus, complex state machines, and parsers." +description: "Generate a project-local skill that formally verifies the code where a bug costs the most and tests reach the least, in any language, with whichever verification tool fits. Use for /create-formal-verification-skill, \"model-check this race\", \"prove this invariant\", or when concurrency, retries, state machines, parsers, or unsafe code need more than tests." disable-model-invocation: true --- -# Create Formal Verification Skill +# Create a formal verification skill -Generate project-local formal verification specifications and model checkers for high-consequence algorithms. Formal methods verify invariants mathematically across entire state spaces. They carry high authoring and maintenance costs, so strict gating is mandatory. +A test checks the cases someone thought to write. Formal verification checks every case in a stated scope: every interleaving in a model, every input up to a bound, or every input. This skill finds the target in the repo where a bug costs the most, verifies its key invariant, and leaves a project-local skill that lets the next agent recheck changes cold, mid-task. -## Applicability Gating Criteria +## Choose the target from the code -Before authoring a formal specification or model checking harness, evaluate the target system against the gating criteria. +Answer from the codebase first, and ask the user only what you cannot observe. If the user named an area or bug, start there. -### Strictly Reserved Targets +Use this four-domain quick selector to gate formal methods against their maintenance cost: -Formal verification is strictly reserved for these high-consequence domains: -1. **Concurrency protocols:** Multi-threaded synchronization primitives, lockless data structures, and non-blocking algorithms where interleavings defy testing. -2. **Distributed consensus:** Raft, Paxos, leader election, quorum replication, and split-brain recovery protocols under network partitions. -3. **Complex state machines:** Multi-actor lifecycle transitions with concurrent events, timeout hazards, and asynchronous state resets. -4. **Critical parsers and serializers:** Untrusted input decoders, binary serialization boundaries, and cryptographic envelope validators where ambiguity introduces security vulnerabilities. +- **Concurrency protocols.** Synchronization primitives, lockless structures, and interleavings that tests miss. +- **Distributed consensus.** Leader election, quorum replication, split-brain recovery, and partition tolerance. +- **Complex state machines.** Multi-actor lifecycles with concurrent events, retries, timeouts, and asynchronous resets. +- **Critical parsers and serializers.** Untrusted input decoders, binary framing, and cryptographic envelope checks. -### Reject Non-Applicable Targets +If the target is routine CRUD endpoints, standard UI layouts and render loops, linear request handlers, or simple option parsers, reject formal verification and point to standard tests or [`/create-verification-skill`](../create-verification-skill/SKILL.md). For applicable work, pick the strongest promise whose violation harms users and defies unit tests, not the easiest module to model. -Immediately reject requests to formally verify non-applicable targets: -- Ordinary CRUD APIs and database mutation endpoints. -- Standard UI components, view layouts, styling systems, and render loops. -- Simple linear business logic and sequential request-response handlers. -- Routine configuration parsers, environment loaders, and CLI option parsing. +## Let the question choose the tool -When a target is non-applicable, reject formal verification immediately. Redirect to standard automated unit tests, integration harnesses, property-based testing, or verification skills (`/create-verification-skill`). +Pick the lowest-cost tool that answers the question: -## Authoring Process for Applicable Targets +- **Event ordering and concurrency.** Use a model checker over a faithful small model; TLA+ is the default in any language. +- **Input-level safety or data-structure invariants.** Use an SMT-backed verifier or prover that checks the real code (such as memory safety or overflow). If none exists for the language, test the real code with generated inputs instead of modeling a pure function by hand. +- **Unbounded size properties.** Use a proof assistant when no finite bound suffices. -When a target satisfies the gating criteria, proceed with model authoring: +Prefer a tool the repo's developers can install and run locally, and record why you chose it. -1. **Define state and actions.** Name state variables and state boundaries. Formulate explicit next-state relations. -2. **Specify safety invariants.** State properties that must never be violated (such as mutual exclusion or absence of deadlocks). -3. **Specify liveness properties.** State conditions that must eventually occur (such as request fulfillment or eventual consensus). -4. **Run model checker.** Model check finite state configurations to exhaustively search for counterexamples. -5. **Map counterexamples to code.** Translate any model checker counterexample directly into a reproducible unit test in the target codebase. +## What makes it good + +- **Code-to-model traceability and indivisible step fidelity.** Every state, action, and rule in the model points to code a reviewer can open. What the verification treats as one indivisible step must be one indivisible step in the code. Use the repo's real symbol and module names. +- **Able to fail.** A check that has never failed proves nothing. Prove every property catches a broken variant (such as a removed guard or reordered step). +- **Findings stay findings.** When current code breaks a property, report the counterexample in the code's terms. Never weaken the property or model to force a pass, and never edit product code unless the user asks. +- **Honest about scope.** State the verified bounds, assumptions, and exclusions explicitly. +- **Readable without the tool.** State each property and its harm in one plain sentence, and narrate counterexamples as short steps in the code's words. +- **Cheap to rerun.** One command, pinned or reproducible tool versions, and fast execution so agents rerun it on relevant edits. +- **Kept in step with the code.** Record the coverage map (files and functions covered) and the sync-commit SHA where verification last matched the code. + +## Generate the verify skill + +Write a project-local skill (such as `.agents/skills/verify-/SKILL.md`) with YAML frontmatter containing `name` and `description` so the skill registers. + +From that skill alone, the next agent must be able to see whether an edit touches covered code, run the check, distinguish a code bug from a modeling error, and update the verification when behavior intentionally changes. Include: + +- The **coverage map** (exact files, functions, bounds, and assumptions). +- The **sync-commit SHA** (`git rev-parse HEAD` once verified), with instructions to advance it only after confirming the verification still describes the code at the new commit. +- Real repo commands, paths, and identifiers with zero placeholders. + +If the check uses a TLA+ model, direct the next agent to read every run with [`/statechart`](../statechart/SKILL.md) by name. It extracts shortest counterexample paths on failures and draws the state graph on passes. Never hardcode `/statechart`'s internal script flags or paths into the generated skill, because releases evolve independently. + +## Prove it before you hand off + +Run the generated skill's instructions end to end as the next agent would against a temporary scratch change in the real code that breaks the property. Confirm the check catches the break, then revert the scratch change and confirm the check returns to baseline (passing, or failing only on the findings you are reporting). If the skill misses the break or fails to run, fix the skill or verification, not the scratch change. + +## Report and hand off + +Write the full verification report to the Antigravity Brain Artifact `/brain//formal_verification_report.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`). Record: + +- Verified properties and harms in plain sentences. +- Tool choice rationale, bounds, assumptions, and exclusions. +- Findings and counterexamples in the code's terms. +- Coverage map, sync-commit SHA, rerun command, and the scratch-break mutation receipt. + +In chat, summarize the result, name any close second target if you spotted one, link `[formal_verification_report.md](file:///brain//formal_verification_report.md)`, and point the user to [`/maintain-formal-verification-skill`](../maintain-formal-verification-skill/SKILL.md) for catching future code drift. diff --git a/skills/maintain-formal-verification-skill/SKILL.md b/skills/maintain-formal-verification-skill/SKILL.md new file mode 100644 index 0000000..169619d --- /dev/null +++ b/skills/maintain-formal-verification-skill/SKILL.md @@ -0,0 +1,60 @@ +--- +name: maintain-formal-verification-skill +description: "Bring a project's formal verification back in line with the code after the code changes: find the commits that touched verified code, update the model, harness, or properties to describe the code as it is now, rerun, and say whether each failure is drift in the verification or a bug in the code. Use for /maintain-formal-verification-skill, \"is the model still true to the code\", or after merges and refactors that touched verified code without rechecking it." +disable-model-invocation: true +--- + +# Maintain a formal verification skill + +A formal check proves a property of what it describes. When the code changes and the verification does not, the check can keep passing while describing code that no longer exists. That pass is dangerous because it looks like a proof. + +This skill is the upkeep loop for a project-local verify skill generated by [`/create-formal-verification-skill`](../create-formal-verification-skill/SKILL.md), or for any project-local skill that runs a model checker, prover, or code-level verifier against named code. The project-local skill handles a change made while using that skill. This skill handles changes that skipped it: merges, direct edits, and drift across many commits. + +## Outcomes + +Assign each check one outcome, and state it directly: + +- **in sync.** No change since the last sync alters what the check describes, and the check passes. +- **updated.** The code changed, the verification now describes the new code, and the check passes. +- **bug.** The verification describes the current code, and the code breaks the property. This is a code finding, not drift. +- **blocked.** The check could not be brought back in line or could not run. State why. + +A check can be both `updated` and `bug`: updating the verification makes it describe the current code again, and then the property fails on it. + +## Edit scope + +Edit only verification files: models, harnesses, property files, and the verify skill itself. Never edit product code during a run unless the user asks you to. When a property fails on the current code, do not weaken the property or the model to make it pass. Report the failure. + +## Pass + +1. **Find the checks.** A verify skill has no fixed name, so find each project-local skill (such as `.agents/skills/verify-*/SKILL.md`) that runs a model checker, prover, or verifier against named code. Read every check found, or the one the user named. Collect the property, the covered code, the bounds and assumptions, the run command, and the sync-commit SHA where the verification last matched the code. If no verify skill exists, stop and point to [`/create-formal-verification-skill`](../create-formal-verification-skill/SKILL.md). If the skill omits a sync commit, use the last commit that touched the verification files and record that fallback. + +2. **Run it as it is.** Run each check once before editing anything and record the result. A pass here proves only that the old description holds, not that the code holds. A failure here can be drift or a bug. Defer classification until step 5. + +3. **Read every change to covered code.** Diff the covered files from the sync commit to `HEAD`, and read every commit message. Inspect renamed, split, or relocated functions that came from covered code. Inspect new code that writes the same fields or enters the guarded state. Classify each change: + - **No effect.** Formatting, comments, or paths outside what the verification models. Verify this against the model or harness, not the commit message alone. + - **The verification no longer describes the code.** An indivisible step split into two, a branch changed, a guard moved, a new path reaches the guarded state, or a value's range changed. Update the model or harness. + - **The promise changed on purpose.** The change alters intended behavior, backed by doc comments, tests, changelog notes, or commit messages. Update the property and cite that evidence. + - **The promise may be broken.** Behavior changed without evidence of intent. Treat any resulting failure as a bug candidate. + +4. **Update from the code, not from the result.** Update the model or harness so every changed part maps back to code a reviewer can open, preserving indivisible-step fidelity so one indivisible step in code stays one step in verification. Write the update from the code before rerunning, and never shape the model around what makes the check pass. Change a property only when the promise changed on purpose, recording the old wording, new wording, and evidence. Keep existing bounds unless the code change invalidates them; if you must shrink a bound, explain why in the report. + +5. **Rerun and judge each result.** If the check is a TLA+ model, inspect every result with [`/statechart`](../statechart/SKILL.md). + - **Pass.** Prove the updated check can still fail. Introduce a temporary scratch break in the new code targeting what the property guards (such as removing a check or reordering a step), confirm the check catches it, and revert the scratch break. + - **Fail.** Replay the counterexample step by step against the real code. If a step is impossible in code, the verification has a modeling error; fix the verification and document what was wrong. If every step is reachable, report a bug: name the introducing commit, state the counterexample as steps in the code's terms, and state the harm in one sentence. Include a non-committed reproduction if one cheaply demonstrates the bug. + +6. **Update the verify skill.** Update the coverage map (files and functions), commands, bounds, assumptions, and sync-commit SHA to the checked commit. Do not advance the sync commit for a `blocked` check, and note why. Run the verify skill once end to end as the next agent would to confirm its instructions still execute cleanly. + +## Report + +Write the full maintenance report to the Antigravity Brain Artifact `/brain//formal_verification_report.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`). Include for each check: + +- The outcome and the list of commits reviewed. +- Each change made to the verification and why (code shape changed, or promise changed on purpose with cited evidence). +- The rerun result and the scratch-break mutation receipt showing the updated check still catches failures. +- Each code bug in plain words: counterexample steps in the code's terms, harm in one sentence, and introducing commit SHA. +- Remaining coverage gaps, including new code that touches guarded state but stays unverified. + +State explicitly which prior failures were verification drift and which were product bugs. If a check passed before your update and fails afterward, state that the earlier pass held only on a stale description. + +Keep verification updates in their own commit, separate from any product fix. In chat, summarize the outcomes and link `[formal_verification_report.md](file:///brain//formal_verification_report.md)` instead of pasting the full report. diff --git a/skills/statechart/SKILL.md b/skills/statechart/SKILL.md index 2ac4746..6b3fb32 100644 --- a/skills/statechart/SKILL.md +++ b/skills/statechart/SKILL.md @@ -1,44 +1,81 @@ --- name: statechart -description: Model system states and render native Mermaid state diagrams and failure paths. Use for /statechart or complex state modeling. +description: "Check a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and render it as a Mermaid stateDiagram-v2 chart, or create an explicitly labeled unverified design sketch. The report gives the shortest path to each state that breaks a rule. Use for /statechart, or to show a bug as a path through states." +disable-model-invocation: true --- # Statechart -Model system states, transitions, invariants, and failure modes using native Mermaid state diagrams. Use for complex lifecycle flows, state synchronization, distributed race analysis, or when validating stateful protocol behavior. +The chart shows how a system moves between states in the reader's words, so the reader can judge whether the behavior is right. -## Core Modeling Invariants +Choose one of two explicit modes before starting: -1. **Enumerate Explicit States.** Distinguish legitimate reachable states from illegitimate or zombie states. -2. **State Invariants.** For each state, define the assertions that must hold true while the system remains in that state. -3. **Transitions and Triggers.** Identify explicit events, timeouts, and inputs that trigger transitions between states. -4. **Identify Failure and Crash Paths.** Model crashes, aborts, and retries at every transition boundary. -5. **Find Shortest Failure Path.** Analyze the shortest sequence of events leading from the initial state to an invalid or unhandled failure state. +- **Mode 1 (Verified TLC model).** Use whenever checking a real protocol, concurrency flow, or code model. Run `scripts/statechart` over `.tla` and `.cfg` files, then embed the checked `chart.mmd` (`stateDiagram-v2`) and `report.md` into an Antigravity Brain Artifact. +- **Mode 2 (Unverified design sketch).** Use only when sketching an early idea before writing a spec. Write native Mermaid `stateDiagram-v2` (or `flowchart TD`) directly into the Brain Artifact, and label the artifact heading and body explicitly as an **Unverified Design Sketch**. Never present a Mode 2 sketch as checked or verified. -## Native Mermaid State Diagram Artifacts +## Mode 1. Verified TLC model -Render models directly as native Mermaid `stateDiagram-v2` or `flowchart TD` blocks within Brain Artifacts (`/brain//statechart_.md`). Avoid external compilers or heavyweight Java/TLC tooling. +### Run the compiler -### Example Schema +Work in a scratch folder outside the repo, such as `/brain//scratch/` or a temporary directory. Write a TLA+ spec and its config, then run: -````markdown -```mermaid -stateDiagram-v2 - [*] --> Idle - Idle --> InFlight : dispatch - InFlight --> Verifying : report_received - InFlight --> Stalled : timeout / no_signal - Verifying --> Merged : clean_verdict - Verifying --> FixForward : defect_proven - FixForward --> InFlight : patch_rebased - Stalled --> Terminated : watchdog_kill - Terminated --> [*] - Merged --> [*] +```sh +/scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR] ``` -```` -## Verification Checklist +`scripts/statechart.ts` is TypeScript. `scripts/statechart` is a POSIX launcher that selects Node 22.18 to 22.x, Node 23.6+, Bun 1.1.5+, or Deno 2.0+. On native Windows, run `node --disable-warning=ExperimentalWarning /scripts/statechart.ts` with a supported Node version. -- Are all error transitions terminal or explicitly handled by reconciliation? -- Is there any transition where an illegitimate state can reach steady state? -- Does the shortest failure path have an automated test reproducing it? +The first run installs TLC and Java via `mise` and requires network access. + +### Write the spec + +- Write every rule the reader agrees to as an `INVARIANT` (or `PROPERTY`). Add state variables if a rule needs information not yet modeled. Never weaken a rule to make it hold. +- Write `Next` as a disjunction of named actions, such as `YouPressPlay \/ YouPressStop`, so TLC labels steps instead of naming every step `Next`. +- A terminal state with no step out fails `NoDeadlock`. When an `INVARIANT` or `PROPERTY` already uses the name `NoDeadlock`, the deadlock check is named `CHECK_DEADLOCK`. Add a self-loop action in `Next` for valid end states, such as `Done == phase \in {"paid", "failed"} /\ UNCHANGED vars`, and label it in `step()`. + +### Pick the chart (`--view`) + +Put reader-facing phrasing, phase grouping, colors, and chart title in a `--view` module: + +- `state(vars)` controls chart shape. Return a string for a flat chart (`export const state = (v) => (v.paid ? "Paid" : "Paying");`), an array for nested parent states (`export const state = (v) => v.main.split(".");`), or a plain object for parallel regions (`export const state = (v) => ({ Playback: v.playback, Volume: v.volume });`). Keep variable names out of labels. In `vars`, TLA+ sequences are objects indexed from `1` (`v.pc[1]`), and sets are arrays. +- `step(action, from, to)` returns an arrow label in the reader's words (for example `"you press play"` or `"the connect fails"`), hiding code and TLA+ action names. Matching labels merge into one arrow. End conditional steps with bracketed conditions (`"you press play [while the file loads]"`), except in regions charts where the compiler already annotates other-region conditions. +- `group(vars)` returns a phase name mapped by `colors` (`blue`, `orange`, `purple`, `yellow`, `teal`, `tan`, or `pink`). Mixed groups behind one chart state leave it uncolored. +- `title` sets the Mermaid chart title string. + +Keep `state()`, `group()`, and `step()` pure functions of their arguments because the compiler caches answers once per state or step. Steps staying inside one chart label are not drawn; split the label if that self-step matters. + +Aim for about 20 arrows or fewer. Merge equivalent labels first, while preserving every bug-path state and never merging states that break different rules. If the chart stays too busy, return `null` from `step()` to hide noisy steps while obeying four constraints: keep every chart state reachable from a start state, keep at least one outgoing arrow for states that can step, hide all or none of an arrow's steps, and list hidden steps in the handoff. + +### Read the report + +- States breaking a rule get class `breaks` (all underlying model states break it) or `mayBreak` (some break it), shown in the Legend. In regions charts, a region state gets marked when every combination with it can break a rule, or when a combination breaks a rule and none of its states is marked yet. +- TLC explores past invariant-breaking states unless bounded by small constants, `CONSTRAINT`, or `ACTION_CONSTRAINT`. Past a constraint, TLC checks rules in the immediate next state without exploring further or checking deadlock there. +- With `VIEW` or `SYMMETRY`, TLC collapses equivalent states onto representatives, so arrows can point to a representative state instead of the concrete successor. `report.md` notes this. +- The compiler checks all rules with one worker, then iteratively removes each failing invariant and reruns (capped at 100,000 distinct states after the first break) to uncover further breaks. Rules omitted when a run hits that cap or errors appear under `Rules not checked`. +- `tlc.out` captures TLC's output on the original config, and `tlc-RULE.out` holds traces for broken properties or bugs outside the chart. Running Java with `-XX:+UseParallelGC` avoids a duplicate startup warning line. + +### Embed in Brain Artifacts + +The compiler draws full charts up to a 500-state budget (measured on the config as written). Above 500 states, `chart.mmd` draws only bug paths, or is omitted when no rules break while `report.md` still records the state count and verdicts. + +Write `/brain//statechart_.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`), embedding: + +1. Header stating **Verified TLC Model** with spec name, bounds, and rerun command. +2. The generated `chart.mmd` inside a `mermaid` fenced block (`stateDiagram-v2`) so Antigravity's native Mermaid renderer displays it directly. +3. The verdict summary and shortest counterexample paths from `report.md`. + +For optional standalone SVG export (when the user requests an SVG image or a large chart is hard to inspect inline), follow [`references/render.md`](references/render.md). + +### Hand off + +Link `[statechart_.md](file:///brain//statechart_.md)` in chat. For each bug, include one line naming the rule, the reader-facing sentence for that rule, and the numbered counterexample path from `report.md`. State what the model leaves out, and include the rerun command with a fresh `--out` directory. + +When the model represents real code, replay every counterexample path against the real code as an automated test or live reproduction, one step per action. If a step cannot happen in code, assume the model drifted until proven otherwise. + +## Mode 2. Unverified design sketch + +When exploring an unverified design flow before writing a TLA+ spec, write `/brain//statechart_.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`) using native Mermaid `stateDiagram-v2` (or `flowchart TD`): + +1. Mark the artifact title and top banner explicitly as **Unverified Design Sketch (Not TLC-Checked)**. +2. Enumerate explicit states, legitimate and invalid transitions, triggers, timeouts, and failure or crash recovery paths. +3. Include a checklist noting error handling, illegitimate-to-steady-state reachability, and candidate tests or TLA+ invariants for promoting the sketch to Mode 1. diff --git a/skills/statechart/references/render.md b/skills/statechart/references/render.md new file mode 100644 index 0000000..bc71a57 --- /dev/null +++ b/skills/statechart/references/render.md @@ -0,0 +1,95 @@ +# Export a standalone SVG + +Antigravity renders `stateDiagram-v2` blocks natively inside `/brain//statechart_.md`. Use this workflow only when the user asks for a standalone SVG file or a large chart is easier to inspect outside inline text. + +Render each `.mmd` file with the npm package `pele@1.9.0`. Install Pele once, outside the repo. Write each SVG next to its `.mmd` file with the same stem, then copy any SVG you want to embed into `/brain//` before referencing it in an Antigravity artifact. The API is documented at https://pele.run/api. Pass `{ limit: 1_000_000, outputLimit: 8_000_000, maxEdges: 10_000 }` to `render`, because Pele's defaults are smaller than a 500-state chart can grow. When Pele throws a `PeleError`, surface the Mermaid text and the error. + +## Colors + +Pele ignores Mermaid `theme` and `themeVariables`. Set its `--pele-*` CSS variables on `.pele` (documented at https://pele.run/theming). `scripts/statechart` assigns each state its group color class (`class sN teal`) and bug marks (`class sN breaks`, `class sN mayBreak`, `class sN bugPath`, and `class sN repeats`). + +`chart.mmd` includes `classDef` rules for `breaks` and `mayBreak` so standard Mermaid viewers show bug marks natively, while group colors, `bugPath`, and `repeats` have no `classDef`. Because Pele writes `classDef` rules as inline `style` attributes that override normal CSS, the mark rules below use `!important` so dark themes stay readable. Put mark rules after group colors so bug marks take precedence. + +Prepend this `