@netnodeag/kraftwerk 0.82.0 → 0.84.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 (77) hide show
  1. package/README.md +212 -11
  2. package/dist/cli/init.js +1 -0
  3. package/dist/cli/kraftwerk.js +3 -0
  4. package/dist/cli/presentations.d.ts +2 -0
  5. package/dist/cli/presentations.js +261 -0
  6. package/dist/client/routes.d.ts +18 -0
  7. package/dist/client/routes.js +18 -0
  8. package/dist/config.d.ts +16 -0
  9. package/dist/config.js +10 -2
  10. package/dist/core/boards.d.ts +14 -1
  11. package/dist/core/boards.js +34 -1
  12. package/dist/core/chat/context.js +11 -2
  13. package/dist/core/git.js +3 -1
  14. package/dist/core/presentations/browser.d.ts +43 -0
  15. package/dist/core/presentations/browser.js +53 -0
  16. package/dist/core/presentations/builtin.d.ts +3 -0
  17. package/dist/core/presentations/builtin.js +142 -0
  18. package/dist/core/presentations/chart.d.ts +34 -0
  19. package/dist/core/presentations/chart.js +159 -0
  20. package/dist/core/presentations/deck.d.ts +63 -0
  21. package/dist/core/presentations/deck.js +198 -0
  22. package/dist/core/presentations/export.d.ts +21 -0
  23. package/dist/core/presentations/export.js +75 -0
  24. package/dist/core/presentations/html.d.ts +135 -0
  25. package/dist/core/presentations/html.js +389 -0
  26. package/dist/core/presentations/index.d.ts +252 -0
  27. package/dist/core/presentations/index.js +753 -0
  28. package/dist/core/presentations/layout.d.ts +47 -0
  29. package/dist/core/presentations/layout.js +147 -0
  30. package/dist/core/presentations/markdown.d.ts +49 -0
  31. package/dist/core/presentations/markdown.js +158 -0
  32. package/dist/core/presentations/merge.d.ts +26 -0
  33. package/dist/core/presentations/merge.js +28 -0
  34. package/dist/core/presentations/presence.d.ts +31 -0
  35. package/dist/core/presentations/presence.js +131 -0
  36. package/dist/core/presentations/render.d.ts +33 -0
  37. package/dist/core/presentations/render.js +318 -0
  38. package/dist/core/presentations/slots.d.ts +33 -0
  39. package/dist/core/presentations/slots.js +114 -0
  40. package/dist/core/presentations/template.d.ts +253 -0
  41. package/dist/core/presentations/template.js +141 -0
  42. package/dist/core/presentations/versions.d.ts +30 -0
  43. package/dist/core/presentations/versions.js +75 -0
  44. package/dist/core/refs.d.ts +1 -1
  45. package/dist/core/refs.js +9 -1
  46. package/dist/core/search.d.ts +10 -0
  47. package/dist/core/search.js +6 -0
  48. package/dist/core/settings.d.ts +2 -0
  49. package/dist/core/settings.js +12 -1
  50. package/dist/core/trash.d.ts +1 -1
  51. package/dist/server/api/index.d.ts +62 -1
  52. package/dist/server/api/index.js +2 -0
  53. package/dist/server/api/presentations.d.ts +66 -0
  54. package/dist/server/api/presentations.js +185 -0
  55. package/dist/server/api/socket.js +24 -1
  56. package/dist/server/api/workspace.d.ts +5 -0
  57. package/dist/server/api/workspace.js +2 -0
  58. package/package.json +6 -2
  59. package/schema/kraftwerk.schema.json +18 -0
  60. package/web/dist/assets/{dist-BBFUIftm.js → dist-3Yr8mX0X.js} +1 -1
  61. package/web/dist/assets/{dist-DtUB2Uu2.js → dist-BVzRayNB.js} +1 -1
  62. package/web/dist/assets/{dist-BuwdjX6z.js → dist-BdYm_4II.js} +1 -1
  63. package/web/dist/assets/{dist-C16bXf8c.js → dist-Bf3GuzEk.js} +1 -1
  64. package/web/dist/assets/{dist-Bie1ebP9.js → dist-DGymUpLv.js} +1 -1
  65. package/web/dist/assets/{dist-CH73jsgO.js → dist-DIvdTMOT.js} +1 -1
  66. package/web/dist/assets/{dist-DvkrCSGL.js → dist-DchG_zAX.js} +1 -1
  67. package/web/dist/assets/{dist-C0ve4Tka.js → dist-Dt9RqYvy.js} +1 -1
  68. package/web/dist/assets/dist-m1b2E3aJ.js +1 -0
  69. package/web/dist/assets/{dist-C_rJjRj7.js → dist-mxFa618U.js} +1 -1
  70. package/web/dist/assets/{dist-CDUZdAAS.js → dist-xXM6FJLm.js} +1 -1
  71. package/web/dist/assets/{editor-3z92i0tV.js → editor-DYDCHRgT.js} +3 -3
  72. package/web/dist/assets/index-CvvZzwHR.js +473 -0
  73. package/web/dist/assets/index-JhhhmD7T.css +2 -0
  74. package/web/dist/index.html +2 -2
  75. package/web/dist/assets/dist-DYICNp09.js +0 -1
  76. package/web/dist/assets/index-DRhNELK_.js +0 -232
  77. package/web/dist/assets/index-unGEux3Y.css +0 -2
