@maidang1/hataraku 0.0.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.
Files changed (167) hide show
  1. package/.claude/CLAUDE.md +21 -0
  2. package/.codex/skills/beautiful-mermaid/SKILL.md +171 -0
  3. package/.codex/skills/beautiful-mermaid/references/mermaid-syntax.md +235 -0
  4. package/.codex/skills/beautiful-mermaid/scripts/create-html.ts +177 -0
  5. package/.codex/skills/beautiful-mermaid/scripts/render.ts +221 -0
  6. package/.codex/skills/find-skills/SKILL.md +133 -0
  7. package/.github/workflows/publish-github-packages.yml +58 -0
  8. package/.github/workflows/publish-npm.yml +46 -0
  9. package/.vscode/settings.json +2 -0
  10. package/AGENTS.md +41 -0
  11. package/LICENSE +21 -0
  12. package/README.md +119 -0
  13. package/bun.lock +327 -0
  14. package/docs/agent/architecture.md +28 -0
  15. package/docs/agent/development_commands.md +6 -0
  16. package/docs/plan/agent-plan-2026-02-05.md +136 -0
  17. package/docs/plan/core-agent-sdk-structure-2026-02-07.md +156 -0
  18. package/docs/plan/implementation-summary.md +303 -0
  19. package/docs/plan/mcp-2026-02-05.md +700 -0
  20. package/docs/plan/op.md +478 -0
  21. package/docs/plan/skills-2026-02-05.md +352 -0
  22. package/docs/plan/skills-flow.svg +120 -0
  23. package/docs/plan/tui-readability-2026-02-06.md +67 -0
  24. package/package.json +34 -0
  25. package/src/cli/index.tsx +4 -0
  26. package/src/cli/main.tsx +98 -0
  27. package/src/core/README.md +19 -0
  28. package/src/core/api/agent.ts +1 -0
  29. package/src/core/api/config.ts +1 -0
  30. package/src/core/api/index.ts +10 -0
  31. package/src/core/api/integrations.ts +1 -0
  32. package/src/core/api/observability.ts +1 -0
  33. package/src/core/api/policy.ts +1 -0
  34. package/src/core/api/providers.ts +1 -0
  35. package/src/core/api/runtime.ts +1 -0
  36. package/src/core/api/shared.ts +1 -0
  37. package/src/core/api/tools.ts +1 -0
  38. package/src/core/api/types.ts +1 -0
  39. package/src/core/index.ts +1 -0
  40. package/src/core/internal/config/defaults.ts +8 -0
  41. package/src/core/internal/config/index.ts +3 -0
  42. package/src/core/internal/config/loader.ts +97 -0
  43. package/src/core/internal/config/schema.ts +47 -0
  44. package/src/core/internal/integrations/index.ts +2 -0
  45. package/src/core/internal/integrations/mcp/connection-manager.ts +231 -0
  46. package/src/core/internal/integrations/mcp/health-checker.ts +91 -0
  47. package/src/core/internal/integrations/mcp/index.ts +197 -0
  48. package/src/core/internal/integrations/mcp/retry-strategy.ts +111 -0
  49. package/src/core/internal/integrations/mcp/tool-cache.ts +103 -0
  50. package/src/core/internal/integrations/mcp/transport.ts +58 -0
  51. package/src/core/internal/integrations/mcp/types.ts +95 -0
  52. package/src/core/internal/integrations/mcp/utils.ts +44 -0
  53. package/src/core/internal/integrations/skills/cache/index.ts +38 -0
  54. package/src/core/internal/integrations/skills/cache/interface.ts +9 -0
  55. package/src/core/internal/integrations/skills/cache/memory-cache.ts +118 -0
  56. package/src/core/internal/integrations/skills/config/defaults.ts +35 -0
  57. package/src/core/internal/integrations/skills/config/index.ts +71 -0
  58. package/src/core/internal/integrations/skills/config/schema.ts +31 -0
  59. package/src/core/internal/integrations/skills/core/errors.ts +36 -0
  60. package/src/core/internal/integrations/skills/core/events.ts +143 -0
  61. package/src/core/internal/integrations/skills/core/types.ts +83 -0
  62. package/src/core/internal/integrations/skills/dependency/conflict-detector.ts +126 -0
  63. package/src/core/internal/integrations/skills/dependency/graph.ts +91 -0
  64. package/src/core/internal/integrations/skills/dependency/resolver.ts +128 -0
  65. package/src/core/internal/integrations/skills/dependency/types.ts +51 -0
  66. package/src/core/internal/integrations/skills/discovery/index.ts +98 -0
  67. package/src/core/internal/integrations/skills/discovery/resolver.ts +39 -0
  68. package/src/core/internal/integrations/skills/discovery/scanner.ts +116 -0
  69. package/src/core/internal/integrations/skills/discovery/strategies/file-system.ts +16 -0
  70. package/src/core/internal/integrations/skills/index.ts +3 -0
  71. package/src/core/internal/integrations/skills/integration/lifecycle.ts +124 -0
  72. package/src/core/internal/integrations/skills/integration/mcp-loader.ts +100 -0
  73. package/src/core/internal/integrations/skills/integration/tool-mapper.ts +56 -0
  74. package/src/core/internal/integrations/skills/loaders/index.ts +5 -0
  75. package/src/core/internal/integrations/skills/loaders/skill-loader.ts +97 -0
  76. package/src/core/internal/integrations/skills/manager.ts +200 -0
  77. package/src/core/internal/integrations/skills/parsers/base.ts +134 -0
  78. package/src/core/internal/integrations/skills/parsers/factory.ts +42 -0
  79. package/src/core/internal/integrations/skills/parsers/index.ts +71 -0
  80. package/src/core/internal/integrations/skills/parsers/markdown.ts +111 -0
  81. package/src/core/internal/integrations/skills/parsers/yaml-metadata.ts +49 -0
  82. package/src/core/internal/integrations/skills/types.ts +15 -0
  83. package/src/core/internal/integrations/skills/utils/fs.ts +59 -0
  84. package/src/core/internal/integrations/skills/utils/logger.ts +109 -0
  85. package/src/core/internal/integrations/skills/utils/path.ts +27 -0
  86. package/src/core/internal/integrations/skills/validation/index.ts +43 -0
  87. package/src/core/internal/integrations/skills/validation/schema.ts +37 -0
  88. package/src/core/internal/integrations/skills/validation/skill-validator.ts +56 -0
  89. package/src/core/internal/observability/index.ts +2 -0
  90. package/src/core/internal/observability/logging/env.ts +32 -0
  91. package/src/core/internal/observability/logging/export.ts +55 -0
  92. package/src/core/internal/observability/logging/index.ts +4 -0
  93. package/src/core/internal/observability/logging/session-logger.ts +54 -0
  94. package/src/core/internal/observability/logging/types.ts +53 -0
  95. package/src/core/internal/policy/index.ts +1 -0
  96. package/src/core/internal/policy/safety/index.ts +2 -0
  97. package/src/core/internal/policy/safety/policy.ts +96 -0
  98. package/src/core/internal/policy/safety/types.ts +24 -0
  99. package/src/core/internal/providers/anthropic/client.ts +20 -0
  100. package/src/core/internal/providers/anthropic/index.ts +1 -0
  101. package/src/core/internal/providers/index.ts +1 -0
  102. package/src/core/internal/sdk/agent/agent.ts +691 -0
  103. package/src/core/internal/sdk/agent/index.ts +3 -0
  104. package/src/core/internal/sdk/agent/session.ts +9 -0
  105. package/src/core/internal/sdk/agent/tool-loop.ts +10 -0
  106. package/src/core/internal/sdk/index.ts +3 -0
  107. package/src/core/internal/sdk/runtime/context.ts +1 -0
  108. package/src/core/internal/sdk/runtime/errors.ts +9 -0
  109. package/src/core/internal/sdk/runtime/execution.ts +12 -0
  110. package/src/core/internal/sdk/runtime/index.ts +3 -0
  111. package/src/core/internal/sdk/types/api.ts +4 -0
  112. package/src/core/internal/sdk/types/index.ts +1 -0
  113. package/src/core/internal/sdk/types/internal.ts +1 -0
  114. package/src/core/internal/shared/fs.ts +10 -0
  115. package/src/core/internal/shared/index.ts +3 -0
  116. package/src/core/internal/shared/message.ts +12 -0
  117. package/src/core/internal/shared/path.ts +10 -0
  118. package/src/core/internal/tools/base/errors.ts +6 -0
  119. package/src/core/internal/tools/base/index.ts +3 -0
  120. package/src/core/internal/tools/base/schema.ts +1 -0
  121. package/src/core/internal/tools/base/tool.ts +42 -0
  122. package/src/core/internal/tools/builtins/architect.ts +45 -0
  123. package/src/core/internal/tools/builtins/bash.ts +135 -0
  124. package/src/core/internal/tools/builtins/fetch.ts +62 -0
  125. package/src/core/internal/tools/builtins/file-edit.ts +134 -0
  126. package/src/core/internal/tools/builtins/file-read.ts +75 -0
  127. package/src/core/internal/tools/builtins/fs.ts +254 -0
  128. package/src/core/internal/tools/builtins/glob.ts +75 -0
  129. package/src/core/internal/tools/builtins/grep.ts +104 -0
  130. package/src/core/internal/tools/builtins/index.ts +26 -0
  131. package/src/core/internal/tools/builtins/list-files.ts +64 -0
  132. package/src/core/internal/tools/builtins/search.ts +50 -0
  133. package/src/core/internal/tools/builtins/skills.ts +127 -0
  134. package/src/core/internal/tools/builtins/todo.ts +121 -0
  135. package/src/core/internal/tools/guards/file-edit-cache.ts +21 -0
  136. package/src/core/internal/tools/guards/limits.ts +43 -0
  137. package/src/core/internal/tools/index.ts +39 -0
  138. package/src/core/internal/tools/registry/index.ts +2 -0
  139. package/src/core/internal/tools/registry/presets.ts +28 -0
  140. package/src/core/internal/tools/registry/registry.ts +21 -0
  141. package/src/index.ts +3 -0
  142. package/src/render/commands/index.ts +113 -0
  143. package/src/render/commands/init.ts +45 -0
  144. package/src/render/components/ActivityPane.tsx +67 -0
  145. package/src/render/components/ChatBubble.tsx +58 -0
  146. package/src/render/components/ConfirmCard.tsx +100 -0
  147. package/src/render/components/ConfirmSelectMenu.tsx +56 -0
  148. package/src/render/components/ConversationPane.tsx +65 -0
  149. package/src/render/components/EventTimeline.tsx +30 -0
  150. package/src/render/components/MarkdownText.tsx +139 -0
  151. package/src/render/components/SlashCommandMenu.tsx +68 -0
  152. package/src/render/components/Spinner.tsx +18 -0
  153. package/src/render/components/StatusBar.tsx +72 -0
  154. package/src/render/components/Timeline.tsx +57 -0
  155. package/src/render/components/TimelineEvent.tsx +313 -0
  156. package/src/render/components/ToolCard.tsx +126 -0
  157. package/src/render/components/formatters/confirm.test.ts +34 -0
  158. package/src/render/components/formatters/confirm.ts +32 -0
  159. package/src/render/index.tsx +466 -0
  160. package/src/render/state/events.ts +301 -0
  161. package/src/render/state/history.ts +5 -0
  162. package/src/render/state/loading.ts +18 -0
  163. package/src/render/state/message.tsx +35 -0
  164. package/src/render/state/store.ts +7 -0
  165. package/src/render/theme.ts +52 -0
  166. package/test-e2e.ts +250 -0
  167. package/tsconfig.json +29 -0
