micro-models-agent 0.28.9 → 0.29.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 (167) hide show
  1. package/dist/cli/commands.js +220 -0
  2. package/dist/cli/completer.js +168 -0
  3. package/dist/cli/index.js +2 -0
  4. package/dist/cli/main.js +113 -0
  5. package/dist/cli/repl.js +987 -0
  6. package/dist/cli/security-commands.js +166 -0
  7. package/dist/cli/setup.js +229 -0
  8. package/dist/config/config.js +186 -0
  9. package/dist/config/defaults.js +91 -0
  10. package/dist/config/experts.js +15 -0
  11. package/dist/config/index.js +3 -0
  12. package/dist/config/security.js +193 -0
  13. package/dist/config/types.js +1 -0
  14. package/dist/core/agent-moe.js +98 -0
  15. package/dist/core/agent.js +461 -0
  16. package/dist/core/bootstrap.js +321 -0
  17. package/dist/core/index.js +2 -0
  18. package/dist/core/prompt-builder.js +55 -0
  19. package/dist/core/session-logger.js +122 -0
  20. package/dist/core/types.js +1 -0
  21. package/dist/i18n/en.json +461 -0
  22. package/dist/i18n/index.js +43 -0
  23. package/dist/i18n/ru.json +461 -0
  24. package/dist/index.js +22 -0
  25. package/dist/llm/image-utils.js +144 -0
  26. package/dist/llm/index.js +4 -0
  27. package/dist/llm/model-loader.js +78 -0
  28. package/dist/llm/openai-compat.js +324 -0
  29. package/dist/llm/orchestrator.js +194 -0
  30. package/dist/llm/provider.js +10 -0
  31. package/dist/llm/response.js +39 -0
  32. package/dist/llm/token-counter.js +39 -0
  33. package/dist/llm/types.js +1 -0
  34. package/dist/logger/app-logger.js +76 -0
  35. package/dist/logger/index.js +1 -0
  36. package/dist/main.js +2251 -724
  37. package/dist/migration/backup.js +45 -0
  38. package/dist/migration/detect.js +50 -0
  39. package/dist/migration/index.js +2 -0
  40. package/dist/modules/browser/actions.js +46 -0
  41. package/dist/modules/browser/cookie-store.js +24 -0
  42. package/dist/modules/browser/index.js +5 -0
  43. package/dist/modules/browser/module.js +28 -0
  44. package/dist/modules/browser/session.js +287 -0
  45. package/dist/modules/browser/snapshot.js +114 -0
  46. package/dist/modules/browser/types.js +9 -0
  47. package/dist/modules/context/history.js +15 -0
  48. package/dist/modules/context/index.js +1 -0
  49. package/dist/modules/context/manager.js +240 -0
  50. package/dist/modules/execution/auditor.js +72 -0
  51. package/dist/modules/execution/index.js +6 -0
  52. package/dist/modules/execution/module.js +337 -0
  53. package/dist/modules/execution/moe-executor.js +209 -0
  54. package/dist/modules/execution/plan-validator.js +153 -0
  55. package/dist/modules/execution/planner.js +35 -0
  56. package/dist/modules/execution/stuck-detector.js +134 -0
  57. package/dist/modules/execution/tracker.js +53 -0
  58. package/dist/modules/execution/types.js +1 -0
  59. package/dist/modules/execution/verifier.js +149 -0
  60. package/dist/modules/hallucination/confidence.js +54 -0
  61. package/dist/modules/hallucination/consistency.js +60 -0
  62. package/dist/modules/hallucination/detector.js +41 -0
  63. package/dist/modules/hallucination/factual.js +170 -0
  64. package/dist/modules/hallucination/index.js +4 -0
  65. package/dist/modules/index.js +5 -0
  66. package/dist/modules/indexer/cache.js +38 -0
  67. package/dist/modules/indexer/index.js +3 -0
  68. package/dist/modules/indexer/module.js +192 -0
  69. package/dist/modules/indexer/walker.js +101 -0
  70. package/dist/modules/mcp/client.js +393 -0
  71. package/dist/modules/mcp/index.js +3 -0
  72. package/dist/modules/mcp/module.js +146 -0
  73. package/dist/modules/mcp/registry.js +15 -0
  74. package/dist/modules/memory/index.js +1 -0
  75. package/dist/modules/memory/module.js +48 -0
  76. package/dist/modules/memory/search.js +40 -0
  77. package/dist/modules/memory/store.js +65 -0
  78. package/dist/modules/pipelines/engine.js +60 -0
  79. package/dist/modules/pipelines/index.js +3 -0
  80. package/dist/modules/pipelines/parser.js +53 -0
  81. package/dist/modules/pipelines/template.js +14 -0
  82. package/dist/modules/plugins/builtin/lint-on-write.js +121 -0
  83. package/dist/modules/plugins/builtin/notify.js +8 -0
  84. package/dist/modules/plugins/index.js +1 -0
  85. package/dist/modules/plugins/loader.js +28 -0
  86. package/dist/modules/plugins/manager.js +161 -0
  87. package/dist/modules/plugins/types.js +1 -0
  88. package/dist/modules/processes/detect.js +34 -0
  89. package/dist/modules/processes/index.js +3 -0
  90. package/dist/modules/processes/registry.js +148 -0
  91. package/dist/modules/processes/runner.js +124 -0
  92. package/dist/modules/registry.js +45 -0
  93. package/dist/modules/security/audit-log.js +116 -0
  94. package/dist/modules/security/audit-notifier.js +292 -0
  95. package/dist/modules/security/command-validator.js +185 -0
  96. package/dist/modules/security/content-scanner.js +52 -0
  97. package/dist/modules/security/data-sanitizer.js +97 -0
  98. package/dist/modules/security/encryption.js +240 -0
  99. package/dist/modules/security/index.js +14 -0
  100. package/dist/modules/security/network-validator.js +79 -0
  101. package/dist/modules/security/path-validator.js +155 -0
  102. package/dist/modules/security/rate-limiter.js +119 -0
  103. package/dist/modules/security/security-policies.js +393 -0
  104. package/dist/modules/security/session-encryption.js +193 -0
  105. package/dist/modules/security/session-isolation.js +95 -0
  106. package/dist/modules/session/index.js +3 -0
  107. package/dist/modules/session/manager.js +167 -0
  108. package/dist/modules/session/module.js +24 -0
  109. package/dist/modules/session/store.js +174 -0
  110. package/dist/modules/session/types.js +1 -0
  111. package/dist/modules/skills/index.js +3 -0
  112. package/dist/modules/skills/loader.js +72 -0
  113. package/dist/modules/skills/matcher.js +27 -0
  114. package/dist/modules/skills/module.js +143 -0
  115. package/dist/modules/types.js +1 -0
  116. package/dist/modules/updater/checker.js +32 -0
  117. package/dist/modules/updater/index.js +1 -0
  118. package/dist/modules/user-profile/compressor.js +16 -0
  119. package/dist/modules/user-profile/index.js +1 -0
  120. package/dist/modules/user-profile/profile.js +68 -0
  121. package/dist/tools/approve.js +32 -0
  122. package/dist/tools/attach-image.js +89 -0
  123. package/dist/tools/bash.js +140 -0
  124. package/dist/tools/browser.js +97 -0
  125. package/dist/tools/create-dir.js +56 -0
  126. package/dist/tools/delete-file.js +63 -0
  127. package/dist/tools/edit-file.js +77 -0
  128. package/dist/tools/executor.js +95 -0
  129. package/dist/tools/file-info.js +45 -0
  130. package/dist/tools/filter-tools.js +10 -0
  131. package/dist/tools/glob-tool.js +26 -0
  132. package/dist/tools/grep-tool.js +64 -0
  133. package/dist/tools/index.js +52 -0
  134. package/dist/tools/list-dir.js +47 -0
  135. package/dist/tools/load-skill.js +48 -0
  136. package/dist/tools/mcp-call.js +68 -0
  137. package/dist/tools/move-file.js +84 -0
  138. package/dist/tools/path-utils.js +51 -0
  139. package/dist/tools/pipeline-run.js +144 -0
  140. package/dist/tools/preview.js +2 -0
  141. package/dist/tools/process-kill.js +29 -0
  142. package/dist/tools/process-list.js +38 -0
  143. package/dist/tools/process-log.js +41 -0
  144. package/dist/tools/question.js +142 -0
  145. package/dist/tools/read-file.js +73 -0
  146. package/dist/tools/recall.js +110 -0
  147. package/dist/tools/registry.js +36 -0
  148. package/dist/tools/remember.js +67 -0
  149. package/dist/tools/scope-check.js +30 -0
  150. package/dist/tools/search-history.js +64 -0
  151. package/dist/tools/subagent.js +142 -0
  152. package/dist/tools/types.js +1 -0
  153. package/dist/tools/user-input.js +123 -0
  154. package/dist/tools/web-browse.js +57 -0
  155. package/dist/tools/web-fetch.js +72 -0
  156. package/dist/tools/web-search.js +59 -0
  157. package/dist/tools/write-file.js +80 -0
  158. package/dist/ui/box.js +81 -0
  159. package/dist/ui/colors.js +4 -0
  160. package/dist/ui/diff.js +185 -0
  161. package/dist/ui/index.js +6 -0
  162. package/dist/ui/md-formatter.js +212 -0
  163. package/dist/ui/output.js +13 -0
  164. package/dist/ui/renderer.js +141 -0
  165. package/dist/ui/spinner.js +70 -0
  166. package/dist/ui/table.js +144 -0
  167. package/package.json +4 -4