@@ -0,0 +1,253 @@
1
+ import * as z from "zod";
2
+ export { SLOT_KINDS, CANVAS, BASE_COLORS, PPI, STAGE_W, layoutFor, defaultSlotOf, resolveColor, resolveFont, slideSlots, templateColors, type SlotKind, type SlotPatch } from "./layout.js";
3
+ declare const Slot: z.ZodObject<{
4
+ x: z.ZodNumber;
5
+ y: z.ZodNumber;
6
+ w: z.ZodNumber;
7
+ h: z.ZodNumber;
8
+ kind: z.ZodDefault<z.ZodEnum<{
9
+ chart: "chart";
10
+ embed: "embed";
11
+ html: "html";
12
+ image: "image";
13
+ markdown: "markdown";
14
+ table: "table";
15
+ text: "text";
16
+ }>>;
17
+ size: z.ZodOptional<z.ZodNumber>;
18
+ bold: z.ZodOptional<z.ZodBoolean>;
19
+ italic: z.ZodOptional<z.ZodBoolean>;
20
+ color: z.ZodOptional<z.ZodString>;
21
+ font: z.ZodOptional<z.ZodString>;
22
+ align: z.ZodOptional<z.ZodEnum<{
23
+ center: "center";
24
+ left: "left";
25
+ right: "right";
26
+ }>>;
27
+ valign: z.ZodOptional<z.ZodEnum<{
28
+ bottom: "bottom";
29
+ middle: "middle";
30
+ top: "top";
31
+ }>>;
32
+ fill: z.ZodOptional<z.ZodString>;
33
+ required: z.ZodOptional<z.ZodBoolean>;
34
+ placeholder: z.ZodOptional<z.ZodString>;
35
+ class: z.ZodOptional<z.ZodString>;
36
+ underline: z.ZodOptional<z.ZodBoolean>;
37
+ strike: z.ZodOptional<z.ZodBoolean>;
38
+ rotate: z.ZodOptional<z.ZodNumber>;
39
+ radius: z.ZodOptional<z.ZodNumber>;
40
+ border: z.ZodOptional<z.ZodNumber>;
41
+ borderColor: z.ZodOptional<z.ZodString>;
42
+ shadow: z.ZodOptional<z.ZodBoolean>;
43
+ opacity: z.ZodOptional<z.ZodNumber>;
44
+ z: z.ZodOptional<z.ZodNumber>;
45
+ fit: z.ZodOptional<z.ZodEnum<{
46
+ contain: "contain";
47
+ cover: "cover";
48
+ }>>;
49
+ }, z.core.$strip>;
50
+ export type SlotDef = z.output<typeof Slot>;
51
+ declare const Shape: z.ZodObject<{
52
+ x: z.ZodNumber;
53
+ y: z.ZodNumber;
54
+ w: z.ZodNumber;
55
+ h: z.ZodNumber;
56
+ kind: z.ZodDefault<z.ZodEnum<{
57
+ line: "line";
58
+ rect: "rect";
59
+ }>>;
60
+ fill: z.ZodOptional<z.ZodString>;
61
+ color: z.ZodOptional<z.ZodString>;
62
+ width: z.ZodOptional<z.ZodNumber>;
63
+ }, z.core.$strip>;
64
+ export type ShapeDef = z.output<typeof Shape>;
65
+ declare const Layout: z.ZodObject<{
66
+ background: z.ZodOptional<z.ZodString>;
67
+ shapes: z.ZodDefault<z.ZodArray<z.ZodObject<{
68
+ x: z.ZodNumber;
69
+ y: z.ZodNumber;
70
+ w: z.ZodNumber;
71
+ h: z.ZodNumber;
72
+ kind: z.ZodDefault<z.ZodEnum<{
73
+ line: "line";
74
+ rect: "rect";
75
+ }>>;
76
+ fill: z.ZodOptional<z.ZodString>;
77
+ color: z.ZodOptional<z.ZodString>;
78
+ width: z.ZodOptional<z.ZodNumber>;
79
+ }, z.core.$strip>>>;
80
+ slots: z.ZodRecord<z.ZodString, z.ZodObject<{
81
+ x: z.ZodNumber;
82
+ y: z.ZodNumber;
83
+ w: z.ZodNumber;
84
+ h: z.ZodNumber;
85
+ kind: z.ZodDefault<z.ZodEnum<{
86
+ chart: "chart";
87
+ embed: "embed";
88
+ html: "html";
89
+ image: "image";
90
+ markdown: "markdown";
91
+ table: "table";
92
+ text: "text";
93
+ }>>;
94
+ size: z.ZodOptional<z.ZodNumber>;
95
+ bold: z.ZodOptional<z.ZodBoolean>;
96
+ italic: z.ZodOptional<z.ZodBoolean>;
97
+ color: z.ZodOptional<z.ZodString>;
98
+ font: z.ZodOptional<z.ZodString>;
99
+ align: z.ZodOptional<z.ZodEnum<{
100
+ center: "center";
101
+ left: "left";
102
+ right: "right";
103
+ }>>;
104
+ valign: z.ZodOptional<z.ZodEnum<{
105
+ bottom: "bottom";
106
+ middle: "middle";
107
+ top: "top";
108
+ }>>;
109
+ fill: z.ZodOptional<z.ZodString>;
110
+ required: z.ZodOptional<z.ZodBoolean>;
111
+ placeholder: z.ZodOptional<z.ZodString>;
112
+ class: z.ZodOptional<z.ZodString>;
113
+ underline: z.ZodOptional<z.ZodBoolean>;
114
+ strike: z.ZodOptional<z.ZodBoolean>;
115
+ rotate: z.ZodOptional<z.ZodNumber>;
116
+ radius: z.ZodOptional<z.ZodNumber>;
117
+ border: z.ZodOptional<z.ZodNumber>;
118
+ borderColor: z.ZodOptional<z.ZodString>;
119
+ shadow: z.ZodOptional<z.ZodBoolean>;
120
+ opacity: z.ZodOptional<z.ZodNumber>;
121
+ z: z.ZodOptional<z.ZodNumber>;
122
+ fit: z.ZodOptional<z.ZodEnum<{
123
+ contain: "contain";
124
+ cover: "cover";
125
+ }>>;
126
+ }, z.core.$strip>>;
127
+ default: z.ZodOptional<z.ZodString>;
128
+ description: z.ZodOptional<z.ZodString>;
129
+ }, z.core.$strip>;
130
+ export type LayoutDef = z.output<typeof Layout>;
131
+ export declare const TemplateSchema: z.ZodObject<{
132
+ name: z.ZodString;
133
+ size: z.ZodDefault<z.ZodEnum<{
134
+ "16:9": "16:9";
135
+ "4:3": "4:3";
136
+ }>>;
137
+ fonts: z.ZodDefault<z.ZodObject<{
138
+ heading: z.ZodDefault<z.ZodString>;
139
+ body: z.ZodDefault<z.ZodString>;
140
+ }, z.core.$strip>>;
141
+ colors: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
142
+ layouts: z.ZodRecord<z.ZodString, z.ZodObject<{
143
+ background: z.ZodOptional<z.ZodString>;
144
+ shapes: z.ZodDefault<z.ZodArray<z.ZodObject<{
145
+ x: z.ZodNumber;
146
+ y: z.ZodNumber;
147
+ w: z.ZodNumber;
148
+ h: z.ZodNumber;
149
+ kind: z.ZodDefault<z.ZodEnum<{
150
+ line: "line";
151
+ rect: "rect";
152
+ }>>;
153
+ fill: z.ZodOptional<z.ZodString>;
154
+ color: z.ZodOptional<z.ZodString>;
155
+ width: z.ZodOptional<z.ZodNumber>;
156
+ }, z.core.$strip>>>;
157
+ slots: z.ZodRecord<z.ZodString, z.ZodObject<{
158
+ x: z.ZodNumber;
159
+ y: z.ZodNumber;
160
+ w: z.ZodNumber;
161
+ h: z.ZodNumber;
162
+ kind: z.ZodDefault<z.ZodEnum<{
163
+ chart: "chart";
164
+ embed: "embed";
165
+ html: "html";
166
+ image: "image";
167
+ markdown: "markdown";
168
+ table: "table";
169
+ text: "text";
170
+ }>>;
171
+ size: z.ZodOptional<z.ZodNumber>;
172
+ bold: z.ZodOptional<z.ZodBoolean>;
173
+ italic: z.ZodOptional<z.ZodBoolean>;
174
+ color: z.ZodOptional<z.ZodString>;
175
+ font: z.ZodOptional<z.ZodString>;
176
+ align: z.ZodOptional<z.ZodEnum<{
177
+ center: "center";
178
+ left: "left";
179
+ right: "right";
180
+ }>>;
181
+ valign: z.ZodOptional<z.ZodEnum<{
182
+ bottom: "bottom";
183
+ middle: "middle";
184
+ top: "top";
185
+ }>>;
186
+ fill: z.ZodOptional<z.ZodString>;
187
+ required: z.ZodOptional<z.ZodBoolean>;
188
+ placeholder: z.ZodOptional<z.ZodString>;
189
+ class: z.ZodOptional<z.ZodString>;
190
+ underline: z.ZodOptional<z.ZodBoolean>;
191
+ strike: z.ZodOptional<z.ZodBoolean>;
192
+ rotate: z.ZodOptional<z.ZodNumber>;
193
+ radius: z.ZodOptional<z.ZodNumber>;
194
+ border: z.ZodOptional<z.ZodNumber>;
195
+ borderColor: z.ZodOptional<z.ZodString>;
196
+ shadow: z.ZodOptional<z.ZodBoolean>;
197
+ opacity: z.ZodOptional<z.ZodNumber>;
198
+ z: z.ZodOptional<z.ZodNumber>;
199
+ fit: z.ZodOptional<z.ZodEnum<{
200
+ contain: "contain";
201
+ cover: "cover";
202
+ }>>;
203
+ }, z.core.$strip>>;
204
+ default: z.ZodOptional<z.ZodString>;
205
+ description: z.ZodOptional<z.ZodString>;
206
+ }, z.core.$strip>>;
207
+ default: z.ZodOptional<z.ZodString>;
208
+ css: z.ZodOptional<z.ZodString>;
209
+ snippets: z.ZodDefault<z.ZodArray<z.ZodObject<{
210
+ name: z.ZodString;
211
+ description: z.ZodOptional<z.ZodString>;
212
+ kind: z.ZodDefault<z.ZodEnum<{
213
+ html: "html";
214
+ markdown: "markdown";
215
+ }>>;
216
+ content: z.ZodString;
217
+ w: z.ZodDefault<z.ZodNumber>;
218
+ h: z.ZodDefault<z.ZodNumber>;
219
+ }, z.core.$strip>>>;
220
+ }, z.core.$strip>;
221
+ export type TemplateDef = z.output<typeof TemplateSchema>;
222
+ export type Snippet = TemplateDef["snippets"][number];
223
+ export interface Template extends TemplateDef {
224
+ slug: string;
225
+ /** The file it came from; absent for the built-in one. */
226
+ path?: string;
227
+ builtin?: boolean;
228
+ /** The theme stylesheet's text, as read (its relative URLs point into the template folder). */
229
+ cssText?: string;
230
+ }
231
+ export { DEFAULT_TEMPLATE, DEFAULT_CSS } from "./builtin.js";
232
+ export declare const TEMPLATES_DIR = "templates";
233
+ export declare const TEMPLATE_FILE = "template.yml";
234
+ /** Parse a template.yml's text. Throws with the field that is wrong. */
235
+ export declare function parseTemplate(slug: string, raw: string, file?: string): Template;
236
+ export interface TemplateSummary {
237
+ slug: string;
238
+ name: string;
239
+ size: "16:9" | "4:3";
240
+ layouts: string[];
241
+ builtin?: boolean;
242
+ path?: string;
243
+ /** Set when the file exists but cannot be used. */
244
+ error?: string;
245
+ }
246
+ /** The workspace's templates (templates/<slug>/template.yml under the root), unusable ones with their error. */
247
+ export declare function loadWorkspaceTemplates(root: string): Promise<{
248
+ templates: Template[];
249
+ errors: TemplateSummary[];
250
+ }>;
251
+ export declare const templateSummary: (t: Template) => TemplateSummary;
252
+ /** The YAML of the built-in template, for `presentations templates init` and the docs. */
253
+ export declare function defaultTemplateYaml(): string;
@@ -0,0 +1,141 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ import { parse, stringify } from "yaml";
4
+ import * as z from "zod";
5
+ import { SLUG_RE } from "../slug.js";
6
+ /**
7
+ * The template engine: a template names the canvas, the fonts and the
8
+ * colors, and defines layouts — each a set of named slots placed on the
9
+ * canvas in inches, plus decorative shapes behind them. A slide picks a
10
+ * layout and fills its slots with markdown; the renderer draws exactly
11
+ * what the layout says. One template (`default`) is built in; a workspace
12
+ * adds its own as `templates/<slug>/template.yml` under the presentations
13
+ * root with the same schema, and agents can write those too.
14
+ */
15
+ import { SLOT_KINDS, CANVAS } from "./layout.js";
16
+ export { SLOT_KINDS, CANVAS, BASE_COLORS, PPI, STAGE_W, layoutFor, defaultSlotOf, resolveColor, resolveFont, slideSlots, templateColors } from "./layout.js";
17
+ const Color = z.string().min(1);
18
+ const Box = { x: z.number(), y: z.number(), w: z.number().positive(), h: z.number().positive() };
19
+ const Slot = z.object({
20
+ kind: z.enum(SLOT_KINDS).default("markdown"),
21
+ ...Box,
22
+ /** Font size in points (text, markdown, table cells). */
23
+ size: z.number().positive().optional(),
24
+ bold: z.boolean().optional(),
25
+ italic: z.boolean().optional(),
26
+ /** A color name of the template (text, accent, …) or #hex. */
27
+ color: Color.optional(),
28
+ /** `heading`, `body` or a font family name. */
29
+ font: z.string().optional(),
30
+ align: z.enum(["left", "center", "right"]).optional(),
31
+ valign: z.enum(["top", "middle", "bottom"]).optional(),
32
+ /** The box's own background (a color name or #hex). */
33
+ fill: Color.optional(),
34
+ /** A slide using the layout must fill it; the check reports it otherwise. */
35
+ required: z.boolean().optional(),
36
+ /** What the slot shows when empty (the renderer leaves it out; the editor hints it). */
37
+ placeholder: z.string().optional(),
38
+ /** CSS classes of the slot's box in the HTML render (the theme styles them: `eyebrow`, `statement`, …). */
39
+ class: z.string().optional(),
40
+ underline: z.boolean().optional(),
41
+ strike: z.boolean().optional(),
42
+ /** Degrees, clockwise. */
43
+ rotate: z.number().optional(),
44
+ /** Corner radius in points. */
45
+ radius: z.number().min(0).optional(),
46
+ /** Border width in points, and its color (a name of the template or #hex). */
47
+ border: z.number().min(0).optional(),
48
+ borderColor: Color.optional(),
49
+ shadow: z.boolean().optional(),
50
+ /** 0 to 1. */
51
+ opacity: z.number().min(0).max(1).optional(),
52
+ /** Stacking: higher is in front. Default: the order of the slots. */
53
+ z: z.number().optional(),
54
+ /** A picture: `contain` (default) or `cover` the box. */
55
+ fit: z.enum(["contain", "cover"]).optional(),
56
+ });
57
+ const Shape = z.object({
58
+ kind: z.enum(["rect", "line"]).default("rect"),
59
+ ...Box,
60
+ fill: Color.optional(),
61
+ color: Color.optional(),
62
+ /** Line width in points. */
63
+ width: z.number().positive().optional(),
64
+ });
65
+ const Layout = z.object({
66
+ /** The slide background (a color name or #hex); the template's `background` otherwise. */
67
+ background: Color.optional(),
68
+ shapes: z.array(Shape).default([]),
69
+ slots: z.record(z.string().regex(/^[a-z][a-z0-9_-]*$/i), Slot),
70
+ /** The slot the slide's unmarked content goes into; the first markdown slot otherwise. */
71
+ default: z.string().optional(),
72
+ /** What the layout is for, shown in the editor's layout picker. */
73
+ description: z.string().optional(),
74
+ });
75
+ export const TemplateSchema = z.object({
76
+ name: z.string().min(1),
77
+ size: z.enum(["16:9", "4:3"]).default("16:9"),
78
+ fonts: z.object({ heading: z.string().default("Calibri"), body: z.string().default("Calibri") }).default({ heading: "Calibri", body: "Calibri" }),
79
+ colors: z.record(z.string(), Color).default({}),
80
+ layouts: z.record(z.string().regex(/^[a-z][a-z0-9-]*$/), Layout),
81
+ /** The layout of a slide that names none. Default: `content` when it exists, else the first. */
82
+ default: z.string().optional(),
83
+ /** The theme stylesheet, relative to the template folder (default: theme.css when it exists). It styles the HTML slides; fonts and pictures it names sit beside it. */
84
+ css: z.string().optional(),
85
+ /** Ready-made pieces for the editor's insert menu: cards, figures, a flow — HTML (or markdown) that the theme styles. */
86
+ snippets: z.array(z.object({ name: z.string().min(1), description: z.string().optional(), kind: z.enum(["html", "markdown"]).default("html"), content: z.string(), w: z.number().positive().default(8), h: z.number().positive().default(2.4) })).default([]),
87
+ });
88
+ export { DEFAULT_TEMPLATE, DEFAULT_CSS } from "./builtin.js";
89
+ import { DEFAULT_TEMPLATE } from "./builtin.js";
90
+ export const TEMPLATES_DIR = "templates";
91
+ export const TEMPLATE_FILE = "template.yml";
92
+ /** Parse a template.yml's text. Throws with the field that is wrong. */
93
+ export function parseTemplate(slug, raw, file) {
94
+ const data = parse(raw);
95
+ const r = TemplateSchema.safeParse(data);
96
+ if (!r.success)
97
+ throw new Error(`${file ?? slug}: ${z.prettifyError(r.error)}`);
98
+ for (const [name, layout] of Object.entries(r.data.layouts)) {
99
+ if (layout.default && !layout.slots[layout.default])
100
+ throw new Error(`${file ?? slug}: layout "${name}" names default slot "${layout.default}" which it does not define`);
101
+ }
102
+ if (r.data.default && !r.data.layouts[r.data.default])
103
+ throw new Error(`${file ?? slug}: default layout "${r.data.default}" is not defined`);
104
+ return { ...r.data, slug, ...(file ? { path: file } : {}) };
105
+ }
106
+ /** The workspace's templates (templates/<slug>/template.yml under the root), unusable ones with their error. */
107
+ export async function loadWorkspaceTemplates(root) {
108
+ const dir = path.join(root, TEMPLATES_DIR);
109
+ const entries = await fs.readdir(dir, { withFileTypes: true }).catch(() => []);
110
+ const templates = [];
111
+ const errors = [];
112
+ for (const e of entries) {
113
+ if (!e.isDirectory() || !SLUG_RE.test(e.name))
114
+ continue;
115
+ const file = path.join(dir, e.name, TEMPLATE_FILE);
116
+ const raw = await fs.readFile(file, "utf8").catch(() => null);
117
+ if (raw === null)
118
+ continue;
119
+ try {
120
+ const t = parseTemplate(e.name, raw, file);
121
+ const css = await fs.readFile(path.join(dir, e.name, t.css ?? "theme.css"), "utf8").catch(() => null);
122
+ if (css !== null)
123
+ t.cssText = css;
124
+ else if (t.css)
125
+ throw new Error(`${file}: css "${t.css}" does not exist`);
126
+ templates.push(t);
127
+ }
128
+ catch (err) {
129
+ errors.push({ slug: e.name, name: e.name, size: "16:9", layouts: [], path: file, error: err.message });
130
+ }
131
+ }
132
+ templates.sort((a, b) => a.slug.localeCompare(b.slug));
133
+ return { templates, errors };
134
+ }
135
+ export const templateSummary = (t) => ({ slug: t.slug, name: t.name, size: t.size, layouts: Object.keys(t.layouts), ...(t.builtin ? { builtin: true } : {}), ...(t.path ? { path: t.path } : {}) });
136
+ /** The YAML of the built-in template, for `presentations templates init` and the docs. */
137
+ export function defaultTemplateYaml() {
138
+ const { slug: _s, builtin: _b, path: _p, cssText: _c, ...def } = DEFAULT_TEMPLATE;
139
+ // A readable file: the layouts keep their key order; zod defaults are written out so the file is complete.
140
+ return `# A kraftwerk presentation template — copy of the built-in "default".\n# Positions are inches on a ${def.size} canvas (${CANVAS[def.size].w} x ${CANVAS[def.size].h}); colors are names from \`colors\` or #hex.\n${stringify(def)}`;
141
+ }
@@ -0,0 +1,30 @@
1
+ import { type DeckDoc } from "./deck.js";
2
+ /**
3
+ * Earlier versions of a deck, like a document's version history: copies
4
+ * of deck.md in the deck's `.history/` folder, taken before a save
5
+ * replaces it (the editor's saves at most once a minute — it saves while
6
+ * you type) and whenever deck.md changed on disk (an agent, the CLI,
7
+ * another tool). The newest KEEP stay. Works whether or not the
8
+ * workspace commits to git.
9
+ */
10
+ export declare const HISTORY_DIR = ".history";
11
+ export declare const KEEP = 50;
12
+ export interface DeckVersion {
13
+ id: string;
14
+ at: string;
15
+ title: string;
16
+ slides: number;
17
+ }
18
+ /**
19
+ * Keep `raw` (the deck as it was) as a version. Skipped when it equals the
20
+ * newest version, and — unless `force` — when the newest is under a minute
21
+ * old (a burst of saves while typing is one version).
22
+ */
23
+ export declare function snapshot(dir: string, raw: string, force?: boolean): Promise<void>;
24
+ export declare function listVersions(dir: string): Promise<DeckVersion[]>;
25
+ export declare function readVersion(dir: string, id: string): Promise<{
26
+ id: string;
27
+ at: string;
28
+ source: string;
29
+ deck: DeckDoc;
30
+ }>;
@@ -0,0 +1,75 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ import { parseDeck } from "./deck.js";
4
+ /**
5
+ * Earlier versions of a deck, like a document's version history: copies
6
+ * of deck.md in the deck's `.history/` folder, taken before a save
7
+ * replaces it (the editor's saves at most once a minute — it saves while
8
+ * you type) and whenever deck.md changed on disk (an agent, the CLI,
9
+ * another tool). The newest KEEP stay. Works whether or not the
10
+ * workspace commits to git.
11
+ */
12
+ export const HISTORY_DIR = ".history";
13
+ export const KEEP = 50;
14
+ const THROTTLE_MS = 60_000;
15
+ const ID_RE = /^\d{8}T\d{6}(\d{3})?Z(-\d+)?$/;
16
+ const idOf = (d) => d.toISOString().replace(/[-:]/g, "").replace(/\.(\d{3})Z$/, "$1Z");
17
+ const atOf = (id) => {
18
+ const m = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(\d{3})?Z/.exec(id);
19
+ return m ? `${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}.${m[7] ?? "000"}Z` : id;
20
+ };
21
+ async function ids(dir) {
22
+ const files = await fs.readdir(path.join(dir, HISTORY_DIR)).catch(() => []);
23
+ return files.filter((f) => f.endsWith(".md") && ID_RE.test(f.slice(0, -3))).map((f) => f.slice(0, -3)).sort().reverse();
24
+ }
25
+ /**
26
+ * Keep `raw` (the deck as it was) as a version. Skipped when it equals the
27
+ * newest version, and — unless `force` — when the newest is under a minute
28
+ * old (a burst of saves while typing is one version).
29
+ */
30
+ export async function snapshot(dir, raw, force = false) {
31
+ if (!raw.trim())
32
+ return;
33
+ const have = await ids(dir);
34
+ const newest = have[0];
35
+ if (newest) {
36
+ const last = await fs.readFile(path.join(dir, HISTORY_DIR, `${newest}.md`), "utf8").catch(() => null);
37
+ if (last === raw)
38
+ return;
39
+ if (!force && Date.now() - Date.parse(atOf(newest)) < THROTTLE_MS)
40
+ return;
41
+ }
42
+ await fs.mkdir(path.join(dir, HISTORY_DIR), { recursive: true });
43
+ let id = idOf(new Date());
44
+ for (let n = 2; have.includes(id); n++)
45
+ id = `${idOf(new Date())}-${n}`;
46
+ await fs.writeFile(path.join(dir, HISTORY_DIR, `${id}.md`), raw);
47
+ for (const old of [id, ...have].slice(KEEP))
48
+ await fs.rm(path.join(dir, HISTORY_DIR, `${old}.md`), { force: true });
49
+ }
50
+ export async function listVersions(dir) {
51
+ const out = [];
52
+ for (const id of await ids(dir)) {
53
+ const raw = await fs.readFile(path.join(dir, HISTORY_DIR, `${id}.md`), "utf8").catch(() => "");
54
+ let title = "";
55
+ let slides = 0;
56
+ try {
57
+ const d = parseDeck(raw);
58
+ title = d.title;
59
+ slides = d.slides.length;
60
+ }
61
+ catch {
62
+ title = "(cannot be read)";
63
+ }
64
+ out.push({ id, at: atOf(id), title, slides });
65
+ }
66
+ return out;
67
+ }
68
+ export async function readVersion(dir, id) {
69
+ if (!ID_RE.test(id))
70
+ throw new Error(`no version "${id}"`);
71
+ const source = await fs.readFile(path.join(dir, HISTORY_DIR, `${id}.md`), "utf8").catch(() => null);
72
+ if (source === null)
73
+ throw new Error(`no version "${id}"`);
74
+ return { id, at: atOf(id), source, deck: parseDeck(source) };
75
+ }
@@ -13,7 +13,7 @@
13
13
  * like never do. A target that does not exist is reported (found: false),
