micro-models-agent 0.60.1 β†’ 0.61.1

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 (233) hide show
  1. package/CHANGELOG.md +601 -584
  2. package/README.md +358 -358
  3. package/dist/certification/certifications.json +493 -493
  4. package/dist/cli/commands.js +447 -0
  5. package/dist/cli/completer.js +167 -0
  6. package/dist/cli/index.js +2 -0
  7. package/dist/cli/main.js +153 -0
  8. package/dist/cli/plugin-commands.js +36 -0
  9. package/dist/cli/repl-commands.js +761 -0
  10. package/dist/cli/repl.js +702 -0
  11. package/dist/cli/run-result.js +33 -0
  12. package/dist/cli/security-commands.js +164 -0
  13. package/dist/cli/setup.js +237 -0
  14. package/dist/config/config.js +276 -0
  15. package/dist/config/defaults.js +141 -0
  16. package/dist/config/domains.js +179 -0
  17. package/dist/config/experts.js +15 -0
  18. package/dist/config/index.js +4 -0
  19. package/dist/config/security.js +213 -0
  20. package/dist/config/types.js +1 -0
  21. package/dist/core/agent-moe.js +102 -0
  22. package/dist/core/agent.js +1018 -0
  23. package/dist/core/bootstrap.js +481 -0
  24. package/dist/core/crash-handler.js +51 -0
  25. package/dist/core/environment.js +199 -0
  26. package/dist/core/index.js +2 -0
  27. package/dist/core/prompt-builder.js +76 -0
  28. package/dist/core/session-logger.js +251 -0
  29. package/dist/core/types.js +1 -0
  30. package/dist/core/version.js +26 -0
  31. package/dist/core/workspace.js +76 -0
  32. package/dist/i18n/en.json +757 -746
  33. package/dist/i18n/index.js +46 -0
  34. package/dist/i18n/ru.json +757 -746
  35. package/dist/index.js +22 -0
  36. package/dist/llm/image-utils.js +143 -0
  37. package/dist/llm/index.js +4 -0
  38. package/dist/llm/model-loader.js +78 -0
  39. package/dist/llm/openai-compat.js +497 -0
  40. package/dist/llm/orchestrator.js +200 -0
  41. package/dist/llm/provider.js +10 -0
  42. package/dist/llm/response.js +39 -0
  43. package/dist/llm/token-counter.js +39 -0
  44. package/dist/llm/types.js +1 -0
  45. package/dist/logger/app-logger.js +189 -0
  46. package/dist/logger/file-log.js +151 -0
  47. package/dist/logger/index.js +1 -0
  48. package/dist/main.js +503 -340
  49. package/dist/migration/backup.js +45 -0
  50. package/dist/migration/detect.js +50 -0
  51. package/dist/migration/index.js +2 -0
  52. package/dist/modules/artifacts/store.js +61 -0
  53. package/dist/modules/browser/actions.js +76 -0
  54. package/dist/modules/browser/bridge-client.js +199 -0
  55. package/dist/modules/browser/bridge-path.js +10 -0
  56. package/dist/modules/browser/bridge-server.mjs +219 -219
  57. package/dist/modules/browser/cookie-store.js +24 -0
  58. package/dist/modules/browser/driver.js +136 -0
  59. package/dist/modules/browser/index.js +7 -0
  60. package/dist/modules/browser/module.js +29 -0
  61. package/dist/modules/browser/session.js +342 -0
  62. package/dist/modules/browser/snapshot.js +148 -0
  63. package/dist/modules/browser/types.js +12 -0
  64. package/dist/modules/certification/cli.js +213 -0
  65. package/dist/modules/certification/fact-checker.js +82 -0
  66. package/dist/modules/certification/loader.js +106 -0
  67. package/dist/modules/certification/manifest.js +58 -0
  68. package/dist/modules/certification/runner.js +245 -0
  69. package/dist/modules/certification/scenarios.js +407 -0
  70. package/dist/modules/certification/types.js +1 -0
  71. package/dist/modules/context/chunk-query.js +100 -0
  72. package/dist/modules/context/fact-extractor.js +168 -0
  73. package/dist/modules/context/history.js +15 -0
  74. package/dist/modules/context/index.js +1 -0
  75. package/dist/modules/context/manager.js +440 -0
  76. package/dist/modules/execution/audit-runners.js +206 -0
  77. package/dist/modules/execution/auditor.js +218 -0
  78. package/dist/modules/execution/execution-plugin.js +431 -0
  79. package/dist/modules/execution/index.js +8 -0
  80. package/dist/modules/execution/module.js +625 -0
  81. package/dist/modules/execution/moe-executor.js +304 -0
  82. package/dist/modules/execution/plan-coverage.js +68 -0
  83. package/dist/modules/execution/plan-persister.js +46 -0
  84. package/dist/modules/execution/plan-store.js +196 -0
  85. package/dist/modules/execution/plan-tool.js +677 -0
  86. package/dist/modules/execution/plan-validator.js +153 -0
  87. package/dist/modules/execution/planner.js +94 -0
  88. package/dist/modules/execution/stuck-detector.js +746 -0
  89. package/dist/modules/execution/tracker.js +69 -0
  90. package/dist/modules/execution/types.js +1 -0
  91. package/dist/modules/execution/verifier.js +235 -0
  92. package/dist/modules/execution/windows-commands.js +41 -0
  93. package/dist/modules/hallucination/confidence.js +66 -0
  94. package/dist/modules/hallucination/consistency.js +26 -0
  95. package/dist/modules/hallucination/detector.js +47 -0
  96. package/dist/modules/hallucination/factual.js +169 -0
  97. package/dist/modules/hallucination/index.js +5 -0
  98. package/dist/modules/hallucination/js-identifiers.js +262 -0
  99. package/dist/modules/hallucination/llm-judge.js +101 -0
  100. package/dist/modules/index.js +5 -0
  101. package/dist/modules/indexer/cache.js +40 -0
  102. package/dist/modules/indexer/index.js +3 -0
  103. package/dist/modules/indexer/module.js +246 -0
  104. package/dist/modules/indexer/project-profile.js +183 -0
  105. package/dist/modules/indexer/walker.js +101 -0
  106. package/dist/modules/lsp/check-tool.js +58 -0
  107. package/dist/modules/lsp/client.js +389 -0
  108. package/dist/modules/lsp/command.js +60 -0
  109. package/dist/modules/lsp/config.js +135 -0
  110. package/dist/modules/lsp/index.js +3 -0
  111. package/dist/modules/lsp/module.js +260 -0
  112. package/dist/modules/lsp/probe.js +86 -0
  113. package/dist/modules/lsp/project-root.js +32 -0
  114. package/dist/modules/lsp/startup-check.js +144 -0
  115. package/dist/modules/lsp/types.js +1 -0
  116. package/dist/modules/mcp/client.js +399 -0
  117. package/dist/modules/mcp/index.js +3 -0
  118. package/dist/modules/mcp/module.js +142 -0
  119. package/dist/modules/mcp/registry.js +15 -0
  120. package/dist/modules/memory/index.js +1 -0
  121. package/dist/modules/memory/module.js +96 -0
  122. package/dist/modules/memory/search.js +42 -0
  123. package/dist/modules/memory/store.js +69 -0
  124. package/dist/modules/pipelines/engine.js +60 -0
  125. package/dist/modules/pipelines/index.js +3 -0
  126. package/dist/modules/pipelines/parser.js +56 -0
  127. package/dist/modules/pipelines/template.js +14 -0
  128. package/dist/modules/plugins/builtin/lint-on-write.js +334 -0
  129. package/dist/modules/plugins/builtin/notify.js +9 -0
  130. package/dist/modules/plugins/index.js +1 -0
  131. package/dist/modules/plugins/loader.js +70 -0
  132. package/dist/modules/plugins/manager.js +261 -0
  133. package/dist/modules/plugins/types.js +1 -0
  134. package/dist/modules/pricing/index.js +61 -0
  135. package/dist/modules/pricing/prices.js +129 -0
  136. package/dist/modules/processes/detect.js +34 -0
  137. package/dist/modules/processes/index.js +2 -0
  138. package/dist/modules/processes/registry.js +327 -0
  139. package/dist/modules/processes/runner.js +23 -0
  140. package/dist/modules/providers/create.js +22 -0
  141. package/dist/modules/providers/fallback.js +79 -0
  142. package/dist/modules/providers/health.js +46 -0
  143. package/dist/modules/providers/index.js +5 -0
  144. package/dist/modules/providers/manager.js +161 -0
  145. package/dist/modules/providers/presets.js +128 -0
  146. package/dist/modules/providers/registry.js +22 -0
  147. package/dist/modules/providers/types.js +1 -0
  148. package/dist/modules/registry.js +48 -0
  149. package/dist/modules/security/audit-log.js +136 -0
  150. package/dist/modules/security/audit-notifier.js +292 -0
  151. package/dist/modules/security/command-validator.js +219 -0
  152. package/dist/modules/security/content-scanner.js +53 -0
  153. package/dist/modules/security/data-sanitizer.js +89 -0
  154. package/dist/modules/security/encryption.js +242 -0
  155. package/dist/modules/security/index.js +14 -0
  156. package/dist/modules/security/network-validator.js +88 -0
  157. package/dist/modules/security/path-validator.js +203 -0
  158. package/dist/modules/security/rate-limiter.js +119 -0
  159. package/dist/modules/security/security-policies.js +531 -0
  160. package/dist/modules/security/session-encryption.js +210 -0
  161. package/dist/modules/security/session-isolation.js +95 -0
  162. package/dist/modules/session/index.js +3 -0
  163. package/dist/modules/session/manager.js +172 -0
  164. package/dist/modules/session/module.js +24 -0
  165. package/dist/modules/session/store.js +222 -0
  166. package/dist/modules/session/types.js +1 -0
  167. package/dist/modules/skills/index.js +2 -0
  168. package/dist/modules/skills/loader.js +72 -0
  169. package/dist/modules/skills/matcher.js +27 -0
  170. package/dist/modules/skills/module.js +129 -0
  171. package/dist/modules/types.js +1 -0
  172. package/dist/modules/updater/checker.js +96 -0
  173. package/dist/modules/updater/index.js +2 -0
  174. package/dist/modules/updater/module.js +116 -0
  175. package/dist/modules/user-profile/compressor.js +16 -0
  176. package/dist/modules/user-profile/index.js +1 -0
  177. package/dist/modules/user-profile/profile.js +68 -0
  178. package/dist/skills/builtin/git.md +36 -36
  179. package/dist/skills/builtin/typescript.md +35 -35
  180. package/dist/tools/approve.js +33 -0
  181. package/dist/tools/attach-image.js +101 -0
  182. package/dist/tools/bash.js +519 -0
  183. package/dist/tools/browser.js +115 -0
  184. package/dist/tools/chunk-query.js +100 -0
  185. package/dist/tools/create-dir.js +56 -0
  186. package/dist/tools/delete-file.js +63 -0
  187. package/dist/tools/download-file.js +117 -0
  188. package/dist/tools/edit-file.js +80 -0
  189. package/dist/tools/enable-tools.js +59 -0
  190. package/dist/tools/executor.js +154 -0
  191. package/dist/tools/file-info.js +47 -0
  192. package/dist/tools/filter-tools.js +17 -0
  193. package/dist/tools/glob-tool.js +27 -0
  194. package/dist/tools/grep-tool.js +125 -0
  195. package/dist/tools/hidden-tools-block.js +37 -0
  196. package/dist/tools/index.js +78 -0
  197. package/dist/tools/list-dir.js +49 -0
  198. package/dist/tools/load-skill.js +43 -0
  199. package/dist/tools/mcp-call.js +69 -0
  200. package/dist/tools/move-file.js +86 -0
  201. package/dist/tools/path-utils.js +101 -0
  202. package/dist/tools/pipeline-run.js +145 -0
  203. package/dist/tools/preview.js +2 -0
  204. package/dist/tools/process-kill.js +40 -0
  205. package/dist/tools/process-list.js +37 -0
  206. package/dist/tools/process-log.js +54 -0
  207. package/dist/tools/question.js +141 -0
  208. package/dist/tools/read-file.js +179 -0
  209. package/dist/tools/recall.js +118 -0
  210. package/dist/tools/registry.js +47 -0
  211. package/dist/tools/remember.js +68 -0
  212. package/dist/tools/scope-check.js +32 -0
  213. package/dist/tools/search-history.js +85 -0
  214. package/dist/tools/subagent.js +196 -0
  215. package/dist/tools/types.js +1 -0
  216. package/dist/tools/user-input.js +123 -0
  217. package/dist/tools/web-browse.js +87 -0
  218. package/dist/tools/web-fetch.js +119 -0
  219. package/dist/tools/web-search.js +105 -0
  220. package/dist/tools/write-file.js +82 -0
  221. package/dist/ui/box.js +77 -0
  222. package/dist/ui/colors.js +4 -0
  223. package/dist/ui/diff.js +178 -0
  224. package/dist/ui/index.js +6 -0
  225. package/dist/ui/line-editor.js +822 -0
  226. package/dist/ui/line-math.js +73 -0
  227. package/dist/ui/md-formatter.js +212 -0
  228. package/dist/ui/output.js +13 -0
  229. package/dist/ui/plan-view.js +103 -0
  230. package/dist/ui/renderer.js +259 -0
  231. package/dist/ui/spinner.js +70 -0
  232. package/dist/ui/table.js +144 -0
  233. package/package.json +51 -51
