@senad-d/drawme 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * DrawMe — a native Pi extension that turns natural-language descriptions into
3
3
  * `.drawio` diagrams and exports them to PNG/SVG/PDF/JPG via the draw.io desktop
4
- * CLI. It exposes the skill's workflow as plain commands + tools instead of a
5
- * skill, and does zero network I/O (see the audit note in the README).
4
+ * CLI. It exposes the authoring workflow as plain commands and model-callable
5
+ * tools.
6
6
  *
7
- * Tools: drawio_check · drawio_export · drawio_validate
7
+ * Tools: drawio_check · drawio_export · drawio_validate · drawio_from_mermaid
8
+ * drawio_layout · drawio_shapesearch · drawio_explain · drawio_open
8
9
  * Commands: /drawme · /drawme-check · /drawme-export
9
10
  */
10
11
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -28,6 +29,7 @@ import { drawmeWorkflow } from "./workflow";
28
29
 
29
30
  const HERE = dirname(fileURLToPath(import.meta.url));
30
31
  const REF_DIR = resolve(HERE, "..", "assets", "references");
32
+ const AGENT_REFERENCE_PATH = resolve(HERE, "..", "docs", "agent-guide.md");
31
33
 
32
34
  const FORMAT = Type.Union([Type.Literal("png"), Type.Literal("svg"), Type.Literal("pdf"), Type.Literal("jpg")]);
33
35
  const MODE = Type.Union([Type.Literal("preview"), Type.Literal("final")]);
