micro-models-agent 0.52.0 → 0.52.1

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 (231) hide show
  1. package/README.md +358 -358
  2. package/dist/main.js +244 -122
  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 +1 -1
  7. package/dist/cli/commands.js +0 -447
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -153
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -761
  13. package/dist/cli/repl.js +0 -702
  14. package/dist/cli/run-result.js +0 -33
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -237
  17. package/dist/config/config.js +0 -276
  18. package/dist/config/defaults.js +0 -141
  19. package/dist/config/domains.js +0 -179
  20. package/dist/config/experts.js +0 -15
  21. package/dist/config/index.js +0 -4
  22. package/dist/config/security.js +0 -213
  23. package/dist/config/types.js +0 -1
  24. package/dist/core/agent-moe.js +0 -102
  25. package/dist/core/agent.js +0 -1018
  26. package/dist/core/bootstrap.js +0 -481
  27. package/dist/core/crash-handler.js +0 -51
  28. package/dist/core/environment.js +0 -199
  29. package/dist/core/index.js +0 -2
  30. package/dist/core/prompt-builder.js +0 -76
  31. package/dist/core/session-logger.js +0 -251
  32. package/dist/core/types.js +0 -1
  33. package/dist/core/version.js +0 -26
  34. package/dist/core/workspace.js +0 -76
  35. package/dist/i18n/en.json +0 -679
  36. package/dist/i18n/index.js +0 -46
  37. package/dist/i18n/ru.json +0 -679
  38. package/dist/index.js +0 -22
  39. package/dist/llm/image-utils.js +0 -143
  40. package/dist/llm/index.js +0 -4
  41. package/dist/llm/model-loader.js +0 -78
  42. package/dist/llm/openai-compat.js +0 -497
  43. package/dist/llm/orchestrator.js +0 -200
  44. package/dist/llm/provider.js +0 -10
  45. package/dist/llm/response.js +0 -39
  46. package/dist/llm/token-counter.js +0 -39
  47. package/dist/llm/types.js +0 -1
  48. package/dist/logger/app-logger.js +0 -189
  49. package/dist/logger/file-log.js +0 -151
  50. package/dist/logger/index.js +0 -1
  51. package/dist/migration/backup.js +0 -45
  52. package/dist/migration/detect.js +0 -50
  53. package/dist/migration/index.js +0 -2
  54. package/dist/modules/artifacts/store.js +0 -61
  55. package/dist/modules/browser/actions.js +0 -76
  56. package/dist/modules/browser/bridge-client.js +0 -199
  57. package/dist/modules/browser/bridge-path.js +0 -10
  58. package/dist/modules/browser/cookie-store.js +0 -24
  59. package/dist/modules/browser/driver.js +0 -136
  60. package/dist/modules/browser/index.js +0 -7
  61. package/dist/modules/browser/module.js +0 -29
  62. package/dist/modules/browser/session.js +0 -342
  63. package/dist/modules/browser/snapshot.js +0 -148
  64. package/dist/modules/browser/types.js +0 -12
  65. package/dist/modules/certification/cli.js +0 -213
  66. package/dist/modules/certification/fact-checker.js +0 -82
  67. package/dist/modules/certification/loader.js +0 -106
  68. package/dist/modules/certification/manifest.js +0 -58
  69. package/dist/modules/certification/runner.js +0 -245
  70. package/dist/modules/certification/scenarios.js +0 -407
  71. package/dist/modules/certification/types.js +0 -1
  72. package/dist/modules/context/chunk-query.js +0 -100
  73. package/dist/modules/context/fact-extractor.js +0 -168
  74. package/dist/modules/context/history.js +0 -15
  75. package/dist/modules/context/index.js +0 -1
  76. package/dist/modules/context/manager.js +0 -440
  77. package/dist/modules/execution/audit-runners.js +0 -206
  78. package/dist/modules/execution/auditor.js +0 -218
  79. package/dist/modules/execution/execution-plugin.js +0 -431
  80. package/dist/modules/execution/index.js +0 -8
  81. package/dist/modules/execution/module.js +0 -625
  82. package/dist/modules/execution/moe-executor.js +0 -304
  83. package/dist/modules/execution/plan-coverage.js +0 -68
  84. package/dist/modules/execution/plan-persister.js +0 -46
  85. package/dist/modules/execution/plan-store.js +0 -196
  86. package/dist/modules/execution/plan-tool.js +0 -677
  87. package/dist/modules/execution/plan-validator.js +0 -153
  88. package/dist/modules/execution/planner.js +0 -94
  89. package/dist/modules/execution/stuck-detector.js +0 -746
  90. package/dist/modules/execution/tracker.js +0 -69
  91. package/dist/modules/execution/types.js +0 -1
  92. package/dist/modules/execution/verifier.js +0 -235
  93. package/dist/modules/execution/windows-commands.js +0 -41
  94. package/dist/modules/hallucination/confidence.js +0 -66
  95. package/dist/modules/hallucination/consistency.js +0 -26
  96. package/dist/modules/hallucination/detector.js +0 -47
  97. package/dist/modules/hallucination/factual.js +0 -169
  98. package/dist/modules/hallucination/index.js +0 -5
  99. package/dist/modules/hallucination/js-identifiers.js +0 -262
  100. package/dist/modules/hallucination/llm-judge.js +0 -101
  101. package/dist/modules/index.js +0 -5
  102. package/dist/modules/indexer/cache.js +0 -40
  103. package/dist/modules/indexer/index.js +0 -3
  104. package/dist/modules/indexer/module.js +0 -246
  105. package/dist/modules/indexer/project-profile.js +0 -183
  106. package/dist/modules/indexer/walker.js +0 -101
  107. package/dist/modules/lsp/check-tool.js +0 -58
  108. package/dist/modules/lsp/client.js +0 -389
  109. package/dist/modules/lsp/command.js +0 -60
  110. package/dist/modules/lsp/config.js +0 -135
  111. package/dist/modules/lsp/index.js +0 -3
  112. package/dist/modules/lsp/module.js +0 -260
  113. package/dist/modules/lsp/probe.js +0 -86
  114. package/dist/modules/lsp/project-root.js +0 -32
  115. package/dist/modules/lsp/startup-check.js +0 -144
  116. package/dist/modules/lsp/types.js +0 -1
  117. package/dist/modules/mcp/client.js +0 -399
  118. package/dist/modules/mcp/index.js +0 -3
  119. package/dist/modules/mcp/module.js +0 -142
  120. package/dist/modules/mcp/registry.js +0 -15
  121. package/dist/modules/memory/index.js +0 -1
  122. package/dist/modules/memory/module.js +0 -96
  123. package/dist/modules/memory/search.js +0 -42
  124. package/dist/modules/memory/store.js +0 -69
  125. package/dist/modules/pipelines/engine.js +0 -60
  126. package/dist/modules/pipelines/index.js +0 -3
  127. package/dist/modules/pipelines/parser.js +0 -56
  128. package/dist/modules/pipelines/template.js +0 -14
  129. package/dist/modules/plugins/builtin/lint-on-write.js +0 -334
  130. package/dist/modules/plugins/builtin/notify.js +0 -9
  131. package/dist/modules/plugins/index.js +0 -1
  132. package/dist/modules/plugins/loader.js +0 -70
  133. package/dist/modules/plugins/manager.js +0 -261
  134. package/dist/modules/plugins/types.js +0 -1
  135. package/dist/modules/pricing/index.js +0 -61
  136. package/dist/modules/pricing/prices.js +0 -129
  137. package/dist/modules/processes/detect.js +0 -34
  138. package/dist/modules/processes/index.js +0 -2
  139. package/dist/modules/processes/registry.js +0 -327
  140. package/dist/modules/processes/runner.js +0 -23
  141. package/dist/modules/providers/create.js +0 -22
  142. package/dist/modules/providers/fallback.js +0 -79
  143. package/dist/modules/providers/health.js +0 -46
  144. package/dist/modules/providers/index.js +0 -5
  145. package/dist/modules/providers/manager.js +0 -161
  146. package/dist/modules/providers/presets.js +0 -128
  147. package/dist/modules/providers/registry.js +0 -22
  148. package/dist/modules/providers/types.js +0 -1
  149. package/dist/modules/registry.js +0 -48
  150. package/dist/modules/security/audit-log.js +0 -136
  151. package/dist/modules/security/audit-notifier.js +0 -292
  152. package/dist/modules/security/command-validator.js +0 -219
  153. package/dist/modules/security/content-scanner.js +0 -53
  154. package/dist/modules/security/data-sanitizer.js +0 -89
  155. package/dist/modules/security/encryption.js +0 -242
  156. package/dist/modules/security/index.js +0 -14
  157. package/dist/modules/security/network-validator.js +0 -88
  158. package/dist/modules/security/path-validator.js +0 -203
  159. package/dist/modules/security/rate-limiter.js +0 -119
  160. package/dist/modules/security/security-policies.js +0 -531
  161. package/dist/modules/security/session-encryption.js +0 -210
  162. package/dist/modules/security/session-isolation.js +0 -95
  163. package/dist/modules/session/index.js +0 -3
  164. package/dist/modules/session/manager.js +0 -172
  165. package/dist/modules/session/module.js +0 -24
  166. package/dist/modules/session/store.js +0 -222
  167. package/dist/modules/session/types.js +0 -1
  168. package/dist/modules/skills/index.js +0 -2
  169. package/dist/modules/skills/loader.js +0 -72
  170. package/dist/modules/skills/matcher.js +0 -27
  171. package/dist/modules/skills/module.js +0 -129
  172. package/dist/modules/types.js +0 -1
  173. package/dist/modules/updater/checker.js +0 -96
  174. package/dist/modules/updater/index.js +0 -2
  175. package/dist/modules/updater/module.js +0 -116
  176. package/dist/modules/user-profile/compressor.js +0 -16
  177. package/dist/modules/user-profile/index.js +0 -1
  178. package/dist/modules/user-profile/profile.js +0 -68
  179. package/dist/tools/approve.js +0 -33
  180. package/dist/tools/attach-image.js +0 -101
  181. package/dist/tools/bash.js +0 -519
  182. package/dist/tools/browser.js +0 -115
  183. package/dist/tools/chunk-query.js +0 -100
  184. package/dist/tools/create-dir.js +0 -56
  185. package/dist/tools/delete-file.js +0 -63
  186. package/dist/tools/download-file.js +0 -117
  187. package/dist/tools/edit-file.js +0 -80
  188. package/dist/tools/enable-tools.js +0 -59
  189. package/dist/tools/executor.js +0 -154
  190. package/dist/tools/file-info.js +0 -47
  191. package/dist/tools/filter-tools.js +0 -17
  192. package/dist/tools/glob-tool.js +0 -27
  193. package/dist/tools/grep-tool.js +0 -125
  194. package/dist/tools/hidden-tools-block.js +0 -37
  195. package/dist/tools/index.js +0 -78
  196. package/dist/tools/list-dir.js +0 -49
  197. package/dist/tools/load-skill.js +0 -43
  198. package/dist/tools/mcp-call.js +0 -69
  199. package/dist/tools/move-file.js +0 -86
  200. package/dist/tools/path-utils.js +0 -101
  201. package/dist/tools/pipeline-run.js +0 -145
  202. package/dist/tools/preview.js +0 -2
  203. package/dist/tools/process-kill.js +0 -40
  204. package/dist/tools/process-list.js +0 -37
  205. package/dist/tools/process-log.js +0 -54
  206. package/dist/tools/question.js +0 -141
  207. package/dist/tools/read-file.js +0 -179
  208. package/dist/tools/recall.js +0 -118
  209. package/dist/tools/registry.js +0 -47
  210. package/dist/tools/remember.js +0 -68
  211. package/dist/tools/scope-check.js +0 -32
  212. package/dist/tools/search-history.js +0 -85
  213. package/dist/tools/subagent.js +0 -196
  214. package/dist/tools/types.js +0 -1
  215. package/dist/tools/user-input.js +0 -123
  216. package/dist/tools/web-browse.js +0 -87
  217. package/dist/tools/web-fetch.js +0 -119
  218. package/dist/tools/web-search.js +0 -105
  219. package/dist/tools/write-file.js +0 -82
  220. package/dist/ui/box.js +0 -77
  221. package/dist/ui/colors.js +0 -4
  222. package/dist/ui/diff.js +0 -178
  223. package/dist/ui/index.js +0 -6
  224. package/dist/ui/line-editor.js +0 -822
  225. package/dist/ui/line-math.js +0 -73
  226. package/dist/ui/md-formatter.js +0 -212
  227. package/dist/ui/output.js +0 -13
  228. package/dist/ui/plan-view.js +0 -103
  229. package/dist/ui/renderer.js +0 -259
  230. package/dist/ui/spinner.js +0 -70
  231. package/dist/ui/table.js +0 -144
