@synap-core/workspace-templates 0.72.0 → 0.73.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synap-core/workspace-templates",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "type": "module",
5
5
  "description": "Canonical workspace definitions — YAML source + typed exports for browser, backend, CLI, and marketplace",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",
@@ -17,17 +17,32 @@
17
17
  * it proves the criteria and the field AGREE, not which values they hold (the
18
18
  * first test pins those). It goes red when only one side changes.
19
19
  *
20
- * Not covered: grouping works by the Claude Code session that worked them.
21
- * That id lives on the session, not the feature; it waits on a pod read.
20
+ * The Claude Code session (backend#1449, migration 0468): the POD writes
21
+ * `workedIn` / `workedInAll` on a work from the sessions that took it as
22
+ * subject. The catalog only DECLARES them, so a board can group by
23
+ * `workedIn` and a view can filter on `workedInAll`; nothing in the catalog
24
+ * may give them a value (the pod's triggers would strip it anyway). The key
25
+ * set is pinned to the backend's `SERVER_DERIVED_PROPERTY_KEYS` when the
26
+ * synap-backend sibling is beside this repo (the devbox gate tree; skipped,
27
+ * with a warning, where it is absent).
28
+ *
29
+ * Not covered: what the pod actually writes, and how a board labels a column
30
+ * (the humanized id): NEEDS-DOGFOOD on a pod with the Builder updated.
22
31
  */
32
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
33
+ import { dirname, join } from "node:path";
34
+ import { fileURLToPath } from "node:url";
23
35
  import { describe, expect, it } from "vitest";
24
36
  import { readYamlTemplates } from "./generate.mjs";
37
+ import { SERVER_DERIVED_PROPERTY_KEYS, validateTemplate } from "./validate.js";
38
+ import type { WorkspaceYaml } from "./types.js";
25
39
 
26
40
  type Property = {
27
41
  slug: string;
28
42
  valueType: string;
29
43
  inputType?: string;
30
44
  enumValues?: string[];
45
+ label?: string;
31
46
  constraints?: { defaultValue?: unknown };
32
47
  };
33
48
  type View = {
@@ -50,8 +65,8 @@ type Template = {
50
65
  playbooks: Playbook[];
51
66
  };
52
67
 
53
- const builder = readYamlTemplates().find((t) => t.slug === "builder-workspace")!
54
- .data as unknown as Template;
68
+ const corpus = readYamlTemplates();
69
+ const builder = corpus.find((t) => t.slug === "builder-workspace")!.data as unknown as Template;
55
70
  const feature = builder.profiles.find((p) => p.slug === "devplane_feature")!;
56
71
  const prop = (slug: string) => feature.properties.find((p) => p.slug === slug);
57
72
  const bare = (field: string) => field.replace(/^properties\./, "");
@@ -85,15 +100,15 @@ describe("the works views", () => {
85
100
  expect(byName("Feature cards")).toMatchObject({ type: "grid", config: { cardSettings: { colorField: "change" } } });
86
101
  });
87
102
 
88
- it("every field a works view names is a property of the feature (non-vacuity: 4 views)", () => {
89
- const works = ["Feature Board", "Features by type", "Feature list", "Feature cards"].map(byName);
103
+ it("every field a works view names is a property of the feature (non-vacuity: 5 views)", () => {
104
+ const works = ["Feature Board", "Features by type", "Feature list", "Feature cards", "Features by Claude Code session"].map(byName);
90
105
  expect(works.every(Boolean)).toBe(true);
91
106
  const named = works.flatMap((v) => [
92
107
  ...(v!.config?.cardFields ?? []),
93
108
  ...(v!.config?.groupByField ? [v!.config.groupByField] : []),
94
109
  ...(v!.config?.cardSettings?.colorField ? [v!.config.cardSettings.colorField] : []),
95
110
  ]);
96
- expect(named).toEqual(expect.arrayContaining(["change", "repos"]));
111
+ expect(named.map(bare)).toEqual(expect.arrayContaining(["change", "repos", "workedIn"]));
97
112
  expect(named.map(bare).filter((f) => !prop(f))).toEqual([]);
98
113
  });
99
114
  });
@@ -109,3 +124,84 @@ describe("the Shape step teaches the same types the field holds", () => {
109
124
  }
110
125
  });
111
126
  });
