@contractspec/lib.contracts 1.44.0 → 1.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +1 -1
  2. package/dist/app-config/app-config.feature.js +6 -6
  3. package/dist/app-config/contracts.d.ts +50 -50
  4. package/dist/app-config/contracts.js +13 -13
  5. package/dist/app-config/events.d.ts +27 -27
  6. package/dist/app-config/events.js +12 -12
  7. package/dist/app-config/lifecycle-contracts.d.ts +54 -54
  8. package/dist/app-config/lifecycle-contracts.js +19 -19
  9. package/dist/app-config/lifecycle.d.ts +2 -2
  10. package/dist/app-config/runtime.d.ts +3 -3
  11. package/dist/app-config/spec.d.ts +10 -12
  12. package/dist/app-config/spec.js +5 -26
  13. package/dist/capabilities/capabilities.d.ts +4 -11
  14. package/dist/capabilities/capabilities.js +3 -5
  15. package/dist/capabilities/openbanking.js +10 -10
  16. package/dist/client/react/form-render.js +1 -0
  17. package/dist/contract-registry/schemas.d.ts +8 -8
  18. package/dist/contract-registry/schemas.js +1 -1
  19. package/dist/contract-registry/types.d.ts +1 -1
  20. package/dist/data-views/data-views.js +1 -0
  21. package/dist/data-views/registry.d.ts +3 -37
  22. package/dist/data-views/registry.js +4 -66
  23. package/dist/data-views/runtime.d.ts +1 -1
  24. package/dist/data-views/runtime.js +2 -0
  25. package/dist/data-views/spec.d.ts +2 -2
  26. package/dist/docs/index.d.ts +2 -2
  27. package/dist/docs/index.js +2 -2
  28. package/dist/docs/presentations.d.ts +2 -4
  29. package/dist/docs/presentations.js +2 -4
  30. package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +1 -1
  31. package/dist/docs/tech/contracts/tests.docblock.js +1 -1
  32. package/dist/docs/tech/lifecycle-stage-system.docblock.js +1 -1
  33. package/dist/docs/tech-contracts.docs.js +1 -1
  34. package/dist/docs/types.d.ts +1 -1
  35. package/dist/events.d.ts +3 -3
  36. package/dist/examples/docs/examples.docblock.d.ts +6 -0
  37. package/dist/examples/docs/examples.docblock.js +165 -0
  38. package/dist/examples/index.d.ts +5 -0
  39. package/dist/examples/index.js +6 -0
  40. package/dist/examples/registry.d.ts +65 -0
  41. package/dist/examples/registry.js +144 -0
  42. package/dist/examples/schema.d.ts +282 -0
  43. package/dist/examples/schema.js +125 -0
  44. package/dist/examples/types.d.ts +167 -0
  45. package/dist/examples/types.js +43 -0
  46. package/dist/examples/validation.d.ts +65 -0
  47. package/dist/examples/validation.js +144 -0
  48. package/dist/experiments/docs/experiments.docblock.js +1 -1
  49. package/dist/experiments/evaluator.d.ts +1 -1
  50. package/dist/experiments/spec-resolver.d.ts +2 -2
  51. package/dist/experiments/spec.d.ts +6 -8
  52. package/dist/experiments/spec.js +5 -23
  53. package/dist/features/index.d.ts +9 -1
  54. package/dist/features/index.js +8 -1
  55. package/dist/features/install.js +2 -2
  56. package/dist/features/types.d.ts +7 -7
  57. package/dist/forms/forms.d.ts +2 -2
  58. package/dist/forms/forms.js +3 -6
  59. package/dist/index.d.ts +13 -8
  60. package/dist/index.js +11 -2
  61. package/dist/install.d.ts +9 -9
  62. package/dist/integrations/connection.d.ts +1 -1
  63. package/dist/integrations/docs/integrations.docblock.js +1 -1
  64. package/dist/integrations/integrations.feature.js +8 -8
  65. package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
  66. package/dist/integrations/openbanking/contracts/accounts.js +3 -3
  67. package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
  68. package/dist/integrations/openbanking/contracts/balances.js +2 -2
  69. package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
  70. package/dist/integrations/openbanking/contracts/transactions.js +2 -2
  71. package/dist/integrations/openbanking/models.d.ts +55 -55
  72. package/dist/integrations/openbanking/openbanking.feature.js +10 -10
  73. package/dist/integrations/operations.d.ts +102 -102
  74. package/dist/integrations/operations.js +10 -10
  75. package/dist/integrations/providers/elevenlabs.js +2 -2
  76. package/dist/integrations/providers/gcs-storage.js +2 -2
  77. package/dist/integrations/providers/gmail.js +3 -3
  78. package/dist/integrations/providers/google-calendar.js +2 -2
  79. package/dist/integrations/providers/mistral.js +3 -3
  80. package/dist/integrations/providers/postmark.js +2 -2
  81. package/dist/integrations/providers/powens.js +4 -4
  82. package/dist/integrations/providers/qdrant.js +3 -3
  83. package/dist/integrations/providers/stripe.js +2 -2
  84. package/dist/integrations/providers/twilio-sms.js +2 -2
  85. package/dist/integrations/runtime.d.ts +5 -5
  86. package/dist/integrations/spec.d.ts +3 -5
  87. package/dist/integrations/spec.js +5 -26
  88. package/dist/jobs/gcp-cloud-tasks.js +1 -1
  89. package/dist/jobs/gcp-pubsub.js +1 -1
  90. package/dist/jobs/handlers/ping-handler.d.ts +3 -3
  91. package/dist/jobs/handlers/ping-handler.js +2 -2
  92. package/dist/jobs/memory-queue.js +1 -1
  93. package/dist/jobs/queue.d.ts +4 -4
  94. package/dist/jobs/scaleway-sqs-queue.js +2 -2
  95. package/dist/jsonschema.d.ts +4 -4
  96. package/dist/knowledge/binding.d.ts +1 -1
  97. package/dist/knowledge/knowledge.feature.js +8 -8
  98. package/dist/knowledge/operations.d.ts +66 -66
  99. package/dist/knowledge/operations.js +12 -12
  100. package/dist/knowledge/source.d.ts +1 -1
  101. package/dist/knowledge/spaces/email-threads.js +2 -2
  102. package/dist/knowledge/spaces/financial-docs.js +2 -2
  103. package/dist/knowledge/spaces/financial-overview.js +2 -2
  104. package/dist/knowledge/spaces/product-canon.js +2 -2
  105. package/dist/knowledge/spaces/support-faq.js +2 -2
  106. package/dist/knowledge/spaces/uploaded-docs.js +2 -2
  107. package/dist/knowledge/spec.d.ts +3 -5
  108. package/dist/knowledge/spec.js +6 -28
  109. package/dist/llm/exporters.js +2 -2
  110. package/dist/llm/types.d.ts +4 -4
  111. package/dist/markdown.js +1 -1
  112. package/dist/migrations.d.ts +2 -2
  113. package/dist/migrations.js +7 -9
  114. package/dist/onboarding-base.d.ts +29 -29
  115. package/dist/onboarding-base.js +4 -4
  116. package/dist/openapi.js +9 -2
  117. package/dist/operations/operation.d.ts +3 -3
  118. package/dist/operations/registry.d.ts +9 -58
  119. package/dist/operations/registry.js +17 -93
  120. package/dist/ownership.d.ts +1 -1
  121. package/dist/policy/docs/policy.docblock.js +1 -1
  122. package/dist/policy/engine.js +2 -0
  123. package/dist/policy/spec.d.ts +1 -1
  124. package/dist/prompt.d.ts +6 -6
  125. package/dist/promptRegistry.d.ts +4 -4
  126. package/dist/promptRegistry.js +2 -5
  127. package/dist/regenerator/docs/regenerator.docblock.js +1 -1
  128. package/dist/regenerator/types.d.ts +1 -1
  129. package/dist/registry.d.ts +3 -2
  130. package/dist/registry.js +5 -5
  131. package/dist/resources.d.ts +5 -5
  132. package/dist/server/graphql-pothos.js +2 -2
  133. package/dist/server/mcp/registerTools.js +1 -1
  134. package/dist/server/rest-elysia.d.ts +1 -1
  135. package/dist/server/rest-elysia.js +1 -1
  136. package/dist/server/rest-express.d.ts +1 -1
  137. package/dist/server/rest-express.js +1 -1
  138. package/dist/server/rest-generic.d.ts +1 -1
  139. package/dist/server/rest-generic.js +1 -1
  140. package/dist/server/rest-next-app.d.ts +1 -1
  141. package/dist/server/rest-next-mcp.d.ts +1 -1
  142. package/dist/server/rest-next-mcp.js +1 -1
  143. package/dist/server/rest-next-pages.d.ts +1 -1
  144. package/dist/telemetry/docs/telemetry.docblock.js +1 -1
  145. package/dist/telemetry/spec.d.ts +7 -7
  146. package/dist/telemetry/spec.js +17 -44
  147. package/dist/telemetry/tracker.d.ts +2 -2
  148. package/dist/tests/runner.d.ts +1 -1
  149. package/dist/tests/spec.d.ts +5 -5
  150. package/dist/tests/spec.js +3 -5
  151. package/dist/themes.d.ts +4 -6
  152. package/dist/themes.js +5 -27
  153. package/dist/translations/catalog.d.ts +1 -1
  154. package/dist/types.d.ts +5 -5
  155. package/dist/workflow/adapters/db-adapter.js +3 -3
  156. package/dist/workflow/runner.d.ts +4 -2
  157. package/dist/workflow/spec.d.ts +4 -17
  158. package/dist/workflow/spec.js +4 -48
  159. package/dist/workflow/state.d.ts +1 -1
  160. package/dist/workflow/validation.js +1 -1
  161. package/dist/workspace-config/contractsrc-schema.d.ts +419 -419
  162. package/dist/workspace-config/contractsrc-schema.js +86 -86
  163. package/package.json +28 -12