@@ -1,100 +0,0 @@
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
- icon: "🧩",
9
- 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.",
10
- tags: ["research", "code"],
11
- /** Multiple LLM calls (parallel chunk queries + synthesis) need a longer budget. */
12
- timeoutMs: 300000,
13
- parameters: {
14
- type: "object",
15
- properties: {
16
- query: {
17
- type: "string",
18
- description: "The question to answer over the text.",
19
- },
20
- input_path: {
21
- type: "string",
22
- description: "Path to the large text file (scope-checked). Preferred over text.",
23
- },
24
- text: {
25
- type: "string",
26
- description: "Inline text. Use only when a file path is not available.",
27
- },
28
- chunk_chars: {
29
- type: "number",
30
- description: "Approximate chunk size in chars (default 12000).",
31
- },
32
- max_parallel: {
33
- type: "number",
34
- description: "Max parallel chunk queries (default from config.subagent.maxParallelChunkQueries).",
35
- },
36
- max_chunk_tokens: {
37
- type: "number",
38
- description: "Cap on generated tokens per chunk call (default 1024).",
39
- },
40
- max_synthesis_tokens: {
41
- type: "number",
42
- description: "Cap on generated tokens for the synthesis call (default 2048).",
43
- },
44
- reasoning_effort: {
45
- type: "string",
46
- enum: ["none", "low", "medium", "high"],
47
- description: 'Reasoning effort for chunk/synthesis calls (default "none"). "none" prevents long thinking chains from eating the token budget on reasoning models.',
48
- },
49
- synthesize: {
50
- type: "boolean",
51
- description: "Run a final synthesis call over chunk answers (default true).",
52
- },
53
- },
54
- required: ["query"],
55
- },
56
- handler: async (ctx, args) => {
57
- const query = String(args.query || "");
58
- const inputPath = args.input_path ? String(args.input_path) : undefined;
59
- const text = args.text ? String(args.text) : undefined;
60
- if (!query)
61
- return { success: false, output: t("tool.chunk_query_no_query") };
62
- if (!inputPath && !text)
63
- return { success: false, output: t("tool.chunk_query_no_input") };
64
- let content = text || "";
65
- if (inputPath) {
66
- const check = isPathInScope(ctx.baseDir, inputPath, ctx.scope);
67
- if (!check.allowed) {
68
- return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
69
- }
70
- try {
71
- content = readFileSync(resolve(ctx.baseDir, inputPath), "utf8");
72
- }
73
- catch (e) {
74
- return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
75
- }
76
- }
77
- if (!ctx.llmProvider) {
78
- return { success: false, output: "chunk_query: missing llmProvider in context" };
79
- }
80
- const maxParallel = typeof args.max_parallel === "number"
81
- ? args.max_parallel
82
- : (ctx.config.subagent?.maxParallelChunkQueries ?? 4);
83
- const res = await runChunkQuery(ctx.llmProvider, content, query, {
84
- chunkChars: typeof args.chunk_chars === "number" ? args.chunk_chars : undefined,
85
- maxParallel,
86
- synthesize: typeof args.synthesize === "boolean" ? args.synthesize : undefined,
87
- maxChunkTokens: typeof args.max_chunk_tokens === "number" ? args.max_chunk_tokens : undefined,
88
- maxSynthesisTokens: typeof args.max_synthesis_tokens === "number" ? args.max_synthesis_tokens : undefined,
89
- reasoningEffort: ["none", "low", "medium", "high"].includes(args.reasoning_effort)
90
- ? args.reasoning_effort
91
- : undefined,
92
- logger: ctx.logger,
93
- });
94
- ctx.logger.debug(`chunk_query: ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}`);
95
- return {
96
- success: true,
97
- output: `[chunk_query] ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}\n\n${res.synthesis || res.answers.join("\n")}`,
98
- };
99
- },
100
- };
@@ -1,56 +0,0 @@
1
- import { mkdirSync, existsSync } from "fs";
2
- import { t } from "../i18n/index";
3
- import { isPathWritable } from "../modules/security/path-validator";
4
- import { logFileWrite, logSecurityBlock } from "../modules/security/audit-log";
5
- import { getSessionSecurityConfig } from "../modules/security/session-isolation";
6
- import { safeResolvePath } from "./path-utils";
7
- export const createDirTool = {
8
- name: "create_dir",
9
- icon: "📁",
10
- description: "Create a directory (and any intermediate directories).",
11
- tags: ["file"],
12
- parameters: {
13
- type: "object",
14
- properties: {
15
- path: { type: "string", description: "Directory path" },
16
- },
17
- required: ["path"],
18
- },
19
- handler: async (ctx, args) => {
20
- const path = String(args.path);
21
- const resolved = safeResolvePath(ctx.baseDir, path);
22
- // Get session-specific security config
23
- const securityConfig = ctx.sessionContext
24
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
25
- : ctx.config.security;
26
- // Check file operations limit
27
- const maxFileOps = securityConfig?.maxFileOperations ?? 100;
28
- const currentCount = ctx.fileOperationsCount ?? 0;
29
- if (currentCount >= maxFileOps) {
30
- logSecurityBlock(ctx.sessionId, "file_write", `Maximum file operations (${maxFileOps}) exceeded`, path);
31
- return {
32
- success: false,
33
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
34
- };
35
- }
36
- // Check path permissions
37
- const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
38
- if (!scopeCheck.allowed) {
39
- logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
40
- return {
41
- success: false,
42
- output: t("file.path_not_allowed", {
43
- path: `${path} — ${scopeCheck.reason}`,
44
- }),
45
- };
46
- }
47
- if (!existsSync(resolved)) {
48
- mkdirSync(resolved, { recursive: true });
49
- }
50
- // Increment file operations counter
51
- ctx.fileOperationsCount = currentCount + 1;
52
- // Log directory creation
53
- logFileWrite(ctx.sessionId, path, true, "Directory created");
54
- return { success: true, output: t("file.created", { path }) };
55
- },
56
- };
@@ -1,63 +0,0 @@
1
- import { unlinkSync, existsSync, statSync, readFileSync } from "fs";
2
- import { t } from "../i18n/index";
3
- import { isPathWritable } from "../modules/security/path-validator";
4
- import { logFileDelete, logSecurityBlock } from "../modules/security/audit-log";
5
- import { getSessionSecurityConfig } from "../modules/security/session-isolation";
6
- import { generateDeleteDiff } from "../ui/diff";
7
- import { safeResolvePath } from "./path-utils";
8
- export const deleteFileTool = {
9
- name: "delete_file",
10
- icon: "🗑️",
11
- description: "Delete a file from the filesystem.",
12
- tags: ["file"],
13
- parameters: {
14
- type: "object",
15
- properties: {
16
- path: { type: "string", description: "File path" },
17
- },
18
- required: ["path"],
19
- },
20
- handler: async (ctx, args) => {
21
- const path = String(args.path);
22
- const resolved = safeResolvePath(ctx.baseDir, path);
23
- // Get session-specific security config
24
- const securityConfig = ctx.sessionContext
25
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
26
- : ctx.config.security;
27
- // Check file operations limit
28
- const maxFileOps = securityConfig?.maxFileOperations ?? 100;
29
- const currentCount = ctx.fileOperationsCount ?? 0;
30
- if (currentCount >= maxFileOps) {
31
- logSecurityBlock(ctx.sessionId, "file_delete", `Maximum file operations (${maxFileOps}) exceeded`, path);
32
- return {
33
- success: false,
34
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
35
- };
36
- }
37
- // Check path permissions
38
- const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
39
- if (!scopeCheck.allowed) {
40
- logSecurityBlock(ctx.sessionId, "file_delete", scopeCheck.reason || "Path not allowed", path);
41
- return {
42
- success: false,
43
- output: t("file.path_not_allowed", {
44
- path: `${path} — ${scopeCheck.reason}`,
45
- }),
46
- };
47
- }
48
- if (!existsSync(resolved)) {
49
- return { success: false, output: t("file.notfound", { path }) };
50
- }
51
- if (statSync(resolved).isDirectory()) {
52
- return { success: false, output: t("file.is_directory", { path }) };
53
- }
54
- const content = readFileSync(resolved, "utf-8");
55
- unlinkSync(resolved);
56
- const diff = generateDeleteDiff(content);
57
- // Increment file operations counter
58
- ctx.fileOperationsCount = currentCount + 1;
59
- // Log successful file deletion
60
- logFileDelete(ctx.sessionId, path, true);
61
- return { success: true, output: t("file.deleted", { path }), diff };
62
- },
63
- };
@@ -1,117 +0,0 @@
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
- icon: "⬇️",
16
- 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.",
17
- tags: ["file", "research"],
18
- parameters: {
19
- type: "object",
20
- properties: {
21
- url: { type: "string", description: "URL to download" },
22
- path: {
23
- type: "string",
24
- description: "Destination path (relative to the working directory)",
25
- },
26
- max_bytes: {
27
- type: "number",
28
- description: "Optional size cap in bytes (default 100 MB)",
29
- },
30
- },
31
- required: ["url", "path"],
32
- },
33
- handler: async (ctx, args) => {
34
- const url = String(args.url || "").trim();
35
- const path = String(args.path || "").trim();
36
- if (!url || !path) {
37
- return { success: false, output: t("tool.invalid_params") };
38
- }
39
- // Network security: same rules as web_fetch/web_browse.
40
- const securityConfig = ctx.sessionContext
41
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext).network
42
- : ctx.config.security?.network || DEFAULT_SECURITY_CONFIG.network;
43
- const validation = isUrlAllowed(url, securityConfig);
44
- if (!validation.allowed) {
45
- logSecurityBlock(ctx.sessionId, "network_request", validation.reason || "URL blocked by security policy", sanitizeUrl(url));
46
- return {
47
- success: false,
48
- output: `[SECURITY BLOCKED] URL is not allowed: ${validation.reason}`,
49
- };
50
- }
51
- // Path safety: resolve against baseDir and verify writability.
52
- const resolved = safeResolvePath(ctx.baseDir, path);
53
- const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
54
- if (!scopeCheck.allowed) {
55
- logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
56
- return {
57
- success: false,
58
- output: t("file.path_not_allowed", {
59
- path: `${path} — ${scopeCheck.reason}`,
60
- }),
61
- };
62
- }
63
- const maxBytes = Number(args.max_bytes) > 0 ? Number(args.max_bytes) : MAX_DOWNLOAD_BYTES;
64
- try {
65
- const response = await fetch(url, {
66
- signal: AbortSignal.timeout(securityConfig?.requestTimeout || 15000),
67
- });
68
- if (!response.ok) {
69
- logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Status: ${response.status}`);
70
- return {
71
- success: false,
72
- output: t("error.http", {
73
- status: response.status,
74
- statusText: response.statusText,
75
- }),
76
- };
77
- }
78
- const contentLength = Number(response.headers.get("content-length") || "0");
79
- if (contentLength > maxBytes) {
80
- logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${contentLength}`);
81
- return {
82
- success: false,
83
- output: t("tool.download_too_large", { max: String(maxBytes) }),
84
- };
85
- }
86
- const buffer = Buffer.from(await response.arrayBuffer());
87
- if (buffer.byteLength > maxBytes) {
88
- logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${buffer.byteLength}`);
89
- return {
90
- success: false,
91
- output: t("tool.download_too_large", { max: String(maxBytes) }),
92
- };
93
- }
94
- mkdirSync(dirname(resolved), { recursive: true });
95
- writeFileSync(resolved, buffer);
96
- const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
97
- logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
98
- logFileWrite(ctx.sessionId, resolved, true, `Downloaded ${buffer.byteLength} bytes`);
99
- return {
100
- success: true,
101
- output: t("tool.downloaded", {
102
- url: sanitizeUrl(url),
103
- path: resolved,
104
- size: String(buffer.byteLength),
105
- type: contentType,
106
- }),
107
- };
108
- }
109
- catch (e) {
110
- logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Error: ${e.message}`);
111
- return {
112
- success: false,
113
- output: t("error.fetch_failed", { message: e.message }),
114
- };
115
- }
116
- },
117
- };
@@ -1,80 +0,0 @@
1
- import { readFileSync, writeFileSync } from "fs";
2
- import { t } from "../i18n/index";
3
- import { isPathWritable } from "../modules/security/path-validator";
4
- import { scanContent } from "../modules/security/content-scanner";
5
- import { logFileWrite, logSecurityBlock } from "../modules/security/audit-log";
6
- import { getSessionSecurityConfig } from "../modules/security/session-isolation";
7
- import { generateDiff } from "../ui/diff";
8
- import { safeResolvePath } from "./path-utils";
9
- export const editFileTool = {
10
- name: "edit_file",
11
- icon: "✏️",
12
- description: "Find and replace text in an existing file. Uses exact string match (not regex).",
13
- tags: ["file", "code"],
14
- parameters: {
15
- type: "object",
16
- properties: {
17
- path: { type: "string", description: "File path" },
18
- old: { type: "string", description: "Text to replace" },
19
- new: { type: "string", description: "Replacement text" },
20
- },
21
- required: ["path", "old", "new"],
22
- },
23
- handler: async (ctx, args) => {
24
- const path = String(args.path);
25
- const resolved = safeResolvePath(ctx.baseDir, path);
26
- // Get session-specific security config
27
- const securityConfig = ctx.sessionContext
28
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
29
- : ctx.config.security;
30
- // Check file operations limit
31
- const maxFileOps = securityConfig?.maxFileOperations ?? 100;
32
- const currentCount = ctx.fileOperationsCount ?? 0;
33
- if (currentCount >= maxFileOps) {
34
- logSecurityBlock(ctx.sessionId, "file_write", `Maximum file operations (${maxFileOps}) exceeded`, path);
35
- return {
36
- success: false,
37
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
38
- };
39
- }
40
- // Check path permissions
41
- const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
42
- if (!scopeCheck.allowed) {
43
- logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
44
- return {
45
- success: false,
46
- output: t("file.path_not_allowed", {
47
- path: `${path} — ${scopeCheck.reason}`,
48
- }),
49
- };
50
- }
51
- const content = readFileSync(resolved, "utf-8");
52
- const oldStr = String(args.old);
53
- const newStr = String(args.new);
54
- if (!content.includes(oldStr)) {
55
- return {
56
- success: false,
57
- output: t("file.string_not_found", { str: oldStr, path }),
58
- };
59
- }
60
- const updated = content.replace(oldStr, newStr);
61
- // Check new content for dangerous patterns — only when security is enabled
62
- if (securityConfig?.enabled && securityConfig?.contentScan?.enabled) {
63
- const scanResult = scanContent(updated, path, securityConfig.contentScan);
64
- if (!scanResult.allowed) {
65
- logSecurityBlock(ctx.sessionId, "file_write", scanResult.reason || "Content contains dangerous patterns", path);
66
- return {
67
- success: false,
68
- output: `[SECURITY BLOCKED] ${scanResult.reason}`,
69
- };
70
- }
71
- }
72
- writeFileSync(resolved, updated, "utf-8");
73
- const diff = generateDiff(content, updated);
74
- // Increment file operations counter
75
- ctx.fileOperationsCount = currentCount + 1;
76
- // Log successful file edit
77
- logFileWrite(ctx.sessionId, path, true, "File edited");
78
- return { success: true, output: t("file.replaced_in", { path }), diff };
79
- },
80
- };
@@ -1,59 +0,0 @@
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
- icon: "🔌",
13
- 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.",
14
- alwaysOn: true,
15
- parameters: {
16
- type: "object",
17
- properties: {
18
- tags: {
19
- type: "array",
20
- items: { type: "string" },
21
- 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).',
22
- },
23
- },
24
- required: ["tags"],
25
- },
26
- handler: async (ctx, args) => {
27
- const requested = Array.isArray(args.tags) ? args.tags.map(String).filter(Boolean) : [];
28
- if (requested.length === 0) {
29
- return { success: false, output: t("tools.enable_no_tags") };
30
- }
31
- const active = ctx.activeToolTags ?? [];
32
- const added = [];
33
- for (const tag of requested) {
34
- if (!active.includes(tag)) {
35
- active.push(tag);
36
- added.push(tag);
37
- }
38
- }
39
- if (!ctx.toolExecutor) {
40
- return { success: false, output: t("tools.enable_no_executor") };
41
- }
42
- const nowVisible = ctx.toolExecutor.getToolDefinitions([...active]).map((t) => t.name);
43
- if (added.length === 0) {
44
- return {
45
- success: true,
46
- output: t("tools.enable_already_active", {
47
- tags: requested.join(", "),
48
- }),
49
- };
50
- }
51
- return {
52
- success: true,
53
- output: t("tools.enable_added", {
54
- tags: added.join(", "),
55
- tools: nowVisible.join(", "),
56
- }),
57
- };
58
- },
59
- };
@@ -1,154 +0,0 @@
1
- import { killByCallId } from "../modules/processes/runner";
2
- import { t } from "../i18n/index";
3
- const TOOL_EXECUTION_TIMEOUT_MS = 60000;
4
- export class ToolExecutor {
5
- registry;
6
- ctx;
7
- pluginManager;
8
- constructor(registry, ctx, pluginManager) {
9
- this.registry = registry;
10
- this.ctx = ctx;
11
- this.pluginManager = pluginManager;
12
- }
13
- /**
14
- * Execute a tool by name with plain arguments (no call id, no timeout
15
- * wiring). Used internally — e.g. bash redirects a mistaken tool-call-as-
16
- * command into the real tool. Runs through the same registry and plugin
17
- * hooks as a normal call.
18
- */
19
- async executeByName(name, args, ctx) {
20
- const prevCtx = this.ctx;
21
- if (ctx)
22
- this.ctx = ctx;
23
- try {
24
- return await this.execute({
25
- id: `redirect_${Date.now()}`,
26
- name,
27
- arguments: args,
28
- });
29
- }
30
- finally {
31
- this.ctx = prevCtx;
32
- }
33
- }
34
- /** Whether a tool with this name is registered (used before redirects). */
35
- hasTool(name) {
36
- return this.registry.has(name);
37
- }
38
- async execute(call, signal) {
39
- const tool = this.registry.get(call.name);
40
- if (!tool) {
41
- return {
42
- success: false,
43
- output: t("tool.unknown", { name: call.name }),
44
- toolCallId: call.id,
45
- };
46
- }
47
- for (const plugin of this.pluginManager.getAllPlugins()) {
48
- if (plugin.onBeforeTool) {
49
- try {
50
- const proceed = await plugin.onBeforeTool(this.ctx, call);
51
- if (proceed === false || typeof proceed === "string") {
52
- const pluginName = plugin.name || plugin.constructor?.name || "unknown";
53
- const reason = typeof proceed === "string" ? proceed : undefined;
54
- return {
55
- success: false,
56
- output: reason
57
- ? t("tool.blocked_reason", { plugin: pluginName, reason })
58
- : t("tool.blocked", { plugin: pluginName }),
59
- toolCallId: call.id,
60
- };
61
- }
62
- }
63
- catch (e) {
64
- this.ctx.logger.warn(`Plugin onBeforeTool error: ${e.message}`);
65
- }
66
- }
67
- }
68
- let result;
69
- try {
70
- this.ctx.activeCallId = call.id;
71
- if (tool.interactive) {
72
- // Interactive tools wait for user input — no timeout.
73
- result = await tool.handler(this.ctx, call.arguments);
74
- }
75
- else {
76
- const timeoutMs = tool.timeoutMs ?? TOOL_EXECUTION_TIMEOUT_MS;
77
- const timeoutPromise = new Promise((_, reject) => {
78
- setTimeout(() => {
79
- // Kill any long-running child process registered for this call.
80
- killByCallId(call.id);
81
- reject(new Error(t("tool.timeout", {
82
- name: call.name,
83
- seconds: Math.round(timeoutMs / 1000),
84
- })));
85
- }, timeoutMs);
86
- });
87
- const racePromises = [
88
- tool.handler(this.ctx, call.arguments),
89
- timeoutPromise,
90
- ];
91
- if (signal) {
92
- const abortPromise = new Promise((_, reject) => {
93
- const onAbort = () => {
94
- killByCallId(call.id);
95
- reject(new Error(t("tool.aborted", { name: call.name })));
96
- };
97
- if (signal.aborted) {
98
- onAbort();
99
- }
100
- else {
101
- signal.addEventListener("abort", onAbort, { once: true });
102
- }
103
- });
104
- racePromises.push(abortPromise);
105
- }
106
- result = await Promise.race(racePromises);
107
- }
108
- result.toolCallId = call.id;
109
- }
110
- catch (e) {
111
- result = {
112
- success: false,
113
- output: `${t("error.prefix")}${e.message}`,
114
- toolCallId: call.id,
115
- };
116
- }
117
- // After an abort the tool's work is discarded (the agent loop breaks
118
- // without rendering or logging it), so skip the slow post-tool plugins
119
- // (LSP checks, lint, tsc) entirely. When the abort lands mid-plugin the
120
- // signal in the hook context lets the plugin kill its child processes.
121
- if (signal?.aborted) {
122
- this.ctx.logger.debug(`Tool ${call.name}: abort, skipping onAfterTool plugins`);
123
- }
124
- else {
125
- const pluginCtx = signal ? { ...this.ctx, signal } : this.ctx;
126
- for (const plugin of this.pluginManager.getAllPlugins()) {
127
- if (plugin.onAfterTool) {
128
- try {
129
- await plugin.onAfterTool(pluginCtx, call, result);
130
- }
131
- catch (e) {
132
- this.ctx.logger.warn(`Plugin onAfterTool error: ${e.message}`);
133
- }
134
- }
135
- }
136
- }
137
- this.ctx.logger.logToolCall(call.name, JSON.stringify(call.arguments)?.slice(0, 200) ?? "", result.success ? "OK" : `FAIL: ${result.output?.slice(0, 200)}`);
138
- this.ctx.logger.logToolOutput(call.name, result.output ?? "", result.success ? 0 : 1);
139
- this.ctx.logger.debug(`Tool ${call.name}: ${result.success ? "OK" : "FAIL"}`);
140
- return result;
141
- }
142
- getToolDefinitions(tags) {
143
- return this.registry.getAllForLLM(tags);
144
- }
145
- getRegistry() {
146
- return this.registry;
147
- }
148
- setScope(scope) {
149
- this.ctx.scope = scope;
150
- }
151
- updateProvider(provider) {
152
- this.ctx.llmProvider = provider;
153
- }
154
- }