micro-models-agent 0.41.0 → 0.41.2

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