@@ -1,31 +1,10 @@
1
+ import { SpecContractRegistry } from "../registry.js";
2
+
1
3
  //#region src/app-config/spec.ts
2
4
  const blueprintKey = (meta) => `${meta.key}.v${meta.version}`;
3
- var AppBlueprintRegistry = class {
4
- items = /* @__PURE__ */ new Map();
5
- register(spec) {
6
- const key = blueprintKey(spec.meta);
7
- if (this.items.has(key)) throw new Error(`Duplicate AppBlueprint ${key}`);
8
- this.items.set(key, spec);
9
- return this;
10
- }
11
- list() {
12
- return [...this.items.values()];
13
- }
14
- get(key, version) {
15
- if (version != null) return this.items.get(blueprintKey({
16
- key,
17
- version
18
- }));
19
- let latest;
20
- let maxVersion = -Infinity;
21
- for (const spec of this.items.values()) {
22
- if (spec.meta.key !== key) continue;
23
- if (spec.meta.version > maxVersion) {
24
- maxVersion = spec.meta.version;
25
- latest = spec;
26
- }
27
- }
28
- return latest;
5
+ var AppBlueprintRegistry = class extends SpecContractRegistry {
6
+ constructor(items) {
7
+ super("app-config", items);
29
8
  }
30
9
  };
31
10
  function makeAppBlueprintKey(meta) {
@@ -1,4 +1,3 @@
1
- import { DocId } from "../docs/registry.js";
2
1
  import { OwnerShipMeta } from "../ownership.js";
3
2
 
4
3
  //#region src/capabilities/capabilities.d.ts
@@ -7,28 +6,22 @@ type CapabilitySurface = 'operation' | 'event' | 'workflow' | 'presentation' | '
7
6
  interface CapabilitySurfaceRef {
8
7
  surface: CapabilitySurface;
9
8
  key: string;
10
- version: number;
9
+ version: string;
11
10
  description?: string;
12
11
  }
13
12
  interface CapabilityMeta extends OwnerShipMeta {
14
- /** Stable capability slug (e.g., "payments.stripe"). */
15
- key: string;
16
- /** Increment when the capability shape changes. */
17
- version: number;
18
13
  kind: CapabilityKind;
19
- /** Optional doc block id for governance and navigation. */
20
- docId?: DocId[];
21
14
  }
22
15
  interface CapabilityRequirement {
23
16
  key: string;
24
- version?: number;
17
+ version?: string;
25
18
  kind?: CapabilityKind;
26
19
  optional?: boolean;
27
20
  reason?: string;
28
21
  }
29
22
  interface CapabilityRef {
30
23
  key: string;
31
- version: number;
24
+ version: string;
32
25
  }
33
26
  interface CapabilitySpec {
34
27
  meta: CapabilityMeta;
@@ -39,7 +32,7 @@ declare class CapabilityRegistry {
39
32
  private readonly items;
40
33
  register(spec: CapabilitySpec): this;
41
34
  list(): CapabilitySpec[];
42
- get(key: string, version?: number): CapabilitySpec | undefined;
35
+ get(key: string, version?: string): CapabilitySpec | undefined;
43
36
  satisfies(requirement: CapabilityRequirement, additional?: CapabilityRef[] | undefined): boolean;
44
37
  }
45
38
  declare function capabilityKey(spec: CapabilitySpec): string;
@@ -1,3 +1,5 @@
1
+ import { compareVersions } from "compare-versions";
2
+
1
3
  //#region src/capabilities/capabilities.ts
2
4
  const capKey = (key, version) => `${key}.v${version}`;
3
5
  var CapabilityRegistry = class {
@@ -14,13 +16,9 @@ var CapabilityRegistry = class {
14
16
  get(key, version) {
15
17
  if (version != null) return this.items.get(capKey(key, version));
16
18
  let candidate;
17
- let max = -Infinity;
18
19
  for (const spec of this.items.values()) {
19
20
  if (spec.meta.key !== key) continue;
20
- if (spec.meta.version > max) {
21
- max = spec.meta.version;
22
- candidate = spec;
23
- }
21
+ if (!candidate || compareVersions(spec.meta.version, candidate.meta.version) > 0) candidate = spec;
24
22
  }
25
23
  return candidate;
26
24
  }
@@ -6,7 +6,7 @@ const TAGS = ["open-banking", "finance"];
6
6
  const openBankingAccountsReadCapability = {
7
7
  meta: {
8
8
  key: "openbanking.accounts.read",
9
- version: 1,
9
+ version: "1.0.0",
10
10
  kind: "integration",
11
11
  title: "Open Banking Accounts (Read)",
12
12
  description: "Provides read-only access to linked bank accounts, including account summaries and metadata.",
@@ -19,19 +19,19 @@ const openBankingAccountsReadCapability = {
19
19
  {
20
20
  surface: "operation",
21
21
  key: "openbanking.accounts.list",
22
- version: 1,
22
+ version: "1.0.0",
23
23
  description: "List bank accounts linked to a Powens open banking connection."
24
24
  },
25
25
  {
26
26
  surface: "operation",
27
27
  key: "openbanking.accounts.get",
28
- version: 1,
28
+ version: "1.0.0",
29
29
  description: "Retrieve the canonical bank account record for a specific account."
30
30
  },
31
31
  {
32
32
  surface: "operation",
33
33
  key: "openbanking.accounts.sync",
34
- version: 1,
34
+ version: "1.0.0",
35
35
  description: "Trigger a refresh of bank account metadata from the open banking provider."
36
36
  }
37
37
  ]
@@ -39,7 +39,7 @@ const openBankingAccountsReadCapability = {
39
39
  const openBankingTransactionsReadCapability = {
40
40
  meta: {
41
41
  key: "openbanking.transactions.read",
42
- version: 1,
42
+ version: "1.0.0",
43
43
  kind: "integration",
44
44
  title: "Open Banking Transactions (Read)",
45
45
  description: "Enables retrieval of transaction history for linked bank accounts via open banking providers.",
@@ -51,19 +51,19 @@ const openBankingTransactionsReadCapability = {
51
51
  provides: [{
52
52
  surface: "operation",
53
53
  key: "openbanking.transactions.list",
54
- version: 1,
54
+ version: "1.0.0",
55
55
  description: "List transactions for a given bank account with optional date filtering."
56
56
  }, {
57
57
  surface: "operation",
58
58
  key: "openbanking.transactions.sync",
59
- version: 1,
59
+ version: "1.0.0",
60
60
  description: "Synchronise transactions from the open banking provider into the canonical ledger."
61
61
  }]
62
62
  };
63
63
  const openBankingBalancesReadCapability = {
64
64
  meta: {
65
65
  key: "openbanking.balances.read",
66
- version: 1,
66
+ version: "1.0.0",
67
67
  kind: "integration",
68
68
  title: "Open Banking Balances (Read)",
69
69
  description: "Allows querying of current and available balances for linked bank accounts via open banking providers.",
@@ -75,12 +75,12 @@ const openBankingBalancesReadCapability = {
75
75
  provides: [{
76
76
  surface: "operation",
77
77
  key: "openbanking.balances.get",
78
- version: 1,
78
+ version: "1.0.0",
79
79
  description: "Retrieve the latest known balances for a specified bank account."
80
80
  }, {
81
81
  surface: "operation",
82
82
  key: "openbanking.balances.refresh",
83
- version: 1,
83
+ version: "1.0.0",
84
84
  description: "Force a balance refresh from the open banking provider."
85
85
  }]
86
86
  };
@@ -1,4 +1,5 @@
1
1
  import { buildZodWithRelations, evalPredicate } from "../../forms/forms.js";
2
+ import "../../forms/index.js";
2
3
  import React, { useEffect, useMemo, useState } from "react";
3
4
  import { Controller, useFieldArray, useForm } from "react-hook-form";
4
5
  import { zodResolver } from "@hookform/resolvers/zod";
@@ -41,17 +41,17 @@ declare const ContractRegistryItemSchema: z.ZodObject<{
41
41
  "contractspec:app-config": "contractspec:app-config";
42
42
  "contractspec:knowledge": "contractspec:knowledge";
43
43
  }>;
44
- version: z.ZodNumber;
44
+ version: z.ZodString;
45
45
  title: z.ZodString;
46
46
  description: z.ZodString;
47
47
  meta: z.ZodObject<{
48
48
  stability: z.ZodEnum<{
49
- experimental: "experimental";
50
- beta: "beta";
51
- stable: "stable";
52
49
  deprecated: "deprecated";
53
50
  idea: "idea";
54
51
  in_creation: "in_creation";
52
+ experimental: "experimental";
53
+ beta: "beta";
54
+ stable: "stable";
55
55
  }>;
56
56
  owners: z.ZodDefault<z.ZodArray<z.ZodString>>;
57
57
  tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
@@ -90,17 +90,17 @@ declare const ContractRegistryManifestSchema: z.ZodObject<{
90
90
  "contractspec:app-config": "contractspec:app-config";
91
91
  "contractspec:knowledge": "contractspec:knowledge";
92
92
  }>;
93
- version: z.ZodNumber;
93
+ version: z.ZodString;
94
94
  title: z.ZodString;
95
95
  description: z.ZodString;
96
96
  meta: z.ZodObject<{
97
97
  stability: z.ZodEnum<{
98
- experimental: "experimental";
99
- beta: "beta";
100
- stable: "stable";
101
98
  deprecated: "deprecated";
102
99
  idea: "idea";
103
100
  in_creation: "in_creation";
101
+ experimental: "experimental";
102
+ beta: "beta";
103
+ stable: "stable";
104
104
  }>;
105
105
  owners: z.ZodDefault<z.ZodArray<z.ZodString>>;
106
106
  tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
@@ -27,7 +27,7 @@ const ContractRegistryFileSchema = z.object({
27
27
  const ContractRegistryItemSchema = z.object({
28
28
  key: z.string().min(1),
29
29
  type: ContractRegistryItemTypeSchema,
30
- version: z.number().int().nonnegative(),
30
+ version: z.string(),
31
31
  title: z.string().min(1),
32
32
  description: z.string().min(1),
33
33
  meta: z.object({
@@ -19,7 +19,7 @@ interface ContractRegistryFile {
19
19
  interface ContractRegistryItem {
20
20
  key: string;
21
21
  type: ContractRegistryItemType;
22
- version: number;
22
+ version: string;
23
23
  title: string;
24
24
  description: string;
25
25
  meta: {
@@ -1,4 +1,5 @@
1
1
  import { defineDataView } from "./spec.js";
2
2
  import { DataViewRegistry, dataViewKey } from "./registry.js";
3
+ import "./index.js";
3
4
 
4
5
  export { DataViewRegistry, dataViewKey, defineDataView };
@@ -1,5 +1,5 @@
1
- import { GroupKeyFn, RegistryFilter } from "../registry-utils.js";
2
1
  import { DataViewSpec } from "./spec.js";
2
+ import { SpecContractRegistry } from "../registry.js";
3
3
 
4
4
  //#region src/data-views/registry.d.ts
5
5
 
@@ -10,42 +10,8 @@ declare function dataViewKey(spec: DataViewSpec): string;
10
10
  /**
11
11
  * Registry for managing data view specifications.
12
12
  */
13
- declare class DataViewRegistry {
14
- private readonly items;
15
- /**
16
- * Register a data view spec.
17
- * @throws Error if a spec with the same key already exists.
18
- */
19
- register(spec: DataViewSpec): this;
20
- /**
21
- * List all registered data view specs.
22
- */
23
- list(): DataViewSpec[];
24
- /**
25
- * Get a data view by key and optional version.
26
- * If version is not specified, returns the latest version.
27
- */
28
- get(name: string, version?: number): DataViewSpec | undefined;
29
- /**
30
- * Filter data views by criteria.
31
- */
32
- filter(criteria: RegistryFilter): DataViewSpec[];
33
- /**
34
- * List data views with specific tag.
35
- */
36
- listByTag(tag: string): DataViewSpec[];
37
- /**
38
- * List data views by owner.
39
- */
40
- listByOwner(owner: string): DataViewSpec[];
41
- /**
42
- * Group data views by key function.
43
- */
44
- groupBy(keyFn: GroupKeyFn<DataViewSpec>): Map<string, DataViewSpec[]>;
45
- /**
46
- * Get unique tags from all data views.
47
- */
48
- getUniqueTags(): string[];
13
+ declare class DataViewRegistry extends SpecContractRegistry<'data-view', DataViewSpec> {
14
+ constructor(items?: DataViewSpec[]);
49
15
  }
50
16
  //#endregion
51
17
  export { DataViewRegistry, dataViewKey };
@@ -1,7 +1,6 @@
1
- import { filterBy, getUniqueTags, groupBy, init_registry_utils } from "../registry-utils.js";
1
+ import { SpecContractRegistry } from "../registry.js";
2
2
 
3
3
  //#region src/data-views/registry.ts
4
- init_registry_utils();
5
4
  /**
6
5
  * Generate a unique key for a data view spec.
7
6
  */
@@ -11,70 +10,9 @@ function dataViewKey(spec) {
11
10
  /**
12
11
  * Registry for managing data view specifications.
13
12
  */
14
- var DataViewRegistry = class {
15
- items = /* @__PURE__ */ new Map();
16
- /**
17
- * Register a data view spec.
18
- * @throws Error if a spec with the same key already exists.
19
- */
20
- register(spec) {
21
- const key = dataViewKey(spec);
22
- if (this.items.has(key)) throw new Error(`Duplicate data view ${key}`);
23
- this.items.set(key, spec);
24
- return this;
25
- }
26
- /**
27
- * List all registered data view specs.
28
- */
29
- list() {
30
- return [...this.items.values()];
31
- }
32
- /**
33
- * Get a data view by key and optional version.
34
- * If version is not specified, returns the latest version.
35
- */
36
- get(name, version) {
37
- if (version != null) return this.items.get(`${name}.v${version}`);
38
- let candidate;
39
- let max = -Infinity;
40
- for (const spec of this.items.values()) {
41
- if (spec.meta.key !== name) continue;
42
- if (spec.meta.version > max) {
43
- max = spec.meta.version;
44
- candidate = spec;
45
- }
46
- }
47
- return candidate;
48
- }
49
- /**
50
- * Filter data views by criteria.
51
- */
52
- filter(criteria) {
53
- return filterBy(this.list(), criteria);
54
- }
55
- /**
56
- * List data views with specific tag.
57
- */
58
- listByTag(tag) {
59
- return this.list().filter((d) => d.meta.tags?.includes(tag));
60
- }
61
- /**
62
- * List data views by owner.
63
- */
64
- listByOwner(owner) {
65
- return this.list().filter((d) => d.meta.owners?.includes(owner));
66
- }
67
- /**
68
- * Group data views by key function.
69
- */
70
- groupBy(keyFn) {
71
- return groupBy(this.list(), keyFn);
72
- }
73
- /**
74
- * Get unique tags from all data views.
75
- */
76
- getUniqueTags() {
77
- return getUniqueTags(this.list());
13
+ var DataViewRegistry = class extends SpecContractRegistry {
14
+ constructor(items) {
15
+ super("data-view", items);
78
16
  }
79
17
  };
80
18
 
@@ -18,7 +18,7 @@ declare class DataViewRuntime {
18
18
  private subscriptions;
19
19
  constructor(config: DataViewRuntimeConfig);
20
20
  register(spec: DataViewSpec): void;
21
- getSpec(name: string, version?: number): DataViewSpec | undefined;
21
+ getSpec(name: string, version?: string): DataViewSpec | undefined;
22
22
  executeQuery(specName: string, _params: unknown): Promise<DataViewResult>;
23
23
  invalidate(specName: string): void;
24
24
  subscribe(specName: string, callback: () => void): () => void;
@@ -1,3 +1,5 @@
1
+ import "./index.js";
2
+
1
3
  //#region src/data-views/runtime.ts
2
4
  var DataViewRuntime = class {
3
5
  cache = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import { ExperimentRef } from "../experiments/spec.js";
2
1
  import { DataViewConfig, DataViewMeta, DataViewSource, DataViewStates } from "./types.js";
2
+ import { ExperimentRef } from "../experiments/spec.js";
3
3
 
4
4
  //#region src/data-views/spec.d.ts
5
5
 
@@ -22,7 +22,7 @@ interface DataViewSpec {
22
22
  */
23
23
  interface DataViewRef {
24
24
  key: string;
25
- version: number;
25
+ version: string;
26
26
  }
27
27
  /**
28
28
  * Helper to define a data view spec with type safety.
@@ -1,6 +1,6 @@
1
1
  import { DocBlock, DocBlockLink, DocKind, DocVisibility } from "./types.js";
2
- import { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
2
+ import { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
3
3
  import { DocId, DocRegistry, defaultDocRegistry, docId, listRegisteredDocBlocks, registerDocBlocks } from "./registry.js";
4
4
  import { techContractsDocs } from "./tech-contracts.docs.js";
5
5
  import { metaDocs } from "./meta.docs.js";
6
- export { DocBlock, DocBlockLink, DocId, DocKind, DocPresentationOptions, DocPresentationRoute, DocRegistry, DocVisibility, defaultDocRegistry, docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
6
+ export { DocBlock, DocBlockLink, DocId, DocKind, DocPresentationOptions, DocPresentationRoute, DocRegistry, DocVisibility, defaultDocRegistry, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
@@ -1,4 +1,4 @@
1
- import { docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
1
+ import { docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
2
2
  import { DocRegistry, defaultDocRegistry, docId, listRegisteredDocBlocks, registerDocBlocks } from "./registry.js";
3
3
  import { techContractsDocs } from "./tech-contracts.docs.js";
4
4
  import { metaDocs } from "./meta.docs.js";
@@ -26,4 +26,4 @@ import "./tech/studio/project-access-teams.docblock.js";
26
26
  import "./tech/studio/team-invitations.docblock.js";
27
27
  import "./tech/llm/llm-integration.docblock.js";
28
28
 
29
- export { DocRegistry, defaultDocRegistry, docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
29
+ export { DocRegistry, defaultDocRegistry, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
@@ -14,7 +14,7 @@ interface DocPresentationOptions {
14
14
  /** Default presentation targets. */
15
15
  defaultTargets?: PresentationTarget[];
16
16
  /** Default version when block.version is not set. */
17
- defaultVersion?: number;
17
+ defaultVersion?: string;
18
18
  /** Default stability if not provided on the DocBlock. */
19
19
  defaultStability?: Stability;
20
20
  }
@@ -24,10 +24,8 @@ interface DocPresentationRoute {
24
24
  block: DocBlock;
25
25
  }
26
26
  declare function docBlockToPresentationSpec(block: DocBlock, options?: DocPresentationOptions): PresentationSpec;
27
- /** @deprecated Use docBlockToPresentationSpec instead */
28
- declare const docBlockToPresentationV2: typeof docBlockToPresentationSpec;
29
27
  declare function docBlocksToPresentationRoutes(blocks: DocBlock[], options?: DocPresentationOptions): DocPresentationRoute[];
30
28
  declare function docBlocksToPresentationSpecs(blocks: DocBlock[], options?: DocPresentationOptions): PresentationSpec[];
31
29
  declare function mapDocRoutes(routes: DocPresentationRoute[]): [string, PresentationSpec][];
32
30
  //#endregion
33
- export { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
31
+ export { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
@@ -21,7 +21,7 @@ function buildName(block, namespace) {
21
21
  }
22
22
  function docBlockToPresentationSpec(block, options) {
23
23
  const targets = options?.defaultTargets ?? DEFAULT_TARGETS;
24
- const version = block.version ?? options?.defaultVersion ?? 1;
24
+ const version = block.version ?? options?.defaultVersion ?? "1.0.0";
25
25
  const stability = block.stability ?? options?.defaultStability ?? "stable";
26
26
  return {
27
27
  meta: {
@@ -44,8 +44,6 @@ function docBlockToPresentationSpec(block, options) {
44
44
  targets
45
45
  };
46
46
  }
47
- /** @deprecated Use docBlockToPresentationSpec instead */
48
- const docBlockToPresentationV2 = docBlockToPresentationSpec;
49
47
  function docBlocksToPresentationRoutes(blocks, options) {
50
48
  return blocks.map((block) => ({
51
49
  block,
@@ -61,4 +59,4 @@ function mapDocRoutes(routes) {
61
59
  }
62
60
 
63
61
  //#endregion
64
- export { docBlockToPresentationSpec, docBlockToPresentationV2, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
62
+ export { docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
@@ -13,7 +13,7 @@ const tech_contracts_ops_to_presentation_linking_DocBlocks = [{
13
13
  "contracts",
14
14
  "ops-to-presentation-linking"
15
15
  ],
16
- body: "### Ops ↔ Presentation linking (V2)\n\nThis document explains how operations (OperationSpec) are linked to Presentations (PresentationSpec) via Feature modules.\n\n- Location: `@contractspec/lib.contracts/src/features.ts`\n- Field: `FeatureModuleSpec.opToPresentation?: { op: { name; version }; pres: { name; version } }[]`\n- Validation: `installFeature()` validates that linked ops exist in `OperationSpecRegistry` and linked presentations exist in the registry, and that declared targets are present.\n\nExample:\n\n```ts\nimport type { OperationSpecRegistry } from '@contractspec/lib.contracts/src/registry';\nimport { FeatureRegistry, createFeatureModule } from '@contractspec/lib.contracts';\n\nexport function buildFeaturesWithOps(ops: OperationSpecRegistry) {\n const features = new FeatureRegistry();\n features.register(\n createFeatureModule(\n {\n key: 'myapp.widgets.linkage',\n title: 'Widgets (linked)',\n description: 'Links create/update ops to UI presentations',\n domain: 'widgets',\n tags: ['widgets', 'linkage'],\n stability: 'beta',\n },\n {\n operations: [\n { name: 'widgets.create', version: 1 },\n { name: 'widgets.update', version: 1 },\n ],\n presentations: [{ name: 'myapp.widgets.editor.page', version: 1 }],\n opToPresentation: [\n {\n op: { name: 'widgets.create', version: 1 },\n pres: { name: 'myapp.widgets.editor.page', version: 1 },\n },\n {\n op: { name: 'widgets.update', version: 1 },\n pres: { name: 'myapp.widgets.editor.page', version: 1 },\n },\n ],\n presentationsTargets: [\n {\n name: 'myapp.widgets.editor.page',\n version: 1,\n targets: ['react', 'markdown'],\n },\n ],\n }\n )\n );\n return { features };\n}\n```\n\nNotes\n\n- This enables traceability: the UI flow that realizes an op is discoverable via the feature catalog.\n- Presentations can target multiple outputs (`react`, `markdown`, `application/json`, `application/xml`).\n- Use `renderFeaturePresentation()` to render a descriptor to a given target with a component map.\n"
16
+ body: "### Ops ↔ Presentation linking (V2)\n\nThis document explains how operations (OperationSpec) are linked to Presentations (PresentationSpec) via Feature modules.\n\n- Location: `@contractspec/lib.contracts/src/features.ts`\n- Field: `FeatureModuleSpec.opToPresentation?: { op: { name; version }; pres: { name; version } }[]`\n- Validation: `installFeature()` validates that linked ops exist in `OperationSpecRegistry` and linked presentations exist in the registry, and that declared targets are present.\n\nExample:\n\n```ts\nimport type { OperationSpecRegistry } from '@contractspec/lib.contracts/src/registry';\nimport { FeatureRegistry, createFeatureModule } from '@contractspec/lib.contracts';\n\nexport function buildFeaturesWithOps(ops: OperationSpecRegistry) {\n const features = new FeatureRegistry();\n features.register(\n createFeatureModule(\n {\n key: 'myapp.widgets.linkage',\n title: 'Widgets (linked)',\n description: 'Links create/update ops to UI presentations',\n domain: 'widgets',\n tags: ['widgets', 'linkage'],\n stability: 'beta',\n },\n {\n operations: [\n { name: 'widgets.create', version: '1.0.0' },\n { name: 'widgets.update', version: '1.0.0' },\n ],\n presentations: [{ name: 'myapp.widgets.editor.page', version: '1.0.0' }],\n opToPresentation: [\n {\n op: { name: 'widgets.create', version: '1.0.0' },\n pres: { name: 'myapp.widgets.editor.page', version: '1.0.0' },\n },\n {\n op: { name: 'widgets.update', version: '1.0.0' },\n pres: { name: 'myapp.widgets.editor.page', version: '1.0.0' },\n },\n ],\n presentationsTargets: [\n {\n name: 'myapp.widgets.editor.page',\n version: '1.0.0',\n targets: ['react', 'markdown'],\n },\n ],\n }\n )\n );\n return { features };\n}\n```\n\nNotes\n\n- This enables traceability: the UI flow that realizes an op is discoverable via the feature catalog.\n- Presentations can target multiple outputs (`react`, `markdown`, `application/json`, `application/xml`).\n- Use `renderFeaturePresentation()` to render a descriptor to a given target with a component map.\n"
17
17
  }];
18
18
  registerDocBlocks(tech_contracts_ops_to_presentation_linking_DocBlocks);
19
19
 
@@ -13,7 +13,7 @@ const tech_contracts_tests_DocBlocks = [{
13
13
  "contracts",
14
14
  "tests"
15
15
  ],
16
- body: "## TestSpec & TestRunner\n\nUse `TestSpec` to describe end-to-end scenarios for contracts and workflows. Specs live alongside your contracts and exercise the same OperationSpecRegistry handlers the app uses.\n\n- Types & registry: `packages/libs/contracts/src/tests/spec.ts`\n- Runtime runner: `packages/libs/contracts/src/tests/runner.ts`\n- CLI: `contractspec test`\n\n### Structure\n\n```ts\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget; // contract or workflow\n fixtures?: Fixture[]; // optional shared setup before each scenario\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n```\n\n- `Fixture`: run an operation before the scenario (`operation`, optional `input`)\n- `Action`: operation input that the scenario exercises\n- `Assertion`:\n - `expectOutput` `{ match }` deep-equals the handler output\n - `expectError` `{ messageIncludes? }` ensures an error was thrown\n - `expectEvents` `{ events: [{ name, version, min?, max? }] }` checks emitted events\n\n### Example\n\n```ts\nimport { defineCommand, type TestSpec } from '@contractspec/lib.contracts';\n\nexport const AddNumbersSpec = defineCommand({\n meta: { name: 'math.add', version: 1, /* … */ },\n io: {\n input: AddNumbersInput,\n output: AddNumbersOutput,\n },\n policy: { auth: 'user' },\n});\n\nexport const MathAddTests: TestSpec = {\n meta: {\n name: 'math.add.tests',\n version: 1,\n title: 'Math add scenarios',\n owners: ['@team.math'],\n tags: ['math'],\n stability: StabilityEnum.Experimental,\n },\n target: { type: 'contract', operation: { name: 'math.add' } },\n scenarios: [\n {\n name: 'adds positive numbers',\n when: {\n operation: { name: 'math.add' },\n input: { a: 2, b: 3 },\n },\n then: [\n { type: 'expectOutput', match: { sum: 5 } },\n {\n type: 'expectEvents',\n events: [{ name: 'math.sum_calculated', version: 1, min: 1 }],\n },\n ],\n },\n ],\n};\n```\n\n### Running tests\n\n1. Register the contract handlers in a `OperationSpecRegistry`:\n\n```ts\nexport function createRegistry() {\n const registry = new OperationSpecRegistry();\n registry.register(AddNumbersSpec);\n registry.bind(AddNumbersSpec, addNumbersHandler);\n return registry;\n}\n```\n\n2. Run the CLI:\n\n```\ncontractspec test apps/math/tests/math.add.tests.ts \\\n --registry apps/math/tests/registry.ts\n```\n\n- The CLI loads the TestSpec, instantiates the registry (via the provided module), and executes each scenario via `TestRunner`.\n- `--json` outputs machine-readable results.\n\n### Programmatic usage\n\n```ts\nconst runner = new TestRunner({\n registry,\n createContext: () => ({ actor: 'user', organizationId: 'tenant-1' }),\n});\n\nconst result = await runner.run(MathAddTests);\nconsole.log(result.passed, result.failed);\n```\n\n- `createContext` can supply default `HandlerCtx` values.\n- `beforeEach` / `afterEach` hooks let you seed databases or reset state.\n\n### Best practices\n\n- Keep fixtures idempotent so scenarios can run in parallel in the future.\n- Use `expectEvents` to guard analytics/telemetry expectations.\n- Add specs to `TestRegistry` for discovery and documentation.\n- `coverage` captures desired coverage metrics (enforced by future tooling).\n- Pair TestSpec files with CI using `contractspec test --json` and fail builds when `failed > 0`.\n\n### Mocking with Bun's `vi`\n\n- Pass a single function type to `vi.fn<TFunction>()` so calls retain typed arguments:\n\n```ts\nconst handler = vi.fn<typeof fetch>();\nconst fetchImpl: typeof fetch = ((...args) => handler(...args)) as typeof fetch;\nObject.defineProperty(fetchImpl, 'preconnect', {\n value: vi.fn<typeof fetch.preconnect>(),\n});\n```\n\n- When you need to inspect calls, use the typed mock (`handler.mock.calls`) rather than casting to `any`.\n- Narrow optional request data defensively (e.g., check for headers before reading them) so tests remain type-safe under strict `tsconfig` settings.\n\n"
16
+ body: "## TestSpec & TestRunner\n\nUse `TestSpec` to describe end-to-end scenarios for contracts and workflows. Specs live alongside your contracts and exercise the same OperationSpecRegistry handlers the app uses.\n\n- Types & registry: `packages/libs/contracts/src/tests/spec.ts`\n- Runtime runner: `packages/libs/contracts/src/tests/runner.ts`\n- CLI: `contractspec test`\n\n### Structure\n\n```ts\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget; // contract or workflow\n fixtures?: Fixture[]; // optional shared setup before each scenario\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n```\n\n- `Fixture`: run an operation before the scenario (`operation`, optional `input`)\n- `Action`: operation input that the scenario exercises\n- `Assertion`:\n - `expectOutput` `{ match }` deep-equals the handler output\n - `expectError` `{ messageIncludes? }` ensures an error was thrown\n - `expectEvents` `{ events: [{ name, version, min?, max? }] }` checks emitted events\n\n### Example\n\n```ts\nimport { defineCommand, type TestSpec } from '@contractspec/lib.contracts';\n\nexport const AddNumbersSpec = defineCommand({\n meta: { name: 'math.add', version: '1.0.0', /* … */ },\n io: {\n input: AddNumbersInput,\n output: AddNumbersOutput,\n },\n policy: { auth: 'user' },\n});\n\nexport const MathAddTests: TestSpec = {\n meta: {\n name: 'math.add.tests',\n version: '1.0.0',\n title: 'Math add scenarios',\n owners: ['@team.math'],\n tags: ['math'],\n stability: StabilityEnum.Experimental,\n },\n target: { type: 'contract', operation: { name: 'math.add' } },\n scenarios: [\n {\n name: 'adds positive numbers',\n when: {\n operation: { name: 'math.add' },\n input: { a: 2, b: 3 },\n },\n then: [\n { type: 'expectOutput', match: { sum: 5 } },\n {\n type: 'expectEvents',\n events: [{ name: 'math.sum_calculated', version: '1.0.0', min: 1 }],\n },\n ],\n },\n ],\n};\n```\n\n### Running tests\n\n1. Register the contract handlers in a `OperationSpecRegistry`:\n\n```ts\nexport function createRegistry() {\n const registry = new OperationSpecRegistry();\n registry.register(AddNumbersSpec);\n registry.bind(AddNumbersSpec, addNumbersHandler);\n return registry;\n}\n```\n\n2. Run the CLI:\n\n```\ncontractspec test apps/math/tests/math.add.tests.ts \\\n --registry apps/math/tests/registry.ts\n```\n\n- The CLI loads the TestSpec, instantiates the registry (via the provided module), and executes each scenario via `TestRunner`.\n- `--json` outputs machine-readable results.\n\n### Programmatic usage\n\n```ts\nconst runner = new TestRunner({\n registry,\n createContext: () => ({ actor: 'user', organizationId: 'tenant-1' }),\n});\n\nconst result = await runner.run(MathAddTests);\nconsole.log(result.passed, result.failed);\n```\n\n- `createContext` can supply default `HandlerCtx` values.\n- `beforeEach` / `afterEach` hooks let you seed databases or reset state.\n\n### Best practices\n\n- Keep fixtures idempotent so scenarios can run in parallel in the future.\n- Use `expectEvents` to guard analytics/telemetry expectations.\n- Add specs to `TestRegistry` for discovery and documentation.\n- `coverage` captures desired coverage metrics (enforced by future tooling).\n- Pair TestSpec files with CI using `contractspec test --json` and fail builds when `failed > 0`.\n\n### Mocking with Bun's `vi`\n\n- Pass a single function type to `vi.fn<TFunction>()` so calls retain typed arguments:\n\n```ts\nconst handler = vi.fn<typeof fetch>();\nconst fetchImpl: typeof fetch = ((...args) => handler(...args)) as typeof fetch;\nObject.defineProperty(fetchImpl, 'preconnect', {\n value: vi.fn<typeof fetch.preconnect>(),\n});\n```\n\n- When you need to inspect calls, use the typed mock (`handler.mock.calls`) rather than casting to `any`.\n- Narrow optional request data defensively (e.g., check for headers before reading them) so tests remain type-safe under strict `tsconfig` settings.\n\n"
17
17
  }];
18
18
  registerDocBlocks(tech_contracts_tests_DocBlocks);
19
19
 
@@ -9,7 +9,7 @@ const tech_lifecycle_stage_system_DocBlocks = [{
9
9
  visibility: "public",
10
10
  route: "/docs/tech/lifecycle-stage-system",
11
11
  tags: ["tech", "lifecycle-stage-system"],
12
- body: "## ContractSpec Lifecycle Stage System – Technical Design\n\nThis document describes how ContractSpec implements lifecycle detection and guidance. It covers architecture, module boundaries, scoring heuristics, and integration points so libraries, modules, bundles, and Studio surfaces stay synchronized.\n\n---\n\n### 1. Architecture Overview\n\n```\n┌──────────────────────┐\n│ @contractspec/lib.lifecycle │ Types, enums, helpers (pure data)\n└───────────┬──────────┘\n │\n┌───────────▼──────────┐ ┌───────────────────────────┐\n│ modules/lifecycle- │ │ modules/lifecycle-advisor │\n│ core (detection) │ │ (guidance & ceremonies) │\n└───────────┬──────────┘ └───────────┬───────────────┘\n │ │\n ├────────────┬──────────────┤\n ▼ ▼ ▼\n Adapters: analytics, intent, questionnaires\n │\n┌───────────▼──────────┐\n│ bundles/lifecycle- │ Managed service for Studio\n│ managed │ (REST handlers, AI agent) │\n└───────────┬──────────┘\n │\n ContractSpec Studio surfaces\n (web/mobile APIs, CLI, docs)\n```\n\n- **Libraries** provide shared vocabulary.\n- **Modules** encapsulate logic, accepting adapters to avoid environment-specific code.\n- **Bundles** compose modules, register agents/events, and expose APIs for Studio.\n- **Apps** (web-landing, future Studio views) consume bundle APIs; they do not reimplement logic. For web-landing we now resolve `@contractspec/bundle.studio` and `@contractspec/lib.database-contractspec-studio` directly from their `packages/.../src` folders via `tsconfig` path aliases so Prisma stays on the server build and Turbopack no longer pulls the prebundled `dist` artifacts into client chunks.\n\n---\n\n### 2. Core Library (`@contractspec/lib.lifecycle`)\n\n- Stage enum (0–6) with metadata (`question`, `signals`, `traps`).\n- Axes types (`ProductPhase`, `CompanyPhase`, `CapitalPhase`).\n- `LifecycleSignal` (source, metric, value, timestamp).\n- `LifecycleMetricSnapshot` (aggregated numbers).\n- `LifecycleMilestone`, `LifecycleAction`, `LifecycleAssessment` interfaces.\n- Utility helpers:\n - `formatStageSummary(stage, assessment)`\n - `rankStageCandidates(scores)`\n\nThe library exports **no runtime dependencies** so it can be imported from apps, modules, and bundles alike.\n\n---\n\n### 3. Lifecycle Core Module\n\n**Location:** `packages/modules/lifecycle-core/`\n\n#### Components\n1. **StageSignalCollector**\n - Accepts adapter interfaces:\n - `AnalyticsAdapter` (pulls metrics from `@contractspec/lib.analytics` or fixture streams).\n - `IntentAdapter` (hooks into `@contractspec/lib.observability` intent detectors or logs).\n - `QuestionnaireAdapter` (loads JSON questionnaires and responses).\n - Produces normalized `LifecycleSignal[]`.\n\n2. **StageScorer**\n - Weighted scoring model:\n - Base weight per stage (reflecting expected maturity).\n - Feature weights (retention, revenue, team size, qualitative feedback).\n - Confidence computed via variance of contributing signals.\n - Supports pluggable scoring matrices via JSON config.\n - Accepts sparse metric snapshots; the orchestrator sanitizes metrics to numeric-only records before persisting assessments so downstream analytics stay consistent.\n\n3. **LifecycleOrchestrator**\n - Coordinates collectors + scorer.\n - Returns `LifecycleAssessment` with:\n - `stage`, `confidence`, `axisSnapshot`, `signalsUsed`.\n - Recommended focus areas (high-level categories only).\n - Emits events (internally) when stage confidence crosses thresholds (consumed later by bundle).\n\n4. **LifecycleMilestonePlanner**\n - Loads `milestones-catalog.json` (no DB).\n - Filters upcoming milestones per stage + axis.\n - Tracks completion using provided IDs (caller persists).\n\n#### Data Files\n- `configs/stage-weights.json`\n- `configs/milestones-catalog.json`\n- `questionnaires/stage-readiness.json`\n\n#### Extension Hooks\n- All adapters exported as TypeScript interfaces.\n- Implementations for analytics/intent can live in bundles or apps without modifying module code.\n\n---\n\n### 4. Lifecycle Advisor Module\n\n**Location:** `packages/modules/lifecycle-advisor/`\n\n#### Components\n1. **LifecycleRecommendationEngine**\n - Consumes `LifecycleAssessment`.\n - Maps gaps to `LifecycleAction[]` using rule tables (`stage-playbooks.ts`).\n - Supports override hooks for customer-specific rules.\n\n2. **ContractSpecLibraryRecommender**\n - Maintains mapping from stage → recommended libraries/modules/bundles.\n - Returns prioritized list with rationale and adoption prerequisites.\n\n3. **LifecycleCeremonyDesigner**\n - Provides textual/structural data for ceremonies (title, copy, animation cues, soundtrack references).\n - Ensures low-tech friendly instructions (clear copy, undo guidance).\n\n4. **AI Hooks**\n - Defines prompt templates and tool manifests for lifecycle advisor agents (consumed by bundles).\n - Keeps actual LLM integration outside module.\n\n---\n\n### 5. Managed Bundle (`lifecycle-managed`)\n\n**Responsibilities**\n- Wire modules together.\n- Provide HTTP/GraphQL handlers (exact transport optional).\n- Register LifecycleAdvisorAgent via `@contractspec/lib.ai-agent`.\n- LifecycleAdvisorAgent meta: domain `operations`, owners `team-lifecycle`, stability `experimental`, tags `guide/lifecycle/ops` so ops tooling can route incidents quickly.\n- Emit lifecycle events through `@contractspec/lib.bus` + `@contractspec/lib.analytics`.\n- Integrate with `contractspec-studio` packages:\n - Use Studio contracts for authentication/tenant context (without accessing tenant DBs).\n - Store assessments in Studio-managed storage abstractions (in-memory or file-based for now).\n\n**APIs**\n- `POST /lifecycle/assessments`: Accepts metrics + optional questionnaire answers. Returns `LifecycleAssessment`.\n- `GET /lifecycle/playbooks/:stage`: Returns stage playbook + ceremonies.\n- `POST /lifecycle/advise`: Invokes LifecycleAdvisorAgent with context.\n\n**Events**\n- `LifecycleAssessmentCreated`\n- `LifecycleStageChanged`\n- `LifecycleGuidanceConsumed`\n\n---\n\n### 6. Library Enhancements\n\n| Library | Enhancement |\n| --- | --- |\n| `@contractspec/lib.analytics` | Lifecycle metric collectors, helper to emit stage events, adapter implementation used by `StageSignalCollector`. |\n| `@contractspec/lib.evolution` | Accepts `LifecycleContext` when ranking spec anomalies/suggestions. |\n| `@contractspec/lib.growth` | Stage-specific experiment templates + guardrails referencing lifecycle enums. |\n| `@contractspec/lib.observability` | Lifecycle KPI pipeline definitions (drift detection, regression alerts). |\n\nEach enhancement must import stage types from `@contractspec/lib.lifecycle`.\n\n---\n\n### 7. Feature Flags & Progressive Delivery\n\n- Add new flags in progressive-delivery library:\n - `LIFECYCLE_DETECTION_ALPHA`\n - `LIFECYCLE_ADVISOR_ALPHA`\n - `LIFECYCLE_MANAGED_SERVICE`\n- Bundles/modules should check flags before enabling workflows.\n- Flags referenced in docs + Studio UI to avoid accidental exposure.\n\n---\n\n### 8. Analytics & Telemetry\n\n- Events defined in analytics library; consumed by bundle/app:\n - `lifecycle_assessment_run`\n - `lifecycle_stage_changed`\n - `lifecycle_guidance_consumed`\n- Observability pipeline includes:\n - Composite lifecycle health metric (weighted sum of KPIs).\n - Drift detection comparing stage predictions over time.\n - Alert manager recipes for regression (e.g., PMF drop).\n\n---\n\n### 9. Testing Strategy\n\n1. **Unit**\n - StageScorer weight matrix.\n - RecommendationEngine mapping.\n - Library recommender stage coverage.\n\n2. **Contract**\n - Adapters: ensure mock adapters satisfy interfaces.\n - Bundles: ensure HTTP handlers respect request/response contracts even without persistence.\n\n3. **Integration**\n - CLI example runs detection + guidance end-to-end on fixture data.\n - Dashboard example renders assessments, verifying JSON structures remain stable.\n\n---\n\n### 10. Implementation Checklist\n\n- [ ] Documentation (product, tech, ops, user).\n- [ ] Library creation (`@contractspec/lib.lifecycle`).\n- [ ] Modules (`lifecycle-core`, `lifecycle-advisor`).\n- [ ] Bundle (`lifecycle-managed`) + Studio wiring.\n- [ ] Library enhancements (analytics/evolution/growth/observability).\n- [ ] Examples (CLI + dashboard).\n- [ ] Feature flags + telemetry.\n- [ ] Automated tests + fixtures.\n\nKeep this document in sync as modules evolve. When adding new stages or axes, update `@contractspec/lib.lifecycle` first, then cascade to adapters, then refresh docs + Studio copy.*** End Patch*** End Patch\n\n\n"
12
+ body: "## ContractSpec Lifecycle Stage System – Technical Design\n\nThis document describes how ContractSpec implements lifecycle detection and guidance. It covers architecture, module boundaries, scoring heuristics, and integration points so libraries, modules, bundles, and Studio surfaces stay synchronized.\n\n---\n\n### 1. Architecture Overview\n\n```\n┌──────────────────────┐\n│ @contractspec/lib.lifecycle │ Types, enums, helpers (pure data)\n└───────────┬──────────┘\n │\n┌───────────▼──────────┐ ┌───────────────────────────┐\n│ modules/lifecycle- │ │ modules/lifecycle-advisor │\n│ core (detection) │ │ (guidance & ceremonies) │\n└───────────┬──────────┘ └───────────┬───────────────┘\n │ │\n ├────────────┬──────────────┤\n ▼ ▼ ▼\n Adapters: analytics, intent, questionnaires\n │\n┌───────────▼──────────┐\n│ bundles/lifecycle- │ Managed service for Studio\n│ managed │ (REST handlers, AI agent) │\n└───────────┬──────────┘\n │\n ContractSpec Studio surfaces\n (web/mobile APIs, CLI, docs)\n```\n\n- **Libraries** provide shared vocabulary.\n- **Modules** encapsulate logic, accepting adapters to avoid environment-specific code.\n- **Bundles** compose modules, register agents/events, and expose APIs for Studio.\n- **Apps** (web-landing, future Studio views) consume bundle APIs; they do not reimplement logic. For web-landing we now resolve `@contractspec/bundle.studio` and `@contractspec/lib.database-studio` directly from their `packages/.../src` folders via `tsconfig` path aliases so Prisma stays on the server build and Turbopack no longer pulls the prebundled `dist` artifacts into client chunks.\n\n---\n\n### 2. Core Library (`@contractspec/lib.lifecycle`)\n\n- Stage enum (0–6) with metadata (`question`, `signals`, `traps`).\n- Axes types (`ProductPhase`, `CompanyPhase`, `CapitalPhase`).\n- `LifecycleSignal` (source, metric, value, timestamp).\n- `LifecycleMetricSnapshot` (aggregated numbers).\n- `LifecycleMilestone`, `LifecycleAction`, `LifecycleAssessment` interfaces.\n- Utility helpers:\n - `formatStageSummary(stage, assessment)`\n - `rankStageCandidates(scores)`\n\nThe library exports **no runtime dependencies** so it can be imported from apps, modules, and bundles alike.\n\n---\n\n### 3. Lifecycle Core Module\n\n**Location:** `packages/modules/lifecycle-core/`\n\n#### Components\n1. **StageSignalCollector**\n - Accepts adapter interfaces:\n - `AnalyticsAdapter` (pulls metrics from `@contractspec/lib.analytics` or fixture streams).\n - `IntentAdapter` (hooks into `@contractspec/lib.observability` intent detectors or logs).\n - `QuestionnaireAdapter` (loads JSON questionnaires and responses).\n - Produces normalized `LifecycleSignal[]`.\n\n2. **StageScorer**\n - Weighted scoring model:\n - Base weight per stage (reflecting expected maturity).\n - Feature weights (retention, revenue, team size, qualitative feedback).\n - Confidence computed via variance of contributing signals.\n - Supports pluggable scoring matrices via JSON config.\n - Accepts sparse metric snapshots; the orchestrator sanitizes metrics to numeric-only records before persisting assessments so downstream analytics stay consistent.\n\n3. **LifecycleOrchestrator**\n - Coordinates collectors + scorer.\n - Returns `LifecycleAssessment` with:\n - `stage`, `confidence`, `axisSnapshot`, `signalsUsed`.\n - Recommended focus areas (high-level categories only).\n - Emits events (internally) when stage confidence crosses thresholds (consumed later by bundle).\n\n4. **LifecycleMilestonePlanner**\n - Loads `milestones-catalog.json` (no DB).\n - Filters upcoming milestones per stage + axis.\n - Tracks completion using provided IDs (caller persists).\n\n#### Data Files\n- `configs/stage-weights.json`\n- `configs/milestones-catalog.json`\n- `questionnaires/stage-readiness.json`\n\n#### Extension Hooks\n- All adapters exported as TypeScript interfaces.\n- Implementations for analytics/intent can live in bundles or apps without modifying module code.\n\n---\n\n### 4. Lifecycle Advisor Module\n\n**Location:** `packages/modules/lifecycle-advisor/`\n\n#### Components\n1. **LifecycleRecommendationEngine**\n - Consumes `LifecycleAssessment`.\n - Maps gaps to `LifecycleAction[]` using rule tables (`stage-playbooks.ts`).\n - Supports override hooks for customer-specific rules.\n\n2. **ContractSpecLibraryRecommender**\n - Maintains mapping from stage → recommended libraries/modules/bundles.\n - Returns prioritized list with rationale and adoption prerequisites.\n\n3. **LifecycleCeremonyDesigner**\n - Provides textual/structural data for ceremonies (title, copy, animation cues, soundtrack references).\n - Ensures low-tech friendly instructions (clear copy, undo guidance).\n\n4. **AI Hooks**\n - Defines prompt templates and tool manifests for lifecycle advisor agents (consumed by bundles).\n - Keeps actual LLM integration outside module.\n\n---\n\n### 5. Managed Bundle (`lifecycle-managed`)\n\n**Responsibilities**\n- Wire modules together.\n- Provide HTTP/GraphQL handlers (exact transport optional).\n- Register LifecycleAdvisorAgent via `@contractspec/lib.ai-agent`.\n- LifecycleAdvisorAgent meta: domain `operations`, owners `team-lifecycle`, stability `experimental`, tags `guide/lifecycle/ops` so ops tooling can route incidents quickly.\n- Emit lifecycle events through `@contractspec/lib.bus` + `@contractspec/lib.analytics`.\n- Integrate with `contractspec-studio` packages:\n - Use Studio contracts for authentication/tenant context (without accessing tenant DBs).\n - Store assessments in Studio-managed storage abstractions (in-memory or file-based for now).\n\n**APIs**\n- `POST /lifecycle/assessments`: Accepts metrics + optional questionnaire answers. Returns `LifecycleAssessment`.\n- `GET /lifecycle/playbooks/:stage`: Returns stage playbook + ceremonies.\n- `POST /lifecycle/advise`: Invokes LifecycleAdvisorAgent with context.\n\n**Events**\n- `LifecycleAssessmentCreated`\n- `LifecycleStageChanged`\n- `LifecycleGuidanceConsumed`\n\n---\n\n### 6. Library Enhancements\n\n| Library | Enhancement |\n| --- | --- |\n| `@contractspec/lib.analytics` | Lifecycle metric collectors, helper to emit stage events, adapter implementation used by `StageSignalCollector`. |\n| `@contractspec/lib.evolution` | Accepts `LifecycleContext` when ranking spec anomalies/suggestions. |\n| `@contractspec/lib.growth` | Stage-specific experiment templates + guardrails referencing lifecycle enums. |\n| `@contractspec/lib.observability` | Lifecycle KPI pipeline definitions (drift detection, regression alerts). |\n\nEach enhancement must import stage types from `@contractspec/lib.lifecycle`.\n\n---\n\n### 7. Feature Flags & Progressive Delivery\n\n- Add new flags in progressive-delivery library:\n - `LIFECYCLE_DETECTION_ALPHA`\n - `LIFECYCLE_ADVISOR_ALPHA`\n - `LIFECYCLE_MANAGED_SERVICE`\n- Bundles/modules should check flags before enabling workflows.\n- Flags referenced in docs + Studio UI to avoid accidental exposure.\n\n---\n\n### 8. Analytics & Telemetry\n\n- Events defined in analytics library; consumed by bundle/app:\n - `lifecycle_assessment_run`\n - `lifecycle_stage_changed`\n - `lifecycle_guidance_consumed`\n- Observability pipeline includes:\n - Composite lifecycle health metric (weighted sum of KPIs).\n - Drift detection comparing stage predictions over time.\n - Alert manager recipes for regression (e.g., PMF drop).\n\n---\n\n### 9. Testing Strategy\n\n1. **Unit**\n - StageScorer weight matrix.\n - RecommendationEngine mapping.\n - Library recommender stage coverage.\n\n2. **Contract**\n - Adapters: ensure mock adapters satisfy interfaces.\n - Bundles: ensure HTTP handlers respect request/response contracts even without persistence.\n\n3. **Integration**\n - CLI example runs detection + guidance end-to-end on fixture data.\n - Dashboard example renders assessments, verifying JSON structures remain stable.\n\n---\n\n### 10. Implementation Checklist\n\n- [ ] Documentation (product, tech, ops, user).\n- [ ] Library creation (`@contractspec/lib.lifecycle`).\n- [ ] Modules (`lifecycle-core`, `lifecycle-advisor`).\n- [ ] Bundle (`lifecycle-managed`) + Studio wiring.\n- [ ] Library enhancements (analytics/evolution/growth/observability).\n- [ ] Examples (CLI + dashboard).\n- [ ] Feature flags + telemetry.\n- [ ] Automated tests + fixtures.\n\nKeep this document in sync as modules evolve. When adding new stages or axes, update `@contractspec/lib.lifecycle` first, then cascade to adapters, then refresh docs + Studio copy.*** End Patch*** End Patch\n\n\n"
13
13
  }];
14
14
  registerDocBlocks(tech_lifecycle_stage_system_DocBlocks);
15
15
 
@@ -61,7 +61,7 @@ type Tag = string; // curated list available in code (e.g., 'auth', 'spots')
61
61
  // For presentations, meta is a Partial<OwnerShipMeta> plus description, name, version
62
62
  interface PresentationMeta extends Partial<OwnerShipMeta> {
63
63
  name: string;
64
- version: number;
64
+ version: string;
65
65
  description?: string;
66
66
  }
67
67
  \`\`\`
@@ -23,7 +23,7 @@ interface DocBlock {
23
23
  /** Visibility gate. Defaults to public. */
24
24
  visibility?: DocVisibility;
25
25
  /** Optional version to allow evolutions without breaking links. Defaults to 1. */
26
- version?: number;
26
+ version?: string;
27
27
  /** Tags to aid discovery and filtering. */
28
28
  tags?: string[];
29
29
  /** Owning teams or individuals. */
package/dist/events.d.ts CHANGED
@@ -32,13 +32,13 @@ interface EventEnvelope<T> {
32
32
  /** Event name as published (should match spec.name). */
33
33
  key: string;
34
34
  /** Event version as published (should match spec.version). */
35
- version: number;
35
+ version: string;
36
36
  /** Validated payload. */
37
37
  payload: T;
38
38
  }
39
- type EventKey = `${string}.v${number}`;
39
+ type EventKey = `${string}.v${string}`;
40
40
  /** Build a stable string key for an event name/version pair. */
41
- declare const eventKey: (key: string, version: number) => EventKey;
41
+ declare const eventKey: (key: string, version: string) => EventKey;
42
42
  /** In-memory registry for EventSpec. */
43
43
  declare class EventRegistry extends SpecContractRegistry<'event', AnyEventSpec> {
44
44
  constructor(items?: AnyEventSpec[]);
@@ -0,0 +1,6 @@
1
+ import { DocBlock } from "@contractspec/lib.contracts/docs";
2
+
3
+ //#region src/examples/docs/examples.docblock.d.ts
4
+ declare const tech_contracts_examples_DocBlocks: DocBlock[];
5
+ //#endregion
6
+ export { tech_contracts_examples_DocBlocks };