micro-models-agent 0.19.0 → 0.19.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.
Files changed (168) hide show
  1. package/dist/main.js +179 -358
  2. package/package.json +1 -1
  3. package/dist/cli/commands.js +0 -237
  4. package/dist/cli/completer.js +0 -168
  5. package/dist/cli/index.js +0 -2
  6. package/dist/cli/main.js +0 -113
  7. package/dist/cli/repl.js +0 -1010
  8. package/dist/cli/security-commands.js +0 -166
  9. package/dist/cli/setup.js +0 -229
  10. package/dist/config/config.js +0 -186
  11. package/dist/config/defaults.js +0 -91
  12. package/dist/config/experts.js +0 -15
  13. package/dist/config/index.js +0 -3
  14. package/dist/config/security.js +0 -193
  15. package/dist/config/types.js +0 -1
  16. package/dist/core/agent-moe.js +0 -98
  17. package/dist/core/agent.js +0 -471
  18. package/dist/core/bootstrap.js +0 -314
  19. package/dist/core/index.js +0 -2
  20. package/dist/core/prompt-builder.js +0 -55
  21. package/dist/core/session-logger.js +0 -122
  22. package/dist/core/types.js +0 -1
  23. package/dist/i18n/en.json +0 -461
  24. package/dist/i18n/index.js +0 -43
  25. package/dist/i18n/ru.json +0 -461
  26. package/dist/index.js +0 -22
  27. package/dist/llm/image-utils.js +0 -144
  28. package/dist/llm/index.js +0 -4
  29. package/dist/llm/model-loader.js +0 -78
  30. package/dist/llm/openai-compat.js +0 -324
  31. package/dist/llm/orchestrator.js +0 -194
  32. package/dist/llm/provider.js +0 -10
  33. package/dist/llm/response.js +0 -39
  34. package/dist/llm/token-counter.js +0 -39
  35. package/dist/llm/types.js +0 -1
  36. package/dist/logger/app-logger.js +0 -76
  37. package/dist/logger/index.js +0 -1
  38. package/dist/migration/backup.js +0 -45
  39. package/dist/migration/detect.js +0 -50
  40. package/dist/migration/index.js +0 -2
  41. package/dist/modules/browser/actions.js +0 -46
  42. package/dist/modules/browser/cookie-store.js +0 -24
  43. package/dist/modules/browser/index.js +0 -5
  44. package/dist/modules/browser/module.js +0 -28
  45. package/dist/modules/browser/session.js +0 -287
  46. package/dist/modules/browser/snapshot.js +0 -114
  47. package/dist/modules/browser/types.js +0 -9
  48. package/dist/modules/context/index.js +0 -1
  49. package/dist/modules/context/manager.js +0 -240
  50. package/dist/modules/execution/auditor.js +0 -72
  51. package/dist/modules/execution/index.js +0 -6
  52. package/dist/modules/execution/module.js +0 -337
  53. package/dist/modules/execution/moe-executor.js +0 -209
  54. package/dist/modules/execution/plan-validator.js +0 -153
  55. package/dist/modules/execution/planner.js +0 -35
  56. package/dist/modules/execution/stuck-detector.js +0 -134
  57. package/dist/modules/execution/tracker.js +0 -53
  58. package/dist/modules/execution/types.js +0 -1
  59. package/dist/modules/execution/verifier.js +0 -149
  60. package/dist/modules/hallucination/confidence.js +0 -59
  61. package/dist/modules/hallucination/consistency.js +0 -66
  62. package/dist/modules/hallucination/detector.js +0 -33
  63. package/dist/modules/hallucination/factual.js +0 -561
  64. package/dist/modules/hallucination/index.js +0 -3
  65. package/dist/modules/index.js +0 -5
  66. package/dist/modules/indexer/cache.js +0 -38
  67. package/dist/modules/indexer/index.js +0 -3
  68. package/dist/modules/indexer/module.js +0 -192
  69. package/dist/modules/indexer/walker.js +0 -101
  70. package/dist/modules/mcp/client.js +0 -393
  71. package/dist/modules/mcp/index.js +0 -3
  72. package/dist/modules/mcp/module.js +0 -146
  73. package/dist/modules/mcp/registry.js +0 -15
  74. package/dist/modules/memory/index.js +0 -1
  75. package/dist/modules/memory/module.js +0 -48
  76. package/dist/modules/memory/search.js +0 -40
  77. package/dist/modules/memory/store.js +0 -65
  78. package/dist/modules/pipelines/engine.js +0 -60
  79. package/dist/modules/pipelines/index.js +0 -3
  80. package/dist/modules/pipelines/parser.js +0 -53
  81. package/dist/modules/pipelines/template.js +0 -14
  82. package/dist/modules/plugins/builtin/lint-on-write.js +0 -121
  83. package/dist/modules/plugins/builtin/notify.js +0 -8
  84. package/dist/modules/plugins/index.js +0 -1
  85. package/dist/modules/plugins/loader.js +0 -28
  86. package/dist/modules/plugins/manager.js +0 -161
  87. package/dist/modules/plugins/types.js +0 -1
  88. package/dist/modules/processes/detect.js +0 -34
  89. package/dist/modules/processes/index.js +0 -3
  90. package/dist/modules/processes/registry.js +0 -148
  91. package/dist/modules/processes/runner.js +0 -124
  92. package/dist/modules/registry.js +0 -45
  93. package/dist/modules/security/audit-log.js +0 -116
  94. package/dist/modules/security/audit-notifier.js +0 -292
  95. package/dist/modules/security/command-validator.js +0 -185
  96. package/dist/modules/security/content-scanner.js +0 -52
  97. package/dist/modules/security/data-sanitizer.js +0 -97
  98. package/dist/modules/security/encryption.js +0 -240
  99. package/dist/modules/security/index.js +0 -14
  100. package/dist/modules/security/network-validator.js +0 -79
  101. package/dist/modules/security/path-validator.js +0 -155
  102. package/dist/modules/security/rate-limiter.js +0 -119
  103. package/dist/modules/security/security-policies.js +0 -393
  104. package/dist/modules/security/session-encryption.js +0 -193
  105. package/dist/modules/security/session-isolation.js +0 -95
  106. package/dist/modules/session/index.js +0 -3
  107. package/dist/modules/session/manager.js +0 -167
  108. package/dist/modules/session/module.js +0 -24
  109. package/dist/modules/session/store.js +0 -174
  110. package/dist/modules/session/types.js +0 -1
  111. package/dist/modules/skills/index.js +0 -3
  112. package/dist/modules/skills/loader.js +0 -72
  113. package/dist/modules/skills/matcher.js +0 -27
  114. package/dist/modules/skills/module.js +0 -143
  115. package/dist/modules/types.js +0 -1
  116. package/dist/modules/updater/checker.js +0 -32
  117. package/dist/modules/updater/index.js +0 -1
  118. package/dist/modules/user-profile/compressor.js +0 -16
  119. package/dist/modules/user-profile/index.js +0 -1
  120. package/dist/modules/user-profile/profile.js +0 -68
  121. package/dist/skills/builtin/builtin/git.md +0 -36
  122. package/dist/skills/builtin/builtin/typescript.md +0 -35
  123. package/dist/tools/approve.js +0 -32
  124. package/dist/tools/attach-image.js +0 -89
  125. package/dist/tools/bash.js +0 -140
  126. package/dist/tools/browser.js +0 -97
  127. package/dist/tools/create-dir.js +0 -55
  128. package/dist/tools/delete-file.js +0 -62
  129. package/dist/tools/edit-file.js +0 -77
  130. package/dist/tools/executor.js +0 -95
  131. package/dist/tools/file-info.js +0 -45
  132. package/dist/tools/filter-tools.js +0 -10
  133. package/dist/tools/glob-tool.js +0 -26
  134. package/dist/tools/grep-tool.js +0 -64
  135. package/dist/tools/index.js +0 -52
  136. package/dist/tools/list-dir.js +0 -47
  137. package/dist/tools/load-skill.js +0 -48
  138. package/dist/tools/mcp-call.js +0 -68
  139. package/dist/tools/move-file.js +0 -84
  140. package/dist/tools/path-utils.js +0 -51
  141. package/dist/tools/pipeline-run.js +0 -144
  142. package/dist/tools/preview.js +0 -2
  143. package/dist/tools/process-kill.js +0 -29
  144. package/dist/tools/process-list.js +0 -38
  145. package/dist/tools/process-log.js +0 -41
  146. package/dist/tools/question.js +0 -142
  147. package/dist/tools/read-file.js +0 -70
  148. package/dist/tools/recall.js +0 -110
  149. package/dist/tools/registry.js +0 -36
  150. package/dist/tools/remember.js +0 -67
  151. package/dist/tools/scope-check.js +0 -30
  152. package/dist/tools/search-history.js +0 -64
  153. package/dist/tools/subagent.js +0 -142
  154. package/dist/tools/types.js +0 -1
  155. package/dist/tools/user-input.js +0 -123
  156. package/dist/tools/web-browse.js +0 -57
  157. package/dist/tools/web-fetch.js +0 -72
  158. package/dist/tools/web-search.js +0 -59
  159. package/dist/tools/write-file.js +0 -79
  160. package/dist/ui/box.js +0 -81
  161. package/dist/ui/colors.js +0 -4
  162. package/dist/ui/diff.js +0 -185
  163. package/dist/ui/index.js +0 -6
  164. package/dist/ui/md-formatter.js +0 -212
  165. package/dist/ui/output.js +0 -13
  166. package/dist/ui/renderer.js +0 -141
  167. package/dist/ui/spinner.js +0 -70
  168. package/dist/ui/table.js +0 -144
