@synap-core/workspace-templates 0.44.0 → 0.45.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.
@@ -0,0 +1,322 @@
1
+ /**
2
+ * The piece model (founder decisions D4, D6 and G10, 12 Nov 2026; plan
3
+ * 78c60908 §3): `content-composition` is the piece, a writing object whose
4
+ * outputs (posts, any number per account) are derived from it; an
5
+ * inspiration is kept for its content or its form and linked `inspired_by`;
6
+ * chapters are pieces `part_of` a piece; an account names its default project.
7
+ *
8
+ * SEAMS: the lifecycle is checked against the keys a live pod already holds
9
+ * (the founder's 6 Nov declaration, proposal 305683a8, read back with
10
+ * `GET /api/hub/lifecycle?profileSlug=content-composition` on 12 Nov 2026), so
11
+ * no live row or pod playbook loses its status. The inspiration fields are
12
+ * checked against what the REAL `capture_social_post` code returns (the verb's
13
+ * code run as the pod's executor wraps it, on actor-shaped payloads): a key
14
+ * the reader starts returning fails here until it is mapped or declared
15
+ * not kept.
16
+ *
17
+ * NOT covered: the pod's reconcile (a pod that already declares the lifecycle
18
+ * keeps its own: reconcile-lifecycle.pglite.test.ts in synap-backend), and
19
+ * whether a link written in Content OS's lens from a Market inspiration lands
20
+ * (only a real pod answers).
21
+ */
22
+ import { readFileSync } from "node:fs";
23
+ import { dirname, join } from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+ import { describe, expect, it } from "vitest";
26
+ import { getWorkspaceTemplate } from "./templates.js";
27
+ import type { WorkspaceYaml } from "./types.js";
28
+
29
+ const tpl = (slug: string): WorkspaceYaml => {
30
+ const t = getWorkspaceTemplate(slug);
31
+ if (!t) throw new Error(`${slug} is not registered`);
32
+ return t;
33
+ };
34
+ const contentOs = tpl("content-os");
35
+ const profile = (t: WorkspaceYaml, slug: string) => {
36
+ const p = t.profiles.find((x) => x.slug === slug);
37
+ if (!p) throw new Error(`${t.meta.slug} does not declare ${slug}`);
38
+ return p;
39
+ };
40
+ const piece = profile(contentOs, "content-composition");
41
+ const options = piece.lifecycle?.options ?? [];
42
+ const keys = options.map((o) => o.key);
43
+ const opt = (key: string) => options.find((o) => o.key === key);
44
+
45
+ /** The founder's 6 Nov declaration, as the pod returns it, in its order. */
46
+ const LIVE_KEYS = ["intent", "board", "assets_chosen", "generating", "in_review", "approved", "retired"];
47
+
48
+ describe("the piece: content-composition's one lifecycle", () => {
49
+ it("is declared on the property the live rows carry (`status`), options = enumValues", () => {
50
+ expect(piece.lifecycle?.property).toBe("status");
51
+ const prop = piece.properties.find((p) => p.slug === "status");
52
+ expect(prop?.inputType).toBe("select");
53
+ expect(prop?.enumValues).toEqual(keys);
54
+ expect(prop?.constraints?.defaultValue).toBe(keys[0]);
55
+ });
56
+
57
+ it("keeps every live key, in the live order: no row and no pod playbook loses its status", () => {
58
+ expect(LIVE_KEYS.every((k) => keys.includes(k))).toBe(true);
59
+ const positions = LIVE_KEYS.map((k) => keys.indexOf(k));
60
+ expect(positions).toEqual([...positions].sort((a, b) => a - b));
61
+ });
62
+
63
+ it("starts with writing and ends published: Idea → Drafting → … → Ready → Deriving → Published", () => {
64
+ expect(opt("intent")).toMatchObject({ label: "Idea", category: "open" });
65
+ expect(keys.indexOf("drafting")).toBe(1);
66
+ expect(opt("drafting")?.category).toBe("active");
67
+ expect(opt("approved")).toMatchObject({ label: "Ready", category: "active", humanOnly: true });
68
+ expect(keys.indexOf("deriving")).toBe(keys.indexOf("approved") + 1);
69
+ expect(opt("deriving")?.category).toBe("active");
70
+ expect(opt("published")?.category).toBe("done");
71
+ expect(opt("retired")?.category).toBe("lost");
72
+ // One done step: a ready piece still has its outputs to derive.
73
+ expect(options.filter((o) => o.category === "done").map((o) => o.key)).toEqual(["published"]);
74
+ });
75
+ });
76
+
77
+ describe("the piece's graph", () => {
78
+ const links = contentOs.entityLinks ?? [];
79
+ const has = (s: string, t: string, type: string) =>
80
+ links.some((l) => l.sourceProfileSlug === s && l.targetProfileSlug === t && l.type === type);
81
+ const defs = new Map((contentOs.relationDefs ?? []).map((d) => [d.slug as string, d]));
82
+
83
+ it("an output is derived_from its piece; a chapter is part_of a piece; an idea is used_in it", () => {
84
+ expect(has("post", "content-composition", "derived_from")).toBe(true);
85
+ expect(has("content-composition", "content-composition", "part_of")).toBe(true);
86
+ expect(has("idea", "content-composition", "used_in")).toBe(true);
87
+ });
88
+
89
+ it("declares inspired_by and part_of, directional, with their meaning", () => {
90
+ for (const slug of ["inspired_by", "part_of"]) {
91
+ const d = defs.get(slug) as { isDirectional?: boolean; description?: string } | undefined;
92
+ expect(d?.isDirectional, slug).toBe(true);
93
+ expect(d?.description?.length ?? 0, slug).toBeGreaterThan(20);
94
+ }
95
+ });
96
+
97
+ it("keeps the relations already written on live pods", () => {
98
+ expect(has("content-composition", "post", "made_for")).toBe(true);
99
+ expect(has("content-asset", "content-composition", "used_in")).toBe(true);
100
+ expect(has("post", "post", "derived_from")).toBe(true);
101
+ });
102
+ });
103
+
104
+ describe("an account names its default project", () => {
105
+ it("platform carries default-project-id, a project id (projects are not entities)", () => {
106
+ const prop = profile(contentOs, "platform").properties.find((p) => p.slug === "default-project-id");
107
+ expect(prop).toMatchObject({ valueType: "string", inputType: "text" });
108
+ expect(prop?.targetProfileSlug).toBeUndefined();
109
+ });
110
+ });
111
+
112
+ // ── Inspiration: kept for, and a captured post's fields ─────────────────────
113
+
114
+ const inspiration = profile(tpl("ecosystem"), "inspiration");
115
+ const inspirationProps = new Map(inspiration.properties.map((p) => [p.slug, p]));
116
+
117
+ const HERE = dirname(fileURLToPath(import.meta.url));
118
+ const apify = JSON.parse(readFileSync(join(HERE, "../capabilities/apify.capability.json"), "utf8"));
119
+ const reader = (apify.spec.skills as Array<{ name: string; code?: string }>).find((s) => s.name === "capture_social_post")!;
120
+ const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor as new (
121
+ ...args: string[]
122
+ ) => (...a: unknown[]) => Promise<unknown>;
123
+ const readerBody = new AsyncFunction("args", "context", "callProvider", "propose", reader.code!);
124
+ async function read(url: string, item: unknown): Promise<Record<string, unknown>> {
125
+ const callProvider = async () => ({ status: 201, headers: {}, body: [item] });
126
+ const propose = { entity: async () => ({ status: "proposed" }) };
127
+ return (await readerBody({ url }, {}, callProvider, propose)) as Record<string, unknown>;
128
+ }
129
+ const IG_REEL = {
130
+ url: "https://www.instagram.com/reel/REEL1/",
131
+ type: "Video",
132
+ caption: "Behind the scenes",
133
+ ownerUsername: "studio.x",
134
+ timestamp: "2026-10-02T10:00:00.000Z",
135
+ displayUrl: "https://cdn.example/ig/reel-cover.jpg",
136
+ videoUrl: "https://cdn.example/ig/reel.mp4",
137
+ videoDuration: 31.2,
138
+ likesCount: 90,
139
+ commentsCount: 3,
140
+ videoViewCount: 4200,
141
+ };
142
+ const TIKTOK = {
143
+ webVideoUrl: "https://www.tiktok.com/@maker/video/7400000000000000001",
144
+ text: "How we pack an order",
145
+ createTimeISO: "2026-09-30T18:00:00.000Z",
146
+ authorMeta: { name: "maker", profileUrl: "https://www.tiktok.com/@maker" },
147
+ videoMeta: { coverUrl: "https://cdn.example/tt/cover.jpg", downloadAddr: "https://cdn.example/tt/dl.mp4", width: 720, height: 1280, duration: 22 },
148
+ diggCount: 1500,
149
+ commentCount: 12,
150
+ playCount: 99000,
151
+ };
152
+
153
+ /**
154
+ * Where each key the reader returns lands on an inspiration. `null` = not
155
+ * kept, with why: `status` is the read's outcome, `title` becomes the entity's
156
+ * title, `canonicalUrl` is the same post as `sourceUrl` (kept in `url`).
157
+ */
158
+ const KEPT_AS: Record<string, string | null> = {
159
+ status: null,
160
+ title: null,
161
+ canonicalUrl: null,
162
+ sourceUrl: "url",
163
+ author: "author-handle",
164
+ authorUrl: "author-url",
165
+ text: "post-text",
166
+ publishedAt: "published-at",
167
+ media: "media",
168
+ "fields.platform": "source-platform",
169
+ "fields.likes": "likes",
170
+ "fields.comments": "comments",
171
+ "fields.views": "views",
172
+ };
173
+
174
+ describe("inspiration: kept for, and the post capture_social_post reads", () => {
175
+ it("is kept for content, form or both, with no default (say nothing rather than guess)", () => {
176
+ const keptFor = inspirationProps.get("kept-for");
177
+ expect(keptFor).toMatchObject({ inputType: "select", enumValues: ["content", "form", "both"] });
178
+ expect(keptFor?.constraints?.defaultValue).toBeUndefined();
179
+ });
180
+
181
+ it("keeps the fields a live pod already writes on inspirations", () => {
182
+ for (const slug of ["source-platform", "author-handle", "media-format", "production-layer", "priority", "style-read", "analysis", "why", "url"])
183
+ expect(inspirationProps.has(slug), slug).toBe(true);
184
+ });
185
+
186
+ it("every key the REAL reader returns (Instagram and TikTok) lands on a declared field, or is named not kept", async () => {
187
+ const reads = [await read("https://www.instagram.com/reel/REEL1/", IG_REEL), await read(TIKTOK.webVideoUrl, TIKTOK)];
188
+ const returned = new Set<string>();
189
+ for (const r of reads) {
190
+ expect(r.status).toBe("ok");
191
+ for (const [k, v] of Object.entries(r)) {
192
+ if (k === "fields") for (const f of Object.keys(v as object)) returned.add(`fields.${f}`);
193
+ else returned.add(k);
194
+ }
195
+ }
196
+ // Non-vacuity: the reads carried the post's body, counts and media.
197
+ for (const k of ["text", "author", "publishedAt", "media", "fields.likes", "fields.views"]) expect(returned.has(k), k).toBe(true);
198
+ const unmapped = [...returned].filter((k) => !(k in KEPT_AS));
199
+ expect(unmapped).toEqual([]);
200
+ for (const k of returned) {
201
+ const slug = KEPT_AS[k];
202
+ if (slug) expect(inspirationProps.has(slug), `${k} → ${slug}`).toBe(true);
203
+ }
204
+ });
205
+
206
+ it("each captured value fits its field's type", async () => {
207
+ const r = await read("https://www.instagram.com/reel/REEL1/", IG_REEL);
208
+ const fields = r.fields as Record<string, unknown>;
209
+ expect(inspirationProps.get("likes")?.valueType).toBe(typeof fields.likes === "number" ? "number" : "?");
210
+ expect(inspirationProps.get("views")?.valueType).toBe("number");
211
+ expect(inspirationProps.get("media")?.valueType).toBe(Array.isArray(r.media) ? "array" : "?");
212
+ expect(inspirationProps.get("published-at")?.valueType).toBe("date");
213
+ expect(typeof r.publishedAt).toBe("string");
214
+ });
215
+ });
216
+
217
+ // ── Validated studio designs (12 Nov 2026): board, chapter order, captures, thinking ──
218
+
219
+ describe("the piece's board, its chapters' order, and captures", () => {
220
+ it("a piece names its ONE board by the whiteboard view's id (a view is not an entity)", () => {
221
+ const prop = piece.properties.find((p) => p.slug === "board-view-id");
222
+ expect(prop).toMatchObject({ valueType: "string", inputType: "text" });
223
+ expect(prop?.targetProfileSlug).toBeUndefined();
224
+ });
225
+
226
+ it("part_of says where a chapter's order lives: the edge's metadata.order", () => {
227
+ const d = (contentOs.relationDefs ?? []).find((x) => x.slug === "part_of") as { description?: string } | undefined;
228
+ expect(d?.description).toContain("metadata.order");
229
+ });
230
+
231
+ it("a capture is a note with where it came from and its transcript, sorted into a piece by used_in", () => {
232
+ const note = profile(contentOs, "note");
233
+ const by = new Map(note.properties.map((p) => [p.slug, p]));
234
+ expect(by.get("capture-source")).toMatchObject({ inputType: "select", enumValues: ["relay", "voice", "link", "email", "studio"] });
235
+ expect(by.get("transcript")?.inputType).toBe("textarea");
236
+ expect(note.lifecycle).toBeUndefined();
237
+ expect((contentOs.entityLinks ?? []).some((l) => l.sourceProfileSlug === "note" && l.targetProfileSlug === "content-composition" && l.type === "used_in")).toBe(true);
238
+ });
239
+ });
240
+
241
+ describe("Thinking session: a timeboxed process on one piece, the AI never writes it", () => {
242
+ const pb = (contentOs.playbooks ?? []).find((p) => p.name === "Thinking session");
243
+
244
+ it("works one piece, with a timebox param of 60 minutes by default", () => {
245
+ expect(pb?.subjectProfile?.profileSlug).toBe("content-composition");
246
+ const params = (pb?.params ?? []) as Array<{ name: string; type: string; default?: unknown; required?: boolean }>;
247
+ expect(params.find((p) => p.name === "piece")).toMatchObject({ type: "entity", required: true });
248
+ expect(params.find((p) => p.name === "minutes")).toMatchObject({ type: "number", default: 60 });
249
+ expect(pb?.goalTemplate).toContain("{minutes}");
250
+ });
251
+
252
+ it("gather → questions → thesis → draft; only the person-approved draft moves the piece, to Drafting", () => {
253
+ const stages = pb?.stages ?? [];
254
+ expect(stages.map((s) => s.key)).toEqual(["gather", "questions", "thesis", "draft"]);
255
+ const moving = stages.filter((s) => s.subjectStatus);
256
+ expect(moving.map((s) => [s.key, s.subjectStatus])).toEqual([["draft", "drafting"]]);
257
+ expect(keys).toContain("drafting");
258
+ const draft = stages.find((s) => s.key === "draft");
259
+ expect(draft?.gate).toEqual({ kind: "human" });
260
+ expect(draft?.onFail).toEqual({ toStage: "questions" });
261
+ });
262
+
263
+ it("says the AI never writes the piece, and stitches the person's answers in their order", () => {
264
+ expect(pb?.goalTemplate).toMatch(/never write the piece/i);
265
+ expect(pb?.goalTemplate).toMatch(/order they/i);
266
+ });
267
+ });
268
+
269
+ describe("Derive outputs: posts (any number per account) and a newsletter issue, derived_from the piece", () => {
270
+ const pb = (contentOs.playbooks ?? []).find((p) => p.name === "Derive outputs");
271
+ const post = profile(contentOs, "post");
272
+ const postProps = new Set(post.properties.map((p) => p.slug));
273
+ const goal = pb?.goalTemplate ?? "";
274
+
275
+ it("works a piece, as an agent, with the params the studio sends", () => {
276
+ expect(pb?.subjectProfile?.profileSlug).toBe("content-composition");
277
+ expect(pb?.executor).toBe("is-agent");
278
+ expect(pb?.tools).toEqual(["create_entity", "create_relation"]);
279
+ const params = (pb?.params ?? []) as Array<{ name: string; type: string; required?: boolean }>;
280
+ expect(params.map((p) => [p.name, p.type])).toEqual([
281
+ ["piece", "entity"],
282
+ ["accounts", "text"],
283
+ ["posts", "number"],
284
+ ["from", "text"],
285
+ ]);
286
+ expect(params.find((p) => p.name === "piece")?.required).toBe(true);
287
+ for (const p of params) expect(goal, p.name).toContain(`{${p.name}}`);
288
+ });
289
+
290
+ it("every post field the goal names is a real post field, and Idea is the post lifecycle's first step", () => {
291
+ const named = ["post-status", "post-account", "publish-date", "post-hook", "content", "post-platform"];
292
+ for (const f of named) {
293
+ expect(goal, f).toContain(f);
294
+ expect(postProps.has(f), f).toBe(true);
295
+ }
296
+ expect(post.lifecycle?.options[0]?.key).toBe("Idea");
297
+ expect(profile(contentOs, "newsletter").lifecycle?.options[0]?.key).toBe("Idea");
298
+ });
299
+
300
+ it("spreads posts over two weeks, never two on one account the same day, skipping taken days", () => {
301
+ expect(goal).toMatch(/two weeks/);
302
+ expect(goal).toMatch(/never two posts on one account the same day/);
303
+ expect(goal).toMatch(/skip any day/);
304
+ });
305
+
306
+ it("each output is derived_from the piece, declared as a link the space knows", () => {
307
+ expect(pb?.expectedOutputs?.map((o) => [o.kind, o.relationToSubject])).toEqual([
308
+ ["post", "derived_from"],
309
+ ["newsletter", "derived_from"],
310
+ ]);
311
+ const links = contentOs.entityLinks ?? [];
312
+ for (const kind of ["post", "newsletter"])
313
+ expect(links.some((l) => l.sourceProfileSlug === kind && l.targetProfileSlug === "content-composition" && l.type === "derived_from"), kind).toBe(true);
314
+ });
315
+
316
+ it("writes only through its own tools, and leaves the piece's status alone (no update tool)", () => {
317
+ expect(goal).toContain("(create_entity)");
318
+ expect(goal).toContain("(create_relation)");
319
+ expect(goal).not.toMatch(/synap_capture|synap_update_entity|update_entity/);
320
+ expect(goal).toMatch(/piece's own status is not moved/);
321
+ });
322
+ });