@lucern/sdk 0.2.0-alpha.6 → 0.2.0-alpha.7

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 (206) hide show
  1. package/.turbo/turbo-build.log +7 -0
  2. package/.turbo/turbo-typecheck.log +4 -0
  3. package/CHANGELOG.md +13 -0
  4. package/examples/README.md +69 -0
  5. package/examples/contradiction.ts +94 -0
  6. package/examples/investigation-context.ts +118 -0
  7. package/examples/questions-and-tasks.ts +55 -0
  8. package/examples/quickstart.ts +97 -0
  9. package/examples/shared.ts +318 -0
  10. package/examples/strict-public-types.ts +143 -0
  11. package/examples/worktree-lifecycle.ts +79 -0
  12. package/package.json +16 -58
  13. package/src/README.md +6 -0
  14. package/src/adminClient.ts +789 -0
  15. package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
  16. package/src/audiencesClient.ts +209 -0
  17. package/src/auditClient.ts +50 -0
  18. package/src/beliefsClient.ts +319 -0
  19. package/src/client.ts +2647 -0
  20. package/src/contextClient.ts +130 -0
  21. package/{dist/lib/platform/sdk/contextFacade.d.ts → src/contextFacade.ts} +6 -1
  22. package/src/contextPackCompiler.ts +828 -0
  23. package/src/contextPackSchema.ts +251 -0
  24. package/src/contextTypes.ts +153 -0
  25. package/src/contracts/api-enums.contract.ts +202 -0
  26. package/src/contracts/auth-session.contract.ts +109 -0
  27. package/src/contracts/context-pack.contract.ts +700 -0
  28. package/src/contracts/contextPack.ts +1 -0
  29. package/src/contracts/index.ts +10 -0
  30. package/src/contracts/lens-filter.contract.ts +183 -0
  31. package/src/contracts/lens-workflow.contract.ts +162 -0
  32. package/src/contracts/lensFilter.ts +1 -0
  33. package/src/contracts/lensWorkflow.ts +1 -0
  34. package/src/contracts/mcp-tools.contract.ts +3636 -0
  35. package/src/contracts/mcpTools.ts +1 -0
  36. package/src/contracts/prompt.contract.ts +50 -0
  37. package/src/contracts/prompt.ts +1 -0
  38. package/src/contracts/sdk-tools.contract.ts +1457 -0
  39. package/src/contracts/sdkTools.ts +1 -0
  40. package/src/contracts/workflow-runtime.contract.ts +440 -0
  41. package/src/contracts/workflowRuntime.ts +1 -0
  42. package/src/controlObjectOwnership.ts +286 -0
  43. package/src/coreClient.ts +570 -0
  44. package/src/customTools.ts +398 -0
  45. package/src/decisionsClient.ts +286 -0
  46. package/src/domainContext.ts +15 -0
  47. package/src/events.ts +531 -0
  48. package/src/eventsCore.ts +168 -0
  49. package/src/facade/beliefs.ts +83 -0
  50. package/src/facade/context.ts +110 -0
  51. package/src/facade/contradictions.ts +29 -0
  52. package/src/facade/edges.ts +30 -0
  53. package/src/facade/events.ts +23 -0
  54. package/src/facade/evidence.ts +41 -0
  55. package/src/facade/graph.ts +38 -0
  56. package/src/facade/identity.ts +16 -0
  57. package/src/facade/ontologies.ts +34 -0
  58. package/src/facade/questions.ts +59 -0
  59. package/src/facade/search.ts +16 -0
  60. package/src/facade/tasks.ts +37 -0
  61. package/src/facade/topics.ts +42 -0
  62. package/src/facade/webhooks.ts +58 -0
  63. package/src/facade/worktrees.ts +51 -0
  64. package/src/gatewayFacades.ts +1666 -0
  65. package/src/graphClient.ts +529 -0
  66. package/src/harnessClient.ts +585 -0
  67. package/src/identityClient.ts +278 -0
  68. package/src/learningClient.ts +95 -0
  69. package/src/mcpParityClient.ts +240 -0
  70. package/src/mcpParitySurface.ts +70 -0
  71. package/src/ontologyClient.ts +275 -0
  72. package/src/packRuntime.ts +3 -0
  73. package/src/packsClient.ts +260 -0
  74. package/src/policyClient.ts +572 -0
  75. package/src/realtime/index.ts +51 -0
  76. package/src/realtime/refs.ts +17 -0
  77. package/src/reportsClient.ts +99 -0
  78. package/src/schemaClient.ts +129 -0
  79. package/src/sdkSurface.ts +190 -0
  80. package/src/topicsClient.ts +243 -0
  81. package/src/types.ts +807 -0
  82. package/src/workflowClient.ts +826 -0
  83. package/tsconfig.json +9 -0
  84. package/dist/.generated +0 -2
  85. package/dist/index.d.ts +0 -3
  86. package/dist/index.js +0 -3
  87. package/dist/lib/platform/auth/credentials.d.ts +0 -5
  88. package/dist/lib/platform/auth/credentials.js +0 -40
  89. package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
  90. package/dist/lib/platform/sdk/adminClient.js +0 -384
  91. package/dist/lib/platform/sdk/answersClient.js +0 -21
  92. package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
  93. package/dist/lib/platform/sdk/audiencesClient.js +0 -111
  94. package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
  95. package/dist/lib/platform/sdk/auditClient.js +0 -21
  96. package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
  97. package/dist/lib/platform/sdk/beliefsClient.js +0 -124
  98. package/dist/lib/platform/sdk/client.d.ts +0 -2369
  99. package/dist/lib/platform/sdk/client.js +0 -1831
  100. package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
  101. package/dist/lib/platform/sdk/contextClient.js +0 -86
  102. package/dist/lib/platform/sdk/contextFacade.js +0 -10
  103. package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
  104. package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
  105. package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
  106. package/dist/lib/platform/sdk/contextTypes.js +0 -1
  107. package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
  108. package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
  109. package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
  110. package/dist/lib/platform/sdk/coreClient.js +0 -366
  111. package/dist/lib/platform/sdk/customTools.d.ts +0 -83
  112. package/dist/lib/platform/sdk/customTools.js +0 -247
  113. package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
  114. package/dist/lib/platform/sdk/decisionsClient.js +0 -129
  115. package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
  116. package/dist/lib/platform/sdk/domainContext.js +0 -1
  117. package/dist/lib/platform/sdk/events.d.ts +0 -176
  118. package/dist/lib/platform/sdk/events.js +0 -261
  119. package/dist/lib/platform/sdk/eventsCore.d.ts +0 -13
  120. package/dist/lib/platform/sdk/eventsCore.js +0 -13
  121. package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
  122. package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
  123. package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
  124. package/dist/lib/platform/sdk/graphClient.js +0 -235
  125. package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
  126. package/dist/lib/platform/sdk/harnessClient.js +0 -219
  127. package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
  128. package/dist/lib/platform/sdk/identityClient.js +0 -131
  129. package/dist/lib/platform/sdk/index.js +0 -49
  130. package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
  131. package/dist/lib/platform/sdk/learningClient.js +0 -53
  132. package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
  133. package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
  134. package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
  135. package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
  136. package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
  137. package/dist/lib/platform/sdk/ontologyClient.js +0 -161
  138. package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
  139. package/dist/lib/platform/sdk/packRuntime.js +0 -1
  140. package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
  141. package/dist/lib/platform/sdk/packsClient.js +0 -157
  142. package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
  143. package/dist/lib/platform/sdk/policyClient.js +0 -277
  144. package/dist/lib/platform/sdk/promptCatalog.js +0 -1
  145. package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
  146. package/dist/lib/platform/sdk/reportsClient.js +0 -64
  147. package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
  148. package/dist/lib/platform/sdk/schemaClient.js +0 -71
  149. package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
  150. package/dist/lib/platform/sdk/sdkSurface.js +0 -140
  151. package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
  152. package/dist/lib/platform/sdk/topicsClient.js +0 -118
  153. package/dist/lib/platform/sdk/types.d.ts +0 -692
  154. package/dist/lib/platform/sdk/types.js +0 -1
  155. package/dist/lib/platform/sdk/version.d.ts +0 -2
  156. package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
  157. package/dist/lib/platform/sdk/workflowClient.js +0 -366
  158. package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
  159. package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
  160. package/dist/lucern/contracts/src/auth-context.contract.d.ts +0 -8
  161. package/dist/lucern/contracts/src/auth-context.contract.js +0 -8
  162. package/dist/lucern/contracts/src/auth-session.contract.d.ts +0 -8
  163. package/dist/lucern/contracts/src/auth-session.contract.js +0 -8
  164. package/dist/lucern/contracts/src/auth.contract.d.ts +0 -88
  165. package/dist/lucern/contracts/src/auth.contract.js +0 -57
  166. package/dist/lucern/contracts/src/context-pack.contract.d.ts +0 -494
  167. package/dist/lucern/contracts/src/context-pack.contract.js +0 -169
  168. package/dist/lucern/contracts/src/convex-admin.contract.d.ts +0 -5
  169. package/dist/lucern/contracts/src/convex-admin.contract.js +0 -1
  170. package/dist/lucern/contracts/src/events-types.contract.d.ts +0 -8
  171. package/dist/lucern/contracts/src/events-types.contract.js +0 -8
  172. package/dist/lucern/contracts/src/events.contract.d.ts +0 -176
  173. package/dist/lucern/contracts/src/events.contract.js +0 -159
  174. package/dist/lucern/contracts/src/gateway.contract.d.ts +0 -74
  175. package/dist/lucern/contracts/src/gateway.contract.js +0 -19
  176. package/dist/lucern/contracts/src/ids.contract.d.ts +0 -7
  177. package/dist/lucern/contracts/src/ids.contract.js +0 -24
  178. package/dist/lucern/contracts/src/index.d.ts +0 -29
  179. package/dist/lucern/contracts/src/index.js +0 -29
  180. package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
  181. package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
  182. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
  183. package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
  184. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
  185. package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
  186. package/dist/lucern/contracts/src/ontology-matching.contract.d.ts +0 -8
  187. package/dist/lucern/contracts/src/ontology-matching.contract.js +0 -8
  188. package/dist/lucern/contracts/src/prompt.contract.d.ts +0 -24
  189. package/dist/lucern/contracts/src/prompt.contract.js +0 -24
  190. package/dist/lucern/contracts/src/sdk-methods.contract.d.ts +0 -358
  191. package/dist/lucern/contracts/src/sdk-methods.contract.js +0 -19
  192. package/dist/lucern/contracts/src/sdk-tools.contract.d.ts +0 -92
  193. package/dist/lucern/contracts/src/sdk-tools.contract.js +0 -1398
  194. package/dist/lucern/contracts/src/text-matching.contract.d.ts +0 -53
  195. package/dist/lucern/contracts/src/text-matching.contract.js +0 -277
  196. package/dist/lucern/contracts/src/topic-scope.contract.d.ts +0 -8
  197. package/dist/lucern/contracts/src/topic-scope.contract.js +0 -8
  198. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
  199. package/dist/lucern/contracts/src/workflow-runtime.contract.js +0 -257
  200. package/dist/realtime-refs.d.ts +0 -1
  201. package/dist/realtime-refs.js +0 -1
  202. package/dist/realtime.d.ts +0 -1
  203. package/dist/realtime.js +0 -1
  204. /package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +0 -0
  205. /package/{dist/lib/platform/sdk/promptCatalog.d.ts → src/promptCatalog.ts} +0 -0
  206. /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