@@ -1,77 +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
- description: "Find and replace text in an existing file. Uses exact string match (not regex).",
12
- tags: ["file", "code"],
13
- parameters: {
14
- type: "object",
15
- properties: {
16
- path: { type: "string", description: "File path" },
17
- old: { type: "string", description: "Text to replace" },
18
- new: { type: "string", description: "Replacement text" },
19
- },
20
- required: ["path", "old", "new"],
21
- },
22
- handler: async (ctx, args) => {
23
- const path = String(args.path);
24
- const resolved = safeResolvePath(ctx.baseDir, path);
25
- // Get session-specific security config
26
- const securityConfig = ctx.sessionContext
27
- ? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
28
- : ctx.config.security;
29
- // Check file operations limit
30
- const maxFileOps = securityConfig?.maxFileOperations ?? 100;
31
- const currentCount = ctx.fileOperationsCount ?? 0;
32
- if (currentCount >= maxFileOps) {
33
- logSecurityBlock(ctx.sessionId, "file_write", `Maximum file operations (${maxFileOps}) exceeded`, path);
34
- return {
35
- success: false,
36
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
37
- };
38
- }
39
- // Check path permissions
40
- const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
41
- if (!scopeCheck.allowed) {
42
- logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
43
- return {
44
- success: false,
45
- output: t("file.path_not_allowed", {
46
- path: `${path} — ${scopeCheck.reason}`,
47
- }),
48
- };
49
- }
50
- const content = readFileSync(resolved, "utf-8");
51
- const oldStr = String(args.old);
52
- const newStr = String(args.new);
53
- if (!content.includes(oldStr)) {
54
- return {
55
- success: false,
56
- output: t("file.string_not_found", { str: oldStr }),
57
- };
58
- }
59
- const updated = content.replace(oldStr, newStr);
60
- // Check new content for dangerous patterns
61
- const scanResult = scanContent(updated, path, ctx.config.security?.contentScan);
62
- if (!scanResult.allowed) {
63
- logSecurityBlock(ctx.sessionId, "file_write", scanResult.reason || "Content contains dangerous patterns", path);
64
- return {
65
- success: false,
66
- output: `[SECURITY BLOCKED] ${scanResult.reason}`,
67
- };
68
- }
69
- writeFileSync(resolved, updated, "utf-8");
70
- const diff = generateDiff(content, updated);
71
- // Increment file operations counter
72
- ctx.fileOperationsCount = currentCount + 1;
73
- // Log successful file edit
74
- logFileWrite(ctx.sessionId, path, true, "File edited");
75
- return { success: true, output: t("file.replaced_in", { path }), diff };
76
- },
77
- };
@@ -1,95 +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
- async execute(call) {
14
- const tool = this.registry.get(call.name);
15
- if (!tool) {
16
- return {
17
- success: false,
18
- output: t("tool.unknown", { name: call.name }),
19
- toolCallId: call.id,
20
- };
21
- }
22
- for (const plugin of this.pluginManager.getAllPlugins()) {
23
- if (plugin.onBeforeTool) {
24
- try {
25
- const proceed = await plugin.onBeforeTool(this.ctx, call);
26
- if (!proceed) {
27
- return {
28
- success: false,
29
- output: t("tool.blocked", {
30
- plugin: plugin.constructor?.name || "unknown",
31
- }),
32
- toolCallId: call.id,
33
- };
34
- }
35
- }
36
- catch (e) {
37
- this.ctx.logger.warn(`Plugin onBeforeTool error: ${e.message}`);
38
- }
39
- }
40
- }
41
- let result;
42
- try {
43
- this.ctx.activeCallId = call.id;
44
- if (tool.interactive) {
45
- // Interactive tools wait for user input — no timeout.
46
- result = await tool.handler(this.ctx, call.arguments);
47
- }
48
- else {
49
- const timeoutPromise = new Promise((_, reject) => {
50
- setTimeout(() => {
51
- // Kill any long-running child process registered for this call.
52
- killByCallId(call.id);
53
- reject(new Error(t("tool.timeout", {
54
- name: call.name,
55
- seconds: TOOL_EXECUTION_TIMEOUT_MS / 1000,
56
- })));
57
- }, TOOL_EXECUTION_TIMEOUT_MS);
58
- });
59
- result = await Promise.race([
60
- tool.handler(this.ctx, call.arguments),
61
- timeoutPromise,
62
- ]);
63
- }
64
- result.toolCallId = call.id;
65
- }
66
- catch (e) {
67
- result = {
68
- success: false,
69
- output: `${t("error.prefix")}${e.message}`,
70
- toolCallId: call.id,
71
- };
72
- }
73
- for (const plugin of this.pluginManager.getAllPlugins()) {
74
- if (plugin.onAfterTool) {
75
- try {
76
- await plugin.onAfterTool(this.ctx, call, result);
77
- }
78
- catch (e) {
79
- this.ctx.logger.warn(`Plugin onAfterTool error: ${e.message}`);
80
- }
81
- }
82
- }
83
- this.ctx.logger.debug(`Tool ${call.name}: ${result.success ? "OK" : "FAIL"}`);
84
- return result;
85
- }
86
- getToolDefinitions(tags) {
87
- return this.registry.getAllForLLM(tags);
88
- }
89
- getRegistry() {
90
- return this.registry;
91
- }
92
- setScope(scope) {
93
- this.ctx.scope = scope;
94
- }
95
- }
@@ -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,64 +0,0 @@
1
- import { execFileSync, execSync } 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') + `\n... (${lines.length - MAX_PREVIEW_LINES} more lines)`;
11
- }
12
- export const grepTool = {
13
- name: 'grep',
14
- 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.`,
15
- tags: ['file', 'code', 'research'],
16
- parameters: {
17
- type: 'object',
18
- properties: {
19
- pattern: { type: 'string', description: 'Regex pattern to search' },
20
- include: { type: 'string', description: 'File pattern to filter (e.g. *.ts)' },
21
- path: { type: 'string', description: 'Directory to search (defaults to baseDir)' },
22
- },
23
- required: ['pattern'],
24
- },
25
- handler: async (ctx, args) => {
26
- const pattern = String(args.pattern);
27
- const searchPath = args.path ? resolve(ctx.baseDir, String(args.path)) : ctx.baseDir;
28
- // Build rg arguments as an array to avoid shell interpretation of regex
29
- // metacharacters like |, (, ) — these are regex patterns, not shell operators.
30
- const rgArgs = ['-n', '--with-filename', pattern, searchPath];
31
- if (args.include) {
32
- rgArgs.push('-g', String(args.include));
33
- }
34
- // Log the search (sanitized) for audit purposes
35
- logBashCommand(ctx.sessionId, `rg ${rgArgs.join(' ')}`, false, 'grep-tool');
36
- try {
37
- const output = execFileSync('rg', rgArgs, {
38
- encoding: 'utf-8',
39
- maxBuffer: 1024 * 1024,
40
- cwd: ctx.baseDir,
41
- });
42
- return { success: true, output: truncateLines(output || t('file.no_matches')) };
43
- }
44
- catch (e) {
45
- if (e.status === 1)
46
- return { success: true, output: t('file.no_matches') };
47
- // Fall back to plain grep -r when rg is not available or fails
48
- try {
49
- const cmd = `grep -rn "${pattern.replace(/"/g, '\\"')}" "${searchPath}"`;
50
- const output = execSync(cmd, {
51
- encoding: 'utf-8',
52
- maxBuffer: 1024 * 1024,
53
- cwd: ctx.baseDir,
54
- });
55
- return { success: true, output: truncateLines(output || t('file.no_matches')) };
56
- }
57
- catch (e2) {
58
- if (e2.status === 1)
59
- return { success: true, output: t('file.no_matches') };
60
- return { success: false, output: t('error.grep_failed', { message: e2.message }) };
61
- }
62
- }
63
- },
64
- };
@@ -1,52 +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
- import { questionTool } from './question';
22
- import { approveTool } from './approve';
23
- import { createLoadSkillTool } from './load-skill';
24
- import { pipelineRunTool } from './pipeline-run';
25
- import { mcpCallTool } from './mcp-call';
26
- import { searchHistoryTool } from './search-history';
27
- import { rememberTool } from './remember';
28
- import { recallTool } from './recall';
29
- import { createBrowserTool } from './browser';
30
- import { attachImageTool } from './attach-image';
31
- export { ToolRegistry, ToolExecutor };
32
- export { filterToolsByTags } from './filter-tools';
33
- export { readFileTool, writeFileTool, editFileTool, globTool, grepTool, listDirTool, createDirTool, deleteFileTool, moveFileTool, fileInfoTool, bashTool, subagentTool, processListTool, processLogTool, processKillTool, webSearchTool, webFetchTool, webBrowseTool, questionTool, approveTool, createLoadSkillTool, pipelineRunTool, mcpCallTool, searchHistoryTool, rememberTool, recallTool, createBrowserTool, attachImageTool, };
34
- export function registerAllTools(registry, skillsModule) {
35
- const tools = [
36
- readFileTool, writeFileTool, editFileTool,
37
- globTool, grepTool, listDirTool, createDirTool,
38
- deleteFileTool, moveFileTool, fileInfoTool,
39
- bashTool, subagentTool,
40
- processListTool, processLogTool, processKillTool,
41
- webSearchTool, webFetchTool, webBrowseTool,
42
- questionTool, approveTool,
43
- pipelineRunTool, mcpCallTool, searchHistoryTool,
44
- attachImageTool,
45
- ];
46
- if (skillsModule) {
47
- tools.push(createLoadSkillTool(skillsModule));
48
- }
49
- for (const tool of tools) {
50
- registry.register(tool);
51
- }
52
- }
@@ -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,48 +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 or task description. Skills provide specialized instructions and workflows. Only use when the task clearly requires domain-specific knowledge. If loading fails because the skill is too large, continue the task without it.",
7
- parameters: {
8
- type: "object",
9
- properties: {
10
- name: { type: "string", description: "Skill name to load directly" },
11
- task: {
12
- type: "string",
13
- description: "Task description to find matching skill",
14
- },
15
- },
16
- },
17
- handler: async (_ctx, args) => {
18
- const name = args.name ? String(args.name) : undefined;
19
- const task = args.task ? String(args.task) : undefined;
20
- if (!name && !task) {
21
- return { success: false, output: t("tool.name_or_task") };
22
- }
23
- let result;
24
- if (name) {
25
- result = skillsModule.loadByName(name);
26
- }
27
- else if (task) {
28
- result = skillsModule.loadByMatch(task);
29
- }
30
- else {
31
- return { success: false, output: t("tool.invalid_params") };
32
- }
33
- if (!result.success) {
34
- const available = skillsModule.getAvailable();
35
- const hint = available.length > 0
36
- ? `\n\n${t("tool.skill_available_hint")}: ${available.map((s) => s.name).join(", ")}`
37
- : "";
38
- return { success: false, output: result.message + hint };
39
- }
40
- const skill = result.skill;
41
- const budget = skillsModule.getBudget();
42
- return {
43
- success: true,
44
- output: `${result.message}\n\n--- Skill Content ---\n${skill.content}\n\n${t("tool.skill_budget", { remaining: budget.remaining })}`,
45
- };
46
- },
47
- };
48
- }
@@ -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,84 +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
- export const moveFileTool = {
9
- name: "move_file",
10
- description: "Move or rename a file or directory.",
11
- tags: ["file"],
12
- parameters: {
13
- type: "object",
14
- properties: {
15
- from: { type: "string", description: "Source path" },
16
- to: { type: "string", description: "Destination path" },
17
- },
18
- required: ["from", "to"],
19
- },
20
- handler: async (ctx, args) => {
21
- const fromPath = String(args.from);
22
- const toPath = String(args.to);
23
- const baseDir = resolve(ctx.baseDir);
24
- const fromResolved = resolve(baseDir, normalize(fromPath));
25
- const toResolved = resolve(baseDir, normalize(toPath));
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`, `${fromPath} -> ${toPath}`);
35
- return {
36
- success: false,
37
- output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
38
- };
39
- }
40
- // Check source path permissions
41
- const fromCheck = isPathWritable(ctx.baseDir, fromPath, ctx.scope, ctx.config.security?.paths);
42
- if (!fromCheck.allowed) {
43
- logSecurityBlock(ctx.sessionId, "file_write", fromCheck.reason || "Source path not allowed", fromPath);
44
- return {
45
- success: false,
46
- output: t("file.path_not_allowed", {
47
- path: `${fromPath} — ${fromCheck.reason}`,
48
- }),
49
- };
50
- }
51
- // Check destination path permissions
52
- const toCheck = isPathWritable(ctx.baseDir, toPath, ctx.scope, ctx.config.security?.paths);
53
- if (!toCheck.allowed) {
54
- logSecurityBlock(ctx.sessionId, "file_write", toCheck.reason || "Destination path not allowed", toPath);
55
- return {
56
- success: false,
57
- output: t("file.path_not_allowed", {
58
- path: `${toPath} — ${toCheck.reason}`,
59
- }),
60
- };
61
- }
62
- if (!existsSync(fromResolved)) {
63
- return {
64
- success: false,
65
- output: t("file.not_found_short", { path: fromPath }),
66
- };
67
- }
68
- const toDir = dirname(toResolved);
69
- if (!existsSync(toDir)) {
70
- mkdirSync(toDir, { recursive: true });
71
- }
72
- renameSync(fromResolved, toResolved);
73
- const diff = generateMoveDiff(fromPath, toPath);
74
- // Increment file operations counter
75
- ctx.fileOperationsCount = currentCount + 1;
76
- // Log file move
77
- logFileWrite(ctx.sessionId, `${fromPath} -> ${toPath}`, true, "File moved");
78
- return {
79
- success: true,
80
- output: t("file.moved", { from: fromPath, to: toPath }),
81
- diff,
82
- };
83
- },
84
- };
@@ -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
- }