mex-memory/mex / skills/mex-statechart
mex-statechart
VerifiedExplain complicated existing behavior using checked state diagrams. Use when asked for a state diagram, to diagram the previous explanation, show a bug or recovery path, compare a proposed fix or existing TLA+ spec, or derive a model from an agreed chart. Generates native Mermaid and a readable terminal fallback; optionally view and explicitly save in MEX Hub.
upstream/scripts/property-loop.mjs
View on GitHubimport fs from "node:fs";
import { joinAnd, parseDot, parseState, stateKey } from "./lib.mjs";
import { mapView } from "./map-view.mjs";
const TEMPORAL_BREAK = "Error: Temporal properties were violated.";
function lasso(tlcOutput) {
const start = tlcOutput.lastIndexOf(TEMPORAL_BREAK);
if (start < 0) return null;
const lines = tlcOutput.slice(start).split("\n");
const states = [];
for (let i = 0; i < lines.length; i++) {
const back = /^Back to state (\d+): /.exec(lines[i]);
if (back) return { loop: states.slice(Number(back[1]) - 1), stutters: false };
const head = /^State \d+: (<|Stuttering)/.exec(lines[i]);
if (!head) continue;
if (head[1] === "Stuttering") return { loop: states.slice(-1), stutters: true };
const body = [];
while (i + 1 < lines.length && lines[i + 1].trim() !== "") body.push(lines[++i]);
states.push(parseState(body.join("\n")));
}
return null;
}
const collapseRepeatsAroundLoop = (names) => {
const runs = names.filter((name, i) => name !== names[i - 1]);
return runs.length > 1 && runs.at(-1) === runs[0] ? runs.slice(0, -1) : runs;
};
export function repeatsIn(tlcOutput, nameOf) {
const found = lasso(tlcOutput);
return (
found && { states: collapseRepeatsAroundLoop(found.loop.map(nameOf)), stutters: found.stutters }
);
}
function enabledByState({ nodes, edges, loops }) {
const byId = new Map([...nodes.keys()].map((id) => [id, new Set()]));
for (const e of [...edges, ...loops]) byId.get(e.from).add(e.action);
return new Map([...nodes.values()].map((n) => [stateKey(n.vars), byId.get(n.id)]));
}
export function readerStateNamer(mapping, dotFile) {
const readerActions = new Set(mapping.readerActions ?? []);
let enabledAt;
return (vars) => {
enabledAt ??= enabledByState(parseDot(fs.readFileSync(dotFile, "utf8")));
const enabled = enabledAt.get(stateKey(vars)) ?? new Set();
const settled = [...enabled].every((a) => readerActions.has(a));
return String(mapping.state(mapView(vars), { enabled, settled }));
};
}
export function loopSentence(repeats) {
if (!repeats) return null;
const quoted = repeats.states.map((name) => `"${name}"`);
if (repeats.stutters) return `The run stops in ${quoted[0]} forever.`;
if (quoted.length === 1) return `The run stays in ${quoted[0]} forever.`;
return `The run loops through ${joinAnd(quoted)} forever.`;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |