micro-models-agent 0.46.1 → 0.46.3

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 (218) hide show
  1. package/README.md +312 -312
  2. package/dist/main.js +724 -530
  3. package/dist/modules/browser/bridge-server.mjs +202 -202
  4. package/dist/skills/builtin/git.md +36 -36
  5. package/dist/skills/builtin/typescript.md +35 -35
  6. package/package.json +48 -48
  7. package/dist/cli/commands.js +0 -323
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -165
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -661
  13. package/dist/cli/repl.js +0 -616
  14. package/dist/cli/run-result.js +0 -22
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -231
  17. package/dist/config/config.js +0 -249
  18. package/dist/config/defaults.js +0 -124
  19. package/dist/config/experts.js +0 -15
  20. package/dist/config/index.js +0 -3
  21. package/dist/config/security.js +0 -193
  22. package/dist/config/types.js +0 -1
  23. package/dist/core/agent-moe.js +0 -102
  24. package/dist/core/agent.js +0 -886
  25. package/dist/core/bootstrap.js +0 -404
  26. package/dist/core/index.js +0 -2
  27. package/dist/core/prompt-builder.js +0 -76
  28. package/dist/core/session-logger.js +0 -197
  29. package/dist/core/types.js +0 -1
  30. package/dist/core/version.js +0 -24
  31. package/dist/core/workspace.js +0 -76
  32. package/dist/i18n/en.json +0 -598
  33. package/dist/i18n/index.js +0 -46
  34. package/dist/i18n/ru.json +0 -598
  35. package/dist/index.js +0 -22
  36. package/dist/llm/image-utils.js +0 -143
  37. package/dist/llm/index.js +0 -4
  38. package/dist/llm/model-loader.js +0 -78
  39. package/dist/llm/openai-compat.js +0 -359
  40. package/dist/llm/orchestrator.js +0 -198
  41. package/dist/llm/provider.js +0 -10
  42. package/dist/llm/response.js +0 -39
  43. package/dist/llm/token-counter.js +0 -39
  44. package/dist/llm/types.js +0 -1
  45. package/dist/logger/app-logger.js +0 -143
  46. package/dist/logger/file-log.js +0 -151
  47. package/dist/logger/index.js +0 -1
  48. package/dist/migration/backup.js +0 -45
  49. package/dist/migration/detect.js +0 -50
  50. package/dist/migration/index.js +0 -2
  51. package/dist/modules/artifacts/store.js +0 -61
  52. package/dist/modules/browser/actions.js +0 -76
  53. package/dist/modules/browser/bridge-client.js +0 -199
  54. package/dist/modules/browser/bridge-path.js +0 -10
  55. package/dist/modules/browser/cookie-store.js +0 -24
  56. package/dist/modules/browser/driver.js +0 -136
  57. package/dist/modules/browser/index.js +0 -7
  58. package/dist/modules/browser/module.js +0 -29
  59. package/dist/modules/browser/session.js +0 -338
  60. package/dist/modules/browser/snapshot.js +0 -148
  61. package/dist/modules/browser/types.js +0 -12
  62. package/dist/modules/certification/cli.js +0 -174
  63. package/dist/modules/certification/fact-checker.js +0 -82
  64. package/dist/modules/certification/loader.js +0 -105
  65. package/dist/modules/certification/manifest.js +0 -50
  66. package/dist/modules/certification/runner.js +0 -159
  67. package/dist/modules/certification/scenarios.js +0 -124
  68. package/dist/modules/certification/types.js +0 -1
  69. package/dist/modules/context/chunk-query.js +0 -100
  70. package/dist/modules/context/fact-extractor.js +0 -162
  71. package/dist/modules/context/history.js +0 -15
  72. package/dist/modules/context/index.js +0 -1
  73. package/dist/modules/context/manager.js +0 -423
  74. package/dist/modules/execution/audit-runners.js +0 -152
  75. package/dist/modules/execution/auditor.js +0 -218
  76. package/dist/modules/execution/execution-plugin.js +0 -272
  77. package/dist/modules/execution/index.js +0 -8
  78. package/dist/modules/execution/module.js +0 -436
  79. package/dist/modules/execution/moe-executor.js +0 -291
  80. package/dist/modules/execution/plan-coverage.js +0 -68
  81. package/dist/modules/execution/plan-persister.js +0 -46
  82. package/dist/modules/execution/plan-store.js +0 -157
  83. package/dist/modules/execution/plan-tool.js +0 -508
  84. package/dist/modules/execution/plan-validator.js +0 -153
  85. package/dist/modules/execution/planner.js +0 -90
  86. package/dist/modules/execution/stuck-detector.js +0 -510
  87. package/dist/modules/execution/tracker.js +0 -67
  88. package/dist/modules/execution/types.js +0 -1
  89. package/dist/modules/execution/verifier.js +0 -222
  90. package/dist/modules/execution/windows-commands.js +0 -41
  91. package/dist/modules/hallucination/confidence.js +0 -66
  92. package/dist/modules/hallucination/consistency.js +0 -26
  93. package/dist/modules/hallucination/detector.js +0 -43
  94. package/dist/modules/hallucination/factual.js +0 -129
  95. package/dist/modules/hallucination/index.js +0 -5
  96. package/dist/modules/hallucination/js-identifiers.js +0 -262
  97. package/dist/modules/hallucination/llm-judge.js +0 -101
  98. package/dist/modules/index.js +0 -5
  99. package/dist/modules/indexer/cache.js +0 -40
  100. package/dist/modules/indexer/index.js +0 -3
  101. package/dist/modules/indexer/module.js +0 -245
  102. package/dist/modules/indexer/project-profile.js +0 -183
  103. package/dist/modules/indexer/walker.js +0 -101
  104. package/dist/modules/lsp/check-tool.js +0 -58
  105. package/dist/modules/lsp/client.js +0 -278
  106. package/dist/modules/lsp/command.js +0 -60
  107. package/dist/modules/lsp/config.js +0 -135
  108. package/dist/modules/lsp/index.js +0 -3
  109. package/dist/modules/lsp/module.js +0 -232
  110. package/dist/modules/lsp/probe.js +0 -76
  111. package/dist/modules/lsp/project-root.js +0 -32
  112. package/dist/modules/lsp/startup-check.js +0 -141
  113. package/dist/modules/lsp/types.js +0 -1
  114. package/dist/modules/mcp/client.js +0 -399
  115. package/dist/modules/mcp/index.js +0 -3
  116. package/dist/modules/mcp/module.js +0 -142
  117. package/dist/modules/mcp/registry.js +0 -15
  118. package/dist/modules/memory/index.js +0 -1
  119. package/dist/modules/memory/module.js +0 -96
  120. package/dist/modules/memory/search.js +0 -42
  121. package/dist/modules/memory/store.js +0 -69
  122. package/dist/modules/pipelines/engine.js +0 -60
  123. package/dist/modules/pipelines/index.js +0 -3
  124. package/dist/modules/pipelines/parser.js +0 -56
  125. package/dist/modules/pipelines/template.js +0 -14
  126. package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
  127. package/dist/modules/plugins/builtin/notify.js +0 -9
  128. package/dist/modules/plugins/index.js +0 -1
  129. package/dist/modules/plugins/loader.js +0 -70
  130. package/dist/modules/plugins/manager.js +0 -217
  131. package/dist/modules/plugins/types.js +0 -1
  132. package/dist/modules/processes/detect.js +0 -34
  133. package/dist/modules/processes/index.js +0 -2
  134. package/dist/modules/processes/registry.js +0 -327
  135. package/dist/modules/processes/runner.js +0 -23
  136. package/dist/modules/registry.js +0 -47
  137. package/dist/modules/security/audit-log.js +0 -136
  138. package/dist/modules/security/audit-notifier.js +0 -292
  139. package/dist/modules/security/command-validator.js +0 -205
  140. package/dist/modules/security/content-scanner.js +0 -53
  141. package/dist/modules/security/data-sanitizer.js +0 -89
  142. package/dist/modules/security/encryption.js +0 -242
  143. package/dist/modules/security/index.js +0 -14
  144. package/dist/modules/security/network-validator.js +0 -71
  145. package/dist/modules/security/path-validator.js +0 -207
  146. package/dist/modules/security/rate-limiter.js +0 -119
  147. package/dist/modules/security/security-policies.js +0 -531
  148. package/dist/modules/security/session-encryption.js +0 -210
  149. package/dist/modules/security/session-isolation.js +0 -95
  150. package/dist/modules/session/index.js +0 -3
  151. package/dist/modules/session/manager.js +0 -172
  152. package/dist/modules/session/module.js +0 -24
  153. package/dist/modules/session/store.js +0 -222
  154. package/dist/modules/session/types.js +0 -1
  155. package/dist/modules/skills/index.js +0 -2
  156. package/dist/modules/skills/loader.js +0 -72
  157. package/dist/modules/skills/matcher.js +0 -27
  158. package/dist/modules/skills/module.js +0 -129
  159. package/dist/modules/types.js +0 -1
  160. package/dist/modules/updater/checker.js +0 -96
  161. package/dist/modules/updater/index.js +0 -2
  162. package/dist/modules/updater/module.js +0 -116
  163. package/dist/modules/user-profile/compressor.js +0 -16
  164. package/dist/modules/user-profile/index.js +0 -1
  165. package/dist/modules/user-profile/profile.js +0 -68
  166. package/dist/tools/approve.js +0 -32
  167. package/dist/tools/attach-image.js +0 -89
  168. package/dist/tools/bash.js +0 -496
  169. package/dist/tools/browser.js +0 -114
  170. package/dist/tools/chunk-query.js +0 -99
  171. package/dist/tools/create-dir.js +0 -55
  172. package/dist/tools/delete-file.js +0 -62
  173. package/dist/tools/download-file.js +0 -116
  174. package/dist/tools/edit-file.js +0 -79
  175. package/dist/tools/enable-tools.js +0 -58
  176. package/dist/tools/executor.js +0 -144
  177. package/dist/tools/file-info.js +0 -46
  178. package/dist/tools/filter-tools.js +0 -17
  179. package/dist/tools/glob-tool.js +0 -26
  180. package/dist/tools/grep-tool.js +0 -84
  181. package/dist/tools/hidden-tools-block.js +0 -37
  182. package/dist/tools/index.js +0 -78
  183. package/dist/tools/list-dir.js +0 -48
  184. package/dist/tools/load-skill.js +0 -42
  185. package/dist/tools/mcp-call.js +0 -68
  186. package/dist/tools/move-file.js +0 -85
  187. package/dist/tools/path-utils.js +0 -51
  188. package/dist/tools/pipeline-run.js +0 -144
  189. package/dist/tools/preview.js +0 -2
  190. package/dist/tools/process-kill.js +0 -29
  191. package/dist/tools/process-list.js +0 -36
  192. package/dist/tools/process-log.js +0 -45
  193. package/dist/tools/question.js +0 -140
  194. package/dist/tools/read-file.js +0 -91
  195. package/dist/tools/recall.js +0 -117
  196. package/dist/tools/registry.js +0 -47
  197. package/dist/tools/remember.js +0 -67
  198. package/dist/tools/scope-check.js +0 -30
  199. package/dist/tools/search-history.js +0 -84
  200. package/dist/tools/subagent.js +0 -196
  201. package/dist/tools/types.js +0 -1
  202. package/dist/tools/user-input.js +0 -123
  203. package/dist/tools/web-browse.js +0 -86
  204. package/dist/tools/web-fetch.js +0 -98
  205. package/dist/tools/web-search.js +0 -78
  206. package/dist/tools/write-file.js +0 -81
  207. package/dist/ui/box.js +0 -77
  208. package/dist/ui/colors.js +0 -4
  209. package/dist/ui/diff.js +0 -178
  210. package/dist/ui/index.js +0 -6
  211. package/dist/ui/line-editor.js +0 -703
  212. package/dist/ui/line-math.js +0 -69
  213. package/dist/ui/md-formatter.js +0 -212
  214. package/dist/ui/output.js +0 -13
  215. package/dist/ui/plan-view.js +0 -103
  216. package/dist/ui/renderer.js +0 -209
  217. package/dist/ui/spinner.js +0 -70
  218. package/dist/ui/table.js +0 -144
