@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/README.md +135 -68
- package/capabilities/design.capability.json +126 -643
- package/capabilities/storybook.capability.json +84 -0
- package/capabilities/vast-ai-compute-worker.capability.json +178 -76
- package/dist/index.js +1386 -82
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/designing-with-real-components/SKILL.md +7 -1
- package/src/agency-os.yaml +22 -4
- package/src/builder.yaml +1480 -773
- package/src/campaign-channel-platforms.template.test.ts +13 -2
- package/src/catalog-safety.test.ts +14 -3
- package/src/content-os.campaigns.template.test.ts +63 -20
- package/src/content-os.piece-model.template.test.ts +185 -41
- package/src/content-os.template.test.ts +174 -58
- package/src/content-os.yaml +170 -28
- package/src/crm.yaml +289 -46
- package/src/decisions-wave.template.test.ts +171 -47
- package/src/ecosystem.yaml +7 -1
- package/src/finance.yaml +27 -5
- package/src/lifecycle-declarations.test.ts +8 -0
- package/src/marketing.yaml +6 -3
- package/src/process-contract.validate.test.ts +217 -71
- package/src/templates.ts +2332 -1299
- package/src/types.ts +35 -6
- package/src/ui-inventory.template.test.ts +256 -0
- package/src/validate.ts +541 -130
package/src/validate.ts
CHANGED
|
@@ -57,7 +57,14 @@ import type {
|
|
|
57
57
|
// eslint-disable-next-line import/extensions -- .ts extension is intentional; see header.
|
|
58
58
|
import { validateFlowDefinition } from "./validate-flow.ts";
|
|
59
59
|
// eslint-disable-next-line import/extensions -- .ts extension is intentional; see header.
|
|
60
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
INTENT_LABEL_MAX,
|
|
62
|
+
START_EXAMPLE_RANGE,
|
|
63
|
+
START_STARTERS_RANGE,
|
|
64
|
+
START_VIEWS_MAX,
|
|
65
|
+
TEMPLATE_KIND_AS,
|
|
66
|
+
startProfileOf,
|
|
67
|
+
} from "./types.ts";
|
|
61
68
|
|
|
62
69
|
import {
|
|
63
70
|
CAPABILITY_INTENTS,
|
|
@@ -70,7 +77,10 @@ import { validateSpaceSkillDeclaration } from "@synap-core/types/space-brief";
|
|
|
70
77
|
// presentation parser. `tsup.config.ts` BUNDLES this subpath into `dist/`
|
|
71
78
|
// (`noExternal`), so a consumer whose resolved `@synap-core/types` predates
|
|
72
79
|
// `./presentation` (the CP, the CLI) still loads the validator.
|
|
73
|
-
import {
|
|
80
|
+
import {
|
|
81
|
+
declaredMediaSources,
|
|
82
|
+
parseProfilePresentation,
|
|
83
|
+
} from "@synap-core/types/presentation";
|
|
74
84
|
|
|
75
85
|
// A FIFTH runtime import, a sibling leaf like `./validate-flow.ts` (only
|
|
76
86
|
// `import type` inside): the lifecycle preset compiler. Every rule below reads
|
|
@@ -223,7 +233,10 @@ const TEMPLATE_FORBIDDEN_SYSTEM_PROFILE_SLUGS = new Set(["knowledge"]);
|
|
|
223
233
|
* package cannot import `@synap/database`). `reserved-profile-slugs.test.ts`
|
|
224
234
|
* pins the two sets equal.
|
|
225
235
|
*/
|
|
226
|
-
export const RESERVED_PROFILE_SLUGS: ReadonlySet<string> = new Set([
|
|
236
|
+
export const RESERVED_PROFILE_SLUGS: ReadonlySet<string> = new Set([
|
|
237
|
+
"project",
|
|
238
|
+
"projects",
|
|
239
|
+
]);
|
|
227
240
|
const KNOWLEDGE_FORMS = new Set(["insight", "caution"]);
|
|
228
241
|
const LEGACY_KNOWLEDGE_SEED_FIELDS = new Set(["ek_type", "type"]);
|
|
229
242
|
|
|
@@ -302,7 +315,8 @@ function composeBaseDocumentSlugs(
|
|
|
302
315
|
const base = resolveDep(dep.slug);
|
|
303
316
|
if (!base) continue;
|
|
304
317
|
for (const d of base.documents || []) if (d?.slug) out.add(d.slug);
|
|
305
|
-
for (const s of composeBaseDocumentSlugs(base, resolveDep, seen))
|
|
318
|
+
for (const s of composeBaseDocumentSlugs(base, resolveDep, seen))
|
|
319
|
+
out.add(s);
|
|
306
320
|
}
|
|
307
321
|
return out;
|
|
308
322
|
}
|
|
@@ -355,10 +369,12 @@ function withResolvedLifecycles(
|
|
|
355
369
|
return {
|
|
356
370
|
...opts,
|
|
357
371
|
corpus: opts.corpus?.map(compile),
|
|
358
|
-
resolveDep:
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
372
|
+
resolveDep:
|
|
373
|
+
resolveDep &&
|
|
374
|
+
((slug: string) => {
|
|
375
|
+
const t = resolveDep(slug);
|
|
376
|
+
return t && compile(t);
|
|
377
|
+
}),
|
|
362
378
|
};
|
|
363
379
|
}
|
|
364
380
|
|
|
@@ -496,8 +512,7 @@ function checkStageDomains(
|
|
|
496
512
|
);
|
|
497
513
|
continue;
|
|
498
514
|
}
|
|
499
|
-
const target =
|
|
500
|
-
domain === tpl.meta?.slug ? tpl : resolveDep(domain);
|
|
515
|
+
const target = domain === tpl.meta?.slug ? tpl : resolveDep(domain);
|
|
501
516
|
if (!target) {
|
|
502
517
|
// Only knowable with a corpus; a lone-template validate cannot tell.
|
|
503
518
|
if (hasCorpus(resolveDep))
|
|
@@ -635,7 +650,14 @@ export const MAX_SESSION_CRITERIA = 12;
|
|
|
635
650
|
* (rootDir is `src`). `schema/mirror.tripwire.test.ts` pins the two equal,
|
|
636
651
|
* and both to the pod's `playbookActivatorSchema`.
|
|
637
652
|
*/
|
|
638
|
-
export const TEMPLATE_ACTIVATOR_ON = [
|
|
653
|
+
export const TEMPLATE_ACTIVATOR_ON = [
|
|
654
|
+
"created",
|
|
655
|
+
"enters_status",
|
|
656
|
+
"count",
|
|
657
|
+
"schedule",
|
|
658
|
+
"manual",
|
|
659
|
+
"run_ended",
|
|
660
|
+
] as const;
|
|
639
661
|
|
|
640
662
|
/**
|
|
641
663
|
* Does a stage's goal NAME the move into `value` — the status value or its
|
|
@@ -643,10 +665,21 @@ export const TEMPLATE_ACTIVATOR_ON = ["created", "enters_status", "count", "sche
|
|
|
643
665
|
* nothing approves (`stage-on-approved-no-signal`): the goal is what the agent
|
|
644
666
|
* finishing the stage reads, so it is where that move must be written.
|
|
645
667
|
*/
|
|
646
|
-
function goalNamesStatus(
|
|
668
|
+
function goalNamesStatus(
|
|
669
|
+
goal: unknown,
|
|
670
|
+
value: unknown,
|
|
671
|
+
labels: Map<string, string> | null
|
|
672
|
+
): boolean {
|
|
647
673
|
if (typeof goal !== "string" || typeof value !== "string") return false;
|
|
648
|
-
const names = [value, labels?.get(value)].filter(
|
|
649
|
-
|
|
674
|
+
const names = [value, labels?.get(value)].filter(
|
|
675
|
+
(n): n is string => !!n && n.trim() !== ""
|
|
676
|
+
);
|
|
677
|
+
return names.some((n) =>
|
|
678
|
+
new RegExp(
|
|
679
|
+
`(^|[^\\p{L}\\p{N}_])${n.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}($|[^\\p{L}\\p{N}_])`,
|
|
680
|
+
"iu"
|
|
681
|
+
).test(goal)
|
|
682
|
+
);
|
|
650
683
|
}
|
|
651
684
|
|
|
652
685
|
function checkProcessContract(
|
|
@@ -669,11 +702,17 @@ function checkProcessContract(
|
|
|
669
702
|
const raw = pb as unknown as Record<string, unknown>;
|
|
670
703
|
const subjectRaw = (pb.subjectProfile ?? {}) as Record<string, unknown>;
|
|
671
704
|
for (const [field, present] of [
|
|
672
|
-
[
|
|
705
|
+
[
|
|
706
|
+
"subjectProfile.statusProperty",
|
|
707
|
+
subjectRaw.statusProperty !== undefined,
|
|
708
|
+
],
|
|
673
709
|
["subjectProfile.onEnd", subjectRaw.onEnd !== undefined],
|
|
674
710
|
["onEnd", raw.onEnd !== undefined],
|
|
675
711
|
["humanOnlyStatuses", raw.humanOnlyStatuses !== undefined],
|
|
676
|
-
[
|
|
712
|
+
[
|
|
713
|
+
"subjectProfile.humanOnlyStatuses",
|
|
714
|
+
subjectRaw.humanOnlyStatuses !== undefined,
|
|
715
|
+
],
|
|
677
716
|
] as const)
|
|
678
717
|
if (present)
|
|
679
718
|
add(
|
|
@@ -703,7 +742,9 @@ function checkProcessContract(
|
|
|
703
742
|
if (declared) {
|
|
704
743
|
lifecycleProperty = declared.property;
|
|
705
744
|
statuses = new Set(declared.options.map((o) => o.key));
|
|
706
|
-
labels = new Map(
|
|
745
|
+
labels = new Map(
|
|
746
|
+
declared.options.map((o) => [o.key, o.label ?? o.key])
|
|
747
|
+
);
|
|
707
748
|
}
|
|
708
749
|
}
|
|
709
750
|
const checkStatus = (rule: string, path: string, value: unknown) => {
|
|
@@ -740,16 +781,30 @@ function checkProcessContract(
|
|
|
740
781
|
stages.forEach((stage, i) => {
|
|
741
782
|
const sp = `${at}.stages.${stage.key}`;
|
|
742
783
|
if (stage.subjectStatus !== undefined)
|
|
743
|
-
checkStatus(
|
|
784
|
+
checkStatus(
|
|
785
|
+
"stage-subject-status-unknown",
|
|
786
|
+
`${sp}.subjectStatus`,
|
|
787
|
+
stage.subjectStatus
|
|
788
|
+
);
|
|
744
789
|
if (stage.onApproved !== undefined) {
|
|
745
|
-
checkStatus(
|
|
790
|
+
checkStatus(
|
|
791
|
+
"stage-on-approved-unknown",
|
|
792
|
+
`${sp}.onApproved`,
|
|
793
|
+
stage.onApproved
|
|
794
|
+
);
|
|
746
795
|
// The pod's two approval signals (`stage-subject-status.ts`): a
|
|
747
796
|
// required output of this stage (an optional one never holds it back,
|
|
748
797
|
// so it never approves it either), or the NEXT stage's gate passing.
|
|
749
798
|
// A stage's own gate approves the stage BEFORE it, never itself.
|
|
750
|
-
const owesOutput = (stage.expectedOutputs ?? []).some(
|
|
799
|
+
const owesOutput = (stage.expectedOutputs ?? []).some(
|
|
800
|
+
(o) => o.optional !== true
|
|
801
|
+
);
|
|
751
802
|
const nextGated = !!stages[i + 1]?.gate;
|
|
752
|
-
if (
|
|
803
|
+
if (
|
|
804
|
+
!owesOutput &&
|
|
805
|
+
!nextGated &&
|
|
806
|
+
!goalNamesStatus(stage.goal, stage.onApproved, labels)
|
|
807
|
+
)
|
|
753
808
|
add(
|
|
754
809
|
"stage-on-approved-no-signal",
|
|
755
810
|
`${sp}.onApproved`,
|
|
@@ -768,25 +823,54 @@ function checkProcessContract(
|
|
|
768
823
|
(pb.activators ?? []).forEach((a, i) => {
|
|
769
824
|
const ap = `${at}.activators[${i}]`;
|
|
770
825
|
if (!(TEMPLATE_ACTIVATOR_ON as readonly string[]).includes(a.on))
|
|
771
|
-
add(
|
|
826
|
+
add(
|
|
827
|
+
"activator-on-invalid",
|
|
828
|
+
`${ap}.on`,
|
|
829
|
+
`${ap}.on "${String(a.on)}" must be one of ${TEMPLATE_ACTIVATOR_ON.join(", ")}`
|
|
830
|
+
);
|
|
772
831
|
if (a.mode !== "run" && a.mode !== "propose" && a.mode !== "appointment")
|
|
773
|
-
add(
|
|
832
|
+
add(
|
|
833
|
+
"activator-mode-invalid",
|
|
834
|
+
`${ap}.mode`,
|
|
835
|
+
`${ap}.mode "${String(a.mode)}" must be "run", "propose" or "appointment"`
|
|
836
|
+
);
|
|
774
837
|
// A schedule may run with no subject: once per tick, over nothing.
|
|
775
838
|
if (!kind && a.on !== "schedule")
|
|
776
|
-
add(
|
|
839
|
+
add(
|
|
840
|
+
"activator-no-subject",
|
|
841
|
+
ap,
|
|
842
|
+
`${ap} needs subjectProfile.profileSlug — an activator fires on an entity of that kind`
|
|
843
|
+
);
|
|
777
844
|
if (a.on === "enters_status" || a.on === "count") {
|
|
778
845
|
if (a.status === undefined)
|
|
779
|
-
add(
|
|
846
|
+
add(
|
|
847
|
+
"activator-status-required",
|
|
848
|
+
`${ap}.status`,
|
|
849
|
+
`${ap} on "${a.on}" names no status`
|
|
850
|
+
);
|
|
780
851
|
else checkStatus("activator-status-unknown", `${ap}.status`, a.status);
|
|
781
852
|
} else if (a.on === "schedule") {
|
|
782
|
-
for (const st of a.status === undefined
|
|
853
|
+
for (const st of a.status === undefined
|
|
854
|
+
? []
|
|
855
|
+
: typeof a.status === "string"
|
|
856
|
+
? [a.status]
|
|
857
|
+
: a.status)
|
|
783
858
|
checkStatus("activator-status-unknown", `${ap}.status`, st);
|
|
784
859
|
} else if (a.status !== undefined) {
|
|
785
|
-
add(
|
|
860
|
+
add(
|
|
861
|
+
"activator-status-unexpected",
|
|
862
|
+
`${ap}.status`,
|
|
863
|
+
`${ap}.status is not read when on = "${a.on}"`
|
|
864
|
+
);
|
|
786
865
|
}
|
|
787
866
|
});
|
|
788
867
|
|
|
789
|
-
const outputs: Array<{
|
|
868
|
+
const outputs: Array<{
|
|
869
|
+
path: string;
|
|
870
|
+
rel: unknown;
|
|
871
|
+
optional: unknown;
|
|
872
|
+
at: string;
|
|
873
|
+
}> = [
|
|
790
874
|
...(pb.expectedOutputs ?? []).map((o, i) => ({
|
|
791
875
|
at: `${at}.expectedOutputs[${i}]`,
|
|
792
876
|
path: `${at}.expectedOutputs[${i}].relationToSubject`,
|
|
@@ -807,13 +891,25 @@ function checkProcessContract(
|
|
|
807
891
|
// decision nobody's code reads.
|
|
808
892
|
for (const o of outputs)
|
|
809
893
|
if (o.optional !== undefined && typeof o.optional !== "boolean")
|
|
810
|
-
add(
|
|
894
|
+
add(
|
|
895
|
+
"output-optional-not-boolean",
|
|
896
|
+
`${o.at}.optional`,
|
|
897
|
+
`${o.at}.optional = ${JSON.stringify(o.optional)} must be true or false — the pod treats anything but a real true as required`
|
|
898
|
+
);
|
|
811
899
|
for (const { path, rel } of outputs) {
|
|
812
900
|
if (rel === undefined || rel === NO_SUBJECT_RELATION) continue;
|
|
813
901
|
if (!kind) {
|
|
814
|
-
add(
|
|
902
|
+
add(
|
|
903
|
+
"output-relation-no-subject",
|
|
904
|
+
path,
|
|
905
|
+
`${path} = "${String(rel)}" but playbook "${pb.name}" has no subject to relate to (use "${NO_SUBJECT_RELATION}")`
|
|
906
|
+
);
|
|
815
907
|
} else if (typeof rel !== "string" || !relationsOnce().has(rel)) {
|
|
816
|
-
add(
|
|
908
|
+
add(
|
|
909
|
+
"output-relation-unknown",
|
|
910
|
+
path,
|
|
911
|
+
`${path} = "${String(rel)}" is not a relation the corpus defines (entityLinks[].type / relationDefs[].slug)`
|
|
912
|
+
);
|
|
817
913
|
}
|
|
818
914
|
}
|
|
819
915
|
}
|
|
@@ -828,7 +924,13 @@ function checkProcessContract(
|
|
|
828
924
|
* `@synap-core/types` may predate the `./lifecycle` subpath, so it is not
|
|
829
925
|
* imported. `lifecycle-declarations.test.ts` pins the two lists equal.
|
|
830
926
|
*/
|
|
831
|
-
export const LIFECYCLE_CATEGORIES = [
|
|
927
|
+
export const LIFECYCLE_CATEGORIES = [
|
|
928
|
+
"open",
|
|
929
|
+
"active",
|
|
930
|
+
"paused",
|
|
931
|
+
"done",
|
|
932
|
+
"lost",
|
|
933
|
+
] as const;
|
|
832
934
|
|
|
833
935
|
/** MIRROR of the pod's `STUCK_AFTER_DAYS_MAX` (`utils/lifecycle-model.ts`), same reason as above. */
|
|
834
936
|
export const STUCK_AFTER_DAYS_MAX = 3650;
|
|
@@ -850,14 +952,27 @@ export const LIFECYCLE_OPTION_FIELDS = [
|
|
|
850
952
|
"waits",
|
|
851
953
|
"requires",
|
|
852
954
|
] as const;
|
|
853
|
-
export const LIFECYCLE_OPTION_WAITS_FIELDS = [
|
|
955
|
+
export const LIFECYCLE_OPTION_WAITS_FIELDS = [
|
|
956
|
+
"on",
|
|
957
|
+
"waitKind",
|
|
958
|
+
"refFrom",
|
|
959
|
+
"dateBinding",
|
|
960
|
+
] as const;
|
|
854
961
|
|
|
855
962
|
/**
|
|
856
963
|
* What a step may say it waits on: MIRROR of the pod's `HOLD_ON` without
|
|
857
964
|
* `unspecified` (`parseOptionWaits`, `utils/lifecycle-model.ts`: a step that
|
|
858
965
|
* says `unspecified` says nothing, and the pod refuses it).
|
|
859
966
|
*/
|
|
860
|
-
export const LIFECYCLE_WAITS_ON = [
|
|
967
|
+
export const LIFECYCLE_WAITS_ON = [
|
|
968
|
+
"person",
|
|
969
|
+
"agent",
|
|
970
|
+
"external",
|
|
971
|
+
"thing",
|
|
972
|
+
"decision",
|
|
973
|
+
"date",
|
|
974
|
+
"nobody",
|
|
975
|
+
] as const;
|
|
861
976
|
|
|
862
977
|
/** MIRROR of `WAIT_KINDS` (`@synap-core/types/units`, `wait-kind.ts`), same reason as above. */
|
|
863
978
|
export const LIFECYCLE_WAIT_KINDS = [
|
|
@@ -909,7 +1024,10 @@ export function lifecycleOptionWaitsProblems(option: {
|
|
|
909
1024
|
const key = String(option.key);
|
|
910
1025
|
const finished = option.category === "done" || option.category === "lost";
|
|
911
1026
|
if (option.dateBinding !== undefined) {
|
|
912
|
-
if (
|
|
1027
|
+
if (
|
|
1028
|
+
typeof option.dateBinding !== "string" ||
|
|
1029
|
+
!LIFECYCLE_PROPERTY_SLUG.test(option.dateBinding)
|
|
1030
|
+
)
|
|
913
1031
|
out.push({
|
|
914
1032
|
field: "dateBinding",
|
|
915
1033
|
message: `option "${key}" dateBinding must name a date property (its slug, e.g. "dueDate")`,
|
|
@@ -927,22 +1045,35 @@ export function lifecycleOptionWaitsProblems(option: {
|
|
|
927
1045
|
return out;
|
|
928
1046
|
};
|
|
929
1047
|
if (!w || typeof w !== "object" || Array.isArray(w))
|
|
930
|
-
return fail(
|
|
1048
|
+
return fail(
|
|
1049
|
+
`option "${key}" waits must be an object { on, waitKind?, refFrom?, dateBinding? }`
|
|
1050
|
+
);
|
|
931
1051
|
if (finished)
|
|
932
1052
|
return fail(
|
|
933
1053
|
`option "${key}" is ${String(option.category)}: a finished thing waits on nothing (waits is for open, active or paused options)`
|
|
934
1054
|
);
|
|
935
1055
|
const waits = w as Record<string, unknown>;
|
|
936
|
-
if (
|
|
937
|
-
|
|
1056
|
+
if (
|
|
1057
|
+
typeof waits.on !== "string" ||
|
|
1058
|
+
!(LIFECYCLE_WAITS_ON as readonly string[]).includes(waits.on)
|
|
1059
|
+
)
|
|
1060
|
+
return fail(
|
|
1061
|
+
`option "${key}" waits.on must be one of ${LIFECYCLE_WAITS_ON.join(" | ")}`
|
|
1062
|
+
);
|
|
938
1063
|
if (
|
|
939
1064
|
waits.waitKind !== undefined &&
|
|
940
|
-
(typeof waits.waitKind !== "string" ||
|
|
1065
|
+
(typeof waits.waitKind !== "string" ||
|
|
1066
|
+
!(LIFECYCLE_WAIT_KINDS as readonly string[]).includes(waits.waitKind))
|
|
941
1067
|
)
|
|
942
|
-
return fail(
|
|
1068
|
+
return fail(
|
|
1069
|
+
`option "${key}" waits.waitKind is not a wait kind (WAIT_KINDS)`
|
|
1070
|
+
);
|
|
943
1071
|
for (const field of ["refFrom", "dateBinding"] as const) {
|
|
944
1072
|
const v = waits[field];
|
|
945
|
-
if (
|
|
1073
|
+
if (
|
|
1074
|
+
v !== undefined &&
|
|
1075
|
+
(typeof v !== "string" || !LIFECYCLE_PROPERTY_SLUG.test(v))
|
|
1076
|
+
)
|
|
946
1077
|
return fail(
|
|
947
1078
|
`option "${key}" waits.${field} must name a property (its slug, e.g. "${field === "refFrom" ? "contactId" : "nextActionAt"}")`
|
|
948
1079
|
);
|
|
@@ -950,7 +1081,10 @@ export function lifecycleOptionWaitsProblems(option: {
|
|
|
950
1081
|
const unknown = Object.keys(waits).filter(
|
|
951
1082
|
(k) => !(LIFECYCLE_OPTION_WAITS_FIELDS as readonly string[]).includes(k)
|
|
952
1083
|
);
|
|
953
|
-
if (unknown.length > 0)
|
|
1084
|
+
if (unknown.length > 0)
|
|
1085
|
+
return fail(
|
|
1086
|
+
`option "${key}" waits has unknown field(s): ${unknown.join(", ")}`
|
|
1087
|
+
);
|
|
954
1088
|
return out;
|
|
955
1089
|
}
|
|
956
1090
|
|
|
@@ -979,20 +1113,34 @@ export function lifecycleOptionRequiresProblem(option: {
|
|
|
979
1113
|
if (raw === undefined) return null;
|
|
980
1114
|
const key = String(option.key);
|
|
981
1115
|
const at = (i: number) => `option "${key}" requires[${i}]`;
|
|
982
|
-
if (!Array.isArray(raw))
|
|
983
|
-
|
|
1116
|
+
if (!Array.isArray(raw))
|
|
1117
|
+
return `option "${key}" requires must be a list of { kind: "link" | "property", blockerKey, ... }`;
|
|
1118
|
+
if (
|
|
1119
|
+
raw.length > 0 &&
|
|
1120
|
+
(option.category === "done" || option.category === "lost")
|
|
1121
|
+
)
|
|
984
1122
|
return `option "${key}" is ${String(option.category)}: a finished thing requires nothing (requires is for open, active or paused options)`;
|
|
985
|
-
if (raw.length > REQUIREMENTS_PER_OPTION_MAX)
|
|
1123
|
+
if (raw.length > REQUIREMENTS_PER_OPTION_MAX)
|
|
1124
|
+
return `option "${key}" requires at most ${REQUIREMENTS_PER_OPTION_MAX} things`;
|
|
986
1125
|
const seen = new Set<string>();
|
|
987
1126
|
for (const [i, item] of raw.entries()) {
|
|
988
|
-
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
1127
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
1128
|
+
return `${at(i)} must be an object`;
|
|
989
1129
|
const r = item as Record<string, unknown>;
|
|
990
1130
|
if (typeof r.blockerKey !== "string" || !BLOCKER_KEY.test(r.blockerKey))
|
|
991
1131
|
return `${at(i)}.blockerKey must be a lowercase name (letters, digits, _), e.g. "no_contact"`;
|
|
992
|
-
if (seen.has(r.blockerKey))
|
|
1132
|
+
if (seen.has(r.blockerKey))
|
|
1133
|
+
return `${at(i)}.blockerKey "${r.blockerKey}" is declared twice`;
|
|
993
1134
|
seen.add(r.blockerKey);
|
|
994
|
-
if (
|
|
995
|
-
|
|
1135
|
+
if (
|
|
1136
|
+
r.label !== undefined &&
|
|
1137
|
+
(typeof r.label !== "string" || !r.label.trim())
|
|
1138
|
+
)
|
|
1139
|
+
return `${at(i)}.label must be words`;
|
|
1140
|
+
if (
|
|
1141
|
+
r.owner !== undefined &&
|
|
1142
|
+
!(LIFECYCLE_REQUIREMENT_OWNERS as readonly unknown[]).includes(r.owner)
|
|
1143
|
+
)
|
|
996
1144
|
return `${at(i)}.owner must be one of ${LIFECYCLE_REQUIREMENT_OWNERS.join(" | ")}`;
|
|
997
1145
|
if (r.clearedBy !== undefined && !requirementClearedByOk(r.clearedBy))
|
|
998
1146
|
return `${at(i)}.clearedBy must be one of { answer: true } | { intent } | { playbookId } | { capability }`;
|
|
@@ -1000,28 +1148,68 @@ export function lifecycleOptionRequiresProblem(option: {
|
|
|
1000
1148
|
r.forKinds !== undefined &&
|
|
1001
1149
|
(!Array.isArray(r.forKinds) ||
|
|
1002
1150
|
r.forKinds.length === 0 ||
|
|
1003
|
-
!r.forKinds.every(
|
|
1151
|
+
!r.forKinds.every(
|
|
1152
|
+
(k) => typeof k === "string" && LIFECYCLE_PROPERTY_SLUG.test(k)
|
|
1153
|
+
))
|
|
1004
1154
|
)
|
|
1005
1155
|
return `${at(i)}.forKinds must be a list of kind slugs (e.g. ["person"])`;
|
|
1006
|
-
const common = [
|
|
1156
|
+
const common = [
|
|
1157
|
+
"kind",
|
|
1158
|
+
"blockerKey",
|
|
1159
|
+
"label",
|
|
1160
|
+
"owner",
|
|
1161
|
+
"clearedBy",
|
|
1162
|
+
"forKinds",
|
|
1163
|
+
];
|
|
1007
1164
|
if (r.kind === "link") {
|
|
1008
|
-
if (
|
|
1165
|
+
if (
|
|
1166
|
+
typeof r.relation !== "string" ||
|
|
1167
|
+
!LIFECYCLE_PROPERTY_SLUG.test(r.relation)
|
|
1168
|
+
)
|
|
1009
1169
|
return `${at(i)}.relation must name a relation type (its slug, e.g. "works_at")`;
|
|
1010
|
-
if (
|
|
1170
|
+
if (
|
|
1171
|
+
!(LIFECYCLE_REQUIREMENT_DIRECTIONS as readonly unknown[]).includes(
|
|
1172
|
+
r.direction
|
|
1173
|
+
)
|
|
1174
|
+
)
|
|
1011
1175
|
return `${at(i)}.direction must be "out" (the thing is the link's source) or "in" (its target)`;
|
|
1012
|
-
if (
|
|
1176
|
+
if (
|
|
1177
|
+
r.min !== undefined &&
|
|
1178
|
+
!(
|
|
1179
|
+
typeof r.min === "number" &&
|
|
1180
|
+
Number.isInteger(r.min) &&
|
|
1181
|
+
r.min >= 1 &&
|
|
1182
|
+
r.min <= 1000
|
|
1183
|
+
)
|
|
1184
|
+
)
|
|
1013
1185
|
return `${at(i)}.min must be a whole number from 1 to 1000`;
|
|
1014
|
-
const unknown = Object.keys(r).filter(
|
|
1015
|
-
|
|
1186
|
+
const unknown = Object.keys(r).filter(
|
|
1187
|
+
(k) => ![...common, "relation", "direction", "min"].includes(k)
|
|
1188
|
+
);
|
|
1189
|
+
if (unknown.length > 0)
|
|
1190
|
+
return `${at(i)} has unknown field(s): ${unknown.join(", ")}`;
|
|
1016
1191
|
continue;
|
|
1017
1192
|
}
|
|
1018
1193
|
if (r.kind === "property") {
|
|
1019
|
-
if (
|
|
1194
|
+
if (
|
|
1195
|
+
typeof r.property !== "string" ||
|
|
1196
|
+
!LIFECYCLE_PROPERTY_SLUG.test(r.property)
|
|
1197
|
+
)
|
|
1020
1198
|
return `${at(i)}.property must name a property (its slug, e.g. "linkedinUrl")`;
|
|
1021
|
-
if (
|
|
1199
|
+
if (
|
|
1200
|
+
r.in !== undefined &&
|
|
1201
|
+
!(
|
|
1202
|
+
Array.isArray(r.in) &&
|
|
1203
|
+
r.in.length > 0 &&
|
|
1204
|
+
r.in.every((v) => typeof v === "string" && v.trim())
|
|
1205
|
+
)
|
|
1206
|
+
)
|
|
1022
1207
|
return `${at(i)}.in must be a non-empty list of values`;
|
|
1023
|
-
const unknown = Object.keys(r).filter(
|
|
1024
|
-
|
|
1208
|
+
const unknown = Object.keys(r).filter(
|
|
1209
|
+
(k) => ![...common, "property", "in"].includes(k)
|
|
1210
|
+
);
|
|
1211
|
+
if (unknown.length > 0)
|
|
1212
|
+
return `${at(i)} has unknown field(s): ${unknown.join(", ")}`;
|
|
1025
1213
|
continue;
|
|
1026
1214
|
}
|
|
1027
1215
|
return `${at(i)}.kind must be "link" or "property"`;
|
|
@@ -1035,7 +1223,9 @@ function requirementClearedByOk(raw: unknown): boolean {
|
|
|
1035
1223
|
const c = raw as Record<string, unknown>;
|
|
1036
1224
|
if (Object.keys(c).length !== 1) return false;
|
|
1037
1225
|
if (c.answer === true) return true;
|
|
1038
|
-
return (["intent", "playbookId", "capability"] as const).some(
|
|
1226
|
+
return (["intent", "playbookId", "capability"] as const).some(
|
|
1227
|
+
(k) => typeof c[k] === "string" && (c[k] as string).trim() !== ""
|
|
1228
|
+
);
|
|
1039
1229
|
}
|
|
1040
1230
|
|
|
1041
1231
|
/** Key-sorted JSON, so two equal declarations compare equal whatever the YAML key order. */
|
|
@@ -1045,7 +1235,10 @@ function stableJson(v: unknown): string {
|
|
|
1045
1235
|
return `{${Object.keys(v as Record<string, unknown>)
|
|
1046
1236
|
.filter((k) => (v as Record<string, unknown>)[k] !== undefined)
|
|
1047
1237
|
.sort()
|
|
1048
|
-
.map(
|
|
1238
|
+
.map(
|
|
1239
|
+
(k) =>
|
|
1240
|
+
`${JSON.stringify(k)}:${stableJson((v as Record<string, unknown>)[k])}`
|
|
1241
|
+
)
|
|
1049
1242
|
.join(",")}}`;
|
|
1050
1243
|
return JSON.stringify(v);
|
|
1051
1244
|
}
|
|
@@ -1081,8 +1274,15 @@ function checkLifecycleDeclarations(
|
|
|
1081
1274
|
const lc = profile.lifecycle;
|
|
1082
1275
|
const at = `profiles.${profile.slug}.lifecycle`;
|
|
1083
1276
|
if (lc !== undefined) {
|
|
1084
|
-
const prop = (profile.properties ?? []).find(
|
|
1085
|
-
|
|
1277
|
+
const prop = (profile.properties ?? []).find(
|
|
1278
|
+
(p) => p.slug === lc?.property
|
|
1279
|
+
);
|
|
1280
|
+
if (
|
|
1281
|
+
!prop ||
|
|
1282
|
+
prop.inputType !== "select" ||
|
|
1283
|
+
!Array.isArray(prop.enumValues) ||
|
|
1284
|
+
prop.enumValues.length === 0
|
|
1285
|
+
) {
|
|
1086
1286
|
add(
|
|
1087
1287
|
"lifecycle-property-unknown",
|
|
1088
1288
|
`${at}.property`,
|
|
@@ -1105,10 +1305,20 @@ function checkLifecycleDeclarations(
|
|
|
1105
1305
|
`option "${String(o?.key)}" category "${String(o?.category)}" is not one of ${LIFECYCLE_CATEGORIES.join(" · ")}`
|
|
1106
1306
|
);
|
|
1107
1307
|
if (o?.humanOnly !== undefined && typeof o.humanOnly !== "boolean")
|
|
1108
|
-
add(
|
|
1109
|
-
|
|
1308
|
+
add(
|
|
1309
|
+
"lifecycle-option-shape",
|
|
1310
|
+
`${at}.options[${i}].humanOnly`,
|
|
1311
|
+
`option "${String(o?.key)}" humanOnly must be a boolean`
|
|
1312
|
+
);
|
|
1313
|
+
const stuck = (o as { stuckAfterDays?: unknown } | undefined)
|
|
1314
|
+
?.stuckAfterDays;
|
|
1110
1315
|
if (stuck !== undefined) {
|
|
1111
|
-
if (
|
|
1316
|
+
if (
|
|
1317
|
+
typeof stuck !== "number" ||
|
|
1318
|
+
!Number.isInteger(stuck) ||
|
|
1319
|
+
stuck < 1 ||
|
|
1320
|
+
stuck > STUCK_AFTER_DAYS_MAX
|
|
1321
|
+
)
|
|
1112
1322
|
add(
|
|
1113
1323
|
"lifecycle-option-shape",
|
|
1114
1324
|
`${at}.options[${i}].stuckAfterDays`,
|
|
@@ -1122,9 +1332,18 @@ function checkLifecycleDeclarations(
|
|
|
1122
1332
|
);
|
|
1123
1333
|
}
|
|
1124
1334
|
for (const p of lifecycleOptionWaitsProblems(o ?? {}))
|
|
1125
|
-
add(
|
|
1335
|
+
add(
|
|
1336
|
+
"lifecycle-option-shape",
|
|
1337
|
+
`${at}.options[${i}].${p.field}`,
|
|
1338
|
+
p.message
|
|
1339
|
+
);
|
|
1126
1340
|
const requiresProblem = lifecycleOptionRequiresProblem(o ?? {});
|
|
1127
|
-
if (requiresProblem)
|
|
1341
|
+
if (requiresProblem)
|
|
1342
|
+
add(
|
|
1343
|
+
"lifecycle-option-shape",
|
|
1344
|
+
`${at}.options[${i}].requires`,
|
|
1345
|
+
requiresProblem
|
|
1346
|
+
);
|
|
1128
1347
|
});
|
|
1129
1348
|
}
|
|
1130
1349
|
}
|
|
@@ -1188,13 +1407,20 @@ function checkPresentationDeclarations(
|
|
|
1188
1407
|
continue;
|
|
1189
1408
|
}
|
|
1190
1409
|
const props = new Map((profile.properties ?? []).map((p) => [p.slug, p]));
|
|
1191
|
-
const named: Array<{ path: string; slug: string; entityRef?: boolean }> =
|
|
1410
|
+
const named: Array<{ path: string; slug: string; entityRef?: boolean }> =
|
|
1411
|
+
[];
|
|
1192
1412
|
// `source` then each fallback: every home of the media must exist here.
|
|
1193
1413
|
declaredMediaSources(parsed.value).forEach((source, i) => {
|
|
1194
|
-
const where =
|
|
1195
|
-
|
|
1414
|
+
const where =
|
|
1415
|
+
i === 0 ? `${at}.media.source` : `${at}.media.fallbacks[${i - 1}]`;
|
|
1416
|
+
if ("property" in source)
|
|
1417
|
+
named.push({ path: `${where}.property`, slug: source.property });
|
|
1196
1418
|
if ("entityRef" in source)
|
|
1197
|
-
named.push({
|
|
1419
|
+
named.push({
|
|
1420
|
+
path: `${where}.entityRef`,
|
|
1421
|
+
slug: source.entityRef,
|
|
1422
|
+
entityRef: true,
|
|
1423
|
+
});
|
|
1198
1424
|
});
|
|
1199
1425
|
for (const alt of ["card", "row"] as const)
|
|
1200
1426
|
(parsed.value.fields?.[alt] ?? []).forEach((slug, i) =>
|
|
@@ -1257,16 +1483,26 @@ function checkKanbanGrouping(
|
|
|
1257
1483
|
for (const v of tpl.views ?? []) {
|
|
1258
1484
|
if (String(v.type || "").toLowerCase() !== "kanban") continue;
|
|
1259
1485
|
const at = `views."${v.name}"`;
|
|
1260
|
-
const dead =
|
|
1486
|
+
const dead =
|
|
1487
|
+
v.groupBy !== undefined
|
|
1488
|
+
? "groupBy"
|
|
1489
|
+
: (v.config as { groupBy?: unknown } | undefined)?.groupBy !== undefined
|
|
1490
|
+
? "config.groupBy"
|
|
1491
|
+
: null;
|
|
1261
1492
|
if (dead)
|
|
1262
1493
|
add(
|
|
1263
1494
|
"view-kanban-group-dead",
|
|
1264
1495
|
`${at}.${dead}`,
|
|
1265
1496
|
`kanban "${v.name}" declares ${dead} — the board never reads it (it groups by status); write config.groupByField instead`
|
|
1266
1497
|
);
|
|
1267
|
-
const field = (v.config as { groupByField?: unknown } | undefined)
|
|
1498
|
+
const field = (v.config as { groupByField?: unknown } | undefined)
|
|
1499
|
+
?.groupByField;
|
|
1268
1500
|
if (typeof field !== "string" || !field.trim()) {
|
|
1269
|
-
add(
|
|
1501
|
+
add(
|
|
1502
|
+
"view-kanban-group-missing",
|
|
1503
|
+
`${at}.config.groupByField`,
|
|
1504
|
+
`kanban "${v.name}" names no config.groupByField — its columns would be the values of "status"`
|
|
1505
|
+
);
|
|
1270
1506
|
continue;
|
|
1271
1507
|
}
|
|
1272
1508
|
const kind = v.scopeProfileSlug;
|
|
@@ -1274,8 +1510,15 @@ function checkKanbanGrouping(
|
|
|
1274
1510
|
const slug = field.includes(".") ? field.split(".").pop()! : field;
|
|
1275
1511
|
const decls = profileDeclarations(kind, tpl, resolveDep, corpus);
|
|
1276
1512
|
if (decls.length === 0) continue;
|
|
1277
|
-
const prop = decls
|
|
1278
|
-
|
|
1513
|
+
const prop = decls
|
|
1514
|
+
.flatMap((p) => p.properties ?? [])
|
|
1515
|
+
.find((p) => p.slug === slug);
|
|
1516
|
+
if (
|
|
1517
|
+
!prop ||
|
|
1518
|
+
prop.inputType !== "select" ||
|
|
1519
|
+
!Array.isArray(prop.enumValues) ||
|
|
1520
|
+
prop.enumValues.length === 0
|
|
1521
|
+
)
|
|
1279
1522
|
add(
|
|
1280
1523
|
"view-kanban-group-unknown",
|
|
1281
1524
|
`${at}.config.groupByField`,
|
|
@@ -1324,11 +1567,23 @@ function checkIntent(
|
|
|
1324
1567
|
return;
|
|
1325
1568
|
}
|
|
1326
1569
|
if (!intent || typeof intent !== "object" || Array.isArray(intent)) {
|
|
1327
|
-
add(
|
|
1570
|
+
add(
|
|
1571
|
+
"intent-shape",
|
|
1572
|
+
"meta.intent",
|
|
1573
|
+
"meta.intent must be { label, primary?, produces?: [{ profile }] }"
|
|
1574
|
+
);
|
|
1328
1575
|
return;
|
|
1329
1576
|
}
|
|
1330
|
-
const { label, produces, primary } = intent as {
|
|
1331
|
-
|
|
1577
|
+
const { label, produces, primary } = intent as {
|
|
1578
|
+
label?: unknown;
|
|
1579
|
+
produces?: unknown;
|
|
1580
|
+
primary?: unknown;
|
|
1581
|
+
};
|
|
1582
|
+
if (
|
|
1583
|
+
typeof label !== "string" ||
|
|
1584
|
+
!label.trim() ||
|
|
1585
|
+
label.trim().length > INTENT_LABEL_MAX
|
|
1586
|
+
)
|
|
1332
1587
|
add(
|
|
1333
1588
|
"intent-label",
|
|
1334
1589
|
"meta.intent.label",
|
|
@@ -1338,10 +1593,16 @@ function checkIntent(
|
|
|
1338
1593
|
// leads with its flow, so it is named, and it is one of what the space
|
|
1339
1594
|
// produces (the rest are its operational kinds). A library has no flow.
|
|
1340
1595
|
const producedSlugs = Array.isArray(produces)
|
|
1341
|
-
? produces
|
|
1596
|
+
? produces
|
|
1597
|
+
.map((e) => (e as { profile?: unknown } | null)?.profile)
|
|
1598
|
+
.filter((s): s is string => typeof s === "string")
|
|
1342
1599
|
: [];
|
|
1343
1600
|
if (primary !== undefined && (typeof primary !== "string" || !primary.trim()))
|
|
1344
|
-
add(
|
|
1601
|
+
add(
|
|
1602
|
+
"intent-shape",
|
|
1603
|
+
"meta.intent.primary",
|
|
1604
|
+
`meta.intent.primary must be a profile slug (got ${JSON.stringify(primary)})`
|
|
1605
|
+
);
|
|
1345
1606
|
else if (primary === undefined && producedSlugs.length > 0)
|
|
1346
1607
|
add(
|
|
1347
1608
|
"intent-primary-missing",
|
|
@@ -1362,32 +1623,53 @@ function checkIntent(
|
|
|
1362
1623
|
);
|
|
1363
1624
|
if (produces === undefined) return;
|
|
1364
1625
|
if (!Array.isArray(produces)) {
|
|
1365
|
-
add(
|
|
1626
|
+
add(
|
|
1627
|
+
"intent-shape",
|
|
1628
|
+
"meta.intent.produces",
|
|
1629
|
+
"meta.intent.produces must be a list of { profile }"
|
|
1630
|
+
);
|
|
1366
1631
|
return;
|
|
1367
1632
|
}
|
|
1368
1633
|
const closure = [...collectDependencyClosure(tpl, resolveDep)];
|
|
1369
|
-
const sources = [
|
|
1634
|
+
const sources = [
|
|
1635
|
+
tpl,
|
|
1636
|
+
...closure.map(resolveDep).filter((t): t is WorkspaceYaml => !!t),
|
|
1637
|
+
];
|
|
1370
1638
|
const unresolved = closure.some((d) => !resolveDep(d));
|
|
1371
1639
|
const seen = new Set<string>();
|
|
1372
1640
|
produces.forEach((entry, i) => {
|
|
1373
1641
|
const at = `meta.intent.produces[${i}]`;
|
|
1374
1642
|
const slug = (entry as { profile?: unknown } | null)?.profile;
|
|
1375
1643
|
if (typeof slug !== "string" || !slug) {
|
|
1376
|
-
add(
|
|
1644
|
+
add(
|
|
1645
|
+
"intent-shape",
|
|
1646
|
+
`${at}.profile`,
|
|
1647
|
+
`${at} must be { profile: <profile slug> }`
|
|
1648
|
+
);
|
|
1377
1649
|
return;
|
|
1378
1650
|
}
|
|
1379
|
-
if (seen.has(slug))
|
|
1651
|
+
if (seen.has(slug))
|
|
1652
|
+
add("intent-duplicate", `${at}.profile`, `"${slug}" is produced twice`);
|
|
1380
1653
|
seen.add(slug);
|
|
1381
1654
|
const as = (entry as { as?: unknown }).as;
|
|
1382
|
-
if (
|
|
1383
|
-
|
|
1655
|
+
if (
|
|
1656
|
+
as !== undefined &&
|
|
1657
|
+
!(TEMPLATE_KIND_AS as readonly unknown[]).includes(as)
|
|
1658
|
+
)
|
|
1659
|
+
add(
|
|
1660
|
+
"intent-shape",
|
|
1661
|
+
`${at}.as`,
|
|
1662
|
+
`${at}.as must be one of ${TEMPLATE_KIND_AS.join(", ")} (got ${JSON.stringify(as)})`
|
|
1663
|
+
);
|
|
1384
1664
|
if (as === "helper" && slug === primary)
|
|
1385
1665
|
add(
|
|
1386
1666
|
"intent-primary-helper",
|
|
1387
1667
|
`${at}.as`,
|
|
1388
1668
|
`"${slug}" is the space's primary output and cannot be a helper — a helper is worked to serve an output, it is not one`
|
|
1389
1669
|
);
|
|
1390
|
-
const decls = sources.flatMap((t) =>
|
|
1670
|
+
const decls = sources.flatMap((t) =>
|
|
1671
|
+
(t.profiles ?? []).filter((p) => p.slug === slug)
|
|
1672
|
+
);
|
|
1391
1673
|
if (decls.length === 0) {
|
|
1392
1674
|
if (!unresolved)
|
|
1393
1675
|
add(
|
|
@@ -1435,21 +1717,50 @@ function checkStart(
|
|
|
1435
1717
|
if (raw === undefined) return;
|
|
1436
1718
|
const why = ownsNoWorkspace(tpl);
|
|
1437
1719
|
if (why) {
|
|
1438
|
-
add(
|
|
1720
|
+
add(
|
|
1721
|
+
"start-no-workspace",
|
|
1722
|
+
"meta.start",
|
|
1723
|
+
`"${tpl.meta.slug}" is ${why} — it owns no space, so it cannot be an onboarding start`
|
|
1724
|
+
);
|
|
1439
1725
|
return;
|
|
1440
1726
|
}
|
|
1441
|
-
const isStr = (v: unknown): v is string =>
|
|
1442
|
-
|
|
1727
|
+
const isStr = (v: unknown): v is string =>
|
|
1728
|
+
typeof v === "string" && v.trim().length > 0;
|
|
1729
|
+
const strList = (v: unknown): v is string[] =>
|
|
1730
|
+
Array.isArray(v) && v.every(isStr);
|
|
1443
1731
|
const st = raw as Record<string, any>;
|
|
1444
1732
|
const fs = st?.firstSession;
|
|
1445
1733
|
const shapeOk =
|
|
1446
|
-
!!st &&
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1734
|
+
!!st &&
|
|
1735
|
+
typeof st === "object" &&
|
|
1736
|
+
!Array.isArray(st) &&
|
|
1737
|
+
Number.isInteger(st.order) &&
|
|
1738
|
+
st.order > 0 &&
|
|
1739
|
+
isStr(st.label) &&
|
|
1740
|
+
isStr(st.promise) &&
|
|
1741
|
+
strList(st.suggestFor) &&
|
|
1742
|
+
(st.profile === undefined || isStr(st.profile)) &&
|
|
1743
|
+
strList(st.views) &&
|
|
1744
|
+
strList(st.starters) &&
|
|
1745
|
+
Array.isArray(st.example) &&
|
|
1746
|
+
st.example.every(
|
|
1747
|
+
(e: any) =>
|
|
1748
|
+
e &&
|
|
1749
|
+
isStr(e.title) &&
|
|
1750
|
+
(e.values === undefined ||
|
|
1751
|
+
(typeof e.values === "object" &&
|
|
1752
|
+
e.values !== null &&
|
|
1753
|
+
!Array.isArray(e.values)))
|
|
1754
|
+
) &&
|
|
1755
|
+
!!fs &&
|
|
1756
|
+
isStr(fs.title) &&
|
|
1757
|
+
isStr(fs.goal);
|
|
1451
1758
|
if (!shapeOk) {
|
|
1452
|
-
add(
|
|
1759
|
+
add(
|
|
1760
|
+
"start-shape",
|
|
1761
|
+
"meta.start",
|
|
1762
|
+
"meta.start must be { order (int ≥ 1), label, promise, suggestFor[], profile?, views[], example[{ title, values? }], firstSession{ title, goal }, starters[] }"
|
|
1763
|
+
);
|
|
1453
1764
|
return;
|
|
1454
1765
|
}
|
|
1455
1766
|
const start = st as import("./types.ts").TemplateStart;
|
|
@@ -1457,52 +1768,110 @@ function checkStart(
|
|
|
1457
1768
|
// another kind; naming the primary again is a second copy that can drift.
|
|
1458
1769
|
const primary = tpl.meta.intent?.primary;
|
|
1459
1770
|
if (start.profile !== undefined && start.profile === primary)
|
|
1460
|
-
add(
|
|
1771
|
+
add(
|
|
1772
|
+
"start-profile-redundant",
|
|
1773
|
+
"meta.start.profile",
|
|
1774
|
+
`meta.start.profile repeats meta.intent.primary "${primary}" — omit it (the start defaults to the primary output)`
|
|
1775
|
+
);
|
|
1461
1776
|
const profile = startProfileOf(tpl.meta);
|
|
1462
1777
|
if (!profile) {
|
|
1463
|
-
add(
|
|
1778
|
+
add(
|
|
1779
|
+
"start-profile-missing",
|
|
1780
|
+
"meta.profile",
|
|
1781
|
+
`meta.start names no kind and "${tpl.meta.slug}" declares no meta.intent.primary to default to`
|
|
1782
|
+
);
|
|
1464
1783
|
return;
|
|
1465
1784
|
}
|
|
1466
1785
|
if (start.label.trim().length > INTENT_LABEL_MAX)
|
|
1467
|
-
add(
|
|
1786
|
+
add(
|
|
1787
|
+
"start-label",
|
|
1788
|
+
"meta.start.label",
|
|
1789
|
+
`meta.start.label must be at most ${INTENT_LABEL_MAX} characters (got ${JSON.stringify(start.label)})`
|
|
1790
|
+
);
|
|
1468
1791
|
const [exMin, exMax] = START_EXAMPLE_RANGE;
|
|
1469
1792
|
if (start.example.length < exMin || start.example.length > exMax)
|
|
1470
|
-
add(
|
|
1793
|
+
add(
|
|
1794
|
+
"start-example-count",
|
|
1795
|
+
"meta.start.example",
|
|
1796
|
+
`meta.start.example needs ${exMin}-${exMax} rows (got ${start.example.length})`
|
|
1797
|
+
);
|
|
1471
1798
|
const [stMin, stMax] = START_STARTERS_RANGE;
|
|
1472
1799
|
if (start.starters.length < stMin || start.starters.length > stMax)
|
|
1473
|
-
add(
|
|
1800
|
+
add(
|
|
1801
|
+
"start-starters-count",
|
|
1802
|
+
"meta.start.starters",
|
|
1803
|
+
`meta.start.starters needs ${stMin}-${stMax} chips (got ${start.starters.length})`
|
|
1804
|
+
);
|
|
1474
1805
|
|
|
1475
1806
|
// Views: this template's own, scoped to the produced kind.
|
|
1476
1807
|
if (start.views.length < 1 || start.views.length > START_VIEWS_MAX)
|
|
1477
|
-
add(
|
|
1808
|
+
add(
|
|
1809
|
+
"start-views-count",
|
|
1810
|
+
"meta.start.views",
|
|
1811
|
+
`meta.start.views needs 1-${START_VIEWS_MAX} view slugs (got ${start.views.length})`
|
|
1812
|
+
);
|
|
1478
1813
|
start.views.forEach((slug, i) => {
|
|
1479
1814
|
const at = `meta.start.views[${i}]`;
|
|
1480
1815
|
const view = (tpl.views ?? []).find((v) => v.slug === slug);
|
|
1481
1816
|
if (!view) {
|
|
1482
|
-
add(
|
|
1817
|
+
add(
|
|
1818
|
+
"start-views-exist",
|
|
1819
|
+
at,
|
|
1820
|
+
`"${slug}" is not a view (by slug) of "${tpl.meta.slug}"`
|
|
1821
|
+
);
|
|
1483
1822
|
return;
|
|
1484
1823
|
}
|
|
1485
|
-
const scope = [
|
|
1824
|
+
const scope = [
|
|
1825
|
+
view.scopeProfileSlug,
|
|
1826
|
+
...(view.scopeProfileSlugs ?? []),
|
|
1827
|
+
].filter(Boolean);
|
|
1486
1828
|
if (!scope.includes(profile))
|
|
1487
|
-
add(
|
|
1829
|
+
add(
|
|
1830
|
+
"start-views-scope",
|
|
1831
|
+
at,
|
|
1832
|
+
`view "${slug}" is not scoped to "${profile}" (scope: ${scope.join(", ") || "none"})`
|
|
1833
|
+
);
|
|
1488
1834
|
});
|
|
1489
1835
|
|
|
1490
1836
|
// Profile + example against the declarations in the closure.
|
|
1491
1837
|
const closure = [...collectDependencyClosure(tpl, resolveDep)];
|
|
1492
|
-
const sources = [
|
|
1493
|
-
|
|
1838
|
+
const sources = [
|
|
1839
|
+
tpl,
|
|
1840
|
+
...closure.map(resolveDep).filter((t): t is WorkspaceYaml => !!t),
|
|
1841
|
+
];
|
|
1842
|
+
const decls = sources.flatMap((t) =>
|
|
1843
|
+
(t.profiles ?? []).filter((p) => p.slug === profile)
|
|
1844
|
+
);
|
|
1494
1845
|
if (decls.length === 0) {
|
|
1495
1846
|
if (!closure.some((d) => !resolveDep(d)))
|
|
1496
|
-
add(
|
|
1847
|
+
add(
|
|
1848
|
+
"start-profile-unknown",
|
|
1849
|
+
"meta.profile",
|
|
1850
|
+
`"${profile}" is neither declared by "${tpl.meta.slug}" nor by a template it depends on`
|
|
1851
|
+
);
|
|
1497
1852
|
} else {
|
|
1498
|
-
const props = new Map(
|
|
1853
|
+
const props = new Map(
|
|
1854
|
+
decls.flatMap((p) => p.properties ?? []).map((p) => [p.slug, p] as const)
|
|
1855
|
+
);
|
|
1499
1856
|
start.example.forEach((row, i) => {
|
|
1500
1857
|
for (const [key, value] of Object.entries(row.values ?? {})) {
|
|
1501
1858
|
const at = `meta.start.example[${i}].values.${key}`;
|
|
1502
1859
|
const prop = props.get(key);
|
|
1503
|
-
if (!prop)
|
|
1504
|
-
|
|
1505
|
-
|
|
1860
|
+
if (!prop)
|
|
1861
|
+
add(
|
|
1862
|
+
"start-example-property",
|
|
1863
|
+
at,
|
|
1864
|
+
`"${key}" is not a property of "${profile}"`
|
|
1865
|
+
);
|
|
1866
|
+
else if (
|
|
1867
|
+
prop.enumValues?.length &&
|
|
1868
|
+
!prop.enumValues.includes(value as string)
|
|
1869
|
+
)
|
|
1870
|
+
add(
|
|
1871
|
+
"start-example-enum",
|
|
1872
|
+
at,
|
|
1873
|
+
`${JSON.stringify(value)} is not one of ${profile}.${key}: ${prop.enumValues.join(", ")}`
|
|
1874
|
+
);
|
|
1506
1875
|
}
|
|
1507
1876
|
});
|
|
1508
1877
|
}
|
|
@@ -1510,21 +1879,37 @@ function checkStart(
|
|
|
1510
1879
|
// Catalog-wide: one start per card slot and per identity.
|
|
1511
1880
|
const ids = new Set<string>();
|
|
1512
1881
|
start.suggestFor.forEach((id, i) => {
|
|
1513
|
-
if (ids.has(id))
|
|
1882
|
+
if (ids.has(id))
|
|
1883
|
+
add(
|
|
1884
|
+
"start-suggest-duplicate",
|
|
1885
|
+
`meta.start.suggestFor[${i}]`,
|
|
1886
|
+
`identity "${id}" is listed twice`
|
|
1887
|
+
);
|
|
1514
1888
|
ids.add(id);
|
|
1515
1889
|
});
|
|
1516
1890
|
for (const other of corpus ?? []) {
|
|
1517
1891
|
const o = other.meta?.start;
|
|
1518
1892
|
if (!o || other.meta.slug === tpl.meta.slug) continue;
|
|
1519
1893
|
if (o.order === start.order)
|
|
1520
|
-
add(
|
|
1894
|
+
add(
|
|
1895
|
+
"start-order-duplicate",
|
|
1896
|
+
"meta.start.order",
|
|
1897
|
+
`order ${start.order} is also used by "${other.meta.slug}"`
|
|
1898
|
+
);
|
|
1521
1899
|
for (const id of o.suggestFor ?? [])
|
|
1522
|
-
if (ids.has(id))
|
|
1900
|
+
if (ids.has(id))
|
|
1901
|
+
add(
|
|
1902
|
+
"start-suggest-duplicate",
|
|
1903
|
+
"meta.start.suggestFor",
|
|
1904
|
+
`identity "${id}" is also suggested by "${other.meta.slug}"`
|
|
1905
|
+
);
|
|
1523
1906
|
}
|
|
1524
1907
|
}
|
|
1525
1908
|
|
|
1526
1909
|
/** True when the resolver is backed by a real corpus (it resolves foundation). */
|
|
1527
|
-
function hasCorpus(
|
|
1910
|
+
function hasCorpus(
|
|
1911
|
+
resolveDep: (slug: string) => WorkspaceYaml | undefined
|
|
1912
|
+
): boolean {
|
|
1528
1913
|
return resolveDep(SHARED_ROLE_SSOT_SLUG) !== undefined;
|
|
1529
1914
|
}
|
|
1530
1915
|
|
|
@@ -1618,11 +2003,11 @@ export function validateTemplate(
|
|
|
1618
2003
|
// 2026-09-25): install layers it onto its primary required domain, so it
|
|
1619
2004
|
// needs no profile shell — it earns validity by requiring ≥1 workspace.
|
|
1620
2005
|
const isPackRequiringDomains =
|
|
1621
|
-
(tpl.meta?.tags ?? []).includes(
|
|
2006
|
+
(tpl.meta?.tags ?? []).includes("suite") &&
|
|
1622
2007
|
(tpl.dependencies ?? []).some(
|
|
1623
2008
|
(d) =>
|
|
1624
|
-
(d.kind ??
|
|
1625
|
-
(d.relation ??
|
|
2009
|
+
(d.kind ?? "workspace") === "workspace" &&
|
|
2010
|
+
(d.relation ?? "require") === "require"
|
|
1626
2011
|
);
|
|
1627
2012
|
if (
|
|
1628
2013
|
(!tpl.profiles || tpl.profiles.length === 0) &&
|
|
@@ -1716,9 +2101,17 @@ export function validateTemplate(
|
|
|
1716
2101
|
for (const [i, cell] of (tpl.spacePackage?.cells ?? []).entries()) {
|
|
1717
2102
|
const at = `spacePackage.cells[${i}]`;
|
|
1718
2103
|
if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(cell.key ?? "")) {
|
|
1719
|
-
add(
|
|
2104
|
+
add(
|
|
2105
|
+
"space-package-cell-key",
|
|
2106
|
+
`${at}.key`,
|
|
2107
|
+
"A space package cell needs a kebab-case key"
|
|
2108
|
+
);
|
|
1720
2109
|
} else if (packageCellKeys.has(cell.key)) {
|
|
1721
|
-
add(
|
|
2110
|
+
add(
|
|
2111
|
+
"space-package-cell-key-duplicate",
|
|
2112
|
+
`${at}.key`,
|
|
2113
|
+
`Space package cell key "${cell.key}" is declared twice`
|
|
2114
|
+
);
|
|
1722
2115
|
} else {
|
|
1723
2116
|
packageCellKeys.add(cell.key);
|
|
1724
2117
|
}
|
|
@@ -1737,12 +2130,18 @@ export function validateTemplate(
|
|
|
1737
2130
|
}
|
|
1738
2131
|
const entryCellKeys: Array<[string, string | undefined]> = [
|
|
1739
2132
|
["app.cellKey", tpl.app?.kind === "stored" ? tpl.app.cellKey : undefined],
|
|
1740
|
-
[
|
|
2133
|
+
[
|
|
2134
|
+
"layout.primarySurface.cellKey",
|
|
2135
|
+
authoredPrimary?.kind === "cell" ? authoredPrimary.cellKey : undefined,
|
|
2136
|
+
],
|
|
1741
2137
|
];
|
|
1742
2138
|
for (const [path, cellKey] of entryCellKeys) {
|
|
1743
2139
|
if (!cellKey?.startsWith("cell:")) continue;
|
|
1744
2140
|
const own = `cell:${tpl.meta?.slug}:`;
|
|
1745
|
-
if (
|
|
2141
|
+
if (
|
|
2142
|
+
!cellKey.startsWith(own) ||
|
|
2143
|
+
!packageCellKeys.has(cellKey.slice(own.length))
|
|
2144
|
+
) {
|
|
1746
2145
|
add(
|
|
1747
2146
|
"space-package-entry-unknown",
|
|
1748
2147
|
path,
|
|
@@ -1775,7 +2174,8 @@ export function validateTemplate(
|
|
|
1775
2174
|
// The pod refuses these at every profile write path; a reference to one then
|
|
1776
2175
|
// fails referential integrity below, so refusing the declaration is enough.
|
|
1777
2176
|
for (const profile of tpl.profiles || []) {
|
|
1778
|
-
if (!RESERVED_PROFILE_SLUGS.has(String(profile.slug).trim().toLowerCase()))
|
|
2177
|
+
if (!RESERVED_PROFILE_SLUGS.has(String(profile.slug).trim().toLowerCase()))
|
|
2178
|
+
continue;
|
|
1779
2179
|
add(
|
|
1780
2180
|
"profile-slug-reserved",
|
|
1781
2181
|
`profiles.${profile.slug}`,
|
|
@@ -2096,7 +2496,11 @@ export function validateTemplate(
|
|
|
2096
2496
|
"a template rule needs a kebab-case `key` (its identity across versions)"
|
|
2097
2497
|
);
|
|
2098
2498
|
} else if (ruleKeys.has(r.key)) {
|
|
2099
|
-
add(
|
|
2499
|
+
add(
|
|
2500
|
+
"rule-key-duplicate",
|
|
2501
|
+
`${where}.key`,
|
|
2502
|
+
`duplicate rule key "${r.key}"`
|
|
2503
|
+
);
|
|
2100
2504
|
} else {
|
|
2101
2505
|
ruleKeys.add(r.key);
|
|
2102
2506
|
}
|
|
@@ -2123,7 +2527,11 @@ export function validateTemplate(
|
|
|
2123
2527
|
continue;
|
|
2124
2528
|
}
|
|
2125
2529
|
if (skillSlugs.has(s.slug)) {
|
|
2126
|
-
add(
|
|
2530
|
+
add(
|
|
2531
|
+
"skill-duplicate",
|
|
2532
|
+
`${where}.slug`,
|
|
2533
|
+
`duplicate skill slug "${s.slug}"`
|
|
2534
|
+
);
|
|
2127
2535
|
} else {
|
|
2128
2536
|
skillSlugs.add(s.slug);
|
|
2129
2537
|
}
|
|
@@ -2255,7 +2663,10 @@ export function validateTemplate(
|
|
|
2255
2663
|
const documentSlugs = new Set<string>();
|
|
2256
2664
|
for (const [i, d] of (tpl.documents || []).entries()) {
|
|
2257
2665
|
const where = `documents[${i}]`;
|
|
2258
|
-
if (
|
|
2666
|
+
if (
|
|
2667
|
+
typeof d?.slug !== "string" ||
|
|
2668
|
+
!TEMPLATE_DOCUMENT_SLUG_RE.test(d.slug)
|
|
2669
|
+
) {
|
|
2259
2670
|
add(
|
|
2260
2671
|
"document-slug-invalid",
|
|
2261
2672
|
`${where}.slug`,
|