micro-models-agent 0.46.2 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -312
- package/dist/main.js +397 -353
- package/dist/modules/browser/bridge-server.mjs +202 -202
- package/dist/skills/builtin/git.md +36 -36
- package/dist/skills/builtin/typescript.md +35 -35
- package/package.json +48 -48
- package/dist/cli/commands.js +0 -323
- package/dist/cli/completer.js +0 -167
- package/dist/cli/index.js +0 -2
- package/dist/cli/main.js +0 -165
- package/dist/cli/plugin-commands.js +0 -36
- package/dist/cli/repl-commands.js +0 -661
- package/dist/cli/repl.js +0 -616
- package/dist/cli/run-result.js +0 -22
- package/dist/cli/security-commands.js +0 -164
- package/dist/cli/setup.js +0 -231
- package/dist/config/config.js +0 -249
- package/dist/config/defaults.js +0 -124
- package/dist/config/experts.js +0 -15
- package/dist/config/index.js +0 -3
- package/dist/config/security.js +0 -193
- package/dist/config/types.js +0 -1
- package/dist/core/agent-moe.js +0 -102
- package/dist/core/agent.js +0 -886
- package/dist/core/bootstrap.js +0 -404
- package/dist/core/index.js +0 -2
- package/dist/core/prompt-builder.js +0 -76
- package/dist/core/session-logger.js +0 -197
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -24
- package/dist/core/workspace.js +0 -76
- package/dist/i18n/en.json +0 -598
- package/dist/i18n/index.js +0 -46
- package/dist/i18n/ru.json +0 -598
- package/dist/index.js +0 -22
- package/dist/llm/image-utils.js +0 -143
- package/dist/llm/index.js +0 -4
- package/dist/llm/model-loader.js +0 -78
- package/dist/llm/openai-compat.js +0 -359
- package/dist/llm/orchestrator.js +0 -198
- package/dist/llm/provider.js +0 -10
- package/dist/llm/response.js +0 -39
- package/dist/llm/token-counter.js +0 -39
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -143
- package/dist/logger/file-log.js +0 -151
- package/dist/logger/index.js +0 -1
- package/dist/migration/backup.js +0 -45
- package/dist/migration/detect.js +0 -50
- package/dist/migration/index.js +0 -2
- package/dist/modules/artifacts/store.js +0 -61
- package/dist/modules/browser/actions.js +0 -76
- package/dist/modules/browser/bridge-client.js +0 -199
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/cookie-store.js +0 -24
- package/dist/modules/browser/driver.js +0 -136
- package/dist/modules/browser/index.js +0 -7
- package/dist/modules/browser/module.js +0 -29
- package/dist/modules/browser/session.js +0 -338
- package/dist/modules/browser/snapshot.js +0 -148
- package/dist/modules/browser/types.js +0 -12
- package/dist/modules/certification/cli.js +0 -174
- package/dist/modules/certification/fact-checker.js +0 -82
- package/dist/modules/certification/loader.js +0 -105
- package/dist/modules/certification/manifest.js +0 -50
- package/dist/modules/certification/runner.js +0 -159
- package/dist/modules/certification/scenarios.js +0 -124
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -100
- package/dist/modules/context/fact-extractor.js +0 -162
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -1
- package/dist/modules/context/manager.js +0 -423
- package/dist/modules/execution/audit-runners.js +0 -152
- package/dist/modules/execution/auditor.js +0 -218
- package/dist/modules/execution/execution-plugin.js +0 -272
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/module.js +0 -436
- package/dist/modules/execution/moe-executor.js +0 -291
- package/dist/modules/execution/plan-coverage.js +0 -68
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-store.js +0 -157
- package/dist/modules/execution/plan-tool.js +0 -508
- package/dist/modules/execution/plan-validator.js +0 -153
- package/dist/modules/execution/planner.js +0 -90
- package/dist/modules/execution/stuck-detector.js +0 -510
- package/dist/modules/execution/tracker.js +0 -67
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -222
- package/dist/modules/execution/windows-commands.js +0 -41
- package/dist/modules/hallucination/confidence.js +0 -66
- package/dist/modules/hallucination/consistency.js +0 -26
- package/dist/modules/hallucination/detector.js +0 -43
- package/dist/modules/hallucination/factual.js +0 -129
- package/dist/modules/hallucination/index.js +0 -5
- package/dist/modules/hallucination/js-identifiers.js +0 -262
- package/dist/modules/hallucination/llm-judge.js +0 -101
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -40
- package/dist/modules/indexer/index.js +0 -3
- package/dist/modules/indexer/module.js +0 -245
- package/dist/modules/indexer/project-profile.js +0 -183
- package/dist/modules/indexer/walker.js +0 -101
- package/dist/modules/lsp/check-tool.js +0 -58
- package/dist/modules/lsp/client.js +0 -278
- package/dist/modules/lsp/command.js +0 -60
- package/dist/modules/lsp/config.js +0 -135
- package/dist/modules/lsp/index.js +0 -3
- package/dist/modules/lsp/module.js +0 -232
- package/dist/modules/lsp/probe.js +0 -76
- package/dist/modules/lsp/project-root.js +0 -32
- package/dist/modules/lsp/startup-check.js +0 -141
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -399
- package/dist/modules/mcp/index.js +0 -3
- package/dist/modules/mcp/module.js +0 -142
- package/dist/modules/mcp/registry.js +0 -15
- package/dist/modules/memory/index.js +0 -1
- package/dist/modules/memory/module.js +0 -96
- package/dist/modules/memory/search.js +0 -42
- package/dist/modules/memory/store.js +0 -69
- package/dist/modules/pipelines/engine.js +0 -60
- package/dist/modules/pipelines/index.js +0 -3
- package/dist/modules/pipelines/parser.js +0 -56
- package/dist/modules/pipelines/template.js +0 -14
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
- package/dist/modules/plugins/builtin/notify.js +0 -9
- package/dist/modules/plugins/index.js +0 -1
- package/dist/modules/plugins/loader.js +0 -70
- package/dist/modules/plugins/manager.js +0 -217
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -2
- package/dist/modules/processes/registry.js +0 -327
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/registry.js +0 -47
- package/dist/modules/security/audit-log.js +0 -136
- package/dist/modules/security/audit-notifier.js +0 -292
- package/dist/modules/security/command-validator.js +0 -205
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -89
- package/dist/modules/security/encryption.js +0 -242
- package/dist/modules/security/index.js +0 -14
- package/dist/modules/security/network-validator.js +0 -71
- package/dist/modules/security/path-validator.js +0 -207
- package/dist/modules/security/rate-limiter.js +0 -119
- package/dist/modules/security/security-policies.js +0 -531
- package/dist/modules/security/session-encryption.js +0 -210
- package/dist/modules/security/session-isolation.js +0 -95
- package/dist/modules/session/index.js +0 -3
- package/dist/modules/session/manager.js +0 -172
- package/dist/modules/session/module.js +0 -24
- package/dist/modules/session/store.js +0 -222
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/skills/index.js +0 -2
- package/dist/modules/skills/loader.js +0 -72
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -129
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/checker.js +0 -96
- package/dist/modules/updater/index.js +0 -2
- package/dist/modules/updater/module.js +0 -116
- package/dist/modules/user-profile/compressor.js +0 -16
- package/dist/modules/user-profile/index.js +0 -1
- package/dist/modules/user-profile/profile.js +0 -68
- package/dist/tools/approve.js +0 -32
- package/dist/tools/attach-image.js +0 -89
- package/dist/tools/bash.js +0 -496
- package/dist/tools/browser.js +0 -114
- package/dist/tools/chunk-query.js +0 -99
- package/dist/tools/create-dir.js +0 -55
- package/dist/tools/delete-file.js +0 -62
- package/dist/tools/download-file.js +0 -116
- package/dist/tools/edit-file.js +0 -79
- package/dist/tools/enable-tools.js +0 -58
- package/dist/tools/executor.js +0 -144
- package/dist/tools/file-info.js +0 -46
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -26
- package/dist/tools/grep-tool.js +0 -84
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -78
- package/dist/tools/list-dir.js +0 -48
- package/dist/tools/load-skill.js +0 -42
- package/dist/tools/mcp-call.js +0 -68
- package/dist/tools/move-file.js +0 -85
- package/dist/tools/path-utils.js +0 -51
- package/dist/tools/pipeline-run.js +0 -144
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-kill.js +0 -29
- package/dist/tools/process-list.js +0 -36
- package/dist/tools/process-log.js +0 -45
- package/dist/tools/question.js +0 -140
- package/dist/tools/read-file.js +0 -91
- package/dist/tools/recall.js +0 -117
- package/dist/tools/registry.js +0 -47
- package/dist/tools/remember.js +0 -67
- package/dist/tools/scope-check.js +0 -30
- package/dist/tools/search-history.js +0 -84
- package/dist/tools/subagent.js +0 -196
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -123
- package/dist/tools/web-browse.js +0 -86
- package/dist/tools/web-fetch.js +0 -98
- package/dist/tools/web-search.js +0 -78
- package/dist/tools/write-file.js +0 -81
- package/dist/ui/box.js +0 -77
- package/dist/ui/colors.js +0 -4
- package/dist/ui/diff.js +0 -178
- package/dist/ui/index.js +0 -6
- package/dist/ui/line-editor.js +0 -703
- package/dist/ui/line-math.js +0 -69
- package/dist/ui/md-formatter.js +0 -212
- package/dist/ui/output.js +0 -13
- package/dist/ui/plan-view.js +0 -103
- package/dist/ui/renderer.js +0 -209
- package/dist/ui/spinner.js +0 -70
- package/dist/ui/table.js +0 -144
|
@@ -1,99 +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
|
-
description: "Answer a query over a large text (file or inline) by splitting it into chunks and querying the model per chunk in parallel, then optionally synthesizing a final answer. Use when the input is too large for the context window.",
|
|
9
|
-
tags: ["research", "code"],
|
|
10
|
-
/** Multiple LLM calls (parallel chunk queries + synthesis) need a longer budget. */
|
|
11
|
-
timeoutMs: 300000,
|
|
12
|
-
parameters: {
|
|
13
|
-
type: "object",
|
|
14
|
-
properties: {
|
|
15
|
-
query: {
|
|
16
|
-
type: "string",
|
|
17
|
-
description: "The question to answer over the text.",
|
|
18
|
-
},
|
|
19
|
-
input_path: {
|
|
20
|
-
type: "string",
|
|
21
|
-
description: "Path to the large text file (scope-checked). Preferred over text.",
|
|
22
|
-
},
|
|
23
|
-
text: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Inline text. Use only when a file path is not available.",
|
|
26
|
-
},
|
|
27
|
-
chunk_chars: {
|
|
28
|
-
type: "number",
|
|
29
|
-
description: "Approximate chunk size in chars (default 12000).",
|
|
30
|
-
},
|
|
31
|
-
max_parallel: {
|
|
32
|
-
type: "number",
|
|
33
|
-
description: "Max parallel chunk queries (default from config.subagent.maxParallelChunkQueries).",
|
|
34
|
-
},
|
|
35
|
-
max_chunk_tokens: {
|
|
36
|
-
type: "number",
|
|
37
|
-
description: "Cap on generated tokens per chunk call (default 1024).",
|
|
38
|
-
},
|
|
39
|
-
max_synthesis_tokens: {
|
|
40
|
-
type: "number",
|
|
41
|
-
description: "Cap on generated tokens for the synthesis call (default 2048).",
|
|
42
|
-
},
|
|
43
|
-
reasoning_effort: {
|
|
44
|
-
type: "string",
|
|
45
|
-
enum: ["none", "low", "medium", "high"],
|
|
46
|
-
description: 'Reasoning effort for chunk/synthesis calls (default "none"). "none" prevents long thinking chains from eating the token budget on reasoning models.',
|
|
47
|
-
},
|
|
48
|
-
synthesize: {
|
|
49
|
-
type: "boolean",
|
|
50
|
-
description: "Run a final synthesis call over chunk answers (default true).",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
required: ["query"],
|
|
54
|
-
},
|
|
55
|
-
handler: async (ctx, args) => {
|
|
56
|
-
const query = String(args.query || "");
|
|
57
|
-
const inputPath = args.input_path ? String(args.input_path) : undefined;
|
|
58
|
-
const text = args.text ? String(args.text) : undefined;
|
|
59
|
-
if (!query)
|
|
60
|
-
return { success: false, output: t("tool.chunk_query_no_query") };
|
|
61
|
-
if (!inputPath && !text)
|
|
62
|
-
return { success: false, output: t("tool.chunk_query_no_input") };
|
|
63
|
-
let content = text || "";
|
|
64
|
-
if (inputPath) {
|
|
65
|
-
const check = isPathInScope(ctx.baseDir, inputPath, ctx.scope);
|
|
66
|
-
if (!check.allowed) {
|
|
67
|
-
return { success: false, output: `[SCOPE] ${check.reason || "Path not allowed"}` };
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
content = readFileSync(resolve(ctx.baseDir, inputPath), "utf8");
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
return { success: false, output: `Cannot read ${inputPath}: ${e.message}` };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (!ctx.llmProvider) {
|
|
77
|
-
return { success: false, output: "chunk_query: missing llmProvider in context" };
|
|
78
|
-
}
|
|
79
|
-
const maxParallel = typeof args.max_parallel === "number"
|
|
80
|
-
? args.max_parallel
|
|
81
|
-
: (ctx.config.subagent?.maxParallelChunkQueries ?? 4);
|
|
82
|
-
const res = await runChunkQuery(ctx.llmProvider, content, query, {
|
|
83
|
-
chunkChars: typeof args.chunk_chars === "number" ? args.chunk_chars : undefined,
|
|
84
|
-
maxParallel,
|
|
85
|
-
synthesize: typeof args.synthesize === "boolean" ? args.synthesize : undefined,
|
|
86
|
-
maxChunkTokens: typeof args.max_chunk_tokens === "number" ? args.max_chunk_tokens : undefined,
|
|
87
|
-
maxSynthesisTokens: typeof args.max_synthesis_tokens === "number" ? args.max_synthesis_tokens : undefined,
|
|
88
|
-
reasoningEffort: ["none", "low", "medium", "high"].includes(args.reasoning_effort)
|
|
89
|
-
? args.reasoning_effort
|
|
90
|
-
: undefined,
|
|
91
|
-
logger: ctx.logger,
|
|
92
|
-
});
|
|
93
|
-
ctx.logger.debug(`chunk_query: ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}`);
|
|
94
|
-
return {
|
|
95
|
-
success: true,
|
|
96
|
-
output: `[chunk_query] ${res.chunks} chunk(s), ${res.totalChars} chars, max parallel ${res.maxParallelObserved}\n\n${res.synthesis || res.answers.join("\n")}`,
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
};
|
package/dist/tools/create-dir.js
DELETED
|
@@ -1,55 +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
|
-
description: "Create a directory (and any intermediate directories).",
|
|
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
|
-
// Get session-specific security config
|
|
22
|
-
const securityConfig = ctx.sessionContext
|
|
23
|
-
? getSessionSecurityConfig(ctx.config, ctx.sessionContext)
|
|
24
|
-
: ctx.config.security;
|
|
25
|
-
// Check file operations limit
|
|
26
|
-
const maxFileOps = securityConfig?.maxFileOperations ?? 100;
|
|
27
|
-
const currentCount = ctx.fileOperationsCount ?? 0;
|
|
28
|
-
if (currentCount >= maxFileOps) {
|
|
29
|
-
logSecurityBlock(ctx.sessionId, "file_write", `Maximum file operations (${maxFileOps}) exceeded`, path);
|
|
30
|
-
return {
|
|
31
|
-
success: false,
|
|
32
|
-
output: `[SECURITY BLOCKED] Maximum file operations (${maxFileOps}) exceeded`,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
// Check path permissions
|
|
36
|
-
const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
|
|
37
|
-
if (!scopeCheck.allowed) {
|
|
38
|
-
logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
|
|
39
|
-
return {
|
|
40
|
-
success: false,
|
|
41
|
-
output: t("file.path_not_allowed", {
|
|
42
|
-
path: `${path} — ${scopeCheck.reason}`,
|
|
43
|
-
}),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (!existsSync(resolved)) {
|
|
47
|
-
mkdirSync(resolved, { recursive: true });
|
|
48
|
-
}
|
|
49
|
-
// Increment file operations counter
|
|
50
|
-
ctx.fileOperationsCount = currentCount + 1;
|
|
51
|
-
// Log directory creation
|
|
52
|
-
logFileWrite(ctx.sessionId, path, true, "Directory created");
|
|
53
|
-
return { success: true, output: t("file.created", { path }) };
|
|
54
|
-
},
|
|
55
|
-
};
|
|
@@ -1,62 +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
|
-
description: "Delete a file from the filesystem.",
|
|
11
|
-
tags: ["file"],
|
|
12
|
-
parameters: {
|
|
13
|
-
type: "object",
|
|
14
|
-
properties: {
|
|
15
|
-
path: { type: "string", description: "File 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_delete", `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_delete", 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
|
-
return { success: false, output: t("file.notfound", { path }) };
|
|
49
|
-
}
|
|
50
|
-
if (statSync(resolved).isDirectory()) {
|
|
51
|
-
return { success: false, output: t("file.is_directory", { path }) };
|
|
52
|
-
}
|
|
53
|
-
const content = readFileSync(resolved, "utf-8");
|
|
54
|
-
unlinkSync(resolved);
|
|
55
|
-
const diff = generateDeleteDiff(content);
|
|
56
|
-
// Increment file operations counter
|
|
57
|
-
ctx.fileOperationsCount = currentCount + 1;
|
|
58
|
-
// Log successful file deletion
|
|
59
|
-
logFileDelete(ctx.sessionId, path, true);
|
|
60
|
-
return { success: true, output: t("file.deleted", { path }), diff };
|
|
61
|
-
},
|
|
62
|
-
};
|
|
@@ -1,116 +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
|
-
description: "Download a file (image, archive, binary, font, etc.) from a URL and save it to disk. Returns only the path, size and content type — read the saved file with read_file/attach_image afterwards. Use this for binary files; web_fetch/web_browse return text only and cannot save bytes.",
|
|
16
|
-
tags: ["file", "research"],
|
|
17
|
-
parameters: {
|
|
18
|
-
type: "object",
|
|
19
|
-
properties: {
|
|
20
|
-
url: { type: "string", description: "URL to download" },
|
|
21
|
-
path: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "Destination path (relative to the working directory)",
|
|
24
|
-
},
|
|
25
|
-
max_bytes: {
|
|
26
|
-
type: "number",
|
|
27
|
-
description: "Optional size cap in bytes (default 100 MB)",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
required: ["url", "path"],
|
|
31
|
-
},
|
|
32
|
-
handler: async (ctx, args) => {
|
|
33
|
-
const url = String(args.url || "").trim();
|
|
34
|
-
const path = String(args.path || "").trim();
|
|
35
|
-
if (!url || !path) {
|
|
36
|
-
return { success: false, output: t("tool.invalid_params") };
|
|
37
|
-
}
|
|
38
|
-
// Network security: same rules as web_fetch/web_browse.
|
|
39
|
-
const securityConfig = ctx.sessionContext
|
|
40
|
-
? getSessionSecurityConfig(ctx.config, ctx.sessionContext).network
|
|
41
|
-
: ctx.config.security?.network || DEFAULT_SECURITY_CONFIG.network;
|
|
42
|
-
const validation = isUrlAllowed(url, securityConfig);
|
|
43
|
-
if (!validation.allowed) {
|
|
44
|
-
logSecurityBlock(ctx.sessionId, "network_request", validation.reason || "URL blocked by security policy", sanitizeUrl(url));
|
|
45
|
-
return {
|
|
46
|
-
success: false,
|
|
47
|
-
output: `[SECURITY BLOCKED] URL is not allowed: ${validation.reason}`,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
// Path safety: resolve against baseDir and verify writability.
|
|
51
|
-
const resolved = safeResolvePath(ctx.baseDir, path);
|
|
52
|
-
const scopeCheck = isPathWritable(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
|
|
53
|
-
if (!scopeCheck.allowed) {
|
|
54
|
-
logSecurityBlock(ctx.sessionId, "file_write", scopeCheck.reason || "Path not allowed", path);
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
output: t("file.path_not_allowed", {
|
|
58
|
-
path: `${path} — ${scopeCheck.reason}`,
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const maxBytes = Number(args.max_bytes) > 0 ? Number(args.max_bytes) : MAX_DOWNLOAD_BYTES;
|
|
63
|
-
try {
|
|
64
|
-
const response = await fetch(url, {
|
|
65
|
-
signal: AbortSignal.timeout(securityConfig?.requestTimeout || 15000),
|
|
66
|
-
});
|
|
67
|
-
if (!response.ok) {
|
|
68
|
-
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Status: ${response.status}`);
|
|
69
|
-
return {
|
|
70
|
-
success: false,
|
|
71
|
-
output: t("error.http", {
|
|
72
|
-
status: response.status,
|
|
73
|
-
statusText: response.statusText,
|
|
74
|
-
}),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const contentLength = Number(response.headers.get("content-length") || "0");
|
|
78
|
-
if (contentLength > maxBytes) {
|
|
79
|
-
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${contentLength}`);
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
output: t("tool.download_too_large", { max: String(maxBytes) }),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
86
|
-
if (buffer.byteLength > maxBytes) {
|
|
87
|
-
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Too large: ${buffer.byteLength}`);
|
|
88
|
-
return {
|
|
89
|
-
success: false,
|
|
90
|
-
output: t("tool.download_too_large", { max: String(maxBytes) }),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
mkdirSync(dirname(resolved), { recursive: true });
|
|
94
|
-
writeFileSync(resolved, buffer);
|
|
95
|
-
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim() || "unknown";
|
|
96
|
-
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), true, `Status: ${response.status}`);
|
|
97
|
-
logFileWrite(ctx.sessionId, resolved, true, `Downloaded ${buffer.byteLength} bytes`);
|
|
98
|
-
return {
|
|
99
|
-
success: true,
|
|
100
|
-
output: t("tool.downloaded", {
|
|
101
|
-
url: sanitizeUrl(url),
|
|
102
|
-
path: resolved,
|
|
103
|
-
size: String(buffer.byteLength),
|
|
104
|
-
type: contentType,
|
|
105
|
-
}),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
logNetworkRequest(ctx.sessionId, sanitizeUrl(url), false, `Error: ${e.message}`);
|
|
110
|
-
return {
|
|
111
|
-
success: false,
|
|
112
|
-
output: t("error.fetch_failed", { message: e.message }),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
};
|
package/dist/tools/edit-file.js
DELETED
|
@@ -1,79 +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 — only when security is enabled
|
|
61
|
-
if (securityConfig?.enabled && securityConfig?.contentScan?.enabled) {
|
|
62
|
-
const scanResult = scanContent(updated, path, securityConfig.contentScan);
|
|
63
|
-
if (!scanResult.allowed) {
|
|
64
|
-
logSecurityBlock(ctx.sessionId, "file_write", scanResult.reason || "Content contains dangerous patterns", path);
|
|
65
|
-
return {
|
|
66
|
-
success: false,
|
|
67
|
-
output: `[SECURITY BLOCKED] ${scanResult.reason}`,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
writeFileSync(resolved, updated, "utf-8");
|
|
72
|
-
const diff = generateDiff(content, updated);
|
|
73
|
-
// Increment file operations counter
|
|
74
|
-
ctx.fileOperationsCount = currentCount + 1;
|
|
75
|
-
// Log successful file edit
|
|
76
|
-
logFileWrite(ctx.sessionId, path, true, "File edited");
|
|
77
|
-
return { success: true, output: t("file.replaced_in", { path }), diff };
|
|
78
|
-
},
|
|
79
|
-
};
|
|
@@ -1,58 +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
|
-
description: "Enable hidden tool categories for the current session. Only the essential tools (file/code/shell) are active by default. Call this with the tags you need and they become available from the next turn. Available tags: file, code, shell, research, browser, vision, image, memory, core. Returns the newly available tools. To run a task in a separate context instead, use subagent with tool_tags.",
|
|
13
|
-
alwaysOn: true,
|
|
14
|
-
parameters: {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
tags: {
|
|
18
|
-
type: "array",
|
|
19
|
-
items: { type: "string" },
|
|
20
|
-
description: 'Tool tags to enable (e.g. ["research"] for web_search/web_fetch, ["browser"] for the browser, ["memory"] for remember/recall, ["shell"] for process management).',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
required: ["tags"],
|
|
24
|
-
},
|
|
25
|
-
handler: async (ctx, args) => {
|
|
26
|
-
const requested = Array.isArray(args.tags) ? args.tags.map(String).filter(Boolean) : [];
|
|
27
|
-
if (requested.length === 0) {
|
|
28
|
-
return { success: false, output: t("tools.enable_no_tags") };
|
|
29
|
-
}
|
|
30
|
-
const active = ctx.activeToolTags ?? [];
|
|
31
|
-
const added = [];
|
|
32
|
-
for (const tag of requested) {
|
|
33
|
-
if (!active.includes(tag)) {
|
|
34
|
-
active.push(tag);
|
|
35
|
-
added.push(tag);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!ctx.toolExecutor) {
|
|
39
|
-
return { success: false, output: t("tools.enable_no_executor") };
|
|
40
|
-
}
|
|
41
|
-
const nowVisible = ctx.toolExecutor.getToolDefinitions([...active]).map((t) => t.name);
|
|
42
|
-
if (added.length === 0) {
|
|
43
|
-
return {
|
|
44
|
-
success: true,
|
|
45
|
-
output: t("tools.enable_already_active", {
|
|
46
|
-
tags: requested.join(", "),
|
|
47
|
-
}),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
52
|
-
output: t("tools.enable_added", {
|
|
53
|
-
tags: added.join(", "),
|
|
54
|
-
tools: nowVisible.join(", "),
|
|
55
|
-
}),
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
};
|
package/dist/tools/executor.js
DELETED
|
@@ -1,144 +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
|
-
for (const plugin of this.pluginManager.getAllPlugins()) {
|
|
118
|
-
if (plugin.onAfterTool) {
|
|
119
|
-
try {
|
|
120
|
-
await plugin.onAfterTool(this.ctx, call, result);
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
this.ctx.logger.warn(`Plugin onAfterTool error: ${e.message}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
this.ctx.logger.logToolCall(call.name, JSON.stringify(call.arguments)?.slice(0, 200) ?? "", result.success ? "OK" : `FAIL: ${result.output?.slice(0, 200)}`);
|
|
128
|
-
this.ctx.logger.logToolOutput(call.name, result.output ?? "", result.success ? 0 : 1);
|
|
129
|
-
this.ctx.logger.debug(`Tool ${call.name}: ${result.success ? "OK" : "FAIL"}`);
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
getToolDefinitions(tags) {
|
|
133
|
-
return this.registry.getAllForLLM(tags);
|
|
134
|
-
}
|
|
135
|
-
getRegistry() {
|
|
136
|
-
return this.registry;
|
|
137
|
-
}
|
|
138
|
-
setScope(scope) {
|
|
139
|
-
this.ctx.scope = scope;
|
|
140
|
-
}
|
|
141
|
-
updateProvider(provider) {
|
|
142
|
-
this.ctx.llmProvider = provider;
|
|
143
|
-
}
|
|
144
|
-
}
|
package/dist/tools/file-info.js
DELETED
|
@@ -1,46 +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
|
-
boundedOutput: true,
|
|
10
|
-
parameters: {
|
|
11
|
-
type: "object",
|
|
12
|
-
properties: {
|
|
13
|
-
path: { type: "string", description: "File path" },
|
|
14
|
-
},
|
|
15
|
-
required: ["path"],
|
|
16
|
-
},
|
|
17
|
-
handler: async (ctx, args) => {
|
|
18
|
-
const path = String(args.path);
|
|
19
|
-
const resolved = safeResolvePath(ctx.baseDir, path);
|
|
20
|
-
// Check path permissions
|
|
21
|
-
const scopeCheck = isPathInScope(ctx.baseDir, resolved, ctx.scope, ctx.config.security?.paths);
|
|
22
|
-
if (!scopeCheck.allowed) {
|
|
23
|
-
return {
|
|
24
|
-
success: false,
|
|
25
|
-
output: t("file.path_not_allowed", {
|
|
26
|
-
path: `${path} — ${scopeCheck.reason}`,
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (!existsSync(resolved)) {
|
|
31
|
-
return { success: false, output: t("file.not_found_short", { path }) };
|
|
32
|
-
}
|
|
33
|
-
const stat = statSync(resolved);
|
|
34
|
-
return {
|
|
35
|
-
success: true,
|
|
36
|
-
output: JSON.stringify({
|
|
37
|
-
path,
|
|
38
|
-
size: stat.size,
|
|
39
|
-
isDirectory: stat.isDirectory(),
|
|
40
|
-
isFile: stat.isFile(),
|
|
41
|
-
created: stat.birthtime,
|
|
42
|
-
modified: stat.mtime,
|
|
43
|
-
}, null, 2),
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
};
|