micro-models-agent 0.28.8 → 0.28.17

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 (184) hide show
  1. package/dist/cli/commands.js +333 -0
  2. package/dist/cli/completer.js +168 -0
  3. package/dist/cli/index.js +2 -0
  4. package/dist/cli/main.js +140 -0
  5. package/dist/cli/repl-commands.js +633 -0
  6. package/dist/cli/repl.js +486 -0
  7. package/dist/cli/security-commands.js +166 -0
  8. package/dist/cli/setup.js +249 -0
  9. package/dist/config/config.js +202 -0
  10. package/dist/config/defaults.js +100 -0
  11. package/dist/config/experts.js +15 -0
  12. package/dist/config/index.js +3 -0
  13. package/dist/config/security.js +200 -0
  14. package/dist/config/types.js +1 -0
  15. package/dist/core/agent-moe.js +110 -0
  16. package/dist/core/agent.js +695 -0
  17. package/dist/core/bootstrap.js +337 -0
  18. package/dist/core/index.js +2 -0
  19. package/dist/core/prompt-builder.js +55 -0
  20. package/dist/core/session-logger.js +155 -0
  21. package/dist/core/types.js +1 -0
  22. package/dist/core/workspace.js +76 -0
  23. package/dist/i18n/en.json +525 -0
  24. package/dist/i18n/index.js +46 -0
  25. package/dist/i18n/ru.json +525 -0
  26. package/dist/index.js +22 -0
  27. package/dist/llm/image-utils.js +144 -0
  28. package/dist/llm/index.js +4 -0
  29. package/dist/llm/model-loader.js +78 -0
  30. package/dist/llm/openai-compat.js +353 -0
  31. package/dist/llm/orchestrator.js +194 -0
  32. package/dist/llm/provider.js +10 -0
  33. package/dist/llm/response.js +39 -0
  34. package/dist/llm/token-counter.js +39 -0
  35. package/dist/llm/types.js +1 -0
  36. package/dist/logger/app-logger.js +143 -0
  37. package/dist/logger/file-log.js +151 -0
  38. package/dist/logger/index.js +1 -0
  39. package/dist/main.js +1758 -612
  40. package/dist/migration/backup.js +45 -0
  41. package/dist/migration/detect.js +50 -0
  42. package/dist/migration/index.js +2 -0
  43. package/dist/modules/browser/actions.js +46 -0
  44. package/dist/modules/browser/cookie-store.js +24 -0
  45. package/dist/modules/browser/index.js +5 -0
  46. package/dist/modules/browser/module.js +28 -0
  47. package/dist/modules/browser/session.js +335 -0
  48. package/dist/modules/browser/snapshot.js +114 -0
  49. package/dist/modules/browser/types.js +9 -0
  50. package/dist/modules/certification/cli.js +176 -0
  51. package/dist/modules/certification/fact-checker.js +84 -0
  52. package/dist/modules/certification/loader.js +111 -0
  53. package/dist/modules/certification/manifest.js +50 -0
  54. package/dist/modules/certification/runner.js +162 -0
  55. package/dist/modules/certification/scenarios.js +124 -0
  56. package/dist/modules/certification/types.js +1 -0
  57. package/dist/modules/context/index.js +1 -0
  58. package/dist/modules/context/manager.js +349 -0
  59. package/dist/modules/execution/auditor.js +66 -0
  60. package/dist/modules/execution/index.js +8 -0
  61. package/dist/modules/execution/module.js +779 -0
  62. package/dist/modules/execution/moe-executor.js +266 -0
  63. package/dist/modules/execution/plan-coverage.js +68 -0
  64. package/dist/modules/execution/plan-persister.js +46 -0
  65. package/dist/modules/execution/plan-store.js +159 -0
  66. package/dist/modules/execution/plan-validator.js +153 -0
  67. package/dist/modules/execution/planner.js +85 -0
  68. package/dist/modules/execution/stuck-detector.js +347 -0
  69. package/dist/modules/execution/tracker.js +67 -0
  70. package/dist/modules/execution/types.js +1 -0
  71. package/dist/modules/execution/verifier.js +178 -0
  72. package/dist/modules/hallucination/confidence.js +59 -0
  73. package/dist/modules/hallucination/consistency.js +26 -0
  74. package/dist/modules/hallucination/detector.js +46 -0
  75. package/dist/modules/hallucination/factual.js +190 -0
  76. package/dist/modules/hallucination/index.js +5 -0
  77. package/dist/modules/hallucination/js-identifiers.js +72 -0
  78. package/dist/modules/hallucination/llm-judge.js +103 -0
  79. package/dist/modules/index.js +5 -0
  80. package/dist/modules/indexer/cache.js +38 -0
  81. package/dist/modules/indexer/index.js +3 -0
  82. package/dist/modules/indexer/module.js +192 -0
  83. package/dist/modules/indexer/walker.js +101 -0
  84. package/dist/modules/lsp/client.js +235 -0
  85. package/dist/modules/lsp/config.js +81 -0
  86. package/dist/modules/lsp/index.js +3 -0
  87. package/dist/modules/lsp/module.js +68 -0
  88. package/dist/modules/lsp/types.js +1 -0
  89. package/dist/modules/mcp/client.js +399 -0
  90. package/dist/modules/mcp/index.js +3 -0
  91. package/dist/modules/mcp/module.js +146 -0
  92. package/dist/modules/mcp/registry.js +15 -0
  93. package/dist/modules/memory/index.js +1 -0
  94. package/dist/modules/memory/module.js +48 -0
  95. package/dist/modules/memory/search.js +40 -0
  96. package/dist/modules/memory/store.js +69 -0
  97. package/dist/modules/pipelines/engine.js +60 -0
  98. package/dist/modules/pipelines/index.js +3 -0
  99. package/dist/modules/pipelines/parser.js +53 -0
  100. package/dist/modules/pipelines/template.js +14 -0
  101. package/dist/modules/plugins/builtin/lint-on-write.js +226 -0
  102. package/dist/modules/plugins/builtin/notify.js +8 -0
  103. package/dist/modules/plugins/index.js +1 -0
  104. package/dist/modules/plugins/loader.js +28 -0
  105. package/dist/modules/plugins/manager.js +161 -0
  106. package/dist/modules/plugins/types.js +1 -0
  107. package/dist/modules/processes/index.js +2 -0
  108. package/dist/modules/processes/registry.js +238 -0
  109. package/dist/modules/processes/runner.js +23 -0
  110. package/dist/modules/registry.js +45 -0
  111. package/dist/modules/security/audit-log.js +136 -0
  112. package/dist/modules/security/audit-notifier.js +292 -0
  113. package/dist/modules/security/command-validator.js +211 -0
  114. package/dist/modules/security/content-scanner.js +53 -0
  115. package/dist/modules/security/data-sanitizer.js +97 -0
  116. package/dist/modules/security/encryption.js +240 -0
  117. package/dist/modules/security/index.js +14 -0
  118. package/dist/modules/security/network-validator.js +79 -0
  119. package/dist/modules/security/path-validator.js +209 -0
  120. package/dist/modules/security/rate-limiter.js +119 -0
  121. package/dist/modules/security/security-policies.js +547 -0
  122. package/dist/modules/security/session-encryption.js +210 -0
  123. package/dist/modules/security/session-isolation.js +95 -0
  124. package/dist/modules/session/index.js +3 -0
  125. package/dist/modules/session/manager.js +172 -0
  126. package/dist/modules/session/module.js +24 -0
  127. package/dist/modules/session/store.js +228 -0
  128. package/dist/modules/session/types.js +1 -0
  129. package/dist/modules/skills/index.js +2 -0
  130. package/dist/modules/skills/loader.js +72 -0
  131. package/dist/modules/skills/module.js +130 -0
  132. package/dist/modules/types.js +1 -0
  133. package/dist/modules/updater/checker.js +32 -0
  134. package/dist/modules/updater/index.js +1 -0
  135. package/dist/modules/user-profile/compressor.js +16 -0
  136. package/dist/modules/user-profile/index.js +1 -0
  137. package/dist/modules/user-profile/profile.js +68 -0
  138. package/dist/tools/approve.js +32 -0
  139. package/dist/tools/attach-image.js +89 -0
  140. package/dist/tools/bash.js +337 -0
  141. package/dist/tools/browser.js +97 -0
  142. package/dist/tools/create-dir.js +55 -0
  143. package/dist/tools/delete-file.js +62 -0
  144. package/dist/tools/edit-file.js +79 -0
  145. package/dist/tools/executor.js +145 -0
  146. package/dist/tools/file-info.js +45 -0
  147. package/dist/tools/filter-tools.js +10 -0
  148. package/dist/tools/glob-tool.js +26 -0
  149. package/dist/tools/grep-tool.js +86 -0
  150. package/dist/tools/index.js +67 -0
  151. package/dist/tools/list-dir.js +47 -0
  152. package/dist/tools/load-skill.js +44 -0
  153. package/dist/tools/mcp-call.js +68 -0
  154. package/dist/tools/move-file.js +85 -0
  155. package/dist/tools/path-utils.js +51 -0
  156. package/dist/tools/pipeline-run.js +144 -0
  157. package/dist/tools/preview.js +2 -0
  158. package/dist/tools/process-kill.js +29 -0
  159. package/dist/tools/process-list.js +38 -0
  160. package/dist/tools/process-log.js +41 -0
  161. package/dist/tools/question.js +142 -0
  162. package/dist/tools/read-file.js +83 -0
  163. package/dist/tools/recall.js +110 -0
  164. package/dist/tools/registry.js +36 -0
  165. package/dist/tools/remember.js +67 -0
  166. package/dist/tools/scope-check.js +30 -0
  167. package/dist/tools/search-history.js +84 -0
  168. package/dist/tools/subagent.js +151 -0
  169. package/dist/tools/types.js +1 -0
  170. package/dist/tools/user-input.js +123 -0
  171. package/dist/tools/web-browse.js +86 -0
  172. package/dist/tools/web-fetch.js +98 -0
  173. package/dist/tools/web-search.js +78 -0
  174. package/dist/tools/write-file.js +83 -0
  175. package/dist/ui/box.js +81 -0
  176. package/dist/ui/colors.js +4 -0
  177. package/dist/ui/diff.js +178 -0
  178. package/dist/ui/index.js +6 -0
  179. package/dist/ui/md-formatter.js +212 -0
  180. package/dist/ui/output.js +13 -0
  181. package/dist/ui/renderer.js +204 -0
  182. package/dist/ui/spinner.js +70 -0
  183. package/dist/ui/table.js +144 -0
  184. package/package.json +4 -4