127
+
128
+ describe("the Claude Code session: the pod writes it, the catalog only declares it", () => {
129
+ const PKG = join(dirname(fileURLToPath(import.meta.url)), "..");
130
+ const MONO = join(PKG, "../../..");
131
+ const BACKEND_KEYS = join(MONO, "synap-backend/packages/database/src/utils/worked-in.ts");
132
+
133
+ it("workedIn (one string) and workedInAll (a list) are declared with plain labels and no value", () => {
134
+ expect(prop("workedIn")).toMatchObject({ valueType: "string", label: "Claude Code session" });
135
+ expect(prop("workedInAll")).toMatchObject({ valueType: "array", label: "All Claude Code sessions" });
136
+ for (const slug of SERVER_DERIVED_PROPERTY_KEYS) {
137
+ expect({ slug, enumValues: prop(slug)?.enumValues, constraints: prop(slug)?.constraints }).toEqual({
138
+ slug,
139
+ enumValues: undefined,
140
+ constraints: undefined,
141
+ });
142
+ }
143
+ });
144
+
145
+ it("a board groups works by workedIn, with Feature Board's cards", () => {
146
+ const board = builder.views.find((v) => v.name === "Features by Claude Code session");
147
+ const featureBoard = builder.views.find((v) => v.name === "Feature Board")!;
148
+ expect(board).toMatchObject({ type: "kanban", scopeProfileSlug: "devplane_feature", config: { groupByField: "properties.workedIn" } });
149
+ expect(board!.config!.cardFields).toEqual(featureBoard.config!.cardFields);
150
+ expect(board!.config!.cardSettings).toEqual(featureBoard.config!.cardSettings);
151
+ });
152
+
153
+ it("no template, example, playbook, view filter or automation in the catalog names them otherwise", () => {
154
+ // Every YAML template, with the two declarations and the one grouping removed.
155
+ const stray = corpus.flatMap((t) => {
156
+ const data = structuredClone(t.data) as unknown as Template;
157
+ if (t.slug === "builder-workspace") {
158
+ const f = data.profiles.find((p) => p.slug === "devplane_feature")!;
159
+ f.properties = f.properties.filter((p) => !SERVER_DERIVED_PROPERTY_KEYS.includes(p.slug));
160
+ data.views = data.views.filter((v) => v.name !== "Features by Claude Code session");
161
+ }
162
+ return SERVER_DERIVED_PROPERTY_KEYS.some((k) => JSON.stringify(data).includes(k)) ? [t.slug] : [];
163
+ });
164
+ expect(stray).toEqual([]);
165
+ // Every other catalog file (automations, capabilities, skills, agents, views).
166
+ const files: string[] = [];
167
+ const walk = (dir: string) => {
168
+ if (!existsSync(dir)) return;
169
+ for (const name of readdirSync(dir)) {
170
+ const path = join(dir, name);
171
+ if (statSync(path).isDirectory()) walk(path);
172
+ else files.push(path);
173
+ }
174
+ };
175
+ for (const dir of ["automations", "capabilities", "skills", "agents", "views"]) walk(join(PKG, dir));
176
+ expect(files.length).toBeGreaterThan(50);
177
+ const named = files.filter((f) => SERVER_DERIVED_PROPERTY_KEYS.some((k) => readFileSync(f, "utf8").includes(k)));
178
+ expect(named).toEqual([]);
179
+ });
180
+
181
+ it("a template that gives them a value is refused (property-server-derived-value)", () => {
182
+ const data = structuredClone(builder) as unknown as Template;
183
+ data.profiles.find((p) => p.slug === "devplane_feature")!.properties.find((p) => p.slug === "workedIn")!.constraints = {
184
+ defaultValue: "claude-code:x",
185
+ };
186
+ const rules = validateTemplate(data as unknown as WorkspaceYaml, { corpus: corpus.map((t) => t.data as WorkspaceYaml) })
187
+ .errors.map((e) => e.rule);
188
+ expect(rules).toContain("property-server-derived-value");
189
+ const clean = validateTemplate(builder as unknown as WorkspaceYaml, { corpus: corpus.map((t) => t.data as WorkspaceYaml) })
190
+ .errors.map((e) => e.rule);
191
+ expect(clean).not.toContain("property-server-derived-value");
192
+ });
193
+
194
+ const hasBackend = existsSync(BACKEND_KEYS);
195
+ if (!hasBackend) console.warn(`[builder-work-views] SKIP the backend pin: ${BACKEND_KEYS} is absent`);
196
+ it.skipIf(!hasBackend)("the key set equals the backend's SERVER_DERIVED_PROPERTY_KEYS", () => {
197
+ const text = readFileSync(BACKEND_KEYS, "utf8");
198
+ const consts = Object.fromEntries(
199
+ [...text.matchAll(/export const (\w+) = "([^"]+)";/g)].map((m) => [m[1], m[2]])
200
+ );
201
+ const set = text.match(/SERVER_DERIVED_PROPERTY_KEYS[^=]*=\s*new Set\(\[([^\]]*)\]\)/);
202
+ expect(set).not.toBeNull();
203
+ const keys = set![1].split(",").map((s) => s.trim()).filter(Boolean).map((id) => consts[id] ?? id.replace(/"/g, ""));
204
+ expect(keys.length).toBeGreaterThanOrEqual(2);
205
+ expect([...keys].sort()).toEqual([...SERVER_DERIVED_PROPERTY_KEYS].sort());
206
+ });
207
+ });
package/src/builder.yaml CHANGED
@@ -219,6 +219,25 @@ profiles:
219
219
  valueType: array
220
220
  inputType: tags
221
221
  description: "The repositories this work touches, each as <owner>/<repo> (e.g. Synap-core/backend). Set when the work is shaped."
222
+ # The Claude Code sessions that worked this work (founder, 30 Nov 2026,
223
+ # cockpit plan 488556d7, option A; backend#1449, migration 0468). The POD
224
+ # writes both from the sessions that took the work as subject: database
225
+ # triggers keep them read-only for every other writer and strip them from
226
+ # an insert. Declared here only so a saved view can show and filter them
227
+ # (filters need a property definition). So: no default, no enumValues, and
228
+ # no example, playbook or automation in the catalog ever sets them.
229
+ # Value `<harness>:<conversationId>` (e.g. `claude-code:3ea0b8f5-...`);
230
+ # absent when no session worked it, null when none named a conversation.
231
+ - slug: workedIn
232
+ label: Claude Code session
233
+ valueType: string
234
+ inputType: text
235
+ description: "Written by the pod: the Claude Code session (<harness>:<conversation id>) that most recently started a session on this work. Read-only."
236
+ - slug: workedInAll
237
+ label: All Claude Code sessions
238
+ valueType: array
239
+ inputType: tags
240
+ description: "Written by the pod: every Claude Code session that worked this work, newest first. Read-only."
222
241
  - slug: linkedApp
223
242
  label: Linked App
224
243
  valueType: string
@@ -1957,8 +1976,7 @@ views:
1957
1976
  # The works views (founder, 30 Nov 2026, cockpit plan 488556d7): the same
1958
1977
  # works sorted by type, as a list and as cards, so every renderer can offer
1959
1978
  # them. Filtering by type or repo is the view's filter bar, over `change` and
1960
- # `repos`. Grouping by the Claude Code session that worked a work waits on a
1961
- # pod read (the session holds that id, the feature does not).
1979
+ # `repos`; by Claude Code session, over the pod-written `workedInAll`.
1962
1980
  - name: Features by type
1963
1981
  slug: features-by-type
1964
1982
  type: kanban
@@ -1982,6 +2000,17 @@ views:
1982
2000
  config:
1983
2001
  cardFields: [change, featureStatus, repos]
1984
2002
  cardSettings: { colorField: change }
2003
+ # One column per Claude Code session (the distinct values of the pod-written
2004
+ # `workedIn`; a work no session worked has no value and no column).
2005
+ - name: Features by Claude Code session
2006
+ slug: features-by-claude-code-session
2007
+ type: kanban
2008
+ scopeProfileSlug: devplane_feature
2009
+ description: Every work grouped by the Claude Code session that last worked it, each card marked with its type.
2010
+ config:
2011
+ groupByField: properties.workedIn
2012
+ cardFields: [change, priority, repos]
2013
+ cardSettings: { colorField: change }
1985
2014
  - name: Changes by state
1986
2015
  slug: changes-by-state
1987
2016
  type: kanban
@@ -54,6 +54,22 @@ describe("kanban grouping — view-kanban-group-*", () => {
54
54
  expect(rules(make({ config: { groupByField: "ghost" } }))).toEqual(["view-kanban-group-unknown"]);
55
55
  });
56
56
 
57
+ it("a string the pod derives (workedIn) groups by its distinct values; any other free text is still refused", () => {
58
+ const withProps = (extra: Record<string, unknown>[], groupByField: string) => {
59
+ const t = make({ config: { groupByField } });
60
+ (t.profiles[0].properties as unknown as Record<string, unknown>[]).push(...extra);
61
+ return rules(t);
62
+ };
63
+ const workedIn = { slug: "workedIn", label: "Claude Code session", valueType: "string", inputType: "text" };
64
+ expect(withProps([workedIn], "properties.workedIn")).toEqual([]);
65
+ // The exception is the KEY, not any string: a free-text field is refused,
66
+ // and so is workedIn when the kind does not declare it.
67
+ expect(withProps([{ slug: "owner", label: "Owner", valueType: "string", inputType: "text" }], "owner")).toEqual(["view-kanban-group-unknown"]);
68
+ expect(withProps([], "workedIn")).toEqual(["view-kanban-group-unknown"]);
69
+ // workedInAll is a list: one card has several values, it is no column key.
70
+ expect(withProps([{ slug: "workedInAll", label: "All", valueType: "array", inputType: "tags" }], "workedInAll")).toEqual(["view-kanban-group-unknown"]);
71
+ });
72
+
57
73
  it("a kind with no declaration in reach (a system kind) is not judged", () => {
58
74
  expect(rules(make({ scopeProfileSlug: "task", config: { groupByField: "anything" } }))).toEqual([]);
59
75
  });
package/src/templates.ts CHANGED
@@ -3820,6 +3820,20 @@ const DATA = {
3820
3820
  "inputType": "tags",
3821
3821
  "description": "The repositories this work touches, each as <owner>/<repo> (e.g. Synap-core/backend). Set when the work is shaped."
3822
3822
  },
3823
+ {
3824
+ "slug": "workedIn",
3825
+ "label": "Claude Code session",
3826
+ "valueType": "string",
3827
+ "inputType": "text",
3828
+ "description": "Written by the pod: the Claude Code session (<harness>:<conversation id>) that most recently started a session on this work. Read-only."
3829
+ },
3830
+ {
3831
+ "slug": "workedInAll",
3832
+ "label": "All Claude Code sessions",
3833
+ "valueType": "array",
3834
+ "inputType": "tags",
3835
+ "description": "Written by the pod: every Claude Code session that worked this work, newest first. Read-only."
3836
+ },
3823
3837
  {
3824
3838
  "slug": "linkedApp",
3825
3839
  "label": "Linked App",
@@ -6686,6 +6700,24 @@ const DATA = {
6686
6700
  }
6687
6701
  }
6688
6702
  },