@@ -1,135 +0,0 @@
1
- /**
2
- * LSP server defaults.
3
- *
4
- * Strategy: prefer `npx` (auto-downloads) over globally installed binaries.
5
- * Servers using system tools (rust-analyzer, gopls) have `autoInstall: false`
6
- * and are skipped silently when not found.
7
- */
8
- export const DEFAULT_LSP_CONFIG = {
9
- enabled: true,
10
- timeout: 15000,
11
- servers: {
12
- typescript: {
13
- command: "npx",
14
- args: [
15
- "--yes",
16
- "--package",
17
- "typescript-language-server",
18
- "--package",
19
- "typescript@5",
20
- "typescript-language-server",
21
- "--stdio",
22
- ],
23
- timeout: 30000,
24
- autoInstall: true,
25
- workspaceMarkers: ["package.json", "tsconfig.json"],
26
- },
27
- javascript: {
28
- command: "npx",
29
- args: [
30
- "--yes",
31
- "--package",
32
- "typescript-language-server",
33
- "--package",
34
- "typescript@5",
35
- "typescript-language-server",
36
- "--stdio",
37
- ],
38
- timeout: 30000,
39
- autoInstall: true,
40
- workspaceMarkers: ["package.json", "tsconfig.json"],
41
- },
42
- python: {
43
- command: "npx",
44
- args: ["pyright", "--stdio"],
45
- timeout: 15000,
46
- autoInstall: true,
47
- workspaceMarkers: ["pyproject.toml", "setup.py", "requirements.txt"],
48
- },
49
- rust: {
50
- command: "rust-analyzer",
51
- timeout: 15000,
52
- autoInstall: false,
53
- workspaceMarkers: ["Cargo.toml"],
54
- },
55
- go: {
56
- command: "gopls",
57
- timeout: 15000,
58
- autoInstall: false,
59
- workspaceMarkers: ["go.mod"],
60
- },
61
- json: {
62
- command: "npx",
63
- args: [
64
- "--yes",
65
- "--package",
66
- "vscode-langservers-extracted",
67
- "vscode-json-language-server",
68
- "--stdio",
69
- ],
70
- timeout: 30000,
71
- autoInstall: true,
72
- workspaceMarkers: ["package.json"],
73
- },
74
- html: {
75
- command: "npx",
76
- args: [
77
- "--yes",
78
- "--package",
79
- "vscode-langservers-extracted",
80
- "--package",
81
- "typescript@5",
82
- "vscode-html-language-server",
83
- "--stdio",
84
- ],
85
- timeout: 60000,
86
- autoInstall: true,
87
- workspaceMarkers: ["package.json"],
88
- },
89
- css: {
90
- command: "npx",
91
- args: [
92
- "--yes",
93
- "--package",
94
- "vscode-langservers-extracted",
95
- "--package",
96
- "typescript@5",
97
- "vscode-css-language-server",
98
- "--stdio",
99
- ],
100
- timeout: 60000,
101
- autoInstall: true,
102
- workspaceMarkers: ["package.json"],
103
- },
104
- },
105
- };
106
- const LANGUAGE_MAP = {
107
- ts: "typescript",
108
- tsx: "typescript",
109
- mts: "typescript",
110
- cts: "typescript",
111
- js: "javascript",
112
- jsx: "javascript",
113
- mjs: "javascript",
114
- cjs: "javascript",
115
- py: "python",
116
- rs: "rust",
117
- go: "go",
118
- json: "json",
119
- html: "html",
120
- css: "css",
121
- scss: "css",
122
- };
123
- /** Language id for a file extension (via LANGUAGE_MAP), or null when unsupported. */
124
- export function getLanguageForFile(filePath) {
125
- const ext = filePath.split(".").pop()?.toLowerCase();
126
- if (!ext)
127
- return null;
128
- return LANGUAGE_MAP[ext] ?? null;
129
- }
130
- export function getServerForFile(filePath, config) {
131
- const lang = getLanguageForFile(filePath);
132
- if (!lang)
133
- return null;
134
- return config.servers[lang] ?? null;
135
- }
@@ -1,3 +0,0 @@
1
- export { LspModule } from "./module";
2
- export { LspClient } from "./client";
3
- export { getServerForFile, DEFAULT_LSP_CONFIG } from "./config";
@@ -1,232 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { resolve } from "path";
3
- import { LspClient } from "./client";
4
- import { getServerForFile, DEFAULT_LSP_CONFIG } from "./config";
5
- import { findProjectRoot } from "./project-root";
6
- import { isPathInScope } from "../security/path-validator";
7
- import { DEFAULT_SECURITY_CONFIG } from "../../config/security";
8
- import { safeResolvePath } from "../../tools/path-utils";
9
- import { t } from "../../i18n/index";
10
- import { severityLabels, collectCheckFiles, formatCheckDiagnostics } from "./check-tool";
11
- /**
12
- * Consecutive LSP failures before a server is disabled for the session. A dead
13
- * server (not installed, npx auto-install failed, path missing) otherwise
14
- * spams `[LSP check failed]` on EVERY write, teaching the model to ignore the
15
- * signal entirely (observed: ses_mst2r0r5 had LSP dead all session and the
16
- * model never reacted). After the threshold we say so once and stop the noise
17
- * for that server — a CSS timeout must not take TypeScript checks down too.
18
- */
19
- const MAX_CONSECUTIVE_LSP_FAILURES = 3;
20
- export class LspModule {
21
- name = "lsp";
22
- config;
23
- client;
24
- failuresByServer = new Map();
25
- disabledServers = new Set();
26
- constructor(config, client) {
27
- this.config = { ...DEFAULT_LSP_CONFIG, ...config };
28
- this.client = client ?? new LspClient();
29
- }
30
- /** Test hook: has the module disabled any LSP server for the session? */
31
- isLspDisabled() {
32
- return this.disabledServers.size > 0;
33
- }
34
- /** Test hook: is the given server (config-derived key) disabled? */
35
- isServerDisabled(key) {
36
- return this.disabledServers.has(key);
37
- }
38
- /** Stable server identity derived from the config. */
39
- serverKey(server) {
40
- return `${server.command}:${(server.args ?? []).join(" ")}`;
41
- }
42
- getPlugin() {
43
- const self = this;
44
- return {
45
- name: "lsp-check",
46
- priority: 15,
47
- onAfterTool: async (_ctx, call, result) => {
48
- if (!self.config.enabled)
49
- return;
50
- if (call.name !== "write_file" && call.name !== "edit_file")
51
- return;
52
- if (!result.success)
53
- return;
54
- const filePath = String(call.arguments.path ?? "");
55
- if (!filePath)
56
- return;
57
- const fullPath = resolve(_ctx.baseDir, filePath);
58
- if (!existsSync(fullPath))
59
- return;
60
- const serverConfig = getServerForFile(fullPath, self.config);
61
- if (!serverConfig)
62
- return;
63
- const key = self.serverKey(serverConfig);
64
- if (self.disabledServers.has(key))
65
- return;
66
- const projectRoot = findProjectRoot(fullPath, _ctx.baseDir, serverConfig.workspaceMarkers ?? []);
67
- try {
68
- const diagnostics = await self.client.checkFile(fullPath, _ctx.baseDir, serverConfig, projectRoot);
69
- self.failuresByServer.set(key, 0);
70
- const errors = diagnostics.filter((d) => d.severity === 1);
71
- const warnings = diagnostics.filter((d) => d.severity === 2);
72
- if (errors.length > 0) {
73
- const items = formatDiagnostics(errors, fullPath);
74
- result.output += `\n\n[LSP errors]:\n${items}`;
75
- }
76
- if (warnings.length > 0) {
77
- const items = formatDiagnostics(warnings, fullPath);
78
- result.output += `\n\n[LSP warnings]:\n${items}`;
79
- }
80
- }
81
- catch (e) {
82
- // Surface failures instead of silently returning [] — a dead LSP
83
- // previously produced ZERO diagnostics across whole sessions and the
84
- // model only found type errors reactively via `bun run build`.
85
- const msg = e instanceof Error ? e.message : String(e);
86
- const failures = (self.failuresByServer.get(key) ?? 0) + 1;
87
- self.failuresByServer.set(key, failures);
88
- try {
89
- _ctx.logger?.warn(`LSP check failed for ${filePath}: ${msg}`);
90
- }
91
- catch { }
92
- if (failures >= MAX_CONSECUTIVE_LSP_FAILURES) {
93
- // One loud, actionable message, then stop the per-write noise for
94
- // the rest of the session. The model must not learn to ignore LSP.
95
- self.disabledServers.add(key);
96
- result.output += `\n\n[LSP disabled: ${t("lsp.unavailable")}]`;
97
- }
98
- else {
99
- result.output += `\n\n[LSP check failed]: ${msg}`;
100
- }
101
- }
102
- },
103
- };
104
- }
105
- /**
106
- * On-demand diagnostics tool. LSP checks only ran after write/edit (the
107
- * plugin above), so a read-only "check this project for errors" task got
108
- * ZERO compiler feedback — the model scanned files with read_file and never
109
- * learned whether the code compiled (observed: ses_msvuao0h — a "проверь на
110
- * ошибки" task ran no build, no lsp, and declared success). `lsp_check`
111
- * gives the model a way to ask for static diagnostics on demand.
112
- */
113
- getToolDefinitions() {
114
- const self = this;
115
- return [
116
- {
117
- name: "lsp_check",
118
- description: 'Run static checks (LSP diagnostics) on a file or directory. For "check for errors" tasks: pass a file to check it, or a directory to check its source files (capped at 15). Returns [LSP errors] / [LSP warnings] for files with a configured LSP server.',
119
- tags: ["code", "check"],
120
- alwaysOn: true,
121
- boundedOutput: true,
122
- timeoutMs: 90000,
123
- parameters: {
124
- type: "object",
125
- properties: {
126
- path: {
127
- type: "string",
128
- description: "File or directory to check",
129
- },
130
- },
131
- required: ["path"],
132
- },
133
- handler: async (ctx, args) => self.runCheck(ctx, args),
134
- },
135
- ];
136
- }
137
- async runCheck(ctx, args) {
138
- if (!this.config.enabled) {
139
- return { success: false, output: t("lsp.check_disabled") };
140
- }
141
- const path = String(args.path ?? "");
142
- if (!path)
143
- return { success: false, output: t("lsp.check_no_path") };
144
- const resolved = safeResolvePath(ctx.baseDir, path);
145
- const securityPaths = ctx.config?.security?.paths || DEFAULT_SECURITY_CONFIG.paths;
146
- const scopeCheck = isPathInScope(ctx.baseDir, resolved, ctx.scope, securityPaths);
147
- if (!scopeCheck.allowed) {
148
- return {
149
- success: false,
150
- output: t("file.path_not_allowed", {
151
- path: `${path} — ${scopeCheck.reason}`,
152
- }),
153
- };
154
- }
155
- if (!existsSync(resolved)) {
156
- return { success: false, output: t("lsp.check_notfound", { path }) };
157
- }
158
- const files = await collectCheckFiles(resolved, this.config);
159
- const errors = [];
160
- const warnings = [];
161
- const notes = [];
162
- let checked = 0;
163
- for (const file of files) {
164
- const serverConfig = getServerForFile(file, this.config);
165
- if (!serverConfig)
166
- continue;
167
- const key = this.serverKey(serverConfig);
168
- if (this.disabledServers.has(key))
169
- continue;
170
- const projectRoot = findProjectRoot(file, ctx.baseDir, serverConfig.workspaceMarkers ?? []);
171
- try {
172
- const diags = await this.client.checkFile(file, ctx.baseDir, serverConfig, projectRoot);
173
- this.failuresByServer.set(key, 0);
174
- checked++;
175
- for (const d of diags) {
176
- if (d.severity === 1)
177
- errors.push({ file, diag: d });
178
- else if (d.severity === 2)
179
- warnings.push({ file, diag: d });
180
- }
181
- }
182
- catch (e) {
183
- const msg = e instanceof Error ? e.message : String(e);
184
- const failures = (this.failuresByServer.get(key) ?? 0) + 1;
185
- this.failuresByServer.set(key, failures);
186
- try {
187
- ctx.logger?.warn(`LSP check failed for ${file}: ${msg}`);
188
- }
189
- catch { }
190
- if (failures >= MAX_CONSECUTIVE_LSP_FAILURES) {
191
- this.disabledServers.add(key);
192
- notes.push(`[LSP disabled: ${t("lsp.unavailable")}]`);
193
- }
194
- else {
195
- notes.push(`[LSP check failed for ${file}: ${msg}]`);
196
- }
197
- }
198
- }
199
- const lines = [];
200
- if (errors.length > 0) {
201
- lines.push(`[LSP errors] (${errors.length}):`);
202
- lines.push(formatCheckDiagnostics(errors, ctx.baseDir));
203
- }
204
- if (warnings.length > 0) {
205
- lines.push(`[LSP warnings] (${warnings.length}):`);
206
- lines.push(formatCheckDiagnostics(warnings, ctx.baseDir));
207
- }
208
- if (checked > 0 && errors.length === 0 && warnings.length === 0) {
209
- lines.push(t("lsp.check_clean", { count: String(checked) }));
210
- }
211
- lines.push(...notes);
212
- if (lines.length === 0) {
213
- return {
214
- success: true,
215
- output: t("lsp.check_clean", { count: String(checked) }),
216
- };
217
- }
218
- return { success: errors.length === 0, output: lines.join("\n") };
219
- }
220
- }
221
- function formatDiagnostics(diagnostics, filePath) {
222
- const filename = filePath.replace(/\\/g, "/").split("/").pop() ?? filePath;
223
- return diagnostics
224
- .slice(0, 5)
225
- .map((d) => {
226
- const line = d.range.start.line + 1;
227
- const col = d.range.start.character + 1;
228
- const sev = severityLabels[d.severity] ?? "unknown";
229
- return ` ${filename}(${line},${col}): ${sev}: ${d.message}`;
230
- })
231
- .join("\n");
232
- }
@@ -1,76 +0,0 @@
1
- import { LspClient } from "./client";
2
- import { getLanguageForFile } from "./config";
3
- import { collectCheckFiles } from "./check-tool";
4
- import { findProjectRoot } from "./project-root";
5
- const DEFAULT_PROBE_TIMEOUT_MS = 30_000;
6
- const DEFAULT_PROBE_DEADLINE_MS = 60_000;
7
- const DEFAULT_MAX_PARALLEL = 3;
8
- /**
9
- * Check which LSP servers apply to the project (via the same bounded file
10
- * walk as lsp_check) and probe each one: spawn + initialize + shutdown.
11
- * Used by the REPL banner so a dead server is visible before the first write.
12
- */
13
- export async function probeLspServers(config, baseDir, deps = {}) {
14
- if (!config.enabled)
15
- return { ok: [], failed: [], noneApplicable: true };
16
- const timeoutCap = deps.timeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
17
- const deadlineMs = deps.deadlineMs ?? DEFAULT_PROBE_DEADLINE_MS;
18
- const maxParallel = deps.maxParallel ?? DEFAULT_MAX_PARALLEL;
19
- const collect = deps.collectFiles ?? collectCheckFiles;
20
- const files = await collect(baseDir, config);
21
- const seen = new Set();
22
- const servers = [];
23
- for (const file of files) {
24
- const language = getLanguageForFile(file);
25
- if (!language)
26
- continue;
27
- const server = config.servers[language];
28
- if (!server || seen.has(language))
29
- continue;
30
- seen.add(language);
31
- servers.push({ language, config: server });
32
- }
33
- if (servers.length === 0)
34
- return { ok: [], failed: [], noneApplicable: true };
35
- // Probe in bounded waves. Probing everything in parallel on a cold npx cache
36
- // makes the servers fight over the shared cache lock — observed as `LSP
37
- // request timeout: initialize` for half the servers. Fully sequential probing
38
- // avoids that but doubles the REPL banner wait (each server ~2s). A wave of
39
- // `maxParallel` keeps the banner fast on a warm cache while capping cold-cache
40
- // contention; each server in a wave gets its own LspClient (the client is
41
- // stateful — process, request ids, response buffer — so concurrent probes on
42
- // a shared instance would cross-talk). When a client is injected (tests), it
43
- // is reused for every server.
44
- const ok = [];
45
- const failed = [];
46
- const deadline = Date.now() + deadlineMs;
47
- const probeOne = async (language, server) => {
48
- const projectRoot = findProjectRoot(baseDir, baseDir, server.workspaceMarkers ?? []);
49
- const serverTimeout = Math.min(server.timeout ?? timeoutCap, timeoutCap);
50
- const started = Date.now();
51
- const probeClient = deps.client ?? new LspClient();
52
- try {
53
- await probeClient.probe(server, projectRoot, serverTimeout);
54
- ok.push({ language, ok: true, durationMs: Date.now() - started });
55
- }
56
- catch (e) {
57
- failed.push({
58
- language,
59
- ok: false,
60
- error: e instanceof Error ? e.message : String(e),
61
- durationMs: Date.now() - started,
62
- });
63
- }
64
- };
65
- for (let i = 0; i < servers.length; i += maxParallel) {
66
- if (Date.now() >= deadline) {
67
- for (const { language } of servers.slice(i)) {
68
- failed.push({ language, ok: false, error: "timeout", durationMs: 0 });
69
- }
70
- break;
71
- }
72
- const wave = servers.slice(i, i + maxParallel);
73
- await Promise.all(wave.map(({ language, config: server }) => probeOne(language, server)));
74
- }
75
- return { ok, failed, noneApplicable: false };
76
- }
@@ -1,32 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { dirname, join } from "path";
3
- /**
4
- * Resolve the LSP workspace root for an edited file.
5
- *
6
- * The workspace root must be the nearest project of the *edited file*, not the
7
- * agent baseDir — tsserver resolves `typescript` relative to the workspace
8
- * root, so for a file in `bicycle-shop/src/x.ts` under baseDir `mma_tests` the
9
- * root must be `bicycle-shop` (observed: "Could not find a valid TypeScript
10
- * installation" on every write/edit because baseDir had no node_modules).
11
- *
12
- * Which files mark a project root is language-specific and is declared in the
13
- * LSP server config (`LspServerConfig.workspaceMarkers`) — this function takes
14
- * the markers as a parameter and performs no language detection itself.
15
- */
16
- export function findProjectRoot(filePath, baseDir, markers) {
17
- if (!markers || markers.length === 0)
18
- return baseDir;
19
- let dir = dirname(filePath);
20
- const root = baseDir.replace(/[\\/]+$/, "");
21
- while (true) {
22
- if (markers.some((m) => existsSync(join(dir, m)))) {
23
- return dir;
24
- }
25
- if (dir === root)
26
- return dir;
27
- const parent = dirname(dir);
28
- if (parent === dir)
29
- return root;
30
- dir = parent;
31
- }
32
- }
@@ -1,141 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { join } from "path";
3
- import { spawn } from "child_process";
4
- import { t } from "../../i18n/index";
5
- import { LspClient } from "./client";
6
- import { collectCheckFiles } from "./check-tool";
7
- import { getServerForFile } from "./config";
8
- import { findProjectRoot } from "./project-root";
9
- /** Startup check never examines more than this many files via LSP. */
10
- const STARTUP_CHECK_FILE_CAP = 5;
11
- /** Overall cap for the whole startup check — never block session start longer. */
12
- const STARTUP_CHECK_TIMEOUT_MS = 60_000;
13
- /** Cap of tsc error lines surfaced in the prompt block. */
14
- const STARTUP_CHECK_ERROR_CAP = 20;
15
- /**
16
- * Scan the project at session start for errors that already exist, so the
17
- * model knows the baseline BEFORE it starts working. Addresses interrupted
18
- * sessions: code left half-broken by a previous run is surfaced up front
19
- * instead of being discovered (or missed) reactively.
20
- *
21
- * Strategy:
22
- * - If the project has a tsconfig.json → one `tsc --noEmit --skipLibCheck`
23
- * invocation (single process, covers the whole project).
24
- * - Otherwise → bounded LSP diagnostics on up to STARTUP_CHECK_FILE_CAP files
25
- * (handles CSS/JSON/plain-JS projects with no TS).
26
- *
27
- * Always fail-open: on any error/timeout/clean result → returns null, so the
28
- * check can never slow down or break session startup.
29
- */
30
- export async function runStartupHealthCheck(config, baseDir, deps = {}) {
31
- if (!config.enabled)
32
- return null;
33
- try {
34
- const result = await Promise.race([
35
- runCheck(config, baseDir, deps),
36
- new Promise((resolve) => setTimeout(() => resolve(null), STARTUP_CHECK_TIMEOUT_MS)),
37
- ]);
38
- if (!result || result.lines.length === 0)
39
- return null;
40
- const content = `${t("lsp.startup_header")}\n${result.lines.join("\n")}`;
41
- return {
42
- content,
43
- priority: "high",
44
- essential: false,
45
- estimatedTokens: Math.ceil(content.length / 4),
46
- };
47
- }
48
- catch {
49
- return null;
50
- }
51
- }
52
- async function runCheck(config, baseDir, deps) {
53
- const projectRoot = findProjectRoot(baseDir, baseDir, ["tsconfig.json", "package.json"]);
54
- if (existsSync(join(projectRoot, "tsconfig.json"))) {
55
- const runTsc = deps.runTsc ?? runTscDefault;
56
- const errors = await runTsc(projectRoot, STARTUP_CHECK_TIMEOUT_MS);
57
- if (errors.length === 0)
58
- return null;
59
- return { lines: errors.slice(0, STARTUP_CHECK_ERROR_CAP) };
60
- }
61
- const client = deps.client ?? new LspClient();
62
- const files = await collectCheckFiles(baseDir, config);
63
- const lines = [];
64
- let checked = 0;
65
- for (const file of files.slice(0, STARTUP_CHECK_FILE_CAP)) {
66
- const serverConfig = getServerForFile(file, config);
67
- if (!serverConfig)
68
- continue;
69
- const fileRoot = findProjectRoot(file, baseDir, serverConfig.workspaceMarkers ?? []);
70
- try {
71
- const diags = await client.checkFile(file, baseDir, serverConfig, fileRoot);
72
- checked++;
73
- for (const d of diags) {
74
- if (d.severity === 1) {
75
- lines.push(formatStartupError(file, baseDir, d));
76
- }
77
- }
78
- }
79
- catch {
80
- // Per-file LSP failure → skip silently (fail-open).
81
- }
82
- }
83
- if (checked === 0 || lines.length === 0)
84
- return null;
85
- return { lines: lines.slice(0, STARTUP_CHECK_ERROR_CAP) };
86
- }
87
- async function runTscDefault(projectRoot, timeoutMs) {
88
- return new Promise((resolve) => {
89
- const child = spawn("npx", ["tsc", "--noEmit", "--skipLibCheck"], {
90
- cwd: projectRoot,
91
- shell: true,
92
- windowsHide: true,
93
- stdio: ["ignore", "pipe", "pipe"],
94
- });
95
- let out = "";
96
- child.stdout?.on("data", (d) => {
97
- out += d.toString();
98
- });
99
- child.stderr?.on("data", (d) => {
100
- out += d.toString();
101
- });
102
- const timer = setTimeout(() => {
103
- child.kill();
104
- resolve([]);
105
- }, timeoutMs);
106
- child.on("error", () => {
107
- clearTimeout(timer);
108
- resolve([]);
109
- });
110
- child.on("close", () => {
111
- clearTimeout(timer);
112
- resolve(parseTscErrors(out));
113
- });
114
- });
115
- }
116
- export function parseTscErrors(output) {
117
- const lines = [];
118
- for (const raw of output.split("\n")) {
119
- const line = raw.replace(/^[a-zA-Z]:/, "").trim();
120
- if (line.includes("error TS"))
121
- lines.push(line);
122
- }
123
- return dedupe(lines);
124
- }
125
- function formatStartupError(file, baseDir, d) {
126
- const rel = file.replace(baseDir.replace(/[\\/]$/, ""), "").replace(/^[\\/]/, "");
127
- const line = d.range.start.line + 1;
128
- const col = d.range.start.character + 1;
129
- return ` ${rel || file}(${line},${col}): error: ${d.message}`;
130
- }
131
- function dedupe(lines) {
132
- const seen = new Set();
133
- const out = [];
134
- for (const line of lines) {
135
- if (!seen.has(line)) {
136
- seen.add(line);
137
- out.push(line);
138
- }
139
- }
140
- return out;
141
- }
@@ -1 +0,0 @@
1
- export {};