@synap-core/workspace-templates 0.7.1 → 0.7.2
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/dist/index.d.ts +60 -1
- package/dist/index.js +234 -28
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/business-developer.yaml +8 -0
- package/src/catalog.test.ts +2 -2
- package/src/composition-graph.test.ts +2 -2
- package/src/concept-guard.test.ts +176 -0
- package/src/concept-guard.ts +219 -0
- package/src/ecosystem.yaml +4 -1
- package/src/generate.d.mts +15 -0
- package/src/generate.mjs +86 -0
- package/src/index.ts +11 -0
- package/src/meetings-knowledge.yaml +136 -22
- package/src/outreach-comms.yaml +5 -2
- package/src/templates-freshness.test.ts +55 -0
- package/src/templates.ts +126 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synap-core/workspace-templates",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "pnpm@9.15.4",
|
|
6
6
|
"description": "Canonical workspace definitions — YAML source + typed exports for browser, backend, CLI, and marketplace",
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"type-check": "tsc --noEmit",
|
|
20
20
|
"build:yaml": "node build.mjs",
|
|
21
21
|
"check:converters": "node scripts/check-converters.mjs",
|
|
22
|
-
"
|
|
22
|
+
"check:concepts": "node scripts/check-concepts.mjs",
|
|
23
|
+
"build": "node build.mjs && tsup && node scripts/check-converters.mjs && node scripts/check-concepts.mjs",
|
|
23
24
|
"provision": "node scripts/provision.mjs",
|
|
24
25
|
"eval": "node scripts/eval-standard.mjs",
|
|
25
|
-
"prepublishOnly": "node build.mjs && tsup && node scripts/check-converters.mjs"
|
|
26
|
+
"prepublishOnly": "node build.mjs && tsup && node scripts/check-converters.mjs && node scripts/check-concepts.mjs"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"zod": "^3.0.0",
|
|
@@ -50,6 +50,12 @@ profiles:
|
|
|
50
50
|
description: A person or company actively being qualified or contacted by this CRM workspace.
|
|
51
51
|
scope: WORKSPACE
|
|
52
52
|
profileKind: role
|
|
53
|
+
# Explicit concept identity: this is the WORKSPACE tier of the `lead`
|
|
54
|
+
# concept, not a second, unrelated one. Declaring it makes the two-tier
|
|
55
|
+
# design machine-readable (both tiers are reachable via getBySemanticSlug)
|
|
56
|
+
# and is what the cross-template concept guard requires alongside its
|
|
57
|
+
# DECLARED_DIVERGENCES entry — see src/concept-guard.ts.
|
|
58
|
+
semanticSlug: crm.lead
|
|
53
59
|
applicableKinds: [person, company]
|
|
54
60
|
properties:
|
|
55
61
|
- slug: lifecycleStage
|
|
@@ -112,6 +118,8 @@ profiles:
|
|
|
112
118
|
description: A CRM lead converted by a won commercial proposal and ready for handoff.
|
|
113
119
|
scope: WORKSPACE
|
|
114
120
|
profileKind: role
|
|
121
|
+
# Workspace tier of the `client` concept — see the note on `crm-lead` above.
|
|
122
|
+
semanticSlug: crm.client
|
|
115
123
|
applicableKinds: [person, company]
|
|
116
124
|
properties:
|
|
117
125
|
- slug: becameClientAt
|
package/src/catalog.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for the mergeCatalog door. Run: `npx
|
|
2
|
+
* Unit tests for the mergeCatalog door. Run: `npx vitest run packages/workspace-templates` (from the repo root).
|
|
3
3
|
*
|
|
4
4
|
* These test the SOURCE (`./catalog.js` → catalog.ts), never `dist/`, so no build
|
|
5
5
|
* is required and there is no stale-generated-output trap.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { test } from "
|
|
8
|
+
import { test } from "vitest";
|
|
9
9
|
import assert from "node:assert/strict";
|
|
10
10
|
import { mergeCatalog, computeTemplateUpdates, type RemoteEntry } from "./catalog.js";
|
|
11
11
|
import type { WorkspaceYaml } from "./types.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unit tests for the `layerTemplateGraph` KEYSTONE engine.
|
|
3
|
-
* Run: `npx
|
|
3
|
+
* Run: `npx vitest run packages/workspace-templates` (from the repo root).
|
|
4
4
|
*
|
|
5
5
|
* These test the SOURCE (`./composition-graph.js` → composition-graph.ts),
|
|
6
6
|
* never `dist/`, so no build is required and there is no stale-generated-
|
|
7
7
|
* output trap (same convention as `catalog.test.ts`).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { test } from "
|
|
10
|
+
import { test } from "vitest";
|
|
11
11
|
import assert from "node:assert/strict";
|
|
12
12
|
import { layerTemplateGraph, type CompositionGraph } from "./composition-graph.js";
|
|
13
13
|
import type { TemplateDependency } from "./types.js";
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concept-guard tests.
|
|
3
|
+
*
|
|
4
|
+
* The first test is the gate: the SHIPPED corpus must be free of undeclared
|
|
5
|
+
* vocabulary forks. The rest prove the guard actually fires — a guard nobody
|
|
6
|
+
* has watched fail is decoration, so the failure cases are pinned here rather
|
|
7
|
+
* than demonstrated once by hand and forgotten.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import {
|
|
12
|
+
DECLARED_DIVERGENCES,
|
|
13
|
+
conceptTerm,
|
|
14
|
+
findConceptViolations,
|
|
15
|
+
formatConceptViolations,
|
|
16
|
+
} from "./concept-guard.js";
|
|
17
|
+
import { WORKSPACE_TEMPLATES } from "./templates.js";
|
|
18
|
+
import type { WorkspaceYaml } from "./types.js";
|
|
19
|
+
|
|
20
|
+
/** Minimal fixture corpus — only the fields the guard reads. */
|
|
21
|
+
function corpus(
|
|
22
|
+
templates: Record<string, Array<Record<string, unknown>>>
|
|
23
|
+
): Record<string, WorkspaceYaml> {
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
Object.entries(templates).map(([slug, profiles]) => [slug, { profiles }])
|
|
26
|
+
) as unknown as Record<string, WorkspaceYaml>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const role = (slug: string, extra: Record<string, unknown> = {}) => ({
|
|
30
|
+
slug,
|
|
31
|
+
displayName: slug,
|
|
32
|
+
profileKind: "role",
|
|
33
|
+
properties: [],
|
|
34
|
+
...extra,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("concept guard — shipped corpus", () => {
|
|
38
|
+
it("has no undeclared cross-template concept forks", () => {
|
|
39
|
+
const violations = findConceptViolations();
|
|
40
|
+
expect(
|
|
41
|
+
violations,
|
|
42
|
+
violations.length ? `\n${formatConceptViolations(violations)}\n` : ""
|
|
43
|
+
).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("still sees the two-tier CRM divergence — declared, not absent", () => {
|
|
47
|
+
// If business-developer's crm-lead/crm-client ever stopped colliding with
|
|
48
|
+
// foundation's lead/client, the allowlist would be stale and rule 3 would
|
|
49
|
+
// fire. This asserts the allowlist is load-bearing, not inert.
|
|
50
|
+
const withoutAllowlist = Object.keys(DECLARED_DIVERGENCES);
|
|
51
|
+
expect(withoutAllowlist).toEqual(["crm-lead|lead", "client|crm-client"]);
|
|
52
|
+
expect(WORKSPACE_TEMPLATES["business-developer"]?.profiles.find((p) => p.slug === "crm-lead")
|
|
53
|
+
?.semanticSlug).toBe("crm.lead");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("conceptTerm", () => {
|
|
58
|
+
it("reduces a qualified concept identifier to its bare noun", () => {
|
|
59
|
+
expect(conceptTerm("lead")).toBe("lead");
|
|
60
|
+
expect(conceptTerm("crm.lead")).toBe("lead");
|
|
61
|
+
expect(conceptTerm("crm-lead")).toBe("lead");
|
|
62
|
+
expect(conceptTerm("marketing.contact")).toBe("contact");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("concept guard — fires on a real fork", () => {
|
|
67
|
+
it("fails when a second template renames an existing role concept", () => {
|
|
68
|
+
const violations = findConceptViolations(
|
|
69
|
+
corpus({
|
|
70
|
+
foundation: [role("partner", { scope: "shared", applicableKinds: ["company"] })],
|
|
71
|
+
"some-addon": [role("channel-partner", { scope: "WORKSPACE" })],
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
// Fixture corpora never match the real allowlist, so the stale-allowlist
|
|
75
|
+
// findings are expected noise here — the collision is what is under test.
|
|
76
|
+
const forks = violations.filter((v) => v.rule !== "stale-allowlist");
|
|
77
|
+
expect(forks).toHaveLength(1);
|
|
78
|
+
expect(forks[0]!.rule).toBe("concept-collision");
|
|
79
|
+
expect(forks[0]!.concept).toBe("partner");
|
|
80
|
+
expect(forks[0]!.message).toContain("channel-partner");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("suppresses exactly the pair an author declared — and nothing else", () => {
|
|
84
|
+
// The SAME shape as the test above, but with the slugs the allowlist names.
|
|
85
|
+
// This is the whole safety property of the escape hatch: it is per-pair, not
|
|
86
|
+
// per-concept, so a THIRD `lead` spelling would still fail.
|
|
87
|
+
const declared = findConceptViolations(
|
|
88
|
+
corpus({
|
|
89
|
+
foundation: [role("lead", { scope: "shared" })],
|
|
90
|
+
"business-developer": [role("crm-lead", { semanticSlug: "crm.lead", scope: "WORKSPACE" })],
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
expect(declared.filter((v) => v.rule === "concept-collision")).toEqual([]);
|
|
94
|
+
|
|
95
|
+
const third = findConceptViolations(
|
|
96
|
+
corpus({
|
|
97
|
+
foundation: [role("lead", { scope: "shared" })],
|
|
98
|
+
"business-developer": [role("crm-lead", { semanticSlug: "crm.lead", scope: "WORKSPACE" })],
|
|
99
|
+
"another-addon": [role("sales-lead", { scope: "WORKSPACE" })],
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
expect(third.filter((v) => v.rule === "concept-collision")).toHaveLength(2);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("fires even when the fork hides behind a namespaced semanticSlug", () => {
|
|
106
|
+
const violations = findConceptViolations(
|
|
107
|
+
corpus({
|
|
108
|
+
foundation: [role("lead")],
|
|
109
|
+
other: [role("pipeline-lead", { semanticSlug: "sales.lead" })],
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
expect(violations.filter((v) => v.rule !== "stale-allowlist").map((v) => v.rule)).toEqual([
|
|
113
|
+
"concept-collision",
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("fails when two aliased profiles disagree on shape", () => {
|
|
118
|
+
const violations = findConceptViolations(
|
|
119
|
+
corpus({
|
|
120
|
+
a: [role("campaign", { semanticSlug: "marketing.campaign", scope: "shared" })],
|
|
121
|
+
b: [role("promo", { semanticSlug: "marketing.campaign", scope: "WORKSPACE" })],
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
expect(violations.map((v) => v.rule)).toContain("alias-shape-divergence");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("fails when an allowlist entry stops matching anything", () => {
|
|
128
|
+
// DECLARED_DIVERGENCES is module-level, so an empty corpus makes every
|
|
129
|
+
// entry stale — exactly the state a resolved divergence would leave behind.
|
|
130
|
+
const violations = findConceptViolations(corpus({}));
|
|
131
|
+
expect(violations.every((v) => v.rule === "stale-allowlist")).toBe(true);
|
|
132
|
+
expect(violations).toHaveLength(Object.keys(DECLARED_DIVERGENCES).length);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("concept guard — stays green on legitimate patterns", () => {
|
|
137
|
+
it("allows the same slug re-declared across templates (overlay mechanism)", () => {
|
|
138
|
+
const violations = findConceptViolations(
|
|
139
|
+
corpus({
|
|
140
|
+
foundation: [role("lead", { scope: "shared", applicableKinds: ["person", "company"] })],
|
|
141
|
+
// A consumer legitimately OMITS row-level fields it does not own.
|
|
142
|
+
marketing: [role("lead", { scope: "shared" })],
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
expect(violations.filter((v) => v.rule !== "stale-allowlist")).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("allows sibling roles authored in ONE template to share a noun", () => {
|
|
149
|
+
const violations = findConceptViolations(
|
|
150
|
+
corpus({
|
|
151
|
+
"blockchain-ecosystem": [role("marketing-agency"), role("paid-ads-agency")],
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
expect(violations.filter((v) => v.rule !== "stale-allowlist")).toEqual([]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("allows an identical concept reused under one semanticSlug", () => {
|
|
158
|
+
const violations = findConceptViolations(
|
|
159
|
+
corpus({
|
|
160
|
+
"content-os": [role("campaign", { semanticSlug: "marketing.campaign", scope: "shared" })],
|
|
161
|
+
marketing: [role("campaign", { semanticSlug: "marketing.campaign", scope: "shared" })],
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
expect(violations.filter((v) => v.rule !== "stale-allowlist")).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("does not police non-role profiles", () => {
|
|
168
|
+
const violations = findConceptViolations(
|
|
169
|
+
corpus({
|
|
170
|
+
a: [{ slug: "note", displayName: "Note", properties: [] }],
|
|
171
|
+
b: [{ slug: "meeting-note", displayName: "Meeting Note", properties: [] }],
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
expect(violations.filter((v) => v.rule !== "stale-allowlist")).toEqual([]);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-template CONCEPT guard — catches vocabulary forks between templates.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS (read before weakening or deleting it):
|
|
5
|
+
* `business-developer.yaml` introduced workspace-scoped `crm-lead`/`crm-client`
|
|
6
|
+
* for the same real-world concept that `foundation.yaml`/`crm.yaml` declare as
|
|
7
|
+
* pod-wide shared `lead`/`client`. Nothing failed. Three reasons:
|
|
8
|
+
*
|
|
9
|
+
* 1. `build.mjs`'s `validate()` runs PER FILE, inside the read loop, so it
|
|
10
|
+
* structurally cannot see that another template already owns `lead`.
|
|
11
|
+
* 2. The only vocabulary rule that exists (`template-shared-role-ssot.test.ts`
|
|
12
|
+
* in synap-backend) polices a HARDCODED five-slug set — and it FORBIDS
|
|
13
|
+
* declaring one of those slugs workspace-scoped, which is exactly what the
|
|
14
|
+
* two-tier design legitimately needed. So RENAMING was the path of least
|
|
15
|
+
* resistance: `crm-lead` is outside the set and passes silently. That rule
|
|
16
|
+
* polices SPELLING, not MEANING.
|
|
17
|
+
* 3. That test also cannot run in CI — it resolves this package across a
|
|
18
|
+
* sibling-repo relative path that CI never checks out. It is green on a dev
|
|
19
|
+
* machine and mute everywhere else.
|
|
20
|
+
*
|
|
21
|
+
* This guard lives HERE, in the repo that owns the template source, and runs in
|
|
22
|
+
* this repo's CI (`pnpm test`) and in `pnpm build` / `prepublishOnly` via
|
|
23
|
+
* `scripts/check-concepts.mjs`. It is deliberately NOT a hardcoded slug list —
|
|
24
|
+
* that is the pattern that failed.
|
|
25
|
+
*
|
|
26
|
+
* WHAT IT DOES NOT DO: it does not guess. There is no fuzzy name matching, no
|
|
27
|
+
* edit distance, no synonym table. A guesser nobody trusts is worse than no
|
|
28
|
+
* guard. It uses two exact, falsifiable signals only — see the rules below.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { WORKSPACE_TEMPLATES } from "./templates.js";
|
|
32
|
+
import type { TemplateProfile, WorkspaceYaml } from "./types.js";
|
|
33
|
+
|
|
34
|
+
export interface ConceptViolation {
|
|
35
|
+
rule: "concept-collision" | "alias-shape-divergence" | "stale-allowlist";
|
|
36
|
+
/** The concept term or semantic slug the finding is about. */
|
|
37
|
+
concept: string;
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* DECLARED, INTENTIONAL divergences — the escape hatch, and deliberately the
|
|
43
|
+
* SECONDARY mechanism. An entry here is an author saying "yes, two spellings of
|
|
44
|
+
* one concept, on purpose, and here is why". Keep it tiny; every entry must
|
|
45
|
+
* carry its WHY. A key that stops matching anything FAILS the guard, so this
|
|
46
|
+
* list cannot rot into a graveyard.
|
|
47
|
+
*
|
|
48
|
+
* Key = the two colliding profile slugs, sorted, joined by "|".
|
|
49
|
+
*/
|
|
50
|
+
export const DECLARED_DIVERGENCES: Record<string, string> = {
|
|
51
|
+
// Two-tier lead vocabulary, documented at business-developer.yaml:1-16.
|
|
52
|
+
// Foundation's `lead` is a SHARED pod-wide role: being a lead is true
|
|
53
|
+
// everywhere. `crm-lead` is a WORKSPACE-scoped role so a person can be a lead
|
|
54
|
+
// inside one CRM workspace without becoming a lead across the whole pod. The
|
|
55
|
+
// tiers are intentionally separate rows; `semanticSlug: crm.lead` records the
|
|
56
|
+
// kinship so the two are discoverable as one concept via getBySemanticSlug.
|
|
57
|
+
"crm-lead|lead":
|
|
58
|
+
"business-developer: workspace-tier lead, deliberately NOT pod-wide foundation `lead` (two-tier CRM design)",
|
|
59
|
+
// Same reasoning for the post-sale side of the same lifecycle.
|
|
60
|
+
"client|crm-client":
|
|
61
|
+
"business-developer: workspace-tier client, deliberately NOT pod-wide foundation `client` (two-tier CRM design)",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A profile's concept identity. `semanticSlug` is the ONE field that can say
|
|
66
|
+
* "same concept, different spelling"; synap-backend's `profile-repository.ts`
|
|
67
|
+
* defaults it to the slug when unset, so this mirrors runtime truth exactly.
|
|
68
|
+
*/
|
|
69
|
+
function effectiveSemanticSlug(profile: TemplateProfile): string {
|
|
70
|
+
return profile.semanticSlug ?? profile.slug;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The bare noun a concept identifier ends in: `crm.lead` → `lead`,
|
|
75
|
+
* `crm-lead` → `lead`, `lead` → `lead`.
|
|
76
|
+
*
|
|
77
|
+
* This is EXACT terminal-token equality on the author's own qualified name —
|
|
78
|
+
* not a similarity heuristic. `crm-lead` and `lead` collide because the author
|
|
79
|
+
* literally wrote the same noun; `prospect` and `lead` do not collide, and that
|
|
80
|
+
* is honest: no guard can know they mean the same thing.
|
|
81
|
+
*/
|
|
82
|
+
export function conceptTerm(semanticSlug: string): string {
|
|
83
|
+
const tokens = semanticSlug.split(/[.\-_]/).filter(Boolean);
|
|
84
|
+
return (tokens[tokens.length - 1] ?? semanticSlug).toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `undefined`/`null` = the template makes NO claim, which cannot contradict one. */
|
|
88
|
+
function declaredValue(profile: TemplateProfile, field: string): string | null {
|
|
89
|
+
const raw = (profile as unknown as Record<string, unknown>)[field];
|
|
90
|
+
if (raw === undefined || raw === null) return null;
|
|
91
|
+
if (field === "applicableKinds") {
|
|
92
|
+
return Array.isArray(raw) ? JSON.stringify([...(raw as string[])].sort()) : null;
|
|
93
|
+
}
|
|
94
|
+
// `scope` is authored as both `shared` and `WORKSPACE` across the corpus.
|
|
95
|
+
return JSON.stringify(String(raw).toLowerCase());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function pairKey(a: string, b: string): string {
|
|
99
|
+
return [a, b].sort().join("|");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface ProfileRef {
|
|
103
|
+
template: string;
|
|
104
|
+
profile: TemplateProfile;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function findConceptViolations(
|
|
108
|
+
templates: Record<string, WorkspaceYaml> = WORKSPACE_TEMPLATES
|
|
109
|
+
): ConceptViolation[] {
|
|
110
|
+
const violations: ConceptViolation[] = [];
|
|
111
|
+
const all: ProfileRef[] = [];
|
|
112
|
+
for (const [templateSlug, template] of Object.entries(templates)) {
|
|
113
|
+
for (const profile of template.profiles ?? []) {
|
|
114
|
+
all.push({ template: templateSlug, profile });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ── RULE 1 — concept collision across templates ────────────────────────────
|
|
119
|
+
// Two ROLE profiles, in DIFFERENT templates, with DIFFERENT slugs, whose
|
|
120
|
+
// concept identifiers end in the same noun. Every qualifier is load-bearing:
|
|
121
|
+
// • ROLE only — roles are the facet vocabulary (the hat an entity wears),
|
|
122
|
+
// where a fork actually hurts: the same person is a lead under one
|
|
123
|
+
// spelling and not under the other. Kinds are things with their own life.
|
|
124
|
+
// • DIFFERENT templates — sibling roles authored in ONE file are a
|
|
125
|
+
// deliberate distinction the author had in front of them (blockchain-
|
|
126
|
+
// ecosystem's `marketing-agency` + `paid-ads-agency`). A fork is by
|
|
127
|
+
// definition cross-template drift. This qualifier is what takes the rule
|
|
128
|
+
// from 1 false positive to 0 on the current corpus.
|
|
129
|
+
// • DIFFERENT slugs — the SAME slug in several templates is the documented
|
|
130
|
+
// overlay/reuse mechanism (`lead` in foundation + crm + marketing), not a
|
|
131
|
+
// fork. That case is rule 2's business.
|
|
132
|
+
const roles = all.filter((r) => r.profile.profileKind === "role");
|
|
133
|
+
const usedAllowlistKeys = new Set<string>();
|
|
134
|
+
const reportedPairs = new Set<string>();
|
|
135
|
+
|
|
136
|
+
for (let i = 0; i < roles.length; i++) {
|
|
137
|
+
for (let j = i + 1; j < roles.length; j++) {
|
|
138
|
+
const a = roles[i]!;
|
|
139
|
+
const b = roles[j]!;
|
|
140
|
+
if (a.template === b.template) continue;
|
|
141
|
+
if (a.profile.slug === b.profile.slug) continue;
|
|
142
|
+
const term = conceptTerm(effectiveSemanticSlug(a.profile));
|
|
143
|
+
if (term !== conceptTerm(effectiveSemanticSlug(b.profile))) continue;
|
|
144
|
+
|
|
145
|
+
const key = pairKey(a.profile.slug, b.profile.slug);
|
|
146
|
+
if (key in DECLARED_DIVERGENCES) {
|
|
147
|
+
usedAllowlistKeys.add(key);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (reportedPairs.has(key)) continue;
|
|
151
|
+
reportedPairs.add(key);
|
|
152
|
+
violations.push({
|
|
153
|
+
rule: "concept-collision",
|
|
154
|
+
concept: term,
|
|
155
|
+
message:
|
|
156
|
+
`two role profiles denote the concept "${term}" under different slugs: ` +
|
|
157
|
+
`"${a.profile.slug}" (${a.template}) vs "${b.profile.slug}" (${b.template}). ` +
|
|
158
|
+
`Either REUSE the existing slug, or — if the divergence is intentional — declare it: ` +
|
|
159
|
+
`set an explicit \`semanticSlug\` on the new profile and add "${key}" to ` +
|
|
160
|
+
`DECLARED_DIVERGENCES in src/concept-guard.ts with the reason.`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── RULE 2 — declared alias, forked shape ──────────────────────────────────
|
|
166
|
+
// Two profiles with DIFFERENT slugs that claim the SAME `semanticSlug` are
|
|
167
|
+
// asserting "one concept". Then their row-level shape must agree, or the
|
|
168
|
+
// assertion is a lie and the field is decorative. Absence is not a conflict:
|
|
169
|
+
// a template that OMITS a row-level field makes no claim (that is exactly how
|
|
170
|
+
// marketing.yaml correctly stops restating what foundation owns).
|
|
171
|
+
// Same-slug re-declaration is NOT checked here — that is the overlay path.
|
|
172
|
+
const bySemantic = new Map<string, ProfileRef[]>();
|
|
173
|
+
for (const ref of all) {
|
|
174
|
+
const key = effectiveSemanticSlug(ref.profile);
|
|
175
|
+
const bucket = bySemantic.get(key);
|
|
176
|
+
if (bucket) bucket.push(ref);
|
|
177
|
+
else bySemantic.set(key, [ref]);
|
|
178
|
+
}
|
|
179
|
+
for (const [semantic, group] of bySemantic) {
|
|
180
|
+
if (new Set(group.map((r) => r.profile.slug)).size < 2) continue;
|
|
181
|
+
for (const field of ["profileKind", "scope", "applicableKinds"]) {
|
|
182
|
+
const claims = new Map<string, string>();
|
|
183
|
+
for (const ref of group) {
|
|
184
|
+
const value = declaredValue(ref.profile, field);
|
|
185
|
+
if (value === null) continue;
|
|
186
|
+
const existing = claims.get(value);
|
|
187
|
+
if (!existing) claims.set(value, `${ref.template}:${ref.profile.slug}`);
|
|
188
|
+
}
|
|
189
|
+
if (claims.size > 1) {
|
|
190
|
+
violations.push({
|
|
191
|
+
rule: "alias-shape-divergence",
|
|
192
|
+
concept: semantic,
|
|
193
|
+
message:
|
|
194
|
+
`profiles aliased to semanticSlug "${semantic}" disagree on \`${field}\`: ` +
|
|
195
|
+
[...claims].map(([v, who]) => `${who} declares ${v}`).join(", ") +
|
|
196
|
+
`. Aliased profiles assert one concept — make the shapes agree, or drop the alias.`,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ── RULE 3 — the allowlist may not rot ─────────────────────────────────────
|
|
203
|
+
for (const key of Object.keys(DECLARED_DIVERGENCES)) {
|
|
204
|
+
if (usedAllowlistKeys.has(key)) continue;
|
|
205
|
+
violations.push({
|
|
206
|
+
rule: "stale-allowlist",
|
|
207
|
+
concept: key,
|
|
208
|
+
message:
|
|
209
|
+
`DECLARED_DIVERGENCES entry "${key}" no longer matches any collision — ` +
|
|
210
|
+
`the divergence was resolved or the profiles were renamed. Delete the entry.`,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return violations;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function formatConceptViolations(violations: ConceptViolation[]): string {
|
|
218
|
+
return violations.map((v) => ` • [${v.rule}] ${v.message}`).join("\n");
|
|
219
|
+
}
|
package/src/ecosystem.yaml
CHANGED
|
@@ -536,7 +536,10 @@ layout:
|
|
|
536
536
|
icon: database
|
|
537
537
|
|
|
538
538
|
bento:
|
|
539
|
-
|
|
539
|
+
# Distinct from the "Ecosystem Map" graph view it embeds — the bento is created
|
|
540
|
+
# as its OWN view row, so reusing an embedded view's name puts two identically
|
|
541
|
+
# named views in the switcher.
|
|
542
|
+
viewName: Ecosystem Home
|
|
540
543
|
blocks:
|
|
541
544
|
- kind: view
|
|
542
545
|
viewName: Ecosystem Map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Types for `generate.mjs` — the shared renderer for `src/templates.ts`. */
|
|
2
|
+
|
|
3
|
+
export interface RawTemplateEntry {
|
|
4
|
+
/** Source file name, e.g. `business-developer.yaml`. */
|
|
5
|
+
file: string;
|
|
6
|
+
/** `meta.slug` as declared in the YAML. */
|
|
7
|
+
slug: string;
|
|
8
|
+
/** The parsed YAML document, untyped on purpose (build-time shape). */
|
|
9
|
+
data: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const SRC_DIR: string;
|
|
13
|
+
export declare const TEMPLATES_FILE: string;
|
|
14
|
+
export declare function readYamlTemplates(): RawTemplateEntry[];
|
|
15
|
+
export declare function renderTemplatesModule(templates: RawTemplateEntry[]): string;
|
package/src/generate.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE renderer for the generated `src/templates.ts` corpus.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS FILE EXISTS (read before inlining it back into build.mjs):
|
|
5
|
+
* `src/templates.ts` is auto-generated from `src/*.yaml` AND committed to git
|
|
6
|
+
* (it has to be — `browser/tsconfig.json` aliases this package straight at
|
|
7
|
+
* `src/`, with no build step, and synap-backend's
|
|
8
|
+
* `__tripwires__/template-shared-role-ssot.test.ts` reads the file by path).
|
|
9
|
+
* A committed artifact can go stale: edit a YAML, run `pnpm test`, and every
|
|
10
|
+
* template-corpus check — including `concept-guard` — passes against
|
|
11
|
+
* vocabulary that no longer exists on disk. Only `pnpm build` regenerated.
|
|
12
|
+
*
|
|
13
|
+
* So the render logic lives HERE, and two callers share it:
|
|
14
|
+
* • `build.mjs` — validates, renders, WRITES the file.
|
|
15
|
+
* • `src/templates-freshness.test.ts` — renders in memory and asserts the
|
|
16
|
+
* committed file matches byte-for-byte. Runs in `pnpm test`, i.e. in CI.
|
|
17
|
+
*
|
|
18
|
+
* Duplicating the template string into the test would recreate the same class
|
|
19
|
+
* of drift one level up, so don't.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { readFileSync, readdirSync } from 'fs';
|
|
23
|
+
import { dirname, join } from 'path';
|
|
24
|
+
import { fileURLToPath } from 'url';
|
|
25
|
+
import yaml from 'js-yaml';
|
|
26
|
+
|
|
27
|
+
export const SRC_DIR = dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
export const TEMPLATES_FILE = join(SRC_DIR, 'templates.ts');
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Read + parse every `src/*.yaml`, in the same (readdir) order build.mjs used.
|
|
32
|
+
* No validation here — validation stays in build.mjs, which is the writer.
|
|
33
|
+
*/
|
|
34
|
+
export function readYamlTemplates() {
|
|
35
|
+
return readdirSync(SRC_DIR)
|
|
36
|
+
.filter((f) => f.endsWith('.yaml'))
|
|
37
|
+
.map((file) => {
|
|
38
|
+
const parsed = yaml.load(readFileSync(join(SRC_DIR, file), 'utf-8'));
|
|
39
|
+
return { file, slug: parsed?.meta?.slug, data: parsed };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Render the full text of `src/templates.ts` for a corpus. Pure. */
|
|
44
|
+
export function renderTemplatesModule(templates) {
|
|
45
|
+
const data = JSON.stringify(
|
|
46
|
+
Object.fromEntries(templates.map((t) => [t.slug, t.data])),
|
|
47
|
+
null,
|
|
48
|
+
2,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return `// ═══════════════════════════════════════════════════════════════════════
|
|
52
|
+
// AUTO-GENERATED from YAML source files in src/*.yaml
|
|
53
|
+
// DO NOT EDIT — run \`node build.mjs\` or \`pnpm build\` to regenerate
|
|
54
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
55
|
+
|
|
56
|
+
import type { WorkspaceYaml } from './types.js';
|
|
57
|
+
|
|
58
|
+
const DATA = ${data} as unknown as Record<string, WorkspaceYaml>;
|
|
59
|
+
|
|
60
|
+
export const WORKSPACE_TEMPLATES: Record<string, WorkspaceYaml> = DATA;
|
|
61
|
+
|
|
62
|
+
export type WorkspaceTemplateSlug = keyof typeof WORKSPACE_TEMPLATES;
|
|
63
|
+
|
|
64
|
+
export function getWorkspaceTemplate(slug: string): WorkspaceYaml | undefined {
|
|
65
|
+
return WORKSPACE_TEMPLATES[slug];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function listWorkspaceTemplates(): WorkspaceYaml[] {
|
|
69
|
+
return Object.values(WORKSPACE_TEMPLATES);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Public templates only (\`meta.isPublic !== false\`). This is a CONVENIENCE
|
|
74
|
+
* filter for the default picker — NOT a security boundary: the private YAML
|
|
75
|
+
* still ships in the published tarball, so anything that must not leak cannot
|
|
76
|
+
* rely on this. \`listWorkspaceTemplates()\` returns all of them (CLI, seeder,
|
|
77
|
+
* tripwire need the full set). Publicity is also expressed per-entry as
|
|
78
|
+
* \`CatalogEntry.isPrivate\` by \`mergeCatalog()\`, so a caller can pass ALL
|
|
79
|
+
* templates and filter at the presentation layer instead of choosing a list
|
|
80
|
+
* function up front — the merge door itself never filters (it stays pure).
|
|
81
|
+
*/
|
|
82
|
+
export function listPublicTemplates(): WorkspaceYaml[] {
|
|
83
|
+
return Object.values(WORKSPACE_TEMPLATES).filter(t => t.meta?.isPublic !== false);
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -98,6 +98,17 @@ export type {
|
|
|
98
98
|
LayerTemplateGraphInput,
|
|
99
99
|
} from "./composition-graph.js";
|
|
100
100
|
|
|
101
|
+
// Cross-template vocabulary-fork guard. Exported because the build/publish gate
|
|
102
|
+
// (`scripts/check-concepts.mjs`) runs it off `dist/` — one implementation, two
|
|
103
|
+
// enforcement points (CI `pnpm test` + `pnpm build`).
|
|
104
|
+
export {
|
|
105
|
+
findConceptViolations,
|
|
106
|
+
formatConceptViolations,
|
|
107
|
+
conceptTerm,
|
|
108
|
+
DECLARED_DIVERGENCES,
|
|
109
|
+
} from "./concept-guard.js";
|
|
110
|
+
export type { ConceptViolation } from "./concept-guard.js";
|
|
111
|
+
|
|
101
112
|
export {
|
|
102
113
|
toWorkspaceDefinition,
|
|
103
114
|
toPackageDefinition,
|