micro-models-agent 0.41.2 → 0.43.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 (171) hide show
  1. package/bin/mma.mjs +41 -41
  2. package/dist/cli/commands.js +19 -9
  3. package/dist/cli/completer.js +37 -36
  4. package/dist/cli/index.js +2 -2
  5. package/dist/cli/main.js +23 -48
  6. package/dist/cli/repl-commands.js +12 -40
  7. package/dist/cli/repl.js +87 -217
  8. package/dist/cli/security-commands.js +7 -5
  9. package/dist/cli/setup.js +26 -8
  10. package/dist/config/config.js +5 -52
  11. package/dist/config/defaults.js +5 -29
  12. package/dist/config/experts.js +1 -1
  13. package/dist/config/index.js +3 -3
  14. package/dist/config/security.js +10 -3
  15. package/dist/core/agent-moe.js +10 -2
  16. package/dist/core/agent.js +82 -273
  17. package/dist/core/bootstrap.js +13 -80
  18. package/dist/core/index.js +2 -2
  19. package/dist/core/prompt-builder.js +2 -23
  20. package/dist/core/session-logger.js +4 -46
  21. package/dist/i18n/en.json +2 -75
  22. package/dist/i18n/ru.json +1 -74
  23. package/dist/index.js +1 -1
  24. package/dist/llm/image-utils.js +5 -4
  25. package/dist/llm/index.js +4 -4
  26. package/dist/llm/model-loader.js +6 -6
  27. package/dist/llm/openai-compat.js +34 -40
  28. package/dist/llm/orchestrator.js +29 -33
  29. package/dist/llm/response.js +9 -9
  30. package/dist/logger/app-logger.js +1 -1
  31. package/dist/logger/index.js +1 -1
  32. package/dist/main.js +648 -183
  33. package/dist/migration/backup.js +13 -13
  34. package/dist/migration/detect.js +11 -11
  35. package/dist/migration/index.js +2 -2
  36. package/dist/modules/browser/actions.js +4 -34
  37. package/dist/modules/browser/bridge-server.mjs +202 -202
  38. package/dist/modules/browser/cookie-store.js +6 -6
  39. package/dist/modules/browser/index.js +5 -7
  40. package/dist/modules/browser/module.js +7 -8
  41. package/dist/modules/browser/session.js +84 -87
  42. package/dist/modules/browser/snapshot.js +58 -92
  43. package/dist/modules/browser/types.js +1 -4
  44. package/dist/modules/certification/cli.js +4 -2
  45. package/dist/modules/certification/fact-checker.js +3 -1
  46. package/dist/modules/certification/loader.js +9 -3
  47. package/dist/modules/certification/runner.js +4 -1
  48. package/dist/modules/context/index.js +1 -1
  49. package/dist/modules/context/manager.js +86 -160
  50. package/dist/modules/execution/auditor.js +25 -177
  51. package/dist/modules/execution/module.js +544 -201
  52. package/dist/modules/execution/moe-executor.js +0 -25
  53. package/dist/modules/execution/plan-store.js +3 -1
  54. package/dist/modules/execution/plan-validator.js +10 -10
  55. package/dist/modules/execution/planner.js +1 -6
  56. package/dist/modules/execution/stuck-detector.js +10 -173
  57. package/dist/modules/execution/verifier.js +42 -86
  58. package/dist/modules/hallucination/confidence.js +1 -8
  59. package/dist/modules/hallucination/detector.js +5 -2
  60. package/dist/modules/hallucination/factual.js +64 -3
  61. package/dist/modules/hallucination/index.js +1 -1
  62. package/dist/modules/hallucination/js-identifiers.js +0 -190
  63. package/dist/modules/hallucination/llm-judge.js +3 -1
  64. package/dist/modules/indexer/cache.js +7 -9
  65. package/dist/modules/indexer/index.js +3 -3
  66. package/dist/modules/indexer/module.js +42 -95
  67. package/dist/modules/indexer/walker.js +17 -17
  68. package/dist/modules/lsp/client.js +31 -74
  69. package/dist/modules/lsp/config.js +33 -87
  70. package/dist/modules/lsp/index.js +3 -3
  71. package/dist/modules/lsp/module.js +21 -185
  72. package/dist/modules/mcp/module.js +6 -2
  73. package/dist/modules/memory/index.js +1 -1
  74. package/dist/modules/memory/module.js +23 -71
  75. package/dist/modules/memory/search.js +9 -11
  76. package/dist/modules/memory/store.js +13 -13
  77. package/dist/modules/pipelines/engine.js +10 -10
  78. package/dist/modules/pipelines/index.js +3 -3
  79. package/dist/modules/pipelines/parser.js +14 -17
  80. package/dist/modules/pipelines/template.js +1 -1
  81. package/dist/modules/plugins/builtin/lint-on-write.js +16 -21
  82. package/dist/modules/plugins/builtin/notify.js +2 -3
  83. package/dist/modules/plugins/index.js +1 -1
  84. package/dist/modules/plugins/loader.js +17 -59
  85. package/dist/modules/plugins/manager.js +17 -73
  86. package/dist/modules/processes/index.js +1 -1
  87. package/dist/modules/processes/registry.js +46 -135
  88. package/dist/modules/registry.js +2 -4
  89. package/dist/modules/security/audit-notifier.js +39 -39
  90. package/dist/modules/security/command-validator.js +8 -2
  91. package/dist/modules/security/data-sanitizer.js +9 -1
  92. package/dist/modules/security/encryption.js +56 -58
  93. package/dist/modules/security/network-validator.js +9 -1
  94. package/dist/modules/security/path-validator.js +3 -1
  95. package/dist/modules/security/security-policies.js +19 -3
  96. package/dist/modules/security/session-encryption.js +1 -1
  97. package/dist/modules/security/session-isolation.js +8 -8
  98. package/dist/modules/session/index.js +3 -3
  99. package/dist/modules/session/module.js +5 -5
  100. package/dist/modules/session/store.js +9 -3
  101. package/dist/modules/skills/module.js +2 -1
  102. package/dist/modules/updater/checker.js +6 -70
  103. package/dist/modules/updater/index.js +1 -2
  104. package/dist/modules/user-profile/compressor.js +2 -2
  105. package/dist/modules/user-profile/index.js +1 -1
  106. package/dist/modules/user-profile/profile.js +9 -9
  107. package/dist/tools/attach-image.js +1 -1
  108. package/dist/tools/bash.js +19 -178
  109. package/dist/tools/browser.js +29 -46
  110. package/dist/tools/executor.js +5 -4
  111. package/dist/tools/file-info.js +12 -13
  112. package/dist/tools/filter-tools.js +2 -9
  113. package/dist/tools/glob-tool.js +11 -11
  114. package/dist/tools/grep-tool.js +3 -1
  115. package/dist/tools/index.js +2 -13
  116. package/dist/tools/list-dir.js +17 -18
  117. package/dist/tools/load-skill.js +3 -1
  118. package/dist/tools/path-utils.js +4 -4
  119. package/dist/tools/pipeline-run.js +25 -25
  120. package/dist/tools/process-kill.js +11 -11
  121. package/dist/tools/process-list.js +22 -20
  122. package/dist/tools/process-log.js +18 -22
  123. package/dist/tools/question.js +3 -1
  124. package/dist/tools/read-file.js +2 -10
  125. package/dist/tools/recall.js +37 -44
  126. package/dist/tools/registry.js +4 -15
  127. package/dist/tools/remember.js +29 -29
  128. package/dist/tools/scope-check.js +9 -9
  129. package/dist/tools/subagent.js +9 -54
  130. package/dist/tools/user-input.js +1 -1
  131. package/dist/tools/web-browse.js +3 -3
  132. package/dist/tools/web-fetch.js +3 -3
  133. package/dist/tools/web-search.js +3 -3
  134. package/dist/tools/write-file.js +3 -1
  135. package/dist/ui/box.js +5 -1
  136. package/dist/ui/index.js +6 -6
  137. package/dist/ui/md-formatter.js +33 -33
  138. package/dist/ui/output.js +5 -5
  139. package/dist/ui/renderer.js +10 -15
  140. package/dist/ui/table.js +1 -1
  141. package/package.json +48 -48
  142. package/dist/cli/plugin-commands.js +0 -36
  143. package/dist/cli/run-result.js +0 -22
  144. package/dist/core/version.js +0 -24
  145. package/dist/modules/artifacts/store.js +0 -61
  146. package/dist/modules/browser/bridge-client.js +0 -199
  147. package/dist/modules/browser/bridge-path.js +0 -10
  148. package/dist/modules/browser/driver.js +0 -136
  149. package/dist/modules/context/chunk-query.js +0 -100
  150. package/dist/modules/context/fact-extractor.js +0 -162
  151. package/dist/modules/context/history.js +0 -15
  152. package/dist/modules/execution/audit-runners.js +0 -152
  153. package/dist/modules/execution/execution-plugin.js +0 -272
  154. package/dist/modules/execution/plan-tool.js +0 -508
  155. package/dist/modules/execution/windows-commands.js +0 -41
  156. package/dist/modules/indexer/project-profile.js +0 -183
  157. package/dist/modules/lsp/check-tool.js +0 -58
  158. package/dist/modules/lsp/command.js +0 -60
  159. package/dist/modules/lsp/probe.js +0 -76
  160. package/dist/modules/lsp/project-root.js +0 -32
  161. package/dist/modules/lsp/startup-check.js +0 -141
  162. package/dist/modules/processes/detect.js +0 -34
  163. package/dist/modules/skills/matcher.js +0 -27
  164. package/dist/modules/updater/module.js +0 -116
  165. package/dist/tools/chunk-query.js +0 -99
  166. package/dist/tools/download-file.js +0 -116
  167. package/dist/tools/enable-tools.js +0 -58
  168. package/dist/tools/hidden-tools-block.js +0 -37
  169. package/dist/ui/line-editor.js +0 -703
  170. package/dist/ui/line-math.js +0 -69
  171. package/dist/ui/plan-view.js +0 -103