14
14
  * never an error — the same rule project links have always followed.
15
15
  */
16
- export declare const REF_KIND_NAMES: readonly ["knowledge", "vibeables", "repos", "workflows", "agents", "projects", "contacts", "places", "events", "boards", "tasks"];
16
+ export declare const REF_KIND_NAMES: readonly ["knowledge", "vibeables", "repos", "workflows", "agents", "projects", "contacts", "places", "events", "boards", "tasks", "presentations"];
17
17
  /** The kind's plural: the link-list name in project.yml and the folder/route name. */
18
18
  export type RefKind = (typeof REF_KIND_NAMES)[number];
19
19
  /** One existing target. */
package/dist/core/refs.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { listAgents } from "./agents.js";
2
2
  import { CONTACTS, EVENTS, listEntities, PLACES } from "./entities.js";
3
3
  import { boardKey, listAllBoards } from "./boards.js";
4
+ import { listAllDecks } from "./presentations/index.js";
4
5
  import { knowledgeIndex } from "./knowledge.js";
5
6
  import { listProjects } from "./projects.js";
6
7
  import { listRepos } from "./repos.js";
@@ -21,7 +22,7 @@ import { listWorkflows } from "./workflows.js";
21
22
  * like never do. A target that does not exist is reported (found: false),
