Skip to content

stark-ai-de/agent-skills / plugins/stark-ai-developer/skills/drawio-diagrams

drawio-diagrams

Verified

Create, edit, review, or export editable draw.io diagrams. Use when the user needs .drawio architecture, flow, sequence, network, or other technical diagrams; not data plots or artistic images.

FileKindSize
SKILL.mdskill md13.6 KB
agents/openai.yamlconfig1.3 KB
assets/openai-icon.pngbinary56.4 KB
references/delivery.mdmarkdown11.5 KB
references/design-profiles.mdmarkdown13.6 KB
references/diagram-type-playbook.mdmarkdown12.1 KB
references/examples/animation-invalid.drawioother1.3 KB
references/examples/animation-off.drawioother1.3 KB
references/examples/animation-on.drawioother1.4 KB
references/examples/animation-static-dependency.drawioother1.3 KB
references/examples/architecture-icons.drawioother6.7 KB
references/examples/compressed-page-before.drawioother1.1 KB
references/examples/crowded-routing-before.drawioother6.3 KB
references/examples/example-broken.drawioother861 B
references/examples/example-clean.drawioother2.0 KB
references/examples/example-comment-broken.drawioother311 B
references/examples/example-contrast-broken.drawioother1.3 KB
references/examples/example-doctype-broken.drawioother301 B
references/examples/example-processing-instruction-broken.drawioother308 B
references/examples/existing-edit-after.drawioother2.6 KB
references/examples/existing-edit-before.drawioother1.9 KB
references/examples/icon-catalog-smoke.drawioother4.2 KB
references/examples/multi-page.drawioother3.4 KB
references/icon-catalog.mdmarkdown26.0 KB
references/layout-readability.mdmarkdown6.6 KB
references/routing-and-simplification.mdmarkdown6.9 KB
references/theming-dark-mode.mdmarkdown7.0 KB
references/toolset-setup.mdmarkdown10.3 KB
references/verification-checklist.mdmarkdown10.1 KB
references/workflow-details.mdmarkdown14.9 KB
references/xml-authoring.mdmarkdown9.3 KB
scripts/lib/transactional-render-output.mjsscript20.2 KB
scripts/open-drawio-url.mjsscript3.0 KB
scripts/preflight-drawio-xml.mjsscript2.1 KB
scripts/probe-drawio-toolset.mjsexecutablescript24.7 KB
scripts/rasterize-themed-svg.mjsscript20.3 KB
scripts/render-drawio.mjsexecutablescript47.6 KB
scripts/search-shapes.mjsexecutablescript7.0 KB
scripts/validate-drawio-diagram-rules.mjsscript35.8 KB
scripts/validate_drawio.pyexecutablescript80.3 KB

scripts/search-shapes.mjs

View on GitHub
#!/usr/bin/env node
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import zlib from "node:zlib";

function usage() {
  return [
    "Usage: node scripts/search-shapes.mjs <keywords...> [--type vertex|edge] [--limit N] [--index PATH] [--json]",
    'Example: node scripts/search-shapes.mjs "postgres database" --type vertex --limit 5 --json',
  ].join("\n");
}

function takeValue(argv, index, option) {
  const value = argv[index + 1];
  if (!value || value.startsWith("--")) throw new Error(`${option} requires a value`);
  return value;
}

function parseArgs(argv) {
  const args = { terms: [], type: null, limit: 10, index: null, json: false };
  for (let i = 0; i < argv.length; i += 1) {
    const token = argv[i];
    if (token === "--help" || token === "-h") {
      args.help = true;
    } else if (token === "--type") {
      args.type = takeValue(argv, i, token);
      i += 1;
    } else if (token === "--limit") {
      args.limit = Number.parseInt(takeValue(argv, i, token), 10);
      i += 1;
    } else if (token === "--index") {
      args.index = path.resolve(takeValue(argv, i, token));
      i += 1;
    } else if (token === "--json") {
      args.json = true;
    } else if (token.startsWith("--")) {
      throw new Error(`Unknown option: ${token}`);
    } else {
      args.terms.push(token);
    }
  }
  if (args.type && !["vertex", "edge"].includes(args.type)) {
    throw new Error("--type must be vertex or edge");
  }
  if (!Number.isInteger(args.limit) || args.limit < 1 || args.limit > 100) {
    throw new Error("--limit must be an integer from 1 to 100");
  }
  return args;
}

function isFile(file) {
  try {
    return fs.statSync(file).isFile();
  } catch {
    return false;
  }
}

function resolveIndex(explicitIndex) {
  const configured = explicitIndex || process.env.DRAWIO_SHAPE_INDEX;
  if (configured) {
    const resolved = path.resolve(configured);
    if (!isFile(resolved)) throw new Error(`Shape index not found: ${resolved}`);
    return resolved;
  }

  const cacheRoot = path.join(os.homedir(), ".cache", "drawio-diagrams");
  const candidates = [
    path.join(cacheRoot, "search-index.json"),
    path.join(cacheRoot, "search-index.json.gz"),
  ];
  const found = candidates.find(isFile);
  if (found) return found;

  throw new Error(
    "Shape index not configured. Pass --index, set DRAWIO_SHAPE_INDEX, or place search-index.json(.gz) in ~/.cache/drawio-diagrams. Download or create an index only after approval.",
  );
}