@@ -8,11 +8,7 @@ export class ConfidenceCheck {
8
8
  }
9
9
  validate(response) {
10
10
  if (!response || response.length < MIN_CHARS) {
11
- return {
12
- status: "retry",
13
- kind: "short",
14
- reason: t("hall.short_response"),
15
- };
11
+ return { status: "retry", reason: t("hall.short_response") };
16
12
  }
17
13
  // Language-agnostic: very short response with no structured content
18
14
  const wordCount = response.split(/\s+/).filter(Boolean).length;
@@ -20,7 +16,6 @@ export class ConfidenceCheck {
20
16
  if (wordCount < MIN_WORDS && !hasStructure) {
21
17
  return {
22
18
  status: "warn",
23
- kind: "short",
24
19
  reason: t("hall.short_response"),
25
20
  };
26
21
  }
@@ -30,7 +25,6 @@ export class ConfidenceCheck {
30
25
  if (overlap > 0.5) {
31
26
  return {
32
27
  status: "retry",
33
- kind: "repetition",
34
28
  reason: t("hall.repetitive", { pct: Math.round(overlap * 100) }),
35
29
  };
36
30
  }
@@ -46,7 +40,6 @@ export class ConfidenceCheck {
46
40
  if (diversity < 0.25) {
47
41
  return {
48
42
  status: "warn",
49
- kind: "diversity",
50
43
  reason: t("hall.repetitive", {
51
44
  pct: Math.round((1 - diversity) * 100),
52
45
  }),
@@ -21,7 +21,8 @@ export class HallucinationDetector {
21
21
  }
22
22
  async validate(response) {
23
23
  const confidenceResult = this.confidence.validate(response);
24
- if (confidenceResult.status === "retry" || confidenceResult.status === "block") {
24
+ if (confidenceResult.status === "retry" ||
25
+ confidenceResult.status === "block") {
25
26
  return confidenceResult;
26
27
  }
27
28
  const factualResult = this.factual?.validate(response);
@@ -29,7 +30,9 @@ export class HallucinationDetector {
29
30
  return factualResult;
30
31
  }
31
32
  // LLM-as-judge consistency: fast path (no decisions) skips any LLM call.
32
- const judgeResult = this.judge ? await this.judge.validate(response, this.consistency) : null;
33
+ const judgeResult = this.judge
34
+ ? await this.judge.validate(response, this.consistency)
35
+ : null;
33
36
  const warnings = [];
34
37
  if (judgeResult && judgeResult.status === "warn")
35
38
  warnings.push(judgeResult.reason || "");
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readdirSync } from "fs";
2
2
  import { resolve, isAbsolute, join } from "path";
3
3
  import { t } from "../../i18n/index";
4
- import { extractFileLikeTokens, stripUrls } from "./js-identifiers";
4
+ import { isJsMemberAccess } from "./js-identifiers";
5
5
  /** Generated/cached dirs to skip when scanning for bare file names. */
6
6
  const IGNORED_DIRS = new Set([
7
7
  "node_modules",
@@ -12,6 +12,59 @@ const IGNORED_DIRS = new Set([
12
12
  ".mma",
13
13
  "_testing",
14
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
+ }
15
68
  export class FactualCheck {
16
69
  baseDir;
17
70
  nameCache = null;
@@ -82,7 +135,8 @@ export class FactualCheck {
82
135
  */
83
136
  getNameIndex() {
84
137
  const now = Date.now();
85
- if (this.nameCache && now - this.nameCacheTime < FactualCheck.NAME_CACHE_TTL_MS) {
138
+ if (this.nameCache &&
139
+ now - this.nameCacheTime < FactualCheck.NAME_CACHE_TTL_MS) {
86
140
  return this.nameCache;
87
141
  }
88
142
  const index = new Map();
@@ -124,6 +178,13 @@ export class FactualCheck {
124
178
  return count;
125
179
  }
126
180
  extractFilePaths(text) {
127
- return extractFileLikeTokens(stripUrls(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);
128
189
  }
129
190
  }
@@ -1,4 +1,4 @@
1
- export { HallucinationDetector } from "./detector";
1
+ export { HallucinationDetector, } from "./detector";
2
2
  export { ConsistencyCheck } from "./consistency";
3
3
  export { ConfidenceCheck } from "./confidence";
4
4
  export { FactualCheck } from "./factual";
@@ -3,17 +3,6 @@
3
3
  * `Math.max`) looks like a file path to `\b[\w./\\-]+\.[a-z]+\b`-style regexes
4
4
  * but is code, not a file. Shared by the hallucination factual check and the
5
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
6
  */
18
7
  const JS_GLOBALS = new Set([
19
8
  "process",
@@ -81,182 +70,3 @@ export function isJsMemberAccess(candidate) {
81
70
  const m = lower.match(/^([\w-]+)\./);
82
71
  return m !== null && JS_GLOBALS.has(m[1]);
83
72
  }
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
- }
@@ -42,7 +42,9 @@ Reply with ONLY valid JSON, no other text:
42
42
  ]);
43
43
  const verdict = this.parseVerdict(verdictText);
44
44
  if (verdict.contradicts) {
45
- const reason = verdict.reason?.trim() ? ` — ${verdict.reason.trim()}` : "";
45
+ const reason = verdict.reason?.trim()
46
+ ? ` — ${verdict.reason.trim()}`
47
+ : "";
46
48
  return {
47
49
  status: "warn",
48
50
  reason: t("hall.contradiction_llm", { reason }),
@@ -1,10 +1,10 @@
1
- import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync } from "fs";
2
- import { join } from "path";
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync } from 'fs';
2
+ import { join } from 'path';
3
3
  export class IndexCache {
4
4
  cachePath;
5
5
  cache = null;
6
6
  constructor(cacheDir) {
7
- this.cachePath = join(cacheDir, "index-cache.json");
7
+ this.cachePath = join(cacheDir, 'index-cache.json');
8
8
  }
9
9
  load() {
10
10
  if (this.cache)
@@ -12,7 +12,7 @@ export class IndexCache {
12
12
  if (!existsSync(this.cachePath))
13
13
  return null;
14
14
  try {
15
- this.cache = JSON.parse(readFileSync(this.cachePath, "utf-8"));
15
+ this.cache = JSON.parse(readFileSync(this.cachePath, 'utf-8'));
16
16
  return this.cache;
17
17
  }
18
18
  catch {
@@ -21,10 +21,10 @@ export class IndexCache {
21
21
  }
22
22
  save(result) {
23
23
  this.cache = result;
24
- const dir = join(this.cachePath, "..");
24
+ const dir = join(this.cachePath, '..');
25
25
  if (!existsSync(dir))
26
26
  mkdirSync(dir, { recursive: true });
27
- writeFileSync(this.cachePath, JSON.stringify(result), "utf-8");
27
+ writeFileSync(this.cachePath, JSON.stringify(result), 'utf-8');
28
28
  }
29
29
  invalidate() {
30
30
  this.cache = null;
@@ -32,9 +32,7 @@ export class IndexCache {
32
32
  try {
33
33
  rmSync(this.cachePath);
34
34
  }
35
- catch {
36
- /* ignore */
37
- }
35
+ catch { /* ignore */ }
38
36
  }
39
37
  }
40
38
  }
@@ -1,3 +1,3 @@
1
- export { Indexer } from "./walker";
2
- export { IndexCache } from "./cache";
3
- export { IndexerModule } from "./module";
1
+ export { Indexer } from './walker';
2
+ export { IndexCache } from './cache';
3
+ export { IndexerModule } from './module';
@@ -1,10 +1,9 @@
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";
1
+ import { dirname } from 'path';
2
+ import { Indexer } from './walker';
3
+ import { IndexCache } from './cache';
4
+ import { t } from '../../i18n/index';
6
5
  export class IndexerModule {
7
- name = "indexer";
6
+ name = 'indexer';
8
7
  indexer;
9
8
  cache;
10
9
  baseDir;
@@ -77,7 +76,7 @@ export class IndexerModule {
77
76
  const content = this.formatMap(this.index);
78
77
  return {
79
78
  content,
80
- priority: "normal",
79
+ priority: 'normal',
81
80
  essential: false,
82
81
  estimatedTokens: this.estimateTokens(content),
83
82
  };
@@ -87,7 +86,7 @@ export class IndexerModule {
87
86
  }
88
87
  getPlugin() {
89
88
  return {
90
- name: "indexer",
89
+ name: 'indexer',
91
90
  onSessionStart: () => {
92
91
  this.buildIndex().catch(() => { });
93
92
  this.watch();
@@ -99,77 +98,35 @@ export class IndexerModule {
99
98
  }
100
99
  formatMap(result) {
101
100
  const summary = this.indexer.summarize(result);
102
- const stackLine = buildProjectProfileLine(this.baseDir);
103
101
  const dirCounts = this.getDirectoryCounts(result);
104
102
  const topDirs = Object.entries(dirCounts)
105
103
  .sort((a, b) => b[1] - a[1])
106
104
  .slice(0, 10)
107
105
  .map(([dir, count]) => `${dir} (${count})`)
108
- .join(", ") || "-";
106
+ .join(', ') || '-';
109
107
  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(", ")}` : "";
108
+ const path = f.path.replace(/\\/g, '/');
109
+ const exports = f.exports.length > 0 ? `: ${f.exports.join(', ')}` : '';
112
110
  return `- ${path}${exports}`;
113
111
  });
114
112
  const more = result.files.length > 100
115
- ? `\n${t("indexer.and_more", { count: result.files.length - 100 })}`
116
- : "";
117
- const duplicates = this.findDuplicateBasenames(result);
113
+ ? `\n${t('indexer.and_more', { count: result.files.length - 100 })}`
114
+ : '';
118
115
  return [
119
- `${t("indexer.map_header")} (${this.baseDir})`,
116
+ `${t('indexer.map_header')} (${this.baseDir})`,
120
117
  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")),
118
+ `${t('indexer.top_directories')}: ${topDirs}`,
119
+ `${t('indexer.files')}:` + (fileLines.length > 0 ? '' : ' ' + t('indexer.empty')),
125
120
  ...fileLines,
126
121
  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;
122
+ ].join('\n');
166
123
  }
167
124
  getDirectoryCounts(result) {
168
125
  const counts = {};
169
126
  for (const f of result.files) {
170
- const normalized = f.path.replace(/\\/g, "/");
127
+ const normalized = f.path.replace(/\\/g, '/');
171
128
  const dir = dirname(normalized);
172
- const key = dir === "." ? "(root)" : dir;
129
+ const key = dir === '.' ? '(root)' : dir;
173
130
  counts[key] = (counts[key] || 0) + 1;
174
131
  }
175
132
  return counts;
@@ -179,63 +136,53 @@ export class IndexerModule {
179
136
  }
180
137
  createProjectMapTool() {
181
138
  return {
182
- name: "project_map",
183
- alwaysOn: true,
184
- description: t("indexer.project_map_desc"),
139
+ name: 'project_map',
140
+ description: t('indexer.project_map_desc'),
185
141
  parameters: {
186
- type: "object",
142
+ type: 'object',
187
143
  properties: {
188
144
  action: {
189
- type: "string",
190
- enum: ["summary", "refresh", "find"],
191
- description: t("indexer.project_map_action_desc"),
145
+ type: 'string',
146
+ enum: ['summary', 'refresh', 'find'],
147
+ description: t('indexer.project_map_action_desc'),
192
148
  },
193
149
  query: {
194
- type: "string",
195
- description: t("indexer.project_map_query_desc"),
150
+ type: 'string',
151
+ description: t('indexer.project_map_query_desc'),
196
152
  },
197
153
  },
198
- required: ["action"],
154
+ required: ['action'],
199
155
  },
200
156
  handler: async (_ctx, args) => {
201
- const action = String(args.action || "summary");
202
- if (action === "refresh") {
157
+ const action = String(args.action || 'summary');
158
+ if (action === 'refresh') {
203
159
  const result = await this.refresh();
204
- const summary = result ? this.indexer.summarize(result) : t("indexer.empty");
205
- const stackLine = result ? buildProjectProfileLine(this.baseDir) : null;
206
- const output = summary && stackLine ? `${summary}\n${stackLine}` : summary;
207
- return this.makeResult(t("indexer.refreshed", { summary: output }));
160
+ const summary = result ? this.indexer.summarize(result) : t('indexer.empty');
161
+ return this.makeResult(t('indexer.refreshed', { summary }));
208
162
  }
209
- if (action === "find") {
210
- const query = String(args.query || "").toLowerCase();
163
+ if (action === 'find') {
164
+ const query = String(args.query || '').toLowerCase();
211
165
  if (!query)
212
- return { success: false, output: t("tool.invalid_params") };
166
+ return { success: false, output: t('tool.invalid_params') };
213
167
  const matches = this.find(query);
214
168
  if (matches.length === 0) {
215
- return this.makeResult(t("indexer.no_matches", { query }));
169
+ return this.makeResult(t('indexer.no_matches', { query }));
216
170
  }
217
- const lines = matches
218
- .map((f) => {
219
- const path = f.path.replace(/\\/g, "/");
220
- const exports = f.exports.length > 0 ? `: ${f.exports.join(", ")}` : "";
171
+ const lines = matches.map((f) => {
172
+ const path = f.path.replace(/\\/g, '/');
173
+ const exports = f.exports.length > 0 ? `: ${f.exports.join(', ')}` : '';
221
174
  return `- ${path}${exports}`;
222
- })
223
- .join("\n");
224
- return this.makeResult(t("indexer.find_results", {
225
- count: matches.length,
226
- results: lines,
227
- }));
175
+ }).join('\n');
176
+ return this.makeResult(t('indexer.find_results', { count: matches.length, results: lines }));
228
177
  }
229
178
  if (!this.index) {
230
179
  await this.buildIndex();
231
180
  }
232
181
  if (!this.index) {
233
- return this.makeResult(t("indexer.not_indexed"));
182
+ return this.makeResult(t('indexer.not_indexed'));
234
183
  }
235
184
  const summary = this.indexer.summarize(this.index);
236
- const stackLine = buildProjectProfileLine(this.baseDir);
237
- const output = summary && stackLine ? `${summary}\n${stackLine}` : summary;
238
- return this.makeResult(t("indexer.summary", { summary: output }));
185
+ return this.makeResult(t('indexer.summary', { summary }));
239
186
  },
240
187
  };
241
188
  }