22
23
  * never an error — the same rule project links have always followed.
23
24
  */
24
- export const REF_KIND_NAMES = ["knowledge", "vibeables", "repos", "workflows", "agents", "projects", "contacts", "places", "events", "boards", "tasks"];
25
+ export const REF_KIND_NAMES = ["knowledge", "vibeables", "repos", "workflows", "agents", "projects", "contacts", "places", "events", "boards", "tasks", "presentations"];
25
26
  /** A list that fails to read is an empty list: a reference into it is "not found", never an error. */
26
27
  const safe = async (p, fallback) => p.catch(() => fallback);
27
28
  export const REF_KINDS = [
@@ -103,6 +104,13 @@ export const REF_KINDS = [
103
104
  return out;
104
105
  },
105
106
  },
107
+ {
108
+ kind: "presentations",
109
+ token: "presentation",
110
+ noun: "presentation",
111
+ // A deck's name is unique within its project; across the workspace the first match wins and the label names where it is.
112
+ list: async () => (await safe(listAllDecks(), [])).map((d) => ({ slug: d.name, label: d.project ? `${d.title} · project ${d.project}` : d.title, href: d.project ? `/projects/${d.project}/presentations/${d.name}` : `/presentations/${d.name}` })),
113
+ },
106
114
  ];
