micro-models-agent 0.43.3 → 0.45.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.
Files changed (188) hide show
  1. package/README.md +312 -312
  2. package/bin/mma.mjs +41 -41
  3. package/dist/main.js +333 -66
  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 -333
  8. package/dist/cli/completer.js +0 -168
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -140
  11. package/dist/cli/repl-commands.js +0 -633
  12. package/dist/cli/repl.js +0 -486
  13. package/dist/cli/security-commands.js +0 -166
  14. package/dist/cli/setup.js +0 -249
  15. package/dist/config/config.js +0 -202
  16. package/dist/config/defaults.js +0 -100
  17. package/dist/config/experts.js +0 -15
  18. package/dist/config/index.js +0 -3
  19. package/dist/config/security.js +0 -200
  20. package/dist/config/types.js +0 -1
  21. package/dist/core/agent-moe.js +0 -110
  22. package/dist/core/agent.js +0 -695
  23. package/dist/core/bootstrap.js +0 -337
  24. package/dist/core/index.js +0 -2
  25. package/dist/core/prompt-builder.js +0 -55
  26. package/dist/core/session-logger.js +0 -155
  27. package/dist/core/types.js +0 -1
  28. package/dist/core/workspace.js +0 -76
  29. package/dist/i18n/en.json +0 -525
  30. package/dist/i18n/index.js +0 -46
  31. package/dist/i18n/ru.json +0 -525
  32. package/dist/index.js +0 -22
  33. package/dist/llm/image-utils.js +0 -144
  34. package/dist/llm/index.js +0 -4
  35. package/dist/llm/model-loader.js +0 -78
  36. package/dist/llm/openai-compat.js +0 -353
  37. package/dist/llm/orchestrator.js +0 -194
  38. package/dist/llm/provider.js +0 -10
  39. package/dist/llm/response.js +0 -39
  40. package/dist/llm/token-counter.js +0 -39
  41. package/dist/llm/types.js +0 -1
  42. package/dist/logger/app-logger.js +0 -143
  43. package/dist/logger/file-log.js +0 -151
  44. package/dist/logger/index.js +0 -1
  45. package/dist/migration/backup.js +0 -45
  46. package/dist/migration/detect.js +0 -50
  47. package/dist/migration/index.js +0 -2
  48. package/dist/modules/browser/actions.js +0 -46
  49. package/dist/modules/browser/cookie-store.js +0 -24
  50. package/dist/modules/browser/index.js +0 -5
  51. package/dist/modules/browser/module.js +0 -28
  52. package/dist/modules/browser/session.js +0 -335
  53. package/dist/modules/browser/snapshot.js +0 -114
  54. package/dist/modules/browser/types.js +0 -9
  55. package/dist/modules/certification/cli.js +0 -176
  56. package/dist/modules/certification/fact-checker.js +0 -84
  57. package/dist/modules/certification/loader.js +0 -111
  58. package/dist/modules/certification/manifest.js +0 -50
  59. package/dist/modules/certification/runner.js +0 -162
  60. package/dist/modules/certification/scenarios.js +0 -124
  61. package/dist/modules/certification/types.js +0 -1
  62. package/dist/modules/context/index.js +0 -1
  63. package/dist/modules/context/manager.js +0 -349
  64. package/dist/modules/execution/auditor.js +0 -66
  65. package/dist/modules/execution/index.js +0 -8
  66. package/dist/modules/execution/module.js +0 -779
  67. package/dist/modules/execution/moe-executor.js +0 -266
  68. package/dist/modules/execution/plan-coverage.js +0 -68
  69. package/dist/modules/execution/plan-persister.js +0 -46
  70. package/dist/modules/execution/plan-store.js +0 -159
  71. package/dist/modules/execution/plan-validator.js +0 -153
  72. package/dist/modules/execution/planner.js +0 -85
  73. package/dist/modules/execution/stuck-detector.js +0 -347
  74. package/dist/modules/execution/tracker.js +0 -67
  75. package/dist/modules/execution/types.js +0 -1
  76. package/dist/modules/execution/verifier.js +0 -178
  77. package/dist/modules/hallucination/confidence.js +0 -59
  78. package/dist/modules/hallucination/consistency.js +0 -26
  79. package/dist/modules/hallucination/detector.js +0 -46
  80. package/dist/modules/hallucination/factual.js +0 -190
  81. package/dist/modules/hallucination/index.js +0 -5
  82. package/dist/modules/hallucination/js-identifiers.js +0 -72
  83. package/dist/modules/hallucination/llm-judge.js +0 -103
  84. package/dist/modules/index.js +0 -5
  85. package/dist/modules/indexer/cache.js +0 -38
  86. package/dist/modules/indexer/index.js +0 -3
  87. package/dist/modules/indexer/module.js +0 -192
  88. package/dist/modules/indexer/walker.js +0 -101
  89. package/dist/modules/lsp/client.js +0 -235
  90. package/dist/modules/lsp/config.js +0 -81
  91. package/dist/modules/lsp/index.js +0 -3
  92. package/dist/modules/lsp/module.js +0 -68
  93. package/dist/modules/lsp/types.js +0 -1
  94. package/dist/modules/mcp/client.js +0 -399
  95. package/dist/modules/mcp/index.js +0 -3
  96. package/dist/modules/mcp/module.js +0 -146
  97. package/dist/modules/mcp/registry.js +0 -15
  98. package/dist/modules/memory/index.js +0 -1
  99. package/dist/modules/memory/module.js +0 -48
  100. package/dist/modules/memory/search.js +0 -40
  101. package/dist/modules/memory/store.js +0 -69
  102. package/dist/modules/pipelines/engine.js +0 -60
  103. package/dist/modules/pipelines/index.js +0 -3
  104. package/dist/modules/pipelines/parser.js +0 -53
  105. package/dist/modules/pipelines/template.js +0 -14
  106. package/dist/modules/plugins/builtin/lint-on-write.js +0 -226
  107. package/dist/modules/plugins/builtin/notify.js +0 -8
  108. package/dist/modules/plugins/index.js +0 -1
  109. package/dist/modules/plugins/loader.js +0 -28
  110. package/dist/modules/plugins/manager.js +0 -161
  111. package/dist/modules/plugins/types.js +0 -1
  112. package/dist/modules/processes/index.js +0 -2
  113. package/dist/modules/processes/registry.js +0 -238
  114. package/dist/modules/processes/runner.js +0 -23
  115. package/dist/modules/registry.js +0 -45
  116. package/dist/modules/security/audit-log.js +0 -136
  117. package/dist/modules/security/audit-notifier.js +0 -292
  118. package/dist/modules/security/command-validator.js +0 -211
  119. package/dist/modules/security/content-scanner.js +0 -53
  120. package/dist/modules/security/data-sanitizer.js +0 -97
  121. package/dist/modules/security/encryption.js +0 -240
  122. package/dist/modules/security/index.js +0 -14
  123. package/dist/modules/security/network-validator.js +0 -79
  124. package/dist/modules/security/path-validator.js +0 -209
  125. package/dist/modules/security/rate-limiter.js +0 -119
  126. package/dist/modules/security/security-policies.js +0 -547
  127. package/dist/modules/security/session-encryption.js +0 -210
  128. package/dist/modules/security/session-isolation.js +0 -95
  129. package/dist/modules/session/index.js +0 -3
  130. package/dist/modules/session/manager.js +0 -172
  131. package/dist/modules/session/module.js +0 -24
  132. package/dist/modules/session/store.js +0 -228
  133. package/dist/modules/session/types.js +0 -1
  134. package/dist/modules/skills/index.js +0 -2
  135. package/dist/modules/skills/loader.js +0 -72
  136. package/dist/modules/skills/module.js +0 -130
  137. package/dist/modules/types.js +0 -1
  138. package/dist/modules/updater/checker.js +0 -32
  139. package/dist/modules/updater/index.js +0 -1
  140. package/dist/modules/user-profile/compressor.js +0 -16
  141. package/dist/modules/user-profile/index.js +0 -1
  142. package/dist/modules/user-profile/profile.js +0 -68
  143. package/dist/tools/approve.js +0 -32
  144. package/dist/tools/attach-image.js +0 -89
  145. package/dist/tools/bash.js +0 -337
  146. package/dist/tools/browser.js +0 -97
  147. package/dist/tools/create-dir.js +0 -55
  148. package/dist/tools/delete-file.js +0 -62
  149. package/dist/tools/edit-file.js +0 -79
  150. package/dist/tools/executor.js +0 -145
  151. package/dist/tools/file-info.js +0 -45
  152. package/dist/tools/filter-tools.js +0 -10
  153. package/dist/tools/glob-tool.js +0 -26
  154. package/dist/tools/grep-tool.js +0 -86
  155. package/dist/tools/index.js +0 -67
  156. package/dist/tools/list-dir.js +0 -47
  157. package/dist/tools/load-skill.js +0 -44
  158. package/dist/tools/mcp-call.js +0 -68
  159. package/dist/tools/move-file.js +0 -85
  160. package/dist/tools/path-utils.js +0 -51
  161. package/dist/tools/pipeline-run.js +0 -144
  162. package/dist/tools/preview.js +0 -2
  163. package/dist/tools/process-kill.js +0 -29
  164. package/dist/tools/process-list.js +0 -38
  165. package/dist/tools/process-log.js +0 -41
  166. package/dist/tools/question.js +0 -142
  167. package/dist/tools/read-file.js +0 -83
  168. package/dist/tools/recall.js +0 -110
  169. package/dist/tools/registry.js +0 -36
  170. package/dist/tools/remember.js +0 -67
  171. package/dist/tools/scope-check.js +0 -30
  172. package/dist/tools/search-history.js +0 -84
  173. package/dist/tools/subagent.js +0 -151
  174. package/dist/tools/types.js +0 -1
  175. package/dist/tools/user-input.js +0 -123
  176. package/dist/tools/web-browse.js +0 -86
  177. package/dist/tools/web-fetch.js +0 -98
  178. package/dist/tools/web-search.js +0 -78
  179. package/dist/tools/write-file.js +0 -83
  180. package/dist/ui/box.js +0 -81
  181. package/dist/ui/colors.js +0 -4
  182. package/dist/ui/diff.js +0 -178
  183. package/dist/ui/index.js +0 -6
  184. package/dist/ui/md-formatter.js +0 -212
  185. package/dist/ui/output.js +0 -13
  186. package/dist/ui/renderer.js +0 -204
  187. package/dist/ui/spinner.js +0 -70
  188. package/dist/ui/table.js +0 -144