@@ -0,0 +1,21 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Development Commands
6
+
7
+ - `bun run src/index.ts` - Run the application
8
+ - `bun --hot src/index.ts` - Run with hot reload for development
9
+ - `bunx tsc -p tsconfig.json --noEmit` - Typecheck
10
+ - `bun run test-e2e.ts` - Run e2e smoke checks
11
+
12
+ ## Project
13
+
14
+ - Name: coding
15
+
16
+ ## Architecture Overview
17
+
18
+ - `src/index.ts` - Entry
19
+ - `src/cli/` - CLI bootstrap (Ink render + wiring)
20
+ - `src/render/` - Ink UI components and Jotai state
21
+ - `src/core/` - Core logic (agent, tools, MCP, skills, config, safety, logging)
@@ -0,0 +1,171 @@
1
+ ---
2
+ name: beautiful-mermaid
3
+ description: Render Mermaid diagrams as SVG and PNG using the Beautiful Mermaid library. Use when the user asks to render a Mermaid diagram.
4
+ ---
5
+
6
+ # Beautiful Mermaid Diagram Rendering
7
+
8
+ Render Mermaid diagrams as SVG and PNG images using the Beautiful Mermaid library.
9
+
10
+ ## Dependencies
11
+
12
+ This skill requires the `agent-browser` skill for PNG rendering. Load it before proceeding with PNG capture.
13
+
14
+ ## Supported Diagram Types
15
+
16
+ - **Flowchart** - Process flows, decision trees, CI/CD pipelines
17
+ - **Sequence** - API calls, OAuth flows, database transactions
18
+ - **State** - State machines, connection lifecycles
19
+ - **Class** - UML class diagrams, design patterns
20
+ - **Entity-Relationship** - Database schemas, data models
21
+
22
+ ## Available Themes
23
+
24
+ Default, Dracula, Solarized, Zinc Dark, Tokyo Night, Tokyo Night Storm, Tokyo Night Light, Catppuccin Latte, Nord, Nord Light, GitHub Dark, GitHub Light, One Dark.
25
+
26
+ If no theme is specified, use `default`.
27
+
28
+ ## Common Syntax Patterns
29
+
30
+ ### Flowchart Edge Labels
31
+
32
+ Use pipe syntax for edge labels:
33
+
34
+ ```mermaid
35
+ A -->|label| B
36
+ A ---|label| B
37
+ ```
38
+
39
+ Avoid space-dash syntax which can cause incomplete renders:
40
+
41
+ ```mermaid
42
+ A -- label --> B # May cause issues
43
+ ```
44
+
45
+ ### Node Labels with Special Characters
46
+
47
+ Wrap labels containing special characters in quotes:
48
+
49
+ ```mermaid
50
+ A["Label with (parens)"]
51
+ B["Label with / slash"]
52
+ ```
53
+
54
+ ## Workflow
55
+
56
+ ### Step 1: Generate or Validate Mermaid Code
57
+
58
+ If the user provides a description rather than code, generate valid Mermaid syntax. Consult `references/mermaid-syntax.md` for full syntax details.
59
+
60
+ ### Step 2: Render SVG
61
+
62
+ Run the rendering script to produce an SVG file:
63
+
64
+ ```bash
65
+ bun run scripts/render.ts --code "graph TD; A-->B" --output diagram --theme default
66
+ ```
67
+
68
+ Or from a file:
69
+
70
+ ```bash
71
+ bun run scripts/render.ts --input diagram.mmd --output diagram --theme tokyo-night
72
+ ```
73
+
74
+ Alternative runtimes:
75
+ ```bash
76
+ npx tsx scripts/render.ts --code "..." --output diagram
77
+ deno run --allow-read --allow-write --allow-net scripts/render.ts --code "..." --output diagram
78
+ ```
79
+
80
+ This produces `<output>.svg` in the current working directory.
81
+
82
+ ### Step 3: Create HTML Wrapper
83
+
84
+ Run the HTML wrapper script to prepare for screenshot:
85
+
86
+ ```bash
87
+ bun run scripts/create-html.ts --svg diagram.svg --output diagram.html
88
+ ```
89
+
90
+ This creates a minimal HTML file that displays the SVG with proper padding and background.
91
+
92
+ ### Step 4: Capture High-Resolution PNG with agent-browser
93
+
94
+ Use the agent-browser CLI to capture a high-quality screenshot. Refer to the `agent-browser` skill for full CLI documentation.
95
+
96
+ ```bash
97
+ # Set 4K viewport for high-resolution capture
98
+ agent-browser set viewport 3840 2160
99
+
100
+ # Open the HTML wrapper
101
+ agent-browser open "file://$(pwd)/diagram.html"
102
+
103
+ # Wait for render to complete
104
+ agent-browser wait 1000
105
+
106
+ # Capture full-page screenshot
107
+ agent-browser screenshot --full diagram.png
108
+
109
+ # Close browser
110
+ agent-browser close
111
+ ```
112
+
113
+ For even higher resolution on complex diagrams, increase the viewport further or use the `--padding` option when creating the HTML wrapper to give the diagram more space.
114
+
115
+ ### Step 5: Clean Up Intermediary Files
116
+
117
+ After rendering, remove all intermediary files. Only the final `.svg` and `.png` should remain.
118
+
119
+ Files to clean up:
120
+ - The HTML wrapper file (e.g., `diagram.html`)
121
+ - Any temporary `.mmd` files created to hold diagram code
122
+ - Any other files created during the rendering process
123
+
124
+ ```bash
125
+ rm diagram.html
126
+ ```
127
+
128
+ If a temporary `.mmd` file was created, remove it as well.
129
+
130
+ ## Output
131
+
132
+ Both outputs are always produced:
133
+ - **SVG**: Vector format, infinitely scalable, small file size
134
+ - **PNG**: High-resolution raster, captured at 4K (3840×2160) viewport with minimum 1200px diagram width
135
+
136
+ Files are saved to the current working directory unless the user explicitly specifies a different path.
137
+
138
+ ## Theme Selection Guide
139
+
140
+ | Theme | Background | Best For |
141
+ |-------|------------|----------|
142
+ | default | Light grey | General use |
143
+ | dracula | Dark purple | Dark mode preference |
144
+ | tokyo-night | Dark blue | Modern dark aesthetic |
145
+ | tokyo-night-storm | Darker blue | Higher contrast |
146
+ | nord | Dark arctic | Muted, calm visuals |
147
+ | nord-light | Light arctic | Light mode with soft tones |
148
+ | github-dark | GitHub dark | Matches GitHub UI |
149
+ | github-light | GitHub light | Matches GitHub UI |
150
+ | catppuccin-latte | Warm light | Soft pastel aesthetic |
151
+ | solarized | Tan/cream | Solarized colour scheme |
152
+ | one-dark | Atom dark | Atom editor aesthetic |
153
+ | zinc-dark | Neutral dark | Minimal, no colour bias |
154
+
155
+ ## Troubleshooting
156
+
157
+ ### Theme not applied
158
+
159
+ Check the render script output for the `bg` and `fg` values, or inspect the SVG's opening tag for `--bg` and `--fg` CSS custom properties.
160
+
161
+ ### Diagram appears cut off or incomplete
162
+
163
+ - Check edge label syntax — use `-->|label|` pipe notation, not `-- label -->`
164
+ - Verify all node IDs are unique
165
+ - Check for unclosed brackets in node labels
166
+
167
+ ### Render produces empty or malformed SVG
168
+
169
+ - Validate Mermaid syntax at https://mermaid.live before rendering
170
+ - Check for special characters that need escaping (wrap in quotes)
171
+ - Ensure flowchart direction is specified (`graph TD`, `graph LR`, etc.)
@@ -0,0 +1,235 @@
1
+ # Mermaid Syntax Reference
2
+
3
+ Quick reference for generating valid Mermaid diagram code.
4
+
5
+ ## Flowchart
6
+
7
+ ```mermaid
8
+ graph TD
9
+ A[Start] --> B{Decision}
10
+ B -->|Yes| C[Action 1]
11
+ B -->|No| D[Action 2]
12
+ C --> E[End]
13
+ D --> E
14
+ ```
15
+
16
+ ### Direction
17
+ - `TD` / `TB` - Top to bottom
18
+ - `BT` - Bottom to top
19
+ - `LR` - Left to right
20
+ - `RL` - Right to left
21
+
22
+ ### Node Shapes
23
+ - `A[Text]` - Rectangle
24
+ - `A(Text)` - Rounded rectangle
25
+ - `A([Text])` - Stadium/pill
26
+ - `A[[Text]]` - Subroutine
27
+ - `A[(Text)]` - Cylinder (database)
28
+ - `A((Text))` - Circle
29
+ - `A>Text]` - Asymmetric
30
+ - `A{Text}` - Diamond (decision)
31
+ - `A{{Text}}` - Hexagon
32
+ - `A[/Text/]` - Parallelogram
33
+ - `A[\Text\]` - Parallelogram alt
34
+ - `A[/Text\]` - Trapezoid
35
+ - `A[\Text/]` - Trapezoid alt
36
+
37
+ ### Edge Styles
38
+ - `A --> B` - Arrow
39
+ - `A --- B` - Line
40
+ - `A -.-> B` - Dotted arrow
41
+ - `A ==> B` - Thick arrow
42
+ - `A -->|text| B` - Arrow with label (preferred)
43
+ - `A ---|text| B` - Line with label (preferred)
44
+
45
+ **Important**: Always use pipe syntax `-->|label|` for edge labels. The space-dash syntax `-- label -->` can cause incomplete renders.
46
+
47
+ ### Subgraphs
48
+ ```mermaid
49
+ graph TD
50
+ subgraph Group1 [Label]
51
+ A --> B
52
+ end
53
+ subgraph Group2
54
+ C --> D
55
+ end
56
+ B --> C
57
+ ```
58
+
59
+ ## Sequence Diagram
60
+
61
+ ```mermaid
62
+ sequenceDiagram
63
+ participant A as Alice
64
+ participant B as Bob
65
+ A->>B: Hello
66
+ B-->>A: Hi there
67
+ A->>+B: Start process
68
+ B-->>-A: Done
69
+ ```
70
+
71
+ ### Arrow Types
72
+ - `->>` - Solid arrow
73
+ - `-->>` - Dashed arrow
74
+ - `-x` - Solid with x
75
+ - `--x` - Dashed with x
76
+ - `-)` - Solid open arrow
77
+ - `--)` - Dashed open arrow
78
+
79
+ ### Activations
80
+ - `+` after arrow activates participant
81
+ - `-` after arrow deactivates participant
82
+
83
+ ### Notes and Boxes
84
+ ```mermaid
85
+ sequenceDiagram
86
+ Note over A,B: Shared note
87
+ Note right of A: Side note
88
+ rect rgb(200, 220, 255)
89
+ A->>B: In a box
90
+ end
91
+ ```
92
+
93
+ ### Loops and Conditionals
94
+ ```mermaid
95
+ sequenceDiagram
96
+ loop Every minute
97
+ A->>B: Ping
98
+ end
99
+ alt Success
100
+ B-->>A: Pong
101
+ else Failure
102
+ B-->>A: Error
103
+ end
104
+ opt Optional
105
+ A->>B: Extra step
106
+ end
107
+ ```
108
+
109
+ ## State Diagram
110
+
111
+ ```mermaid
112
+ stateDiagram-v2
113
+ [*] --> Idle
114
+ Idle --> Processing : start
115
+ Processing --> Done : complete
116
+ Processing --> Error : fail
117
+ Error --> Idle : reset
118
+ Done --> [*]
119
+ ```
120
+
121
+ ### Composite States
122
+ ```mermaid
123
+ stateDiagram-v2
124
+ state Active {
125
+ [*] --> Running
126
+ Running --> Paused : pause
127
+ Paused --> Running : resume
128
+ }
129
+ Idle --> Active : activate
130
+ Active --> Idle : deactivate
131
+ ```
132
+
133
+ ### Notes
134
+ ```mermaid
135
+ stateDiagram-v2
136
+ State1 : Description here
137
+ note right of State1
138
+ Additional info
139
+ end note
140
+ ```
141
+
142
+ ## Class Diagram
143
+
144
+ ```mermaid
145
+ classDiagram
146
+ class Animal {
147
+ +String name
148
+ +int age
149
+ +makeSound() void
150
+ }
151
+ class Dog {
152
+ +bark() void
153
+ }
154
+ Animal <|-- Dog : extends
155
+ ```
156
+
157
+ ### Relationships
158
+ - `<|--` - Inheritance
159
+ - `*--` - Composition
160
+ - `o--` - Aggregation
161
+ - `-->` - Association
162
+ - `--` - Link (solid)
163
+ - `..>` - Dependency
164
+ - `..|>` - Realisation
165
+ - `..` - Link (dashed)
166
+
167
+ ### Cardinality
168
+ ```mermaid
169
+ classDiagram
170
+ Customer "1" --> "*" Order
171
+ Order "1" --> "1..*" LineItem
172
+ ```
173
+
174
+ ### Visibility
175
+ - `+` Public
176
+ - `-` Private
177
+ - `#` Protected
178
+ - `~` Package/Internal
179
+
180
+ ## Entity-Relationship Diagram
181
+
182
+ ```mermaid
183
+ erDiagram
184
+ CUSTOMER ||--o{ ORDER : places
185
+ ORDER ||--|{ LINE-ITEM : contains
186
+ PRODUCT }|..|{ LINE-ITEM : "ordered in"
187
+ ```
188
+
189
+ ### Relationship Types
190
+ - `||` - Exactly one
191
+ - `|{` - One or more
192
+ - `o{` - Zero or more
193
+ - `o|` - Zero or one
194
+
195
+ ### Identifying vs Non-identifying
196
+ - `--` - Identifying (solid)
197
+ - `..` - Non-identifying (dashed)
198
+
199
+ ### Attributes
200
+ ```mermaid
201
+ erDiagram
202
+ CUSTOMER {
203
+ string id PK
204
+ string name
205
+ string email UK
206
+ }
207
+ ORDER {
208
+ int id PK
209
+ string customer_id FK
210
+ date created_at
211
+ }
212
+ ```
213
+
214
+ ## Styling
215
+
216
+ ### CSS Classes
217
+ ```mermaid
218
+ graph TD
219
+ A:::highlight --> B
220
+ classDef highlight fill:#f96,stroke:#333
221
+ ```
222
+
223
+ ### Inline Styles
224
+ ```mermaid
225
+ graph TD
226
+ A --> B
227
+ style A fill:#bbf,stroke:#333
228
+ ```
229
+
230
+ ## Tips
231
+
232
+ 1. **Escape special characters**: Use quotes for labels with special chars: `A["Label with (parens)"]`
233
+ 2. **Multi-line labels**: Use `<br/>` for line breaks
234
+ 3. **Comments**: Use `%%` for comments that won't render
235
+ 4. **IDs vs Labels**: Node IDs should be simple, labels can be complex: `node1["Complex Label Here"]`
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ /**
3
+ * Create an HTML wrapper for an SVG to enable high-quality PNG capture
4
+ *
5
+ * Usage:
6
+ * bun run create-html.ts --svg diagram.svg --output diagram.html
7
+ * bun run create-html.ts --svg diagram.svg --output diagram.html --padding 40
8
+ *
9
+ * Runtimes:
10
+ * bun run create-html.ts ...
11
+ * npx tsx create-html.ts ...
12
+ * deno run --allow-read --allow-write create-html.ts ...
13
+ */
14
+
15
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
16
+ import { resolve, basename } from "node:path";
17
+
18
+ interface Args {
19
+ svg: string;
20
+ output: string;
21
+ padding: number;
22
+ background?: string;
23
+ }
24
+
25
+ function parseArgs(): Args {
26
+ const args = process.argv.slice(2);
27
+ const result: Partial<Args> = { padding: 40 };
28
+
29
+ for (let i = 0; i < args.length; i++) {
30
+ const arg = args[i];
31
+ const next = args[i + 1];
32
+
33
+ switch (arg) {
34
+ case "--svg":
35
+ case "-s":
36
+ result.svg = next;
37
+ i++;
38
+ break;
39
+ case "--output":
40
+ case "-o":
41
+ result.output = next;
42
+ i++;
43
+ break;
44
+ case "--padding":
45
+ case "-p":
46
+ result.padding = parseInt(next, 10) || 40;
47
+ i++;
48
+ break;
49
+ case "--background":
50
+ case "-b":
51
+ result.background = next;
52
+ i++;
53
+ break;
54
+ case "--help":
55
+ case "-h":
56
+ printHelp();
57
+ process.exit(0);
58
+ }
59
+ }
60
+
61
+ if (!result.svg) {
62
+ console.error("Error: --svg is required");
63
+ printHelp();
64
+ process.exit(1);
65
+ }
66
+
67
+ if (!result.output) {
68
+ console.error("Error: --output is required");
69
+ printHelp();
70
+ process.exit(1);
71
+ }
72
+
73
+ return result as Args;
74
+ }
75
+
76
+ function printHelp(): void {
77
+ console.log(`
78
+ SVG to HTML Wrapper
79
+
80
+ Creates a minimal HTML file for screenshot capture of SVG diagrams.
81
+
82
+ Usage:
83
+ create-html.ts --svg <file.svg> --output <file.html> [options]
84
+
85
+ Options:
86
+ -s, --svg <file> Input SVG file
87
+ -o, --output <file> Output HTML file
88
+ -p, --padding <pixels> Padding around SVG (default: 40)
89
+ -b, --background <color> Background colour (auto-detected from SVG)
90
+ -h, --help Show this help
91
+
92
+ Examples:
93
+ create-html.ts --svg diagram.svg --output diagram.html
94
+ create-html.ts --svg diagram.svg --output diagram.html --padding 60
95
+ create-html.ts --svg diagram.svg --output diagram.html --background "#1a1b26"
96
+ `);
97
+ }
98
+
99
+ function extractBackgroundFromSvg(svgContent: string): string | null {
100
+ // Try to extract background from SVG style or rect
101
+ const bgMatch = svgContent.match(/background(?:-color)?:\s*([^;"\s]+)/i);
102
+ if (bgMatch) return bgMatch[1];
103
+
104
+ // Check for a background rect
105
+ const rectMatch = svgContent.match(
106
+ /<rect[^>]*fill="([^"]+)"[^>]*(?:width="100%"|height="100%")/i
107
+ );
108
+ if (rectMatch) return rectMatch[1];
109
+
110
+ // Check style attribute on svg element
111
+ const svgStyleMatch = svgContent.match(
112
+ /<svg[^>]*style="[^"]*background(?:-color)?:\s*([^;"\s]+)/i
113
+ );
114
+ if (svgStyleMatch) return svgStyleMatch[1];
115
+
116
+ return null;
117
+ }
118
+
119
+ function main(): void {
120
+ const args = parseArgs();
121
+
122
+ const svgPath = resolve(args.svg);
123
+ if (!existsSync(svgPath)) {
124
+ console.error(`SVG file not found: ${svgPath}`);
125
+ process.exit(1);
126
+ }
127
+
128
+ const svgContent = readFileSync(svgPath, "utf-8");
129
+
130
+ // Determine background colour
131
+ const background =
132
+ args.background ?? extractBackgroundFromSvg(svgContent) ?? "#ffffff";
133
+
134
+ // Create HTML wrapper optimised for high-resolution screenshot
135
+ // SVG renders at natural size with generous padding, no constraints
136
+ const html = `<!DOCTYPE html>
137
+ <html lang="en">
138
+ <head>
139
+ <meta charset="UTF-8">
140
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
141
+ <title>${basename(args.svg, ".svg")}</title>
142
+ <style>
143
+ * {
144
+ margin: 0;
145
+ padding: 0;
146
+ box-sizing: border-box;
147
+ }
148
+ html, body {
149
+ background: ${background};
150
+ }
151
+ .container {
152
+ padding: ${args.padding}px;
153
+ display: inline-block;
154
+ background: ${background};
155
+ }
156
+ .container svg {
157
+ display: block;
158
+ min-width: 1200px;
159
+ height: auto;
160
+ }
161
+ </style>
162
+ </head>
163
+ <body>
164
+ <div class="container">
165
+ ${svgContent}
166
+ </div>
167
+ </body>
168
+ </html>`;
169
+
170
+ const outputPath = resolve(args.output);
171
+ writeFileSync(outputPath, html, "utf-8");
172
+
173
+ console.log(`HTML wrapper written to: ${outputPath}`);
174
+ console.log(`Background colour: ${background}`);
175
+ }
176
+
177
+ main();