Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions harness/pstack/claude-code/skills/statechart/scripts/lib.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pstack/skills/statechart/scripts/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,16 @@ export function parseMermaid(text) {
implicit.set(id, part());
};
const body = text.replace(/^\s*---[ \t]*\r?\n[^]*?\r?\n---[ \t]*(\r?\n|$)/, "");
let inNote = false;
for (const raw of body.split("\n")) {
if (inNote) {
inNote = !/^\s*end\s+note\s*$/.test(raw);
continue;
}
if (/^\s*note\s[^:]*$/.test(raw)) {
inNote = true;
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoted notes open a block

Medium Severity · Logic Bug

The block detector treats every colon-free note line as a multi-line opener. Mermaid's one-line floating notes use quotes and as rather than a colon, so the parser keeps skipping later chart lines until end note or end of file. Those lines were previously ignored as single-line notes.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6f45cd1. Configure here.

}
const line = raw.trim().replace(/(\[\*\]|[A-Za-z_]\w*):::[\w-]+/g, "$1");
const when = /^%%\s*when\s+(not\s+)?(.+)$/.exec(line);
if (when) {
Expand Down Expand Up @@ -644,6 +653,7 @@ export function parseMermaid(text) {
}
throw new Error(`cannot read chart line: ${line}`);
}
if (inNote) throw new Error("the chart has a note with no end note");
if (stack.length !== 1) throw new Error("the chart has an unclosed {");
if (root.parts.length > 1)
throw new Error(
Expand Down
17 changes: 17 additions & 0 deletions pstack/skills/statechart/scripts/test/statechart.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,23 @@ FromBase == Base!Safe
);
});

test("a multi-line note is not part of the machine", () => {
const { regions } = parseMermaid(`stateDiagram-v2
[*] --> A
note right of A
Waits for the user.
A --> C : not a step
end note
A --> B : go
note left of B : done`);
assert.deepEqual([...regions.Main.states].sort(), ["A", "B"]);
assert.deepEqual(edges(regions.Main), ["A -> B : go"]);
assert.throws(
() => parseMermaid("stateDiagram-v2\n [*] --> A\n note right of A\n A --> B : go"),
/note with no end note/,
);
});

test("the legend is not part of the machine", () => {
const { regions } = parseMermaid(`stateDiagram-v2
state "Legend" as legend {
Expand Down
Loading