dsh-md-studio 1.2.0 → 1.3.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/lib/index.js CHANGED
@@ -1,3 +1,108 @@
1
- export const name="dsh-md-studio";
2
- export const inject=[];
3
- export function apply() {}
1
+ // dsh-md-studio host half (source of truth; build script copies to lib/index.js).
2
+ //
3
+ // 1. Serves an optional vendored mermaid runtime from ./runtime (offline mode).
4
+ // 2. Registers a system-prompt section teaching the model how to emit
5
+ // ```mds-diagram blocks — model-authored SVG widgets rendered by the
6
+ // browser half into themed cards (the WorkBuddy "show_widget" pattern).
7
+
8
+ import { readFile } from "node:fs/promises";
9
+ import { fileURLToPath } from "node:url";
10
+ import { join, normalize, sep } from "node:path";
11
+
12
+ const name = "dsh-md-studio";
13
+ const inject = ["webServer", "systemPrompt"];
14
+
15
+ const RUNTIME_ROUTE = "/dsh-md-studio/runtime";
16
+ const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
17
+
18
+ const MIME = {
19
+ ".js": "text/javascript; charset=utf-8",
20
+ ".mjs": "text/javascript; charset=utf-8",
21
+ ".css": "text/css; charset=utf-8",
22
+ ".json": "application/json; charset=utf-8",
23
+ ".map": "application/json; charset=utf-8",
24
+ ".wasm": "application/wasm",
25
+ ".ttf": "font/ttf",
26
+ ".woff": "font/woff",
27
+ ".woff2": "font/woff2",
28
+ };
29
+
30
+ const GUIDELINE = `## 图表组件(mds-diagram)
31
+
32
+ 当需要输出高质量示意图、流程图、架构分层图或对比图时,优先使用 \`\`\`mds-diagram 围栏(而非 mermaid),内容为一个完整的手写 SVG。渲染环境会自动套用主题卡片并净化内容。
33
+
34
+ 设计规范(深浅主题通吃):
35
+ - 根元素:<svg viewBox="0 0 W H" width="100%" font-family="system-ui,sans-serif">,不设背景色
36
+ - 节点填充主色 #3B82F6(白字),强调/辅助 #8B5CF6,成功 #10B981,警告 #F59E0B,危险 #EF4444
37
+ - 连接线 #94A3B8,文字 fill 白色(在实色节点上)或 #1F2937(在浅底上)
38
+ - 圆角 rect rx=8~10,节点内边距 ≥12px,字号 13~15px
39
+ - 分组/分层容器用半透明底色 rgba(59,130,246,.08) + 描边 rgba(59,130,246,.35)
40
+ - 编号用圆形 badge(circle + 白色居中数字)
41
+ - 箭头用 <marker> 定义,id 唯一
42
+ - 在 <svg> 内放 <title> 描述图表用途(作为卡片标题)
43
+ - 每个文本元素显式设 fill;不要依赖默认继承
44
+
45
+ 仅在图表有明确结构化表达价值时使用;简单流程继续用 mermaid 围栏。`;
46
+
47
+ function apply(ctx) {
48
+ ctx.effect(
49
+ () =>
50
+ ctx.webServer.register({
51
+ kind: "prefix",
52
+ path: RUNTIME_ROUTE,
53
+ async handler(req, res) {
54
+ if (req.method !== "GET" && req.method !== "HEAD") {
55
+ res.writeHead(405);
56
+ res.end();
57
+ return;
58
+ }
59
+ const url = new URL(req.url ?? "/", "http://dsh.invalid");
60
+ let rel;
61
+ try {
62
+ rel = decodeURIComponent(url.pathname.slice(RUNTIME_ROUTE.length));
63
+ } catch {
64
+ res.writeHead(400);
65
+ res.end();
66
+ return;
67
+ }
68
+ rel = rel.replace(/^\/+/, "");
69
+ if (!rel || rel.includes("..") || rel.includes("\0") || rel.includes("\\") || /[:*?"<>|]/.test(rel)) {
70
+ res.writeHead(404);
71
+ res.end();
72
+ return;
73
+ }
74
+ const root = normalize(runtimeDir);
75
+ const target = normalize(join(root, rel));
76
+ if (target !== root && !target.startsWith(root + sep)) {
77
+ res.writeHead(404);
78
+ res.end();
79
+ return;
80
+ }
81
+ try {
82
+ const body = await readFile(target);
83
+ const dot = target.lastIndexOf(".");
84
+ const ext = dot === -1 ? "" : target.slice(dot).toLowerCase();
85
+ res.writeHead(200, {
86
+ "content-type": MIME[ext] ?? "application/octet-stream",
87
+ "cache-control": "public, max-age=86400",
88
+ });
89
+ res.end(req.method === "HEAD" ? undefined : body);
90
+ } catch {
91
+ res.writeHead(404);
92
+ res.end();
93
+ }
94
+ },
95
+ }),
96
+ "dsh-md-studio: vendored runtime route",
97
+ );
98
+ ctx.effect(
99
+ () => ctx.systemPrompt.section({
100
+ name: "mds-diagram-guidelines",
101
+ order: 5200,
102
+ text: GUIDELINE,
103
+ }),
104
+ "dsh-md-studio: diagram design guidelines",
105
+ );
106
+ }
107
+
108
+ export { apply, inject, name };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "name": "dsh-md-studio",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Markdown Studio:在 DSH 原生右侧文件预览与对话消息中渲染 Mermaid 图表、KaTeX 公式、GFM 表格、任务列表、脚注及代码高亮。渲染引擎随包内置,完全离线可用。 / Native DSH right-sidebar Markdown preview with Mermaid diagrams, KaTeX math, GFM tables and syntax highlighting — fully offline.",
5
5
  "keywords": [
6
6
  "deepseek-harness",