backnotprop/pstack / skills/statechart
statechart
VerifiedCheck a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and draw it as a Mermaid statechart. 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.
scripts/passes/paths.ts
View on GitHubimport {
type Bug,
type Graph,
hasRule,
type Lasso,
must,
type PathStep,
type Rule,
stateKey,
type Step,
type Trace,
type TraceState,
type Vars,
} from "../ir.ts";
export function pathGraph(names: string[]) {
const graph: Graph = { states: new Map(), steps: [] };
const ids = new Map<string, string>();
const taken = new Map<string, Step>();
const idOf = (vars: Vars | undefined, start: boolean) => {
if (!vars) throw new Error("TLC's trace has a state with no values.");
const k = stateKey(names.map((name) => vars[name]));
let id = ids.get(k);
if (id === undefined) {
ids.set(k, (id = String(ids.size)));
graph.states.set(id, { vars, start, breaks: [] });
} else if (start) must(graph.states, id).start = true;
return id;
};
const route = (seq: { action: string; vars: Vars | undefined }[]) => {
const start = idOf(seq[0].vars, true);
const path: PathStep[] = [];
let from = start;
for (let i = 1; i < seq.length; i++) {
const { action } = seq[i];
const to = idOf(seq[i].vars, false);
const k = `${from} ${to} ${action}`;
let step = taken.get(k);
if (!step) {
taken.set(k, (step = { from, to, action }));
graph.steps.push(step);
}
path.push({ action, state: to, step });
from = to;
}
return { start, path };
};
return {
graph,
bug: (rule: Rule, trace: TraceState[]): Bug => {
if (!trace.length) throw new Error(`TLC's trace for ${rule.name} has no states.`);
const bug = { rule, ...route(trace) };
const end = must(graph.states, bug.path.at(-1)?.state ?? bug.start);
if (!hasRule(end.breaks, rule)) end.breaks.push(rule);
return bug;
},
lasso: ({ seq, loop }: Trace): Lasso | undefined =>
seq.length ? { ...route(seq), loop, stutters: loop === seq.length - 1 } : undefined,
};
}
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: 196k | 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: 192k | 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: 192k | 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: 192k | Updated | Claude CodeCodex | Verified | Install |