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.
- package/bin/mma.mjs +41 -41
- package/dist/cli/commands.js +19 -9
- package/dist/cli/completer.js +37 -36
- package/dist/cli/index.js +2 -2
- package/dist/cli/main.js +23 -48
- package/dist/cli/repl-commands.js +12 -40
- package/dist/cli/repl.js +87 -217
- package/dist/cli/security-commands.js +7 -5
- package/dist/cli/setup.js +26 -8
- package/dist/config/config.js +5 -52
- package/dist/config/defaults.js +5 -29
- package/dist/config/experts.js +1 -1
- package/dist/config/index.js +3 -3
- package/dist/config/security.js +10 -3
- package/dist/core/agent-moe.js +10 -2
- package/dist/core/agent.js +82 -273
- package/dist/core/bootstrap.js +13 -80
- package/dist/core/index.js +2 -2
- package/dist/core/prompt-builder.js +2 -23
- package/dist/core/session-logger.js +4 -46
- package/dist/i18n/en.json +2 -75
- package/dist/i18n/ru.json +1 -74
- package/dist/index.js +1 -1
- package/dist/llm/image-utils.js +5 -4
- package/dist/llm/index.js +4 -4
- package/dist/llm/model-loader.js +6 -6
- package/dist/llm/openai-compat.js +34 -40
- package/dist/llm/orchestrator.js +29 -33
- package/dist/llm/response.js +9 -9
- package/dist/logger/app-logger.js +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/main.js +648 -183
- package/dist/migration/backup.js +13 -13
- package/dist/migration/detect.js +11 -11
- package/dist/migration/index.js +2 -2
- package/dist/modules/browser/actions.js +4 -34
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/modules/browser/cookie-store.js +6 -6
- package/dist/modules/browser/index.js +5 -7
- package/dist/modules/browser/module.js +7 -8
- package/dist/modules/browser/session.js +84 -87
- package/dist/modules/browser/snapshot.js +58 -92
- package/dist/modules/browser/types.js +1 -4
- package/dist/modules/certification/cli.js +4 -2
- package/dist/modules/certification/fact-checker.js +3 -1
- package/dist/modules/certification/loader.js +9 -3
- package/dist/modules/certification/runner.js +4 -1
- package/dist/modules/context/index.js +1 -1
- package/dist/modules/context/manager.js +86 -160
- package/dist/modules/execution/auditor.js +25 -177
- package/dist/modules/execution/module.js +544 -201
- package/dist/modules/execution/moe-executor.js +0 -25
- package/dist/modules/execution/plan-store.js +3 -1
- package/dist/modules/execution/plan-validator.js +10 -10
- package/dist/modules/execution/planner.js +1 -6
- package/dist/modules/execution/stuck-detector.js +10 -173
- package/dist/modules/execution/verifier.js +42 -86
- package/dist/modules/hallucination/confidence.js +1 -8
- package/dist/modules/hallucination/detector.js +5 -2
- package/dist/modules/hallucination/factual.js +64 -3
- package/dist/modules/hallucination/index.js +1 -1
- package/dist/modules/hallucination/js-identifiers.js +0 -190
- package/dist/modules/hallucination/llm-judge.js +3 -1
- package/dist/modules/indexer/cache.js +7 -9
- package/dist/modules/indexer/index.js +3 -3
- package/dist/modules/indexer/module.js +42 -95
- package/dist/modules/indexer/walker.js +17 -17
- package/dist/modules/lsp/client.js +31 -74
- package/dist/modules/lsp/config.js +33 -87
- package/dist/modules/lsp/index.js +3 -3
- package/dist/modules/lsp/module.js +21 -185
- package/dist/modules/mcp/module.js +6 -2
- package/dist/modules/memory/index.js +1 -1
- package/dist/modules/memory/module.js +23 -71
- package/dist/modules/memory/search.js +9 -11
- package/dist/modules/memory/store.js +13 -13
- package/dist/modules/pipelines/engine.js +10 -10
- package/dist/modules/pipelines/index.js +3 -3
- package/dist/modules/pipelines/parser.js +14 -17
- package/dist/modules/pipelines/template.js +1 -1
- package/dist/modules/plugins/builtin/lint-on-write.js +16 -21
- package/dist/modules/plugins/builtin/notify.js +2 -3
- package/dist/modules/plugins/index.js +1 -1
- package/dist/modules/plugins/loader.js +17 -59
- package/dist/modules/plugins/manager.js +17 -73
- package/dist/modules/processes/index.js +1 -1
- package/dist/modules/processes/registry.js +46 -135
- package/dist/modules/registry.js +2 -4
- package/dist/modules/security/audit-notifier.js +39 -39
- package/dist/modules/security/command-validator.js +8 -2
- package/dist/modules/security/data-sanitizer.js +9 -1
- package/dist/modules/security/encryption.js +56 -58
- package/dist/modules/security/network-validator.js +9 -1
- package/dist/modules/security/path-validator.js +3 -1
- package/dist/modules/security/security-policies.js +19 -3
- package/dist/modules/security/session-encryption.js +1 -1
- package/dist/modules/security/session-isolation.js +8 -8
- package/dist/modules/session/index.js +3 -3
- package/dist/modules/session/module.js +5 -5
- package/dist/modules/session/store.js +9 -3
- package/dist/modules/skills/module.js +2 -1
- package/dist/modules/updater/checker.js +6 -70
- package/dist/modules/updater/index.js +1 -2
- package/dist/modules/user-profile/compressor.js +2 -2
- package/dist/modules/user-profile/index.js +1 -1
- package/dist/modules/user-profile/profile.js +9 -9
- package/dist/tools/attach-image.js +1 -1
- package/dist/tools/bash.js +19 -178
- package/dist/tools/browser.js +29 -46
- package/dist/tools/executor.js +5 -4
- package/dist/tools/file-info.js +12 -13
- package/dist/tools/filter-tools.js +2 -9
- package/dist/tools/glob-tool.js +11 -11
- package/dist/tools/grep-tool.js +3 -1
- package/dist/tools/index.js +2 -13
- package/dist/tools/list-dir.js +17 -18
- package/dist/tools/load-skill.js +3 -1
- package/dist/tools/path-utils.js +4 -4
- package/dist/tools/pipeline-run.js +25 -25
- package/dist/tools/process-kill.js +11 -11
- package/dist/tools/process-list.js +22 -20
- package/dist/tools/process-log.js +18 -22
- package/dist/tools/question.js +3 -1
- package/dist/tools/read-file.js +2 -10
- package/dist/tools/recall.js +37 -44
- package/dist/tools/registry.js +4 -15
- package/dist/tools/remember.js +29 -29
- package/dist/tools/scope-check.js +9 -9
- package/dist/tools/subagent.js +9 -54
- package/dist/tools/user-input.js +1 -1
- package/dist/tools/web-browse.js +3 -3
- package/dist/tools/web-fetch.js +3 -3
- package/dist/tools/web-search.js +3 -3
- package/dist/tools/write-file.js +3 -1
- package/dist/ui/box.js +5 -1
- package/dist/ui/index.js +6 -6
- package/dist/ui/md-formatter.js +33 -33
- package/dist/ui/output.js +5 -5
- package/dist/ui/renderer.js +10 -15
- package/dist/ui/table.js +1 -1
- package/package.json +48 -48
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/run-result.js +0 -22
- package/dist/core/version.js +0 -24
- package/dist/modules/artifacts/store.js +0 -61
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -162
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/execution/audit-runners.js +0 -152
- package/dist/modules/execution/execution-plugin.js +0 -272
- package/dist/modules/execution/plan-tool.js +0 -508
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/probe.js +0 -76
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -141
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/updater/module.js +0 -116
- package/dist/tools/chunk-query.js +0 -99
- package/dist/tools/download-file.js +0 -116
- package/dist/tools/enable-tools.js +0 -58
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/ui/line-editor.js +0 -703
- package/dist/ui/line-math.js +0 -69
- package/dist/ui/plan-view.js +0 -103
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import { t } from "../../i18n/index";
|
|
4
|
-
const MANIFEST_ORDER = [
|
|
5
|
-
"package.json",
|
|
6
|
-
"pyproject.toml",
|
|
7
|
-
"Cargo.toml",
|
|
8
|
-
"go.mod",
|
|
9
|
-
"requirements.txt",
|
|
10
|
-
];
|
|
11
|
-
const MAX_DEPS = 5;
|
|
12
|
-
const MAX_DEV_DEPS = 3;
|
|
13
|
-
const MAX_SCRIPTS = 3;
|
|
14
|
-
/**
|
|
15
|
-
* Find the first existing manifest in priority order (best-effort, root only).
|
|
16
|
-
*/
|
|
17
|
-
export function detectManifest(baseDir) {
|
|
18
|
-
for (const manifest of MANIFEST_ORDER) {
|
|
19
|
-
if (existsSync(join(baseDir, manifest)))
|
|
20
|
-
return manifest;
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
/** Strip version specifiers from a manifest dependency entry. */
|
|
25
|
-
function cleanDependency(entry) {
|
|
26
|
-
let name = entry.trim();
|
|
27
|
-
const eq = name.indexOf("=");
|
|
28
|
-
if (eq > 0)
|
|
29
|
-
name = name.slice(0, eq);
|
|
30
|
-
const ineq = name.search(/[<>=!~^]/);
|
|
31
|
-
if (ineq > 0)
|
|
32
|
-
name = name.slice(0, ineq);
|
|
33
|
-
return name.replace(/["',]/g, "").trim();
|
|
34
|
-
}
|
|
35
|
-
function readPackageJson(baseDir) {
|
|
36
|
-
try {
|
|
37
|
-
const raw = JSON.parse(readFileSync(join(baseDir, "package.json"), "utf-8"));
|
|
38
|
-
if (!raw || typeof raw !== "object")
|
|
39
|
-
return null;
|
|
40
|
-
const profile = {
|
|
41
|
-
runtime: "node",
|
|
42
|
-
deps: Object.keys(raw.dependencies || {}),
|
|
43
|
-
devDeps: Object.keys(raw.devDependencies || {}),
|
|
44
|
-
scripts: {},
|
|
45
|
-
};
|
|
46
|
-
if (typeof raw.name === "string" && raw.name)
|
|
47
|
-
profile.name = raw.name;
|
|
48
|
-
if (raw.scripts && typeof raw.scripts === "object") {
|
|
49
|
-
for (const [key, val] of Object.entries(raw.scripts)) {
|
|
50
|
-
if (typeof val === "string" && val)
|
|
51
|
-
profile.scripts[key] = val;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return profile;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function readPyproject(baseDir) {
|
|
61
|
-
try {
|
|
62
|
-
const content = readFileSync(join(baseDir, "pyproject.toml"), "utf-8");
|
|
63
|
-
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
64
|
-
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
65
|
-
if (nameMatch)
|
|
66
|
-
profile.name = nameMatch[1];
|
|
67
|
-
const depsBlock = content.match(/dependencies\s*=\s*\[([\s\S]*?)\]/);
|
|
68
|
-
if (depsBlock) {
|
|
69
|
-
profile.deps = [...depsBlock[1].matchAll(/"([^"]+)"/g)]
|
|
70
|
-
.map((m) => cleanDependency(m[1]))
|
|
71
|
-
.filter(Boolean);
|
|
72
|
-
}
|
|
73
|
-
return profile;
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function readCargo(baseDir) {
|
|
80
|
-
try {
|
|
81
|
-
const content = readFileSync(join(baseDir, "Cargo.toml"), "utf-8");
|
|
82
|
-
const profile = { runtime: "rust", deps: [], devDeps: [], scripts: {} };
|
|
83
|
-
const nameMatch = content.match(/^\s*name\s*=\s*"([^"]+)"/m);
|
|
84
|
-
if (nameMatch)
|
|
85
|
-
profile.name = nameMatch[1];
|
|
86
|
-
let inDeps = false;
|
|
87
|
-
for (const line of content.split("\n")) {
|
|
88
|
-
const trimmed = line.trim();
|
|
89
|
-
if (/^\[.*\]$/.test(trimmed)) {
|
|
90
|
-
inDeps = trimmed === "[dependencies]";
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (inDeps && /^[A-Za-z0-9_-]+\s*=/.test(trimmed)) {
|
|
94
|
-
profile.deps.push(trimmed.split("=")[0].trim());
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return profile;
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function readGoMod(baseDir) {
|
|
104
|
-
try {
|
|
105
|
-
const content = readFileSync(join(baseDir, "go.mod"), "utf-8");
|
|
106
|
-
const profile = { runtime: "go", deps: [], devDeps: [], scripts: {} };
|
|
107
|
-
const moduleMatch = content.match(/^module\s+(\S+)/m);
|
|
108
|
-
if (moduleMatch)
|
|
109
|
-
profile.name = moduleMatch[1];
|
|
110
|
-
for (const line of content.split("\n")) {
|
|
111
|
-
const m = line.match(/^\s*(\S+)\s+v[\d.]+/);
|
|
112
|
-
if (m && !line.startsWith("//"))
|
|
113
|
-
profile.deps.push(m[1]);
|
|
114
|
-
}
|
|
115
|
-
return profile;
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function readRequirements(baseDir) {
|
|
122
|
-
try {
|
|
123
|
-
const content = readFileSync(join(baseDir, "requirements.txt"), "utf-8");
|
|
124
|
-
const profile = { runtime: "python", deps: [], devDeps: [], scripts: {} };
|
|
125
|
-
for (const line of content.split("\n")) {
|
|
126
|
-
const trimmed = line.trim();
|
|
127
|
-
if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith("-"))
|
|
128
|
-
continue;
|
|
129
|
-
profile.deps.push(cleanDependency(trimmed));
|
|
130
|
-
}
|
|
131
|
-
return profile;
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Read a compact project profile from the workspace manifest (best-effort).
|
|
139
|
-
* Returns null when no readable manifest is present.
|
|
140
|
-
*/
|
|
141
|
-
export function readProjectProfile(baseDir) {
|
|
142
|
-
const manifest = detectManifest(baseDir);
|
|
143
|
-
if (!manifest)
|
|
144
|
-
return null;
|
|
145
|
-
switch (manifest) {
|
|
146
|
-
case "package.json":
|
|
147
|
-
return readPackageJson(baseDir);
|
|
148
|
-
case "pyproject.toml":
|
|
149
|
-
return readPyproject(baseDir);
|
|
150
|
-
case "Cargo.toml":
|
|
151
|
-
return readCargo(baseDir);
|
|
152
|
-
case "go.mod":
|
|
153
|
-
return readGoMod(baseDir);
|
|
154
|
-
case "requirements.txt":
|
|
155
|
-
return readRequirements(baseDir);
|
|
156
|
-
default:
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/** One-line stack-neutral summary of the project profile. */
|
|
161
|
-
export function formatProjectProfile(profile) {
|
|
162
|
-
const parts = [];
|
|
163
|
-
if (profile.deps.length > 0) {
|
|
164
|
-
parts.push(`${t("indexer.stack_deps")}: ${profile.deps.slice(0, MAX_DEPS).join(", ")}`);
|
|
165
|
-
}
|
|
166
|
-
if (profile.devDeps.length > 0) {
|
|
167
|
-
parts.push(`${t("indexer.stack_dev")}: ${profile.devDeps.slice(0, MAX_DEV_DEPS).join(", ")}`);
|
|
168
|
-
}
|
|
169
|
-
const scripts = Object.entries(profile.scripts).slice(0, MAX_SCRIPTS);
|
|
170
|
-
if (scripts.length > 0) {
|
|
171
|
-
parts.push(`${t("indexer.stack_scripts")}: ${scripts.map(([k, v]) => `${k}=${v}`).join(", ")}`);
|
|
172
|
-
}
|
|
173
|
-
const name = profile.name ? ` ${profile.name}` : "";
|
|
174
|
-
return `[Stack: ${profile.runtime}${name} — ${parts.join(" | ")}]`;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Convenience: detect + read + format in one call. Returns null when the
|
|
178
|
-
* workspace has no readable manifest.
|
|
179
|
-
*/
|
|
180
|
-
export function buildProjectProfileLine(baseDir) {
|
|
181
|
-
const profile = readProjectProfile(baseDir);
|
|
182
|
-
return profile ? formatProjectProfile(profile) : null;
|
|
183
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { readdir, stat } from "fs/promises";
|
|
2
|
-
import { resolve, relative } from "path";
|
|
3
|
-
import { getServerForFile } from "./config";
|
|
4
|
-
/** lsp_check directory mode: walk depth and per-call file cap. */
|
|
5
|
-
export const MAX_LSP_CHECK_FILES = 15;
|
|
6
|
-
const MAX_LSP_WALK_DEPTH = 4;
|
|
7
|
-
const SKIP_DIRS = new Set(["node_modules", ".git", ".mma", "dist"]);
|
|
8
|
-
export const severityLabels = {
|
|
9
|
-
1: "error",
|
|
10
|
-
2: "warning",
|
|
11
|
-
3: "info",
|
|
12
|
-
4: "hint",
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Resolve the target to a file (single check) or a bounded list of source
|
|
16
|
-
* files (directory check, capped at MAX_LSP_CHECK_FILES). Only files with a
|
|
17
|
-
* configured LSP server are collected, so unsupported extensions are simply
|
|
18
|
-
* not checked rather than producing noise.
|
|
19
|
-
*/
|
|
20
|
-
export async function collectCheckFiles(resolved, config) {
|
|
21
|
-
const info = await stat(resolved).catch(() => null);
|
|
22
|
-
if (!info)
|
|
23
|
-
return [];
|
|
24
|
-
if (info.isFile())
|
|
25
|
-
return [resolved];
|
|
26
|
-
const out = [];
|
|
27
|
-
await walkDir(resolved, 0, out, config);
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
async function walkDir(dir, depth, out, config) {
|
|
31
|
-
if (depth > MAX_LSP_WALK_DEPTH || out.length >= MAX_LSP_CHECK_FILES)
|
|
32
|
-
return;
|
|
33
|
-
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
34
|
-
for (const entry of entries) {
|
|
35
|
-
if (out.length >= MAX_LSP_CHECK_FILES)
|
|
36
|
-
break;
|
|
37
|
-
if (entry.isDirectory()) {
|
|
38
|
-
if (SKIP_DIRS.has(entry.name))
|
|
39
|
-
continue;
|
|
40
|
-
await walkDir(resolve(dir, entry.name), depth + 1, out, config);
|
|
41
|
-
}
|
|
42
|
-
else if (entry.isFile() && getServerForFile(resolve(dir, entry.name), config)) {
|
|
43
|
-
out.push(resolve(dir, entry.name));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export function formatCheckDiagnostics(items, baseDir) {
|
|
48
|
-
return items
|
|
49
|
-
.slice(0, 40)
|
|
50
|
-
.map(({ file, diag }) => {
|
|
51
|
-
const rel = relative(baseDir, file).replace(/\\/g, "/");
|
|
52
|
-
const line = diag.range.start.line + 1;
|
|
53
|
-
const col = diag.range.start.character + 1;
|
|
54
|
-
const sev = severityLabels[diag.severity] ?? "unknown";
|
|
55
|
-
return ` ${rel}(${line},${col}): ${sev}: ${diag.message}`;
|
|
56
|
-
})
|
|
57
|
-
.join("\n");
|
|
58
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { delimiter, join } from "path";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { platform } from "os";
|
|
4
|
-
const WIN_EXTS = [".cmd", ".bat", ".exe", ".com"];
|
|
5
|
-
/**
|
|
6
|
-
* Resolve the command string passed to `child_process.spawn` on Windows.
|
|
7
|
-
*
|
|
8
|
-
* Node's `spawn` cannot execute `.cmd`/`.bat` shims directly without a shell,
|
|
9
|
-
* and a bare `npx` fails with `spawn npx ENOENT` because on Windows the
|
|
10
|
-
* real executable is `npx.cmd`. This returns the first existing shim
|
|
11
|
-
* (`npx.cmd`, `npx.bat`, `npx.exe`, ...) found on PATH, or the bare command
|
|
12
|
-
* when nothing exists (the spawn will then fail with a meaningful ENOENT).
|
|
13
|
-
*
|
|
14
|
-
* Non-Windows platforms and commands that already carry an extension or a
|
|
15
|
-
* path separator are returned unchanged.
|
|
16
|
-
*/
|
|
17
|
-
export function resolveSpawnCommand(command, platformName = platform(), pathEnv = process.env.PATH ?? "") {
|
|
18
|
-
if (platformName !== "win32")
|
|
19
|
-
return command;
|
|
20
|
-
// Already a path or has an extension — pass through.
|
|
21
|
-
if (command.includes("/") ||
|
|
22
|
-
command.includes("\\") ||
|
|
23
|
-
WIN_EXTS.some((ext) => command.toLowerCase().endsWith(ext))) {
|
|
24
|
-
return command;
|
|
25
|
-
}
|
|
26
|
-
const dirs = pathEnv.split(delimiter).filter(Boolean);
|
|
27
|
-
for (const dir of dirs) {
|
|
28
|
-
for (const ext of WIN_EXTS) {
|
|
29
|
-
const candidate = join(dir, `${command}${ext}`);
|
|
30
|
-
if (existsSync(candidate))
|
|
31
|
-
return `${command}${ext}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return command;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Join a resolved command and its args into a single cmd.exe command line.
|
|
38
|
-
*
|
|
39
|
-
* Under Node on Windows, `spawn` of a `.cmd`/`.bat` shim WITHOUT a shell throws
|
|
40
|
-
* `spawn EINVAL` (CreateProcess cannot run batch files directly). Resolving
|
|
41
|
-
* `npx` → `npx.cmd` fixes the old `ENOENT` but not the `EINVAL` — the spawn
|
|
42
|
-
* still has no shell. The reliable fix is to run the whole command line through
|
|
43
|
-
* `cmd.exe /d /s /c` (i.e. `spawn(line, { shell: true })`). This helper builds
|
|
44
|
-
* that line, quoting any argument that contains cmd.exe metacharacters so the
|
|
45
|
-
* package names and flags in LSP configs (`typescript-language-server --stdio`,
|
|
46
|
-
* `pyright --stdio`) survive the round-trip.
|
|
47
|
-
*
|
|
48
|
-
* Non-Windows platforms never call this (they spawn the resolved command +
|
|
49
|
-
* args directly, no shell).
|
|
50
|
-
*/
|
|
51
|
-
export function buildWinCommandLine(command, args) {
|
|
52
|
-
const quote = (part) => {
|
|
53
|
-
if (part === "")
|
|
54
|
-
return '""';
|
|
55
|
-
if (!/[\s"&|^<>()%!]/.test(part))
|
|
56
|
-
return part;
|
|
57
|
-
return `"${part.replace(/"/g, '\\"')}"`;
|
|
58
|
-
};
|
|
59
|
-
return [command, ...args].map(quote).join(" ");
|
|
60
|
-
}
|
|
@@ -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,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Heuristic detection of long-running (server/watch) commands.
|
|
3
|
-
*
|
|
4
|
-
* The explicit `background: true` bash parameter always wins; this list is a
|
|
5
|
-
* convenience so dev servers don't block the agent. It only inspects the raw
|
|
6
|
-
* shell command (a technical process-type decision, not task classification).
|
|
7
|
-
*/
|
|
8
|
-
const LONG_RUNNING_PATTERNS = [
|
|
9
|
-
/\b(npm|pnpm|yarn|bun|npx)\s+(run\s+)?(dev|start|serve|preview|watch|server)\b/i,
|
|
10
|
-
/\b(deno|node)\s+.*\b(run\s+)?(dev|serve|watch|server)\b/i,
|
|
11
|
-
/(^|\s)--watch\b/i,
|
|
12
|
-
/(^|\s)-w\b/i,
|
|
13
|
-
/\bnodemon\b/i,
|
|
14
|
-
/\btsx watch\b/i,
|
|
15
|
-
/\b(ts-node|tsc)\s+.*--watch\b/i,
|
|
16
|
-
/\bvite(?!\s+(build|create))\b/i,
|
|
17
|
-
/\bwebpack(-dev-server|\s+serve)\b/i,
|
|
18
|
-
/\bastro dev\b/i,
|
|
19
|
-
/\bnext (dev|start)\b/i,
|
|
20
|
-
/\bnuxt (dev|start)\b/i,
|
|
21
|
-
/\bsvelte-kit (dev|preview)\b/i,
|
|
22
|
-
/\bgatsby develop\b/i,
|
|
23
|
-
/\bdocker(-compose)?\s+.*\bup\b/i,
|
|
24
|
-
/\buvicorn\b|\bgunicorn\b/i,
|
|
25
|
-
/\bpython\s+-m\s+http\.server\b/i,
|
|
26
|
-
/\bflask run\b/i,
|
|
27
|
-
/\bphp artisan serve\b/i,
|
|
28
|
-
/\brails (server|s)\b/i,
|
|
29
|
-
/\bvitest watch\b/i,
|
|
30
|
-
/\bjest --watch\b/i,
|
|
31
|
-
];
|
|
32
|
-
export function isLongRunningCommand(command) {
|
|
33
|
-
return LONG_RUNNING_PATTERNS.some((pattern) => pattern.test(command));
|
|
34
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const MIN_WORD_LENGTH = 4;
|
|
2
|
-
export class SkillsMatcher {
|
|
3
|
-
match(taskDescription, skills, maxResults = 3) {
|
|
4
|
-
const taskWords = taskDescription.toLowerCase().split(/\W+/).filter(w => w.length >= MIN_WORD_LENGTH);
|
|
5
|
-
const scored = skills.map(skill => {
|
|
6
|
-
const allKeywords = [
|
|
7
|
-
skill.name.toLowerCase(),
|
|
8
|
-
skill.description.toLowerCase(),
|
|
9
|
-
...skill.keywords.map(k => k.toLowerCase()),
|
|
10
|
-
];
|
|
11
|
-
let score = 0;
|
|
12
|
-
for (const word of taskWords) {
|
|
13
|
-
for (const kw of allKeywords) {
|
|
14
|
-
if (kw === word || (kw.length >= MIN_WORD_LENGTH && kw.includes(word))) {
|
|
15
|
-
score++;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return { skill, score };
|
|
20
|
-
});
|
|
21
|
-
return scored
|
|
22
|
-
.filter(s => s.score > 0)
|
|
23
|
-
.sort((a, b) => b.score - a.score)
|
|
24
|
-
.slice(0, maxResults)
|
|
25
|
-
.map(s => s.skill);
|
|
26
|
-
}
|
|
27
|
-
}
|