function loadIndex(indexPath) {
  const raw = fs.readFileSync(indexPath);
  const json = indexPath.endsWith(".gz")
    ? zlib.gunzipSync(raw).toString("utf8")
    : raw.toString("utf8");
  const data = JSON.parse(json);
  if (!Array.isArray(data)) throw new Error("Shape index must be a JSON array");
  return data;
}

function itemTitle(item) {
  return String(item.title || item.name || item.label || "");
}

function itemTags(item) {
  return Array.isArray(item.tags) ? item.tags.join(" ") : String(item.tags || "");
}

function itemStyle(item) {
  return String(item.style || item.mystyle || item.mxStyle || "");
}

function tokenize(value) {
  const expanded = String(value)
    .replace(/([a-z])([A-Z])/g, "$1 $2")
    .replace(/([A-Za-z])(\d)/g, "$1 $2")
    .replace(/(\d)([A-Za-z])/g, "$1 $2");
  return (expanded.match(/[A-Za-z0-9]+/g) || [])
    .map((token) => token.toLowerCase())
    .filter((token) => token.length >= 2);
}

function queryTerms(values) {
  return [...new Set(values.flatMap(tokenize))];
}

const SOUNDEX_CODES = "01230120022455012603010202";

function soundexDigit(letter) {
  const index = letter.charCodeAt(0) - 97;
  if (index < 0 || index > 25) return "";
  const digit = SOUNDEX_CODES[index];
  return digit === "0" ? "" : digit;
}

function soundex(value) {
  const letters = String(value)
    .toLowerCase()
    .replace(/[^a-z]/g, "");
  if (!letters) return "";
  let result = letters[0].toUpperCase();
  let previous = "";
  for (const letter of letters.slice(1)) {
    const digit = soundexDigit(letter);
    if (digit && digit !== previous) result += digit;
    if (digit) previous = digit;
    if (result.length === 4) break;
  }
  return result.padEnd(4, "0");
}

function tagTokens(item) {
  return [
    ...new Set(
      itemTags(item)
        .toLowerCase()
        .replace(/[/,()]/g, " ")
        .split(/\s+/)
        .filter((token) => token.length >= 2),
    ),
  ];
}

function phoneticToken(value) {
  return soundex(value.replace(/\.*\d*$/, ""));
}

function termScore(term, tags) {
  if (tags.includes(term)) return 1;
  const phonetic = phoneticToken(term);
  if (phonetic && tags.some((tag) => phoneticToken(tag) === phonetic)) return 0.5;
  return 0;
}

function rankItem(item, terms, index) {
  const title = itemTitle(item);
  const tags = tagTokens(item);
  const scores = terms.map((term) => termScore(term, tags));
  const titleTokens = new Set(
    title
      .toLowerCase()
      .split(/[^a-z0-9]+/)
      .filter(Boolean),
  );
  return {
    item,
    index,
    matchedTerms: scores.filter((score) => score > 0).length,
    score: scores.reduce((sum, score) => sum + score, 0),
    titleHits: terms.filter((term) => titleTokens.has(term)).length,
  };
}

function resultFor(item) {
  return {
    title: itemTitle(item),
    style: itemStyle(item),
    w: item.w ?? null,
    h: item.h ?? null,
    type: item.type || null,
  };
}

function main() {
  try {
    const args = parseArgs(process.argv.slice(2));
    if (args.help) {
      console.log(usage());
      return;
    }
    const terms = queryTerms(args.terms);
    if (terms.length === 0) throw new Error("Provide at least one keyword");

    const data = loadIndex(resolveIndex(args.index));
    const ranked = data
      .filter((item) => !args.type || item.type === args.type)
      .map((item, index) => rankItem(item, terms, index))
      .filter((entry) => entry.matchedTerms > 0);
    const strict = ranked.filter((entry) => entry.matchedTerms === terms.length);
    const pool = strict.length > 0 ? strict : ranked;
    const fallback = strict.length === 0 && pool.length > 0;

    const matches = pool
      .sort(
        (a, b) =>
          b.score - a.score ||
          b.titleHits - a.titleHits ||
          itemTitle(a.item).localeCompare(itemTitle(b.item)) ||
          a.index - b.index,
      )
      .slice(0, args.limit)
      .map(({ item }) => resultFor(item));

    if (matches.length === 0) {
      console.error(`No shapes matched: ${terms.join(" ")}`);
      process.exitCode = 1;
      return;
    }
    if (fallback) {
      console.error("No shape matched every term; showing ranked partial matches.");
    }

    if (args.json) {
      console.log(JSON.stringify(matches, null, 2));
      return;
    }
    for (const item of matches) {
      const dimensions = item.w && item.h ? `${item.w}x${item.h}` : "unsized";
      console.log(`${item.title || "(untitled shape)"} [${item.type || "unknown"}] ${dimensions}`);
      console.log(`  style: ${item.style}`);
    }
  } catch (error) {
    console.error(error.message);
    console.error(usage());
    process.exit(2);
  }
}

main();
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall