@synap-core/workspace-templates 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -206,7 +206,12 @@ export interface TemplateProfile {
206
206
  }
207
207
 
208
208
  /** Fixed categories (`@synap-core/types/lifecycle` LIFECYCLE_CATEGORIES). */
209
- export type TemplateLifecycleCategory = "open" | "active" | "paused" | "done" | "lost";
209
+ export type TemplateLifecycleCategory =
210
+ | "open"
211
+ | "active"
212
+ | "paused"
213
+ | "done"
214
+ | "lost";
210
215
 
211
216
  export interface TemplateLifecycleOption {
212
217
  /** The stored value — one of the property's `enumValues`. */
@@ -248,7 +253,11 @@ export type TemplateLifecycleRequirement = {
248
253
  blockerKey: string;
249
254
  label?: string;
250
255
  /** Exactly one of `{answer: true}`, `{intent}`, `{playbookId}`, `{capability}`. */
251
- clearedBy?: { answer: true } | { intent: string } | { playbookId: string } | { capability: string };
256
+ clearedBy?:
257
+ | { answer: true }
258
+ | { intent: string }
259
+ | { playbookId: string }
260
+ | { capability: string };
252
261
  /** Whose move it is; absent ⇒ `you`. */
253
262
  owner?: "you" | "agent";
254
263
  /** Only things of these kinds (profile slugs) are held to it. */
@@ -261,7 +270,14 @@ export type TemplateLifecycleRequirement = {
261
270
  /** A step's declared wait (the pod's `LifecycleOptionWaits`). */
262
271
  export interface TemplateLifecycleOptionWaits {
263
272
  /** A hold's `on`, never `unspecified`: person · agent · external · thing · decision · date · nobody. */
264
- on: "person" | "agent" | "external" | "thing" | "decision" | "date" | "nobody";
273
+ on:
274
+ | "person"
275
+ | "agent"
276
+ | "external"
277
+ | "thing"
278
+ | "decision"
279
+ | "date"
280
+ | "nobody";
265
281
  /** The finer kind (`WAIT_KINDS`: "signature", "payment"…); absent ⇒ derived from `on`. */
266
282
  waitKind?: string;
267
283
  /** The property or relation naming WHO or WHAT is waited on (a deal's `contactId`). */
@@ -615,7 +631,12 @@ export interface TemplatePlaybook {
615
631
  * The rules the process follows, in order (pod `playbookGuidanceSchema`,
616
632
  * backend#924): `{ ref: "kind:<slug>" | "skill:<slug>", label?, when?, where? }`.
617
633
  */
618
- guidance?: Array<{ ref: string; label?: string; when?: string; where?: Record<string, string[]> }>;
634
+ guidance?: Array<{
635
+ ref: string;
636
+ label?: string;
637
+ when?: string;
638
+ where?: Record<string, string[]>;
639
+ }>;
619
640
  /**
620
641
  * DECLARATIONS of when the process starts. Compiled at install/apply into
621
642
  * governed rules through the pod's ONE rule door and linked in
@@ -641,7 +662,13 @@ export interface TemplatePlaybook {
641
662
  export interface TemplatePlaybookStage {
642
663
  key: string;
643
664
  name: string;
644
- category: "backlog" | "planned" | "started" | "paused" | "completed" | "canceled";
665
+ category:
666
+ | "backlog"
667
+ | "planned"
668
+ | "started"
669
+ | "paused"
670
+ | "completed"
671
+ | "canceled";
645
672
  description?: string;
646
673
  goal?: string;
647
674
  suggestedTasks?: string[];
@@ -1078,7 +1105,9 @@ export interface TemplateMeta {
1078
1105
  * else the space's primary output. The ONE derivation — the validator and the
1079
1106
  * wire converter (`define.ts`) both read it.
1080
1107
  */
1081
- export function startProfileOf(meta: Pick<TemplateMeta, "intent" | "start">): string | undefined {
1108
+ export function startProfileOf(
1109
+ meta: Pick<TemplateMeta, "intent" | "start">
1110
+ ): string | undefined {
1082
1111
  return meta.start?.profile ?? meta.intent?.primary;
1083
1112
  }
1084
1113
 
@@ -0,0 +1,256 @@
1
+ /**
2
+ * The UI inventory on the pod (plan 48854969 §9, founder decisions D0/D1/D3,
3
+ * 23 Nov 2026): what Storybook shows, mirrored as `ui-component`, `ui-page`
4
+ * and `user-flow` records, the review of a component, and the Storybook
5
+ * capability that feeds them.
6
+ *
7
+ * What this guards:
8
+ * 1. the three kinds carry the contract's lifecycle (keys, categories, the
9
+ * person-only options) and land pod-wide, like `ui-design`;
10
+ * 2. a page's template and layout are the page grammar's own lists
11
+ * (`@synap-core/headless/surface-runtime` PAGE_TEMPLATES / PAGE_LAYOUTS),
12
+ * read from that file, not restated;
13
+ * 3. composition, variants, a flow's pages and the app are links the
14
+ * template declares;
15
+ * 4. "Review a UI component" FOLLOWS ui-component: its verdict branches
16
+ * before any code, the fix is built and gated before the ONE human gate
17
+ * (the approval, D3), which releases land, publish and done; the weekly
18
+ * fan-out is a per_thing schedule over the changed components;
19
+ * 5. "Design a user flow" works the user flow: its stages name options of
20
+ * the flow's lifecycle;
21
+ * 6. Dev installs the two design skills it tells agents to load (each a
22
+ * catalog package), so `design-critique` is no longer "not found";
23
+ * 7. the storybook capability declares its two builtin verbs, the change
24
+ * list read-only.
25
+ *
26
+ * Each verb's `parameters` IS `STORYBOOK_VERB_PARAMETERS`
27
+ * (`@synap-core/types/storybook`), the one param contract the backend's
28
+ * catalog-coherence tripwire also reads.
29
+ *
30
+ * Not covered: the verbs' behaviour on the pod (backend), and whether the pod
31
+ * honours a per_thing schedule with `only`.
32
+ */
33
+ import { existsSync, readFileSync } from "node:fs";
34
+ import { join } from "node:path";
35
+ import { describe, expect, it } from "vitest";
36
+ import {
37
+ STORYBOOK_CAPABILITY_KEY,
38
+ STORYBOOK_VERBS,
39
+ STORYBOOK_VERB_PARAMETERS,
40
+ } from "@synap-core/types/storybook";
41
+ import { getWorkspaceTemplate } from "./templates.js";
42
+
43
+ const builder = getWorkspaceTemplate("builder-workspace")!;
44
+ const kind = (slug: string) => builder.profiles.find((p) => p.slug === slug)!;
45
+ type Lifecycle = { property: string; options: { key: string; category: string; humanOnly?: boolean }[] };
46
+ const lifecycleOf = (slug: string) => (kind(slug) as unknown as { lifecycle: Lifecycle }).lifecycle;
47
+ const enumOf = (slug: string, prop: string) =>
48
+ kind(slug).properties.find((p) => p.slug === prop)?.enumValues as string[] | undefined;
49
+
50
+ type Stage = {
51
+ key: string;
52
+ subjectStatus?: string;
53
+ onApproved?: string;
54
+ gate?: { kind: string };
55
+ onFail?: { toStage: string };
56
+ };
57
+ type Pb = {
58
+ name: string;
59
+ subjectProfile?: { profileSlug: string };
60
+ activators?: { on: string; size?: string; only?: { property: string; in: string[] }; cron?: string }[];
61
+ stages: Stage[];
62
+ };
63
+ const playbook = (name: string) =>
64
+ (builder.playbooks as unknown as Pb[]).find((p) => p.name === name)!;
65
+
66
+ /** A `const NAME = [ "a", "b" ] as const` list, read from source text. */
67
+ function constList(source: string, name: string): string[] {
68
+ const m = source.match(new RegExp(`export const ${name} = \\[([^\\]]*)\\]`));
69
+ if (!m) throw new Error(`${name} not found`);
70
+ return [...m[1].matchAll(/"([^"]+)"/g)].map((x) => x[1]);
71
+ }
72
+
73
+ describe("UI inventory kinds", () => {
74
+ it("ui-component and ui-page share the ui-status lifecycle of the contract", () => {
75
+ for (const slug of ["ui-component", "ui-page"]) {
76
+ const lc = lifecycleOf(slug);
77
+ expect(lc.property, slug).toBe("ui-status");
78
+ expect(lc.options.map((o) => [o.key, o.category]), slug).toEqual([
79
+ ["proposed", "open"],
80
+ ["stable", "active"],
81
+ ["consolidate", "active"],
82
+ ["deprecated", "done"],
83
+ ["gone", "lost"],
84
+ ]);
85
+ // deprecated is a person's call; gone is the sync's, so it is not person-only.
86
+ expect(lc.options.filter((o) => o.humanOnly).map((o) => o.key), slug).toEqual(["deprecated"]);
87
+ expect(enumOf(slug, "ui-status"), slug).toEqual(lc.options.map((o) => o.key));
88
+ }
89
+ });
90
+
91
+ it("user-flow runs draft → designed → built → live, retired; live and retired are a person's", () => {
92
+ const lc = lifecycleOf("user-flow");
93
+ expect(lc.property).toBe("flow-status");
94
+ expect(lc.options.map((o) => [o.key, o.category])).toEqual([
95
+ ["draft", "open"],
96
+ ["designed", "active"],
97
+ ["built", "active"],
98
+ ["live", "done"],
99
+ ["retired", "lost"],
100
+ ]);
101
+ expect(lc.options.filter((o) => o.humanOnly).map((o) => o.key)).toEqual(["live", "retired"]);
102
+ });
103
+
104
+ it("the three kinds land pod-wide, like the live ui-design", () => {
105
+ for (const slug of ["ui-component", "ui-page", "user-flow"])
106
+ expect((kind(slug) as unknown as { entityScope?: string }).entityScope, slug).toBe("pod");
107
+ });
108
+
109
+ it("a component carries what the sync and the review write", () => {
110
+ const props = new Set(kind("ui-component").properties.map((p) => p.slug));
111
+ for (const p of [
112
+ "component-level", "source-path", "export-name", "story-ids", "story-url", "screenshot",
113
+ "props-summary", "component-family", "kit", "design-app", "source-hash", "reviewed-hash", "review-state",
114
+ ])
115
+ expect(props.has(p), p).toBe(true);
116
+ expect(enumOf("ui-component", "review-state")).toEqual(["fresh", "changed", "in-review"]);
117
+ expect(enumOf("ui-component", "component-level")).toEqual(["primitive", "composite", "section", "layout"]);
118
+ });
119
+
120
+ it("a page's template and layout are the page grammar's lists", () => {
121
+ const source = readFileSync(
122
+ join(__dirname, "..", "..", "headless", "src", "surface-runtime", "page-grammar.ts"),
123
+ "utf8"
124
+ );
125
+ const templates = constList(source, "PAGE_TEMPLATES");
126
+ const layouts = constList(source, "PAGE_LAYOUTS");
127
+ expect(templates).toHaveLength(9); // non-vacuity
128
+ expect(layouts).toHaveLength(6);
129
+ expect(enumOf("ui-page", "page-template")).toEqual(templates);
130
+ expect(enumOf("ui-page", "page-layout")).toEqual(layouts);
131
+ });
132
+
133
+ // Dev installs on pods that hold neither Brand nor Foundation (Foundation is
134
+ // not on every pod: backend workspace-reconcile-order.ts). So a record links
135
+ // only to kinds Dev declares itself, or to a pod file: no per-record brand
136
+ // (the brand identity is the Storybook sync SOURCE's config, lead decision
137
+ // 23 Nov 2026) and no audience.
138
+ it("their entity fields point only at kinds Dev declares, or a file: no brand, no audience per record", () => {
139
+ const own = new Set(builder.profiles.map((p) => p.slug));
140
+ const targets = ["ui-component", "ui-page", "user-flow"].flatMap((slug) =>
141
+ kind(slug)
142
+ .properties.filter((p) => p.valueType === "entity_id")
143
+ .map((p) => `${slug}.${p.slug}→${(p as { targetProfileSlug?: string }).targetProfileSlug}`),
144
+ );
145
+ expect(targets.length).toBeGreaterThan(0);
146
+ for (const t of targets) {
147
+ const target = t.split("→")[1];
148
+ expect(target === "file" || own.has(target), t).toBe(true);
149
+ }
150
+ });
151
+
152
+ it("composition, variants, a flow's pages and the app are declared links", () => {
153
+ const links = new Set(
154
+ (builder.entityLinks ?? []).map((l) => `${l.sourceProfileSlug}>${l.type}>${l.targetProfileSlug}`)
155
+ );
156
+ for (const l of [
157
+ "ui-component>composed_of>ui-component",
158
+ "ui-page>composed_of>ui-component",
159
+ "ui-component>extends>ui-component",
160
+ "user-flow>traverses>ui-page",
161
+ "ui-component>belongs_to>devplane_app",
162
+ "ui-page>belongs_to>devplane_app",
163
+ "user-flow>belongs_to>devplane_app",
164
+ ])
165
+ expect(links.has(l), l).toBe(true);
166
+ const defs = new Set((builder.relationDefs ?? []).map((d) => d.slug));
167
+ for (const slug of ["composed_of", "extends", "traverses", "belongs_to"]) expect(defs.has(slug), slug).toBe(true);
168
+ });
169
+ });
170
+
171
+ describe("Review a UI component", () => {
172
+ const pb = playbook("Review a UI component");
173
+
174
+ it("follows ui-component and moves no ui-status", () => {
175
+ expect(pb.subjectProfile?.profileSlug).toBe("ui-component");
176
+ expect(pb.stages.filter((s) => s.subjectStatus || s.onApproved)).toEqual([]);
177
+ });
178
+
179
+ it("asks the person ONCE, after the fix is built and gated, and that approval releases land, publish and done", () => {
180
+ const keys = pb.stages.map((s) => s.key);
181
+ // The keys the one-approval mechanism (lane l5) attaches to.
182
+ expect(keys).toEqual(["critique", "verdict", "implement", "gate", "approve", "land", "publish", "done"]);
183
+ const human = pb.stages.filter((s) => s.gate?.kind === "human").map((s) => s.key);
184
+ expect(human).toEqual(["approve"]);
185
+ expect(keys.indexOf("approve")).toBeGreaterThan(keys.indexOf("gate"));
186
+ expect(pb.stages.find((s) => s.key === "gate")?.gate?.kind).toBe("check");
187
+ for (const s of pb.stages)
188
+ if (s.onFail) expect(keys, `${s.key}.onFail`).toContain(s.onFail.toStage);
189
+ // The verdict branches before any code: fine ends the run, a rewrite stops on the person.
190
+ const verdict = (pb.stages.find((s) => s.key === "verdict") as unknown as { goal: string }).goal;
191
+ expect(verdict).toMatch(/FINE:[^]*the run ends, nothing is built/);
192
+ expect(verdict).toMatch(/REWRITE:[^]*never go on to Implement/);
193
+ });
194
+
195
+ it("each week, opens one review per component that changed since its last review", () => {
196
+ const weekly = (pb.activators ?? []).find((a) => a.on === "schedule");
197
+ expect(weekly?.size).toBe("per_thing");
198
+ expect(weekly?.only).toEqual({ property: "review-state", in: ["changed"] });
199
+ expect(enumOf("ui-component", "review-state")).toContain("changed");
200
+ expect((pb.activators ?? []).some((a) => a.on === "manual")).toBe(true);
201
+ });
202
+ });
203
+
204
+ describe("Design a user flow", () => {
205
+ const pb = playbook("Design a user flow (UX, from need to buildable design)");
206
+
207
+ it("works the user flow through its own lifecycle", () => {
208
+ expect(pb.subjectProfile?.profileSlug).toBe("user-flow");
209
+ const options = new Set(lifecycleOf("user-flow").options.map((o) => o.key));
210
+ const moves = pb.stages.flatMap((s) => [s.subjectStatus, s.onApproved]).filter(Boolean);
211
+ expect(moves.length).toBeGreaterThanOrEqual(2); // non-vacuity: draft, designed
212
+ expect(moves.filter((m) => !options.has(m!))).toEqual([]);
213
+ const choose = pb.stages.find((s) => s.key === "choose")!;
214
+ expect(choose.gate?.kind).toBe("human");
215
+ expect(choose.onApproved).toBe("designed");
216
+ });
217
+ });
218
+
219
+ describe("the design skills and the storybook capability", () => {
220
+ const root = join(__dirname, "..");
221
+
222
+ it("Dev installs and links the skills its processes tell agents to load", () => {
223
+ const deps = ((builder as unknown as { dependencies?: { slug: string; kind?: string; relation: string }[] }).dependencies ?? [])
224
+ .filter((d) => d.kind === "skill")
225
+ .map((d) => d.slug);
226
+ const linked = ((builder as unknown as { skills?: { slug: string }[] }).skills ?? []).map((s) => s.slug);
227
+ for (const slug of ["design-critique", "designing-with-real-components"]) {
228
+ expect(deps, slug).toContain(slug);
229
+ expect(linked, slug).toContain(slug);
230
+ expect(existsSync(join(root, "skills", `${slug}.catalog.json`)), slug).toBe(true);
231
+ expect(existsSync(join(root, "skills", slug, "SKILL.md")), slug).toBe(true);
232
+ }
233
+ });
234
+
235
+ it("the storybook capability declares its two builtin verbs with the one param contract, the change list read-only", () => {
236
+ const manifest = JSON.parse(readFileSync(join(root, "capabilities", "storybook.capability.json"), "utf8")) as {
237
+ meta: { slug: string };
238
+ spec: {
239
+ key: string;
240
+ skills: { name: string; kind: string; scope: string; parameters: unknown; metadata?: { readOnly?: boolean } }[];
241
+ };
242
+ };
243
+ expect(manifest.meta.slug).toBe(STORYBOOK_CAPABILITY_KEY);
244
+ expect(manifest.spec.key).toBe(STORYBOOK_CAPABILITY_KEY);
245
+ expect(manifest.spec.skills.map((s) => s.name).sort()).toEqual([...STORYBOOK_VERBS].sort());
246
+ for (const s of manifest.spec.skills) {
247
+ expect(s.kind, s.name).toBe("builtin");
248
+ expect(s.scope, s.name).toBe("pod");
249
+ expect(s.parameters, s.name).toEqual(STORYBOOK_VERB_PARAMETERS[s.name as (typeof STORYBOOK_VERBS)[number]]);
250
+ }
251
+ const changed = manifest.spec.skills.find((s) => s.name === "storybook.changed");
252
+ const sync = manifest.spec.skills.find((s) => s.name === "storybook.sync");
253
+ expect(changed?.metadata?.readOnly).toBe(true);
254
+ expect(sync?.metadata?.readOnly).toBeUndefined();
255
+ });
256
+ });