@@ -0,0 +1,149 @@
1
+ import { existsSync } from 'fs';
2
+ import { resolve, extname } from 'path';
3
+ import { execSync } from 'child_process';
4
+ import { t } from '../../i18n/index';
5
+ import { validateExpertConfig } from '../../config/experts';
6
+ export class StepVerifier {
7
+ baseDir;
8
+ constructor(baseDir) {
9
+ this.baseDir = baseDir;
10
+ }
11
+ async checkFileExists(path) {
12
+ const resolved = resolve(this.baseDir, path);
13
+ const exists = existsSync(resolved);
14
+ return {
15
+ passed: exists,
16
+ message: exists ? t('verify.file_exists', { path }) : t('verify.file_not_found', { path }),
17
+ };
18
+ }
19
+ async runScript(scriptName) {
20
+ try {
21
+ execSync(`bun run ${scriptName}`, {
22
+ cwd: this.baseDir,
23
+ encoding: 'utf-8',
24
+ timeout: 60_000,
25
+ stdio: 'pipe',
26
+ });
27
+ return { passed: true, message: t('verify.script_passed', { script: scriptName }) };
28
+ }
29
+ catch (e) {
30
+ return { passed: false, message: t('verify.script_failed', { script: scriptName, message: e.message }) };
31
+ }
32
+ }
33
+ async runTypeCheck() {
34
+ const tsconfigPath = resolve(this.baseDir, 'tsconfig.json');
35
+ if (!existsSync(tsconfigPath)) {
36
+ return { passed: true, message: 'No tsconfig.json found — skipping type check' };
37
+ }
38
+ try {
39
+ execSync('npx tsc --noEmit', {
40
+ cwd: this.baseDir,
41
+ encoding: 'utf-8',
42
+ timeout: 60_000,
43
+ stdio: 'pipe',
44
+ });
45
+ return { passed: true, message: 'TypeScript type check passed' };
46
+ }
47
+ catch (e) {
48
+ const stderr = e.stderr?.toString() || e.stdout?.toString() || e.message;
49
+ return { passed: false, message: `TypeScript type check failed: ${stderr.slice(0, 500)}` };
50
+ }
51
+ }
52
+ async runTests() {
53
+ const pkgPath = resolve(this.baseDir, 'package.json');
54
+ if (!existsSync(pkgPath)) {
55
+ return { passed: true, message: 'No package.json found — skipping tests' };
56
+ }
57
+ try {
58
+ const pkg = JSON.parse(require('fs').readFileSync(pkgPath, 'utf-8'));
59
+ if (!pkg.scripts?.test) {
60
+ return { passed: true, message: 'No test script defined — skipping tests' };
61
+ }
62
+ }
63
+ catch { /* fall through — attempt to run */ }
64
+ return this.runScript('test');
65
+ }
66
+ async verifyArtifactFiles(files) {
67
+ return Promise.all(files.map(f => this.checkFileExists(f)));
68
+ }
69
+ async verifyMoEManifest(plan, config, allToolTags) {
70
+ const errors = [];
71
+ const warnings = [];
72
+ const details = [];
73
+ const expertErrors = validateExpertConfig(config, allToolTags);
74
+ for (const err of expertErrors) {
75
+ errors.push(err);
76
+ details.push({ passed: false, message: err });
77
+ }
78
+ const tscResult = await this.runTypeCheck();
79
+ details.push(tscResult);
80
+ if (!tscResult.passed) {
81
+ errors.push(tscResult.message);
82
+ }
83
+ for (const sub of plan.subtasks) {
84
+ const fileChecks = await this.verifyArtifactFiles(sub.allowed_files || []);
85
+ for (const check of fileChecks) {
86
+ details.push(check);
87
+ if (!check.passed) {
88
+ errors.push(check.message);
89
+ }
90
+ }
91
+ }
92
+ return {
93
+ success: errors.length === 0,
94
+ errors,
95
+ warnings,
96
+ details,
97
+ };
98
+ }
99
+ async verifyStep(stepDescription) {
100
+ const fileMatches = stepDescription.match(/\b[\w./-]+\.[a-z]+/gi) || [];
101
+ const results = [];
102
+ let syntaxValid = true;
103
+ for (const filePath of fileMatches) {
104
+ const result = await this.checkFileExists(filePath);
105
+ results.push(result);
106
+ if (result.passed) {
107
+ const fullPath = resolve(this.baseDir, filePath);
108
+ if (!this.validateSyntax(fullPath)) {
109
+ syntaxValid = false;
110
+ results.push({ passed: false, message: t('verify.syntax_error', { path: filePath }) });
111
+ }
112
+ }
113
+ }
114
+ return {
115
+ passed: results.every(r => r.passed),
116
+ syntaxValid,
117
+ failed: results.filter(r => !r.passed),
118
+ };
119
+ }
120
+ validateSyntax(filePath) {
121
+ const ext = extname(filePath);
122
+ if (ext === '.ts' || ext === '.tsx') {
123
+ try {
124
+ execSync(`npx tsc --noEmit --skipLibCheck ${filePath}`, { stdio: 'pipe', timeout: 10000 });
125
+ return true;
126
+ }
127
+ catch (err) {
128
+ if (err.status === 127 || err.message.includes('not found') || err.message.includes('ENOENT')) {
129
+ return true;
130
+ }
131
+ const stderr = err.stderr?.toString() || '';
132
+ if (stderr.includes('error TS') && !stderr.includes('Cannot find module')) {
133
+ return false;
134
+ }
135
+ return true;
136
+ }
137
+ }
138
+ if (ext === '.js' || ext === '.jsx') {
139
+ try {
140
+ execSync(`node --check ${filePath}`, { stdio: 'pipe', timeout: 5000 });
141
+ return true;
142
+ }
143
+ catch {
144
+ return false;
145
+ }
146
+ }
147
+ return true;
148
+ }
149
+ }
@@ -0,0 +1,54 @@
1
+ import { t } from "../../i18n/index";
2
+ const MIN_CHARS = 1;
3
+ const MIN_WORDS = 5;
4
+ export class ConfidenceCheck {
5
+ previousResponse = "";
6
+ setPreviousResponse(response) {
7
+ this.previousResponse = response;
8
+ }
9
+ validate(response) {
10
+ if (!response || response.length < MIN_CHARS) {
11
+ return { status: "retry", reason: t("hall.short_response") };
12
+ }
13
+ // Language-agnostic: very short response with no structured content
14
+ const wordCount = response.split(/\s+/).filter(Boolean).length;
15
+ const hasStructure = /```|^\s*[-*]\s|^\s*\d+\.\s|<[^>]+>/m.test(response);
16
+ if (wordCount < MIN_WORDS && !hasStructure) {
17
+ return {
18
+ status: "warn",
19
+ reason: t("hall.short_response"),
20
+ };
21
+ }
22
+ // Language-agnostic: repetition detection via word overlap
23
+ if (this.previousResponse) {
24
+ const overlap = this.calculateOverlap(response, this.previousResponse);
25
+ if (overlap > 0.5) {
26
+ return {
27
+ status: "retry",
28
+ reason: t("hall.repetitive", { pct: Math.round(overlap * 100) }),
29
+ };
30
+ }
31
+ }
32
+ // Language-agnostic: very low word diversity (same words repeated)
33
+ const words = response.toLowerCase().split(/\s+/).filter(w => w.length > 2);
34
+ if (words.length >= 10) {
35
+ const unique = new Set(words);
36
+ const diversity = unique.size / words.length;
37
+ if (diversity < 0.25) {
38
+ return {
39
+ status: "warn",
40
+ reason: t("hall.repetitive", { pct: Math.round((1 - diversity) * 100) }),
41
+ };
42
+ }
43
+ }
44
+ return { status: "pass" };
45
+ }
46
+ calculateOverlap(a, b) {
47
+ const wordsA = new Set(a.toLowerCase().split(/\s+/));
48
+ const wordsB = b.toLowerCase().split(/\s+/);
49
+ if (wordsB.length === 0)
50
+ return 0;
51
+ const matches = wordsB.filter((w) => wordsA.has(w));
52
+ return matches.length / wordsB.length;
53
+ }
54
+ }
@@ -0,0 +1,60 @@
1
+ import { t } from '../../i18n/index';
2
+ export class ConsistencyCheck {
3
+ decisions = [];
4
+ createdFiles = new Set();
5
+ deletedFiles = new Set();
6
+ trackDecision(decision, location) {
7
+ this.decisions.push({ decision, location });
8
+ }
9
+ trackCreatedFile(path) {
10
+ this.createdFiles.add(path);
11
+ }
12
+ trackDeletedFile(path) {
13
+ this.deletedFiles.add(path);
14
+ }
15
+ getCreatedFiles() {
16
+ return Array.from(this.createdFiles);
17
+ }
18
+ validate(response) {
19
+ const lower = response.toLowerCase();
20
+ for (const d of this.decisions) {
21
+ const decisionWords = d.decision.toLowerCase().split(/\s+/).filter(w => w.length > 3);
22
+ const contradicts = decisionWords.some(word => {
23
+ // English patterns
24
+ if (lower.includes(`instead of ${word}`))
25
+ return true;
26
+ if (lower.includes(`not ${word}`))
27
+ return true;
28
+ if (lower.includes(`replacing ${word} with`))
29
+ return true;
30
+ if (lower.includes(`switching to`))
31
+ return true;
32
+ if (lower.includes(`changing from ${word}`))
33
+ return true;
34
+ if (lower.includes(`abandoning ${word}`))
35
+ return true;
36
+ // Russian patterns
37
+ if (lower.includes(`вместо ${word}`))
38
+ return true;
39
+ if (lower.includes(`заменяя ${word}`))
40
+ return true;
41
+ if (lower.includes(`заменяем ${word}`))
42
+ return true;
43
+ if (lower.includes(`переключаемся на`))
44
+ return true;
45
+ if (lower.includes(`от ${word} к`))
46
+ return true;
47
+ if (lower.includes(`отказываемся от ${word}`))
48
+ return true;
49
+ return false;
50
+ });
51
+ if (contradicts) {
52
+ return {
53
+ status: 'warn',
54
+ reason: t('hall.contradiction', { decision: d.decision, location: d.location }),
55
+ };
56
+ }
57
+ }
58
+ return { status: 'pass' };
59
+ }
60
+ }
@@ -0,0 +1,41 @@
1
+ import { FactualCheck } from './factual';
2
+ import { ConsistencyCheck } from './consistency';
3
+ import { ConfidenceCheck } from './confidence';
4
+ export class HallucinationDetector {
5
+ factual;
6
+ consistency;
7
+ confidence;
8
+ constructor() {
9
+ this.factual = new FactualCheck();
10
+ this.consistency = new ConsistencyCheck();
11
+ this.confidence = new ConfidenceCheck();
12
+ }
13
+ getFactualCheck() {
14
+ return this.factual;
15
+ }
16
+ getConsistencyCheck() {
17
+ return this.consistency;
18
+ }
19
+ getConfidenceCheck() {
20
+ return this.confidence;
21
+ }
22
+ validate(response) {
23
+ const confidenceResult = this.confidence.validate(response);
24
+ if (confidenceResult.status === 'retry' || confidenceResult.status === 'block') {
25
+ return confidenceResult;
26
+ }
27
+ const factualResult = this.factual.validate(response);
28
+ const consistencyResult = this.consistency.validate(response);
29
+ const warnings = [];
30
+ if (factualResult.status === 'warn')
31
+ warnings.push(factualResult.reason || '');
32
+ if (consistencyResult.status === 'warn')
33
+ warnings.push(consistencyResult.reason || '');
34
+ if (confidenceResult.status === 'warn')
35
+ warnings.push(confidenceResult.reason || '');
36
+ if (warnings.length > 0) {
37
+ return { status: 'warn', reason: warnings.join('; ') };
38
+ }
39
+ return { status: 'pass' };
40
+ }
41
+ }
@@ -0,0 +1,170 @@
1
+ import { t } from "../../i18n/index";
2
+ import { existsSync } from "fs";
3
+ import { join } from "path";
4
+ const FILE_EXTENSIONS = new Set([
5
+ "ts",
6
+ "tsx",
7
+ "js",
8
+ "jsx",
9
+ "mjs",
10
+ "cjs",
11
+ "mts",
12
+ "cts",
13
+ "json",
14
+ "md",
15
+ "yaml",
16
+ "yml",
17
+ "py",
18
+ "rs",
19
+ "go",
20
+ "java",
21
+ "c",
22
+ "cpp",
23
+ "h",
24
+ "hpp",
25
+ "html",
26
+ "css",
27
+ "scss",
28
+ "less",
29
+ "vue",
30
+ "svelte",
31
+ "sh",
32
+ "bash",
33
+ "zsh",
34
+ "ps1",
35
+ "bat",
36
+ "cmd",
37
+ "txt",
38
+ "env",
39
+ "env.local",
40
+ "env.production",
41
+ "gitignore",
42
+ "dockerignore",
43
+ "dockerfile",
44
+ "makefile",
45
+ "cmake",
46
+ "toml",
47
+ "lock",
48
+ "config",
49
+ "log",
50
+ "xml",
51
+ "sql",
52
+ "graphql",
53
+ "proto",
54
+ "wasm",
55
+ ]);
56
+ const VERSION_PATTERN = /^\d+(\.\d+)*$/;
57
+ const COMMON_WORDS = new Set([
58
+ "node.js", "Node.js",
59
+ "console.log", "console.error", "console.warn", "console.info",
60
+ "Math.floor", "Math.ceil", "Math.round", "Math.max", "Math.min",
61
+ "JSON.parse", "JSON.stringify",
62
+ "Object.keys", "Object.values", "Object.entries",
63
+ "Array.from", "Array.isArray",
64
+ "Date.now", "Date.parse",
65
+ "RegExp", "Promise",
66
+ ]);
67
+ export class FactualCheck {
68
+ knownPaths = new Set();
69
+ createdPaths = new Set();
70
+ readFiles = new Set();
71
+ baseDir = process.cwd();
72
+ setBaseDir(dir) {
73
+ this.baseDir = dir;
74
+ }
75
+ trackReadPath(path) {
76
+ this.knownPaths.add(path);
77
+ const base = path.split(/[/\\]/).pop();
78
+ if (base && base !== path)
79
+ this.knownPaths.add(base);
80
+ // Track that this file was actually read by the agent
81
+ this.readFiles.add(base || path);
82
+ }
83
+ trackCreatedPath(path) {
84
+ this.knownPaths.add(path);
85
+ const base = path.split(/[/\\]/).pop();
86
+ if (base && base !== path)
87
+ this.knownPaths.add(base);
88
+ this.createdPaths.add(path);
89
+ }
90
+ trackDeletedPath(path) {
91
+ this.knownPaths.add(path);
92
+ const base = path.split(/[/\\]/).pop();
93
+ if (base && base !== path)
94
+ this.knownPaths.add(base);
95
+ this.createdPaths.delete(path);
96
+ }
97
+ /**
98
+ * Register file paths found in a document (e.g. structure.md, README).
99
+ * Files mentioned in project documentation are not hallucinations.
100
+ */
101
+ trackDocumentContent(content) {
102
+ // Match common path patterns in documentation
103
+ const pathPatterns = /(?:^|\s)([\w\-./]+\.\w{1,10})(?:\s|$|[,;)])/gm;
104
+ let match;
105
+ while ((match = pathPatterns.exec(content)) !== null) {
106
+ const file = match[1];
107
+ if (file.includes('/') || file.includes('\\')) {
108
+ this.knownPaths.add(file);
109
+ }
110
+ const base = file.split(/[/\\]/).pop();
111
+ if (base)
112
+ this.knownPaths.add(base);
113
+ }
114
+ }
115
+ pathExistsOnDisk(path) {
116
+ try {
117
+ // Skip absolute paths — they're either system paths or outside the project.
118
+ // On Windows, existsSync('/...') can hang on certain paths.
119
+ if (path.startsWith("/") || path.startsWith("~") || /^[A-Za-z]:/.test(path)) {
120
+ return false;
121
+ }
122
+ return existsSync(join(this.baseDir, path));
123
+ }
124
+ catch {
125
+ return false;
126
+ }
127
+ }
128
+ validate(response) {
129
+ const pathRegex = /[\w\-./]+\.\w+/g;
130
+ const mentionedPaths = response.match(pathRegex) || [];
131
+ const unknownPaths = mentionedPaths.filter((p) => {
132
+ if (this.knownPaths.has(p))
133
+ return false;
134
+ if (VERSION_PATTERN.test(p))
135
+ return false;
136
+ if (COMMON_WORDS.has(p))
137
+ return false;
138
+ // Skip absolute paths — agent responses use relative paths; absolute
139
+ // paths are either system paths or URLs, and existsSync can hang on
140
+ // Windows for root-relative paths like "/page.html".
141
+ if (p.startsWith("/") || p.startsWith("~") || /^[A-Za-z]:/.test(p))
142
+ return false;
143
+ if (this.pathExistsOnDisk(p))
144
+ return false;
145
+ const ext = p.split(".").pop()?.toLowerCase() || "";
146
+ if (!FILE_EXTENSIONS.has(ext))
147
+ return false;
148
+ const basename = p
149
+ .split("/")
150
+ .pop()
151
+ ?.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
152
+ if (basename) {
153
+ const urlPattern = new RegExp(`(https?|file)://[^\\s]*${basename}`);
154
+ if (urlPattern.test(response))
155
+ return false;
156
+ }
157
+ return true;
158
+ });
159
+ if (unknownPaths.length > 0) {
160
+ const uniquePaths = [...new Set(unknownPaths)];
161
+ return {
162
+ status: "warn",
163
+ reason: t("hall.unknown_paths", {
164
+ paths: uniquePaths.slice(0, 3).join(", "),
165
+ }),
166
+ };
167
+ }
168
+ return { status: "pass" };
169
+ }
170
+ }
@@ -0,0 +1,4 @@
1
+ export { HallucinationDetector } from './detector';
2
+ export { FactualCheck } from './factual';
3
+ export { ConsistencyCheck } from './consistency';
4
+ export { ConfidenceCheck } from './confidence';
@@ -0,0 +1,5 @@
1
+ export { ModuleRegistry } from './registry';
2
+ export { SkillsLoader, SkillsMatcher, SkillsModule } from './skills';
3
+ export { PluginManager } from './plugins';
4
+ export { PluginLoader } from './plugins/loader';
5
+ export { MCPClient, MCPRegistry } from './mcp';
@@ -0,0 +1,38 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync } from 'fs';
2
+ import { join } from 'path';
3
+ export class IndexCache {
4
+ cachePath;
5
+ cache = null;
6
+ constructor(cacheDir) {
7
+ this.cachePath = join(cacheDir, 'index-cache.json');
8
+ }
9
+ load() {
10
+ if (this.cache)
11
+ return this.cache;
12
+ if (!existsSync(this.cachePath))
13
+ return null;
14
+ try {
15
+ this.cache = JSON.parse(readFileSync(this.cachePath, 'utf-8'));
16
+ return this.cache;
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ save(result) {
23
+ this.cache = result;
24
+ const dir = join(this.cachePath, '..');
25
+ if (!existsSync(dir))
26
+ mkdirSync(dir, { recursive: true });
27
+ writeFileSync(this.cachePath, JSON.stringify(result), 'utf-8');
28
+ }
29
+ invalidate() {
30
+ this.cache = null;
31
+ if (existsSync(this.cachePath)) {
32
+ try {
33
+ rmSync(this.cachePath);
34
+ }
35
+ catch { /* ignore */ }
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ export { Indexer } from './walker';
2
+ export { IndexCache } from './cache';
3
+ export { IndexerModule } from './module';