CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

statelyai/stately

Find implicit state machines, review state bugs, and check or visualize statecharts with Stately.

Quality

95%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Medium

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

check-view.mjsscripts/

// Generated by scripts/sync-stately-check-view.mjs; edit packages/api-contract/src/check-view.ts.
function record(value) {
    return value !== null && typeof value === 'object' && !Array.isArray(value);
}
function normalizeSchemas(data) {
    if (data.schemas == null || record(data.schemas)) {
        const schemas = {
            context: null,
            input: null,
            output: null,
            events: {},
            ...(record(data.schemas) ? data.schemas : {}),
        };
        const meta = record(data.schemaMeta) ? data.schemaMeta : {};
        const eventMeta = record(meta.events) ? meta.events : {};
        if (record(schemas.events)) {
            for (const [name, schema] of Object.entries(schemas.events)) {
                const provenance = eventMeta[name];
                if (record(provenance) &&
                    provenance.origin === 'auto' &&
                    Object.keys(provenance).length === 1 &&
                    record(schema) &&
                    Object.keys(schema).length === 3 &&
                    schema.type === 'object' &&
                    record(schema.properties) &&
                    !Object.keys(schema.properties).length &&
                    Array.isArray(schema.required) &&
                    !schema.required.length) {
                    delete schemas.events[name];
                    delete eventMeta[name];
                }
            }
        }
        if (record(meta.events) && !Object.keys(meta.events).length)
            delete meta.events;
        if (record(data.schemaMeta) && !Object.keys(meta).length)
            delete data.schemaMeta;
        data.schemas = Object.entries(schemas).every(([key, value]) => key === 'events'
            ? record(value) && !Object.keys(value).length
            : ['context', 'input', 'output'].includes(key) && value == null)
            ? null
            : schemas;
    }
    if (data.schemaMeta == null)
        delete data.schemaMeta;
}
export function canonicalCheckView(graph) {
    const dataWithout = (value, excluded) => {
        const data = structuredClone(record(value) ? value : {});
        for (const key of ['layout', 'style', 'color'])
            delete data[key];
        for (const key of excluded)
            delete data[key];
        if (data.meta == null)
            delete data.meta;
        if (record(data.meta)) {
            delete data.meta['@statelyai.evidence'];
            delete data.meta['@statelyai.checkResult'];
            delete data.meta['@statelyai.checkReport'];
            delete data.meta['@statelyai.checkViewSha256'];
            if (!Object.keys(data.meta).length)
                delete data.meta;
        }
        return data;
    };
    const root = graph.nodes.find((node) => node.parentId == null);
    const graphData = dataWithout(graph.data, [
        'statelyMcpModel',
        'statelyMcpProposal',
        'statelyMcpBehaviorRecord',
        'statelyMcpCapture',
        'statelyMcpCaptureArchive',
    ]);
    const implementations = record(graphData.implementations)
        ? graphData.implementations
        : {};
    if (graphData.implementations == null || record(graphData.implementations)) {
        const normalizedImplementations = {
            ...implementations,
        };
        for (const name of ['actions', 'actors', 'delays', 'guards', 'tags'])
            normalizedImplementations[name] ??= [];
        graphData.implementations = normalizedImplementations;
    }
    normalizeSchemas(graphData);
    const view = {
        id: graph.id,
        type: graph.type ?? 'directed',
        parentId: graph.parentId ?? null,
        initialNodeId: graph.initialNodeId ?? root?.id ?? null,
        data: graphData,
        nodes: graph.nodes.map((node) => {
            const data = dataWithout(node.data, []);
            return {
                id: node.id,
                parentId: node.parentId ?? null,
                data: {
                    ...data,
                    nodeId: data.nodeId ?? node.id,
                    type: data.type ??
                        (graph.nodes.some((child) => child.parentId === node.id)
                            ? 'compound'
                            : 'atomic'),
                    initialId: data.initialId ?? null,
                    history: data.history ?? false,
                    entry: data.entry ?? [],
                    exit: data.exit ?? [],
                    invokes: data.invokes ?? [],
                    tags: data.tags ?? [],
                    description: data.description ?? null,
                },
            };
        }),
        edges: graph.edges.map((edge) => {
            const data = dataWithout(edge.data, []);
            return {
                id: edge.id,
                sourceId: edge.sourceId,
                targetId: edge.targetId,
                data: {
                    ...data,
                    guard: data.guard ?? null,
                    actions: data.actions ?? [],
                    transitionType: data.transitionType ?? 'normal',
                    description: data.description ?? null,
                },
            };
        }),
    };
    const stable = (value) => Array.isArray(value)
        ? value.map(stable)
        : record(value)
            ? Object.fromEntries(Object.entries(value)
                .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
                .map(([key, item]) => [key, stable(item)]))
            : value;
    view.nodes.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
    view.edges.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
    return stable(view);
}
export function serializeCheckView(graph) {
    return JSON.stringify(canonicalCheckView(graph));
}

.mcp.json

LICENSE

README.md

SKILL.md

tile.json