107
115
  const boardHref = (b) => (b.project ? `/projects/${b.project}/boards/${b.board}` : `/boards/${b.board}`);
108
116
  const byKind = new Map(REF_KINDS.map((d) => [d.kind, d]));
@@ -29,6 +29,16 @@ export interface WorkspaceAgents {
29
29
  entities: EntityHit[];
30
30
  /** Open tasks of this instance's boards; empty for other workspaces and while boards are off. */
31
31
  tasks: TaskHit[];
32
+ /** Decks of this instance; empty for other workspaces and while presentations are off. */
33
+ decks: DeckHit[];
34
+ }
35
+ /** What the palette needs of a presentation. */
36
+ export interface DeckHit {
37
+ name: string;
38
+ title: string;
39
+ project?: string;
40
+ slides: number;
41
+ href: string;
32
42
  }
33
43
  /** What the palette needs of a task. */
34
44
  export interface TaskHit {
@@ -7,6 +7,10 @@ import { currentInstanceUrl, discoverWorkspaces, listWorkspaceRecords } from "./
7
7
  import { CONTACTS, EVENTS, listEntities, PLACES } from "./entities.js";
8
8
  import { listProjects, toProjectHit } from "./projects.js";
9
9
  import { getBoard, listAllBoards } from "./boards.js";
10
+ import { listAllDecks } from "./presentations/index.js";
11
+ async function deckHits() {
12
+ return (await listAllDecks().catch(() => [])).map((d) => ({ name: d.name, title: d.title, ...(d.project ? { project: d.project } : {}), slides: d.slides, href: d.project ? `/projects/${d.project}/presentations/${d.name}` : `/presentations/${d.name}` }));
13
+ }
10
14
  async function taskHits() {
11
15
  const out = [];
12
16
  for (const b of await listAllBoards().catch(() => [])) {
@@ -46,6 +50,7 @@ export async function searchAgents() {
46
50
  projects: (await listProjects().catch(() => ({ projects: [] }))).projects.filter((p) => p.status !== "archived").map(toProjectHit),
47
51
  entities: (await Promise.all([CONTACTS, PLACES, EVENTS].map(entityHits))).flat(),
48
52
  tasks: await taskHits(),
53
+ decks: await deckHits(),
49
54
  };
50
55
  const [workspaces, known] = await Promise.all([discoverWorkspaces(), listWorkspaceRecords()]);
51
56
  const records = new Map(known.map((p) => [p.root, p]));
@@ -64,6 +69,7 @@ export async function searchAgents() {
64
69
  projects: records.get(w.root)?.projects ?? [],
65
70
  entities: [],
66
71
  tasks: [],
72
+ decks: [],
67
73
  }));
68
74
  return { workspaces: [self, ...others] };
69
75
  }