6703
+ {
6704
+ "name": "Features by Claude Code session",
6705
+ "slug": "features-by-claude-code-session",
6706
+ "type": "kanban",
6707
+ "scopeProfileSlug": "devplane_feature",
6708
+ "description": "Every work grouped by the Claude Code session that last worked it, each card marked with its type.",
6709
+ "config": {
6710
+ "groupByField": "properties.workedIn",
6711
+ "cardFields": [
6712
+ "change",
6713
+ "priority",
6714
+ "repos"
6715
+ ],
6716
+ "cardSettings": {
6717
+ "colorField": "change"
6718
+ }
6719
+ }
6720
+ },
6689
6721
  {
6690
6722
  "name": "Changes by state",
6691
6723
  "slug": "changes-by-state",
package/src/validate.ts CHANGED
@@ -1459,6 +1459,49 @@ function checkPresentationDeclarations(
1459
1459
  }
1460
1460
  }
1461
1461
 
1462
+ // ── Server-derived properties: the pod writes them, a template only declares ─
1463
+
1464
+ /**
1465
+ * Property keys the POD derives and writes on any kind a session takes as its
1466
+ * subject (backend#1449, migration 0468): mirrors
1467
+ * `SERVER_DERIVED_PROPERTY_KEYS` in synap-backend
1468
+ * `packages/database/src/utils/worked-in.ts`, pinned equal by
1469
+ * `builder-work-views.template.test.ts`. A template may DECLARE them (a saved
1470
+ * view filters only on a declared property) but never give them a value: the
1471
+ * pod's triggers strip them from any other write, so a default or an option
1472
+ * list would be a promise the pod refuses (rule `property-server-derived-value`).
1473
+ */
1474
+ export const SERVER_DERIVED_PROPERTY_KEYS: readonly string[] = ["workedIn", "workedInAll"];
1475
+
1476
+ /**
1477
+ * The server-derived keys that hold ONE string, so a kanban can group by them:
1478
+ * one column per distinct value (`KanbanAdapter` derives columns from the
1479
+ * values entities carry when the field has no option list).
1480
+ */
1481
+ export const SERVER_DERIVED_GROUP_KEYS: readonly string[] = ["workedIn"];
1482
+
1483
+ function checkServerDerivedProperties(
1484
+ tpl: WorkspaceYaml,
1485
+ add: (rule: string, path: string, message: string) => void
1486
+ ): void {
1487
+ for (const p of tpl.profiles || [])
1488
+ for (const pr of p.properties || []) {
1489
+ if (!SERVER_DERIVED_PROPERTY_KEYS.includes(pr.slug)) continue;
1490
+ const c = (pr.constraints ?? {}) as Record<string, unknown>;
1491
+ const valued = [
1492
+ ...(Array.isArray(pr.enumValues) && pr.enumValues.length > 0 ? ["enumValues"] : []),
1493
+ ...("defaultValue" in c ? ["constraints.defaultValue"] : []),
1494
+ ...("enum" in c ? ["constraints.enum"] : []),
1495
+ ];
1496
+ if (valued.length > 0)
1497
+ add(
1498
+ "property-server-derived-value",
1499
+ `profiles.${p.slug}.${pr.slug}`,
1500
+ `property ${p.slug}.${pr.slug} is written by the pod alone; a template declares it and gives it no value (${valued.join(", ")})`
1501
+ );
1502
+ }
1503
+ }
1504
+
1462
1505
  // ── Kanban grouping: the board names the field its columns are ─────────────