@@ -1,145 +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 ||
53
- plugin.constructor?.name ||
54
- "unknown";
55
- const reason = typeof proceed === "string" ? proceed : undefined;
56
- return {
57
- success: false,
58
- output: reason
59
- ? t("tool.blocked_reason", { plugin: pluginName, reason })
60
- : t("tool.blocked", { plugin: pluginName }),
61
- toolCallId: call.id,
62
- };
63
- }
64
- }
65
- catch (e) {
66
- this.ctx.logger.warn(`Plugin onBeforeTool error: ${e.message}`);
67
- }
68
- }
69
- }
70
- let result;
71
- try {
72
- this.ctx.activeCallId = call.id;
73
- if (tool.interactive) {
74
- // Interactive tools wait for user input — no timeout.
75
- result = await tool.handler(this.ctx, call.arguments);
76
- }
77
- else {
78
- const timeoutPromise = new Promise((_, reject) => {
79
- setTimeout(() => {
80
- // Kill any long-running child process registered for this call.
81
- killByCallId(call.id);
82
- reject(new Error(t("tool.timeout", {
83
- name: call.name,
84
- seconds: TOOL_EXECUTION_TIMEOUT_MS / 1000,
85
- })));
86
- }, TOOL_EXECUTION_TIMEOUT_MS);
87
- });
88
- const racePromises = [
89
- tool.handler(this.ctx, call.arguments),
90
- timeoutPromise,
91
- ];
92
- if (signal) {
93
- const abortPromise = new Promise((_, reject) => {
94
- const onAbort = () => {
95
- killByCallId(call.id);
96
- reject(new Error(t("tool.aborted", { name: call.name })));
97
- };
98
- if (signal.aborted) {
99
- onAbort();
100
- }
101
- else {
102
- signal.addEventListener("abort", onAbort, { once: true });
103
- }
104
- });
105
- racePromises.push(abortPromise);
106
- }
107
- result = await Promise.race(racePromises);
108
- }
109
- result.toolCallId = call.id;
110
- }
111
- catch (e) {
112
- result = {
113
- success: false,
114
- output: `${t("error.prefix")}${e.message}`,
115
- toolCallId: call.id,
116
- };
117
- }
118
- for (const plugin of this.pluginManager.getAllPlugins()) {
119
- if (plugin.onAfterTool) {
120
- try {
121
- await plugin.onAfterTool(this.ctx, call, result);
122
- }
123
- catch (e) {
124
- this.ctx.logger.warn(`Plugin onAfterTool error: ${e.message}`);
125
- }
126
- }
127
- }
128
- this.ctx.logger.logToolCall(call.name, JSON.stringify(call.arguments)?.slice(0, 200) ?? "", result.success ? "OK" : `FAIL: ${result.output?.slice(0, 200)}`);
129
- this.ctx.logger.logToolOutput(call.name, result.output ?? "", result.success ? 0 : 1);
130
- this.ctx.logger.debug(`Tool ${call.name}: ${result.success ? "OK" : "FAIL"}`);
131
- return result;
132
- }
133
- getToolDefinitions(tags) {
134
- return this.registry.getAllForLLM(tags);
135
- }
136
- getRegistry() {
137
- return this.registry;
138
- }
139
- setScope(scope) {
140
- this.ctx.scope = scope;
141
- }
142
- updateProvider(provider) {
143
- this.ctx.llmProvider = provider;
144
- }
145
- }
@@ -1,45 +0,0 @@
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
- export const fileInfoTool = {
6
- name: 'file_info',
7
- description: 'Get metadata about a file or directory (size, creation date, modification date).',
8
- tags: ['file'],
9
- parameters: {
10
- type: 'object',
11
- properties: {
12
- path: { type: 'string', description: 'File path' },
13
- },
14
- required: ['path'],
15
- },
16
- handler: async (ctx, args) => {
17
- const path = String(args.path);
18
- const resolved = safeResolvePath(ctx.baseDir, path);
19
- // Check path permissions
20
- const scopeCheck = isPathInScope(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
21
- if (!scopeCheck.allowed) {
22
- return {
23
- success: false,
24
- output: t('file.path_not_allowed', {
25
- path: `${path} — ${scopeCheck.reason}`,
26
- }),
27
- };
28
- }
29
- if (!existsSync(resolved)) {
30
- return { success: false, output: t('file.not_found_short', { path }) };
31
- }
32
- const stat = statSync(resolved);
33
- return {
34
- success: true,
35
- output: JSON.stringify({
36
- path,
37
- size: stat.size,
38
- isDirectory: stat.isDirectory(),
39
- isFile: stat.isFile(),
40
- created: stat.birthtime,
41
- modified: stat.mtime,
42
- }, null, 2),
43
- };
44
- },
45
- };
@@ -1,10 +0,0 @@
1
- export function filterToolsByTags(tools, toolTags) {
2
- if (!toolTags || toolTags.length === 0)
3
- return tools;
4
- const tagSet = new Set(toolTags);
5
- return tools.filter(t => {
6
- if (!t.tags || t.tags.length === 0)
7
- return false;
8
- return t.tags.some(tag => tagSet.has(tag));
9
- });
10
- }
@@ -1,26 +0,0 @@
1
- import { globSync } from 'fs';
2
- import { t } from '../i18n/index';
3
- import { MAX_PREVIEW_LINES } from './preview';
4
- export const globTool = {
5
- name: 'glob',
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: ['file', 'code', 'research'],
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- pattern: { type: 'string', description: 'Glob pattern' },
12
- },
13
- required: ['pattern'],
14
- },
15
- handler: async (ctx, args) => {
16
- const pattern = String(args.pattern);
17
- const results = globSync(pattern, { cwd: ctx.baseDir });
18
- if (results.length === 0) {
19
- return { success: true, output: t('file.no_matches') };
20
- }
21
- const truncated = results.length > MAX_PREVIEW_LINES
22
- ? `\n... (${results.length - MAX_PREVIEW_LINES} more files)`
23
- : '';
24
- return { success: true, output: results.slice(0, MAX_PREVIEW_LINES).join('\n') + truncated };
25
- },
26
- };
@@ -1,86 +0,0 @@
1
- import { execFileSync } from "child_process";
2
- import { resolve } from "path";
3
- import { t } from "../i18n/index";
4
- import { logBashCommand } from "../modules/security/audit-log";
5
- import { MAX_PREVIEW_LINES } from "./preview";
6
- function truncateLines(output) {
7
- const lines = output.split("\n");
8
- if (lines.length <= MAX_PREVIEW_LINES)
9
- return output;
10
- return (lines.slice(0, MAX_PREVIEW_LINES).join("\n") +
11
- `\n... (${lines.length - MAX_PREVIEW_LINES} more lines)`);
12
- }
13
- export const grepTool = {
14
- name: "grep",
15
- description: `Search file contents using a regular expression. Shows up to ${MAX_PREVIEW_LINES} matching lines by default. Uses ripgrep (rg) if available, otherwise falls back to grep -r.`,
16
- tags: ["file", "code", "research"],
17
- parameters: {
18
- type: "object",
19
- properties: {
20
- pattern: { type: "string", description: "Regex pattern to search" },
21
- include: {
22
- type: "string",
23
- description: "File pattern to filter (e.g. *.ts)",
24
- },
25
- path: {
26
- type: "string",
27
- description: "Directory to search (defaults to baseDir)",
28
- },
29
- },
30
- required: ["pattern"],
31
- },
32
- handler: async (ctx, args) => {
33
- const pattern = String(args.pattern);
34
- const searchPath = args.path
35
- ? resolve(ctx.baseDir, String(args.path))
36
- : ctx.baseDir;
37
- // Build rg arguments as an array to avoid shell interpretation of regex
38
- // metacharacters like |, (, ) — these are regex patterns, not shell operators.
39
- const rgArgs = ["-n", "--with-filename", pattern, searchPath];
40
- if (args.include) {
41
- rgArgs.push("-g", String(args.include));
42
- }
43
- // Log the search (sanitized) for audit purposes
44
- logBashCommand(ctx.sessionId, `rg ${rgArgs.join(" ")}`, false, "grep-tool");
45
- try {
46
- const output = execFileSync("rg", rgArgs, {
47
- encoding: "utf-8",
48
- maxBuffer: 1024 * 1024,
49
- cwd: ctx.baseDir,
50
- });
51
- return {
52
- success: true,
53
- output: truncateLines(output || t("file.no_matches")),
54
- };
55
- }
56
- catch (e) {
57
- if (e.status === 1)
58
- return { success: true, output: t("file.no_matches") };
59
- // Fall back to plain grep -r when rg is not available or fails.
60
- // Using execFileSync with array args avoids shell injection.
61
- try {
62
- const grepArgs = ["-rn", pattern, searchPath];
63
- if (args.include) {
64
- grepArgs.push("--include", String(args.include));
65
- }
66
- const output = execFileSync("grep", grepArgs, {
67
- encoding: "utf-8",
68
- maxBuffer: 1024 * 1024,
69
- cwd: ctx.baseDir,
70
- });
71
- return {
72
- success: true,
73
- output: truncateLines(output || t("file.no_matches")),
74
- };
75
- }
76
- catch (e2) {
77
- if (e2.status === 1)
78
- return { success: true, output: t("file.no_matches") };
79
- return {
80
- success: false,
81
- output: t("error.grep_failed", { message: e2.message }),
82
- };
83
- }
84
- }
85
- },
86
- };
@@ -1,67 +0,0 @@
1
- import { ToolRegistry } from "./registry";
2
- import { ToolExecutor } from "./executor";
3
- import { readFileTool } from "./read-file";
4
- import { writeFileTool } from "./write-file";
5
- import { editFileTool } from "./edit-file";
6
- import { globTool } from "./glob-tool";
7
- import { grepTool } from "./grep-tool";
8
- import { listDirTool } from "./list-dir";
9
- import { createDirTool } from "./create-dir";
10
- import { deleteFileTool } from "./delete-file";
11
- import { moveFileTool } from "./move-file";
12
- import { fileInfoTool } from "./file-info";
13
- import { bashTool } from "./bash";
14
- import { processListTool } from "./process-list";
15
- import { processLogTool } from "./process-log";
16
- import { processKillTool } from "./process-kill";
17
- import { subagentTool } from "./subagent";
18
- import { webSearchTool } from "./web-search";
19
- import { webFetchTool } from "./web-fetch";
20
- import { webBrowseTool } from "./web-browse";
21
- // questionTool and approveTool removed — interactive menus are too disruptive for small models.
22
- // The model should ask questions as plain text in its response instead.
23
- // import { questionTool } from './question'
24
- // import { approveTool } from './approve'
25
- import { createLoadSkillTool } from "./load-skill";
26
- import { pipelineRunTool } from "./pipeline-run";
27
- import { mcpCallTool } from "./mcp-call";
28
- import { searchHistoryTool } from "./search-history";
29
- import { rememberTool } from "./remember";
30
- import { recallTool } from "./recall";
31
- import { createBrowserTool } from "./browser";
32
- import { attachImageTool } from "./attach-image";
33
- export { ToolRegistry, ToolExecutor };
34
- 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) {
37
- const tools = [
38
- readFileTool,
39
- writeFileTool,
40
- editFileTool,
41
- globTool,
42
- grepTool,
43
- listDirTool,
44
- createDirTool,
45
- deleteFileTool,
46
- moveFileTool,
47
- fileInfoTool,
48
- bashTool,
49
- subagentTool,
50
- processListTool,
51
- processLogTool,
52
- processKillTool,
53
- webSearchTool,
54
- webFetchTool,
55
- webBrowseTool,
56
- pipelineRunTool,
57
- mcpCallTool,
58
- searchHistoryTool,
59
- attachImageTool,
60
- ];
61
- if (skillsModule) {
62
- tools.push(createLoadSkillTool(skillsModule));
63
- }
64
- for (const tool of tools) {
65
- registry.register(tool);
66
- }
67
- }
@@ -1,47 +0,0 @@
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
- export const listDirTool = {
8
- name: 'list_dir',
9
- description: `List files and directories in a given path. Shows up to ${MAX_PREVIEW_LINES} entries by default.`,
10
- tags: ['file'],
11
- parameters: {
12
- type: 'object',
13
- properties: {
14
- path: { type: 'string', description: 'Directory path' },
15
- },
16
- required: ['path'],
17
- },
18
- handler: async (ctx, args) => {
19
- const path = String(args.path);
20
- const resolved = safeResolvePath(ctx.baseDir, path);
21
- // Check path permissions
22
- const scopeCheck = isPathInScope(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
23
- if (!scopeCheck.allowed) {
24
- return {
25
- success: false,
26
- output: t('file.path_not_allowed', {
27
- path: `${path} — ${scopeCheck.reason}`,
28
- }),
29
- };
30
- }
31
- if (!existsSync(resolved)) {
32
- return { success: false, output: t('file.dir_notfound', { path }) };
33
- }
34
- const entries = readdirSync(resolved);
35
- const lines = entries.map(e => {
36
- const full = resolve(resolved, e);
37
- return statSync(full).isDirectory() ? `${e}/` : e;
38
- });
39
- if (lines.length === 0) {
40
- return { success: true, output: t('file.empty') };
41
- }
42
- const truncated = lines.length > MAX_PREVIEW_LINES
43
- ? `\n... (${lines.length - MAX_PREVIEW_LINES} more entries)`
44
- : '';
45
- return { success: true, output: lines.slice(0, MAX_PREVIEW_LINES).join('\n') + truncated };
46
- },
47
- };
@@ -1,44 +0,0 @@
1
- import { t } from "../i18n/index";
2
- export function createLoadSkillTool(skillsModule) {
3
- return {
4
- name: "load_skill",
5
- tags: ["core"],
6
- description: "Load a skill by name. Skills provide specialized instructions and workflows. When loaded, the skill content is injected into the system prompt (not conversation history) so it persists through context compaction. Only use when the task clearly requires domain-specific knowledge.",
7
- parameters: {
8
- type: "object",
9
- properties: {
10
- name: {
11
- type: "string",
12
- description: "Exact skill name to load (see [Available Skills] for names)",
13
- },
14
- },
15
- required: ["name"],
16
- },
17
- handler: async (_ctx, args) => {
18
- const name = args.name ? String(args.name) : undefined;
19
- if (!name) {
20
- return { success: false, output: t("tool.invalid_params") };
21
- }
22
- const result = skillsModule.loadByName(name);
23
- if (!result.success) {
24
- const available = skillsModule.getAvailable();
25
- const hint = available.length > 0
26
- ? `\n\n${t("tool.skill_available_hint")}: ${available.map((s) => s.name).join(", ")}`
27
- : "";
28
- return { success: false, output: result.message + hint };
29
- }
30
- const budget = skillsModule.getBudget();
31
- const tokens = result.skill
32
- ? Math.ceil(result.skill.content.length / 4)
33
- : 0;
34
- return {
35
- success: true,
36
- output: t("tool.skill_budget", {
37
- name,
38
- tokens,
39
- remaining: budget.remaining,
40
- }),
41
- };
42
- },
43
- };
44
- }
@@ -1,68 +0,0 @@
1
- import { MCPClient } from "../modules/mcp/client";
2
- import { MCPRegistry } from "../modules/mcp/registry";
3
- const registry = new MCPRegistry();
4
- let initialized = false;
5
- function ensureInitialized(ctx) {
6
- if (initialized)
7
- return;
8
- initialized = true;
9
- const servers = ctx.config.mcpServers || {};
10
- for (const [name, cfg] of Object.entries(servers)) {
11
- if (cfg.enabled !== false) {
12
- registry.register({
13
- name: cfg.name || name,
14
- command: cfg.command,
15
- args: cfg.args,
16
- env: cfg.env,
17
- transport: cfg.transport,
18
- url: cfg.url,
19
- headers: cfg.headers,
20
- timeout: cfg.timeout,
21
- });
22
- }
23
- }
24
- }
25
- export const mcpCallTool = {
26
- name: "mcp_call",
27
- description: "Call a tool on an MCP (Model Context Protocol) server. MCP servers provide external capabilities like databases, APIs, or specialized tools.",
28
- tags: ["code", "research"],
29
- parameters: {
30
- type: "object",
31
- properties: {
32
- server: { type: "string", description: "MCP server name" },
33
- tool: { type: "string", description: "Tool name on the server" },
34
- args: { type: "object", description: "Arguments to pass to the tool" },
35
- },
36
- required: ["server", "tool"],
37
- },
38
- handler: async (ctx, args) => {
39
- const serverName = String(args.server || "");
40
- const toolName = String(args.tool || "");
41
- const toolArgs = (args.args || {});
42
- if (!serverName || !toolName) {
43
- return { success: false, output: "Server and tool names are required" };
44
- }
45
- ensureInitialized(ctx);
46
- const serverConfig = registry.get(serverName);
47
- if (!serverConfig) {
48
- const available = registry.list();
49
- return {
50
- success: false,
51
- output: `MCP server "${serverName}" not found. Available: ${available.join(", ") || "(none)"}`,
52
- };
53
- }
54
- try {
55
- const client = new MCPClient(serverConfig);
56
- await client.connect();
57
- const result = await client.callTool(toolName, toolArgs);
58
- await client.disconnect();
59
- return {
60
- success: true,
61
- output: `MCP call result:\n${JSON.stringify(result, null, 2)}`,
62
- };
63
- }
64
- catch (e) {
65
- return { success: false, output: `MCP call failed: ${e.message}` };
66
- }
67
- },
68
- };
@@ -1,85 +0,0 @@
1
- import { renameSync, existsSync, mkdirSync } from "fs";
2
- import { resolve, normalize, dirname } from "path";
3
- import { t } from "../i18n/index";
4
- import { isPathWritable } from "../modules/security/path-validator";
5
- import { logFileWrite, logSecurityBlock } from "../modules/security/audit-log";
6
- import { getSessionSecurityConfig } from "../modules/security/session-isolation";
7
- import { generateMoveDiff } from "../ui/diff";
8
- import { safeResolvePath } from "./path-utils";
9
- export const moveFileTool = {
10
- name: "move_file",
11
- description: "Move or rename a file or directory.",
12
- tags: ["file"],
13
- parameters: {
14
- type: "object",
15
- properties: {
16
- from: { type: "string", description: "Source path" },
17
- to: { type: "string", description: "Destination path" },
18
- },
19
- required: ["from", "to"],
20
- },
21
- handler: async (ctx, args) => {
22
- const fromPath = String(args.from);
23
- const toPath = String(args.to);
24
- const baseDir = resolve(ctx.baseDir);
25
- const fromResolved = safeResolvePath(baseDir, normalize(fromPath));
26
- const toResolved = safeResolvePath(baseDir, normalize(toPath));
27
- // Get session-specific security config
28
- const securityConfig = ctx.sessionContext
29
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
30
- : ctx.config.security;
31
- // Check file operations limit
32
- const maxFileOps = securityConfig?.maxFileOperations ?? 100;
33
- const currentCount = ctx.fileOperationsCount ?? 0;
34
- if (currentCount >= maxFileOps) {
35
- logSecurityBlock(ctx.sessionId, "file_write", `Maximum file operations (${maxFileOps}) exceeded`, `${fromPath} -> ${toPath}`);
36
- return {
37
- success: false,
38
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
39
- };
40
- }
41
- // Check source path permissions
42
- const fromCheck = isPathWritable(ctx.baseDir, fromPath, ctx.scope, ctx.config.security?.paths);
43
- if (!fromCheck.allowed) {
44
- logSecurityBlock(ctx.sessionId, "file_write", fromCheck.reason || "Source path not allowed", fromPath);
45
- return {
46
- success: false,
47
- output: t("file.path_not_allowed", {
48
- path: `${fromPath} — ${fromCheck.reason}`,
49
- }),
50
- };
51
- }
52
- // Check destination path permissions
53
- const toCheck = isPathWritable(ctx.baseDir, toPath, ctx.scope, ctx.config.security?.paths);
54
- if (!toCheck.allowed) {
55
- logSecurityBlock(ctx.sessionId, "file_write", toCheck.reason || "Destination path not allowed", toPath);
56
- return {
57
- success: false,
58
- output: t("file.path_not_allowed", {
59
- path: `${toPath} — ${toCheck.reason}`,
60
- }),
61
- };
62
- }
63
- if (!existsSync(fromResolved)) {
64
- return {
65
- success: false,
66
- output: t("file.not_found_short", { path: fromPath }),
67
- };
68
- }
69
- const toDir = dirname(toResolved);
70
- if (!existsSync(toDir)) {
71
- mkdirSync(toDir, { recursive: true });
72
- }
73
- renameSync(fromResolved, toResolved);
74
- const diff = generateMoveDiff(fromPath, toPath);
75
- // Increment file operations counter
76
- ctx.fileOperationsCount = currentCount + 1;
77
- // Log file move
78
- logFileWrite(ctx.sessionId, `${fromPath} -> ${toPath}`, true, "File moved");
79
- return {
80
- success: true,
81
- output: t("file.moved", { from: fromPath, to: toPath }),
82
- diff,
83
- };
84
- },
85
- };
@@ -1,51 +0,0 @@
1
- import { resolve, normalize, dirname, basename, sep } from 'path';
2
- import { existsSync } from 'fs';
3
- /**
4
- * Resolve a user-provided path against baseDir.
5
- *
6
- * Handles common model mistakes:
7
- * 1. Leading slash: "/testing/cat3" → resolve relative to baseDir
8
- * 2. Missing separator: "E:\agent_test" when baseDir is "E:\agent\_test"
9
- * → inserts the missing backslash
10
- *
11
- * For new files the parent directory must exist; we check that instead of
12
- * the full path so write_file still works.
13
- */
14
- export function safeResolvePath(baseDir, userPath) {
15
- const norm = normalize(userPath);
16
- const stripped = norm.replace(/^[/\\]/, '');
17
- const resolved = resolve(baseDir, stripped);
18
- // Fast path: if it exists (or parent does for new files), return it
19
- if (existsSync(resolved) || existsSync(dirname(resolved)))
20
- return resolved;
21
- const baseNorm = normalize(baseDir);
22
- // Walk ancestors and look for missing separators
23
- let cur = baseNorm;
24
- while (cur && cur !== dirname(cur)) {
25
- const name = basename(cur);
26
- if (!name) {
27
- cur = dirname(cur);
28
- continue;
29
- }
30
- let idx = stripped.toLowerCase().indexOf(name.toLowerCase());
31
- while (idx >= 0) {
32
- const afterIdx = idx + name.length;
33
- const afterChar = stripped[afterIdx];
34
- if (afterChar && afterChar !== '\\' && afterChar !== '/') {
35
- const fixed = stripped.slice(0, afterIdx) + sep + stripped.slice(afterIdx);
36
- const fixedResolved = resolve(baseDir, normalize(fixed));
37
- if (existsSync(fixedResolved) || existsSync(dirname(fixedResolved))) {
38
- return fixedResolved;
39
- }
40
- // Try from ancestor's parent
41
- const fromParent = resolve(dirname(cur), normalize(fixed));
42
- if (existsSync(fromParent) || existsSync(dirname(fromParent))) {
43
- return fromParent;
44
- }
45
- }
46
- idx = stripped.toLowerCase().indexOf(name.toLowerCase(), idx + 1);
47
- }
48
- cur = dirname(cur);
49
- }
50
- return resolved;
51
- }