@diagent/cli 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -127,13 +127,12 @@ tool that isn't in training data. To teach every Claude Code session
127
127
  across every project about this CLI, install the bundled Skill:
128
128
 
129
129
  ```bash
130
- mkdir -p ~/.claude/skills/diagent
131
- curl -o ~/.claude/skills/diagent/SKILL.md \
132
- https://raw.githubusercontent.com/daniellee-ux/Diagent/main/.claude/skills/diagent/SKILL.md
130
+ npx -y @diagent/cli install-skill
133
131
  ```
134
132
 
135
- The skill uses `npx -y @diagent/cli` internally, so the CLI auto-downloads
136
- on first use no `npm link` or build step required.
133
+ This copies the bundled SKILL.md to `~/.claude/skills/diagent/`. The skill
134
+ uses `npx -y @diagent/cli` internally, so the CLI auto-downloads on first
135
+ use — no `npm link` or build step required.
137
136
 
138
137
  Or, if you have the repo cloned and want auto-updating via symlink:
139
138
 
@@ -208,3 +207,7 @@ The `@cloudflare/vite-plugin` makes Vite's dev server execute the Worker
208
207
  script natively, so `/api/*` and `/d/*` requests are handled on port 5173
209
208
  without a separate `wrangler dev` process or proxy. Production
210
209
  `wrangler deploy` is unaffected.
