@appeeky/open-slideshow 0.0.0-stage → 0.1.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +9 -0
  5. package/dist/brand.d.ts +55 -0
  6. package/dist/brand.js +246 -0
  7. package/dist/cli.d.ts +1 -0
  8. package/dist/cli.js +261 -0
  9. package/dist/decks.d.ts +44 -0
  10. package/dist/decks.js +90 -0
  11. package/dist/fonts.d.ts +45 -0
  12. package/dist/fonts.js +243 -0
  13. package/dist/gallery.d.ts +35 -0
  14. package/dist/gallery.js +109 -0
  15. package/dist/images.d.ts +49 -0
  16. package/dist/images.js +223 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.js +13 -0
  19. package/dist/lint.d.ts +33 -0
  20. package/dist/lint.js +181 -0
  21. package/dist/mcp.d.ts +3 -0
  22. package/dist/mcp.js +233 -0
  23. package/dist/publish.d.ts +100 -0
  24. package/dist/publish.js +401 -0
  25. package/dist/render.d.ts +73 -0
  26. package/dist/render.js +515 -0
  27. package/dist/schedule.d.ts +19 -0
  28. package/dist/schedule.js +114 -0
  29. package/dist/schema.d.ts +1004 -0
  30. package/dist/schema.js +174 -0
  31. package/dist/shape.d.ts +31 -0
  32. package/dist/shape.js +169 -0
  33. package/dist/skill.d.ts +7 -0
  34. package/dist/skill.js +17 -0
  35. package/dist/templates.d.ts +44 -0
  36. package/dist/templates.js +185 -0
  37. package/dist/text.d.ts +40 -0
  38. package/dist/text.js +230 -0
  39. package/dist/themes.d.ts +43 -0
  40. package/dist/themes.js +202 -0
  41. package/dist/version.d.ts +1 -0
  42. package/dist/version.js +1 -0
  43. package/dist/viral.d.ts +12 -0
  44. package/dist/viral.js +35 -0
  45. package/dist/workspace.d.ts +80 -0
  46. package/dist/workspace.js +306 -0
  47. package/package.json +65 -4
  48. package/skills/open-slideshow/SKILL.md +52 -0
  49. package/skills/open-slideshow/references/brand.md +54 -0
  50. package/skills/open-slideshow/references/channels.md +63 -0
  51. package/skills/open-slideshow/references/images.md +53 -0
  52. package/skills/open-slideshow/references/languages.md +41 -0
  53. package/skills/open-slideshow/references/publishing.md +70 -0
  54. package/skills/open-slideshow/references/review.md +74 -0
  55. package/skills/open-slideshow/references/templates.md +59 -0
  56. package/skills/open-slideshow/references/troubleshooting.md +82 -0
  57. package/skills/open-slideshow/references/writing.md +76 -0