@@ -38,6 +38,8 @@ export interface SaveSettingsInput {
38
38
  events?: ReposSettingsInput;
39
39
  /** Omitted = untouched. Same shape and rules as repos (boards.columns in the file is kept). */
40
40
  boards?: ReposSettingsInput;
41
+ /** Omitted = untouched. Same shape and rules as repos. */
42
+ presentations?: ReposSettingsInput;
41
43
  }
42
44
  export interface ReposSettingsInput {
43
45
  enabled: boolean;
@@ -1,8 +1,9 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { parseDocument } from "yaml";
4
- import { BOARDS_DEFAULT_ROOT, ENTITY_KINDS, entityDefaultRoot, ignoreEntryFor, PROJECTS_DEFAULT_ROOT, REPOS_DEFAULT_ROOT, resolveWorkspace, VIBEABLES_DEFAULT_ROOT, isSafeGitName } from "../config.js";
4
+ import { BOARDS_DEFAULT_ROOT, PRESENTATIONS_DEFAULT_ROOT, ENTITY_KINDS, entityDefaultRoot, ignoreEntryFor, PROJECTS_DEFAULT_ROOT, REPOS_DEFAULT_ROOT, resolveWorkspace, VIBEABLES_DEFAULT_ROOT, isSafeGitName } from "../config.js";
5
5
  import { ensureBoardsRoot } from "./boards.js";
6
+ import { ensurePresentationsRoot } from "./presentations/index.js";
6
7
  import { ensureEntitiesRoot } from "./entities.js";
7
8
  import { ensureProjectsRoot } from "./projects.js";
8
9
  import { disposeAllDevs, ensureVibeablesRoot } from "./vibeables.js";
@@ -86,6 +87,7 @@ const ROOT_DEFAULTS = {
86
87
  places: entityDefaultRoot("places"),
87
88
  events: entityDefaultRoot("events"),
88
89
  boards: BOARDS_DEFAULT_ROOT,
90
+ presentations: PRESENTATIONS_DEFAULT_ROOT,
89
91
  };
90
92
  /** The repos, vibeables, projects, contacts, places or events block to write; null when the feature is off and nothing else is set. */
91
93
  function cleanRootBlock(block, value, projectRoot) {
@@ -191,6 +193,13 @@ export async function saveSettings(input) {
191
193
  else
192
194
  doc.set("boards", { ...(block ?? { enabled: false }), ...(columns ? { columns } : {}) });
193
195
  }
196
+ if (input.presentations !== undefined) {
197
+ const block = cleanRootBlock("presentations", input.presentations, project.root);
198
+ if (block === null)
199
+ doc.delete("presentations");
200
+ else
201
+ doc.set("presentations", block);
202
+ }
194
203
  await fs.writeFile(configPath, doc.toString());
195
204
  // Turning repositories on prepares the folder so the first clone and the
196
205
  // workspace git both find it in the right state.
@@ -205,5 +214,7 @@ export async function saveSettings(input) {
205
214
  await ensureEntitiesRoot(kind).catch(() => { });
206
215
  if (input.boards?.enabled)
207
216
  await ensureBoardsRoot().catch(() => { });
217
+ if (input.presentations?.enabled)
218
+ await ensurePresentationsRoot().catch(() => { });
208
219
  return getSettings();
209
220
  }
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export declare const TRASH_DIR = "kraftwerk-data/trash";
10
10
  /** What can be in the trash; also the folder under trash/ it lands in. */
11
- export type TrashKind = "agents" | "agent-skills" | "projects" | "boards" | "tasks" | "contacts" | "places" | "events" | "workflows" | "knowledge" | "vibeables" | "channels" | "repos" | "chats" | "runs" | "files";
11
+ export type TrashKind = "agents" | "agent-skills" | "projects" | "boards" | "tasks" | "presentations" | "contacts" | "places" | "events" | "workflows" | "knowledge" | "vibeables" | "channels" | "repos" | "chats" | "runs" | "files";
12
12
  export interface TrashEntry {
13
13
  /** Path inside the trash, forward slashes — the entry's handle. */
14
14
  id: string;