@@ -1,53 +0,0 @@
1
- /**
2
- * Shared lexical matching primitives used across MCP handlers and graph utilities.
3
- *
4
- * The goal is not to replace downstream LLM scoring. It provides a fast,
5
- * deterministic substrate for candidate generation, reranking, and light
6
- * classification across belief/question/evidence/entity surfaces.
7
- */
8
- export type LexicalStrategy = "tokenOverlap" | "bigramJaccard" | "wordOverlap";
9
- export type PreparedLexicalQuery = {
10
- raw: string;
11
- tokens: string[];
12
- words: string[];
13
- bigrams: Set<string>;
14
- };
15
- export type LexicalSignal = {
16
- strategy?: LexicalStrategy;
17
- text: string | null | undefined;
18
- weight: number;
19
- };
20
- export type LexicalRerankOptions = {
21
- lexicalWeight?: number;
22
- rankWeight?: number;
23
- };
24
- /** Tokenize a string into lowercase words, removing stop words. */
25
- export declare function tokenizeSearchText(text: string): string[];
26
- /** Simple stemmer: strip common English suffixes for fuzzy matching. */
27
- export declare function stemToken(word: string): string;
28
- /** Compute token overlap score between query tokens and text tokens. */
29
- export declare function tokenOverlapScore(queryTokens: string[], textTokens: string[]): number;
30
- /**
31
- * Extract character bigrams from text. Normalizes to lowercase, removes
32
- * non-alphanumeric characters, and generates overlapping pairs.
33
- */
34
- export declare function bigramTokenize(text: string): Set<string>;
35
- /**
36
- * Extract word-level tokens from text (for coarser matching).
37
- * Normalizes to lowercase, splits on non-alphanumeric.
38
- */
39
- export declare function wordTokenize(text: string): string[];
40
- /** Jaccard similarity between two sets: |A ∩ B| / |A ∪ B|. */
41
- export declare function jaccardSimilarity(setA: Set<string>, setB: Set<string>): number;
42
- /** Exact word overlap score: fraction of type words found in input text. */
43
- export declare function wordOverlapScore(inputWords: string[], typeWords: string[]): number;
44
- /** Pre-compute reusable lexical structures for a query. */
45
- export declare function prepareLexicalQuery(query: string): PreparedLexicalQuery;
46
- /** Score a single lexical signal against a prepared query. */
47
- export declare function scoreLexicalSignal(query: PreparedLexicalQuery, signal: LexicalSignal): number;
48
- /** Weighted lexical score across multiple textual signals. */
49
- export declare function scoreLexicalSignals(query: PreparedLexicalQuery, signals: LexicalSignal[]): number;
50
- /** Map a candidate's original rank position into a 0..1 prior. */
51
- export declare function rankWindowScore(index: number, total: number): number;
52
- /** Rerank a candidate window by lexical overlap while preserving original-rank prior. */
53
- export declare function rerankLexicalWindow<T>(query: string, items: T[], getText: (item: T) => string | null | undefined, options?: LexicalRerankOptions): T[];
@@ -1,277 +0,0 @@
1
- /**
2
- * Shared lexical matching primitives used across MCP handlers and graph utilities.
3
- *
4
- * The goal is not to replace downstream LLM scoring. It provides a fast,
5
- * deterministic substrate for candidate generation, reranking, and light
6
- * classification across belief/question/evidence/entity surfaces.
7
- */
8
- const TOKEN_SPLIT_REGEX = /[^a-z0-9]+/;
9
- const NON_ALPHANUMERIC_REGEX = /[^a-z0-9]/g;
10
- /** Stop words that add noise to scoring. */
11
- const STOP_WORDS = new Set([
12
- "the",
13
- "a",
14
- "an",
15
- "and",
16
- "or",
17
- "but",
18
- "in",
19
- "on",
20
- "at",
21
- "to",
22
- "for",
23
- "of",
24
- "with",
25
- "by",
26
- "from",
27
- "is",
28
- "it",
29
- "as",
30
- "be",
31
- "was",
32
- "are",
33
- "this",
34
- "that",
35
- "has",
36
- "had",
37
- "have",
38
- "not",
39
- "all",
40
- "can",
41
- "do",
42
- "its",
43
- "may",
44
- "will",
45
- "how",
46
- "what",
47
- "which",
48
- "who",
49
- "when",
50
- "where",
51
- "than",
52
- "then",
53
- "each",
54
- "into",
55
- "such",
56
- "any",
57
- "been",
58
- "if",
59
- "would",
60
- "about",
61
- "should",
62
- "these",
63
- "those",
64
- "their",
65
- "we",
66
- "our",
67
- "so",
68
- ]);
69
- /** Tokenize a string into lowercase words, removing stop words. */
70
- export function tokenizeSearchText(text) {
71
- return text
72
- .toLowerCase()
73
- .split(TOKEN_SPLIT_REGEX)
74
- .filter((token) => token.length >= 2 && !STOP_WORDS.has(token));
75
- }
76
- /** Simple stemmer: strip common English suffixes for fuzzy matching. */
77
- export function stemToken(word) {
78
- if (word.length <= 4) {
79
- return word;
80
- }
81
- if (word.endsWith("ation")) {
82
- return word.slice(0, -5);
83
- }
84
- if (word.endsWith("ment")) {
85
- return word.slice(0, -4);
86
- }
87
- if (word.endsWith("ness")) {
88
- return word.slice(0, -4);
89
- }
90
- if (word.endsWith("ical")) {
91
- return word.slice(0, -4);
92
- }
93
- if (word.endsWith("tion")) {
94
- return word.slice(0, -4);
95
- }
96
- if (word.endsWith("sion")) {
97
- return word.slice(0, -4);
98
- }
99
- if (word.endsWith("ing")) {
100
- return word.slice(0, -3);
101
- }
102
- if (word.endsWith("ous")) {
103
- return word.slice(0, -3);
104
- }
105
- if (word.endsWith("ive")) {
106
- return word.slice(0, -3);
107
- }
108
- if (word.endsWith("ity")) {
109
- return word.slice(0, -3);
110
- }
111
- if (word.endsWith("ics")) {
112
- return word.slice(0, -3);
113
- }
114
- if (word.endsWith("ly")) {
115
- return word.slice(0, -2);
116
- }
117
- if (word.endsWith("ed")) {
118
- return word.slice(0, -2);
119
- }
120
- if (word.endsWith("er")) {
121
- return word.slice(0, -2);
122
- }
123
- if (word.endsWith("es")) {
124
- return word.slice(0, -2);
125
- }
126
- if (word.endsWith("al")) {
127
- return word.slice(0, -2);
128
- }
129
- if (word.endsWith("ic")) {
130
- return word.slice(0, -2);
131
- }
132
- if (word.endsWith("s") && !word.endsWith("ss")) {
133
- return word.slice(0, -1);
134
- }
135
- return word;
136
- }
137
- /** Compute token overlap score between query tokens and text tokens. */
138
- export function tokenOverlapScore(queryTokens, textTokens) {
139
- if (queryTokens.length === 0 || textTokens.length === 0) {
140
- return 0;
141
- }
142
- const stemmedText = new Set(textTokens.map(stemToken));
143
- let matchCount = 0;
144
- for (const queryToken of queryTokens) {
145
- const stemmedQuery = stemToken(queryToken);
146
- if (stemmedText.has(stemmedQuery)) {
147
- matchCount += 1;
148
- continue;
149
- }
150
- for (const textToken of stemmedText) {
151
- if (textToken.startsWith(stemmedQuery) ||
152
- stemmedQuery.startsWith(textToken)) {
153
- matchCount += 0.5;
154
- break;
155
- }
156
- }
157
- }
158
- return matchCount / queryTokens.length;
159
- }
160
- /**
161
- * Extract character bigrams from text. Normalizes to lowercase, removes
162
- * non-alphanumeric characters, and generates overlapping pairs.
163
- */
164
- export function bigramTokenize(text) {
165
- const normalized = text.toLowerCase().replace(NON_ALPHANUMERIC_REGEX, "");
166
- const bigrams = new Set();
167
- for (let i = 0; i < normalized.length - 1; i++) {
168
- bigrams.add(normalized.slice(i, i + 2));
169
- }
170
- return bigrams;
171
- }
172
- /**
173
- * Extract word-level tokens from text (for coarser matching).
174
- * Normalizes to lowercase, splits on non-alphanumeric.
175
- */
176
- export function wordTokenize(text) {
177
- return text
178
- .toLowerCase()
179
- .split(TOKEN_SPLIT_REGEX)
180
- .filter((token) => token.length > 1);
181
- }
182
- /** Jaccard similarity between two sets: |A ∩ B| / |A ∪ B|. */
183
- export function jaccardSimilarity(setA, setB) {
184
- if (setA.size === 0 && setB.size === 0) {
185
- return 0;
186
- }
187
- let intersectionSize = 0;
188
- const smaller = setA.size <= setB.size ? setA : setB;
189
- const larger = setA.size <= setB.size ? setB : setA;
190
- for (const item of smaller) {
191
- if (larger.has(item)) {
192
- intersectionSize++;
193
- }
194
- }
195
- const unionSize = setA.size + setB.size - intersectionSize;
196
- return unionSize === 0 ? 0 : intersectionSize / unionSize;
197
- }
198
- /** Exact word overlap score: fraction of type words found in input text. */
199
- export function wordOverlapScore(inputWords, typeWords) {
200
- if (typeWords.length === 0) {
201
- return 0;
202
- }
203
- let matches = 0;
204
- for (const word of typeWords) {
205
- if (inputWords.includes(word)) {
206
- matches++;
207
- }
208
- }
209
- return matches / typeWords.length;
210
- }
211
- /** Pre-compute reusable lexical structures for a query. */
212
- export function prepareLexicalQuery(query) {
213
- return {
214
- raw: query,
215
- tokens: tokenizeSearchText(query),
216
- words: wordTokenize(query),
217
- bigrams: bigramTokenize(query),
218
- };
219
- }
220
- /** Score a single lexical signal against a prepared query. */
221
- export function scoreLexicalSignal(query, signal) {
222
- const text = signal.text?.trim();
223
- if (!text) {
224
- return 0;
225
- }
226
- switch (signal.strategy ?? "tokenOverlap") {
227
- case "bigramJaccard":
228
- return jaccardSimilarity(query.bigrams, bigramTokenize(text));
229
- case "wordOverlap":
230
- return wordOverlapScore(query.words, wordTokenize(text));
231
- default:
232
- return tokenOverlapScore(query.tokens, tokenizeSearchText(text));
233
- }
234
- }
235
- /** Weighted lexical score across multiple textual signals. */
236
- export function scoreLexicalSignals(query, signals) {
237
- let weightedScore = 0;
238
- let totalWeight = 0;
239
- for (const signal of signals) {
240
- if (!signal.text?.trim() || signal.weight <= 0) {
241
- continue;
242
- }
243
- weightedScore += scoreLexicalSignal(query, signal) * signal.weight;
244
- totalWeight += signal.weight;
245
- }
246
- return totalWeight === 0 ? 0 : weightedScore / totalWeight;
247
- }
248
- /** Map a candidate's original rank position into a 0..1 prior. */
249
- export function rankWindowScore(index, total) {
250
- if (total <= 1) {
251
- return 1;
252
- }
253
- const clampedIndex = Math.max(0, Math.min(index, total - 1));
254
- return 1 - clampedIndex / (total - 1);
255
- }
256
- /** Rerank a candidate window by lexical overlap while preserving original-rank prior. */
257
- export function rerankLexicalWindow(query, items, getText, options) {
258
- const preparedQuery = prepareLexicalQuery(query);
259
- if (preparedQuery.tokens.length === 0 || items.length <= 1) {
260
- return items;
261
- }
262
- const lexicalWeight = options?.lexicalWeight ?? 0.65;
263
- const rankWeight = options?.rankWeight ?? 0.35;
264
- return items
265
- .map((item, index) => {
266
- const lexicalScore = scoreLexicalSignals(preparedQuery, [
267
- { text: getText(item) ?? "", weight: 1, strategy: "tokenOverlap" },
268
- ]);
269
- const rankScore = rankWindowScore(index, items.length);
270
- return {
271
- item,
272
- combinedScore: lexicalScore * lexicalWeight + rankScore * rankWeight,
273
- };
274
- })
275
- .sort((left, right) => right.combinedScore - left.combinedScore)
276
- .map(({ item }) => item);
277
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * @lucern/contracts — topic-scope compat shim
3
- *
4
- * This file moved to ./v1/topics/v1.ts during EK-16 T1 PR 2.
5
- * Retained here until the Lucern 1.0.0 barrel-sunset cut (D12).
6
- * New code should import from "@lucern/contracts/v1/topics" directly.
7
- */
8
- export * from "./v1/topics/v1";
@@ -1,8 +0,0 @@
1
- /**
2
- * @lucern/contracts — topic-scope compat shim
3
- *
4
- * This file moved to ./v1/topics/v1.ts during EK-16 T1 PR 2.
5
- * Retained here until the Lucern 1.0.0 barrel-sunset cut (D12).
6
- * New code should import from "@lucern/contracts/v1/topics" directly.
7
- */
8
- export * from "./v1/topics/v1.js";
@@ -1,161 +0,0 @@
1
- /**
2
- * Workflow Runtime Contract v1
3
- *
4
- * Canonical TypeScript contract for Lucern's graph-local workflow runtime.
5
- * WF-1 defines the typed substrate for:
6
- * - workflow definitions and run receipts
7
- * - action mutation tiering and approval expectations
8
- * - hooks over worktree/question/evidence/inbox events
9
- * - output unions for domain-specific artifacts
10
- * - deterministic integrity checks and operational metadata
11
- *
12
- * BREAKING CHANGE RULES:
13
- * - Adding optional fields is NON-breaking
14
- * - Removing fields or renaming enum values is BREAKING
15
- * - Reclassifying a mutation tier is BREAKING
16
- * - Changing canonical workflow IDs is BREAKING
17
- */
18
- export declare const WORKFLOW_RUNTIME_SCHEMA_VERSION: "1.0.0";
19
- export declare const WORKFLOW_MUTATION_TIERS: readonly ["read_only", "low_risk_write", "high_risk_write"];
20
- export type WorkflowMutationTier = (typeof WORKFLOW_MUTATION_TIERS)[number];
21
- export declare const WORKFLOW_APPROVAL_MODES: readonly ["none", "audit_only", "human_required", "auto_approve"];
22
- export type WorkflowApprovalMode = (typeof WORKFLOW_APPROVAL_MODES)[number];
23
- export declare const DEFAULT_TIER_APPROVAL_MODE: Readonly<Record<WorkflowMutationTier, WorkflowApprovalMode>>;
24
- export declare const WORKFLOW_ACTION_KINDS: readonly ["context_pack", "integrity_check", "lucern_tool", "report_compile", "brief_publish", "notification", "custom"];
25
- export type WorkflowActionKind = (typeof WORKFLOW_ACTION_KINDS)[number];
26
- export declare const WORKFLOW_HOOK_EVENTS: readonly ["schedule.tick", "worktree.activated", "worktree.completed", "question.created", "question.answered", "evidence.appended", "inbox.item_created"];
27
- export type WorkflowHookEvent = (typeof WORKFLOW_HOOK_EVENTS)[number];
28
- export declare const WORKFLOW_OUTPUT_KINDS: readonly ["engineering_brief", "research_memo", "strategy_artifact", "inbox_summary", "pipeline_brief", "structured_payload"];
29
- export type WorkflowOutputKind = (typeof WORKFLOW_OUTPUT_KINDS)[number];
30
- export declare const WORKFLOW_RUN_STATUSES: readonly ["queued", "running", "awaiting_approval", "completed", "failed", "cancelled"];
31
- export type WorkflowRunStatus = (typeof WORKFLOW_RUN_STATUSES)[number];
32
- export declare const WORKFLOW_TRIGGER_KINDS: readonly ["manual", "schedule", "hook"];
33
- export type WorkflowTriggerKind = (typeof WORKFLOW_TRIGGER_KINDS)[number];
34
- export declare const WORKFLOW_PROOF_ARTIFACT_KINDS: readonly ["report", "brief", "artifact", "dashboard", "test_evidence"];
35
- export type WorkflowProofArtifactKind = (typeof WORKFLOW_PROOF_ARTIFACT_KINDS)[number];
36
- export declare const WORKFLOW_STAFFING_HINTS: readonly ["solo", "backend+tests", "fullstack", "mcp+tests"];
37
- export type WorkflowStaffingHint = (typeof WORKFLOW_STAFFING_HINTS)[number];
38
- export declare const WORKFLOW_AUTO_FIX_MODES: readonly ["disabled", "dry_run", "safe", "aggressive"];
39
- export type WorkflowAutoFixMode = (typeof WORKFLOW_AUTO_FIX_MODES)[number];
40
- export declare const WORKFLOW_INTEGRITY_CHECKS: readonly ["null_dependency_refs", "superseded_blockers", "band_order_inconsistency", "sparse_shaping", "failed_completed_gate"];
41
- export type WorkflowIntegrityCheckId = (typeof WORKFLOW_INTEGRITY_CHECKS)[number];
42
- export type WorkflowProofArtifact = {
43
- kind: WorkflowProofArtifactKind;
44
- label: string;
45
- required?: boolean;
46
- sourceRef?: string;
47
- };
48
- export type WorkflowAutoFixPolicy = {
49
- mode: WorkflowAutoFixMode;
50
- maxActionsPerRun?: number;
51
- permittedMutationTiers?: WorkflowMutationTier[];
52
- requireAuditTrail?: boolean;
53
- escalationGate?: string;
54
- };
55
- export declare const DEFAULT_WORKFLOW_AUTO_FIX_POLICY: WorkflowAutoFixPolicy;
56
- export type WorkflowApprovalPolicy = {
57
- mode: WorkflowApprovalMode;
58
- approvalGate?: string;
59
- autoApprovePolicyKey?: string;
60
- rationaleRequired?: boolean;
61
- };
62
- export type WorkflowOutputBase = {
63
- outputId: string;
64
- kind: WorkflowOutputKind;
65
- title: string;
66
- summary: string;
67
- generatedAt?: number;
68
- };
69
- export type EngineeringBriefOutput = WorkflowOutputBase & {
70
- kind: "engineering_brief";
71
- sections: Array<{
72
- heading: string;
73
- body: string;
74
- }>;
75
- touchedPaths?: string[];
76
- };
77
- export type ResearchMemoOutput = WorkflowOutputBase & {
78
- kind: "research_memo";
79
- claims: string[];
80
- evidenceRefs?: string[];
81
- };
82
- export type StrategyArtifactOutput = WorkflowOutputBase & {
83
- kind: "strategy_artifact";
84
- recommendations: string[];
85
- decisionWindow?: string;
86
- };
87
- export type InboxSummaryOutput = WorkflowOutputBase & {
88
- kind: "inbox_summary";
89
- channel: "developer_portal" | "chat" | "ops";
90
- inboxTitle: string;
91
- inboxBody: string;
92
- };
93
- export type PipelineBriefOutput = WorkflowOutputBase & {
94
- kind: "pipeline_brief";
95
- hingeWorktreeId?: string;
96
- groupedBlockers: Array<{
97
- blocker: string;
98
- blockedWorktreeIds: string[];
99
- }>;
100
- };
101
- export type StructuredPayloadOutput = WorkflowOutputBase & {
102
- kind: "structured_payload";
103
- payload: Record<string, unknown>;
104
- };
105
- export type WorkflowOutputContract = EngineeringBriefOutput | ResearchMemoOutput | StrategyArtifactOutput | InboxSummaryOutput | PipelineBriefOutput | StructuredPayloadOutput;
106
- export type WorkflowActionContract = {
107
- actionId: string;
108
- kind: WorkflowActionKind;
109
- title: string;
110
- description: string;
111
- mutationTier: WorkflowMutationTier;
112
- toolName?: string;
113
- produces?: WorkflowOutputKind[];
114
- idempotent?: boolean;
115
- approval: WorkflowApprovalPolicy;
116
- };
117
- export type WorkflowHookContract = {
118
- hookId: string;
119
- event: WorkflowHookEvent;
120
- description: string;
121
- condition?: string;
122
- actionIds: string[];
123
- };
124
- export type WorkflowTriggerContract = {
125
- kind: "manual";
126
- description?: string;
127
- } | {
128
- kind: "schedule";
129
- cadence: "hourly" | "daily" | "weekly";
130
- timezone?: string;
131
- } | {
132
- kind: "hook";
133
- event: WorkflowHookEvent;
134
- };
135
- export type WorkflowDefinitionV1 = {
136
- workflowId: string;
137
- version: typeof WORKFLOW_RUNTIME_SCHEMA_VERSION;
138
- title: string;
139
- description: string;
140
- trigger: WorkflowTriggerContract;
141
- staffingHint?: WorkflowStaffingHint;
142
- proofArtifacts?: WorkflowProofArtifact[];
143
- autoFixPolicy?: WorkflowAutoFixPolicy;
144
- actions: readonly WorkflowActionContract[];
145
- hooks?: readonly WorkflowHookContract[];
146
- outputs: readonly WorkflowOutputKind[];
147
- integrityChecks?: readonly WorkflowIntegrityCheckId[];
148
- };
149
- export type WorkflowRunReceiptV1 = {
150
- runId: string;
151
- workflowId: string;
152
- status: WorkflowRunStatus;
153
- triggeredBy: WorkflowTriggerKind;
154
- startedAt: number;
155
- completedAt?: number;
156
- outputKinds: WorkflowOutputKind[];
157
- approvalsRequired?: number;
158
- };
159
- export declare const NIGHTLY_RECONCILIATION_WORKFLOW_ID: "workflow.pipeline_reconciliation.v1";
160
- export declare const MORNING_BRIEF_WORKFLOW_ID: "workflow.morning_brief.v1";
161
- export declare const CANONICAL_WORKFLOW_DEFINITIONS: readonly WorkflowDefinitionV1[];