@@ -0,0 +1,59 @@
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
34
+ .toLowerCase()
35
+ .split(/\s+/)
36
+ .filter((w) => w.length > 2);
37
+ if (words.length >= 10) {
38
+ const unique = new Set(words);
39
+ const diversity = unique.size / words.length;
40
+ if (diversity < 0.25) {
41
+ return {
42
+ status: "warn",
43
+ reason: t("hall.repetitive", {
44
+ pct: Math.round((1 - diversity) * 100),
45
+ }),
46
+ };
47
+ }
48
+ }
49
+ return { status: "pass" };
50
+ }
51
+ calculateOverlap(a, b) {
52
+ const wordsA = new Set(a.toLowerCase().split(/\s+/));
53
+ const wordsB = b.toLowerCase().split(/\s+/);
54
+ if (wordsB.length === 0)
55
+ return 0;
56
+ const matches = wordsB.filter((w) => wordsA.has(w));
57
+ return matches.length / wordsB.length;
58
+ }
59
+ }
@@ -0,0 +1,26 @@
1
+ export class ConsistencyCheck {
2
+ decisions = [];
3
+ createdFiles = new Set();
4
+ deletedFiles = new Set();
5
+ trackDecision(decision, location) {
6
+ this.decisions.push({ decision, location });
7
+ }
8
+ trackCreatedFile(path) {
9
+ this.createdFiles.add(path);
10
+ }
11
+ trackDeletedFile(path) {
12
+ this.deletedFiles.add(path);
13
+ }
14
+ getCreatedFiles() {
15
+ return Array.from(this.createdFiles);
16
+ }
17
+ getDeletedFiles() {
18
+ return Array.from(this.deletedFiles);
19
+ }
20
+ getDecisions() {
21
+ return this.decisions;
22
+ }
23
+ hasDecisions() {
24
+ return this.decisions.length > 0;
25
+ }
26
+ }
@@ -0,0 +1,46 @@
1
+ import { ConsistencyCheck } from "./consistency";
2
+ import { ConfidenceCheck } from "./confidence";
3
+ import { FactualCheck } from "./factual";
4
+ import { LLMJudge } from "./llm-judge";
5
+ export class HallucinationDetector {
6
+ consistency;
7
+ confidence;
8
+ factual;
9
+ judge;
10
+ constructor(baseDir, llmProvider) {
11
+ this.consistency = new ConsistencyCheck();
12
+ this.confidence = new ConfidenceCheck();
13
+ this.factual = baseDir ? new FactualCheck(baseDir) : null;
14
+ this.judge = llmProvider ? new LLMJudge(llmProvider) : null;
15
+ }
16
+ getConsistencyCheck() {
17
+ return this.consistency;
18
+ }
19
+ getConfidenceCheck() {
20
+ return this.confidence;
21
+ }
22
+ async validate(response) {
23
+ const confidenceResult = this.confidence.validate(response);
24
+ if (confidenceResult.status === "retry" ||
25
+ confidenceResult.status === "block") {
26
+ return confidenceResult;
27
+ }
28
+ const factualResult = this.factual?.validate(response);
29
+ if (factualResult && factualResult.status !== "pass") {
30
+ return factualResult;
31
+ }
32
+ // LLM-as-judge consistency: fast path (no decisions) skips any LLM call.
33
+ const judgeResult = this.judge
34
+ ? await this.judge.validate(response, this.consistency)
35
+ : null;
36
+ const warnings = [];
37
+ if (judgeResult && judgeResult.status === "warn")
38
+ warnings.push(judgeResult.reason || "");
39
+ if (confidenceResult.status === "warn")
40
+ warnings.push(confidenceResult.reason || "");
41
+ if (warnings.length > 0) {
42
+ return { status: "warn", reason: warnings.join("; ") };
43
+ }
44
+ return { status: "pass" };
45
+ }
46
+ }
@@ -0,0 +1,190 @@
1
+ import { existsSync, readdirSync } from "fs";
2
+ import { resolve, isAbsolute, join } from "path";
3
+ import { t } from "../../i18n/index";
4
+ import { isJsMemberAccess } from "./js-identifiers";
5
+ /** Generated/cached dirs to skip when scanning for bare file names. */
6
+ const IGNORED_DIRS = new Set([
7
+ "node_modules",
8
+ ".git",
9
+ "dist",
10
+ "build",
11
+ "coverage",
12
+ ".mma",
13
+ "_testing",
14
+ ]);
15
+ const NON_FILE_EXTENSIONS = new Set([
16
+ "com",
17
+ "org",
18
+ "net",
19
+ "gov",
20
+ "edu",
21
+ "io",
22
+ "dev",
23
+ "app",
24
+ "co",
25
+ "ai",
26
+ "ru",
27
+ "de",
28
+ "fr",
29
+ "uk",
30
+ "us",
31
+ "es",
32
+ "it",
33
+ "jp",
34
+ "cn",
35
+ "br",
36
+ ]);
37
+ /** Well-known runtime/library names that end in .js/.ts but are NOT files. */
38
+ const TECH_NAMES = new Set([
39
+ "node.js",
40
+ "react.js",
41
+ "vue.js",
42
+ "next.js",
43
+ "angular.js",
44
+ "express.js",
45
+ "deno.js",
46
+ "qwik.js",
47
+ "svelte.js",
48
+ "jquery.js",
49
+ ]);
50
+ /**
51
+ * JS/TS global identifiers whose member access (`process.env`, `console.log`)
52
+ * looks like a file path to the regex but is code, not a file.
53
+ */
54
+ function looksLikeFilePath(s) {
55
+ const lower = s.toLowerCase();
56
+ // "Node.js" etc. are technologies, not files — never flag them.
57
+ if (TECH_NAMES.has(lower))
58
+ return false;
59
+ if (!s.includes("/") && !s.includes("\\") && !s.match(/^\w+\.[a-z]{2,4}$/i))
60
+ return false;
61
+ // process.env / console.log / Math.max — member access on JS globals,
62
+ // not file paths. Only applies to bare `word.word` (no slashes).
63
+ if (isJsMemberAccess(s))
64
+ return false;
65
+ const ext = s.split(".").pop()?.toLowerCase() || "";
66
+ return !NON_FILE_EXTENSIONS.has(ext);
67
+ }
68
+ export class FactualCheck {
69
+ baseDir;
70
+ nameCache = null;
71
+ nameCacheTime = 0;
72
+ lastRescan = 0;
73
+ static NAME_CACHE_TTL_MS = 5_000;
74
+ static RESCAN_COOLDOWN_MS = 2_000;
75
+ static MAX_INDEXED_FILES = 20_000;
76
+ constructor(baseDir) {
77
+ this.baseDir = baseDir;
78
+ }
79
+ validate(response) {
80
+ const filePaths = this.extractFilePaths(response);
81
+ if (filePaths.length === 0)
82
+ return { status: "pass" };
83
+ const nonExistent = [];
84
+ for (const fp of filePaths) {
85
+ if (!this.pathExists(fp)) {
86
+ nonExistent.push(fp);
87
+ }
88
+ }
89
+ if (nonExistent.length > 0) {
90
+ return {
91
+ status: "warn",
92
+ reason: t("hall.unknown_paths", {
93
+ paths: nonExistent.slice(0, 5).join(", "),
94
+ }),
95
+ };
96
+ }
97
+ return { status: "pass" };
98
+ }
99
+ /**
100
+ * Bare filenames ("bikes.json") and relative paths ("src/data/bikes.json")
101
+ * both land on the project tree. Absolute paths are checked as-is.
102
+ */
103
+ pathExists(fp) {
104
+ if (isAbsolute(fp))
105
+ return existsSync(fp);
106
+ // "foo.json" has no directory part — treat it as a bare name that may
107
+ // live anywhere under baseDir (e.g. src/data/bikes.json). Resolving it
108
+ // against the workspace root alone produced false "unknown file" warnings.
109
+ if (!fp.includes("/") && !fp.includes("\\")) {
110
+ return this.bareNameExists(fp);
111
+ }
112
+ return existsSync(resolve(this.baseDir, fp));
113
+ }
114
+ bareNameExists(name) {
115
+ if (existsSync(resolve(this.baseDir, name)))
116
+ return true;
117
+ if (this.indexHas(name))
118
+ return true;
119
+ // A write_file from this session may have created the file after the
120
+ // index was built. Do a one-off rescan (rate-limited) before warning.
121
+ const now = Date.now();
122
+ if (now - this.lastRescan < FactualCheck.RESCAN_COOLDOWN_MS)
123
+ return false;
124
+ this.lastRescan = now;
125
+ this.nameCache = null;
126
+ this.nameCacheTime = 0;
127
+ return this.indexHas(name);
128
+ }
129
+ indexHas(name) {
130
+ return (this.getNameIndex().get(name)?.length ?? 0) > 0;
131
+ }
132
+ /**
133
+ * Basename → paths index, rebuilt every NAME_CACHE_TTL_MS so newly created
134
+ * files (write_file) are picked up without a full scan on every response.
135
+ */
136
+ getNameIndex() {
137
+ const now = Date.now();
138
+ if (this.nameCache &&
139
+ now - this.nameCacheTime < FactualCheck.NAME_CACHE_TTL_MS) {
140
+ return this.nameCache;
141
+ }
142
+ const index = new Map();
143
+ const scanned = this.scanDir(this.baseDir, index, 0);
144
+ if (scanned > 0 || index.size > 0) {
145
+ this.nameCache = index;
146
+ this.nameCacheTime = now;
147
+ }
148
+ return index;
149
+ }
150
+ scanDir(dir, index, count) {
151
+ if (count >= FactualCheck.MAX_INDEXED_FILES)
152
+ return count;
153
+ let entries;
154
+ try {
155
+ entries = readdirSync(dir, { withFileTypes: true });
156
+ }
157
+ catch {
158
+ return count;
159
+ }
160
+ for (const entry of entries) {
161
+ if (count >= FactualCheck.MAX_INDEXED_FILES)
162
+ break;
163
+ const full = join(dir, entry.name);
164
+ if (entry.isDirectory()) {
165
+ if (!IGNORED_DIRS.has(entry.name)) {
166
+ count = this.scanDir(full, index, count);
167
+ }
168
+ }
169
+ else if (entry.isFile()) {
170
+ const list = index.get(entry.name);
171
+ if (list)
172
+ list.push(full);
173
+ else
174
+ index.set(entry.name, [full]);
175
+ count++;
176
+ }
177
+ }
178
+ return count;
179
+ }
180
+ extractFilePaths(text) {
181
+ // Capture absolute Windows paths (with drive letter) and relative paths.
182
+ // The old pattern started at a word boundary, so "E:\project\src\a.ts"
183
+ // only matched "project\src\a.ts" — resolve() then glued that onto
184
+ // baseDir producing a bogus path and a false "unknown file" warning
185
+ // even for files that actually exist on disk.
186
+ const pattern = /\b(?:[a-zA-Z]:[\\/])?[\w./\\-]+\.[a-z]{2,6}\b/gi;
187
+ const matches = text.match(pattern) || [];
188
+ return [...new Set(matches)].filter(looksLikeFilePath);
189
+ }
190
+ }
@@ -0,0 +1,5 @@
1
+ export { HallucinationDetector, } from "./detector";
2
+ export { ConsistencyCheck } from "./consistency";
3
+ export { ConfidenceCheck } from "./confidence";
4
+ export { FactualCheck } from "./factual";
5
+ export { LLMJudge } from "./llm-judge";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * JS/TS global identifiers whose member access (`process.env`, `console.log`,
3
+ * `Math.max`) looks like a file path to `\b[\w./\\-]+\.[a-z]+\b`-style regexes
4
+ * but is code, not a file. Shared by the hallucination factual check and the
5
+ * execution auditor so both stop flagging member access as "missing files".
6
+ */
7
+ const JS_GLOBALS = new Set([
8
+ "process",
9
+ "console",
10
+ "math",
11
+ "json",
12
+ "global",
13
+ "globalthis",
14
+ "window",
15
+ "document",
16
+ "buffer",
17
+ "module",
18
+ "require",
19
+ "exports",
20
+ "url",
21
+ "promise",
22
+ "array",
23
+ "object",
24
+ "string",
25
+ "number",
26
+ "boolean",
27
+ "symbol",
28
+ "date",
29
+ "regexp",
30
+ "error",
31
+ "map",
32
+ "set",
33
+ "weakmap",
34
+ "weakset",
35
+ "proxy",
36
+ "reflect",
37
+ "intl",
38
+ "crypto",
39
+ "performance",
40
+ "fetch",
41
+ "navigator",
42
+ "location",
43
+ "settimeout",
44
+ "setinterval",
45
+ "cleartimeout",
46
+ "clearinterval",
47
+ "queuemicrotask",
48
+ "structuredclone",
49
+ "textencoder",
50
+ "textdecoder",
51
+ "atomics",
52
+ "sharedarraybuffer",
53
+ "dataview",
54
+ "arraybuffer",
55
+ "bigint",
56
+ "infinity",
57
+ "nan",
58
+ "undefined",
59
+ "bun",
60
+ "deno",
61
+ "node",
62
+ ]);
63
+ /**
64
+ * True when `candidate` starts with a known JS/TS global followed by a dot
65
+ * (`process.env`, `console.log`, `process.env.NODE` partial matches from
66
+ * `\b[\w./\\-]+\.[a-z]+`-style regexes) — member access, not a file path.
67
+ */
68
+ export function isJsMemberAccess(candidate) {
69
+ const lower = candidate.toLowerCase();
70
+ const m = lower.match(/^([\w-]+)\./);
71
+ return m !== null && JS_GLOBALS.has(m[1]);
72
+ }
@@ -0,0 +1,103 @@
1
+ import { t } from "../../i18n/index";
2
+ const JUDGE_TIMEOUT_MS = 15000;
3
+ const MAX_DECISIONS_SHOWN = 6;
4
+ const MAX_RESPONSE_CHARS = 2000;
5
+ /**
6
+ * LLM-as-judge consistency check. Asks a model whether the agent's latest
7
+ * response contradicts any of its earlier decisions — replacing the fragile
8
+ * word-matching heuristic that only caught exact substring reversals.
9
+ *
10
+ * Fast path: when no decisions are tracked, returns pass without any LLM call.
11
+ * Any judge failure (timeout, provider error, unparseable verdict) degrades to
12
+ * pass so the agent loop is never blocked by the judge.
13
+ */
14
+ export class LLMJudge {
15
+ provider;
16
+ constructor(provider) {
17
+ this.provider = provider;
18
+ }
19
+ async validate(response, consistency) {
20
+ const decisions = consistency.getDecisions();
21
+ if (decisions.length === 0) {
22
+ return { status: "pass" };
23
+ }
24
+ const shown = decisions.slice(-MAX_DECISIONS_SHOWN);
25
+ const decisionLines = shown
26
+ .map((d, i) => `${i + 1}. [${d.location || "agent"}] "${d.decision}"`)
27
+ .join("\n");
28
+ const system = `You are a consistency checker for an AI coding agent. The agent previously made these decisions:
29
+
30
+ ${decisionLines}
31
+
32
+ Decide whether the agent's NEW response contradicts any of these decisions. A contradiction means reversing or abandoning a previously stated approach (e.g. switching to a different framework, changing a chosen strategy, or undoing a decision that was explicitly made).
33
+
34
+ Reply with ONLY valid JSON, no other text:
35
+ - {"contradicts": false}
36
+ - {"contradicts": true, "reason": "short explanation"}`;
37
+ const user = `Agent's new response:\n\n${response.slice(0, MAX_RESPONSE_CHARS)}`;
38
+ try {
39
+ const verdictText = await this.askJudge([
40
+ { role: "system", content: system },
41
+ { role: "user", content: user },
42
+ ]);
43
+ const verdict = this.parseVerdict(verdictText);
44
+ if (verdict.contradicts) {
45
+ const reason = verdict.reason?.trim()
46
+ ? ` — ${verdict.reason.trim()}`
47
+ : "";
48
+ return {
49
+ status: "warn",
50
+ reason: t("hall.contradiction_llm", { reason }),
51
+ };
52
+ }
53
+ return { status: "pass" };
54
+ }
55
+ catch {
56
+ return { status: "pass" };
57
+ }
58
+ }
59
+ async askJudge(messages) {
60
+ let text = "";
61
+ let timer;
62
+ const consume = (async () => {
63
+ for await (const chunk of this.provider.chat(messages, [])) {
64
+ if (chunk.type === "text" && chunk.content) {
65
+ text += chunk.content;
66
+ }
67
+ }
68
+ return text;
69
+ })();
70
+ const timeout = new Promise((_, reject) => {
71
+ timer = setTimeout(() => reject(new Error("LLM judge timed out")), JUDGE_TIMEOUT_MS);
72
+ });
73
+ try {
74
+ return await Promise.race([consume, timeout]);
75
+ }
76
+ finally {
77
+ if (timer)
78
+ clearTimeout(timer);
79
+ }
80
+ }
81
+ parseVerdict(text) {
82
+ const block = text.match(/\{[\s\S]*\}/);
83
+ if (block) {
84
+ try {
85
+ const obj = JSON.parse(block[0]);
86
+ if (typeof obj.contradicts === "boolean") {
87
+ return {
88
+ contradicts: obj.contradicts,
89
+ reason: typeof obj.reason === "string" ? obj.reason : undefined,
90
+ };
91
+ }
92
+ }
93
+ catch {
94
+ // fall through to lenient parsing
95
+ }
96
+ }
97
+ const lower = text.toLowerCase();
98
+ if (lower.includes('"contradicts": true') || /^yes\b/.test(lower.trim())) {
99
+ return { contradicts: true, reason: text.slice(0, 200) };
100
+ }
101
+ return { contradicts: false };
102
+ }
103
+ }
@@ -0,0 +1,5 @@
1
+ export { ModuleRegistry } from "./registry";
2
+ export { SkillsLoader, 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';