notoken-core 1.5.1 → 2.0.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 (99) hide show
  1. package/config/chat-responses.json +767 -0
  2. package/config/concept-clusters.json +31 -0
  3. package/config/entities.json +93 -0
  4. package/config/image-prompts.json +20 -0
  5. package/config/intent-vectors.json +1 -0
  6. package/config/intents.json +5023 -65
  7. package/config/ollama-models.json +193 -0
  8. package/config/rules.json +32 -1
  9. package/dist/automation/discordPatchright.d.ts +35 -0
  10. package/dist/automation/discordPatchright.js +424 -0
  11. package/dist/automation/discordSetup.d.ts +31 -0
  12. package/dist/automation/discordSetup.js +338 -0
  13. package/dist/conversation/coreference.js +44 -4
  14. package/dist/conversation/pendingActions.d.ts +55 -0
  15. package/dist/conversation/pendingActions.js +127 -0
  16. package/dist/conversation/store.d.ts +72 -0
  17. package/dist/conversation/store.js +140 -1
  18. package/dist/conversation/topicTracker.d.ts +36 -0
  19. package/dist/conversation/topicTracker.js +141 -0
  20. package/dist/execution/ssh.d.ts +42 -1
  21. package/dist/execution/ssh.js +532 -3
  22. package/dist/handlers/executor.js +3981 -16
  23. package/dist/index.d.ts +25 -3
  24. package/dist/index.js +36 -2
  25. package/dist/nlp/batchParser.d.ts +30 -0
  26. package/dist/nlp/batchParser.js +77 -0
  27. package/dist/nlp/conceptExpansion.d.ts +54 -0
  28. package/dist/nlp/conceptExpansion.js +136 -0
  29. package/dist/nlp/conceptRouter.d.ts +49 -0
  30. package/dist/nlp/conceptRouter.js +302 -0
  31. package/dist/nlp/confidenceCalibrator.d.ts +62 -0
  32. package/dist/nlp/confidenceCalibrator.js +116 -0
  33. package/dist/nlp/correctionLearner.d.ts +45 -0
  34. package/dist/nlp/correctionLearner.js +207 -0
  35. package/dist/nlp/entitySpellCorrect.d.ts +35 -0
  36. package/dist/nlp/entitySpellCorrect.js +141 -0
  37. package/dist/nlp/knowledgeGraph.d.ts +70 -0
  38. package/dist/nlp/knowledgeGraph.js +380 -0
  39. package/dist/nlp/llmFallback.js +28 -1
  40. package/dist/nlp/multiClassifier.js +91 -6
  41. package/dist/nlp/multiIntent.d.ts +43 -0
  42. package/dist/nlp/multiIntent.js +154 -0
  43. package/dist/nlp/parseIntent.d.ts +6 -1
  44. package/dist/nlp/parseIntent.js +180 -5
  45. package/dist/nlp/ruleParser.js +315 -0
  46. package/dist/nlp/semanticSimilarity.d.ts +30 -0
  47. package/dist/nlp/semanticSimilarity.js +174 -0
  48. package/dist/nlp/vocabularyBuilder.d.ts +43 -0
  49. package/dist/nlp/vocabularyBuilder.js +224 -0
  50. package/dist/nlp/wikidata.d.ts +49 -0
  51. package/dist/nlp/wikidata.js +228 -0
  52. package/dist/policy/confirm.d.ts +10 -0
  53. package/dist/policy/confirm.js +39 -0
  54. package/dist/policy/safety.js +6 -4
  55. package/dist/utils/aliases.d.ts +5 -0
  56. package/dist/utils/aliases.js +39 -0
  57. package/dist/utils/analysis.js +71 -15
  58. package/dist/utils/browser.d.ts +64 -0
  59. package/dist/utils/browser.js +364 -0
  60. package/dist/utils/commandHistory.d.ts +20 -0
  61. package/dist/utils/commandHistory.js +108 -0
  62. package/dist/utils/completer.d.ts +17 -0
  63. package/dist/utils/completer.js +79 -0
  64. package/dist/utils/config.js +32 -2
  65. package/dist/utils/dbQuery.d.ts +25 -0
  66. package/dist/utils/dbQuery.js +248 -0
  67. package/dist/utils/discordDiag.d.ts +35 -0
  68. package/dist/utils/discordDiag.js +826 -0
  69. package/dist/utils/diskCleanup.d.ts +36 -0
  70. package/dist/utils/diskCleanup.js +775 -0
  71. package/dist/utils/entityResolver.d.ts +107 -0
  72. package/dist/utils/entityResolver.js +468 -0
  73. package/dist/utils/imageGen.d.ts +92 -0
  74. package/dist/utils/imageGen.js +2031 -0
  75. package/dist/utils/installTracker.d.ts +57 -0
  76. package/dist/utils/installTracker.js +160 -0
  77. package/dist/utils/multiExec.d.ts +21 -0
  78. package/dist/utils/multiExec.js +141 -0
  79. package/dist/utils/openclawDiag.d.ts +29 -0
  80. package/dist/utils/openclawDiag.js +1035 -0
  81. package/dist/utils/output.js +4 -0
  82. package/dist/utils/platform.js +2 -1
  83. package/dist/utils/progressReporter.d.ts +50 -0
  84. package/dist/utils/progressReporter.js +58 -0
  85. package/dist/utils/projectDetect.d.ts +44 -0
  86. package/dist/utils/projectDetect.js +319 -0
  87. package/dist/utils/projectScanner.d.ts +44 -0
  88. package/dist/utils/projectScanner.js +312 -0
  89. package/dist/utils/shellCompat.d.ts +78 -0
  90. package/dist/utils/shellCompat.js +186 -0
  91. package/dist/utils/smartArchive.d.ts +16 -0
  92. package/dist/utils/smartArchive.js +172 -0
  93. package/dist/utils/smartRetry.d.ts +26 -0
  94. package/dist/utils/smartRetry.js +114 -0
  95. package/dist/utils/updater.d.ts +1 -0
  96. package/dist/utils/updater.js +1 -1
  97. package/dist/utils/version.d.ts +20 -0
  98. package/dist/utils/version.js +212 -0
  99. package/package.json +6 -3
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Correction Learner — learns from user corrections after misrouted intents.
3
+ *
4
+ * When the user says "no I meant X" or "not that, I want Y", this module
5
+ * records the correction and uses it to improve future classifications.
6
+ * Uses fuzzy matching so similar phrases benefit from past corrections.
7
+ */
8
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
9
+ import { resolve } from "node:path";
10
+ import { homedir } from "node:os";
11
+ // ─── Constants ──────────────────────────────────────────────────────────────
12
+ const CORRECTIONS_DIR = resolve(homedir(), ".notoken");
13
+ const CORRECTIONS_FILE = resolve(CORRECTIONS_DIR, "learned-corrections.json");
14
+ const MAX_ENTRIES = 500;
15
+ // ─── Persistence ────────────────────────────────────────────────────────────
16
+ function loadCorrections() {
17
+ if (!existsSync(CORRECTIONS_FILE))
18
+ return [];
19
+ try {
20
+ const data = JSON.parse(readFileSync(CORRECTIONS_FILE, "utf-8"));
21
+ return Array.isArray(data) ? data : [];
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ }
27
+ function saveCorrections(corrections) {
28
+ if (!existsSync(CORRECTIONS_DIR)) {
29
+ mkdirSync(CORRECTIONS_DIR, { recursive: true });
30
+ }
31
+ // Prune to MAX_ENTRIES, keeping most recently seen
32
+ if (corrections.length > MAX_ENTRIES) {
33
+ corrections.sort((a, b) => b.lastSeen.localeCompare(a.lastSeen));
34
+ corrections = corrections.slice(0, MAX_ENTRIES);
35
+ }
36
+ writeFileSync(CORRECTIONS_FILE, JSON.stringify(corrections, null, 2));
37
+ }
38
+ // ─── Fuzzy Matching ─────────────────────────────────────────────────────────
39
+ /** Tokenize and normalize text for comparison. */
40
+ function tokenize(text) {
41
+ return text.toLowerCase().replace(/[^\w\s]/g, "").split(/\s+/).filter(w => w.length > 1);
42
+ }
43
+ /**
44
+ * Jaccard similarity between two token sets — measures overlap.
45
+ * Returns 0..1 where 1 = identical token sets.
46
+ */
47
+ function jaccardSimilarity(a, b) {
48
+ if (a.length === 0 && b.length === 0)
49
+ return 1;
50
+ const setA = new Set(a);
51
+ const setB = new Set(b);
52
+ let intersection = 0;
53
+ for (const token of setA) {
54
+ if (setB.has(token))
55
+ intersection++;
56
+ }
57
+ const union = setA.size + setB.size - intersection;
58
+ return union === 0 ? 0 : intersection / union;
59
+ }
60
+ /**
61
+ * Edit distance between two words (Levenshtein).
62
+ */
63
+ function editDistance(a, b) {
64
+ const m = a.length, n = b.length;
65
+ if (m === 0)
66
+ return n;
67
+ if (n === 0)
68
+ return m;
69
+ const dp = Array.from({ length: n + 1 }, (_, i) => i);
70
+ for (let i = 1; i <= m; i++) {
71
+ let prev = dp[0];
72
+ dp[0] = i;
73
+ for (let j = 1; j <= n; j++) {
74
+ const tmp = dp[j];
75
+ dp[j] = a[i - 1] === b[j - 1] ? prev : 1 + Math.min(prev, dp[j], dp[j - 1]);
76
+ prev = tmp;
77
+ }
78
+ }
79
+ return dp[n];
80
+ }
81
+ /**
82
+ * Fuzzy token similarity — allows minor spelling differences between words.
83
+ * Each token in A is matched to the closest token in B (edit distance <= 2).
84
+ */
85
+ function fuzzyTokenOverlap(a, b) {
86
+ if (a.length === 0 && b.length === 0)
87
+ return 1;
88
+ if (a.length === 0 || b.length === 0)
89
+ return 0;
90
+ let matches = 0;
91
+ for (const tokA of a) {
92
+ for (const tokB of b) {
93
+ const maxDist = tokA.length <= 4 ? 1 : 2;
94
+ if (tokA === tokB || editDistance(tokA, tokB) <= maxDist) {
95
+ matches++;
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ return matches / Math.max(a.length, b.length);
101
+ }
102
+ // ─── Public API ─────────────────────────────────────────────────────────────
103
+ /**
104
+ * Record a user correction. Merges with existing entry if the same
105
+ * input+wrongIntent+correctIntent triple already exists.
106
+ */
107
+ export function recordCorrection(input, wrongIntent, correctIntent) {
108
+ const corrections = loadCorrections();
109
+ const normalized = input.trim().toLowerCase();
110
+ const existing = corrections.find(c => c.input === normalized && c.wrongIntent === wrongIntent && c.correctIntent === correctIntent);
111
+ if (existing) {
112
+ existing.count++;
113
+ existing.lastSeen = new Date().toISOString();
114
+ }
115
+ else {
116
+ corrections.push({
117
+ input: normalized,
118
+ wrongIntent,
119
+ correctIntent,
120
+ count: 1,
121
+ lastSeen: new Date().toISOString(),
122
+ });
123
+ }
124
+ saveCorrections(corrections);
125
+ }
126
+ /**
127
+ * Check if a user input matches a previously corrected pattern.
128
+ * Uses fuzzy matching so synonymous phrases benefit from past corrections.
129
+ *
130
+ * Returns the corrected intent with a confidence score, or null if no match.
131
+ */
132
+ export function checkCorrections(rawText) {
133
+ const corrections = loadCorrections();
134
+ if (corrections.length === 0)
135
+ return null;
136
+ const inputTokens = tokenize(rawText);
137
+ if (inputTokens.length === 0)
138
+ return null;
139
+ let bestMatch = null;
140
+ let bestScore = 0;
141
+ for (const correction of corrections) {
142
+ const corrTokens = tokenize(correction.input);
143
+ // Combine Jaccard (exact) and fuzzy overlap for robustness
144
+ const jaccard = jaccardSimilarity(inputTokens, corrTokens);
145
+ const fuzzy = fuzzyTokenOverlap(inputTokens, corrTokens);
146
+ const score = Math.max(jaccard, fuzzy * 0.9);
147
+ // Boost score for corrections with high count (proven patterns)
148
+ const boosted = score + Math.min(correction.count * 0.02, 0.1);
149
+ if (boosted > bestScore && boosted >= 0.55) {
150
+ bestScore = boosted;
151
+ bestMatch = correction;
152
+ }
153
+ }
154
+ if (!bestMatch)
155
+ return null;
156
+ // Confidence: base from similarity, capped at 0.92
157
+ const confidence = Math.min(0.92, 0.6 + (bestScore - 0.55) * 0.8);
158
+ return { intent: bestMatch.correctIntent, confidence };
159
+ }
160
+ /**
161
+ * Detect if the user is issuing a correction to a previous misroute.
162
+ *
163
+ * Patterns detected:
164
+ * "no I meant restart the service"
165
+ * "not that, I want to check disk"
166
+ * "wrong, I wanted to see logs"
167
+ * "no, show me the containers"
168
+ * "I said restart not status"
169
+ *
170
+ * Returns the corrected intent text (the part after the correction marker)
171
+ * or null if this is not a correction.
172
+ */
173
+ export function detectCorrection(rawText, lastIntent) {
174
+ if (!lastIntent)
175
+ return null;
176
+ const text = rawText.trim();
177
+ // Pattern list: correction prefix → capture the intended action
178
+ const patterns = [
179
+ /^no[,.]?\s+(?:i\s+)?meant?\s+(?:to\s+)?(.+)/i,
180
+ /^no[,.]?\s+i\s+want(?:ed)?\s+(?:to\s+)?(.+)/i,
181
+ /^not\s+that[,.]?\s+(?:i\s+)?want(?:ed)?\s+(?:to\s+)?(.+)/i,
182
+ /^not\s+that[,.]?\s+(.+)/i,
183
+ /^wrong[,.]?\s+(?:i\s+)?want(?:ed)?\s+(?:to\s+)?(.+)/i,
184
+ /^wrong[,.]?\s+(.+)/i,
185
+ /^no[,.]?\s+(?:do|run|show|check|list|start|stop|restart|open|get)\s+(.+)/i,
186
+ /^no[,.]?\s+(show|check|list|start|stop|restart|open|get)\s+(.+)/i,
187
+ /^i\s+said\s+(.+?)(?:\s+not\s+.+)?$/i,
188
+ /^i\s+meant?\s+(?:to\s+)?(.+)/i,
189
+ /^that'?s?\s+(?:not\s+)?(?:what\s+i\s+)?(?:meant|wanted)[,.]?\s+(?:i\s+want(?:ed)?\s+(?:to\s+)?)?(.+)/i,
190
+ ];
191
+ for (const pattern of patterns) {
192
+ const match = text.match(pattern);
193
+ if (match) {
194
+ // Use the last capture group (some patterns have 2 groups)
195
+ const captured = match[match.length > 2 ? 2 : 1]?.trim();
196
+ if (captured && captured.length >= 2) {
197
+ return captured;
198
+ }
199
+ }
200
+ }
201
+ // Simple "no" followed by a complete new command on next line or after punctuation
202
+ // Only bare "no" / "nope" / "wrong" without further text — caller handles next input
203
+ if (/^(no|nope|wrong|that'?s\s+wrong|not\s+what\s+i\s+(meant|wanted))\.?$/i.test(text)) {
204
+ return ""; // Signal: user rejected, but correction text is in the next input
205
+ }
206
+ return null;
207
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Entity spell correction — "restart nignx" → "did you mean nginx?"
3
+ *
4
+ * Also does fuzzy entity matching:
5
+ * "the web server" → nginx (if nginx is the only web server in the graph)
6
+ * "the database" → mysql (if mysql is the only database)
7
+ */
8
+ import { type GraphEntity } from "./knowledgeGraph.js";
9
+ export interface SpellSuggestion {
10
+ original: string;
11
+ suggested: string;
12
+ distance: number;
13
+ confidence: number;
14
+ }
15
+ /**
16
+ * Check if a word is a misspelling of a known entity.
17
+ * Returns suggestion if distance ≤ 2 and word length ≥ 4.
18
+ */
19
+ export declare function suggestEntityCorrection(word: string): SpellSuggestion | null;
20
+ /**
21
+ * Correct entity misspellings in a full text.
22
+ * Returns corrected text and list of corrections made.
23
+ */
24
+ export declare function correctEntities(text: string): {
25
+ corrected: string;
26
+ corrections: SpellSuggestion[];
27
+ };
28
+ /**
29
+ * Fuzzy entity description matching.
30
+ * "the web server" → nginx (if nginx is the only service type entity)
31
+ * "the database" → mysql (if there's only one database)
32
+ */
33
+ export declare function resolveDescription(description: string): GraphEntity | null;
34
+ /** Reset cached vocabulary (call after graph changes). */
35
+ export declare function resetEntityVocab(): void;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Entity spell correction — "restart nignx" → "did you mean nginx?"
3
+ *
4
+ * Also does fuzzy entity matching:
5
+ * "the web server" → nginx (if nginx is the only web server in the graph)
6
+ * "the database" → mysql (if mysql is the only database)
7
+ */
8
+ import { loadKnowledgeGraph } from "./knowledgeGraph.js";
9
+ import { loadRules } from "../utils/config.js";
10
+ // ─── Levenshtein distance ───────────────────────────────────────────────────
11
+ function levenshtein(a, b) {
12
+ const m = a.length, n = b.length;
13
+ if (m === 0)
14
+ return n;
15
+ if (n === 0)
16
+ return m;
17
+ const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
18
+ for (let i = 0; i <= m; i++)
19
+ dp[i][0] = i;
20
+ for (let j = 0; j <= n; j++)
21
+ dp[0][j] = j;
22
+ for (let i = 1; i <= m; i++) {
23
+ for (let j = 1; j <= n; j++) {
24
+ dp[i][j] = a[i - 1] === b[j - 1]
25
+ ? dp[i - 1][j - 1]
26
+ : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
27
+ }
28
+ }
29
+ return dp[m][n];
30
+ }
31
+ // ─── Entity vocabulary ──────────────────────────────────────────────────────
32
+ let _entityVocab = null;
33
+ function getEntityVocab() {
34
+ if (_entityVocab)
35
+ return _entityVocab;
36
+ _entityVocab = new Map();
37
+ // From knowledge graph
38
+ try {
39
+ const g = loadKnowledgeGraph();
40
+ for (const ent of Object.values(g.entities)) {
41
+ _entityVocab.set(ent.name.toLowerCase(), ent.name);
42
+ for (const alias of ent.aliases)
43
+ _entityVocab.set(alias.toLowerCase(), ent.name);
44
+ }
45
+ }
46
+ catch { }
47
+ // From service aliases
48
+ try {
49
+ const rules = loadRules();
50
+ for (const [svc, aliases] of Object.entries(rules.serviceAliases ?? {})) {
51
+ _entityVocab.set(svc.toLowerCase(), svc);
52
+ for (const alias of aliases)
53
+ _entityVocab.set(alias.toLowerCase(), svc);
54
+ }
55
+ }
56
+ catch { }
57
+ return _entityVocab;
58
+ }
59
+ /**
60
+ * Check if a word is a misspelling of a known entity.
61
+ * Returns suggestion if distance ≤ 2 and word length ≥ 4.
62
+ */
63
+ export function suggestEntityCorrection(word) {
64
+ if (word.length < 4)
65
+ return null;
66
+ const lower = word.toLowerCase();
67
+ const vocab = getEntityVocab();
68
+ // Exact match — no correction needed
69
+ if (vocab.has(lower))
70
+ return null;
71
+ let bestDist = Infinity;
72
+ let bestMatch = "";
73
+ for (const [known, canonical] of vocab) {
74
+ if (Math.abs(known.length - lower.length) > 2)
75
+ continue; // Skip if lengths too different
76
+ const dist = levenshtein(lower, known);
77
+ if (dist < bestDist && dist <= 2) {
78
+ bestDist = dist;
79
+ bestMatch = canonical;
80
+ }
81
+ }
82
+ if (bestMatch && bestDist <= 2) {
83
+ return {
84
+ original: word,
85
+ suggested: bestMatch,
86
+ distance: bestDist,
87
+ confidence: bestDist === 1 ? 0.9 : 0.7,
88
+ };
89
+ }
90
+ return null;
91
+ }
92
+ /**
93
+ * Correct entity misspellings in a full text.
94
+ * Returns corrected text and list of corrections made.
95
+ */
96
+ export function correctEntities(text) {
97
+ const words = text.split(/\s+/);
98
+ const corrections = [];
99
+ const correctedWords = words.map(word => {
100
+ const suggestion = suggestEntityCorrection(word.replace(/[.,!?]/g, ""));
101
+ if (suggestion) {
102
+ corrections.push(suggestion);
103
+ return word.replace(suggestion.original, suggestion.suggested);
104
+ }
105
+ return word;
106
+ });
107
+ return {
108
+ corrected: correctedWords.join(" "),
109
+ corrections,
110
+ };
111
+ }
112
+ /**
113
+ * Fuzzy entity description matching.
114
+ * "the web server" → nginx (if nginx is the only service type entity)
115
+ * "the database" → mysql (if there's only one database)
116
+ */
117
+ export function resolveDescription(description) {
118
+ try {
119
+ const g = loadKnowledgeGraph();
120
+ const lower = description.toLowerCase();
121
+ // Type-based resolution
122
+ const typeMap = {
123
+ "web server": "service", "api server": "service", "app server": "service",
124
+ "database": "database", "db": "database",
125
+ "container": "container", "box": "server", "machine": "server",
126
+ };
127
+ for (const [desc, type] of Object.entries(typeMap)) {
128
+ if (lower.includes(desc)) {
129
+ const matches = Object.values(g.entities).filter(e => e.type === type);
130
+ if (matches.length === 1)
131
+ return matches[0]; // Only one of that type — must be it
132
+ }
133
+ }
134
+ }
135
+ catch { }
136
+ return null;
137
+ }
138
+ /** Reset cached vocabulary (call after graph changes). */
139
+ export function resetEntityVocab() {
140
+ _entityVocab = null;
141
+ }
@@ -0,0 +1,70 @@
1
+ export type EntityType = "service" | "server" | "database" | "port" | "user" | "package" | "container" | "path" | "llm" | "channel";
2
+ export type RelationType = "runs_on" | "depends_on" | "has_port" | "has_ip" | "installed_on" | "uses" | "owned_by" | "connects_to" | "requires";
3
+ export interface GraphEntity {
4
+ name: string;
5
+ type: EntityType;
6
+ aliases: string[];
7
+ properties: Record<string, string | number | boolean>;
8
+ }
9
+ export interface GraphRelation {
10
+ from: string;
11
+ to: string;
12
+ relation: RelationType;
13
+ properties?: Record<string, string | number | boolean>;
14
+ }
15
+ export interface KnowledgeGraph {
16
+ entities: Record<string, GraphEntity>;
17
+ relations: GraphRelation[];
18
+ lastBuilt?: string;
19
+ }
20
+ export declare function loadKnowledgeGraph(): KnowledgeGraph;
21
+ export declare function saveKnowledgeGraph(graph?: KnowledgeGraph): void;
22
+ export declare function addEntity(name: string, type: EntityType, aliases?: string[], properties?: Record<string, string | number | boolean>): GraphEntity;
23
+ export declare function addRelation(from: string, to: string, relation: RelationType, properties?: Record<string, string | number | boolean>): GraphRelation;
24
+ /** Find an entity by exact name, alias, or prefix (min 3 chars). */
25
+ export declare function getEntity(name: string): GraphEntity | null;
26
+ /** Find all entities related to entityName, optionally filtered by relation type. */
27
+ export declare function getRelated(entityName: string, relation?: RelationType): Array<{
28
+ entity: GraphEntity;
29
+ relation: GraphRelation;
30
+ direction: "outgoing" | "incoming";
31
+ }>;
32
+ /** A scored candidate for reference resolution. */
33
+ export interface ResolutionCandidate {
34
+ entity: GraphEntity;
35
+ score: number;
36
+ reason: string;
37
+ }
38
+ /**
39
+ * Resolve "it", "the server", "that service" using graph context + recent entities.
40
+ * Returns the best candidate. Use resolveCandidates() for all scored options.
41
+ */
42
+ export declare function resolveReference(text: string, recentEntities: string[]): GraphEntity | null;
43
+ /**
44
+ * Get all resolution candidates, scored and ranked.
45
+ * Scores: recent entity = 1.0 - (0.1 * position), type match = +0.2, relation match = +0.15
46
+ */
47
+ export declare function resolveCandidates(text: string, recentEntities: string[]): ResolutionCandidate[];
48
+ /** Use relationships to infer intent context from tokens. Resolves anaphora and finds target/location. */
49
+ export declare function inferIntent(tokens: string[], recentEntities?: string[]): {
50
+ resolvedEntities: Array<{
51
+ token: string;
52
+ entity: GraphEntity;
53
+ }>;
54
+ impliedRelations: GraphRelation[];
55
+ target?: GraphEntity;
56
+ location?: GraphEntity;
57
+ };
58
+ /** General-purpose query — find entities by type and/or property filter. */
59
+ export declare function queryGraph(filter: {
60
+ type?: EntityType;
61
+ property?: string;
62
+ value?: string | number | boolean;
63
+ }): GraphEntity[];
64
+ /** Build the full knowledge graph from all sources. */
65
+ export declare function buildGraph(): KnowledgeGraph;
66
+ /** Force a rebuild of the graph from all sources and persist. */
67
+ export declare function rebuildGraph(): KnowledgeGraph;
68
+ export declare function learnFromExecution(intent: string, fields: Record<string, unknown>, rawText: string): void;
69
+ /** Flush any pending graph changes to disk. */
70
+ export declare function flushGraph(): void;