@@ -80,14 +82,19 @@ export default function drawme(pi: ExtensionAPI): void {
80
82
  name: "drawio_export",
81
83
  label: "draw.io: export",
82
84
  description:
83
- "Export a .drawio file to PNG/SVG/PDF/JPG via the draw.io CLI. Use mode:'preview' for a clean, width-capped PNG to self-check with vision (never embedded), and mode:'final' for the deliverable (embedded editable output; the truncated -e PNG IEND chunk is auto-repaired). Runs entirely locally.",
84
- promptSnippet: "Export a .drawio to PNG/SVG/PDF/JPG (mode:'preview' for self-check, mode:'final' for the deliverable).",
85
+ "Export a .drawio file to PNG/SVG/PDF/JPG via the draw.io CLI. Use mode:'preview' for a clean, width-capped PNG to self-check with vision (never embedded), and mode:'final' for the deliverable (embedded editable output; the truncated -e PNG IEND chunk is auto-repaired). A successful final export automatically removes preview artifacts previously created for the same source.",
86
+ promptSnippet:
87
+ "Export a .drawio to PNG/SVG/PDF/JPG (mode:'preview' for self-check, mode:'final' for the deliverable and automatic preview cleanup).",
85
88
  parameters: exportParams,
86
89
  async execute(_id, params) {
87
90
  try {
88
91
  const r = await exportDiagram(params as ExportOptions);
89
92
  const lines = [`Exported ${r.output}`, `format=${r.format} mode=${r.mode} embed=${r.embed}`];
90
93
  if (r.repaired) lines.push("(repaired truncated -e PNG IEND chunk)");
94
+ if (r.removedPreviews.length > 0) lines.push(`Removed preview artifact(s): ${r.removedPreviews.join(", ")}`);
95
+ if (r.previewCleanupWarnings.length > 0) {
96
+ lines.push(`Preview cleanup warning(s): ${r.previewCleanupWarnings.join("; ")}`);
97
+ }
91
98
  const versionSuffix = r.version ? ` (${r.version})` : "";
92
99
  lines.push(`binary=${r.binary}${versionSuffix}`);
93
100
  return textResult(lines.join("\n"), r);
@@ -176,7 +183,7 @@ export default function drawme(pi: ExtensionAPI): void {
176
183
  name: "drawio_shapesearch",
177
184
  label: "draw.io: shape search",
178
185
  description:
179
- "Find the exact official draw.io style= string for a shape by keyword (e.g. 'aws lambda', 'uml actor', 'k8s pod'). Covers 10k+ AWS/Azure/GCP/Cisco/Kubernetes/UML/BPMN/network shapes. Use this instead of guessing a style= when a diagram needs a specific vendor or notation shape. Local index, no network.",
186
+ "Find the exact official draw.io style= string for a shape by keyword (e.g. 'aws lambda', 'uml actor', 'k8s pod'). Covers 10k+ AWS/Azure/GCP/Cisco/Kubernetes/UML/BPMN/network shapes from a bundled index. Use this instead of guessing a style= when a diagram needs a specific vendor or notation shape.",
180
187
  promptSnippet: "Look up the exact official style= string for a draw.io shape by keyword.",
181
188
  parameters: Type.Object({
182
189
  query: Type.String({ description: "Keywords, e.g. 'aws lambda' or 'uml actor'" }),
@@ -194,7 +201,7 @@ export default function drawme(pi: ExtensionAPI): void {
194
201
  name: "drawio_explain",
195
202
  label: "draw.io: explain",
196
203
  description:
197
- "Describe an existing .drawio as structured Markdown (components grouped by container, relations with edge-label verbs, per page). Useful for a README/PR summary or to read a diagram back before editing. Pure-local, no draw.io CLI needed.",
204
+ "Describe an existing .drawio as structured Markdown (components grouped by container, relations with edge-label verbs, per page). Useful for a README/PR summary or to read a diagram back before editing. No draw.io CLI needed.",
198
205
  promptSnippet: "Describe an existing .drawio as Markdown (components + relations).",
199
206
  parameters: Type.Object({ input: Type.String({ description: "Path to the .drawio file" }) }),
200
207
  async execute(_id, params) {
@@ -211,7 +218,7 @@ export default function drawme(pi: ExtensionAPI): void {
211
218
  name: "drawio_open",
212
219
  label: "draw.io: open",
213
220
  description:
214
- "Open a .drawio source or an exported file in the OS default application (draw.io desktop for .drawio) so the user can fine-tune it. Local action, no network.",
221
+ "Open a .drawio source or an exported file in the OS default application (draw.io desktop for .drawio) so the user can fine-tune it.",
215
222
  promptSnippet: "Open a .drawio or exported file in the desktop app.",
216
223
  parameters: Type.Object({ path: Type.String({ description: "File to open" }) }),
217
224
  async execute(_id, params) {
@@ -232,7 +239,7 @@ export default function drawme(pi: ExtensionAPI): void {
232
239
  ctx.ui.notify("Usage: /drawme <description of the diagram to create>", "info");
233
240
  return;
234
241
  }
235
- pi.sendUserMessage(drawmeWorkflow(desc, REF_DIR));
242
+ pi.sendUserMessage(drawmeWorkflow(desc, REF_DIR, AGENT_REFERENCE_PATH));
236
243
  },
237
244
  });
238
245
 
package/src/png.ts CHANGED
@@ -4,11 +4,10 @@
4
4
  * draw.io's CLI emits `-e` (embedded-XML) PNGs with the 4-byte IEND length
5
5
  * field present but the trailing 8 bytes of "IEND" type + CRC missing, so strict
6
6
  * PNG decoders and vision APIs reject the file (draw.io-desktop issue #8).
7
- * SVG/PDF are unaffected. Ported 1:1 from the skill's `scripts/repair_png.py`.
7
+ * SVG/PDF are unaffected.
8
8
  *
9
9
  * Idempotent: a no-op once the file already ends with a valid IEND chunk, so it
10
- * is safe to run unconditionally after every `-e` PNG export. Local-only, no
11
- * network.
10
+ * is safe to run unconditionally after every `-e` PNG export.
12
11
  */
13
12
  import { readFile, writeFile } from "node:fs/promises";
14
13
 
@@ -1,13 +1,11 @@
1
1
  /**
2
- * Search 10k+ official draw.io shapes for their exact `style=` strings — a
3
- * pure-TypeScript port of the skill's `scripts/shapesearch.py`, over the bundled
4
- * `assets/data/shape-index.json.gz` (upstream draw.io shape data; see the notice
5
- * beside it). Resolves a keyword query (e.g. "aws lambda", "uml actor") to the
6
- * real palette style so a diagram uses the official shape instead of a guess.
7
- * Local-only, no network.
2
+ * Search 10k+ official draw.io shapes for their exact `style=` strings using the
3
+ * bundled `assets/data/shape-index.json.gz` file (upstream draw.io shape data;
4
+ * see the notice beside it). Resolves a keyword query such as "aws lambda" or
5
+ * "uml actor" to the real palette style instead of a guess.
8
6
  *
9
- * Algorithm mirrors upstream (tag map with exact + Soundex matching, strict AND
10
- * first, scored OR fallback) plus the skill's verbatim-title tiebreaker.
7
+ * Uses a tag map with exact + Soundex matching, strict AND first, a scored OR
8
+ * fallback, and a verbatim-title tiebreaker.
11
9
  */
12
10
  import { readFileSync } from "node:fs";
13
11
  import { gunzipSync } from "node:zlib";
package/src/validate.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Deterministic structural linter for `.drawio` files — a pure-TypeScript port of
3
- * the skill's `scripts/validate.py`. Catches the class of mistakes a vision
2
+ * Deterministic structural linter for `.drawio` files. Catches mistakes a vision
4
3
  * self-check is slow and unreliable at: dangling edge endpoints, duplicate or
5
4
  * reserved ids, broken parent references, and (as warnings) off-grid geometry,
6
5
  * overlapping sibling nodes, and edge-routing defects. Runs without launching
7
- * draw.io. Local-only, no network.
6
+ * draw.io.
8
7
  */
9
8
  import { readFile } from "node:fs/promises";
10
9
  import { DOMParser } from "@xmldom/xmldom";
@@ -34,7 +33,7 @@ function pyFloat(s: string): number | undefined {
34
33
  return Number.isNaN(n) ? undefined : n;
35
34
  }
36
35
 
37
- /** Python `repr()` of an optional attribute, for message parity with validate.py. */
36
+ /** Quote an optional attribute consistently in diagnostic messages. */
38
37
  function repr(s: string | null): string {
39
38
  return s === null ? "None" : `'${s}'`;
40
39
  }
package/src/workflow.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Builds the message the `/drawme` command injects to drive the diagram
3
- * workflow. It steers the model through the skill's author→validate→preview→
4
- * self-check→final loop while pointing it at the DrawMe tools and the bundled,
5
- * network-free authoring references.
3
+ * workflow. It steers the model through the author→validate→preview→self-check→
4
+ * final loop while pointing it at the DrawMe tools and bundled references.
6
5
  */
7
- export function drawmeWorkflow(description: string, refDir: string): string {
6
+ export function drawmeWorkflow(description: string, refDir: string, agentReferencePath: string): string {
8
7
  const quoted = description.replaceAll("\n", "\n> ");
9
8
  return [
10
9
  "# DrawMe — create a diagram",
@@ -13,7 +12,11 @@ export function drawmeWorkflow(description: string, refDir: string): string {
13
12
  "",
14
13
  `> ${quoted}`,
15
14
  "",
16
- "Produce a `.drawio` file and export it, following the workflow below. For anything that touches the draw.io CLI, use the DrawMe tools (`drawio_check`, `drawio_validate`, `drawio_export`) — do NOT shell out to `drawio` yourself. Everything runs locally; there is no network access.",
15
+ "Before starting, read `" +
16
+ agentReferencePath +
17
+ "`, the official DrawMe extension reference for agent behavior, tool options, decision rules, and limitations.",
18
+ "",
19
+ "Produce a `.drawio` file and export it, following the workflow below. For anything that touches the draw.io CLI, use the DrawMe tools — do NOT shell out to `drawio` yourself.",
17
20
  "",
18
21
  "1. **Check** — call `drawio_check` once (note the version: v30+ unlocks Mermaid conversion and the auto-layout pass). If the CLI is unavailable, still author the `.drawio` XML, tell the user how to install draw.io / open the file, and skip the export + self-check steps.",
19
22
  "2. **Plan** — choose the diagram type, shapes, relationships, and layout direction (LR or TB). For a specific type (ERD, UML class, sequence, C4, architecture, ML/DL, flowchart, SysML, BPMN, network, swimlane), read `" +
@@ -29,6 +32,6 @@ export function drawmeWorkflow(description: string, refDir: string): string {
29
32
  refDir +
30
33
  "/troubleshooting.md`.",
31
34
  "6. **Review** — show the PNG to the user, apply targeted XML edits from their feedback, and re-preview until they approve.",
32
- "7. **Final export** — call `drawio_export` with `mode: \"final\"` for each requested format (default PNG; SVG/PDF/JPG on request). Report the `.drawio` source path and every exported file path, and offer to open the source in the desktop app with `drawio_open` for fine-tuning.",
35
+ "7. **Final export** — call `drawio_export` with `mode: \"final\"` for each requested format (default PNG; SVG/PDF/JPG on request). The first successful final export automatically removes preview artifacts created for the same source; do not delete them yourself or report them as retained outputs. Report the `.drawio` source path and every final exported file path, and offer to open the source in the desktop app with `drawio_open` for fine-tuning.",
33
36
  ].join("\n");
34
37
  }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2023"],
7
+ "types": ["node"],
8
+ "strict": true,
9
+ "noEmit": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "resolveJsonModule": true,
13
+ "verbatimModuleSyntax": true,
14
+ "forceConsistentCasingInFileNames": true
15
+ },
16
+ "include": ["src", "tests"]
17
+ }