@lucern/sdk 0.2.0-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.
- package/README.md +97 -0
- package/dist/index.js +8980 -0
- package/dist/index.js.map +1 -0
- package/dist/lucern/contracts/src/auth-session.contract.d.ts +53 -0
- package/dist/lucern/contracts/src/context-pack.contract.d.ts +494 -0
- package/dist/lucern/contracts/src/lens-filter.contract.d.ts +70 -0
- package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +84 -0
- package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +151 -0
- package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +161 -0
- package/dist/lucern/mcp-server/src/context-pack-policy.d.ts +119 -0
- package/dist/lucern/mcp-server/src/context-pack-schema.d.ts +18 -0
- package/dist/lucern/modules/graph-primitives/src/ontology-matching.d.ts +78 -0
- package/dist/lucern/modules/graph-primitives/src/text-matching.d.ts +53 -0
- package/dist/lucern/packages/client-core/src/beliefs.d.ts +30 -0
- package/dist/lucern/packages/client-core/src/context.d.ts +29 -0
- package/dist/lucern/packages/client-core/src/contradictions.d.ts +11 -0
- package/dist/lucern/packages/client-core/src/edges.d.ts +11 -0
- package/dist/lucern/packages/client-core/src/events.d.ts +9 -0
- package/dist/lucern/packages/client-core/src/evidence.d.ts +21 -0
- package/dist/lucern/packages/client-core/src/graph.d.ts +17 -0
- package/dist/lucern/packages/client-core/src/identity.d.ts +7 -0
- package/dist/lucern/packages/client-core/src/ids.d.ts +7 -0
- package/dist/lucern/packages/client-core/src/ontologies.d.ts +13 -0
- package/dist/lucern/packages/client-core/src/questions.d.ts +39 -0
- package/dist/lucern/packages/client-core/src/search.d.ts +7 -0
- package/dist/lucern/packages/client-core/src/tasks.d.ts +13 -0
- package/dist/lucern/packages/client-core/src/topics.d.ts +17 -0
- package/dist/lucern/packages/client-core/src/webhooks.d.ts +35 -0
- package/dist/lucern/packages/client-core/src/worktrees.d.ts +17 -0
- package/dist/lucern/packages/domain-beliefs/src/beliefs.d.ts +283 -0
- package/dist/lucern/packages/domain-beliefs/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-context/src/compile.d.ts +11 -0
- package/dist/lucern/packages/domain-context/src/context-pack-compiler.d.ts +101 -0
- package/dist/lucern/packages/domain-context/src/index.d.ts +4 -0
- package/dist/lucern/packages/domain-context/src/ports.d.ts +58 -0
- package/dist/lucern/packages/domain-context/src/public-types.d.ts +1 -0
- package/dist/lucern/packages/domain-edges/src/contradictions.d.ts +59 -0
- package/dist/lucern/packages/domain-edges/src/edges.d.ts +91 -0
- package/dist/lucern/packages/domain-edges/src/index.d.ts +2 -0
- package/dist/lucern/packages/domain-evidence/src/evidence.d.ts +115 -0
- package/dist/lucern/packages/domain-evidence/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-graph/src/graph.d.ts +150 -0
- package/dist/lucern/packages/domain-identity/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-identity/src/whoami.d.ts +13 -0
- package/dist/lucern/packages/domain-ontologies/src/ontologies.d.ts +123 -0
- package/dist/lucern/packages/domain-questions/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-questions/src/questions.d.ts +147 -0
- package/dist/lucern/packages/domain-search/src/search.d.ts +97 -0
- package/dist/lucern/packages/domain-tasks/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-tasks/src/tasks.d.ts +102 -0
- package/dist/lucern/packages/domain-topics/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-topics/src/topics.d.ts +147 -0
- package/dist/lucern/packages/domain-worktrees/src/index.d.ts +1 -0
- package/dist/lucern/packages/domain-worktrees/src/worktrees.d.ts +185 -0
- package/dist/lucern/packages/events/src/index.d.ts +4 -0
- package/dist/lucern/packages/events/src/matching.d.ts +3 -0
- package/dist/lucern/packages/events/src/outbox.d.ts +15 -0
- package/dist/lucern/packages/events/src/types.d.ts +151 -0
- package/dist/lucern/packages/events/src/webhooks.d.ts +9 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/beliefs.d.ts +15 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/context.d.ts +12 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/contradictions.d.ts +7 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/edges.d.ts +7 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/events.d.ts +6 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/evidence.d.ts +21 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/graph.d.ts +10 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/identity.d.ts +5 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/ontologies.d.ts +8 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/questions.d.ts +39 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/search.d.ts +5 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/tasks.d.ts +8 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/topics.d.ts +10 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/webhooks.d.ts +16 -0
- package/dist/lucern/packages/sdk-typescript/src/facade/worktrees.d.ts +10 -0
- package/dist/lucern/packages/sdk-typescript/src/index.d.ts +28 -0
- package/dist/packages/sdk/src/adminClient.d.ts +89 -0
- package/dist/packages/sdk/src/answersClient.d.ts +5 -0
- package/dist/packages/sdk/src/audiencesClient.d.ts +87 -0
- package/dist/packages/sdk/src/auditClient.d.ts +23 -0
- package/dist/packages/sdk/src/beliefsClient.d.ts +54 -0
- package/dist/packages/sdk/src/client.d.ts +1610 -0
- package/dist/packages/sdk/src/contextClient.d.ts +9 -0
- package/dist/packages/sdk/src/contracts/api-enums.contract.d.ts +58 -0
- package/dist/packages/sdk/src/controlObjectOwnership.d.ts +293 -0
- package/dist/packages/sdk/src/coreClient.d.ts +120 -0
- package/dist/packages/sdk/src/customTools.d.ts +65 -0
- package/dist/packages/sdk/src/decisionsClient.d.ts +110 -0
- package/dist/packages/sdk/src/graphClient.d.ts +209 -0
- package/dist/packages/sdk/src/harnessClient.d.ts +222 -0
- package/dist/packages/sdk/src/identityClient.d.ts +104 -0
- package/dist/packages/sdk/src/index.d.ts +28 -0
- package/dist/packages/sdk/src/learningClient.d.ts +43 -0
- package/dist/packages/sdk/src/mcpParityClient.d.ts +68 -0
- package/dist/packages/sdk/src/mcpParitySurface.d.ts +8 -0
- package/dist/packages/sdk/src/ontologyClient.d.ts +115 -0
- package/dist/packages/sdk/src/packsClient.d.ts +101 -0
- package/dist/packages/sdk/src/policyClient.d.ts +204 -0
- package/dist/packages/sdk/src/reportsClient.d.ts +31 -0
- package/dist/packages/sdk/src/schemaClient.d.ts +54 -0
- package/dist/packages/sdk/src/sdkSurface.d.ts +56 -0
- package/dist/packages/sdk/src/topicsClient.d.ts +45 -0
- package/dist/packages/sdk/src/types.d.ts +489 -0
- package/dist/packages/sdk/src/version.d.ts +2 -0
- package/dist/packages/sdk/src/workflowClient.d.ts +274 -0
- package/package.json +56 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical lens workflow contract shared across schema, SDK, and MCP surfaces.
|
|
3
|
+
*/
|
|
4
|
+
export type { LensFilterCriteria, TaxonomyFilterCriteriaV1, EntityTypeFilterV1, OntologyScope, FilterValidationResult, } from "./lens-filter.contract";
|
|
5
|
+
export { validateFilterCriteria, isLensFilterCriteria, isTaxonomyFilterCriteriaV1, } from "./lens-filter.contract";
|
|
6
|
+
export declare const LENS_PERSPECTIVE_TYPES: readonly ["investigation", "monitoring", "analysis", "comparison", "taxonomy"];
|
|
7
|
+
export type LensPerspectiveType = (typeof LENS_PERSPECTIVE_TYPES)[number];
|
|
8
|
+
export declare const LENS_STATUSES: readonly ["draft", "active", "archived"];
|
|
9
|
+
export type LensStatus = (typeof LENS_STATUSES)[number];
|
|
10
|
+
export declare const LENS_TASK_TEMPLATE_PRIORITIES: readonly ["critical", "high", "medium", "low"];
|
|
11
|
+
export type LensTaskTemplatePriority = (typeof LENS_TASK_TEMPLATE_PRIORITIES)[number];
|
|
12
|
+
export type LensLooseMetadata = Record<string, unknown>;
|
|
13
|
+
export type LensPromptTemplateReference = {
|
|
14
|
+
key: string;
|
|
15
|
+
promptRef: string;
|
|
16
|
+
phase?: string;
|
|
17
|
+
role?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
metadata?: LensLooseMetadata;
|
|
21
|
+
};
|
|
22
|
+
export type LensWorkflowStepTemplate = {
|
|
23
|
+
key: string;
|
|
24
|
+
title: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
promptTemplateKey?: string;
|
|
27
|
+
taskTemplateKeys?: string[];
|
|
28
|
+
metadata?: LensLooseMetadata;
|
|
29
|
+
};
|
|
30
|
+
export type LensWorkflowTemplate = {
|
|
31
|
+
key: string;
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
steps: LensWorkflowStepTemplate[];
|
|
35
|
+
metadata?: LensLooseMetadata;
|
|
36
|
+
};
|
|
37
|
+
export type LensTaskTemplate = {
|
|
38
|
+
key: string;
|
|
39
|
+
title: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
priority?: LensTaskTemplatePriority;
|
|
42
|
+
phase?: string;
|
|
43
|
+
metadata?: LensLooseMetadata;
|
|
44
|
+
};
|
|
45
|
+
export type LensQuestionTemplate = {
|
|
46
|
+
key: string;
|
|
47
|
+
text: string;
|
|
48
|
+
priority?: LensTaskTemplatePriority;
|
|
49
|
+
linkedBeliefKey?: string;
|
|
50
|
+
metadata?: LensLooseMetadata;
|
|
51
|
+
};
|
|
52
|
+
export type LensBranchMigrationSuggestion = {
|
|
53
|
+
recommendedTool: "create_lens";
|
|
54
|
+
perspectiveType: LensPerspectiveType;
|
|
55
|
+
message: string;
|
|
56
|
+
suggestedPayload: {
|
|
57
|
+
name: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
topicId?: string;
|
|
60
|
+
workspaceId?: string;
|
|
61
|
+
perspectiveType: LensPerspectiveType;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export declare const BRANCH_DEPRECATION_MESSAGE = "Branches are deprecated for operational framing. Create a workspace-scoped lens instead.";
|
|
65
|
+
export type DeprecatedBranchMetadata = {
|
|
66
|
+
deprecated: true;
|
|
67
|
+
deprecationMessage: string;
|
|
68
|
+
lensSuggestion: LensBranchMigrationSuggestion;
|
|
69
|
+
};
|
|
70
|
+
export declare function inferLensPerspectiveTypeFromBranchSchema(schema?: string | null): LensPerspectiveType;
|
|
71
|
+
export declare function migrateBranchToLens(args: {
|
|
72
|
+
name: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
topicId?: string;
|
|
75
|
+
workspaceId?: string;
|
|
76
|
+
schema?: string | null;
|
|
77
|
+
}): LensBranchMigrationSuggestion;
|
|
78
|
+
export declare function buildDeprecatedBranchMetadata(args: {
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
topicId?: string;
|
|
82
|
+
workspaceId?: string;
|
|
83
|
+
schema?: string | null;
|
|
84
|
+
}): DeprecatedBranchMetadata;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Contract Definitions
|
|
3
|
+
*
|
|
4
|
+
* Machine-readable source of truth for all Lucern MCP tool names,
|
|
5
|
+
* descriptions, parameters, and response schemas.
|
|
6
|
+
*
|
|
7
|
+
* CONTRACT SURFACE: These definitions are the external API for AI agents.
|
|
8
|
+
* Renaming a tool or changing its description is a BREAKING CHANGE.
|
|
9
|
+
*
|
|
10
|
+
* Git-native naming rules (enforced by lint):
|
|
11
|
+
* 1. Workflow tools use git verbs directly (add_worktree, merge, push, open_pull_request)
|
|
12
|
+
* 2. Knowledge tools use epistemic verbs (create_belief, fork_belief, modulate_confidence)
|
|
13
|
+
* 3. First sentence of description includes the git analog verb
|
|
14
|
+
* 4. Description includes "Like `git X`" parenthetical
|
|
15
|
+
* 5. Parameter names use domain terms (canonicalText, nodeId, confidence)
|
|
16
|
+
*/
|
|
17
|
+
export type McpToolContract = {
|
|
18
|
+
/** Stable tool name — breaking change to rename */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Git-semantic description — breaking change to remove git references */
|
|
21
|
+
description: string;
|
|
22
|
+
/** Parameter schema (JSON Schema subset) */
|
|
23
|
+
parameters: Record<string, McpParameterDef>;
|
|
24
|
+
/** Required parameter names */
|
|
25
|
+
required: string[];
|
|
26
|
+
/** Response shape description */
|
|
27
|
+
response: McpResponseDef;
|
|
28
|
+
/** Which Lucern module owns the implementation */
|
|
29
|
+
ownerModule: string;
|
|
30
|
+
/** Ontology primitive this tool operates on */
|
|
31
|
+
ontologyPrimitive: "belief" | "evidence" | "source" | "question" | "judgment" | "worktree" | "branch" | "lens" | "edge" | "graph" | "task" | "policy" | "ontology" | "identity";
|
|
32
|
+
/** MCP surface tier — showcase (front page, every demo) or workhorse (complete CRUD, discovered when building) */
|
|
33
|
+
tier: "showcase" | "workhorse";
|
|
34
|
+
/** Hide this tool from public discovery surfaces. */
|
|
35
|
+
internal?: boolean;
|
|
36
|
+
/** Deprecation notice shown in contract-driven docs and discovery. */
|
|
37
|
+
deprecated?: string;
|
|
38
|
+
};
|
|
39
|
+
export type McpParameterDef = {
|
|
40
|
+
type: "string" | "number" | "boolean" | "array" | "object";
|
|
41
|
+
description: string;
|
|
42
|
+
required?: boolean;
|
|
43
|
+
enum?: string[];
|
|
44
|
+
};
|
|
45
|
+
export type McpResponseDef = {
|
|
46
|
+
description: string;
|
|
47
|
+
fields: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
export declare const CREATE_BELIEF: McpToolContract;
|
|
50
|
+
export declare const GET_BELIEF: McpToolContract;
|
|
51
|
+
export declare const REFINE_BELIEF: McpToolContract;
|
|
52
|
+
export declare const MODULATE_CONFIDENCE: McpToolContract;
|
|
53
|
+
export declare const FORK_BELIEF: McpToolContract;
|
|
54
|
+
export declare const ARCHIVE_BELIEF: McpToolContract;
|
|
55
|
+
export declare const CREATE_EPISTEMIC_CONTRACT: McpToolContract;
|
|
56
|
+
export declare const ADD_EVIDENCE: McpToolContract;
|
|
57
|
+
export declare const FLAG_CONTRADICTION: McpToolContract;
|
|
58
|
+
export declare const ADD_WORKTREE: McpToolContract;
|
|
59
|
+
export declare const MERGE: McpToolContract;
|
|
60
|
+
export declare const QUERY_LINEAGE: McpToolContract;
|
|
61
|
+
export declare const GET_CONFIDENCE_HISTORY: McpToolContract;
|
|
62
|
+
export declare const GET_AUDIT_TRAIL: McpToolContract;
|
|
63
|
+
export declare const TRAVERSE_GRAPH: McpToolContract;
|
|
64
|
+
export declare const GET_GRAPH_NEIGHBORHOOD: McpToolContract;
|
|
65
|
+
export declare const TRACE_ENTITY_IMPACT: McpToolContract;
|
|
66
|
+
export declare const SEARCH_BELIEFS: McpToolContract;
|
|
67
|
+
export declare const SEARCH_RESOURCES: McpToolContract;
|
|
68
|
+
export declare const FIND_CONTRADICTIONS: McpToolContract;
|
|
69
|
+
export declare const CREATE_EDGE: McpToolContract;
|
|
70
|
+
export declare const RECORD_JUDGMENT: McpToolContract;
|
|
71
|
+
export declare const CREATE_LENS: McpToolContract;
|
|
72
|
+
export declare const LIST_LENSES: McpToolContract;
|
|
73
|
+
export declare const APPLY_LENS_TO_TOPIC: McpToolContract;
|
|
74
|
+
export declare const REMOVE_LENS_FROM_TOPIC: McpToolContract;
|
|
75
|
+
export declare const PUSH: McpToolContract;
|
|
76
|
+
export declare const OPEN_PULL_REQUEST: McpToolContract;
|
|
77
|
+
export declare const BISECT_CONFIDENCE: McpToolContract;
|
|
78
|
+
export declare const DETECT_CONFIRMATION_BIAS: McpToolContract;
|
|
79
|
+
export declare const GET_GRAPH_STRUCTURE_ANALYSIS: McpToolContract;
|
|
80
|
+
export declare const GET_FALSIFICATION_QUESTIONS: McpToolContract;
|
|
81
|
+
export declare const SEARCH_SOURCES: McpToolContract;
|
|
82
|
+
export declare const EXECUTE_DEEP_RESEARCH: McpToolContract;
|
|
83
|
+
export declare const SEARCH_EVIDENCE: McpToolContract;
|
|
84
|
+
export declare const CREATE_EVIDENCE: McpToolContract;
|
|
85
|
+
export declare const GET_EVIDENCE: McpToolContract;
|
|
86
|
+
export declare const LIST_EVIDENCE: McpToolContract;
|
|
87
|
+
export declare const LINK_EVIDENCE: McpToolContract;
|
|
88
|
+
export declare const LINK_EVIDENCE_TO_BELIEF: McpToolContract;
|
|
89
|
+
export declare const CREATE_QUESTION: McpToolContract;
|
|
90
|
+
export declare const GET_QUESTION: McpToolContract;
|
|
91
|
+
export declare const REFINE_QUESTION: McpToolContract;
|
|
92
|
+
export declare const LIST_QUESTIONS: McpToolContract;
|
|
93
|
+
export declare const ANSWER_QUESTION: McpToolContract;
|
|
94
|
+
export declare const UPDATE_QUESTION_STATUS: McpToolContract;
|
|
95
|
+
export declare const ARCHIVE_QUESTION: McpToolContract;
|
|
96
|
+
export declare const LINK_EVIDENCE_TO_QUESTION: McpToolContract;
|
|
97
|
+
export declare const CREATE_ANSWER: McpToolContract;
|
|
98
|
+
export declare const GET_ANSWER: McpToolContract;
|
|
99
|
+
export declare const GET_HIGH_PRIORITY_QUESTIONS: McpToolContract;
|
|
100
|
+
export declare const FIND_MISSING_QUESTIONS: McpToolContract;
|
|
101
|
+
export declare const LIST_BELIEFS: McpToolContract;
|
|
102
|
+
export declare const LIST_WORKTREES: McpToolContract;
|
|
103
|
+
export declare const LIST_ALL_WORKTREES: McpToolContract;
|
|
104
|
+
export declare const ACTIVATE_WORKTREE: McpToolContract;
|
|
105
|
+
export declare const UPDATE_WORKTREE_TARGETS: McpToolContract;
|
|
106
|
+
export declare const UPDATE_WORKTREE_METADATA: McpToolContract;
|
|
107
|
+
export declare const IDENTITY_WHOAMI: McpToolContract;
|
|
108
|
+
export declare const COMPILE_CONTEXT: McpToolContract;
|
|
109
|
+
export declare const CHECK_PERMISSION: McpToolContract;
|
|
110
|
+
export declare const FILTER_BY_PERMISSION: McpToolContract;
|
|
111
|
+
export declare const INGEST_OBSERVATION: McpToolContract;
|
|
112
|
+
export declare const GET_OBSERVATION_CONTEXT: McpToolContract;
|
|
113
|
+
export declare const CREATE_TASK: McpToolContract;
|
|
114
|
+
export declare const COMPLETE_TASK: McpToolContract;
|
|
115
|
+
export declare const UPDATE_TASK: McpToolContract;
|
|
116
|
+
export declare const LIST_TASKS: McpToolContract;
|
|
117
|
+
export declare const CREATE_TOPIC: McpToolContract;
|
|
118
|
+
export declare const LIST_TOPICS: McpToolContract;
|
|
119
|
+
export declare const GET_TOPIC: McpToolContract;
|
|
120
|
+
export declare const UPDATE_TOPIC: McpToolContract;
|
|
121
|
+
export declare const GET_TOPIC_TREE: McpToolContract;
|
|
122
|
+
export declare const GET_CODE_CONTEXT: McpToolContract;
|
|
123
|
+
export declare const GET_CHANGE_HISTORY: McpToolContract;
|
|
124
|
+
export declare const RECORD_ATTEMPT: McpToolContract;
|
|
125
|
+
export declare const GET_FAILURE_LOG: McpToolContract;
|
|
126
|
+
export declare const GET_TOPIC_COVERAGE: McpToolContract;
|
|
127
|
+
export declare const GET_GRAPH_GAPS: McpToolContract;
|
|
128
|
+
export declare const MANAGE_WRITE_POLICY: McpToolContract;
|
|
129
|
+
export declare const LIST_ONTOLOGIES: McpToolContract;
|
|
130
|
+
export declare const GET_ONTOLOGY: McpToolContract;
|
|
131
|
+
export declare const APPLY_ONTOLOGY: McpToolContract;
|
|
132
|
+
export declare const MATCH_ENTITY_TYPE: McpToolContract;
|
|
133
|
+
export declare const CREATE_ONTOLOGY: McpToolContract;
|
|
134
|
+
export declare const UPDATE_ONTOLOGY: McpToolContract;
|
|
135
|
+
export declare const ARCHIVE_ONTOLOGY: McpToolContract;
|
|
136
|
+
export declare const CREATE_ONTOLOGY_VERSION: McpToolContract;
|
|
137
|
+
export declare const PUBLISH_ONTOLOGY_VERSION: McpToolContract;
|
|
138
|
+
export declare const DEPRECATE_ONTOLOGY_VERSION: McpToolContract;
|
|
139
|
+
export declare const RESOLVE_EFFECTIVE_ONTOLOGY: McpToolContract;
|
|
140
|
+
/** All MCP tool contracts, indexed by name */
|
|
141
|
+
export declare const MCP_TOOL_CONTRACTS: Record<string, McpToolContract>;
|
|
142
|
+
/** Tool names that MUST include git-semantic language in descriptions */
|
|
143
|
+
export declare const GIT_SEMANTIC_REQUIRED_TOOLS: string[];
|
|
144
|
+
/**
|
|
145
|
+
* Lint validation: every tool description must contain "Like `git" or "Like a `git"
|
|
146
|
+
* or reference a git operation in the first sentence.
|
|
147
|
+
*/
|
|
148
|
+
export declare function validateGitSemantics(tool: McpToolContract): {
|
|
149
|
+
valid: boolean;
|
|
150
|
+
reason?: string;
|
|
151
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
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[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-Pack Ranking and Injection Policy
|
|
3
|
+
*
|
|
4
|
+
* Implements the ranking algorithm and token-budget injection planner
|
|
5
|
+
* for context pack assembly. All tunable constants are imported from
|
|
6
|
+
* the canonical contract at lucern/contracts/src/context-pack.contract.ts.
|
|
7
|
+
*/
|
|
8
|
+
import { type ContextPackSectionKey, type ContextRankingProfile, type PackWeightOverride, type RankingWeightVector } from "../../contracts/src/context-pack.contract.js";
|
|
9
|
+
export type SectionKey = ContextPackSectionKey;
|
|
10
|
+
export type RankCandidate = {
|
|
11
|
+
id: string;
|
|
12
|
+
text: string;
|
|
13
|
+
updatedAt?: number | null;
|
|
14
|
+
createdAt?: number | null;
|
|
15
|
+
confidence?: number | null;
|
|
16
|
+
beliefType?: string | null;
|
|
17
|
+
priority?: string | null;
|
|
18
|
+
severity?: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type RankedCandidate<T extends RankCandidate> = T & {
|
|
21
|
+
score: number;
|
|
22
|
+
/** Human-readable justification for the ranking (RS-2). */
|
|
23
|
+
justification?: string;
|
|
24
|
+
};
|
|
25
|
+
/** An item excluded from the injection plan (RS-2). */
|
|
26
|
+
export type ExcludedItem = {
|
|
27
|
+
id: string;
|
|
28
|
+
section: SectionKey;
|
|
29
|
+
reason: "budget_exceeded" | "anti_repetition" | "below_threshold";
|
|
30
|
+
score: number;
|
|
31
|
+
};
|
|
32
|
+
export type InjectionPlan = {
|
|
33
|
+
tokenBudget: number;
|
|
34
|
+
estimatedTokens: number;
|
|
35
|
+
sectionBudgets: Record<SectionKey, number>;
|
|
36
|
+
sectionUsage: Record<SectionKey, number>;
|
|
37
|
+
selected: Record<SectionKey, string[]>;
|
|
38
|
+
/** Items excluded from injection with reasons (RS-2). */
|
|
39
|
+
excludedItems?: ExcludedItem[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Resolve effective ranking weights by merging overrides onto defaults.
|
|
43
|
+
* Overrides are partial — only specified fields replace defaults.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveEffectiveWeights(overrides?: PackWeightOverride[]): Readonly<Record<ContextPackSectionKey, RankingWeightVector>>;
|
|
46
|
+
/**
|
|
47
|
+
* Filter out candidates whose IDs appear in the suppression set.
|
|
48
|
+
* Returns the filtered list and the IDs that were suppressed.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applySuppression<T extends RankCandidate>(candidates: T[], suppressedIds: ReadonlySet<string>): {
|
|
51
|
+
filtered: T[];
|
|
52
|
+
suppressed: string[];
|
|
53
|
+
};
|
|
54
|
+
/** Options for RS-2 enhanced ranking. */
|
|
55
|
+
export type RankContextOptions = {
|
|
56
|
+
/** Pack weight overrides from domain pack binding. */
|
|
57
|
+
effectiveWeights?: Readonly<Record<ContextPackSectionKey, RankingWeightVector>>;
|
|
58
|
+
/** Generate human-readable justifications for each ranked item. */
|
|
59
|
+
includeJustifications?: boolean;
|
|
60
|
+
/** Stable timestamp anchor for recency scoring when compilation must be deterministic. */
|
|
61
|
+
referenceTimeMs?: number;
|
|
62
|
+
};
|
|
63
|
+
export declare function rankContextSection<T extends RankCandidate>(section: SectionKey, rows: T[], queryTokens: string[], limit: number, profile: ContextRankingProfile, options?: RankContextOptions): RankedCandidate<T>[];
|
|
64
|
+
export declare function parseTokenBudget(value: unknown, fallback?: number): number;
|
|
65
|
+
export declare function buildInjectionPlan(args: {
|
|
66
|
+
tokenBudget: number;
|
|
67
|
+
invariants: Array<{
|
|
68
|
+
nodeId: string;
|
|
69
|
+
canonicalText: string;
|
|
70
|
+
score?: number;
|
|
71
|
+
}>;
|
|
72
|
+
activeBeliefs: Array<{
|
|
73
|
+
nodeId: string;
|
|
74
|
+
canonicalText: string;
|
|
75
|
+
score?: number;
|
|
76
|
+
}>;
|
|
77
|
+
openQuestions: Array<{
|
|
78
|
+
questionId: string;
|
|
79
|
+
text: string;
|
|
80
|
+
score?: number;
|
|
81
|
+
}>;
|
|
82
|
+
recentEvidence: Array<{
|
|
83
|
+
nodeId: string;
|
|
84
|
+
canonicalText: string;
|
|
85
|
+
score?: number;
|
|
86
|
+
}>;
|
|
87
|
+
contradictions: Array<{
|
|
88
|
+
contradictionId: string;
|
|
89
|
+
description: string;
|
|
90
|
+
score?: number;
|
|
91
|
+
}>;
|
|
92
|
+
/** Track excluded items with reasons (RS-2). */
|
|
93
|
+
trackExclusions?: boolean;
|
|
94
|
+
}): InjectionPlan;
|
|
95
|
+
/**
|
|
96
|
+
* Candidate for entity ranking in the context pack.
|
|
97
|
+
* Entities are ranked separately from the token-budgeted sections.
|
|
98
|
+
*/
|
|
99
|
+
export type EntityCandidate = {
|
|
100
|
+
nodeId: string;
|
|
101
|
+
entityType: string;
|
|
102
|
+
title: string;
|
|
103
|
+
canonicalText: string;
|
|
104
|
+
connectedBeliefCount: number;
|
|
105
|
+
connectedEvidenceCount: number;
|
|
106
|
+
metadata: Record<string, unknown>;
|
|
107
|
+
updatedAt?: number | null;
|
|
108
|
+
};
|
|
109
|
+
export type RankedEntity = EntityCandidate & {
|
|
110
|
+
score: number;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Rank entities by query relevance + connectivity.
|
|
114
|
+
*
|
|
115
|
+
* Uses ENTITY_RANKING_WEIGHTS: { query: 0.4, connectivity: 0.6 }
|
|
116
|
+
* - query: Token-hit scoring against the focus query
|
|
117
|
+
* - connectivity: Normalized count of connected beliefs + evidence
|
|
118
|
+
*/
|
|
119
|
+
export declare function rankEntities(candidates: EntityCandidate[], queryTokens: string[], limit?: number): RankedEntity[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-Pack Schema Validation
|
|
3
|
+
*
|
|
4
|
+
* Runtime validator for ContextPackV1 output. Types and constants are
|
|
5
|
+
* imported from the canonical contract at lucern/contracts/src/context-pack.contract.ts.
|
|
6
|
+
*
|
|
7
|
+
* This module is intentionally thin: it re-exports the contract types and provides
|
|
8
|
+
* runtime validation that the contract cannot enforce (since TypeScript types
|
|
9
|
+
* are erased at runtime).
|
|
10
|
+
*/
|
|
11
|
+
import { CONTEXT_PACK_SCHEMA_VERSION, type ContextRankingProfile } from "../../contracts/src/context-pack.contract.js";
|
|
12
|
+
export { CONTEXT_PACK_SCHEMA_VERSION, type ContextRankingProfile };
|
|
13
|
+
type ValidationResult = {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
errors: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function validateContextPackSchema(payload: unknown): ValidationResult;
|
|
18
|
+
export declare function assertContextPackSchema(payload: unknown): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ontology Matching Engine — L0 entity type classification and similarity scoring.
|
|
3
|
+
*
|
|
4
|
+
* Provides bigram-based text similarity for matching free text against
|
|
5
|
+
* ontology entity types. Domain-agnostic: works identically for companies,
|
|
6
|
+
* molecules, code modules, or any tenant-defined entity vocabulary.
|
|
7
|
+
*
|
|
8
|
+
* Used by:
|
|
9
|
+
* - match_entity_type MCP handler (classify new entities)
|
|
10
|
+
* - discover_entity_connections MCP handler (suggest missing bridge edges)
|
|
11
|
+
*
|
|
12
|
+
* @module graph-primitives/ontology-matching
|
|
13
|
+
*/
|
|
14
|
+
/** An entity type definition from a resolved ontology version. */
|
|
15
|
+
export type OntologyEntityType = {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
subtypes?: Array<{
|
|
20
|
+
value: string;
|
|
21
|
+
label: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
/** A scored match between input text and an entity type. */
|
|
26
|
+
export type EntityTypeMatch = {
|
|
27
|
+
entityType: string;
|
|
28
|
+
label: string;
|
|
29
|
+
score: number;
|
|
30
|
+
reason: string;
|
|
31
|
+
};
|
|
32
|
+
/** A candidate entity node that can be matched against a target node. */
|
|
33
|
+
export type EntityMatchCandidate = {
|
|
34
|
+
nodeId: string;
|
|
35
|
+
entityType: string;
|
|
36
|
+
title: string;
|
|
37
|
+
canonicalText: string;
|
|
38
|
+
connectedBeliefCount: number;
|
|
39
|
+
connectedEvidenceCount: number;
|
|
40
|
+
};
|
|
41
|
+
/** A scored entity match with suggested bridge edge type. */
|
|
42
|
+
export type EntityConnectionMatch = {
|
|
43
|
+
entityNodeId: string;
|
|
44
|
+
entityType: string;
|
|
45
|
+
title: string;
|
|
46
|
+
score: number;
|
|
47
|
+
suggestedEdgeType: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Score how well input text matches a single entity type definition.
|
|
52
|
+
* Combines bigram Jaccard similarity, word overlap, and description matching.
|
|
53
|
+
*/
|
|
54
|
+
export declare function scoreEntityTypeMatch(inputText: string, entityType: OntologyEntityType): EntityTypeMatch;
|
|
55
|
+
/**
|
|
56
|
+
* Rank all entity types in an ontology against input text.
|
|
57
|
+
* Returns matches sorted by score (descending), filtered to score > minScore.
|
|
58
|
+
*/
|
|
59
|
+
export declare function rankEntityTypeMatches(inputText: string, entityTypes: OntologyEntityType[], options?: {
|
|
60
|
+
minScore?: number;
|
|
61
|
+
limit?: number;
|
|
62
|
+
}): EntityTypeMatch[];
|
|
63
|
+
/**
|
|
64
|
+
* Score how well a node's text matches an entity candidate.
|
|
65
|
+
* Used by discover_entity_connections to suggest missing bridge edges.
|
|
66
|
+
*/
|
|
67
|
+
export declare function scoreEntityConnection(nodeText: string, candidate: EntityMatchCandidate, options?: {
|
|
68
|
+
connectivityWeight?: number;
|
|
69
|
+
}): EntityConnectionMatch;
|
|
70
|
+
/**
|
|
71
|
+
* Rank entity candidates against a node's text.
|
|
72
|
+
* Returns sorted matches above the minimum score threshold.
|
|
73
|
+
*/
|
|
74
|
+
export declare function rankEntityConnections(nodeText: string, candidates: EntityMatchCandidate[], options?: {
|
|
75
|
+
minScore?: number;
|
|
76
|
+
limit?: number;
|
|
77
|
+
connectivityWeight?: number;
|
|
78
|
+
}): EntityConnectionMatch[];
|
|
@@ -0,0 +1,53 @@
|
|
|
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[];
|