notoken-core 1.6.0 → 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.
- package/config/chat-responses.json +767 -0
- package/config/concept-clusters.json +31 -0
- package/config/entities.json +93 -0
- package/config/image-prompts.json +20 -0
- package/config/intent-vectors.json +1 -0
- package/config/intents.json +4946 -83
- package/config/ollama-models.json +193 -0
- package/config/rules.json +32 -1
- package/dist/automation/discordPatchright.d.ts +35 -0
- package/dist/automation/discordPatchright.js +424 -0
- package/dist/automation/discordSetup.d.ts +31 -0
- package/dist/automation/discordSetup.js +338 -0
- package/dist/conversation/coreference.js +44 -4
- package/dist/conversation/pendingActions.d.ts +55 -0
- package/dist/conversation/pendingActions.js +127 -0
- package/dist/conversation/store.d.ts +72 -0
- package/dist/conversation/store.js +140 -1
- package/dist/conversation/topicTracker.d.ts +36 -0
- package/dist/conversation/topicTracker.js +141 -0
- package/dist/execution/ssh.d.ts +42 -1
- package/dist/execution/ssh.js +532 -3
- package/dist/handlers/executor.js +3981 -16
- package/dist/index.d.ts +25 -3
- package/dist/index.js +36 -2
- package/dist/nlp/batchParser.d.ts +30 -0
- package/dist/nlp/batchParser.js +77 -0
- package/dist/nlp/conceptExpansion.d.ts +54 -0
- package/dist/nlp/conceptExpansion.js +136 -0
- package/dist/nlp/conceptRouter.d.ts +49 -0
- package/dist/nlp/conceptRouter.js +302 -0
- package/dist/nlp/confidenceCalibrator.d.ts +62 -0
- package/dist/nlp/confidenceCalibrator.js +116 -0
- package/dist/nlp/correctionLearner.d.ts +45 -0
- package/dist/nlp/correctionLearner.js +207 -0
- package/dist/nlp/entitySpellCorrect.d.ts +35 -0
- package/dist/nlp/entitySpellCorrect.js +141 -0
- package/dist/nlp/knowledgeGraph.d.ts +70 -0
- package/dist/nlp/knowledgeGraph.js +380 -0
- package/dist/nlp/llmFallback.js +28 -1
- package/dist/nlp/multiClassifier.js +91 -6
- package/dist/nlp/multiIntent.d.ts +43 -0
- package/dist/nlp/multiIntent.js +154 -0
- package/dist/nlp/parseIntent.d.ts +6 -1
- package/dist/nlp/parseIntent.js +180 -5
- package/dist/nlp/ruleParser.js +315 -0
- package/dist/nlp/semanticSimilarity.d.ts +30 -0
- package/dist/nlp/semanticSimilarity.js +174 -0
- package/dist/nlp/vocabularyBuilder.d.ts +43 -0
- package/dist/nlp/vocabularyBuilder.js +224 -0
- package/dist/nlp/wikidata.d.ts +49 -0
- package/dist/nlp/wikidata.js +228 -0
- package/dist/policy/confirm.d.ts +10 -0
- package/dist/policy/confirm.js +39 -0
- package/dist/policy/safety.js +6 -4
- package/dist/utils/aliases.d.ts +5 -0
- package/dist/utils/aliases.js +39 -0
- package/dist/utils/analysis.js +71 -15
- package/dist/utils/browser.d.ts +64 -0
- package/dist/utils/browser.js +364 -0
- package/dist/utils/commandHistory.d.ts +20 -0
- package/dist/utils/commandHistory.js +108 -0
- package/dist/utils/completer.d.ts +17 -0
- package/dist/utils/completer.js +79 -0
- package/dist/utils/config.js +32 -2
- package/dist/utils/dbQuery.d.ts +25 -0
- package/dist/utils/dbQuery.js +248 -0
- package/dist/utils/discordDiag.d.ts +35 -0
- package/dist/utils/discordDiag.js +826 -0
- package/dist/utils/diskCleanup.d.ts +36 -0
- package/dist/utils/diskCleanup.js +775 -0
- package/dist/utils/entityResolver.d.ts +107 -0
- package/dist/utils/entityResolver.js +468 -0
- package/dist/utils/imageGen.d.ts +92 -0
- package/dist/utils/imageGen.js +2031 -0
- package/dist/utils/installTracker.d.ts +57 -0
- package/dist/utils/installTracker.js +160 -0
- package/dist/utils/multiExec.d.ts +21 -0
- package/dist/utils/multiExec.js +141 -0
- package/dist/utils/openclawDiag.d.ts +29 -0
- package/dist/utils/openclawDiag.js +1035 -0
- package/dist/utils/output.js +4 -0
- package/dist/utils/platform.js +2 -1
- package/dist/utils/progressReporter.d.ts +50 -0
- package/dist/utils/progressReporter.js +58 -0
- package/dist/utils/projectDetect.d.ts +44 -0
- package/dist/utils/projectDetect.js +319 -0
- package/dist/utils/projectScanner.d.ts +44 -0
- package/dist/utils/projectScanner.js +312 -0
- package/dist/utils/shellCompat.d.ts +78 -0
- package/dist/utils/shellCompat.js +186 -0
- package/dist/utils/smartArchive.d.ts +16 -0
- package/dist/utils/smartArchive.js +172 -0
- package/dist/utils/smartRetry.d.ts +26 -0
- package/dist/utils/smartRetry.js +114 -0
- package/dist/utils/updater.d.ts +1 -0
- package/dist/utils/updater.js +1 -1
- package/dist/utils/version.d.ts +20 -0
- package/dist/utils/version.js +212 -0
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -12,12 +12,23 @@ export { parseByRules } from "./nlp/ruleParser.js";
|
|
|
12
12
|
export { disambiguate } from "./nlp/disambiguate.js";
|
|
13
13
|
export { classifyMulti } from "./nlp/multiClassifier.js";
|
|
14
14
|
export { semanticParse, tokenize, keyboardDistance, fuzzyMatch } from "./nlp/semantic.js";
|
|
15
|
+
export { findSimilarIntents, phraseSimilarity, expandWithCooccurrences } from "./nlp/semanticSimilarity.js";
|
|
16
|
+
export { loadKnowledgeGraph, saveKnowledgeGraph, addEntity, addRelation, getEntity, getRelated, resolveReference, resolveCandidates, inferIntent, queryGraph, rebuildGraph, learnFromExecution, flushGraph } from "./nlp/knowledgeGraph.js";
|
|
17
|
+
export { expandQuery, findCluster, suggestIntents, clusterWords } from "./nlp/conceptExpansion.js";
|
|
15
18
|
export { analyzeUncertainty, getUncoveredSpans } from "./nlp/uncertainty.js";
|
|
16
19
|
export { llmFallback, isLLMConfigured, getLLMBackend, formatLLMFallback } from "./nlp/llmFallback.js";
|
|
20
|
+
export { suggestEntityCorrection, correctEntities, resolveDescription, resetEntityVocab } from "./nlp/entitySpellCorrect.js";
|
|
21
|
+
export { recordOutcome, getMultiplier, calibrateVotes, recordCorrection, getCalibrationStats, flushCalibration } from "./nlp/confidenceCalibrator.js";
|
|
22
|
+
export { detectBatch, expandBatch, expandEnvironmentBatch } from "./nlp/batchParser.js";
|
|
23
|
+
export { getCurrentTopic, suggestFollowups, getTopicDefault } from "./conversation/topicTracker.js";
|
|
24
|
+
export { progressReporter, reportProgress, reportStep } from "./utils/progressReporter.js";
|
|
25
|
+
export { loadHistory as loadCommandHistory, addToHistory, searchHistory as searchCommandHistory, getRecentCommands, getReadlineHistory } from "./utils/commandHistory.js";
|
|
17
26
|
export { executeIntent } from "./handlers/executor.js";
|
|
18
27
|
export { runRemoteCommand, runLocalCommand } from "./execution/ssh.js";
|
|
19
28
|
export { loadRules, loadIntents, getIntentDef, loadHosts, getConfigDir } from "./utils/config.js";
|
|
20
29
|
export { CONFIG_DIR, DATA_DIR, LOG_DIR, PACKAGE_ROOT, USER_HOME, isSEA, ensureUserDirs } from "./utils/paths.js";
|
|
30
|
+
export { loadAliases, resolveAlias, saveAlias, removeAlias, listAliases } from "./utils/aliases.js";
|
|
31
|
+
export { buildCompletions, completeInput } from "./utils/completer.js";
|
|
21
32
|
export { detectLocalPlatform, getInstallCommand, getServiceCommand, getPackageForCommand, formatPlatform } from "./utils/platform.js";
|
|
22
33
|
export type { PlatformInfo } from "./utils/platform.js";
|
|
23
34
|
export { winToLinux, linuxToWin, normalizePath, getUserDirs, isWSL, isWindows } from "./utils/wslPaths.js";
|
|
@@ -27,8 +38,8 @@ export { analyzeDirectory } from "./utils/dirAnalysis.js";
|
|
|
27
38
|
export { smartRead, smartSearch, getFileInfo } from "./utils/smartFile.js";
|
|
28
39
|
export { parseFile, formatParsedFile, detectFileType } from "./parsers/index.js";
|
|
29
40
|
export { findKnownLocations, searchRemoteFile } from "./parsers/fileFinder.js";
|
|
30
|
-
export { getOrCreateConversation, addUserTurn, addSystemTurn, saveConversation, getLastEntity, getRecentEntities, listConversations } from "./conversation/store.js";
|
|
31
|
-
export type { Conversation, ConversationTurn, KnowledgeNode, UncertaintyReport } from "./conversation/store.js";
|
|
41
|
+
export { getOrCreateConversation, addUserTurn, addSystemTurn, saveConversation, getLastEntity, getRecentEntities, getRecentTurns, listConversations, loadContextFile, unloadContextFile, listContextFiles, setEntityFocus, getEntityFocus, getPreviousFocus, resolveFocusReference } from "./conversation/store.js";
|
|
42
|
+
export type { Conversation, ConversationTurn, KnowledgeNode, UncertaintyReport, EntityFocus } from "./conversation/store.js";
|
|
32
43
|
export { resolveCoreferences, extractEntitiesFromFields } from "./conversation/coreference.js";
|
|
33
44
|
export { redactSecrets, listSecrets, clearSecrets, saveSecretsToFile, resolvePlaceholders } from "./conversation/secrets.js";
|
|
34
45
|
export { taskRunner, type BackgroundTask } from "./agents/taskRunner.js";
|
|
@@ -44,10 +55,21 @@ export { formatExplain } from "./utils/explain.js";
|
|
|
44
55
|
export { formatParsedCommand } from "./utils/output.js";
|
|
45
56
|
export { Spinner, withSpinner, progressBar } from "./utils/spinner.js";
|
|
46
57
|
export { createBackup, rollback, listBackups, cleanExpiredBackups, formatBackupList } from "./utils/autoBackup.js";
|
|
47
|
-
export { checkForUpdate, checkForUpdateSync, runUpdate, formatUpdateBanner, type UpdateInfo } from "./utils/updater.js";
|
|
58
|
+
export { checkForUpdate, checkForUpdateSync, runUpdate, formatUpdateBanner, isNewer, type UpdateInfo } from "./utils/updater.js";
|
|
48
59
|
export { detectProviders, formatStatus, goOffline, goOnline, disableLLM, enableLLM, isOfflineMode, isLLMDisabled, recordOfflineCommand, getTokensSaved, formatTokensSaved, formatTokensSavedBrief, saveOnExit, getSessionId, type LLMProvider, type LLMState, } from "./utils/llmManager.js";
|
|
49
60
|
export { getRecentSessions, getSessionsForFolder, formatSessionSummary, formatSessionList, type SessionSummary, } from "./utils/sessionSummary.js";
|
|
50
61
|
export { isSessionOpen, toggleSession, hideSession, unhideSession, getHiddenSessions, getLastViewedSession, createFullBackup, restoreFromBackup, listFullBackups, formatBackupsList, type BackupInfo, } from "./utils/sessionBackup.js";
|
|
62
|
+
export { analyzeFailure, type FailureAnalysis, } from "./utils/smartRetry.js";
|
|
63
|
+
export { suggestAction, getLastPendingAction, consumePendingAction, isAffirmation, isRedirectingPendingAction, clearPendingActions, type PendingAction, } from "./conversation/pendingActions.js";
|
|
64
|
+
export { parseMultiIntent, splitCompoundSentence, formatPlanSteps, type MultiIntentPlan, type PlanStep, } from "./nlp/multiIntent.js";
|
|
65
|
+
export { routeByConcepts, mergeConceptDomains, type ConceptRouterResult } from "./nlp/conceptRouter.js";
|
|
66
|
+
export { enrichVocabularyFromWiki, loadLearnedVocabulary, getEnrichedConcepts, type LearnedVocabulary, } from "./nlp/vocabularyBuilder.js";
|
|
67
|
+
export { commandExists, tryExec as shellTryExec, getTempDir, timestamp, fileSize, lineCount, shellExec, crossPlatformCmd, silenceStderr, isWin, getPlatformSummary, isAdmin, getSystemInstallCmd, } from "./utils/shellCompat.js";
|
|
68
|
+
export { trackInstall, getInstallHistory, getInstalledByType, getInstalledItem, untrackInstall, formatInstallHistory, getUninstallSteps, type InstalledItem, type InstallHistory, } from "./utils/installTracker.js";
|
|
69
|
+
export { searchWikidata, lookupUnknownNouns, formatWikiEntity, formatWikiSuggestions, type WikiEntity, type WikiLookupResult, } from "./nlp/wikidata.js";
|
|
70
|
+
export { detectGpu, detectImageEngines, getBestImageEngine, generateImage, getInstallPlan, installImageEngine, formatImageEngineStatus, getDriveInfo, resolveUserPath, type ImageEngine, type ImageEngineStatus, type GpuInfo, type GenerateResult, type DriveInfo, } from "./utils/imageGen.js";
|
|
71
|
+
export { scanProjects, summarizeDirectory, formatProjectList, formatDirSummary, type ProjectInfo, type DirSummary, } from "./utils/projectScanner.js";
|
|
72
|
+
export { detectBrowserEngines, getBestEngine, installBrowserEngine, browse, formatBrowserStatus, stopDockerBrowser, normalizeUrl, type BrowserEngine, type BrowserStatus, type BrowseOptions, type BrowseResult, type InstallResult, } from "./utils/browser.js";
|
|
51
73
|
export { logFailure, loadFailures, clearFailures } from "./utils/logger.js";
|
|
52
74
|
export { logUncertainty, loadUncertaintyLog, getUncertaintySummary } from "./nlp/uncertainty.js";
|
|
53
75
|
export { recordHistory, loadHistory, getRecentHistory, searchHistory } from "./context/history.js";
|
package/dist/index.js
CHANGED
|
@@ -13,14 +13,26 @@ export { parseByRules } from "./nlp/ruleParser.js";
|
|
|
13
13
|
export { disambiguate } from "./nlp/disambiguate.js";
|
|
14
14
|
export { classifyMulti } from "./nlp/multiClassifier.js";
|
|
15
15
|
export { semanticParse, tokenize, keyboardDistance, fuzzyMatch } from "./nlp/semantic.js";
|
|
16
|
+
export { findSimilarIntents, phraseSimilarity, expandWithCooccurrences } from "./nlp/semanticSimilarity.js";
|
|
17
|
+
export { loadKnowledgeGraph, saveKnowledgeGraph, addEntity, addRelation, getEntity, getRelated, resolveReference, resolveCandidates, inferIntent, queryGraph, rebuildGraph, learnFromExecution, flushGraph } from "./nlp/knowledgeGraph.js";
|
|
18
|
+
export { expandQuery, findCluster, suggestIntents, clusterWords } from "./nlp/conceptExpansion.js";
|
|
16
19
|
export { analyzeUncertainty, getUncoveredSpans } from "./nlp/uncertainty.js";
|
|
17
20
|
export { llmFallback, isLLMConfigured, getLLMBackend, formatLLMFallback } from "./nlp/llmFallback.js";
|
|
21
|
+
export { suggestEntityCorrection, correctEntities, resolveDescription, resetEntityVocab } from "./nlp/entitySpellCorrect.js";
|
|
22
|
+
export { recordOutcome, getMultiplier, calibrateVotes, recordCorrection, getCalibrationStats, flushCalibration } from "./nlp/confidenceCalibrator.js";
|
|
23
|
+
export { detectBatch, expandBatch, expandEnvironmentBatch } from "./nlp/batchParser.js";
|
|
24
|
+
export { getCurrentTopic, suggestFollowups, getTopicDefault } from "./conversation/topicTracker.js";
|
|
25
|
+
// ── Progress & History ──
|
|
26
|
+
export { progressReporter, reportProgress, reportStep } from "./utils/progressReporter.js";
|
|
27
|
+
export { loadHistory as loadCommandHistory, addToHistory, searchHistory as searchCommandHistory, getRecentCommands, getReadlineHistory } from "./utils/commandHistory.js";
|
|
18
28
|
// ── Execution ──
|
|
19
29
|
export { executeIntent } from "./handlers/executor.js";
|
|
20
30
|
export { runRemoteCommand, runLocalCommand } from "./execution/ssh.js";
|
|
21
31
|
// ── Config ──
|
|
22
32
|
export { loadRules, loadIntents, getIntentDef, loadHosts, getConfigDir } from "./utils/config.js";
|
|
23
33
|
export { CONFIG_DIR, DATA_DIR, LOG_DIR, PACKAGE_ROOT, USER_HOME, isSEA, ensureUserDirs } from "./utils/paths.js";
|
|
34
|
+
export { loadAliases, resolveAlias, saveAlias, removeAlias, listAliases } from "./utils/aliases.js";
|
|
35
|
+
export { buildCompletions, completeInput } from "./utils/completer.js";
|
|
24
36
|
// ── Platform & Detection ──
|
|
25
37
|
export { detectLocalPlatform, getInstallCommand, getServiceCommand, getPackageForCommand, formatPlatform } from "./utils/platform.js";
|
|
26
38
|
// ── Paths ──
|
|
@@ -35,7 +47,7 @@ export { smartRead, smartSearch, getFileInfo } from "./utils/smartFile.js";
|
|
|
35
47
|
export { parseFile, formatParsedFile, detectFileType } from "./parsers/index.js";
|
|
36
48
|
export { findKnownLocations, searchRemoteFile } from "./parsers/fileFinder.js";
|
|
37
49
|
// ── Conversation ──
|
|
38
|
-
export { getOrCreateConversation, addUserTurn, addSystemTurn, saveConversation, getLastEntity, getRecentEntities, listConversations } from "./conversation/store.js";
|
|
50
|
+
export { getOrCreateConversation, addUserTurn, addSystemTurn, saveConversation, getLastEntity, getRecentEntities, getRecentTurns, listConversations, loadContextFile, unloadContextFile, listContextFiles, setEntityFocus, getEntityFocus, getPreviousFocus, resolveFocusReference } from "./conversation/store.js";
|
|
39
51
|
export { resolveCoreferences, extractEntitiesFromFields } from "./conversation/coreference.js";
|
|
40
52
|
export { redactSecrets, listSecrets, clearSecrets, saveSecretsToFile, resolvePlaceholders } from "./conversation/secrets.js";
|
|
41
53
|
// ── Agents & Background ──
|
|
@@ -57,13 +69,35 @@ export { Spinner, withSpinner, progressBar } from "./utils/spinner.js";
|
|
|
57
69
|
// ── Auto-backup ──
|
|
58
70
|
export { createBackup, rollback, listBackups, cleanExpiredBackups, formatBackupList } from "./utils/autoBackup.js";
|
|
59
71
|
// ── Updates ──
|
|
60
|
-
export { checkForUpdate, checkForUpdateSync, runUpdate, formatUpdateBanner } from "./utils/updater.js";
|
|
72
|
+
export { checkForUpdate, checkForUpdateSync, runUpdate, formatUpdateBanner, isNewer } from "./utils/updater.js";
|
|
61
73
|
// ── LLM Manager ──
|
|
62
74
|
export { detectProviders, formatStatus, goOffline, goOnline, disableLLM, enableLLM, isOfflineMode, isLLMDisabled, recordOfflineCommand, getTokensSaved, formatTokensSaved, formatTokensSavedBrief, saveOnExit, getSessionId, } from "./utils/llmManager.js";
|
|
63
75
|
// ── Session Summaries ──
|
|
64
76
|
export { getRecentSessions, getSessionsForFolder, formatSessionSummary, formatSessionList, } from "./utils/sessionSummary.js";
|
|
65
77
|
// ── Session Backup & Prefs ──
|
|
66
78
|
export { isSessionOpen, toggleSession, hideSession, unhideSession, getHiddenSessions, getLastViewedSession, createFullBackup, restoreFromBackup, listFullBackups, formatBackupsList, } from "./utils/sessionBackup.js";
|
|
79
|
+
// ── Smart Retry ──
|
|
80
|
+
export { analyzeFailure, } from "./utils/smartRetry.js";
|
|
81
|
+
// ── Pending Actions ──
|
|
82
|
+
export { suggestAction, getLastPendingAction, consumePendingAction, isAffirmation, isRedirectingPendingAction, clearPendingActions, } from "./conversation/pendingActions.js";
|
|
83
|
+
// ── Multi-Intent ──
|
|
84
|
+
export { parseMultiIntent, splitCompoundSentence, formatPlanSteps, } from "./nlp/multiIntent.js";
|
|
85
|
+
// ── Concept Router ──
|
|
86
|
+
export { routeByConcepts, mergeConceptDomains } from "./nlp/conceptRouter.js";
|
|
87
|
+
// ── Vocabulary Builder ──
|
|
88
|
+
export { enrichVocabularyFromWiki, loadLearnedVocabulary, getEnrichedConcepts, } from "./nlp/vocabularyBuilder.js";
|
|
89
|
+
// ── Shell Compatibility ──
|
|
90
|
+
export { commandExists, tryExec as shellTryExec, getTempDir, timestamp, fileSize, lineCount, shellExec, crossPlatformCmd, silenceStderr, isWin, getPlatformSummary, isAdmin, getSystemInstallCmd, } from "./utils/shellCompat.js";
|
|
91
|
+
// ── Install Tracker ──
|
|
92
|
+
export { trackInstall, getInstallHistory, getInstalledByType, getInstalledItem, untrackInstall, formatInstallHistory, getUninstallSteps, } from "./utils/installTracker.js";
|
|
93
|
+
// ── Wikidata Knowledge Base ──
|
|
94
|
+
export { searchWikidata, lookupUnknownNouns, formatWikiEntity, formatWikiSuggestions, } from "./nlp/wikidata.js";
|
|
95
|
+
// ── Image Generation ──
|
|
96
|
+
export { detectGpu, detectImageEngines, getBestImageEngine, generateImage, getInstallPlan, installImageEngine, formatImageEngineStatus, getDriveInfo, resolveUserPath, } from "./utils/imageGen.js";
|
|
97
|
+
// ── Project Scanner ──
|
|
98
|
+
export { scanProjects, summarizeDirectory, formatProjectList, formatDirSummary, } from "./utils/projectScanner.js";
|
|
99
|
+
// ── Browser ──
|
|
100
|
+
export { detectBrowserEngines, getBestEngine, installBrowserEngine, browse, formatBrowserStatus, stopDockerBrowser, normalizeUrl, } from "./utils/browser.js";
|
|
67
101
|
// ── Logging ──
|
|
68
102
|
export { logFailure, loadFailures, clearFailures } from "./utils/logger.js";
|
|
69
103
|
export { logUncertainty, loadUncertaintyLog, getUncertaintySummary } from "./nlp/uncertainty.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch Parser — detect and expand batch commands.
|
|
3
|
+
*
|
|
4
|
+
* "restart nginx, redis, and mysql on prod"
|
|
5
|
+
* → 3 intents: restart nginx on prod, restart redis on prod, restart mysql on prod
|
|
6
|
+
*
|
|
7
|
+
* "check disk on prod, staging, and dev"
|
|
8
|
+
* → 3 intents: check disk on prod, check disk on staging, check disk on dev
|
|
9
|
+
*
|
|
10
|
+
* "stop containers api, worker, and scheduler"
|
|
11
|
+
* → 3 intents: stop container api, stop container worker, stop container scheduler
|
|
12
|
+
*/
|
|
13
|
+
export interface BatchExpansion {
|
|
14
|
+
isBatch: boolean;
|
|
15
|
+
commands: string[];
|
|
16
|
+
original: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Detect if input contains a batch/list of targets and expand.
|
|
20
|
+
*/
|
|
21
|
+
export declare function expandBatch(rawText: string): BatchExpansion;
|
|
22
|
+
/**
|
|
23
|
+
* Also handle "on X, Y, and Z" pattern:
|
|
24
|
+
* "check disk on prod, staging, and dev"
|
|
25
|
+
*/
|
|
26
|
+
export declare function expandEnvironmentBatch(rawText: string): BatchExpansion;
|
|
27
|
+
/**
|
|
28
|
+
* Try both batch patterns and return the first match.
|
|
29
|
+
*/
|
|
30
|
+
export declare function detectBatch(rawText: string): BatchExpansion;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch Parser — detect and expand batch commands.
|
|
3
|
+
*
|
|
4
|
+
* "restart nginx, redis, and mysql on prod"
|
|
5
|
+
* → 3 intents: restart nginx on prod, restart redis on prod, restart mysql on prod
|
|
6
|
+
*
|
|
7
|
+
* "check disk on prod, staging, and dev"
|
|
8
|
+
* → 3 intents: check disk on prod, check disk on staging, check disk on dev
|
|
9
|
+
*
|
|
10
|
+
* "stop containers api, worker, and scheduler"
|
|
11
|
+
* → 3 intents: stop container api, stop container worker, stop container scheduler
|
|
12
|
+
*/
|
|
13
|
+
// Patterns for comma-separated lists with "and"
|
|
14
|
+
const LIST_PATTERN = /^(.+?)\s+([\w-]+(?:\s*,\s*[\w-]+)*\s*(?:,?\s*and\s+[\w-]+))\s*(.*)$/i;
|
|
15
|
+
/**
|
|
16
|
+
* Detect if input contains a batch/list of targets and expand.
|
|
17
|
+
*/
|
|
18
|
+
export function expandBatch(rawText) {
|
|
19
|
+
const text = rawText.trim();
|
|
20
|
+
// Pattern: "verb targets, target2, and target3 modifier"
|
|
21
|
+
// E.g., "restart nginx, redis, and mysql on prod"
|
|
22
|
+
const match = text.match(LIST_PATTERN);
|
|
23
|
+
if (!match)
|
|
24
|
+
return { isBatch: false, commands: [text], original: text };
|
|
25
|
+
const prefix = match[1].trim(); // "restart"
|
|
26
|
+
const listPart = match[2].trim(); // "nginx, redis, and mysql"
|
|
27
|
+
const suffix = match[3].trim(); // "on prod"
|
|
28
|
+
// Parse the comma/and-separated list
|
|
29
|
+
const items = listPart
|
|
30
|
+
.replace(/\s+and\s+/gi, ", ")
|
|
31
|
+
.split(/\s*,\s*/)
|
|
32
|
+
.map(s => s.trim())
|
|
33
|
+
.filter(s => s.length > 0);
|
|
34
|
+
// Need at least 2 items for it to be a batch
|
|
35
|
+
if (items.length < 2)
|
|
36
|
+
return { isBatch: false, commands: [text], original: text };
|
|
37
|
+
// Verify these look like service/entity names (not random words)
|
|
38
|
+
const looksLikeEntities = items.every(item => /^[\w][\w.-]*$/.test(item) && item.length >= 2 && item.length <= 30);
|
|
39
|
+
if (!looksLikeEntities)
|
|
40
|
+
return { isBatch: false, commands: [text], original: text };
|
|
41
|
+
// Expand: "restart X on prod" for each item
|
|
42
|
+
const commands = items.map(item => `${prefix} ${item}${suffix ? ` ${suffix}` : ""}`);
|
|
43
|
+
return { isBatch: true, commands, original: text };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Also handle "on X, Y, and Z" pattern:
|
|
47
|
+
* "check disk on prod, staging, and dev"
|
|
48
|
+
*/
|
|
49
|
+
export function expandEnvironmentBatch(rawText) {
|
|
50
|
+
const text = rawText.trim();
|
|
51
|
+
// Pattern: "command on env1, env2, and env3"
|
|
52
|
+
const match = text.match(/^(.+?)\s+on\s+([\w-]+(?:\s*,\s*[\w-]+)*\s*(?:,?\s*and\s+[\w-]+))$/i);
|
|
53
|
+
if (!match)
|
|
54
|
+
return { isBatch: false, commands: [text], original: text };
|
|
55
|
+
const command = match[1].trim();
|
|
56
|
+
const envPart = match[2].trim();
|
|
57
|
+
const envs = envPart
|
|
58
|
+
.replace(/\s+and\s+/gi, ", ")
|
|
59
|
+
.split(/\s*,\s*/)
|
|
60
|
+
.map(s => s.trim())
|
|
61
|
+
.filter(s => s.length > 0);
|
|
62
|
+
if (envs.length < 2)
|
|
63
|
+
return { isBatch: false, commands: [text], original: text };
|
|
64
|
+
const commands = envs.map(env => `${command} on ${env}`);
|
|
65
|
+
return { isBatch: true, commands, original: text };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Try both batch patterns and return the first match.
|
|
69
|
+
*/
|
|
70
|
+
export function detectBatch(rawText) {
|
|
71
|
+
// Try environment batch first ("check disk on prod, staging, and dev")
|
|
72
|
+
const envBatch = expandEnvironmentBatch(rawText);
|
|
73
|
+
if (envBatch.isBatch)
|
|
74
|
+
return envBatch;
|
|
75
|
+
// Then try entity batch ("restart nginx, redis, and mysql")
|
|
76
|
+
return expandBatch(rawText);
|
|
77
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concept expansion module.
|
|
3
|
+
*
|
|
4
|
+
* Auto-expands concepts so the classifier catches more natural language
|
|
5
|
+
* variations. Synonym clusters and domain mappings are stored in
|
|
6
|
+
* config/concept-clusters.json so users can extend them.
|
|
7
|
+
*
|
|
8
|
+
* Main exports:
|
|
9
|
+
* - expandQuery(text) — appends synonym keywords for scoring
|
|
10
|
+
* - findCluster(word) — returns the cluster name a word belongs to
|
|
11
|
+
* - suggestIntents(word) — maps a concept cluster to likely intent domains
|
|
12
|
+
*/
|
|
13
|
+
/** Force-reload config (useful after user edits the JSON). */
|
|
14
|
+
export declare function reloadConfig(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Find which cluster a word belongs to.
|
|
17
|
+
* Returns the canonical cluster name, or undefined if no match.
|
|
18
|
+
*
|
|
19
|
+
* findCluster("reboot") → "restart"
|
|
20
|
+
* findCluster("hello") → undefined
|
|
21
|
+
*/
|
|
22
|
+
export declare function findCluster(word: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Expand a query by appending synonym keywords from every cluster
|
|
25
|
+
* that matches a token in the text. The original text is preserved;
|
|
26
|
+
* extra tokens are appended (space-separated) for scoring purposes.
|
|
27
|
+
*
|
|
28
|
+
* expandQuery("reboot the server")
|
|
29
|
+
* → "reboot the server restart cycle reload bounce"
|
|
30
|
+
*/
|
|
31
|
+
export declare function expandQuery(text: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Given a word, find its cluster, then return the intent domain patterns
|
|
34
|
+
* whose concept list includes that cluster.
|
|
35
|
+
*
|
|
36
|
+
* suggestIntents("reboot")
|
|
37
|
+
* → ["service.*", "docker.*"] (domains that list "restart")
|
|
38
|
+
*
|
|
39
|
+
* suggestIntents("hello")
|
|
40
|
+
* → []
|
|
41
|
+
*/
|
|
42
|
+
export declare function suggestIntents(word: string): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Return all clusters that are relevant to a given intent domain.
|
|
45
|
+
*
|
|
46
|
+
* clustersForDomain("docker.restart") → ["restart", "stop", "start", "show"]
|
|
47
|
+
*/
|
|
48
|
+
export declare function clustersForDomain(intentId: string): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Get all synonyms for a cluster (including the canonical name).
|
|
51
|
+
*
|
|
52
|
+
* clusterWords("restart") → ["restart", "reboot", "bounce", "cycle", "reload"]
|
|
53
|
+
*/
|
|
54
|
+
export declare function clusterWords(clusterName: string): string[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concept expansion module.
|
|
3
|
+
*
|
|
4
|
+
* Auto-expands concepts so the classifier catches more natural language
|
|
5
|
+
* variations. Synonym clusters and domain mappings are stored in
|
|
6
|
+
* config/concept-clusters.json so users can extend them.
|
|
7
|
+
*
|
|
8
|
+
* Main exports:
|
|
9
|
+
* - expandQuery(text) — appends synonym keywords for scoring
|
|
10
|
+
* - findCluster(word) — returns the cluster name a word belongs to
|
|
11
|
+
* - suggestIntents(word) — maps a concept cluster to likely intent domains
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
import { resolve, dirname } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
// ─── Load config ─────────────────────────────────────────────────────────────
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const CONFIG_PATH = resolve(__dirname, "../../config/concept-clusters.json");
|
|
19
|
+
let config;
|
|
20
|
+
function loadConfig() {
|
|
21
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
function getConfig() {
|
|
25
|
+
if (!config)
|
|
26
|
+
config = loadConfig();
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
/** Force-reload config (useful after user edits the JSON). */
|
|
30
|
+
export function reloadConfig() {
|
|
31
|
+
config = loadConfig();
|
|
32
|
+
}
|
|
33
|
+
// ─── Synonym lookup (built lazily) ──────────────────────────────────────────
|
|
34
|
+
/** Reverse index: synonym word → cluster name. Built once on first access. */
|
|
35
|
+
let reverseIndex;
|
|
36
|
+
function getReverseIndex() {
|
|
37
|
+
if (reverseIndex)
|
|
38
|
+
return reverseIndex;
|
|
39
|
+
reverseIndex = new Map();
|
|
40
|
+
const clusters = getConfig().synonymClusters;
|
|
41
|
+
for (const [canonical, synonyms] of Object.entries(clusters)) {
|
|
42
|
+
reverseIndex.set(canonical, canonical);
|
|
43
|
+
for (const s of synonyms) {
|
|
44
|
+
reverseIndex.set(s.toLowerCase(), canonical);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return reverseIndex;
|
|
48
|
+
}
|
|
49
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
50
|
+
/**
|
|
51
|
+
* Find which cluster a word belongs to.
|
|
52
|
+
* Returns the canonical cluster name, or undefined if no match.
|
|
53
|
+
*
|
|
54
|
+
* findCluster("reboot") → "restart"
|
|
55
|
+
* findCluster("hello") → undefined
|
|
56
|
+
*/
|
|
57
|
+
export function findCluster(word) {
|
|
58
|
+
return getReverseIndex().get(word.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Expand a query by appending synonym keywords from every cluster
|
|
62
|
+
* that matches a token in the text. The original text is preserved;
|
|
63
|
+
* extra tokens are appended (space-separated) for scoring purposes.
|
|
64
|
+
*
|
|
65
|
+
* expandQuery("reboot the server")
|
|
66
|
+
* → "reboot the server restart cycle reload bounce"
|
|
67
|
+
*/
|
|
68
|
+
export function expandQuery(text) {
|
|
69
|
+
const clusters = getConfig().synonymClusters;
|
|
70
|
+
const idx = getReverseIndex();
|
|
71
|
+
const tokens = text.toLowerCase().split(/\s+/);
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
const extras = [];
|
|
74
|
+
for (const tok of tokens) {
|
|
75
|
+
const cluster = idx.get(tok);
|
|
76
|
+
if (!cluster || seen.has(cluster))
|
|
77
|
+
continue;
|
|
78
|
+
seen.add(cluster);
|
|
79
|
+
// Append canonical name + all synonyms that aren't already in the text
|
|
80
|
+
const all = [cluster, ...clusters[cluster]];
|
|
81
|
+
for (const w of all) {
|
|
82
|
+
const lower = w.toLowerCase();
|
|
83
|
+
if (!tokens.includes(lower))
|
|
84
|
+
extras.push(lower);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return extras.length ? `${text} ${extras.join(" ")}` : text;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Given a word, find its cluster, then return the intent domain patterns
|
|
91
|
+
* whose concept list includes that cluster.
|
|
92
|
+
*
|
|
93
|
+
* suggestIntents("reboot")
|
|
94
|
+
* → ["service.*", "docker.*"] (domains that list "restart")
|
|
95
|
+
*
|
|
96
|
+
* suggestIntents("hello")
|
|
97
|
+
* → []
|
|
98
|
+
*/
|
|
99
|
+
export function suggestIntents(word) {
|
|
100
|
+
const cluster = findCluster(word);
|
|
101
|
+
if (!cluster)
|
|
102
|
+
return [];
|
|
103
|
+
const domains = getConfig().domainConcepts;
|
|
104
|
+
const matches = [];
|
|
105
|
+
for (const [pattern, concepts] of Object.entries(domains)) {
|
|
106
|
+
if (concepts.includes(cluster))
|
|
107
|
+
matches.push(pattern);
|
|
108
|
+
}
|
|
109
|
+
return matches;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Return all clusters that are relevant to a given intent domain.
|
|
113
|
+
*
|
|
114
|
+
* clustersForDomain("docker.restart") → ["restart", "stop", "start", "show"]
|
|
115
|
+
*/
|
|
116
|
+
export function clustersForDomain(intentId) {
|
|
117
|
+
const domains = getConfig().domainConcepts;
|
|
118
|
+
for (const [pattern, concepts] of Object.entries(domains)) {
|
|
119
|
+
const re = new RegExp("^" + pattern.replace(/\./g, "\\.").replace(/\*/g, ".*") + "$");
|
|
120
|
+
if (re.test(intentId))
|
|
121
|
+
return concepts;
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get all synonyms for a cluster (including the canonical name).
|
|
127
|
+
*
|
|
128
|
+
* clusterWords("restart") → ["restart", "reboot", "bounce", "cycle", "reload"]
|
|
129
|
+
*/
|
|
130
|
+
export function clusterWords(clusterName) {
|
|
131
|
+
const clusters = getConfig().synonymClusters;
|
|
132
|
+
const syns = clusters[clusterName];
|
|
133
|
+
if (!syns)
|
|
134
|
+
return [];
|
|
135
|
+
return [clusterName, ...syns];
|
|
136
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concept-based intent router.
|
|
3
|
+
*
|
|
4
|
+
* Instead of matching exact synonym phrases, this extracts concepts
|
|
5
|
+
* from the user's input and routes to the right intent domain.
|
|
6
|
+
*
|
|
7
|
+
* How it works:
|
|
8
|
+
* 1. Tokenize with compromise (POS tags)
|
|
9
|
+
* 2. Extract: action verbs, subject nouns, attribute adjectives, question type
|
|
10
|
+
* 3. Map concepts to intent domains via a concept→domain map
|
|
11
|
+
* 4. Pick the best intent within that domain
|
|
12
|
+
*
|
|
13
|
+
* This handles:
|
|
14
|
+
* "is this happening offline or locally is it free or using cloud?"
|
|
15
|
+
* → concepts: [offline, local, free, cloud] → domain: ai.image_status
|
|
16
|
+
*
|
|
17
|
+
* "can you check what crontabs I have running"
|
|
18
|
+
* → action: check, subject: crontabs → domain: cron.list
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Merge additional concept→domain mappings into the router at runtime.
|
|
22
|
+
* Used by the vocabulary builder to inject learned concepts.
|
|
23
|
+
* Existing domains for a concept are preserved; new ones are appended.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeConceptDomains(mappings: Record<string, string[]>): void;
|
|
26
|
+
export interface DependencyRouteResult {
|
|
27
|
+
intent: string;
|
|
28
|
+
confidence: number;
|
|
29
|
+
verb: string;
|
|
30
|
+
object?: string;
|
|
31
|
+
location?: string;
|
|
32
|
+
reason: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Route by parsing dependency structure (SVO triples).
|
|
36
|
+
* Maps verb+object combinations to specific intents with graduated confidence.
|
|
37
|
+
*/
|
|
38
|
+
export declare function routeByDependencies(rawText: string): DependencyRouteResult | null;
|
|
39
|
+
export interface ConceptRouterResult {
|
|
40
|
+
intent: string;
|
|
41
|
+
confidence: number;
|
|
42
|
+
concepts: string[];
|
|
43
|
+
isQuestion: boolean;
|
|
44
|
+
reason: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Route user input to intent by understanding concepts, not matching phrases.
|
|
48
|
+
*/
|
|
49
|
+
export declare function routeByConcepts(rawText: string): ConceptRouterResult | null;
|