1463
1506
 
1464
1507
  /**
@@ -1472,7 +1515,9 @@ function checkPresentationDeclarations(
1472
1515
  * by `status`;
1473
1516
  * - `config.groupByField` is required;
1474
1517
  * - it names a select property (with enumValues) of the scoped kind, when a
1475
- * declaration of that kind is in reach (a system kind is not judged).
1518
+ * declaration of that kind is in reach (a system kind is not judged), or a
1519
+ * string property of that kind the pod derives ({@link SERVER_DERIVED_GROUP_KEYS}:
1520
+ * one column per distinct value, no option list exists to name).
1476
1521
  */
1477
1522
  function checkKanbanGrouping(
1478
1523
  tpl: WorkspaceYaml,
@@ -1513,11 +1558,16 @@ function checkKanbanGrouping(
1513
1558
  const prop = decls
1514
1559
  .flatMap((p) => p.properties ?? [])
1515
1560
  .find((p) => p.slug === slug);
1561
+ const derivedGroup =
1562
+ !!prop &&
1563
+ SERVER_DERIVED_GROUP_KEYS.includes(prop.slug) &&
1564
+ prop.valueType === "string";
1516
1565
  if (
1517
- !prop ||
1518
- prop.inputType !== "select" ||
1519
- !Array.isArray(prop.enumValues) ||
1520
- prop.enumValues.length === 0
1566
+ !derivedGroup &&
1567
+ (!prop ||
1568
+ prop.inputType !== "select" ||
1569
+ !Array.isArray(prop.enumValues) ||
1570
+ prop.enumValues.length === 0)
1521
1571
  )
1522
1572
  add(
1523
1573
  "view-kanban-group-unknown",
@@ -2736,6 +2786,7 @@ export function validateTemplate(
2736
2786
  checkStageDomains(tpl, resolveDepFrom(opts), add);
2737
2787
  checkProcessContract(tpl, resolveDepFrom(opts), opts.corpus, add);
2738
2788
  checkKanbanGrouping(tpl, resolveDepFrom(opts), opts.corpus, add);
2789
+ checkServerDerivedProperties(tpl, add);
2739
2790
  checkLifecycleDeclarations(tpl, resolveDepFrom(opts), opts.corpus, add);
2740
2791
  checkPresentationDeclarations(tpl, resolveDepFrom(opts), opts.corpus, add);
2741
2792
  checkIntent(tpl, resolveDepFrom(opts), add);