@presentation-md/mcp-server 1.2.0 → 1.3.0
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/dist/lib/html-metrics.d.ts +14 -0
- package/dist/lib/html-metrics.js +389 -0
- package/dist/lib/html-metrics.js.map +1 -0
- package/dist/lib/resolve-themes.d.ts +4 -0
- package/dist/lib/resolve-themes.js +30 -0
- package/dist/lib/resolve-themes.js.map +1 -0
- package/dist/lib/screenshot-slides.d.ts +27 -0
- package/dist/lib/screenshot-slides.js +204 -0
- package/dist/lib/screenshot-slides.js.map +1 -0
- package/dist/tools/export-deck.js +4 -2
- package/dist/tools/export-deck.js.map +1 -1
- package/dist/tools/generate-deck-prompt.js +3 -3
- package/dist/tools/generate-deck-prompt.js.map +1 -1
- package/dist/tools/judge-deck.js +296 -23
- package/dist/tools/judge-deck.js.map +1 -1
- package/dist/tools/preview-themes.js +3 -2
- package/dist/tools/preview-themes.js.map +1 -1
- package/dist/tools/render-deck.js +3 -2
- package/dist/tools/render-deck.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T2/T3 slide screenshots via headless Chrome/Chromium.
|
|
3
|
+
* Isolates each .slide into its own mini-HTML so capture does not depend on
|
|
4
|
+
* hash-scroll timing (more reliable than #__shot for headless Chrome).
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
|
+
import { constants } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { randomBytes } from "node:crypto";
|
|
12
|
+
const CHROME_CANDIDATES = [
|
|
13
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
14
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
15
|
+
"google-chrome",
|
|
16
|
+
"chromium",
|
|
17
|
+
"chromium-browser",
|
|
18
|
+
"chrome",
|
|
19
|
+
];
|
|
20
|
+
async function existsExecutable(path) {
|
|
21
|
+
try {
|
|
22
|
+
await access(path, constants.X_OK);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function which(cmd) {
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
const child = spawn("which", [cmd]);
|
|
32
|
+
let out = "";
|
|
33
|
+
child.stdout.on("data", (d) => {
|
|
34
|
+
out += d.toString();
|
|
35
|
+
});
|
|
36
|
+
child.on("close", (code) => {
|
|
37
|
+
const p = out.trim();
|
|
38
|
+
resolve(code === 0 && p ? p : undefined);
|
|
39
|
+
});
|
|
40
|
+
child.on("error", () => resolve(undefined));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export async function findChrome() {
|
|
44
|
+
for (const c of CHROME_CANDIDATES) {
|
|
45
|
+
if (c.includes("/")) {
|
|
46
|
+
if (await existsExecutable(c))
|
|
47
|
+
return c;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const found = await which(c);
|
|
51
|
+
if (found && (await existsExecutable(found)))
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const OPEN_TAG_RE = /<(section|div)\b[^>]*class\s*=\s*("[^"]*"|'[^']*')[^>]*>/gi;
|
|
58
|
+
function hasSlideClass(quoted) {
|
|
59
|
+
return quoted.slice(1, -1).split(/\s+/).includes("slide");
|
|
60
|
+
}
|
|
61
|
+
/** Extract outer HTML of each top-level .slide element. */
|
|
62
|
+
export function extractSlideChunks(html) {
|
|
63
|
+
const opens = [];
|
|
64
|
+
OPEN_TAG_RE.lastIndex = 0;
|
|
65
|
+
let m;
|
|
66
|
+
while ((m = OPEN_TAG_RE.exec(html))) {
|
|
67
|
+
if (hasSlideClass(m[2])) {
|
|
68
|
+
opens.push({ start: m.index, end: m.index + m[0].length, tag: m[1].toLowerCase() });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const chunks = [];
|
|
72
|
+
for (let i = 0; i < opens.length; i++) {
|
|
73
|
+
const start = opens[i].start;
|
|
74
|
+
const end = i + 1 < opens.length ? opens[i + 1].start : html.length;
|
|
75
|
+
let slice = html.slice(start, end);
|
|
76
|
+
const close = new RegExp(`</${opens[i].tag}\\s*>`, "i");
|
|
77
|
+
const closeMatch = slice.match(close);
|
|
78
|
+
if (closeMatch && closeMatch.index != null) {
|
|
79
|
+
slice = slice.slice(0, closeMatch.index + closeMatch[0].length);
|
|
80
|
+
}
|
|
81
|
+
chunks.push(slice);
|
|
82
|
+
}
|
|
83
|
+
return chunks;
|
|
84
|
+
}
|
|
85
|
+
/** Build a one-slide deck HTML that forces reveals visible (no scroll needed). */
|
|
86
|
+
export function isolateSlideHtml(fullHtml, slideOuterHtml) {
|
|
87
|
+
const headMatch = fullHtml.match(/<head\b[^>]*>[\s\S]*?<\/head>/i);
|
|
88
|
+
const deckAttr = fullHtml.match(/<main\b[^>]*class\s*=\s*["'][^"']*deck[^"']*["'][^>]*>/i) ??
|
|
89
|
+
fullHtml.match(/<(?:main|div)\b[^>]*data-surface\s*=\s*["'][^"']+["'][^>]*>/i);
|
|
90
|
+
const openDeck = deckAttr?.[0] ?? `<main class="deck">`;
|
|
91
|
+
const head = headMatch?.[0] ?? '<head><meta charset="utf-8"/></head>';
|
|
92
|
+
const forceCss = `<style>
|
|
93
|
+
html,body{margin:0;padding:0;overflow:hidden;height:100%;}
|
|
94
|
+
html{scroll-snap-type:none !important;}
|
|
95
|
+
.slide{min-height:100vh !important;height:100vh !important;}
|
|
96
|
+
.reveal{opacity:1 !important;transform:none !important;animation:none !important;}
|
|
97
|
+
.slide .reveal,.slide.in-view .reveal{opacity:1 !important;}
|
|
98
|
+
.nav-hint,.pmd-attribution{display:none !important;}
|
|
99
|
+
</style>`;
|
|
100
|
+
return `<!doctype html><html>${head}${forceCss}<body>${openDeck}${slideOuterHtml}</main>
|
|
101
|
+
<script>document.querySelectorAll(".slide,.reveal").forEach(function(el){el.classList.add("in-view");});</script>
|
|
102
|
+
</body></html>`;
|
|
103
|
+
}
|
|
104
|
+
function readPngSize(buf) {
|
|
105
|
+
if (buf.length < 24)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (buf[0] !== 0x89 || buf[1] !== 0x50)
|
|
108
|
+
return undefined;
|
|
109
|
+
const width = buf.readUInt32BE(16);
|
|
110
|
+
const height = buf.readUInt32BE(20);
|
|
111
|
+
if (!width || !height)
|
|
112
|
+
return undefined;
|
|
113
|
+
return { width, height };
|
|
114
|
+
}
|
|
115
|
+
function runChrome(chrome, args, timeoutMs = 25000) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const child = spawn(chrome, args, { stdio: "ignore" });
|
|
118
|
+
const t = setTimeout(() => {
|
|
119
|
+
child.kill("SIGKILL");
|
|
120
|
+
resolve({ code: null });
|
|
121
|
+
}, timeoutMs);
|
|
122
|
+
child.on("close", (code) => {
|
|
123
|
+
clearTimeout(t);
|
|
124
|
+
resolve({ code });
|
|
125
|
+
});
|
|
126
|
+
child.on("error", () => {
|
|
127
|
+
clearTimeout(t);
|
|
128
|
+
resolve({ code: null });
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
export async function screenshotSlides(html, opts = {}) {
|
|
133
|
+
const chrome = await findChrome();
|
|
134
|
+
if (!chrome) {
|
|
135
|
+
return {
|
|
136
|
+
ok: false,
|
|
137
|
+
chrome_missing: true,
|
|
138
|
+
shots: [],
|
|
139
|
+
detail: "NO_CHROME: install Google Chrome/Chromium, or fall back to T1 HTML metrics only.",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const width = opts.width ?? 1600;
|
|
143
|
+
const height = opts.height ?? 900;
|
|
144
|
+
const shotsDir = opts.shotsDir ??
|
|
145
|
+
join(tmpdir(), `pmd-judge-shots-${randomBytes(6).toString("hex")}`);
|
|
146
|
+
await mkdir(shotsDir, { recursive: true });
|
|
147
|
+
await writeFile(join(shotsDir, "deck.html"), html, "utf-8");
|
|
148
|
+
const chunks = extractSlideChunks(html);
|
|
149
|
+
const n = Math.min(Math.max(chunks.length, 1), opts.maxSlides ?? 40);
|
|
150
|
+
const shots = [];
|
|
151
|
+
for (let i = 1; i <= n; i++) {
|
|
152
|
+
const idx = String(i).padStart(2, "0");
|
|
153
|
+
const outPath = join(shotsDir, `slide-${idx}.png`);
|
|
154
|
+
const chunk = chunks[i - 1] ?? `<section class="slide"><p>missing slide ${i}</p></section>`;
|
|
155
|
+
const isolated = isolateSlideHtml(html, chunk);
|
|
156
|
+
const isoPath = join(shotsDir, `slide-${idx}.html`);
|
|
157
|
+
await writeFile(isoPath, isolated, "utf-8");
|
|
158
|
+
await runChrome(chrome, [
|
|
159
|
+
"--headless=new",
|
|
160
|
+
"--disable-gpu",
|
|
161
|
+
"--hide-scrollbars",
|
|
162
|
+
"--no-first-run",
|
|
163
|
+
"--no-default-browser-check",
|
|
164
|
+
`--window-size=${width},${height}`,
|
|
165
|
+
"--virtual-time-budget=5000",
|
|
166
|
+
"--run-all-compositor-stages-before-draw",
|
|
167
|
+
`--screenshot=${outPath}`,
|
|
168
|
+
`file://${isoPath}`,
|
|
169
|
+
]);
|
|
170
|
+
try {
|
|
171
|
+
const buf = await readFile(outPath);
|
|
172
|
+
const size = readPngSize(buf);
|
|
173
|
+
const meta = {
|
|
174
|
+
slide: i,
|
|
175
|
+
path: outPath,
|
|
176
|
+
bytes: buf.length,
|
|
177
|
+
width: size?.width,
|
|
178
|
+
height: size?.height,
|
|
179
|
+
};
|
|
180
|
+
if (buf.length < 4_000) {
|
|
181
|
+
meta.warn = "shot looks near-empty (tiny file) — check overflow/blank slide";
|
|
182
|
+
}
|
|
183
|
+
shots.push(meta);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
shots.push({
|
|
187
|
+
slide: i,
|
|
188
|
+
path: outPath,
|
|
189
|
+
bytes: 0,
|
|
190
|
+
warn: "screenshot file missing after Chrome run",
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
ok: shots.some((s) => s.bytes > 0),
|
|
196
|
+
chrome_path: chrome,
|
|
197
|
+
shots_dir: shotsDir,
|
|
198
|
+
shots,
|
|
199
|
+
detail: shots.every((s) => s.bytes > 0)
|
|
200
|
+
? `Captured ${shots.length} isolated slide screenshot(s).`
|
|
201
|
+
: `Partial capture: ${shots.filter((s) => s.bytes > 0).length}/${shots.length} ok.`,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=screenshot-slides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot-slides.js","sourceRoot":"","sources":["../../src/lib/screenshot-slides.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,iBAAiB,GAAG;IACxB,8DAA8D;IAC9D,oDAAoD;IACpD,eAAe;IACf,UAAU;IACV,kBAAkB;IAClB,QAAQ;CACT,CAAC;AAoBF,KAAK,UAAU,gBAAgB,CAAC,IAAY;IAC1C,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,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MAAM;QACnB,SAAS,EAAE,QAAQ;QACnB,KAAK;QACL,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;YACrC,CAAC,CAAC,YAAY,KAAK,CAAC,MAAM,gCAAgC;YAC1D,CAAC,CAAC,oBAAoB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,MAAM;KACtF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writeFile } from "node:fs/promises";
|
|
2
|
-
import { renderDeck, renderDeckPptx
|
|
2
|
+
import { renderDeck, renderDeckPptx } from "@presentation-md/render";
|
|
3
|
+
import { resolveThemesDir } from "../lib/resolve-themes.js";
|
|
3
4
|
function applyThemeOverride(rawJson, theme) {
|
|
4
5
|
if (!theme)
|
|
5
6
|
return rawJson;
|
|
@@ -53,7 +54,7 @@ export const exportDeckTool = {
|
|
|
53
54
|
const warnings = [];
|
|
54
55
|
const slide_count = slideCountOf(deckJson);
|
|
55
56
|
if (format === "html") {
|
|
56
|
-
const html = await renderDeck(deckJson,
|
|
57
|
+
const html = await renderDeck(deckJson, resolveThemesDir());
|
|
57
58
|
const result = {
|
|
58
59
|
format,
|
|
59
60
|
slide_count,
|
|
@@ -68,6 +69,7 @@ export const exportDeckTool = {
|
|
|
68
69
|
return result;
|
|
69
70
|
}
|
|
70
71
|
const buffer = await renderDeckPptx(deckJson, {
|
|
72
|
+
...resolveThemesDir(),
|
|
71
73
|
onWarn: (msg) => warnings.push(msg),
|
|
72
74
|
});
|
|
73
75
|
const result = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-deck.js","sourceRoot":"","sources":["../../src/tools/export-deck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE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AAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC;YAC5D,MAAM,MAAM,GAA0E;gBACpF,MAAM;gBACN,WAAW;aACZ,CAAC;YACF,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC3C,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;YACrB,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE;YAC5C,GAAG,gBAAgB,EAAE;YACrB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;SACpC,CAAC,CAAC;QAEH,MAAM,MAAM,GAOR;YACF,MAAM;YACN,WAAW;YACX,WAAW,EAAE,MAAM,CAAC,UAAU;YAC9B,QAAQ;SACT,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACpC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join, dirname } from "node:path";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { loadTheme } from "@presentation-md/core";
|
|
5
|
-
import {
|
|
5
|
+
import { resolveThemesDir } from "../lib/resolve-themes.js";
|
|
6
6
|
function getCoreRoot() {
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const coreMain = require.resolve("@presentation-md/core");
|
|
@@ -23,9 +23,9 @@ export const generateDeckPromptTool = {
|
|
|
23
23
|
const themeName = input["theme"] ?? "default-tech";
|
|
24
24
|
const intent = input["intent"] ?? "";
|
|
25
25
|
const coreRoot = getCoreRoot();
|
|
26
|
-
const themesDir =
|
|
26
|
+
const { themesDir, fallbackThemesDirs } = resolveThemesDir();
|
|
27
27
|
const [theme, skill, deckSchemaReference, stunning25, themesMd] = await Promise.all([
|
|
28
|
-
loadTheme(themeName, { themesDir }),
|
|
28
|
+
loadTheme(themeName, { themesDir, fallbackThemesDirs }),
|
|
29
29
|
readFile(join(coreRoot, "SKILL.md"), "utf-8"),
|
|
30
30
|
readFile(join(coreRoot, "references", "deck-schema.md"), "utf-8"),
|
|
31
31
|
readFile(join(coreRoot, "references", "stunning-25.md"), "utf-8").catch(() => ""),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-deck-prompt.js","sourceRoot":"","sources":["../../src/tools/generate-deck-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"generate-deck-prompt.js","sourceRoot":"","sources":["../../src/tools/generate-deck-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,SAAS,WAAW;IAClB,MAAM,OAAO,G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YAAY,EAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;YACjF,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;SAC7E,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG;YACnB,iCAAiC;YACjC,iFAAiF;YACjF,iEAAiE;YACjE,wHAAwH;YACxH,sCAAsC;YACtC,kGAAkG;YAClG,iHAAiH;SAClH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,MAAM;YACN,aAAa,EAAE,YAAY;YAC3B,KAAK;YACL,qBAAqB,EAAE,mBAAmB;YAC1C,gBAAgB,EAAE,QAAQ,IAAI,SAAS;YACvC,qBAAqB,EAAE,UAAU,IAAI,SAAS;YAC9C,OAAO,EAAE,KAAK,CAAC,OAA4C;YAC3D,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/tools/judge-deck.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
1
7
|
import { validateDeckJson } from "@presentation-md/core";
|
|
8
|
+
import { renderDeck } from "@presentation-md/render";
|
|
9
|
+
import { analyzeHtmlDeck } from "../lib/html-metrics.js";
|
|
10
|
+
import { screenshotSlides } from "../lib/screenshot-slides.js";
|
|
11
|
+
import { resolveThemesDir } from "../lib/resolve-themes.js";
|
|
2
12
|
const WORD_GATE = 40;
|
|
3
13
|
const IGNORE_KEYS = new Set([
|
|
4
14
|
"layout",
|
|
@@ -27,6 +37,18 @@ const IGNORE_KEYS = new Set([
|
|
|
27
37
|
"html",
|
|
28
38
|
"tone",
|
|
29
39
|
]);
|
|
40
|
+
const RUBRIC_DIMENSIONS = [
|
|
41
|
+
{ key: "narrative", weight: 12, label: "Narrative & tension" },
|
|
42
|
+
{ key: "clarity", weight: 12, label: "Message clarity / 3-second rule" },
|
|
43
|
+
{ key: "typography", weight: 11, label: "Typography system" },
|
|
44
|
+
{ key: "color", weight: 11, label: "Colour discipline" },
|
|
45
|
+
{ key: "layout_flat", weight: 11, label: "Layout, whitespace & flat-system fidelity" },
|
|
46
|
+
{ key: "brand", weight: 10, label: "Brand fidelity" },
|
|
47
|
+
{ key: "craft", weight: 10, label: "Craft & polish" },
|
|
48
|
+
{ key: "proof", weight: 9, label: "Data & proof integrity" },
|
|
49
|
+
{ key: "variety", weight: 8, label: "Layout variety" },
|
|
50
|
+
{ key: "close", weight: 6, label: "The close / CTA" },
|
|
51
|
+
];
|
|
30
52
|
function countWords(text) {
|
|
31
53
|
return text.split(/\s+/).filter((w) => /[A-Za-z0-9]/.test(w)).length;
|
|
32
54
|
}
|
|
@@ -50,7 +72,7 @@ function iterTextBlocks(obj) {
|
|
|
50
72
|
}
|
|
51
73
|
return out;
|
|
52
74
|
}
|
|
53
|
-
/** T1
|
|
75
|
+
/** T0/T1 structural judge (deck JSON) — ports deck-design-judge metrics gates. */
|
|
54
76
|
function judgeDeckJson(deck) {
|
|
55
77
|
const flags = [];
|
|
56
78
|
const slides = Array.isArray(deck["slides"]) ? deck["slides"] : [];
|
|
@@ -151,48 +173,299 @@ function judgeDeckJson(deck) {
|
|
|
151
173
|
flags,
|
|
152
174
|
};
|
|
153
175
|
}
|
|
176
|
+
function parseTier(raw) {
|
|
177
|
+
const s = String(raw ?? "t1").toLowerCase().replace(/^tier[-_]?/, "");
|
|
178
|
+
if (s === "t0" || s === "0")
|
|
179
|
+
return "t0";
|
|
180
|
+
if (s === "t2" || s === "2")
|
|
181
|
+
return "t2";
|
|
182
|
+
if (s === "t3" || s === "3")
|
|
183
|
+
return "t3";
|
|
184
|
+
return "t1";
|
|
185
|
+
}
|
|
186
|
+
function resolveJudgeScriptsDir() {
|
|
187
|
+
if (process.env.PRESENTATION_MD_JUDGE_SCRIPTS) {
|
|
188
|
+
return process.env.PRESENTATION_MD_JUDGE_SCRIPTS;
|
|
189
|
+
}
|
|
190
|
+
// monorepo: packages/mcp-server/dist/tools → ../../../skills/deck-design-judge/scripts
|
|
191
|
+
try {
|
|
192
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
193
|
+
const candidate = join(here, "..", "..", "..", "..", "skills", "deck-design-judge", "scripts");
|
|
194
|
+
return candidate;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function runPythonJson(script, args, timeoutMs = 180_000) {
|
|
201
|
+
return new Promise((resolve) => {
|
|
202
|
+
const child = spawn("python3", [script, ...args], { stdio: ["ignore", "pipe", "pipe"] });
|
|
203
|
+
let stdout = "";
|
|
204
|
+
let stderr = "";
|
|
205
|
+
const t = setTimeout(() => {
|
|
206
|
+
child.kill("SIGKILL");
|
|
207
|
+
resolve({ ok: false, stdout, stderr: stderr + "\n(timeout)", code: null });
|
|
208
|
+
}, timeoutMs);
|
|
209
|
+
child.stdout.on("data", (d) => {
|
|
210
|
+
stdout += d.toString();
|
|
211
|
+
});
|
|
212
|
+
child.stderr.on("data", (d) => {
|
|
213
|
+
stderr += d.toString();
|
|
214
|
+
});
|
|
215
|
+
child.on("close", (code) => {
|
|
216
|
+
clearTimeout(t);
|
|
217
|
+
resolve({ ok: code === 0, stdout, stderr, code });
|
|
218
|
+
});
|
|
219
|
+
child.on("error", (err) => {
|
|
220
|
+
clearTimeout(t);
|
|
221
|
+
resolve({ ok: false, stdout, stderr: String(err), code: null });
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function agentRubricPayload(shots) {
|
|
226
|
+
return {
|
|
227
|
+
status: "agent_rubric",
|
|
228
|
+
note: "T3 multi-model panel needs API keys + skills/deck-design-judge/scripts/judge_panel.py. " +
|
|
229
|
+
"Open each shot, score every dimension 0–5 with evidence, prefer the lower anchor when merely fine.",
|
|
230
|
+
dimensions: RUBRIC_DIMENSIONS,
|
|
231
|
+
shots: shots.map((s) => ({ slide: s.slide, path: s.path })),
|
|
232
|
+
instruction: "Return judge.json shape: { tier:'t3', dimensions:{ [key]: { score:0-5, evidence:string } }, summary?: string }. " +
|
|
233
|
+
"Any gate hit caps grade at C / Not ready.",
|
|
234
|
+
};
|
|
235
|
+
}
|
|
154
236
|
export const judgeDeckTool = {
|
|
155
237
|
name: "judge_deck",
|
|
156
|
-
description: "
|
|
238
|
+
description: "Design judge for Deck JSON / rendered HTML (deck-design-judge tiers). " +
|
|
239
|
+
"t0/t1: structural JSON gates. t2: render + HTML metrics (G1–G5) + Chrome screenshots when available. " +
|
|
240
|
+
"t3: t2 + multi-model panel when judge_panel.py + API keys exist; otherwise returns an agent rubric payload with shot paths.",
|
|
157
241
|
inputSchema: {
|
|
158
242
|
type: "object",
|
|
159
243
|
properties: {
|
|
160
244
|
json: {
|
|
161
245
|
type: "string",
|
|
162
|
-
description: "Deck JSON string to judge",
|
|
246
|
+
description: "Deck JSON string to judge (required unless html is provided for t2/t3)",
|
|
247
|
+
},
|
|
248
|
+
html: {
|
|
249
|
+
type: "string",
|
|
250
|
+
description: "Optional pre-rendered HTML. When omitted for t2/t3, the tool renders from json.",
|
|
251
|
+
},
|
|
252
|
+
tier: {
|
|
253
|
+
type: "string",
|
|
254
|
+
enum: ["t0", "t1", "t2", "t3"],
|
|
255
|
+
description: "Judge tier (default t1). t2/t3 need Chrome for screenshots; t3 prefers judge_panel.py.",
|
|
256
|
+
},
|
|
257
|
+
theme: {
|
|
258
|
+
type: "string",
|
|
259
|
+
description: "Theme override when rendering for t2/t3",
|
|
260
|
+
},
|
|
261
|
+
shots_dir: {
|
|
262
|
+
type: "string",
|
|
263
|
+
description: "Directory to write T2/T3 PNG screenshots (default: temp dir)",
|
|
264
|
+
},
|
|
265
|
+
skip_screenshots: {
|
|
266
|
+
type: "boolean",
|
|
267
|
+
description: "If true, t2/t3 skip Chrome shots and only run HTML metrics",
|
|
268
|
+
},
|
|
269
|
+
max_slides: {
|
|
270
|
+
type: "number",
|
|
271
|
+
description: "Cap screenshots to first N slides (default 40)",
|
|
163
272
|
},
|
|
164
273
|
},
|
|
165
|
-
required: [
|
|
274
|
+
required: [],
|
|
166
275
|
},
|
|
167
276
|
handler: async (input) => {
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
277
|
+
const tier = parseTier(input["tier"]);
|
|
278
|
+
const json = input["json"] != null ? String(input["json"]) : "";
|
|
279
|
+
const htmlIn = input["html"] != null ? String(input["html"]) : "";
|
|
280
|
+
const skipShots = Boolean(input["skip_screenshots"]);
|
|
281
|
+
const shotsDir = input["shots_dir"] != null ? String(input["shots_dir"]) : undefined;
|
|
282
|
+
const maxSlides = typeof input["max_slides"] === "number" ? Math.max(1, Math.floor(input["max_slides"])) : 40;
|
|
283
|
+
const theme = input["theme"] != null ? String(input["theme"]) : undefined;
|
|
284
|
+
if (!json && !htmlIn) {
|
|
175
285
|
return {
|
|
176
286
|
valid: false,
|
|
177
287
|
pass: false,
|
|
178
|
-
|
|
288
|
+
tier,
|
|
289
|
+
schema_errors: ["Provide json and/or html"],
|
|
179
290
|
metrics: {},
|
|
180
|
-
flags: [{ id: "
|
|
181
|
-
next: "
|
|
291
|
+
flags: [{ id: "input", severity: "error", detail: "json or html required" }],
|
|
292
|
+
next: "Pass deck JSON (and optionally pre-rendered html).",
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
let deck;
|
|
296
|
+
let schema = { valid: true, errors: [] };
|
|
297
|
+
if (json) {
|
|
298
|
+
schema = validateDeckJson(json);
|
|
299
|
+
try {
|
|
300
|
+
deck = JSON.parse(json);
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
return {
|
|
304
|
+
valid: false,
|
|
305
|
+
pass: false,
|
|
306
|
+
tier,
|
|
307
|
+
schema_errors: [`Invalid JSON: ${err.message}`],
|
|
308
|
+
metrics: {},
|
|
309
|
+
flags: [{ id: "parse", severity: "error", detail: "Could not parse deck JSON" }],
|
|
310
|
+
next: "Fix JSON, then re-run judge_deck.",
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const structural = deck ? judgeDeckJson(deck) : { metrics: { mode: "none" }, flags: [] };
|
|
315
|
+
// T0 = metrics-only JSON (no visual-beat craft heuristics beyond density) — keep same structural for simplicity
|
|
316
|
+
if (tier === "t0" || tier === "t1") {
|
|
317
|
+
const gateHits = structural.flags.filter((f) => f.severity === "gate").length;
|
|
318
|
+
const pass = schema.valid && gateHits === 0;
|
|
319
|
+
return {
|
|
320
|
+
valid: schema.valid,
|
|
321
|
+
pass,
|
|
322
|
+
tier,
|
|
323
|
+
schema_errors: schema.valid ? [] : schema.errors,
|
|
324
|
+
metrics: structural.metrics,
|
|
325
|
+
flags: structural.flags,
|
|
326
|
+
next: pass
|
|
327
|
+
? tier === "t0"
|
|
328
|
+
? "T0 density gates clear. Escalate to judge_deck tier=t1/t2 before ship."
|
|
329
|
+
: "Structural gates clear. Escalate to judge_deck tier=t2 for HTML metrics + screenshots before final ship."
|
|
330
|
+
: "Fix gate/warn flags (and schema errors), then re-run judge_deck before shipping.",
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
// ── T2 / T3: render + HTML metrics + optional screenshots ──
|
|
334
|
+
let html = htmlIn;
|
|
335
|
+
let rendered_path;
|
|
336
|
+
if (!html) {
|
|
337
|
+
if (!json) {
|
|
338
|
+
return {
|
|
339
|
+
valid: false,
|
|
340
|
+
pass: false,
|
|
341
|
+
tier,
|
|
342
|
+
schema_errors: ["html or json required for t2/t3"],
|
|
343
|
+
metrics: {},
|
|
344
|
+
flags: [{ id: "input", severity: "error", detail: "Need json to render or html to analyze" }],
|
|
345
|
+
next: "Pass json (to render) or html (pre-rendered).",
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
let deckJson = json;
|
|
349
|
+
if (theme && deck) {
|
|
350
|
+
const meta = { ...(deck["meta"] ?? {}), theme };
|
|
351
|
+
deckJson = JSON.stringify({ ...deck, meta });
|
|
352
|
+
}
|
|
353
|
+
html = await renderDeck(deckJson, resolveThemesDir());
|
|
354
|
+
const work = shotsDir ?? join(tmpdir(), `pmd-judge-${randomBytes(6).toString("hex")}`);
|
|
355
|
+
await mkdir(work, { recursive: true });
|
|
356
|
+
rendered_path = join(work, "deck.html");
|
|
357
|
+
await writeFile(rendered_path, html, "utf-8");
|
|
358
|
+
}
|
|
359
|
+
const htmlJudged = analyzeHtmlDeck(html);
|
|
360
|
+
// Merge structural craft warnings (cadence etc.) that HTML mode lacks
|
|
361
|
+
const mergedFlags = [...htmlJudged.flags];
|
|
362
|
+
for (const f of structural.flags) {
|
|
363
|
+
if (["cadence", "visual_beat", "asymmetry", "data_viz"].includes(f.id)) {
|
|
364
|
+
if (!mergedFlags.some((x) => x.id === f.id && x.detail === f.detail)) {
|
|
365
|
+
mergedFlags.push(f);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
let screenshots;
|
|
370
|
+
if (!skipShots) {
|
|
371
|
+
screenshots = await screenshotSlides(html, {
|
|
372
|
+
shotsDir: shotsDir ?? (rendered_path ? dirname(rendered_path) : undefined),
|
|
373
|
+
maxSlides,
|
|
374
|
+
});
|
|
375
|
+
for (const shot of screenshots.shots) {
|
|
376
|
+
if (shot.warn) {
|
|
377
|
+
mergedFlags.push({
|
|
378
|
+
id: "shot_qa",
|
|
379
|
+
severity: "warn",
|
|
380
|
+
slide: shot.slide,
|
|
381
|
+
detail: `Slide ${shot.slide}: ${shot.warn}`,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
screenshots = {
|
|
388
|
+
ok: false,
|
|
389
|
+
shots: [],
|
|
390
|
+
detail: "Screenshots skipped (skip_screenshots=true).",
|
|
182
391
|
};
|
|
183
392
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
393
|
+
let panel = undefined;
|
|
394
|
+
if (tier === "t3") {
|
|
395
|
+
const scriptsDir = resolveJudgeScriptsDir();
|
|
396
|
+
const panelScript = scriptsDir ? join(scriptsDir, "judge_panel.py") : undefined;
|
|
397
|
+
const hasKey = Boolean(process.env.ANTHROPIC_API_KEY) ||
|
|
398
|
+
Boolean(process.env.OPENROUTER_API_KEY) ||
|
|
399
|
+
Boolean(process.env.OPENAI_API_KEY);
|
|
400
|
+
if (panelScript && hasKey && rendered_path) {
|
|
401
|
+
const outJudge = join(dirname(rendered_path), "judge.json");
|
|
402
|
+
const metricsPath = join(dirname(rendered_path), "metrics.json");
|
|
403
|
+
await writeFile(metricsPath, JSON.stringify({ metrics: htmlJudged.metrics, flags: mergedFlags }, null, 2), "utf-8");
|
|
404
|
+
const run = await runPythonJson(panelScript, [
|
|
405
|
+
rendered_path,
|
|
406
|
+
"--metrics",
|
|
407
|
+
metricsPath,
|
|
408
|
+
"--out",
|
|
409
|
+
outJudge,
|
|
410
|
+
]);
|
|
411
|
+
if (run.ok) {
|
|
412
|
+
try {
|
|
413
|
+
const { readFile } = await import("node:fs/promises");
|
|
414
|
+
panel = JSON.parse(await readFile(outJudge, "utf-8"));
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
panel = { status: "panel_wrote_unreadable", stderr: run.stderr };
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
panel = {
|
|
422
|
+
...agentRubricPayload(screenshots.shots),
|
|
423
|
+
panel_error: run.stderr || run.stdout || "judge_panel.py failed",
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
panel = {
|
|
429
|
+
...agentRubricPayload(screenshots.shots),
|
|
430
|
+
skipped_reason: !panelScript
|
|
431
|
+
? "judge_panel.py not found (set PRESENTATION_MD_JUDGE_SCRIPTS)"
|
|
432
|
+
: !hasKey
|
|
433
|
+
? "No ANTHROPIC_API_KEY / OPENROUTER_API_KEY / OPENAI_API_KEY — agent should score rubric with shots open"
|
|
434
|
+
: "Need rendered_path for panel",
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const gateHits = mergedFlags.filter((f) => f.severity === "gate").length;
|
|
439
|
+
const pass = schema.valid && gateHits === 0 && (screenshots.chrome_missing ? true : screenshots.ok !== false || skipShots);
|
|
187
440
|
return {
|
|
188
441
|
valid: schema.valid,
|
|
189
|
-
pass,
|
|
442
|
+
pass: schema.valid && gateHits === 0,
|
|
443
|
+
tier,
|
|
190
444
|
schema_errors: schema.valid ? [] : schema.errors,
|
|
191
|
-
metrics:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
:
|
|
445
|
+
metrics: {
|
|
446
|
+
...htmlJudged.metrics,
|
|
447
|
+
structural_layouts: structural.metrics["layouts"],
|
|
448
|
+
screenshots_ok: screenshots.ok,
|
|
449
|
+
chrome_missing: screenshots.chrome_missing ?? false,
|
|
450
|
+
},
|
|
451
|
+
flags: mergedFlags,
|
|
452
|
+
html_path: rendered_path,
|
|
453
|
+
screenshots: {
|
|
454
|
+
ok: screenshots.ok,
|
|
455
|
+
chrome_missing: screenshots.chrome_missing ?? false,
|
|
456
|
+
shots_dir: screenshots.shots_dir,
|
|
457
|
+
shots: screenshots.shots,
|
|
458
|
+
detail: screenshots.detail,
|
|
459
|
+
},
|
|
460
|
+
panel,
|
|
461
|
+
next: !schema.valid || gateHits > 0
|
|
462
|
+
? "Fix gate/schema issues, then re-run judge_deck at the same tier."
|
|
463
|
+
: screenshots.chrome_missing
|
|
464
|
+
? "HTML metrics clear but Chrome missing — install Chrome for real T2 shots, or open html_path and review visually."
|
|
465
|
+
: tier === "t3" && panel && typeof panel === "object" && panel.status === "agent_rubric"
|
|
466
|
+
? "Open each shot path, score the 10 rubric dimensions, apply top fixes, re-judge."
|
|
467
|
+
: "T2/T3 visual QA artifacts ready — review shots, apply top fixes if any warns remain, then ship.",
|
|
468
|
+
screenshots_pass: pass,
|
|
196
469
|
};
|
|
197
470
|
},
|
|
198
471
|
};
|