@@ -0,0 +1,12 @@
1
+ export * from "./schema.js";
2
+ export { THEMES, getTheme } from "./themes.js";
3
+ export { openWorkspace, initWorkspace, loadDeck, saveDeck, listDecks } from "./workspace.js";
4
+ export { brandContext } from "./brand.js";
5
+ export { newDeck, updateDeck, renderDeckById } from "./decks.js";
6
+ export { lintDeck } from "./lint.js";
7
+ export { themeGallery, templateGallery } from "./gallery.js";
8
+ export { TEMPLATES, getTemplate, followsTemplate } from "./templates.js";
9
+ export { publishDeck } from "./publish.js";
10
+ export { planSlots, dueSlots } from "./schedule.js";
11
+ export { createServer } from "./mcp.js";
12
+ export { SKILL } from "./skill.js";
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // The library Appeeky Spec (and anyone) can use: open-slideshow does not depend on Spec.
2
+ export * from "./schema.js";
3
+ export { THEMES, getTheme } from "./themes.js";
4
+ export { openWorkspace, initWorkspace, loadDeck, saveDeck, listDecks } from "./workspace.js";
5
+ export { brandContext } from "./brand.js";
6
+ export { newDeck, updateDeck, renderDeckById } from "./decks.js";
7
+ export { lintDeck } from "./lint.js";
8
+ export { themeGallery, templateGallery } from "./gallery.js";
9
+ export { TEMPLATES, getTemplate, followsTemplate } from "./templates.js";
10
+ export { publishDeck } from "./publish.js";
11
+ export { planSlots, dueSlots } from "./schedule.js";
12
+ export { createServer } from "./mcp.js";
13
+ export { SKILL } from "./skill.js";
package/dist/lint.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { type RenderContext } from "./render.js";
2
+ import { type Workspace } from "./workspace.js";
3
+ import type { Deck } from "./schema.js";
4
+ export declare const LIMITS: {
5
+ tiktok: {
6
+ photos: number;
7
+ title: number;
8
+ caption: number;
9
+ hashtags: number;
10
+ };
11
+ instagram: {
12
+ photos: number;
13
+ caption: number;
14
+ hashtags: number;
15
+ };
16
+ };
17
+ export interface LintIssue {
18
+ level: "error" | "warning";
19
+ code: string;
20
+ message: string;
21
+ slide?: number;
22
+ }
23
+ export interface LintResult {
24
+ ok: boolean;
25
+ errors: LintIssue[];
26
+ warnings: LintIssue[];
27
+ }
28
+ export declare function platformsOf(deck: Deck): Set<"tiktok" | "instagram">;
29
+ export declare function captionText(deck: Deck): string;
30
+ export declare function renderContext(ws: Workspace, deck: Deck): RenderContext;
31
+ export declare function lintDeck(ws: Workspace, deck: Deck, opts?: {
32
+ platforms?: ("tiktok" | "instagram")[];
33
+ }): Promise<LintResult>;
package/dist/lint.js ADDED
@@ -0,0 +1,181 @@
1
+ import { laySlide, tipNumbers, themeFor } from "./render.js";
2
+ import { bannedPhrases, normalizeHook, usedHooks } from "./brand.js";
3
+ import { markupError, plainText } from "./text.js";
4
+ import { contrast, getTheme } from "./themes.js";
5
+ import { followsTemplate, getTemplate, shapeText, TEMPLATES } from "./templates.js";
6
+ import { imageMeta, needsAttribution } from "./images.js";
7
+ import { resolveImage } from "./workspace.js";
8
+ export const LIMITS = {
9
+ tiktok: { photos: 35, title: 90, caption: 4000, hashtags: 30 },
10
+ instagram: { photos: 20, caption: 2200, hashtags: 30 },
11
+ };
12
+ export function platformsOf(deck) {
13
+ const out = new Set();
14
+ for (const a of deck.accounts) {
15
+ const s = a.toLowerCase();
16
+ if (s.includes("tiktok"))
17
+ out.add("tiktok");
18
+ if (s.includes("instagram") || s.startsWith("ig:"))
19
+ out.add("instagram");
20
+ }
21
+ return out;
22
+ }
23
+ export function captionText(deck) {
24
+ const tags = deck.hashtags.map((h) => `#${h}`).join(" ");
25
+ return [deck.caption.trim(), tags].filter(Boolean).join("\n\n");
26
+ }
27
+ export function renderContext(ws, deck) {
28
+ const brand = ws.settings.brand;
29
+ return {
30
+ theme: themeFor({ theme: deck.theme, colors: deck.colors ?? brand.colors }),
31
+ size: deck.size,
32
+ brand: { name: brand.name ?? ws.settings.app.name, handle: brand.handle, icon: brand.icon ? resolveImage(ws, brand.icon) ?? undefined : undefined },
33
+ resolveImage: (ref) => resolveImage(ws, ref),
34
+ locale: deck.language,
35
+ };
36
+ }
37
+ const findPhrase = (text, phrase) => new RegExp(`(^|[^\\p{L}\\p{N}])${phrase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^\\p{L}\\p{N}]|$)`, "iu").test(text);
38
+ export async function lintDeck(ws, deck, opts = {}) {
39
+ const issues = [];
40
+ const add = (level, code, message, slide) => issues.push({ level, code, message, ...(slide === undefined ? {} : { slide }) });
41
+ const theme = getTheme(deck.theme);
42
+ if (!theme) {
43
+ add("error", "unknown-theme", `unknown theme "${deck.theme}"`);
44
+ return finish(issues);
45
+ }
46
+ const platforms = new Set([...platformsOf(deck), ...(opts.platforms ?? [])]);
47
+ const n = deck.slides.length;
48
+ // Structure
49
+ if (deck.slides[0]?.kind !== "cover")
50
+ add("warning", "no-cover", "the first slide is the hook: make it a cover slide");
51
+ if (deck.slides.filter((s) => s.kind === "cover").length > 1)
52
+ add("warning", "many-covers", "more than one cover slide");
53
+ if (n < 3)
54
+ add("warning", "short", `only ${n} slide${n === 1 ? "" : "s"}: slideshows with 5–8 slides keep people swiping`);
55
+ if (n > 12)
56
+ add("warning", "long", `${n} slides: past 10–12 most people stop swiping`);
57
+ if (platforms.has("instagram") && n > LIMITS.instagram.photos)
58
+ add("error", "ig-too-many", `Instagram takes at most ${LIMITS.instagram.photos} images; this deck has ${n}`);
59
+ if (platforms.has("instagram") && n < 2)
60
+ add("error", "ig-too-few", "an Instagram carousel needs at least 2 images");
61
+ if (platforms.has("tiktok") && n > LIMITS.tiktok.photos)
62
+ add("error", "tiktok-too-many", `TikTok takes at most ${LIMITS.tiktok.photos} photos`);
63
+ if (platforms.has("instagram") && deck.size === "9:16")
64
+ add("warning", "ig-916", "Instagram crops 9:16 carousel images to 4:5 in the feed; use 4:5 for Instagram");
65
+ // Template
66
+ if (deck.template) {
67
+ const t = getTemplate(deck.template);
68
+ if (!t)
69
+ add("error", "unknown-template", `unknown template "${deck.template}"; one of ${TEMPLATES.map((x) => x.id).join(", ")}`);
70
+ else if (!followsTemplate(t, deck.slides.map((s) => s.kind)))
71
+ add("warning", "template-shape", `the slides do not follow the ${t.id} template: ${shapeText(t)}. This deck: ${deck.slides.map((s) => s.kind).join(" → ")}`);
72
+ }
73
+ // Words
74
+ const banned = bannedPhrases(ws.settings);
75
+ const brand = ws.settings.brand;
76
+ const all = [];
77
+ deck.slides.forEach((s, i) => {
78
+ const texts = [s.title, s.body, ...(s.items ?? []), s.author].filter((t) => !!t);
79
+ if (!texts.length)
80
+ add("error", "empty-slide", `slide ${i + 1} has no text`, i);
81
+ for (const t of texts) {
82
+ const err = markupError(t);
83
+ if (err)
84
+ add("error", "markup", `slide ${i + 1}: ${err}`, i);
85
+ }
86
+ if (s.kind === "list" && !s.items?.length)
87
+ add("error", "list-empty", `slide ${i + 1} is a list without items`, i);
88
+ if (s.kind === "quote" && !s.title)
89
+ add("error", "quote-empty", `slide ${i + 1} is a quote without the quote (title)`, i);
90
+ if (s.kind === "cover" && !s.title)
91
+ add("error", "cover-empty", `slide ${i + 1} is a cover without a title (the hook)`, i);
92
+ const words = texts.map(plainText).join(" ").split(/\s+/).filter(Boolean).length;
93
+ if (words > 45)
94
+ add("warning", "wordy", `slide ${i + 1} has ${words} words; people read slides in about 2 seconds, keep it under 35`, i);
95
+ if (s.kind === "cover" && s.title && plainText(s.title).split(/\s+/).length > 14)
96
+ add("warning", "long-hook", `the hook has ${plainText(s.title).split(/\s+/).length} words; the best hooks are under 10`, i);
97
+ all.push(...texts.map(plainText));
98
+ if (s.image) {
99
+ const p = resolveImage(ws, s.image);
100
+ if (!p)
101
+ add("error", "image-missing", `slide ${i + 1}: image "${s.image}" is not in this workspace (import it with image_import)`, i);
102
+ }
103
+ else if (theme.design === "photo" || (s.kind === "cover" && theme.design === "magazine" && deck.full_cover)) {
104
+ add("warning", "no-image", `slide ${i + 1} has no image; the ${theme.name} theme looks best with a photo on every slide`, i);
105
+ }
106
+ if (s.kind === "app" && !brand.icon)
107
+ add("warning", "no-icon", `slide ${i + 1} shows the app but the brand has no icon (brand_set icon, or set the App Store id)`, i);
108
+ });
109
+ const text = [...all, deck.caption].join("\n");
110
+ for (const p of banned)
111
+ if (findPhrase(text, p))
112
+ add(ws.settings.strict_phrases ? "error" : "warning", "banned-phrase", `"${p}" sounds machine-written; say it plainly`);
113
+ for (const w of brand.words_to_avoid)
114
+ if (findPhrase(text, w.toLowerCase()))
115
+ add("error", "brand-word", `the brand never says "${w}"`);
116
+ for (const c of brand.claims_never) {
117
+ const key = c.toLowerCase().replace(/[^\p{L}\p{N} ]/gu, "").trim();
118
+ if (key.split(" ").length <= 4 && findPhrase(text, key))
119
+ add("error", "brand-claim", `the brand never claims "${c}"`);
120
+ }
121
+ if (/\b(lorem ipsum|todo|tbd|xxx)\b/i.test(text) || /\[[^\]]{1,30}\]/.test(text))
122
+ add("error", "placeholder", "placeholder text left in the deck");
123
+ // Hooks already used
124
+ const cover = deck.slides.find((s) => s.kind === "cover");
125
+ if (cover?.title) {
126
+ const key = normalizeHook(cover.title);
127
+ const dup = usedHooks(ws, 500).find((h) => h.deck !== deck.id && normalizeHook(h.hook) === key);
128
+ if (dup)
129
+ add("warning", "repeat-hook", `this hook was used before${dup.deck ? ` in ${dup.deck}` : ""}: "${dup.hook}"`);
130
+ }
131
+ // Caption and hashtags
132
+ const caption = captionText(deck);
133
+ if (!deck.caption.trim())
134
+ add("warning", "no-caption", "no caption");
135
+ if (platforms.has("instagram") && caption.length > LIMITS.instagram.caption)
136
+ add("error", "ig-caption", `Instagram captions are at most ${LIMITS.instagram.caption} characters; this one is ${caption.length}`);
137
+ if (caption.length > LIMITS.tiktok.caption)
138
+ add("error", "caption-long", `caption is ${caption.length} characters; TikTok takes ${LIMITS.tiktok.caption}`);
139
+ if (deck.hashtags.length > 8)
140
+ add("warning", "many-hashtags", `${deck.hashtags.length} hashtags; 3–5 relevant ones work better`);
141
+ if (new Set(deck.hashtags.map((h) => h.toLowerCase())).size !== deck.hashtags.length)
142
+ add("warning", "dup-hashtags", "the same hashtag twice");
143
+ if (/#[\p{L}\p{N}_]+/u.test(deck.caption) && deck.hashtags.length)
144
+ add("warning", "hashtags-twice", "hashtags are in the caption and in hashtags; they would be posted twice");
145
+ if (deck.tiktok?.cover_index !== undefined && deck.tiktok.cover_index >= n)
146
+ add("error", "cover-index", `tiktok.cover_index ${deck.tiktok.cover_index} is past the last slide`);
147
+ // Colours
148
+ const colors = deck.colors ?? brand.colors;
149
+ if (colors && theme.design !== "photo") {
150
+ const c = contrast(colors.fg, colors.bg);
151
+ if (c < 4.5)
152
+ add(c < 3 ? "error" : "warning", "contrast", `text colour on background has contrast ${c.toFixed(1)}:1; it needs 4.5:1 to read on a phone`);
153
+ if (theme.accent_style === "color" && contrast(colors.accent, colors.bg) < 3)
154
+ add("warning", "accent-contrast", "the accent colour is hard to see on the background");
155
+ }
156
+ // Images that need credit
157
+ const credits = deck.slides.map((s) => (s.image ? imageMeta(ws, s.image) : null)).filter(needsAttribution);
158
+ if (credits.length && !/photo|credit|cc by|📷/i.test(deck.caption))
159
+ add("warning", "attribution", `${credits.length} image(s) are CC BY: credit the authors (credits.txt is written on export; add a credit to the caption)`);
160
+ // Layout: fit every slide exactly as the renderer will.
161
+ const ctx = renderContext(ws, deck);
162
+ const nums = tipNumbers(deck.slides);
163
+ const layoutIssues = [];
164
+ for (let i = 0; i < n; i++) {
165
+ try {
166
+ const laid = await laySlide(ctx, { deck, slide: deck.slides[i], index: i, tipNumber: nums[i], dry: true });
167
+ layoutIssues.push(...laid.issues);
168
+ }
169
+ catch (e) {
170
+ add("error", "layout", `slide ${i + 1}: ${e.message}`, i);
171
+ }
172
+ }
173
+ for (const li of layoutIssues)
174
+ if (!issues.some((x) => x.code === li.code && x.slide === li.slide))
175
+ add(li.level, li.code, li.message, li.slide);
176
+ return finish(issues);
177
+ }
178
+ function finish(issues) {
179
+ const errors = issues.filter((i) => i.level === "error");
180
+ return { ok: errors.length === 0, errors, warnings: issues.filter((i) => i.level === "warning") };
181
+ }
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare function createServer(): McpServer;
3
+ export declare function startMcp(): Promise<void>;
package/dist/mcp.js ADDED
@@ -0,0 +1,233 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ import sharp from "sharp";
6
+ import { z } from "zod";
7
+ import { brandContext, ensureIcon, fetchAppStore } from "./brand.js";
8
+ import { newDeck, readManifest, renderDeckById, updateDeck } from "./decks.js";
9
+ import { templateGallery, themeGallery } from "./gallery.js";
10
+ import { TEMPLATES, templateGuide } from "./templates.js";
11
+ import { hitsSheet, importHit, importImageFromFile, importImageFromUrl, listImages, searchImages } from "./images.js";
12
+ import { lintDeck } from "./lint.js";
13
+ import { AppeekyClient, PostizClient, publishDeck } from "./publish.js";
14
+ import { viralLines, viralSearch, viralSheet } from "./viral.js";
15
+ import { assignSlot, dueSlots, planSlots, readPlan, savePlan } from "./schedule.js";
16
+ import { brandSchema, channelSchema, colorsSchema, sizeSchema, slideSchema, textStyleSchema, tiktokOptionsSchema } from "./schema.js";
17
+ import { THEMES } from "./themes.js";
18
+ import { initWorkspace, isInside, listChannels, listDecks, loadChannel, loadDeck, openWorkspace, saveChannel, saveSettings, UserError } from "./workspace.js";
19
+ import { VERSION } from "./version.js";
20
+ import { guideText, guideTopics } from "./skill.js";
21
+ const text = (t) => ({ type: "text", text: t });
22
+ const json = (v) => text(JSON.stringify(v, null, 2));
23
+ async function imageContent(file, maxWidth = 1500) {
24
+ const buf = await sharp(readFileSync(file)).resize({ width: maxWidth, withoutEnlargement: true }).jpeg({ quality: 78 }).toBuffer();
25
+ return { type: "image", data: buf.toString("base64"), mimeType: "image/jpeg" };
26
+ }
27
+ function wrap(fn) {
28
+ return async (args) => {
29
+ try {
30
+ const ws = openWorkspace(process.env.OPEN_SLIDESHOW_DIR ?? process.cwd());
31
+ const content = await fn(args, ws);
32
+ if (ws.warnings.length)
33
+ content.push(text(`Workspace warnings:\n${ws.warnings.map((w) => `- ${w}`).join("\n")}`));
34
+ return { content };
35
+ }
36
+ catch (e) {
37
+ const msg = e instanceof UserError || e instanceof Error ? e.message : String(e);
38
+ return { content: [text(msg)], isError: true };
39
+ }
40
+ };
41
+ }
42
+ const deckFields = {
43
+ size: sizeSchema.optional().describe("4:5 (feed, default), 1:1 or 9:16 (full-screen TikTok)"),
44
+ theme: z.string().optional().describe("theme id from themes_list"),
45
+ colors: colorsSchema.optional().describe("brand colours instead of the theme's"),
46
+ full_cover: z.boolean().optional(),
47
+ text_style: textStyleSchema.optional(),
48
+ show_handle: z.boolean().optional(),
49
+ caption: z.string().max(4000).optional(),
50
+ hashtags: z.array(z.string()).max(30).optional().describe("without #, 3–5 relevant ones"),
51
+ accounts: z.array(z.string()).optional().describe('e.g. ["tiktok"], ["instagram:@handle"], ["tiktok:all"]'),
52
+ when: z.string().optional().describe("ISO time with zone to schedule, e.g. 2026-12-08T18:30:00+03:00"),
53
+ tiktok: tiktokOptionsSchema.optional(),
54
+ topic: z.string().max(200).optional(),
55
+ template: z.string().optional().describe("template id from templates_list; lint checks the slides follow it"),
56
+ language: z.string().optional(),
57
+ channel: z.string().optional(),
58
+ };
59
+ export function createServer() {
60
+ const server = new McpServer({ name: "open-slideshow", version: VERSION }, {
61
+ instructions: "open-slideshow makes TikTok slideshows and Instagram carousels on this machine. You write the words; open-slideshow renders, checks and publishes. " +
62
+ "Always start with brand_context and follow it (tone, claims, hooks already used). If it lists missing brand facts, ask the user and save them with brand_set before writing. " +
63
+ "Detailed guides for every step and error: the guide tool. Let the user pick a theme with themes_preview and a shape with templates_preview. Then deck_create (with template) → deck_render → look at the sheet → fix → deck_publish (preview first; confirm only after the user says yes).",
64
+ });
65
+ server.registerTool("guide", { description: `Detailed open-slideshow guide on one topic: ${guideTopics().join(", ")}. Read the one you need when the task gets there (e.g. review after rendering, troubleshooting on an error).`, inputSchema: { topic: z.string() } }, wrap(async (a) => {
66
+ const t = guideText(a.topic);
67
+ if (!t)
68
+ throw new UserError(`no guide "${a.topic}"; topics: ${guideTopics().join(", ")}`);
69
+ return [text(t)];
70
+ }));
71
+ server.registerTool("workspace_info", { description: "Where open-slideshow works here (standalone folder or Appeeky Spec repo), and what is in it." }, wrap(async (_a, ws) => [
72
+ json({ mode: ws.mode, root: ws.root, dir: ws.dir, initialized: ws.initialized, app: ws.settings.app, default_theme: ws.settings.defaults.theme, decks: listDecks(ws).map((d) => ({ id: d.id, status: d.deck?.status, error: d.error })), channels: listChannels(ws).map((c) => c.id), images: listImages(ws).length }),
73
+ ]));
74
+ server.registerTool("workspace_init", { description: "Set up open-slideshow in this folder (only needed outside a Spec repo).", inputSchema: { app_name: z.string().optional(), app_store_id: z.string().optional(), theme: z.string().optional() } }, wrap(async (a) => {
75
+ const ws = initWorkspace(process.env.OPEN_SLIDESHOW_DIR ?? process.cwd(), { app: { name: a.app_name, app_store_id: a.app_store_id, country: "us" }, ...(a.theme ? { defaults: { theme: a.theme, size: "4:5", language: "en" } } : {}) });
76
+ return [text(`ready in ${ws.dir} (${ws.mode} mode). Next: brand_context.`)];
77
+ }));
78
+ server.registerTool("brand_context", { description: "Everything about the app and brand to write slides in its voice: what it does, audience, tone, claims never to make, the App Store listing, the Spec playbook, hooks already used and how they did, and phrases to avoid. Call it before writing any slide.", inputSchema: { offline: z.boolean().optional() } }, wrap(async (a, ws) => {
79
+ const ctx = await brandContext(ws, { offline: a.offline });
80
+ return [text(ctx.markdown), json({ missing: ctx.missing, questions: ctx.questions, used_hooks: ctx.used_hooks.length })];
81
+ }));
82
+ server.registerTool("brand_set", {
83
+ description: "Save brand facts the user told you (merged into what is there). Lists replace the old list. In a Spec repo the playbook stays the main source; this fills the rest.",
84
+ inputSchema: { brand: brandSchema.partial().describe("name, handle, one_liner, audience, tone[], voice_examples[], words_to_use[], words_to_avoid[], claims_allowed[], claims_never[], cta, colors, icon, notes"), app_store_id: z.string().optional(), default_theme: z.string().optional(), default_size: sizeSchema.optional() },
85
+ }, wrap(async (a, ws) => {
86
+ const s = structuredClone(ws.settings);
87
+ s.brand = brandSchema.parse({ ...s.brand, ...(a.brand ?? {}) });
88
+ if (a.app_store_id) {
89
+ if (ws.mode === "spec")
90
+ throw new UserError("in a Spec repo the App Store id comes from appeeky.spec.yaml");
91
+ s.app.app_store_id = a.app_store_id;
92
+ }
93
+ if (a.default_theme) {
94
+ if (!THEMES.some((t) => t.id === a.default_theme))
95
+ throw new UserError(`unknown theme ${a.default_theme}`);
96
+ s.defaults.theme = a.default_theme;
97
+ }
98
+ if (a.default_size)
99
+ s.defaults.size = a.default_size;
100
+ if (s.brand.icon && !listImages(ws).some((m) => m.ref === s.brand.icon))
101
+ throw new UserError("brand.icon must be an image imported with image_import (its ref)");
102
+ saveSettings(ws, s);
103
+ if (s.app.app_store_id && !s.brand.icon) {
104
+ const ws2 = openWorkspace(ws.root);
105
+ const icon = await ensureIcon(ws2, await fetchAppStore(ws2, s.app.app_store_id, s.app.country));
106
+ if (icon) {
107
+ ws2.settings.brand.icon = icon;
108
+ saveSettings(ws2, ws2.settings);
109
+ }
110
+ }
111
+ return [text(`saved to ${ws.settings_file}`)];
112
+ }));
113
+ server.registerTool("themes_list", { description: "The 10 slide themes: id, look and when to use each." }, wrap(async () => [json(THEMES.map((t) => ({ id: t.id, name: t.name, design: t.design, description: t.description, needs_photos: t.design === "photo" })))]));
114
+ server.registerTool("themes_preview", { description: "One picture with every theme side by side, so the user can pick. With deck, uses that deck's own slides. Show the picture to the user and ask which one; save it with brand_set default_theme or deck_update theme.", inputSchema: { deck: z.string().optional(), slides: z.number().int().min(1).max(3).optional() } }, wrap(async (a, ws) => {
115
+ const g = await themeGallery(ws, a);
116
+ return [text(`Themes, left to right in pairs (labels above each): ${g.themes.map((t) => t.id).join(", ")}\nFile: ${g.sheet}`), await imageContent(g.sheet, 1800)];
117
+ }));
118
+ server.registerTool("templates_list", { description: "Slideshow shapes (tips, mistakes, story, before-after, ranking, quotes, checklist): which slides in which order, what to write on each, and when each works. Pick one with the user before writing; set it as the deck's template." }, wrap(async () => [json(TEMPLATES.map(templateGuide))]));
119
+ server.registerTool("templates_preview", { description: "One picture with every template as a row of example slides, in a theme (default: the user's theme). Show it to the user and ask which shape fits; it also shows how the theme looks across a whole deck.", inputSchema: { theme: z.string().optional(), templates: z.array(z.string()).optional() } }, wrap(async (a, ws) => {
120
+ const g = await templateGallery(ws, a);
121
+ return [text(`Templates in ${g.theme}, one per row: ${g.templates.map((t) => `${t.id} (${t.description})`).join("; ")}\nFile: ${g.sheet}`), await imageContent(g.sheet, 1800)];
122
+ }));
123
+ server.registerTool("deck_create", {
124
+ description: "Write a new slideshow, usually following a template (templates_list). Slides: cover (the hook, title), tip (title + body, numbered automatically), list (title + items), quote (title = the quote, author), bridge (turn to the app), app (shows the app icon and name), text (body only). Wrap words in *stars* for the accent colour. Keep each slide under ~25 words.",
125
+ inputSchema: { id: z.string().optional().describe("folder name; made from the topic when left out"), slides: z.array(slideSchema).min(1).max(35), ...deckFields },
126
+ }, wrap(async (a, ws) => {
127
+ const deck = newDeck(ws, a);
128
+ const lint = await lintDeck(ws, deck);
129
+ return [json({ id: deck.id, file: join(ws.dir, "decks", deck.id, "deck.yaml"), errors: lint.errors, warnings: lint.warnings }), text("Next: fix errors with deck_update, then deck_render and look at the sheet.")];
130
+ }));
131
+ server.registerTool("deck_update", {
132
+ description: "Change a deck: any field, the whole slides list, or single slides (slide_edits by 0-based index; a null value removes a field), insert, remove, move.",
133
+ inputSchema: {
134
+ id: z.string(),
135
+ slides: z.array(slideSchema).optional(),
136
+ slide_edits: z.array(z.object({ index: z.number().int().min(0), set: z.record(z.unknown()) })).optional(),
137
+ insert: z.array(z.object({ index: z.number().int().min(0), slide: slideSchema })).optional(),
138
+ remove: z.array(z.number().int().min(0)).optional(),
139
+ move: z.object({ from: z.number().int(), to: z.number().int() }).optional(),
140
+ ...deckFields,
141
+ },
142
+ }, wrap(async (a, ws) => {
143
+ const { id, ...patch } = a;
144
+ const deck = updateDeck(ws, id, patch);
145
+ const lint = await lintDeck(ws, deck);
146
+ return [json({ id: deck.id, slides: deck.slides.length, errors: lint.errors, warnings: lint.warnings })];
147
+ }));
148
+ server.registerTool("deck_get", { description: "A deck's content and status.", inputSchema: { id: z.string() } }, wrap(async (a, ws) => [json({ ...loadDeck(ws, a.id), rendered: readManifest(ws, a.id) })]));
149
+ server.registerTool("deck_list", { description: "All decks with status and hook." }, wrap(async (_a, ws) => [json(listDecks(ws).map((d) => ({ id: d.id, status: d.deck?.status, theme: d.deck?.theme, slides: d.deck?.slides.length, hook: d.deck?.slides[0]?.title, when: d.deck?.when, error: d.error })))]));
150
+ server.registerTool("deck_lint", { description: "Check a deck without rendering: text that does not fit, missing images and glyphs, platform limits, banned phrases, brand rules, repeated hooks.", inputSchema: { id: z.string(), platforms: z.array(z.enum(["tiktok", "instagram"])).optional() } }, wrap(async (a, ws) => [json(await lintDeck(ws, loadDeck(ws, a.id), { platforms: a.platforms }))]));
151
+ server.registerTool("deck_render", { description: "Render the deck to JPEGs and return a sheet of all slides to look at. Always look at it before publishing: check that words are readable over the photos and nothing is cut.", inputSchema: { id: z.string(), slide: z.number().int().min(1).optional().describe("also return this slide (1-based) full size") } }, wrap(async (a, ws) => {
152
+ const r = await renderDeckById(ws, a.id);
153
+ const out = [json({ dir: r.dir, files: r.files, errors: r.lint.errors, warnings: r.lint.warnings }), await imageContent(join(r.dir, r.sheet), 1600)];
154
+ if (a.slide && r.files[a.slide - 1])
155
+ out.push(await imageContent(join(r.dir, r.files[a.slide - 1]), 1080));
156
+ return out;
157
+ }));
158
+ server.registerTool("image_search", { description: "Find photos. Openverse needs no key (CC0, public domain, CC BY only); Unsplash or Pexels with the user's own UNSPLASH_ACCESS_KEY / PEXELS_API_KEY. Returns thumbnails to pick from; then image_import with the hit.", inputSchema: { query: z.string().min(2).max(200), provider: z.enum(["openverse", "unsplash", "pexels"]).optional(), orientation: z.enum(["portrait", "landscape", "square"]).optional(), limit: z.number().int().min(1).max(30).optional() } }, wrap(async (a) => {
159
+ const hits = await searchImages(a.query, { ...a, orientation: a.orientation ?? "portrait" });
160
+ if (!hits.length)
161
+ return [text("nothing found; try other words (concrete things work best: 'messy desk at night', not 'productivity')")];
162
+ const sheet = await hitsSheet(hits);
163
+ return [
164
+ json(hits.map((h, i) => ({ n: i + 1, ...h }))),
165
+ ...(sheet ? [text("Numbered thumbnails: pick photos that fit the slide's words and look like a real phone photo."), { type: "image", data: sheet.toString("base64"), mimeType: "image/jpeg" }] : []),
166
+ ];
167
+ }));
168
+ server.registerTool("viral_search", { description: "What already works on TikTok for a topic: the most liked photo slideshows (or videos), with their covers, captions, slide counts and numbers. Use it before writing hooks for a new topic, to learn which angles and shapes people respond to. Needs APPEEKY_API_KEY; each search costs $0.01 from the user's Appeeky balance (the same search within the hour is free), so say so before the first one. Study the patterns, never copy a hook or reuse their images: they belong to their creators.", inputSchema: { query: z.string().min(2).max(120).describe("the topic in the words people search, e.g. 'morning routine', 'study tips'"), kind: z.enum(["slideshow", "video", "any"]).optional(), since: z.enum(["week", "month", "quarter", "half", "any"]).optional(), limit: z.number().int().min(1).max(40).optional() } }, wrap(async (a) => {
169
+ const posts = await viralSearch(a.query, { kind: a.kind ?? "slideshow", since: a.since ?? "quarter", limit: a.limit ?? 20 });
170
+ if (!posts.length)
171
+ return [text("nothing found; try the words people would type into TikTok's search, or a wider since")];
172
+ const sheet = await viralSheet(posts);
173
+ return [
174
+ text(viralLines(posts).join("\n")),
175
+ json(posts.map((p, i) => ({ n: i + 1, ...p, images: p.images.slice(0, 3) }))),
176
+ ...(sheet ? [text("Numbered covers, most liked first. Read the hook on each: its length, its promise, the number in it, who it speaks to. Then write your own for this brand."), { type: "image", data: sheet.toString("base64"), mimeType: "image/jpeg" }] : []),
177
+ ];
178
+ }));
179
+ server.registerTool("image_import", { description: "Bring an image into the workspace: a hit from image_search, an https URL the user gave, or a file path on this machine (e.g. a screenshot, or an image Codex/another tool generated). Returns the ref to use as a slide's image.", inputSchema: { hit: z.record(z.unknown()).optional(), url: z.string().optional(), path: z.string().optional(), license: z.string().optional(), author: z.string().optional() } }, wrap(async (a, ws) => {
180
+ const n = [a.hit, a.url, a.path].filter(Boolean).length;
181
+ if (n !== 1)
182
+ throw new UserError("give exactly one of hit, url or path");
183
+ const meta = a.hit ? await importHit(ws, a.hit) : a.url ? await importImageFromUrl(ws, a.url, { license: a.license ?? "unknown", author: a.author }) : await importImageFromFile(ws, a.path, { license: a.license ?? "own", author: a.author });
184
+ return [json(meta), ...(meta.license === "unknown" ? [text("License unknown: only use it if the user owns it or has the right to post it.")] : [])];
185
+ }));
186
+ server.registerTool("image_list", { description: "Images already in the workspace." }, wrap(async (_a, ws) => [json(listImages(ws))]));
187
+ server.registerTool("channel_save", { description: "Create or change a channel: an account plan with schedule (window or fixed times, days, per_day, timezone, prepare), content rules (audience, topics, never, slide_count, bridge, brand) and design. Starts disabled.", inputSchema: { channel: channelSchema.partial().extend({ id: z.string(), name: z.string().optional() }) } }, wrap(async (a, ws) => {
188
+ let base = { name: a.channel.id };
189
+ try {
190
+ base = loadChannel(ws, a.channel.id);
191
+ }
192
+ catch {
193
+ /* new */
194
+ }
195
+ const ch = saveChannel(ws, { ...base, ...a.channel });
196
+ return [json(ch)];
197
+ }));
198
+ server.registerTool("channel_list", { description: "Channels and their schedules." }, wrap(async (_a, ws) => [json(listChannels(ws))]));
199
+ server.registerTool("plan", { description: "Work out the next post times for enabled channels and save them. Returns the slots; due ones need a deck.", inputSchema: { days: z.number().int().min(1).max(62).optional(), channel: z.string().optional() } }, wrap(async (a, ws) => {
200
+ const chans = listChannels(ws).filter((c) => c.channel && (a.channel ? c.id === a.channel : c.channel.enabled));
201
+ if (!chans.length)
202
+ throw new UserError(a.channel ? `no channel ${a.channel}` : "no enabled channels (channel_save with enabled: true)");
203
+ const fresh = chans.flatMap((c) => planSlots(c.channel, new Date(), a.days ?? 7));
204
+ const all = savePlan(ws, fresh);
205
+ return [json({ slots: all, due: dueSlots(ws) })];
206
+ }));
207
+ server.registerTool("due", { description: "Slots that need a deck now, with the channel's content rules. For each: brand_context, write a deck for the channel, render, look, then deck_publish with when = the slot time." }, wrap(async (_a, ws) => {
208
+ const due = dueSlots(ws);
209
+ return [json(due.map((s) => ({ ...s, channel_rules: loadChannel(ws, s.channel) })))];
210
+ }));
211
+ server.registerTool("slot_assign", { description: "Put a deck in a planned slot (sets the deck's when and channel).", inputSchema: { channel: z.string(), at: z.string(), deck: z.string() } }, wrap(async (a, ws) => {
212
+ const slot = assignSlot(ws, a.channel, a.at, a.deck);
213
+ const ch = loadChannel(ws, a.channel);
214
+ updateDeck(ws, a.deck, { when: slot.at, channel: a.channel, ...(ch.accounts.length ? { accounts: ch.accounts } : {}), ...(ch.tiktok ? { tiktok: ch.tiktok } : {}) });
215
+ return [json(slot)];
216
+ }));
217
+ server.registerTool("accounts_list", { description: "Social accounts connected in Appeeky (needs APPEEKY_API_KEY), or with service: postiz the channels connected in Postiz (needs POSTIZ_API_KEY).", inputSchema: { service: z.enum(["appeeky", "postiz"]).optional() } }, wrap(async (a) => [json(await (a.service === "postiz" ? new PostizClient() : new AppeekyClient()).accounts())]));
218
+ server.registerTool("deck_publish", {
219
+ description: "Publish a rendered deck. provider: export (files to a folder), photos (macOS Photos album, post from the phone), appeeky (post or schedule with the user's APPEEKY_API_KEY), postiz (post or schedule through the user's Postiz, cloud or self-hosted, with POSTIZ_API_KEY), spec-draft (in a Spec repo: a draft file Spec sends after review). Without confirm it only shows what would happen: show that to the user, and call with confirm: true only after they agree.",
220
+ inputSchema: { id: z.string(), provider: z.enum(["export", "photos", "appeeky", "postiz", "spec-draft"]), confirm: z.boolean().optional(), again: z.boolean().optional(), when: z.string().optional(), accounts: z.array(z.string()).optional(), out: z.string().optional() },
221
+ }, wrap(async (a, ws) => {
222
+ if (a.out && !isInside(ws.root, a.out))
223
+ throw new UserError("over MCP, export only inside the workspace; use the CLI for other folders");
224
+ const r = await publishDeck(ws, a.id, a);
225
+ return [json(r)];
226
+ }));
227
+ server.registerTool("plan_show", { description: "The saved plan of slots." }, wrap(async (_a, ws) => [json(readPlan(ws))]));
228
+ return server;
229
+ }
230
+ export async function startMcp() {
231
+ const server = createServer();
232
+ await server.connect(new StdioServerTransport());
233
+ }
@@ -0,0 +1,100 @@
1
+ import type { Deck, TikTokOptions } from "./schema.js";
2
+ import { type Workspace } from "./workspace.js";
3
+ export declare const APPEEKY_API_URL = "https://api.appeeky.com/v1";
4
+ /** Postiz Cloud. A self-hosted Postiz is https://<your-domain>/api/public/v1, set in POSTIZ_API_URL. */
5
+ export declare const POSTIZ_API_URL = "https://api.postiz.com/public/v1";
6
+ export type Provider = "export" | "photos" | "appeeky" | "postiz" | "spec-draft";
7
+ export interface PublishOptions {
8
+ provider: Provider;
9
+ /** Nothing leaves the machine and no file outside the deck is written without it. */
10
+ confirm?: boolean;
11
+ /** Publish again even though this exact render was published before. */
12
+ again?: boolean;
13
+ out?: string;
14
+ /** Override the deck's `when`. */
15
+ when?: string;
16
+ accounts?: string[];
17
+ }
18
+ export interface PublishResult {
19
+ provider: Provider;
20
+ done: boolean;
21
+ preview: Record<string, unknown>;
22
+ message: string;
23
+ files?: string[];
24
+ post_id?: string;
25
+ draft_file?: string;
26
+ }
27
+ export declare function tiktokExtra(deck: Deck, t: TikTokOptions | undefined): Record<string, unknown>;
28
+ export declare function publishDeck(ws: Workspace, id: string, o: PublishOptions): Promise<PublishResult>;
29
+ export declare function hookOf(deck: Deck): string;
30
+ export interface Account {
31
+ id: string;
32
+ platform: string;
33
+ name: string;
34
+ active: boolean;
35
+ problem?: string;
36
+ /** The service's own name for the platform, when it differs (Postiz: instagram-standalone). */
37
+ kind?: string;
38
+ }
39
+ export interface ViralPost {
40
+ id: string;
41
+ url: string;
42
+ kind: "slideshow" | "video";
43
+ caption: string;
44
+ hashtags: string[];
45
+ images: string[];
46
+ slideCount: number | null;
47
+ views: number | null;
48
+ likes: number | null;
49
+ comments: number | null;
50
+ shares: number | null;
51
+ saves: number | null;
52
+ engagement: number | null;
53
+ publishedAt: string | null;
54
+ music: string | null;
55
+ creator: {
56
+ handle: string;
57
+ name: string;
58
+ followers: number | null;
59
+ url: string;
60
+ };
61
+ }
62
+ export declare class AppeekyClient {
63
+ private key;
64
+ private base;
65
+ constructor(key?: string | undefined, base?: string);
66
+ private call;
67
+ /** The most liked TikTok posts for a topic (one search from the Appeeky balance). */
68
+ viral(query: string, opts?: {
69
+ kind?: string;
70
+ since?: string;
71
+ limit?: number;
72
+ }): Promise<{
73
+ posts: ViralPost[];
74
+ }>;
75
+ accounts(): Promise<Account[]>;
76
+ upload(file: string): Promise<string>;
77
+ createPost(body: Record<string, unknown>): Promise<string>;
78
+ }
79
+ /**
80
+ * Postiz, the open-source scheduler, cloud or self-hosted. Its channels are "integrations"; the
81
+ * slideshow goes up as images, then one request schedules it on every chosen channel. The key is
82
+ * the user's own, from Postiz settings; nothing else is sent.
83
+ */
84
+ export declare class PostizClient {
85
+ private key;
86
+ private base;
87
+ constructor(key?: string | undefined, base?: string);
88
+ private call;
89
+ accounts(): Promise<Account[]>;
90
+ /** Returns the uploaded image as JSON {id, path}, which is what a Postiz post refers to. */
91
+ upload(file: string): Promise<string>;
92
+ createPost(body: Record<string, unknown>): Promise<string>;
93
+ }
94
+ /** One Postiz request: the same slides and caption on every channel, with each platform's settings. */
95
+ export declare function postizBody(deck: Deck, accounts: Account[], caption: string, media: string[], when: string | undefined): Record<string, unknown>;
96
+ /** Account names as people write them: `tiktok`, `tiktok:all`, `@handle`, `instagram:@handle`, or an id. */
97
+ export declare function resolveAccounts(refs: string[], all: Account[], service?: string): {
98
+ accounts: Account[];
99
+ problems: string[];
100
+ };