notoken-core 1.6.0 → 1.8.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 (123) hide show
  1. package/config/ascii-art.json +12 -0
  2. package/config/chat-responses.json +1019 -0
  3. package/config/cheat-sheets.json +94 -0
  4. package/config/concept-clusters.json +31 -0
  5. package/config/daily-tips.json +105 -0
  6. package/config/entities.json +93 -0
  7. package/config/history-today.json +9762 -0
  8. package/config/image-prompts.json +20 -0
  9. package/config/intent-vectors.json +1 -0
  10. package/config/intents.json +5354 -85
  11. package/config/ollama-models.json +193 -0
  12. package/config/rules.json +32 -1
  13. package/config/startup-quotes.json +45 -0
  14. package/dist/automation/discordPatchright.d.ts +35 -0
  15. package/dist/automation/discordPatchright.js +424 -0
  16. package/dist/automation/discordSetup.d.ts +31 -0
  17. package/dist/automation/discordSetup.js +338 -0
  18. package/dist/automation/smAutomation.d.ts +82 -0
  19. package/dist/automation/smAutomation.js +448 -0
  20. package/dist/conversation/coreference.js +44 -4
  21. package/dist/conversation/pendingActions.d.ts +55 -0
  22. package/dist/conversation/pendingActions.js +127 -0
  23. package/dist/conversation/store.d.ts +72 -0
  24. package/dist/conversation/store.js +140 -1
  25. package/dist/conversation/topicTracker.d.ts +36 -0
  26. package/dist/conversation/topicTracker.js +141 -0
  27. package/dist/execution/ssh.d.ts +42 -1
  28. package/dist/execution/ssh.js +538 -3
  29. package/dist/handlers/executor.d.ts +2 -0
  30. package/dist/handlers/executor.js +4234 -31
  31. package/dist/index.d.ts +35 -4
  32. package/dist/index.js +51 -3
  33. package/dist/nlp/batchParser.d.ts +30 -0
  34. package/dist/nlp/batchParser.js +77 -0
  35. package/dist/nlp/conceptExpansion.d.ts +54 -0
  36. package/dist/nlp/conceptExpansion.js +136 -0
  37. package/dist/nlp/conceptRouter.d.ts +49 -0
  38. package/dist/nlp/conceptRouter.js +302 -0
  39. package/dist/nlp/confidenceCalibrator.d.ts +62 -0
  40. package/dist/nlp/confidenceCalibrator.js +116 -0
  41. package/dist/nlp/correctionLearner.d.ts +45 -0
  42. package/dist/nlp/correctionLearner.js +207 -0
  43. package/dist/nlp/entitySpellCorrect.d.ts +35 -0
  44. package/dist/nlp/entitySpellCorrect.js +141 -0
  45. package/dist/nlp/knowledgeGraph.d.ts +70 -0
  46. package/dist/nlp/knowledgeGraph.js +380 -0
  47. package/dist/nlp/llmFallback.js +28 -1
  48. package/dist/nlp/multiClassifier.js +91 -6
  49. package/dist/nlp/multiIntent.d.ts +43 -0
  50. package/dist/nlp/multiIntent.js +154 -0
  51. package/dist/nlp/parseIntent.d.ts +6 -1
  52. package/dist/nlp/parseIntent.js +180 -5
  53. package/dist/nlp/ruleParser.js +317 -0
  54. package/dist/nlp/semanticSimilarity.d.ts +30 -0
  55. package/dist/nlp/semanticSimilarity.js +174 -0
  56. package/dist/nlp/vocabularyBuilder.d.ts +43 -0
  57. package/dist/nlp/vocabularyBuilder.js +224 -0
  58. package/dist/nlp/wikidata.d.ts +49 -0
  59. package/dist/nlp/wikidata.js +228 -0
  60. package/dist/policy/confirm.d.ts +10 -0
  61. package/dist/policy/confirm.js +39 -0
  62. package/dist/policy/safety.js +6 -4
  63. package/dist/types/intent.d.ts +8 -0
  64. package/dist/types/intent.js +1 -0
  65. package/dist/utils/achievements.d.ts +38 -0
  66. package/dist/utils/achievements.js +126 -0
  67. package/dist/utils/aliases.d.ts +5 -0
  68. package/dist/utils/aliases.js +39 -0
  69. package/dist/utils/analysis.js +71 -15
  70. package/dist/utils/bookmarks.d.ts +13 -0
  71. package/dist/utils/bookmarks.js +51 -0
  72. package/dist/utils/browser.d.ts +64 -0
  73. package/dist/utils/browser.js +364 -0
  74. package/dist/utils/commandHistory.d.ts +20 -0
  75. package/dist/utils/commandHistory.js +108 -0
  76. package/dist/utils/completer.d.ts +17 -0
  77. package/dist/utils/completer.js +79 -0
  78. package/dist/utils/config.js +32 -2
  79. package/dist/utils/dbQuery.d.ts +25 -0
  80. package/dist/utils/dbQuery.js +248 -0
  81. package/dist/utils/devTools.d.ts +35 -0
  82. package/dist/utils/devTools.js +95 -0
  83. package/dist/utils/discordDiag.d.ts +35 -0
  84. package/dist/utils/discordDiag.js +826 -0
  85. package/dist/utils/diskCleanup.d.ts +36 -0
  86. package/dist/utils/diskCleanup.js +775 -0
  87. package/dist/utils/entityResolver.d.ts +107 -0
  88. package/dist/utils/entityResolver.js +468 -0
  89. package/dist/utils/imageGen.d.ts +92 -0
  90. package/dist/utils/imageGen.js +2031 -0
  91. package/dist/utils/installTracker.d.ts +57 -0
  92. package/dist/utils/installTracker.js +160 -0
  93. package/dist/utils/multiExec.d.ts +21 -0
  94. package/dist/utils/multiExec.js +141 -0
  95. package/dist/utils/openclawDiag.d.ts +29 -0
  96. package/dist/utils/openclawDiag.js +1035 -0
  97. package/dist/utils/output.js +4 -0
  98. package/dist/utils/platform.js +2 -1
  99. package/dist/utils/progressReporter.d.ts +50 -0
  100. package/dist/utils/progressReporter.js +58 -0
  101. package/dist/utils/projectDetect.d.ts +44 -0
  102. package/dist/utils/projectDetect.js +319 -0
  103. package/dist/utils/projectScanner.d.ts +44 -0
  104. package/dist/utils/projectScanner.js +312 -0
  105. package/dist/utils/shellCompat.d.ts +78 -0
  106. package/dist/utils/shellCompat.js +186 -0
  107. package/dist/utils/smartArchive.d.ts +16 -0
  108. package/dist/utils/smartArchive.js +172 -0
  109. package/dist/utils/smartRetry.d.ts +26 -0
  110. package/dist/utils/smartRetry.js +114 -0
  111. package/dist/utils/snippets.d.ts +13 -0
  112. package/dist/utils/snippets.js +53 -0
  113. package/dist/utils/stabilityMatrixManager.d.ts +80 -0
  114. package/dist/utils/stabilityMatrixManager.js +268 -0
  115. package/dist/utils/teachMode.d.ts +41 -0
  116. package/dist/utils/teachMode.js +100 -0
  117. package/dist/utils/timer.d.ts +22 -0
  118. package/dist/utils/timer.js +52 -0
  119. package/dist/utils/updater.d.ts +1 -0
  120. package/dist/utils/updater.js +1 -1
  121. package/dist/utils/version.d.ts +20 -0
  122. package/dist/utils/version.js +212 -0
  123. package/package.json +6 -3
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Version check and self-upgrade utilities.
3
+ *
4
+ * Checks npm registry for latest published version and compares
5
+ * with the locally installed version.
6
+ */
7
+ import { execSync } from "node:child_process";
8
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
9
+ import { resolve, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { homedir } from "node:os";
12
+ const c = {
13
+ reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m",
14
+ green: "\x1b[32m", yellow: "\x1b[33m", red: "\x1b[31m", cyan: "\x1b[36m",
15
+ };
16
+ /** Get the current local version from package.json. */
17
+ export function getLocalVersion() {
18
+ try {
19
+ // Try relative to this file first (works in dist/)
20
+ const pkgPath = resolve(dirname(fileURLToPath(import.meta.url)), "../../package.json");
21
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
22
+ return pkg.version ?? "unknown";
23
+ }
24
+ catch {
25
+ return "unknown";
26
+ }
27
+ }
28
+ /** Fetch the latest version from npm registry (non-blocking, best-effort). */
29
+ export async function getLatestVersion() {
30
+ try {
31
+ const result = execSync("npm view notoken version 2>/dev/null", {
32
+ encoding: "utf-8",
33
+ timeout: 10_000,
34
+ }).trim();
35
+ return result || null;
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ /** Compare two semver strings. Returns 1 if a > b, -1 if a < b, 0 if equal. */
42
+ export function compareSemver(a, b) {
43
+ const pa = a.split(".").map(Number);
44
+ const pb = b.split(".").map(Number);
45
+ for (let i = 0; i < 3; i++) {
46
+ if ((pa[i] ?? 0) > (pb[i] ?? 0))
47
+ return 1;
48
+ if ((pa[i] ?? 0) < (pb[i] ?? 0))
49
+ return -1;
50
+ }
51
+ return 0;
52
+ }
53
+ /** Check if an update is available. Returns formatted message or null. */
54
+ export async function checkForUpdate() {
55
+ const local = getLocalVersion();
56
+ if (local === "unknown")
57
+ return null;
58
+ const latest = await getLatestVersion();
59
+ if (!latest)
60
+ return null;
61
+ if (compareSemver(latest, local) > 0) {
62
+ return `${c.yellow}Update available: ${c.bold}v${local}${c.reset}${c.yellow} → ${c.bold}${c.green}v${latest}${c.reset}${c.yellow} Run: ${c.cyan}notoken upgrade${c.reset}`;
63
+ }
64
+ return null;
65
+ }
66
+ // ─── Version history ─────────────────────────────────────────────────────────
67
+ const VERSION_HISTORY_PATH = resolve(homedir(), ".notoken", "version-history.json");
68
+ function loadVersionHistory() {
69
+ try {
70
+ if (existsSync(VERSION_HISTORY_PATH)) {
71
+ return JSON.parse(readFileSync(VERSION_HISTORY_PATH, "utf-8"));
72
+ }
73
+ }
74
+ catch { }
75
+ return [];
76
+ }
77
+ function saveVersionHistory(history) {
78
+ const dir = dirname(VERSION_HISTORY_PATH);
79
+ if (!existsSync(dir))
80
+ mkdirSync(dir, { recursive: true });
81
+ writeFileSync(VERSION_HISTORY_PATH, JSON.stringify(history, null, 2) + "\n");
82
+ }
83
+ function recordVersion(version, action) {
84
+ const history = loadVersionHistory();
85
+ history.push({ version, date: new Date().toISOString(), action });
86
+ // Keep last 20 entries
87
+ if (history.length > 20)
88
+ history.splice(0, history.length - 20);
89
+ saveVersionHistory(history);
90
+ }
91
+ /** Get the previous version from history. */
92
+ function getPreviousVersion() {
93
+ const history = loadVersionHistory();
94
+ // Find the second-to-last unique version
95
+ const versions = [...new Set(history.map((h) => h.version))];
96
+ return versions.length >= 2 ? versions[versions.length - 2] : null;
97
+ }
98
+ // ─── Upgrade ─────────────────────────────────────────────────────────────────
99
+ /** Run the upgrade. Records current version before upgrading for rollback. */
100
+ export async function runUpgrade() {
101
+ const local = getLocalVersion();
102
+ const latest = await getLatestVersion();
103
+ console.log(`${c.bold}notoken upgrade${c.reset}\n`);
104
+ console.log(` Current version: ${c.bold}v${local}${c.reset}`);
105
+ if (!latest) {
106
+ console.log(` ${c.yellow}Could not check npm registry.${c.reset}`);
107
+ console.log(` ${c.dim}Try manually: npm install -g notoken@latest${c.reset}`);
108
+ return;
109
+ }
110
+ console.log(` Latest version: ${c.bold}v${latest}${c.reset}`);
111
+ if (compareSemver(latest, local) <= 0) {
112
+ console.log(`\n ${c.green}✓ Already up to date.${c.reset}`);
113
+ return;
114
+ }
115
+ // Record current version before upgrading
116
+ recordVersion(local, "upgrade");
117
+ console.log(`\n ${c.cyan}Upgrading v${local} → v${latest}...${c.reset}`);
118
+ console.log(` ${c.dim}Previous version saved — run "notoken rollback" to revert.${c.reset}\n`);
119
+ try {
120
+ execSync("npm install -g notoken@latest", {
121
+ stdio: "inherit",
122
+ timeout: 120_000,
123
+ });
124
+ recordVersion(latest, "upgrade");
125
+ console.log(`\n ${c.green}✓ Upgraded to v${latest}${c.reset}`);
126
+ console.log(` ${c.dim}If something breaks: notoken rollback${c.reset}`);
127
+ }
128
+ catch (err) {
129
+ const msg = err instanceof Error ? err.message : String(err);
130
+ console.error(`\n ${c.red}✗ Upgrade failed: ${msg.split("\n")[0]}${c.reset}`);
131
+ console.error(` ${c.dim}Try manually: npm install -g notoken@latest${c.reset}`);
132
+ }
133
+ }
134
+ // ─── Rollback ────────────────────────────────────────────────────────────────
135
+ /** Roll back to the previous version. */
136
+ export async function runRollback(targetVersion) {
137
+ const local = getLocalVersion();
138
+ console.log(`${c.bold}notoken rollback${c.reset}\n`);
139
+ console.log(` Current version: ${c.bold}v${local}${c.reset}`);
140
+ // Determine target version
141
+ let target = targetVersion;
142
+ if (!target) {
143
+ target = getPreviousVersion() ?? undefined;
144
+ }
145
+ if (!target) {
146
+ // No history — list available versions for the user to pick
147
+ console.log(` ${c.yellow}No previous version in history.${c.reset}\n`);
148
+ console.log(` ${c.bold}Available versions:${c.reset}`);
149
+ await listVersions();
150
+ console.log(`\n ${c.dim}To rollback to a specific version:${c.reset}`);
151
+ console.log(` ${c.cyan}notoken rollback 1.0.1${c.reset}`);
152
+ return;
153
+ }
154
+ if (target === local) {
155
+ console.log(` ${c.green}✓ Already on v${target}.${c.reset}`);
156
+ return;
157
+ }
158
+ console.log(` Rolling back to: ${c.bold}v${target}${c.reset}\n`);
159
+ try {
160
+ execSync(`npm install -g notoken@${target}`, {
161
+ stdio: "inherit",
162
+ timeout: 120_000,
163
+ });
164
+ recordVersion(target, "rollback");
165
+ console.log(`\n ${c.green}✓ Rolled back to v${target}${c.reset}`);
166
+ }
167
+ catch (err) {
168
+ const msg = err instanceof Error ? err.message : String(err);
169
+ console.error(`\n ${c.red}✗ Rollback failed: ${msg.split("\n")[0]}${c.reset}`);
170
+ console.error(` ${c.dim}Try manually: npm install -g notoken@${target}${c.reset}`);
171
+ }
172
+ }
173
+ /** List recent published versions from npm. */
174
+ async function listVersions() {
175
+ try {
176
+ const result = execSync("npm view notoken versions --json 2>/dev/null", {
177
+ encoding: "utf-8",
178
+ timeout: 10_000,
179
+ }).trim();
180
+ const versions = JSON.parse(result);
181
+ const recent = versions.slice(-10).reverse();
182
+ const local = getLocalVersion();
183
+ for (const v of recent) {
184
+ const marker = v === local ? ` ${c.green}← current${c.reset}` : "";
185
+ console.log(` ${c.cyan}v${v}${c.reset}${marker}`);
186
+ }
187
+ }
188
+ catch {
189
+ console.log(` ${c.yellow}Could not fetch versions from npm.${c.reset}`);
190
+ }
191
+ }
192
+ /** Show version history. */
193
+ export function showVersionHistory() {
194
+ const history = loadVersionHistory();
195
+ console.log(`${c.bold}notoken version history${c.reset}\n`);
196
+ console.log(` Current: ${c.bold}v${getLocalVersion()}${c.reset}\n`);
197
+ if (history.length === 0) {
198
+ console.log(` ${c.dim}No upgrade/rollback history yet.${c.reset}`);
199
+ return;
200
+ }
201
+ for (const entry of history.slice(-10).reverse()) {
202
+ const icon = entry.action === "upgrade" ? `${c.green}↑${c.reset}` :
203
+ entry.action === "rollback" ? `${c.yellow}↓${c.reset}` :
204
+ `${c.cyan}•${c.reset}`;
205
+ const date = new Date(entry.date).toLocaleDateString();
206
+ console.log(` ${icon} v${entry.version} ${c.dim}${date} ${entry.action}${c.reset}`);
207
+ }
208
+ const prev = getPreviousVersion();
209
+ if (prev) {
210
+ console.log(`\n ${c.dim}To rollback: ${c.cyan}notoken rollback${c.reset} ${c.dim}(→ v${prev})${c.reset}`);
211
+ }
212
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "notoken-core",
3
- "version": "1.6.0",
4
- "description": "Shared engine for notoken NLP parsing, execution, detection, analysis",
3
+ "version": "1.8.0",
4
+ "description": "Shared engine for notoken \u2014 NLP parsing, execution, detection, analysis",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Dino Bartolome",
@@ -25,18 +25,21 @@
25
25
  "test": "vitest run"
26
26
  },
27
27
  "dependencies": {
28
+ "@types/ssh2": "^1.15.5",
28
29
  "compromise": "^14.15.0",
29
30
  "dotenv": "^17.3.1",
30
31
  "simple-git": "^3.33.0",
32
+ "ssh2": "^1.17.0",
31
33
  "yaml": "^2.8.3",
32
34
  "zod": "^3.22.0"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@types/node": "^20.0.0",
38
+ "playwright": "^1.59.1",
36
39
  "typescript": "^5.3.0",
37
40
  "vitest": "^1.6.1"
38
41
  },
39
42
  "engines": {
40
43
  "node": ">=18"
41
44
  }
42
- }
45
+ }