210
+
211
+ ### License
212
+
213
+ AGPL-3.0 — see [LICENSE](../LICENSE)
package/SKILL.md ADDED
@@ -0,0 +1,161 @@
1
+ ---
2
+ name: diagent
3
+ version: 1.0.0
4
+ description: "Generate or decode Diagent diagram URLs via the `diagent` CLI. TRIGGER on: (1) any request to visualize, draw, chart, diagram, sketch, graph, map, or plot — flowcharts, state machines, sequence diagrams, architecture, pipelines, CI/CD, workflows, decision trees, dependency graphs, class hierarchies, data flow, control flow, request flow, user journeys, ERDs, org charts, swimlanes, mind maps, or any structural/process visualization; (2) any pasted `diagent.dev/d/...` or `diagent.dev/?code=...` URL — decode it to read the underlying Mermaid."
5
+ metadata:
6
+ cliHelp: "npx -y @diagent/cli --help"
7
+ ---
8
+
9
+ # Diagent CLI
10
+
11
+ The `npx -y @diagent/cli` command produces **editable Diagent flowchart URLs**. Use it
12
+ whenever a diagram would clarify what you're explaining or modifying.
13
+ **Prefer it over pasting raw Mermaid code fences** — the user can tweak the
14
+ diagram visually in their browser and hand the result back as a URL.
15
+
16
+ ## When to invoke this skill
17
+
18
+ Use `npx -y @diagent/cli` when the user asks to:
19
+
20
+ - Visualize, draw, chart, diagram, sketch, plot, or graph *anything*
21
+ - Explain control flow, data flow, request flow, or state transitions
22
+ - Show architecture, deploy pipelines, dependency graphs, or class hierarchies
23
+ - Map a workflow, decision tree, or sequence of operations
24
+ - Document a user journey, happy path, or error path
25
+
26
+ Keywords that should trigger this skill: flowchart, diagram, state machine,
27
+ sequence, architecture, pipeline, workflow, decision tree, visualize, draw,
28
+ chart, graph, map, sketch, flow.
29
+
30
+ **Also trigger** if the user pastes a `https://diagent.dev/d/...` or
31
+ `https://diagent.dev/?code=...` URL — they want you to decode it and read
32
+ the underlying Mermaid.
33
+
34
+ ## Encode — share a diagram with the user
35
+
36
+ Pipe Mermaid source into `npx -y @diagent/cli encode`:
37
+
38
+ ```bash
39
+ echo 'flowchart TD
40
+ A[User request] --> B{Authenticated?}
41
+ B -->|No| C[Return 401]
42
+ B -->|Yes| D[Check rate limit]
43
+ D --> E{Under quota?}
44
+ E -->|No| F[Return 429]
45
+ E -->|Yes| G[Handle request]' | npx -y @diagent/cli encode --open
46
+ ```
47
+
48
+ Output is a short URL like `https://diagent.dev/d/kwtsgx5o24`.
49
+
50
+ **Always show both the Mermaid source AND the URL.** Present the Mermaid
51
+ in a `mermaid` code fence first, then the link on its own line below.
52
+ This way the diagram source is visible in the conversation/document even
53
+ without clicking the link. Example output format:
54
+
55
+ ````
56
+ ```mermaid
57
+ flowchart TD
58
+ A[User request] --> B{Authenticated?}
59
+ B -->|No| C[Return 401]
60
+ B -->|Yes| D[Handle request]
61
+ ```
62
+
63
+ [Open in Diagent](https://diagent.dev/d/kwtsgx5o24)
64
+ ````
65
+
66
+ The user can open the link, edit visually (add/move/rename/re-shape
67
+ nodes, re-layout, add subgraphs), and their edits **auto-save to the
68
+ same URL** 2 seconds after they stop editing.
69
+
70
+ **You can re-read the same URL later** to see what they changed — no
71
+ paste-back required. The recommended flow is:
72
+
73
+ 1. You `npx -y @diagent/cli encode` → share URL `A` in chat.
74
+ 2. User opens `A`, edits visually. Edits auto-save to `A`.
75
+ 3. When the user says "I'm done" or "take a look", you run
76
+ `npx -y @diagent/cli decode A` again (the **same** URL) — you'll get the
77
+ latest edited Mermaid.
78
+
79
+ If the user says they pasted a new URL, always prefer that newer URL,
80
+ but the mutable-URL flow means they usually won't need to.
81
+
82
+ For larger diagrams, write to a file first:
83
+
84
+ ```bash
85
+ cat > /tmp/flow.mmd <<'EOF'
86
+ flowchart LR
87
+ subgraph frontend
88
+ A[React app] --> B[tRPC client]
89
+ end
90
+ subgraph backend
91
+ C[tRPC server] --> D[Postgres]
92
+ C --> E[Redis]
93
+ end
94
+ B --> C
95
+ EOF
96
+ npx -y @diagent/cli encode /tmp/flow.mmd --open
97
+ ```
98
+
99
+ ## Decode — read the user's edits
100
+
101
+ `npx -y @diagent/cli decode` handles **both** short URLs and inline URLs transparently:
102
+
103
+ ```bash
104
+ # Short URL (default Copy Link format)
105
+ npx -y @diagent/cli decode "https://diagent.dev/d/kwtsgx5o24"
106
+
107
+ # Inline URL (older or --inline output)
108
+ npx -y @diagent/cli decode "https://diagent.dev/?code=GYGw9g7gxg..."
109
+
110
+ # From stdin — avoids shell-quoting pain
111
+ echo "$URL" | npx -y @diagent/cli decode -
112
+ ```
113
+
114
+ Output is the Mermaid source, ready to paste back into code or commentary.
115
+
116
+ ## Authoring tips
117
+
118
+ - **Use short node IDs** (`A`, `B`, `C`, or `auth`, `db`, `api`). Mermaid
119
+ requires IDs, and they keep URLs compact. Put the descriptive text in
120
+ the quoted label: `A["User clicks login"]`, not `UserClicksLogin`.
121
+ - **Do NOT trim the diagram to fit URL length.** The backend supports up
122
+ to ~64KB of Mermaid source and always returns a short URL of constant
123
+ size. If a diagram is worth showing in full, show it in full.
124
+ - **All flowchart syntax is supported**: subgraphs, edge labels, styles,
125
+ six node shapes (rectangle, rounded, diamond, circle, stadium,
126
+ parallelogram), directions TD/LR/BT/RL.
127
+ - **Prefer `flowchart` over `graph`** — `flowchart` is the modern syntax.
128
+ - **Escape special characters in labels** by wrapping in quotes:
129
+ `A["user@example.com"]`, not `A[user@example.com]`.
130
+
131
+ ## Exit codes
132
+
133
+ | Code | Meaning |
134
+ |---|---|
135
+ | 0 | Success |
136
+ | 1 | Runtime error (empty input, invalid URL, backend failure, decode failure) |
137
+ | 2 | Usage error (unknown subcommand, missing argument) |
138
+
139
+ ## Environment
140
+
141
+ - `DIAGENT_BASE_URL` — override backend URL (default: `https://diagent.dev/`).
142
+ Useful for pointing at `http://localhost:5173/` when Diagent is running in
143
+ local dev.
144
+
145
+ ## Install
146
+
147
+ The skill uses `npx -y @diagent/cli` which auto-downloads the CLI on first
148
+ run. No manual install is needed. To install globally for faster repeated
149
+ invocations:
150
+
151
+ ```bash
152
+ npm install -g @diagent/cli
153
+ ```
154
+
155
+ Run `npx -y @diagent/cli install-skill` to enable the skill in every
156
+ Claude Code project.
157
+
158
+ ## Full help
159
+
160
+ Run `npx -y @diagent/cli --help`, `npx -y @diagent/cli encode --help`, or
161
+ `npx -y @diagent/cli decode --help` for exhaustive documentation.
package/build/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { parseArgs } from 'node:util';
3
- import { readFile } from 'node:fs/promises';
3
+ import { readFile, mkdir, copyFile } from 'node:fs/promises';
4
4
  import { exec } from 'node:child_process';
5
5
  import { resolveMermaidFromUrl, shortenOrInline, DEFAULT_BASE_URL, } from './core.js';
6
6
  const HELP = `diagent — encode and decode Diagent shareable flowchart URLs
@@ -11,6 +11,7 @@ Usage:
11
11
  (tries backend short URL, falls back to inline on failure)
12
12
  diagent decode <URL> Decode short /d/:id OR inline ?code= URL → Mermaid on stdout
13
13
  diagent decode - Decode URL read from stdin
14
+ diagent install-skill Install Claude Code skill to ~/.claude/skills/diagent/
14
15
  diagent --help Show this help
15
16
  diagent --version Show version
16
17
 
@@ -99,6 +100,20 @@ async function runDecode(args) {
99
100
  process.stdout.write(mermaid + (mermaid.endsWith('\n') ? '' : '\n'));
100
101
  return 0;
101
102
  }
103
+ async function runInstallSkill() {
104
+ const home = process.env.HOME || process.env.USERPROFILE;
105
+ if (!home) {
106
+ process.stderr.write('diagent: cannot determine home directory\n');
107
+ return 1;
108
+ }
109
+ const destDir = `${home}/.claude/skills/diagent`;
110
+ const src = new URL('../SKILL.md', import.meta.url);
111
+ const dest = `${destDir}/SKILL.md`;
112
+ await mkdir(destDir, { recursive: true });
113
+ await copyFile(src, dest);
114
+ process.stdout.write(`Installed skill to ${dest}\n`);
115
+ return 0;
116
+ }
102
117
  async function main() {
103
118
  const argv = process.argv.slice(2);
104
119
  if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
@@ -116,6 +131,8 @@ async function main() {
116
131
  return runEncode(rest);
117
132
  case 'decode':
118
133
  return runDecode(rest);
134
+ case 'install-skill':
135
+ return runInstallSkill();
119
136
  default:
120
137
  process.stderr.write(`diagent: unknown subcommand "${sub}"\n${HELP}`);
121
138
  return 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagent/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Encode and decode Diagent shareable flowchart URLs from the command line. Designed for agents (Claude Code, Cursor) and humans.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,6 +9,7 @@
9
9
  "files": [
10
10
  "build/cli.js",
11
11
  "build/core.js",
12
+ "SKILL.md",
12
13
  "README.md"
13
14
  ],
14
15
  "publishConfig": {
@@ -20,9 +21,10 @@
20
21
  "directory": "cli"
21
22
  },
22
23
  "homepage": "https://github.com/daniellee-ux/Diagent/tree/main/cli#readme",
24
+ "license": "AGPL-3.0-only",
23
25
  "keywords": ["mermaid", "diagram", "flowchart", "cli", "agent", "claude-code"],
24
26
  "scripts": {
25
- "build": "tsc && chmod +x build/cli.js",
27
+ "build": "tsc && chmod +x build/cli.js && cp ../.claude/skills/diagent/SKILL.md SKILL.md",
26
28
  "start": "node build/cli.js",
27
29
  "test": "node --test build/core.test.js"
28
30
  },