@lucern/contracts 0.1.0-alpha.3 → 0.1.1-alpha.1

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 (145) hide show
  1. package/dist/index.d.ts +2003 -29
  2. package/dist/index.js +5627 -30
  3. package/package.json +15 -58
  4. package/src/agents/v1.ts +8 -0
  5. package/src/api-enums.contract.ts +183 -0
  6. package/{dist/auth-context.contract.js → src/auth-context.contract.ts} +1 -1
  7. package/{dist/auth-session.contract.js → src/auth-session.contract.ts} +1 -1
  8. package/src/auth.contract.ts +162 -0
  9. package/src/beliefs/v1.ts +8 -0
  10. package/src/context-pack.contract.ts +704 -0
  11. package/src/convex-admin.contract.ts +14 -0
  12. package/{dist/events-types.contract.js → src/events-types.contract.ts} +1 -1
  13. package/src/events.contract.ts +376 -0
  14. package/src/evidence/v1.ts +8 -0
  15. package/src/gateway.contract.ts +151 -0
  16. package/src/graph/v1.ts +8 -0
  17. package/src/ids.contract.ts +36 -0
  18. package/src/index.ts +30 -0
  19. package/src/lens-filter.contract.ts +183 -0
  20. package/src/lens-workflow.contract.ts +162 -0
  21. package/src/mcp-tools.contract.ts +3636 -0
  22. package/src/ontologies/v1.ts +8 -0
  23. package/{dist/ontology-matching.contract.js → src/ontology-matching.contract.ts} +1 -1
  24. package/src/prompt.contract.ts +50 -0
  25. package/src/questions/v1.ts +8 -0
  26. package/src/sdk-methods.contract.ts +522 -0
  27. package/src/sdk-tools.contract.ts +1545 -0
  28. package/src/text-matching.contract.ts +347 -0
  29. package/{dist/topic-scope.contract.js → src/topic-scope.contract.ts} +1 -1
  30. package/src/topics/v1.ts +8 -0
  31. package/{dist/v1/agents/v1.d.ts → src/v1/agents/v1.ts} +0 -1
  32. package/{dist/v1/beliefs/v1.d.ts → src/v1/beliefs/v1.ts} +0 -1
  33. package/{dist/v1/evidence/v1.d.ts → src/v1/evidence/v1.ts} +0 -1
  34. package/{dist/v1/graph/v1.d.ts → src/v1/graph/v1.ts} +0 -1
  35. package/src/v1/ontologies/v1.ts +276 -0
  36. package/{dist/v1/questions/v1.d.ts → src/v1/questions/v1.ts} +0 -1
  37. package/src/v1/topics/v1.ts +79 -0
  38. package/{dist/v1/worktrees/v1.d.ts → src/v1/worktrees/v1.ts} +0 -1
  39. package/src/workflow-runtime.contract.ts +440 -0
  40. package/src/worktrees/v1.ts +8 -0
  41. package/tsconfig.json +9 -0
  42. package/README.md +0 -43
  43. package/dist/api-enums.contract.d.ts +0 -59
  44. package/dist/api-enums.contract.d.ts.map +0 -1
  45. package/dist/api-enums.contract.js +0 -148
  46. package/dist/api-enums.contract.js.map +0 -1
  47. package/dist/auth-context.contract.d.ts +0 -9
  48. package/dist/auth-context.contract.d.ts.map +0 -1
  49. package/dist/auth-context.contract.js.map +0 -1
  50. package/dist/auth-session.contract.d.ts +0 -9
  51. package/dist/auth-session.contract.d.ts.map +0 -1
  52. package/dist/auth-session.contract.js.map +0 -1
  53. package/dist/auth.contract.d.ts +0 -89
  54. package/dist/auth.contract.d.ts.map +0 -1
  55. package/dist/auth.contract.js +0 -58
  56. package/dist/auth.contract.js.map +0 -1
  57. package/dist/context-pack.contract.d.ts +0 -495
  58. package/dist/context-pack.contract.d.ts.map +0 -1
  59. package/dist/context-pack.contract.js +0 -170
  60. package/dist/context-pack.contract.js.map +0 -1
  61. package/dist/convex-admin.contract.d.ts +0 -6
  62. package/dist/convex-admin.contract.d.ts.map +0 -1
  63. package/dist/convex-admin.contract.js +0 -2
  64. package/dist/convex-admin.contract.js.map +0 -1
  65. package/dist/events-types.contract.d.ts +0 -9
  66. package/dist/events-types.contract.d.ts.map +0 -1
  67. package/dist/events-types.contract.js.map +0 -1
  68. package/dist/events.contract.d.ts +0 -177
  69. package/dist/events.contract.d.ts.map +0 -1
  70. package/dist/events.contract.js +0 -160
  71. package/dist/events.contract.js.map +0 -1
  72. package/dist/gateway.contract.d.ts +0 -75
  73. package/dist/gateway.contract.d.ts.map +0 -1
  74. package/dist/gateway.contract.js +0 -20
  75. package/dist/gateway.contract.js.map +0 -1
  76. package/dist/ids.contract.d.ts +0 -8
  77. package/dist/ids.contract.d.ts.map +0 -1
  78. package/dist/ids.contract.js +0 -25
  79. package/dist/ids.contract.js.map +0 -1
  80. package/dist/index.d.ts.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/lens-filter.contract.d.ts +0 -71
  83. package/dist/lens-filter.contract.d.ts.map +0 -1
  84. package/dist/lens-filter.contract.js +0 -96
  85. package/dist/lens-filter.contract.js.map +0 -1
  86. package/dist/lens-workflow.contract.d.ts +0 -85
  87. package/dist/lens-workflow.contract.d.ts.map +0 -1
  88. package/dist/lens-workflow.contract.js +0 -55
  89. package/dist/lens-workflow.contract.js.map +0 -1
  90. package/dist/mcp-tools.contract.d.ts +0 -152
  91. package/dist/mcp-tools.contract.d.ts.map +0 -1
  92. package/dist/mcp-tools.contract.js +0 -3282
  93. package/dist/mcp-tools.contract.js.map +0 -1
  94. package/dist/ontology-matching.contract.d.ts +0 -9
  95. package/dist/ontology-matching.contract.d.ts.map +0 -1
  96. package/dist/ontology-matching.contract.js.map +0 -1
  97. package/dist/prompt.contract.d.ts +0 -25
  98. package/dist/prompt.contract.d.ts.map +0 -1
  99. package/dist/prompt.contract.js +0 -25
  100. package/dist/prompt.contract.js.map +0 -1
  101. package/dist/sdk-methods.contract.d.ts +0 -356
  102. package/dist/sdk-methods.contract.d.ts.map +0 -1
  103. package/dist/sdk-methods.contract.js +0 -17
  104. package/dist/sdk-methods.contract.js.map +0 -1
  105. package/dist/sdk-tools.contract.d.ts +0 -93
  106. package/dist/sdk-tools.contract.d.ts.map +0 -1
  107. package/dist/sdk-tools.contract.js +0 -1399
  108. package/dist/sdk-tools.contract.js.map +0 -1
  109. package/dist/text-matching.contract.d.ts +0 -54
  110. package/dist/text-matching.contract.d.ts.map +0 -1
  111. package/dist/text-matching.contract.js +0 -278
  112. package/dist/text-matching.contract.js.map +0 -1
  113. package/dist/topic-scope.contract.d.ts +0 -9
  114. package/dist/topic-scope.contract.d.ts.map +0 -1
  115. package/dist/topic-scope.contract.js.map +0 -1
  116. package/dist/v1/agents/v1.d.ts.map +0 -1
  117. package/dist/v1/agents/v1.js +0 -2
  118. package/dist/v1/agents/v1.js.map +0 -1
  119. package/dist/v1/beliefs/v1.d.ts.map +0 -1
  120. package/dist/v1/beliefs/v1.js +0 -2
  121. package/dist/v1/beliefs/v1.js.map +0 -1
  122. package/dist/v1/evidence/v1.d.ts.map +0 -1
  123. package/dist/v1/evidence/v1.js +0 -2
  124. package/dist/v1/evidence/v1.js.map +0 -1
  125. package/dist/v1/graph/v1.d.ts.map +0 -1
  126. package/dist/v1/graph/v1.js +0 -2
  127. package/dist/v1/graph/v1.js.map +0 -1
  128. package/dist/v1/ontologies/v1.d.ts +0 -77
  129. package/dist/v1/ontologies/v1.d.ts.map +0 -1
  130. package/dist/v1/ontologies/v1.js +0 -179
  131. package/dist/v1/ontologies/v1.js.map +0 -1
  132. package/dist/v1/questions/v1.d.ts.map +0 -1
  133. package/dist/v1/questions/v1.js +0 -2
  134. package/dist/v1/questions/v1.js.map +0 -1
  135. package/dist/v1/topics/v1.d.ts +0 -20
  136. package/dist/v1/topics/v1.d.ts.map +0 -1
  137. package/dist/v1/topics/v1.js +0 -62
  138. package/dist/v1/topics/v1.js.map +0 -1
  139. package/dist/v1/worktrees/v1.d.ts.map +0 -1
  140. package/dist/v1/worktrees/v1.js +0 -2
  141. package/dist/v1/worktrees/v1.js.map +0 -1
  142. package/dist/workflow-runtime.contract.d.ts +0 -162
  143. package/dist/workflow-runtime.contract.d.ts.map +0 -1
  144. package/dist/workflow-runtime.contract.js +0 -258
  145. package/dist/workflow-runtime.contract.js.map +0 -1
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Lens Filter Criteria Contract
3
+ *
4
+ * Version-discriminated filter DSL for lenses. Each filter criteria document
5
+ * carries a `version` and `kind` discriminator so future shapes can coexist
6
+ * without schema migrations. The Convex `filterCriteria` field remains v.any()
7
+ * — all type enforcement happens here at the TypeScript contract layer.
8
+ *
9
+ * Forward-compatibility guarantees:
10
+ * - `version` field: new versions add fields, never remove or rename existing ones
11
+ * - `kind` field: new filter kinds (temporal, confidence-range) can be added
12
+ * without touching taxonomy code paths
13
+ * - `entityTypeFilters` array items are open to extension in future versions
14
+ * - Resolution logic switches on `version` + `kind` to select the right resolver
15
+ *
16
+ * @module lucern/contracts/src/lens-filter
17
+ */
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // V1: Taxonomy Filter — entity type + subtype matching
21
+ // ---------------------------------------------------------------------------
22
+
23
+ /**
24
+ * A single entity type filter entry. Matches nodes whose `nodeType` equals
25
+ * `entityTypeValue`, optionally further narrowed by subtype membership.
26
+ *
27
+ * V2 will add `propertyMatchers` here for arbitrary JSON Schema facet queries.
28
+ */
29
+ export type EntityTypeFilterV1 = {
30
+ /** References ontologyVersion.entityTypes[].value, e.g. "company" */
31
+ entityTypeValue: string;
32
+
33
+ /** Optional subtype narrowing. If omitted or empty, all subtypes match. */
34
+ subtypeValues?: string[];
35
+ };
36
+
37
+ /**
38
+ * Optional scope to restrict which ontology the filter resolves against.
39
+ * If omitted, resolution uses whatever ontology is active in the workspace.
40
+ */
41
+ export type OntologyScope = {
42
+ /** Restrict to a specific ontology by key, e.g. "vc-investment" */
43
+ ontologyKey?: string;
44
+ };
45
+
46
+ /**
47
+ * Taxonomy filter criteria v1: entity type + subtype matching over ontology.
48
+ */
49
+ export type TaxonomyFilterCriteriaV1 = {
50
+ version: 1;
51
+ kind: "taxonomy";
52
+ entityTypeFilters: EntityTypeFilterV1[];
53
+ ontologyScope?: OntologyScope;
54
+ };
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // Union: All filter criteria versions and kinds
58
+ // ---------------------------------------------------------------------------
59
+
60
+ /**
61
+ * Discriminated union of all supported filter criteria.
62
+ * Resolution logic switches on `version` + `kind`.
63
+ *
64
+ * To add a new filter kind:
65
+ * 1. Define a new type (e.g., TemporalFilterCriteriaV1)
66
+ * 2. Add it to this union
67
+ * 3. Add a resolver in taxonomy-filter.ts
68
+ * 4. No schema migration needed — filterCriteria is v.any()
69
+ */
70
+ export type LensFilterCriteria = TaxonomyFilterCriteriaV1;
71
+ // Future: | TemporalFilterCriteriaV1 | ConfidenceRangeFilterCriteriaV1 | ...
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Type guards
75
+ // ---------------------------------------------------------------------------
76
+
77
+ export function isLensFilterCriteria(
78
+ value: unknown
79
+ ): value is LensFilterCriteria {
80
+ if (!value || typeof value !== "object") return false;
81
+ const obj = value as Record<string, unknown>;
82
+ return typeof obj.version === "number" && typeof obj.kind === "string";
83
+ }
84
+
85
+ export function isTaxonomyFilterCriteriaV1(
86
+ value: unknown
87
+ ): value is TaxonomyFilterCriteriaV1 {
88
+ if (!isLensFilterCriteria(value)) return false;
89
+ return value.version === 1 && value.kind === "taxonomy";
90
+ }
91
+
92
+ // ---------------------------------------------------------------------------
93
+ // Validation
94
+ // ---------------------------------------------------------------------------
95
+
96
+ export type FilterValidationResult =
97
+ | { valid: true }
98
+ | { valid: false; errors: string[] };
99
+
100
+ /**
101
+ * Validate a filter criteria document at the contract layer.
102
+ * This runs before persisting to Convex.
103
+ */
104
+ export function validateFilterCriteria(
105
+ value: unknown
106
+ ): FilterValidationResult {
107
+ if (value === undefined || value === null) {
108
+ return { valid: true }; // filterCriteria is optional
109
+ }
110
+
111
+ if (!isLensFilterCriteria(value)) {
112
+ return {
113
+ valid: false,
114
+ errors: [
115
+ 'filterCriteria must have numeric "version" and string "kind" fields',
116
+ ],
117
+ };
118
+ }
119
+
120
+ if (isTaxonomyFilterCriteriaV1(value)) {
121
+ return validateTaxonomyFilterV1(value);
122
+ }
123
+
124
+ // Cast to access properties — TypeScript narrows to `never` when all union
125
+ // members are exhausted, but at runtime unknown version/kind combos are possible.
126
+ const raw = value as { version: number; kind: string };
127
+ return {
128
+ valid: false,
129
+ errors: [
130
+ `Unsupported filter criteria: version=${raw.version}, kind=${raw.kind}`,
131
+ ],
132
+ };
133
+ }
134
+
135
+ function validateTaxonomyFilterV1(
136
+ criteria: TaxonomyFilterCriteriaV1
137
+ ): FilterValidationResult {
138
+ const errors: string[] = [];
139
+
140
+ if (!Array.isArray(criteria.entityTypeFilters)) {
141
+ errors.push("entityTypeFilters must be an array");
142
+ return { valid: false, errors };
143
+ }
144
+
145
+ if (criteria.entityTypeFilters.length === 0) {
146
+ errors.push("entityTypeFilters must contain at least one entry");
147
+ return { valid: false, errors };
148
+ }
149
+
150
+ for (let i = 0; i < criteria.entityTypeFilters.length; i++) {
151
+ const filter = criteria.entityTypeFilters[i];
152
+ if (!filter || typeof filter.entityTypeValue !== "string") {
153
+ errors.push(
154
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
155
+ );
156
+ continue;
157
+ }
158
+ if (filter.entityTypeValue.trim().length === 0) {
159
+ errors.push(
160
+ `entityTypeFilters[${i}].entityTypeValue must be a non-empty string`
161
+ );
162
+ }
163
+ if (
164
+ filter.subtypeValues !== undefined &&
165
+ !Array.isArray(filter.subtypeValues)
166
+ ) {
167
+ errors.push(`entityTypeFilters[${i}].subtypeValues must be an array`);
168
+ }
169
+ }
170
+
171
+ if (criteria.ontologyScope !== undefined) {
172
+ if (
173
+ typeof criteria.ontologyScope !== "object" ||
174
+ criteria.ontologyScope === null
175
+ ) {
176
+ errors.push("ontologyScope must be an object");
177
+ }
178
+ }
179
+
180
+ return errors.length === 0
181
+ ? { valid: true }
182
+ : { valid: false, errors };
183
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Canonical lens workflow contract shared across schema, SDK, and MCP surfaces.
3
+ */
4
+
5
+ // Re-export filter criteria types for consumers who import from lens-workflow
6
+ export type {
7
+ LensFilterCriteria,
8
+ TaxonomyFilterCriteriaV1,
9
+ EntityTypeFilterV1,
10
+ OntologyScope,
11
+ FilterValidationResult,
12
+ } from "./lens-filter.contract";
13
+ export {
14
+ validateFilterCriteria,
15
+ isLensFilterCriteria,
16
+ isTaxonomyFilterCriteriaV1,
17
+ } from "./lens-filter.contract";
18
+
19
+ export const LENS_PERSPECTIVE_TYPES = [
20
+ "investigation",
21
+ "monitoring",
22
+ "analysis",
23
+ "comparison",
24
+ "taxonomy",
25
+ ] as const;
26
+
27
+ export type LensPerspectiveType = (typeof LENS_PERSPECTIVE_TYPES)[number];
28
+
29
+ export const LENS_STATUSES = ["draft", "active", "archived"] as const;
30
+
31
+ export type LensStatus = (typeof LENS_STATUSES)[number];
32
+
33
+ export const LENS_TASK_TEMPLATE_PRIORITIES = [
34
+ "critical",
35
+ "high",
36
+ "medium",
37
+ "low",
38
+ ] as const;
39
+
40
+ export type LensTaskTemplatePriority =
41
+ (typeof LENS_TASK_TEMPLATE_PRIORITIES)[number];
42
+
43
+ export type LensLooseMetadata = Record<string, unknown>;
44
+
45
+ export type LensPromptTemplateReference = {
46
+ key: string;
47
+ promptRef: string;
48
+ phase?: string;
49
+ role?: string;
50
+ version?: string;
51
+ required?: boolean;
52
+ metadata?: LensLooseMetadata;
53
+ };
54
+
55
+ export type LensWorkflowStepTemplate = {
56
+ key: string;
57
+ title: string;
58
+ description?: string;
59
+ promptTemplateKey?: string;
60
+ taskTemplateKeys?: string[];
61
+ metadata?: LensLooseMetadata;
62
+ };
63
+
64
+ export type LensWorkflowTemplate = {
65
+ key: string;
66
+ name: string;
67
+ description?: string;
68
+ steps: LensWorkflowStepTemplate[];
69
+ metadata?: LensLooseMetadata;
70
+ };
71
+
72
+ export type LensTaskTemplate = {
73
+ key: string;
74
+ title: string;
75
+ description?: string;
76
+ priority?: LensTaskTemplatePriority;
77
+ phase?: string;
78
+ metadata?: LensLooseMetadata;
79
+ };
80
+
81
+ export type LensQuestionTemplate = {
82
+ key: string;
83
+ text: string;
84
+ priority?: LensTaskTemplatePriority;
85
+ linkedBeliefKey?: string;
86
+ metadata?: LensLooseMetadata;
87
+ };
88
+
89
+ export type LensBranchMigrationSuggestion = {
90
+ recommendedTool: "create_lens";
91
+ perspectiveType: LensPerspectiveType;
92
+ message: string;
93
+ suggestedPayload: {
94
+ name: string;
95
+ description?: string;
96
+ topicId?: string;
97
+ workspaceId?: string;
98
+ perspectiveType: LensPerspectiveType;
99
+ };
100
+ };
101
+
102
+ export const BRANCH_DEPRECATION_MESSAGE =
103
+ "Branches are deprecated for operational framing. Create a workspace-scoped lens instead.";
104
+
105
+ export type DeprecatedBranchMetadata = {
106
+ deprecated: true;
107
+ deprecationMessage: string;
108
+ lensSuggestion: LensBranchMigrationSuggestion;
109
+ };
110
+
111
+ export function inferLensPerspectiveTypeFromBranchSchema(
112
+ schema?: string | null
113
+ ): LensPerspectiveType {
114
+ const normalized = schema?.trim().toLowerCase();
115
+ if (normalized === "phase") {
116
+ return "monitoring";
117
+ }
118
+ if (normalized === "axis" || normalized === "dimension") {
119
+ return "comparison";
120
+ }
121
+ if (normalized === "track") {
122
+ return "investigation";
123
+ }
124
+ return "analysis";
125
+ }
126
+
127
+ export function migrateBranchToLens(args: {
128
+ name: string;
129
+ description?: string;
130
+ topicId?: string;
131
+ workspaceId?: string;
132
+ schema?: string | null;
133
+ }): LensBranchMigrationSuggestion {
134
+ const perspectiveType = inferLensPerspectiveTypeFromBranchSchema(args.schema);
135
+ return {
136
+ recommendedTool: "create_lens",
137
+ perspectiveType,
138
+ message:
139
+ "Branches are deprecated for operational framing. Create a workspace-scoped lens with the suggested payload instead.",
140
+ suggestedPayload: {
141
+ name: args.name,
142
+ description: args.description,
143
+ topicId: args.topicId,
144
+ workspaceId: args.workspaceId,
145
+ perspectiveType,
146
+ },
147
+ };
148
+ }
149
+
150
+ export function buildDeprecatedBranchMetadata(args: {
151
+ name: string;
152
+ description?: string;
153
+ topicId?: string;
154
+ workspaceId?: string;
155
+ schema?: string | null;
156
+ }): DeprecatedBranchMetadata {
157
+ return {
158
+ deprecated: true,
159
+ deprecationMessage: BRANCH_DEPRECATION_MESSAGE,
160
+ lensSuggestion: migrateBranchToLens(args),
161
+ };
162
+ }