@@ -0,0 +1,262 @@
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
+ * Also home of the shared "is this token actually a file?" filter
8
+ * (`isFilePathLike` / `extractFileLikeTokens` / `stripUrls`) so the two
9
+ * extractors cannot drift apart again (observed: auditor treated a URL
10
+ * hostname `whom-pointing-jewel-maine.trycloudflare.com` in a plan step as a
11
+ * missing file while the factual check correctly ignored it).
12
+ *
13
+ * Bare `word.ext` tokens are gated on an allow-list of real file extensions
14
+ * (`FILE_EXTENSIONS`) instead of a deny-list of TLDs β€” a domain in any present
15
+ * or future TLD (`Gismeteo.by`, `weather.com`, `example.xyz`) can never be
16
+ * mistaken for a file, and no TLD list needs maintaining.
17
+ */
18
+ const JS_GLOBALS = new Set([
19
+ "process",
20
+ "console",
21
+ "math",
22
+ "json",
23
+ "global",
24
+ "globalthis",
25
+ "window",
26
+ "document",
27
+ "buffer",
28
+ "module",
29
+ "require",
30
+ "exports",
31
+ "url",
32
+ "promise",
33
+ "array",
34
+ "object",
35
+ "string",
36
+ "number",
37
+ "boolean",
38
+ "symbol",
39
+ "date",
40
+ "regexp",
41
+ "error",
42
+ "map",
43
+ "set",
44
+ "weakmap",
45
+ "weakset",
46
+ "proxy",
47
+ "reflect",
48
+ "intl",
49
+ "crypto",
50
+ "performance",
51
+ "fetch",
52
+ "navigator",
53
+ "location",
54
+ "settimeout",
55
+ "setinterval",
56
+ "cleartimeout",
57
+ "clearinterval",
58
+ "queuemicrotask",
59
+ "structuredclone",
60
+ "textencoder",
61
+ "textdecoder",
62
+ "atomics",
63
+ "sharedarraybuffer",
64
+ "dataview",
65
+ "arraybuffer",
66
+ "bigint",
67
+ "infinity",
68
+ "nan",
69
+ "undefined",
70
+ "bun",
71
+ "deno",
72
+ "node",
73
+ ]);
74
+ /**
75
+ * True when `candidate` starts with a known JS/TS global followed by a dot
76
+ * (`process.env`, `console.log`, `process.env.NODE` partial matches from
77
+ * `\b[\w./\\-]+\.[a-z]+`-style regexes) β€” member access, not a file path.
78
+ */
79
+ export function isJsMemberAccess(candidate) {
80
+ const lower = candidate.toLowerCase();
81
+ const m = lower.match(/^([\w-]+)\./);
82
+ return m !== null && JS_GLOBALS.has(m[1]);
83
+ }
84
+ /**
85
+ * File extensions that make a bare `word.ext` token a plausible file path.
86
+ *
87
+ * An allow-list, deliberately: enumerating everything that is NOT a file (TLDs,
88
+ * brand names, …) is a brittle heuristic that can never be complete. Instead a
89
+ * bare `word.ext` is only treated as a file when its extension is a known one β€”
90
+ * so `Gismeteo.by`, `weather.com`, or any future TLD is never flagged, while a
91
+ * genuine `config.json` / `helper.ts` still is.
92
+ */
93
+ const FILE_EXTENSIONS = new Set([
94
+ // source / code
95
+ "ts",
96
+ "tsx",
97
+ "js",
98
+ "jsx",
99
+ "mjs",
100
+ "cjs",
101
+ "py",
102
+ "pyc",
103
+ "rb",
104
+ "go",
105
+ "rs",
106
+ "java",
107
+ "jar",
108
+ "kt",
109
+ "kts",
110
+ "c",
111
+ "h",
112
+ "cc",
113
+ "cpp",
114
+ "cxx",
115
+ "hpp",
116
+ "hh",
117
+ "cs",
118
+ "php",
119
+ "swift",
120
+ "m",
121
+ "mm",
122
+ "lua",
123
+ "pl",
124
+ "sh",
125
+ "bash",
126
+ "zsh",
127
+ "fish",
128
+ "bat",
129
+ "cmd",
130
+ "ps1",
131
+ "vue",
132
+ "svelte",
133
+ "dart",
134
+ // config / data / docs
135
+ "json",
136
+ "jsonc",
137
+ "json5",
138
+ "yaml",
139
+ "yml",
140
+ "toml",
141
+ "ini",
142
+ "cfg",
143
+ "conf",
144
+ "env",
145
+ "xml",
146
+ "html",
147
+ "htm",
148
+ "md",
149
+ "markdown",
150
+ "rst",
151
+ "txt",
152
+ "log",
153
+ "csv",
154
+ "tsv",
155
+ "lock",
156
+ "sql",
157
+ "sqlite",
158
+ "db",
159
+ "wasm",
160
+ "map",
161
+ "css",
162
+ "scss",
163
+ "sass",
164
+ "less",
165
+ // assets / binary
166
+ "svg",
167
+ "png",
168
+ "jpg",
169
+ "jpeg",
170
+ "gif",
171
+ "webp",
172
+ "bmp",
173
+ "ico",
174
+ "avif",
175
+ "tiff",
176
+ "pdf",
177
+ "doc",
178
+ "docx",
179
+ "xls",
180
+ "xlsx",
181
+ "ppt",
182
+ "pptx",
183
+ "odt",
184
+ "ods",
185
+ "zip",
186
+ "gz",
187
+ "tar",
188
+ "tgz",
189
+ "bz2",
190
+ "xz",
191
+ "7z",
192
+ "rar",
193
+ "bin",
194
+ "exe",
195
+ "dll",
196
+ "so",
197
+ "o",
198
+ "a",
199
+ "dylib",
200
+ ]);
201
+ /** Well-known runtime/library names that end in .js/.ts but are NOT files. */
202
+ const TECH_NAMES = new Set([
203
+ "node.js",
204
+ "react.js",
205
+ "vue.js",
206
+ "next.js",
207
+ "angular.js",
208
+ "express.js",
209
+ "deno.js",
210
+ "qwik.js",
211
+ "svelte.js",
212
+ "jquery.js",
213
+ ]);
214
+ const FILE_TOKEN_RE = /\b(?:[a-zA-Z]:[\\/])?[\w./\\-]+\.[a-z]{1,6}\b/gi;
215
+ /**
216
+ * True when `candidate` is a plausible file path token: for a path with a
217
+ * directory separator the last segment must carry a non-empty stem before the
218
+ * extension (extension-only segments like `tsx/.ts` are rejected), while a bare
219
+ * `word.ext` is only a file when its extension is a known file extension (so
220
+ * domains like `Gismeteo.by` / `weather.com` are never files). JS member access
221
+ * (`process.env`) and technology names (`node.js`) are never files.
222
+ */
223
+ export function isFilePathLike(s) {
224
+ const lower = s.toLowerCase();
225
+ if (TECH_NAMES.has(lower))
226
+ return false;
227
+ if (isJsMemberAccess(s))
228
+ return false;
229
+ const ext = s.split(".").pop()?.toLowerCase() || "";
230
+ if (!s.includes("/") && !s.includes("\\")) {
231
+ if (!/^\w+\.[a-z]{1,6}$/i.test(s))
232
+ return false;
233
+ return FILE_EXTENSIONS.has(ext);
234
+ }
235
+ // Tokens with a directory separator: require the LAST segment to carry a
236
+ // real file name (a non-empty stem before the extension). Otherwise an
237
+ // extension-only segment like "tsx/.ts" (from ".tsx/.ts" in a step
238
+ // description) or a dotfile ("src/.env") is misread as a file and the plan
239
+ // deliverable gate demands "create tsx/.ts" (observed in ses_mstda6uo:
240
+ // step "ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ Ρ‡Ρ‚ΠΎ ΠΎΡΡ‚Π°Π»ΠΈΡΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ .tsx/.ts Ρ„Π°ΠΉΠ»Ρ‹").
241
+ const last = s.split(/[\\/]/).pop() ?? "";
242
+ const lastDot = last.lastIndexOf(".");
243
+ if (lastDot <= 0)
244
+ return false;
245
+ return true;
246
+ }
247
+ /**
248
+ * Extract deduplicated file-like tokens from free text. Bare `word.ext` tokens
249
+ * are filtered through `isFilePathLike` (allow-list of real file extensions, so
250
+ * hostnames/TLDs like `whom-pointing-jewel-maine.trycloudflare.com` or
251
+ * `Gismeteo.by` never survive); URLs are stripped first so
252
+ * `https://host/repo.git` never survives as a "file".
253
+ */
254
+ export function extractFileLikeTokens(text) {
255
+ const matches = text.match(FILE_TOKEN_RE) || [];
256
+ return [...new Set(matches.filter(isFilePathLike))];
257
+ }
258
+ /** Remove URL tokens (scheme://… up to whitespace/quote) so they are never
259
+ * parsed as file paths. */
260
+ export function stripUrls(text) {
261
+ return text.replace(/\bhttps?:\/\/[^\s"'<>]+/gi, " ");
262
+ }
@@ -0,0 +1,101 @@
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() ? ` β€” ${verdict.reason.trim()}` : "";
46
+ return {
47
+ status: "warn",
48
+ reason: t("hall.contradiction_llm", { reason }),
49
+ };
50
+ }
51
+ return { status: "pass" };
52
+ }
53
+ catch {
54
+ return { status: "pass" };
55
+ }
56
+ }
57
+ async askJudge(messages) {
58
+ let text = "";
59
+ let timer;
60
+ const consume = (async () => {
61
+ for await (const chunk of this.provider.chat(messages, [])) {
62
+ if (chunk.type === "text" && chunk.content) {
63
+ text += chunk.content;
64
+ }
65
+ }
66
+ return text;
67
+ })();
68
+ const timeout = new Promise((_, reject) => {
69
+ timer = setTimeout(() => reject(new Error("LLM judge timed out")), JUDGE_TIMEOUT_MS);
70
+ });
71
+ try {
72
+ return await Promise.race([consume, timeout]);
73
+ }
74
+ finally {
75
+ if (timer)
76
+ clearTimeout(timer);
77
+ }
78
+ }
79
+ parseVerdict(text) {
80
+ const block = text.match(/\{[\s\S]*\}/);
81
+ if (block) {
82
+ try {
83
+ const obj = JSON.parse(block[0]);
84
+ if (typeof obj.contradicts === "boolean") {
85
+ return {
86
+ contradicts: obj.contradicts,
87
+ reason: typeof obj.reason === "string" ? obj.reason : undefined,
88
+ };
89
+ }
90
+ }
91
+ catch {
92
+ // fall through to lenient parsing
93
+ }
94
+ }
95
+ const lower = text.toLowerCase();
96
+ if (lower.includes('"contradicts": true') || /^yes\b/.test(lower.trim())) {
97
+ return { contradicts: true, reason: text.slice(0, 200) };
98
+ }
99
+ return { contradicts: false };
100
+ }
101
+ }
@@ -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,40 @@
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 {
36
+ /* ignore */
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,3 @@
1
+ export { Indexer } from "./walker";
2
+ export { IndexCache } from "./cache";
3
+ export { IndexerModule } from "./module";
@@ -0,0 +1,246 @@
1
+ import { dirname } from "path";
2
+ import { Indexer } from "./walker";
3
+ import { IndexCache } from "./cache";
4
+ import { buildProjectProfileLine } from "./project-profile";
5
+ import { t } from "../../i18n/index";
6
+ export class IndexerModule {
7
+ name = "indexer";
8
+ indexer;
9
+ cache;
10
+ baseDir;
11
+ index = null;
12
+ rebuildTimeout = null;
13
+ constructor(opts) {
14
+ this.baseDir = opts.baseDir;
15
+ this.indexer = new Indexer(opts.baseDir);
16
+ this.cache = new IndexCache(opts.cacheDir);
17
+ }
18
+ async buildIndex() {
19
+ if (this.index)
20
+ return this.index;
21
+ const cached = this.cache.load();
22
+ if (cached) {
23
+ this.index = cached;
24
+ return cached;
25
+ }
26
+ try {
27
+ const result = await this.indexer.walk();
28
+ this.cache.save(result);
29
+ this.index = result;
30
+ return result;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ async refresh() {
37
+ this.cache.invalidate();
38
+ this.index = null;
39
+ return this.buildIndex();
40
+ }
41
+ find(query) {
42
+ if (!this.index)
43
+ return [];
44
+ const q = query.toLowerCase();
45
+ return this.index.files.filter((f) => {
46
+ const path = f.path.toLowerCase();
47
+ return path.includes(q) || f.exports.some((e) => e.toLowerCase().includes(q));
48
+ });
49
+ }
50
+ watch() {
51
+ this.unwatch();
52
+ try {
53
+ this.indexer.watch((_event, filename) => {
54
+ if (!filename)
55
+ return;
56
+ if (this.rebuildTimeout)
57
+ clearTimeout(this.rebuildTimeout);
58
+ this.rebuildTimeout = setTimeout(() => {
59
+ this.refresh().catch(() => { });
60
+ }, 2000);
61
+ });
62
+ }
63
+ catch {
64
+ // Watching is best-effort; manual refresh still works.
65
+ }
66
+ }
67
+ unwatch() {
68
+ if (this.rebuildTimeout) {
69
+ clearTimeout(this.rebuildTimeout);
70
+ this.rebuildTimeout = null;
71
+ }
72
+ this.indexer.unwatch();
73
+ }
74
+ getSystemPromptBlock() {
75
+ if (!this.index)
76
+ return null;
77
+ const content = this.formatMap(this.index);
78
+ return {
79
+ content,
80
+ priority: "normal",
81
+ essential: false,
82
+ estimatedTokens: this.estimateTokens(content),
83
+ };
84
+ }
85
+ getToolDefinitions() {
86
+ return [this.createProjectMapTool()];
87
+ }
88
+ getPlugin() {
89
+ return {
90
+ name: "indexer",
91
+ onSessionStart: () => {
92
+ this.buildIndex().catch(() => { });
93
+ this.watch();
94
+ },
95
+ onSessionEnd: () => {
96
+ this.unwatch();
97
+ },
98
+ };
99
+ }
100
+ formatMap(result) {
101
+ const summary = this.indexer.summarize(result);
102
+ const stackLine = buildProjectProfileLine(this.baseDir);
103
+ const dirCounts = this.getDirectoryCounts(result);
104
+ const topDirs = Object.entries(dirCounts)
105
+ .sort((a, b) => b[1] - a[1])
106
+ .slice(0, 10)
107
+ .map(([dir, count]) => `${dir} (${count})`)
108
+ .join(", ") || "-";
109
+ const fileLines = result.files.slice(0, 100).map((f) => {
110
+ const path = f.path.replace(/\\/g, "/");
111
+ const exports = f.exports.length > 0 ? `: ${f.exports.join(", ")}` : "";
112
+ return `- ${path}${exports}`;
113
+ });
114
+ const more = result.files.length > 100
115
+ ? `\n${t("indexer.and_more", { count: result.files.length - 100 })}`
116
+ : "";
117
+ const duplicates = this.findDuplicateBasenames(result);
118
+ return [
119
+ `${t("indexer.map_header")} (${this.baseDir})`,
120
+ summary,
121
+ ...(stackLine ? [stackLine] : []),
122
+ `${t("indexer.top_directories")}: ${topDirs}`,
123
+ ...(duplicates.length > 0 ? [t("indexer.duplicates", { names: duplicates.join(", ") })] : []),
124
+ `${t("indexer.files")}:` + (fileLines.length > 0 ? "" : " " + t("indexer.empty")),
125
+ ...fileLines,
126
+ more,
127
+ ].join("\n");
128
+ }
129
+ /**
130
+ * Find files that share a basename across different extensions in the same
131
+ * directory (e.g. `ProductCard.js` + `ProductCard.tsx`). This is a purely
132
+ * structural fact about the file tree β€” a stale transpiled twin may shadow
133
+ * the real source at build time. Flagging it is not task classification, so
134
+ * it does not violate the no-keyword-matching rule; the model decides what
135
+ * to do with the information.
136
+ */
137
+ findDuplicateBasenames(result) {
138
+ const byDir = {};
139
+ for (const f of result.files) {
140
+ const path = f.path.replace(/\\/g, "/");
141
+ const idx = path.lastIndexOf("/");
142
+ const dir = idx >= 0 ? path.slice(0, idx) : "";
143
+ const name = path.slice(idx + 1);
144
+ const dot = name.lastIndexOf(".");
145
+ if (dot <= 0)
146
+ continue;
147
+ const base = name.slice(0, dot);
148
+ const ext = name.slice(dot + 1);
149
+ if (!byDir[dir])
150
+ byDir[dir] = new Map();
151
+ const list = byDir[dir].get(base) ?? [];
152
+ list.push(ext);
153
+ byDir[dir].set(base, list);
154
+ }
155
+ const dups = [];
156
+ for (const dir of Object.keys(byDir).sort()) {
157
+ for (const [base, exts] of byDir[dir]) {
158
+ if (exts.length < 2)
159
+ continue;
160
+ const uniqueExts = [...new Set(exts)].sort();
161
+ const dirPrefix = dir ? `${dir}/` : "";
162
+ dups.push(`${dirPrefix}${base}.{${uniqueExts.join(",")}}`);
163
+ }
164
+ }
165
+ return dups;
166
+ }
167
+ getDirectoryCounts(result) {
168
+ const counts = {};
169
+ for (const f of result.files) {
170
+ const normalized = f.path.replace(/\\/g, "/");
171
+ const dir = dirname(normalized);
172
+ const key = dir === "." ? "(root)" : dir;
173
+ counts[key] = (counts[key] || 0) + 1;
174
+ }
175
+ return counts;
176
+ }
177
+ estimateTokens(content) {
178
+ return Math.ceil(content.length / 4);
179
+ }
180
+ createProjectMapTool() {
181
+ return {
182
+ name: "project_map",
183
+ icon: "πŸ—ΊοΈ",
184
+ alwaysOn: true,
185
+ description: t("indexer.project_map_desc"),
186
+ parameters: {
187
+ type: "object",
188
+ properties: {
189
+ action: {
190
+ type: "string",
191
+ enum: ["summary", "refresh", "find"],
192
+ description: t("indexer.project_map_action_desc"),
193
+ },
194
+ query: {
195
+ type: "string",
196
+ description: t("indexer.project_map_query_desc"),
197
+ },
198
+ },
199
+ required: ["action"],
200
+ },
201
+ handler: async (_ctx, args) => {
202
+ const action = String(args.action || "summary");
203
+ if (action === "refresh") {
204
+ const result = await this.refresh();
205
+ const summary = result ? this.indexer.summarize(result) : t("indexer.empty");
206
+ const stackLine = result ? buildProjectProfileLine(this.baseDir) : null;
207
+ const output = summary && stackLine ? `${summary}\n${stackLine}` : summary;
208
+ return this.makeResult(t("indexer.refreshed", { summary: output }));
209
+ }
210
+ if (action === "find") {
211
+ const query = String(args.query || "").toLowerCase();
212
+ if (!query)
213
+ return { success: false, output: t("tool.invalid_params") };
214
+ const matches = this.find(query);
215
+ if (matches.length === 0) {
216
+ return this.makeResult(t("indexer.no_matches", { query }));
217
+ }
218
+ const lines = matches
219
+ .map((f) => {
220
+ const path = f.path.replace(/\\/g, "/");
221
+ const exports = f.exports.length > 0 ? `: ${f.exports.join(", ")}` : "";
222
+ return `- ${path}${exports}`;
223
+ })
224
+ .join("\n");
225
+ return this.makeResult(t("indexer.find_results", {
226
+ count: matches.length,
227
+ results: lines,
228
+ }));
229
+ }
230
+ if (!this.index) {
231
+ await this.buildIndex();
232
+ }
233
+ if (!this.index) {
234
+ return this.makeResult(t("indexer.not_indexed"));
235
+ }
236
+ const summary = this.indexer.summarize(this.index);
237
+ const stackLine = buildProjectProfileLine(this.baseDir);
238
+ const output = summary && stackLine ? `${summary}\n${stackLine}` : summary;
239
+ return this.makeResult(t("indexer.summary", { summary: output }));
240
+ },
241
+ };
242
+ }
243
+ makeResult(output) {
244
+ return { success: true, output, display: output };
245
+ }
246
+ }