micro-models-agent 0.40.1 → 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.
- package/bin/mma.mjs +41 -41
- package/dist/cli/commands.js +9 -19
- package/dist/cli/completer.js +36 -37
- package/dist/cli/index.js +2 -2
- package/dist/cli/main.js +48 -23
- package/dist/cli/plugin-commands.js +36 -0
- package/dist/cli/repl-commands.js +40 -12
- package/dist/cli/repl.js +217 -87
- package/dist/cli/run-result.js +22 -0
- package/dist/cli/security-commands.js +5 -7
- package/dist/cli/setup.js +8 -26
- package/dist/config/config.js +52 -5
- package/dist/config/defaults.js +29 -5
- package/dist/config/experts.js +1 -1
- package/dist/config/index.js +3 -3
- package/dist/config/security.js +3 -10
- package/dist/core/agent-moe.js +2 -10
- package/dist/core/agent.js +273 -82
- package/dist/core/bootstrap.js +80 -13
- package/dist/core/index.js +2 -2
- package/dist/core/prompt-builder.js +23 -2
- package/dist/core/session-logger.js +46 -4
- package/dist/core/version.js +24 -0
- package/dist/i18n/en.json +75 -2
- package/dist/i18n/ru.json +74 -1
- package/dist/index.js +1 -1
- package/dist/llm/image-utils.js +4 -5
- package/dist/llm/index.js +4 -4
- package/dist/llm/model-loader.js +6 -6
- package/dist/llm/openai-compat.js +40 -34
- package/dist/llm/orchestrator.js +33 -29
- 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 +2489 -2186
- package/dist/migration/backup.js +13 -13
- package/dist/migration/detect.js +11 -11
- package/dist/migration/index.js +2 -2
- package/dist/modules/artifacts/store.js +61 -0
- package/dist/modules/browser/actions.js +34 -4
- package/dist/modules/browser/bridge-client.js +199 -0
- package/dist/modules/browser/bridge-path.js +10 -0
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/modules/browser/cookie-store.js +6 -6
- package/dist/modules/browser/driver.js +136 -0
- package/dist/modules/browser/index.js +7 -5
- package/dist/modules/browser/module.js +8 -7
- package/dist/modules/browser/session.js +87 -84
- package/dist/modules/browser/snapshot.js +92 -58
- package/dist/modules/browser/types.js +4 -1
- package/dist/modules/certification/cli.js +2 -4
- package/dist/modules/certification/fact-checker.js +1 -3
- package/dist/modules/certification/loader.js +3 -9
- package/dist/modules/certification/runner.js +1 -4
- package/dist/modules/context/chunk-query.js +100 -0
- package/dist/modules/context/fact-extractor.js +162 -0
- package/dist/modules/context/history.js +15 -0
- package/dist/modules/context/index.js +1 -1
- package/dist/modules/context/manager.js +160 -86
- package/dist/modules/execution/audit-runners.js +152 -0
- package/dist/modules/execution/auditor.js +177 -25
- package/dist/modules/execution/execution-plugin.js +272 -0
- package/dist/modules/execution/module.js +201 -544
- package/dist/modules/execution/moe-executor.js +25 -0
- package/dist/modules/execution/plan-store.js +1 -3
- package/dist/modules/execution/plan-tool.js +508 -0
- package/dist/modules/execution/plan-validator.js +10 -10
- package/dist/modules/execution/planner.js +6 -1
- package/dist/modules/execution/stuck-detector.js +173 -10
- package/dist/modules/execution/verifier.js +86 -42
- package/dist/modules/execution/windows-commands.js +41 -0
- package/dist/modules/hallucination/confidence.js +8 -1
- package/dist/modules/hallucination/detector.js +2 -5
- package/dist/modules/hallucination/factual.js +3 -64
- package/dist/modules/hallucination/index.js +1 -1
- package/dist/modules/hallucination/js-identifiers.js +190 -0
- package/dist/modules/hallucination/llm-judge.js +1 -3
- package/dist/modules/indexer/cache.js +9 -7
- package/dist/modules/indexer/index.js +3 -3
- package/dist/modules/indexer/module.js +95 -42
- package/dist/modules/indexer/project-profile.js +183 -0
- package/dist/modules/indexer/walker.js +17 -17
- package/dist/modules/lsp/check-tool.js +58 -0
- package/dist/modules/lsp/client.js +74 -31
- package/dist/modules/lsp/command.js +60 -0
- package/dist/modules/lsp/config.js +87 -33
- package/dist/modules/lsp/index.js +3 -3
- package/dist/modules/lsp/module.js +185 -21
- package/dist/modules/lsp/probe.js +76 -0
- package/dist/modules/lsp/project-root.js +32 -0
- package/dist/modules/lsp/startup-check.js +141 -0
- package/dist/modules/mcp/module.js +2 -6
- package/dist/modules/memory/index.js +1 -1
- package/dist/modules/memory/module.js +71 -23
- package/dist/modules/memory/search.js +11 -9
- 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 +17 -14
- package/dist/modules/pipelines/template.js +1 -1
- package/dist/modules/plugins/builtin/lint-on-write.js +21 -16
- package/dist/modules/plugins/builtin/notify.js +3 -2
- package/dist/modules/plugins/index.js +1 -1
- package/dist/modules/plugins/loader.js +59 -17
- package/dist/modules/plugins/manager.js +73 -17
- package/dist/modules/processes/detect.js +34 -0
- package/dist/modules/processes/index.js +1 -1
- package/dist/modules/processes/registry.js +135 -46
- package/dist/modules/registry.js +4 -2
- package/dist/modules/security/audit-notifier.js +39 -39
- package/dist/modules/security/command-validator.js +2 -8
- package/dist/modules/security/data-sanitizer.js +1 -9
- package/dist/modules/security/encryption.js +58 -56
- package/dist/modules/security/network-validator.js +1 -9
- package/dist/modules/security/path-validator.js +1 -3
- package/dist/modules/security/security-policies.js +3 -19
- 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 +3 -9
- package/dist/modules/skills/matcher.js +27 -0
- package/dist/modules/skills/module.js +1 -2
- package/dist/modules/updater/checker.js +70 -6
- package/dist/modules/updater/index.js +2 -1
- package/dist/modules/updater/module.js +116 -0
- 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 +178 -19
- package/dist/tools/browser.js +46 -29
- package/dist/tools/chunk-query.js +99 -0
- package/dist/tools/download-file.js +116 -0
- package/dist/tools/enable-tools.js +58 -0
- package/dist/tools/executor.js +4 -5
- package/dist/tools/file-info.js +13 -12
- package/dist/tools/filter-tools.js +9 -2
- package/dist/tools/glob-tool.js +11 -11
- package/dist/tools/grep-tool.js +1 -3
- package/dist/tools/hidden-tools-block.js +37 -0
- package/dist/tools/index.js +13 -2
- package/dist/tools/list-dir.js +18 -17
- package/dist/tools/load-skill.js +1 -3
- 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 +20 -22
- package/dist/tools/process-log.js +22 -18
- package/dist/tools/question.js +1 -3
- package/dist/tools/read-file.js +10 -2
- package/dist/tools/recall.js +44 -37
- package/dist/tools/registry.js +15 -4
- package/dist/tools/remember.js +29 -29
- package/dist/tools/scope-check.js +9 -9
- package/dist/tools/subagent.js +54 -9
- 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 +1 -3
- package/dist/ui/box.js +1 -5
- package/dist/ui/index.js +6 -6
- package/dist/ui/line-editor.js +703 -0
- package/dist/ui/line-math.js +69 -0
- package/dist/ui/md-formatter.js +33 -33
- package/dist/ui/output.js +5 -5
- package/dist/ui/plan-view.js +103 -0
- package/dist/ui/renderer.js +15 -10
- package/dist/ui/table.js +1 -1
- package/package.json +48 -48
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { t } from "../i18n/index";
|
|
4
|
+
import { isPathInScope } from "./scope-check";
|
|
5
|
+
import { runChunkQuery } from "../modules/context/chunk-query";
|
|
6
|
+
export const chunkQueryTool = {
|
|
7
|
+
name: "chunk_query",
|
|
8
|
+
description: "Answer a query over a large text (file or inline) by splitting it into chunks and querying the model per chunk in parallel, then optionally synthesizing a final answer. Use when the input is too large for the context window.",
|
|
9
|
+
tags: ["research", "code"],
|
|
10
|
+
/** Multiple LLM calls (parallel chunk queries + synthesis) need a longer budget. */
|
|
11
|
+
timeoutMs: 300000,
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
query: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "The question to answer over the text.",
|
|
18
|
+
},
|
|
19
|
+
input_path: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Path to the large text file (scope-checked). Preferred over text.",
|
|
22
|
+
},
|
|
23
|
+
text: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Inline text. Use only when a file path is not available.",
|
|
26
|
+
},
|
|
27
|
+
chunk_chars: {
|
|
28
|
+
type: "number",
|
|
29
|
+
description: "Approximate chunk size in chars (default 12000).",
|
|
30
|
+
},
|
|
31
|
+
max_parallel: {
|
|
32
|
+
type: "number",
|
|
33
|
+
description: "Max parallel chunk queries (default from config.subagent.maxParallelChunkQueries).",
|
|
34
|
+
},
|
|
35
|
+
max_chunk_tokens: {
|
|
36
|
+
type: "number",
|
|
37
|
+
description: "Cap on generated tokens per chunk call (default 1024).",
|
|
38
|
+
},
|
|
39
|
+
max_synthesis_tokens: {
|
|
40
|
+
type: "number",
|
|
41
|
+
description: "Cap on generated tokens for the synthesis call (default 2048).",
|
|
42
|
+
},
|
|
43
|
+
reasoning_effort: {
|
|
44
|
+
type: "string",
|
|
45
|
+
enum: ["none", "low", "medium", "high"],
|
|
46
|
+
description: 'Reasoning effort for chunk/synthesis calls (default "none"). "none" prevents long thinking chains from eating the token budget on reasoning models.',
|
|
47
|
+
},
|
|
48
|
+
synthesize: {
|
|
49
|
+
type: "boolean",
|
|
50
|
+
description: "Run a final synthesis call over chunk answers (default true).",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ["query"],
|
|
54
|
+
},
|
|
55
|
+
handler: async (ctx, args) => {
|
|
56
|
+
const query = String(args.query || "");
|
|
57
|
+
const inputPath = args.input_path ? String(args.input_path) : undefined;
|
|
58
|
+
const text = args.text ? String(args.text) : undefined;
|
|
59
|
+
if (!query)
|
|
60
|
+
return { success: false, output: t("tool.chunk_query_no_query") };
|
|
61
|
+
if (!inputPath && !text)
|
|
62
|
+
return { success: false, output: t("tool.chunk_query_no_input") };
|
|
63
|
+
let content = text || "";
|
|
64
|
+
if (inputPath) {
|
|
65
|
+
const check = isPathInScope(ctx.baseDir, inputPath, ctx.scope);
|
|
66
|
+
if (!check.allowed) {
|
|
67
|
+
return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
content = readFileSync(resolve(ctx.baseDir, inputPath), "utf8");
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!ctx.llmProvider) {
|
|
77
|
+
return { success: false, output: "chunk_query: missing llmProvider in context" };
|
|
78
|
+
}
|
|
79
|
+
const maxParallel = typeof args.max_parallel === "number"
|
|
80
|
+
? args.max_parallel
|
|
81
|
+
: (ctx.config.subagent?.maxParallelChunkQueries ?? 4);
|
|
82
|
+
const res = await runChunkQuery(ctx.llmProvider, content, query, {
|
|
83
|
+
chunkChars: typeof args.chunk_chars === "number" ? args.chunk_chars : undefined,
|
|
84
|
+
maxParallel,
|
|
85
|
+
synthesize: typeof args.synthesize === "boolean" ? args.synthesize : undefined,
|
|
86
|
+
maxChunkTokens: typeof args.max_chunk_tokens === "number" ? args.max_chunk_tokens : undefined,
|
|
87
|
+
maxSynthesisTokens: typeof args.max_synthesis_tokens === "number" ? args.max_synthesis_tokens : undefined,
|
|
88
|
+
reasoningEffort: ["none", "low", "medium", "high"].includes(args.reasoning_effort)
|
|
89
|
+
? args.reasoning_effort
|
|
90
|
+
: undefined,
|
|
91
|
+
logger: ctx.logger,
|
|
92
|
+
});
|
|
93
|
+
ctx.logger.debug(`chunk_query: ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}`);
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
output: `[chunk_query] ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}\n\n${res.synthesis || res.answers.join("\n")}`,
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { t } from "../i18n/index";
|
|
4
|
+
import { isUrlAllowed, sanitizeUrl } from "../modules/security/network-validator";
|
|
5
|
+
import { isPathWritable } from "../modules/security/path-validator";
|
|
6
|
+
import { logNetworkRequest, logFileWrite, logSecurityBlock } from "../modules/security/audit-log";
|
|
7
|
+
import { getSessionSecurityConfig } from "../modules/security/session-isolation";
|
|
8
|
+
import { DEFAULT_SECURITY_CONFIG } from "../config/security";
|
|
9
|
+
import { safeResolvePath } from "./path-utils";
|
|
10
|
+
/** Default cap for a single download (bytes). Chunked responses without a
|
|
11
|
+
* content-length header are checked after the body is read. */
|
|
12
|
+
export const MAX_DOWNLOAD_BYTES = 100 * 1024 * 1024;
|
|
13
|
+
export const downloadFileTool = {
|
|
14
|
+
name: "download_file",
|
|
15
|
+
description: "Download a file (image, archive, binary, font, etc.) from a URL and save it to disk. Returns only the path, size and content type — read the saved file with read_file/attach_image afterwards. Use this for binary files; web_fetch/web_browse return text only and cannot save bytes.",
|
|
16
|
+
tags: ["file", "research"],
|
|
17
|
+
parameters: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
url: { type: "string", description: "URL to download" },
|
|
21
|
+
path: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Destination path (relative to the working directory)",
|
|
24
|
+
},
|
|
25
|
+
max_bytes: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Optional size cap in bytes (default 100 MB)",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["url", "path"],
|
|
31
|
+
},
|
|
32
|
+
handler: async (ctx, args) => {
|
|
33
|
+
const url = String(args.url || "").trim();
|
|
34
|
+
const path = String(args.path || "").trim();
|
|
35
|
+
if (!url || !path) {
|
|
36
|
+
return { success: false, output: t("tool.invalid_params") };
|
|
37
|
+
}
|
|
38
|
+
// Network security: same rules as web_fetch/web_browse.
|
|
39
|
+
const securityConfig = ctx.sessionContext
|
|
40
|
+
? getSessionSecurityConfig(ctx.config, ctx.sessionContext).network
|
|
41
|
+
: ctx.config.security?.network || DEFAULT_SECURITY_CONFIG.network;
|
|
42
|
+
const validation = isUrlAllowed(url, securityConfig);
|
|
43
|
+
if (!validation.allowed) {
|
|
44
|
+
logSecurityBlock(ctx.sessionId, "network_request", validation.reason || "URL blocked by security policy", sanitizeUrl(url));
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
output: `[SECURITY BLOCKED] URL is not allowed: ${validation.reason}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Path safety: resolve against baseDir and verify writability.
|
|
51
|
+
const resolved = safeResolvePath(ctx.baseDir, path);
|
|
52
|
+
const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
|
|
53
|
+
if (!scopeCheck.allowed) {
|
|
54
|
+
logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
output: t("file.path_not_allowed", {
|
|
58
|
+
path: `${path} — ${scopeCheck.reason}`,
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const maxBytes = Number(args.max_bytes) > 0 ? Number(args.max_bytes) : MAX_DOWNLOAD_BYTES;
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
signal: AbortSignal.timeout(securityConfig?.requestTimeout || 15000),
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Status: ${response.status}`);
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
output: t("error.http", {
|
|
72
|
+
status: response.status,
|
|
73
|
+
statusText: response.statusText,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const contentLength = Number(response.headers.get("content-length") || "0");
|
|
78
|
+
if (contentLength > maxBytes) {
|
|
79
|
+
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${contentLength}`);
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
output: t("tool.download_too_large", { max: String(maxBytes) }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
86
|
+
if (buffer.byteLength > maxBytes) {
|
|
87
|
+
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${buffer.byteLength}`);
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
output: t("tool.download_too_large", { max: String(maxBytes) }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
mkdirSync(dirname(resolved), { recursive: true });
|
|
94
|
+
writeFileSync(resolved, buffer);
|
|
95
|
+
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
|
|
96
|
+
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
|
|
97
|
+
logFileWrite(ctx.sessionId, resolved, true, `Downloaded ${buffer.byteLength} bytes`);
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
output: t("tool.downloaded", {
|
|
101
|
+
url: sanitizeUrl(url),
|
|
102
|
+
path: resolved,
|
|
103
|
+
size: String(buffer.byteLength),
|
|
104
|
+
type: contentType,
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Error: ${e.message}`);
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
output: t("error.fetch_failed", { message: e.message }),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { t } from "../i18n/index";
|
|
2
|
+
/**
|
|
3
|
+
* On-demand tool activation. The main loop exposes only `config.tools.defaultTags`
|
|
4
|
+
* (+ `alwaysOn` structural tools). Specialized tools (web, browser, memory,
|
|
5
|
+
* process) are hidden from the schema to shrink the token footprint; the model
|
|
6
|
+
* activates them by calling this tool with the desired tag. The handler pushes
|
|
7
|
+
* the tags into the shared mutable `ctx.activeToolTags` array, which the agent
|
|
8
|
+
* loop re-reads each iteration to recompute the LLM-visible tool set.
|
|
9
|
+
*/
|
|
10
|
+
export const enableToolsTool = {
|
|
11
|
+
name: "enable_tools",
|
|
12
|
+
description: "Enable hidden tool categories for the current session. Only the essential tools (file/code/shell) are active by default. Call this with the tags you need and they become available from the next turn. Available tags: file, code, shell, research, browser, vision, image, memory, core. Returns the newly available tools. To run a task in a separate context instead, use subagent with tool_tags.",
|
|
13
|
+
alwaysOn: true,
|
|
14
|
+
parameters: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
tags: {
|
|
18
|
+
type: "array",
|
|
19
|
+
items: { type: "string" },
|
|
20
|
+
description: 'Tool tags to enable (e.g. ["research"] for web_search/web_fetch, ["browser"] for the browser, ["memory"] for remember/recall, ["shell"] for process management).',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
required: ["tags"],
|
|
24
|
+
},
|
|
25
|
+
handler: async (ctx, args) => {
|
|
26
|
+
const requested = Array.isArray(args.tags) ? args.tags.map(String).filter(Boolean) : [];
|
|
27
|
+
if (requested.length === 0) {
|
|
28
|
+
return { success: false, output: t("tools.enable_no_tags") };
|
|
29
|
+
}
|
|
30
|
+
const active = ctx.activeToolTags ?? [];
|
|
31
|
+
const added = [];
|
|
32
|
+
for (const tag of requested) {
|
|
33
|
+
if (!active.includes(tag)) {
|
|
34
|
+
active.push(tag);
|
|
35
|
+
added.push(tag);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!ctx.toolExecutor) {
|
|
39
|
+
return { success: false, output: t("tools.enable_no_executor") };
|
|
40
|
+
}
|
|
41
|
+
const nowVisible = ctx.toolExecutor.getToolDefinitions([...active]).map((t) => t.name);
|
|
42
|
+
if (added.length === 0) {
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
output: t("tools.enable_already_active", {
|
|
46
|
+
tags: requested.join(", "),
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
output: t("tools.enable_added", {
|
|
53
|
+
tags: added.join(", "),
|
|
54
|
+
tools: nowVisible.join(", "),
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
package/dist/tools/executor.js
CHANGED
|
@@ -49,9 +49,7 @@ export class ToolExecutor {
|
|
|
49
49
|
try {
|
|
50
50
|
const proceed = await plugin.onBeforeTool(this.ctx, call);
|
|
51
51
|
if (proceed === false || typeof proceed === "string") {
|
|
52
|
-
const pluginName = plugin.name ||
|
|
53
|
-
plugin.constructor?.name ||
|
|
54
|
-
"unknown";
|
|
52
|
+
const pluginName = plugin.name || plugin.constructor?.name || "unknown";
|
|
55
53
|
const reason = typeof proceed === "string" ? proceed : undefined;
|
|
56
54
|
return {
|
|
57
55
|
success: false,
|
|
@@ -75,15 +73,16 @@ export class ToolExecutor {
|
|
|
75
73
|
result = await tool.handler(this.ctx, call.arguments);
|
|
76
74
|
}
|
|
77
75
|
else {
|
|
76
|
+
const timeoutMs = tool.timeoutMs ?? TOOL_EXECUTION_TIMEOUT_MS;
|
|
78
77
|
const timeoutPromise = new Promise((_, reject) => {
|
|
79
78
|
setTimeout(() => {
|
|
80
79
|
// Kill any long-running child process registered for this call.
|
|
81
80
|
killByCallId(call.id);
|
|
82
81
|
reject(new Error(t("tool.timeout", {
|
|
83
82
|
name: call.name,
|
|
84
|
-
seconds:
|
|
83
|
+
seconds: Math.round(timeoutMs / 1000),
|
|
85
84
|
})));
|
|
86
|
-
},
|
|
85
|
+
}, timeoutMs);
|
|
87
86
|
});
|
|
88
87
|
const racePromises = [
|
|
89
88
|
tool.handler(this.ctx, call.arguments),
|
package/dist/tools/file-info.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { statSync, existsSync } from
|
|
2
|
-
import { t } from
|
|
3
|
-
import { isPathInScope } from
|
|
4
|
-
import { safeResolvePath } from
|
|
1
|
+
import { statSync, existsSync } from "fs";
|
|
2
|
+
import { t } from "../i18n/index";
|
|
3
|
+
import { isPathInScope } from "../modules/security/path-validator";
|
|
4
|
+
import { safeResolvePath } from "./path-utils";
|
|
5
5
|
export const fileInfoTool = {
|
|
6
|
-
name:
|
|
7
|
-
description:
|
|
8
|
-
tags: [
|
|
6
|
+
name: "file_info",
|
|
7
|
+
description: "Get metadata about a file or directory (size, creation date, modification date).",
|
|
8
|
+
tags: ["file"],
|
|
9
|
+
boundedOutput: true,
|
|
9
10
|
parameters: {
|
|
10
|
-
type:
|
|
11
|
+
type: "object",
|
|
11
12
|
properties: {
|
|
12
|
-
path: { type:
|
|
13
|
+
path: { type: "string", description: "File path" },
|
|
13
14
|
},
|
|
14
|
-
required: [
|
|
15
|
+
required: ["path"],
|
|
15
16
|
},
|
|
16
17
|
handler: async (ctx, args) => {
|
|
17
18
|
const path = String(args.path);
|
|
@@ -21,13 +22,13 @@ export const fileInfoTool = {
|
|
|
21
22
|
if (!scopeCheck.allowed) {
|
|
22
23
|
return {
|
|
23
24
|
success: false,
|
|
24
|
-
output: t(
|
|
25
|
+
output: t("file.path_not_allowed", {
|
|
25
26
|
path: `${path} — ${scopeCheck.reason}`,
|
|
26
27
|
}),
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
if (!existsSync(resolved)) {
|
|
30
|
-
return { success: false, output: t(
|
|
31
|
+
return { success: false, output: t("file.not_found_short", { path }) };
|
|
31
32
|
}
|
|
32
33
|
const stat = statSync(resolved);
|
|
33
34
|
return {
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter tools by a tag set, always keeping `alwaysOn` tools. Used by MoE
|
|
3
|
+
* expert routing and subagent tool_tags so structural tools (plan/todo/verify,
|
|
4
|
+
* project_map, lsp_check, enable_tools) survive narrowing.
|
|
5
|
+
*/
|
|
1
6
|
export function filterToolsByTags(tools, toolTags) {
|
|
2
7
|
if (!toolTags || toolTags.length === 0)
|
|
3
8
|
return tools;
|
|
4
9
|
const tagSet = new Set(toolTags);
|
|
5
|
-
return tools.filter(t => {
|
|
10
|
+
return tools.filter((t) => {
|
|
11
|
+
if (t.alwaysOn)
|
|
12
|
+
return true;
|
|
6
13
|
if (!t.tags || t.tags.length === 0)
|
|
7
14
|
return false;
|
|
8
|
-
return t.tags.some(tag => tagSet.has(tag));
|
|
15
|
+
return t.tags.some((tag) => tagSet.has(tag));
|
|
9
16
|
});
|
|
10
17
|
}
|
package/dist/tools/glob-tool.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { globSync } from
|
|
2
|
-
import { t } from
|
|
3
|
-
import { MAX_PREVIEW_LINES } from
|
|
1
|
+
import { globSync } from "fs";
|
|
2
|
+
import { t } from "../i18n/index";
|
|
3
|
+
import { MAX_PREVIEW_LINES } from "./preview";
|
|
4
4
|
export const globTool = {
|
|
5
|
-
name:
|
|
5
|
+
name: "glob",
|
|
6
6
|
description: `Search for files matching a glob pattern. Shows up to ${MAX_PREVIEW_LINES} results by default. Uses standard glob syntax (e.g., **/*.ts, src/**/*.test.ts).`,
|
|
7
|
-
tags: [
|
|
7
|
+
tags: ["file", "code", "research"],
|
|
8
8
|
parameters: {
|
|
9
|
-
type:
|
|
9
|
+
type: "object",
|
|
10
10
|
properties: {
|
|
11
|
-
pattern: { type:
|
|
11
|
+
pattern: { type: "string", description: "Glob pattern" },
|
|
12
12
|
},
|
|
13
|
-
required: [
|
|
13
|
+
required: ["pattern"],
|
|
14
14
|
},
|
|
15
15
|
handler: async (ctx, args) => {
|
|
16
16
|
const pattern = String(args.pattern);
|
|
17
17
|
const results = globSync(pattern, { cwd: ctx.baseDir });
|
|
18
18
|
if (results.length === 0) {
|
|
19
|
-
return { success: true, output: t(
|
|
19
|
+
return { success: true, output: t("file.no_matches") };
|
|
20
20
|
}
|
|
21
21
|
const truncated = results.length > MAX_PREVIEW_LINES
|
|
22
22
|
? `\n... (${results.length - MAX_PREVIEW_LINES} more files)`
|
|
23
|
-
:
|
|
24
|
-
return { success: true, output: results.slice(0, MAX_PREVIEW_LINES).join(
|
|
23
|
+
: "";
|
|
24
|
+
return { success: true, output: results.slice(0, MAX_PREVIEW_LINES).join("\n") + truncated };
|
|
25
25
|
},
|
|
26
26
|
};
|
package/dist/tools/grep-tool.js
CHANGED
|
@@ -31,9 +31,7 @@ export const grepTool = {
|
|
|
31
31
|
},
|
|
32
32
|
handler: async (ctx, args) => {
|
|
33
33
|
const pattern = String(args.pattern);
|
|
34
|
-
const searchPath = args.path
|
|
35
|
-
? resolve(ctx.baseDir, String(args.path))
|
|
36
|
-
: ctx.baseDir;
|
|
34
|
+
const searchPath = args.path ? resolve(ctx.baseDir, String(args.path)) : ctx.baseDir;
|
|
37
35
|
// Build rg arguments as an array to avoid shell interpretation of regex
|
|
38
36
|
// metacharacters like |, (, ) — these are regex patterns, not shell operators.
|
|
39
37
|
const rgArgs = ["-n", "--with-filename", pattern, searchPath];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { t } from "../i18n/index";
|
|
2
|
+
/**
|
|
3
|
+
* Build a compact system-prompt block listing the tools hidden by the current
|
|
4
|
+
* tag filter. The model must know these tools exist (and how to reach them)
|
|
5
|
+
* even though they are absent from the LLM tool schema. Grouped by tag with
|
|
6
|
+
* short purposes; capped to keep the block small.
|
|
7
|
+
*/
|
|
8
|
+
export function buildHiddenToolsBlock(allTools, activeTags) {
|
|
9
|
+
if (!allTools.length)
|
|
10
|
+
return "";
|
|
11
|
+
const activeSet = new Set(activeTags);
|
|
12
|
+
const visible = new Set();
|
|
13
|
+
for (const tool of allTools) {
|
|
14
|
+
if (tool.alwaysOn || (tool.tags && tool.tags.some((tag) => activeSet.has(tag)))) {
|
|
15
|
+
visible.add(tool.name);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const hidden = allTools.filter((tool) => !visible.has(tool.name));
|
|
19
|
+
if (hidden.length === 0)
|
|
20
|
+
return "";
|
|
21
|
+
// Group by tag → tools, then by tool name alphabetically within a tag.
|
|
22
|
+
const byTag = new Map();
|
|
23
|
+
for (const tool of hidden) {
|
|
24
|
+
const tags = tool.tags && tool.tags.length > 0 ? tool.tags : ["other"];
|
|
25
|
+
for (const tag of tags) {
|
|
26
|
+
if (!byTag.has(tag))
|
|
27
|
+
byTag.set(tag, []);
|
|
28
|
+
byTag.get(tag).push(tool);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const lines = [t("tools.hidden_header")];
|
|
32
|
+
for (const [tag, tools] of [...byTag.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
33
|
+
const names = [...new Set(tools.map((tool) => tool.name))].sort().join(", ");
|
|
34
|
+
lines.push(`- [${tag}] ${names}`);
|
|
35
|
+
}
|
|
36
|
+
return lines.join("\n");
|
|
37
|
+
}
|
package/dist/tools/index.js
CHANGED
|
@@ -15,9 +15,11 @@ import { processListTool } from "./process-list";
|
|
|
15
15
|
import { processLogTool } from "./process-log";
|
|
16
16
|
import { processKillTool } from "./process-kill";
|
|
17
17
|
import { subagentTool } from "./subagent";
|
|
18
|
+
import { chunkQueryTool } from "./chunk-query";
|
|
18
19
|
import { webSearchTool } from "./web-search";
|
|
19
20
|
import { webFetchTool } from "./web-fetch";
|
|
20
21
|
import { webBrowseTool } from "./web-browse";
|
|
22
|
+
import { downloadFileTool } from "./download-file";
|
|
21
23
|
// questionTool and approveTool removed — interactive menus are too disruptive for small models.
|
|
22
24
|
// The model should ask questions as plain text in its response instead.
|
|
23
25
|
// import { questionTool } from './question'
|
|
@@ -30,10 +32,11 @@ import { rememberTool } from "./remember";
|
|
|
30
32
|
import { recallTool } from "./recall";
|
|
31
33
|
import { createBrowserTool } from "./browser";
|
|
32
34
|
import { attachImageTool } from "./attach-image";
|
|
35
|
+
import { enableToolsTool } from "./enable-tools";
|
|
33
36
|
export { ToolRegistry, ToolExecutor };
|
|
34
37
|
export { filterToolsByTags } from "./filter-tools";
|
|
35
|
-
export { readFileTool, writeFileTool, editFileTool, globTool, grepTool, listDirTool, createDirTool, deleteFileTool, moveFileTool, fileInfoTool, bashTool, subagentTool, processListTool, processLogTool, processKillTool, webSearchTool, webFetchTool, webBrowseTool, createLoadSkillTool, pipelineRunTool, mcpCallTool, searchHistoryTool, rememberTool, recallTool, createBrowserTool, attachImageTool, };
|
|
36
|
-
export function registerAllTools(registry, skillsModule) {
|
|
38
|
+
export { readFileTool, writeFileTool, editFileTool, globTool, grepTool, listDirTool, createDirTool, deleteFileTool, moveFileTool, fileInfoTool, bashTool, subagentTool, chunkQueryTool, processListTool, processLogTool, processKillTool, webSearchTool, webFetchTool, webBrowseTool, downloadFileTool, createLoadSkillTool, pipelineRunTool, mcpCallTool, searchHistoryTool, rememberTool, recallTool, createBrowserTool, attachImageTool, enableToolsTool, };
|
|
39
|
+
export function registerAllTools(registry, skillsModule, opts) {
|
|
37
40
|
const tools = [
|
|
38
41
|
readFileTool,
|
|
39
42
|
writeFileTool,
|
|
@@ -47,17 +50,25 @@ export function registerAllTools(registry, skillsModule) {
|
|
|
47
50
|
fileInfoTool,
|
|
48
51
|
bashTool,
|
|
49
52
|
subagentTool,
|
|
53
|
+
chunkQueryTool,
|
|
50
54
|
processListTool,
|
|
51
55
|
processLogTool,
|
|
52
56
|
processKillTool,
|
|
53
57
|
webSearchTool,
|
|
54
58
|
webFetchTool,
|
|
55
59
|
webBrowseTool,
|
|
60
|
+
downloadFileTool,
|
|
56
61
|
pipelineRunTool,
|
|
57
62
|
mcpCallTool,
|
|
58
63
|
searchHistoryTool,
|
|
59
64
|
attachImageTool,
|
|
60
65
|
];
|
|
66
|
+
// On-demand tool activation is the default. When explicitly disabled
|
|
67
|
+
// (enableOnDemand: false), the tool is not registered at all — combined
|
|
68
|
+
// with an empty defaultTags this restores the legacy all-tools behavior.
|
|
69
|
+
if (opts?.enableOnDemand !== false) {
|
|
70
|
+
tools.push(enableToolsTool);
|
|
71
|
+
}
|
|
61
72
|
if (skillsModule) {
|
|
62
73
|
tools.push(createLoadSkillTool(skillsModule));
|
|
63
74
|
}
|
package/dist/tools/list-dir.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { readdirSync, statSync, existsSync } from
|
|
2
|
-
import { resolve } from
|
|
3
|
-
import { t } from
|
|
4
|
-
import { isPathInScope } from
|
|
5
|
-
import { safeResolvePath } from
|
|
6
|
-
import { MAX_PREVIEW_LINES } from
|
|
1
|
+
import { readdirSync, statSync, existsSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { t } from "../i18n/index";
|
|
4
|
+
import { isPathInScope } from "../modules/security/path-validator";
|
|
5
|
+
import { safeResolvePath } from "./path-utils";
|
|
6
|
+
import { MAX_PREVIEW_LINES } from "./preview";
|
|
7
7
|
export const listDirTool = {
|
|
8
|
-
name:
|
|
8
|
+
name: "list_dir",
|
|
9
9
|
description: `List files and directories in a given path. Shows up to ${MAX_PREVIEW_LINES} entries by default.`,
|
|
10
|
-
tags: [
|
|
10
|
+
tags: ["file"],
|
|
11
|
+
boundedOutput: true,
|
|
11
12
|
parameters: {
|
|
12
|
-
type:
|
|
13
|
+
type: "object",
|
|
13
14
|
properties: {
|
|
14
|
-
path: { type:
|
|
15
|
+
path: { type: "string", description: "Directory path" },
|
|
15
16
|
},
|
|
16
|
-
required: [
|
|
17
|
+
required: ["path"],
|
|
17
18
|
},
|
|
18
19
|
handler: async (ctx, args) => {
|
|
19
20
|
const path = String(args.path);
|
|
@@ -23,25 +24,25 @@ export const listDirTool = {
|
|
|
23
24
|
if (!scopeCheck.allowed) {
|
|
24
25
|
return {
|
|
25
26
|
success: false,
|
|
26
|
-
output: t(
|
|
27
|
+
output: t("file.path_not_allowed", {
|
|
27
28
|
path: `${path} — ${scopeCheck.reason}`,
|
|
28
29
|
}),
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
if (!existsSync(resolved)) {
|
|
32
|
-
return { success: false, output: t(
|
|
33
|
+
return { success: false, output: t("file.dir_notfound", { path }) };
|
|
33
34
|
}
|
|
34
35
|
const entries = readdirSync(resolved);
|
|
35
|
-
const lines = entries.map(e => {
|
|
36
|
+
const lines = entries.map((e) => {
|
|
36
37
|
const full = resolve(resolved, e);
|
|
37
38
|
return statSync(full).isDirectory() ? `${e}/` : e;
|
|
38
39
|
});
|
|
39
40
|
if (lines.length === 0) {
|
|
40
|
-
return { success: true, output: t(
|
|
41
|
+
return { success: true, output: t("file.empty") };
|
|
41
42
|
}
|
|
42
43
|
const truncated = lines.length > MAX_PREVIEW_LINES
|
|
43
44
|
? `\n... (${lines.length - MAX_PREVIEW_LINES} more entries)`
|
|
44
|
-
:
|
|
45
|
-
return { success: true, output: lines.slice(0, MAX_PREVIEW_LINES).join(
|
|
45
|
+
: "";
|
|
46
|
+
return { success: true, output: lines.slice(0, MAX_PREVIEW_LINES).join("\n") + truncated };
|
|
46
47
|
},
|
|
47
48
|
};
|
package/dist/tools/load-skill.js
CHANGED
|
@@ -28,9 +28,7 @@ export function createLoadSkillTool(skillsModule) {
|
|
|
28
28
|
return { success: false, output: result.message + hint };
|
|
29
29
|
}
|
|
30
30
|
const budget = skillsModule.getBudget();
|
|
31
|
-
const tokens = result.skill
|
|
32
|
-
? Math.ceil(result.skill.content.length / 4)
|
|
33
|
-
: 0;
|
|
31
|
+
const tokens = result.skill ? Math.ceil(result.skill.content.length / 4) : 0;
|
|
34
32
|
return {
|
|
35
33
|
success: true,
|
|
36
34
|
output: t("tool.skill_budget", {
|
package/dist/tools/path-utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolve, normalize, dirname, basename, sep } from
|
|
2
|
-
import { existsSync } from
|
|
1
|
+
import { resolve, normalize, dirname, basename, sep } from "path";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
3
|
/**
|
|
4
4
|
* Resolve a user-provided path against baseDir.
|
|
5
5
|
*
|
|
@@ -13,7 +13,7 @@ import { existsSync } from 'fs';
|
|
|
13
13
|
*/
|
|
14
14
|
export function safeResolvePath(baseDir, userPath) {
|
|
15
15
|
const norm = normalize(userPath);
|
|
16
|
-
const stripped = norm.replace(/^[/\\]/,
|
|
16
|
+
const stripped = norm.replace(/^[/\\]/, "");
|
|
17
17
|
const resolved = resolve(baseDir, stripped);
|
|
18
18
|
// Fast path: if it exists (or parent does for new files), return it
|
|
19
19
|
if (existsSync(resolved) || existsSync(dirname(resolved)))
|
|
@@ -31,7 +31,7 @@ export function safeResolvePath(baseDir, userPath) {
|
|
|
31
31
|
while (idx >= 0) {
|
|
32
32
|
const afterIdx = idx + name.length;
|
|
33
33
|
const afterChar = stripped[afterIdx];
|
|
34
|
-
if (afterChar && afterChar !==
|
|
34
|
+
if (afterChar && afterChar !== "\\" && afterChar !== "/") {
|
|
35
35
|
const fixed = stripped.slice(0, afterIdx) + sep + stripped.slice(afterIdx);
|
|
36
36
|
const fixedResolved = resolve(baseDir, normalize(fixed));
|
|
37
37
|
if (existsSync(fixedResolved) || existsSync(dirname(fixedResolved))) {
|