@bike4mind/cli 0.2.64-worktree-refactor-extract-search-query-builders.21815 → 0.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bike4mind-cli.mjs +6 -6
- package/dist/BubblewrapRuntime-BHbtqvLx.mjs +72 -0
- package/dist/ConfigStore-CllM6jOf.mjs +8614 -0
- package/dist/ImageStore-DaKT_Ew8.mjs +202 -0
- package/dist/ProxyManager-Dl2nFk-A.mjs +259 -0
- package/dist/ProxyManager-kiOD1X8-.mjs +3 -0
- package/dist/SandboxOrchestrator-BEW3rqYi.mjs +159 -0
- package/dist/SandboxOrchestrator-CHZgSR3P.mjs +3 -0
- package/dist/SandboxRuntimeAdapter-C1B4t20N.mjs +57 -0
- package/dist/SandboxRuntimeAdapter-D7UAG13n.mjs +3 -0
- package/dist/SeatbeltRuntime-D4m0VOcD.mjs +116 -0
- package/dist/StderrViolationParser-D0afQ3-1.mjs +70 -0
- package/dist/ViolationLogStore-CZl35HcA.mjs +96 -0
- package/dist/bashExecute-BTkdqlSs-5foM20Lb.mjs +466 -0
- package/dist/commands/doctorCommand.mjs +101 -0
- package/dist/commands/headlessCommand.mjs +319 -0
- package/dist/commands/mcpCommand.mjs +218 -0
- package/dist/commands/updateCommand.mjs +40 -0
- package/dist/createFile-yQfh8uvk-I-yM5DxC.mjs +63 -0
- package/dist/deleteFile-DKHfnyny-G3b1Kj2T.mjs +66 -0
- package/dist/globFiles-D1en6joM-8jekiXdX.mjs +100 -0
- package/dist/grepSearch-aMamoBn_-DCJcY8JS.mjs +173 -0
- package/dist/index.mjs +6722 -0
- package/dist/pathValidation-Cgjh5WQO-DiCZTcq6.mjs +63 -0
- package/dist/store-Dw1nZX2Y.mjs +128 -0
- package/dist/store-nZExNOWX.mjs +3 -0
- package/dist/terminalSetup-rmr1P8KF.mjs +254 -0
- package/dist/tools-C6M5aW8W.mjs +20907 -0
- package/dist/treeSitterEngine-DCSXcm_3.mjs +309 -0
- package/dist/types-DBEjF9YS.mjs +59 -0
- package/dist/types-DK3P88Px.mjs +3 -0
- package/dist/updateChecker-Cu9dkHxV.mjs +120 -0
- package/package.json +10 -10
- package/dist/BubblewrapRuntime-PMIOLWKR.js +0 -71
- package/dist/HydrationEngine-YL2HWJ3V.js +0 -9
- package/dist/ImageStore-MMUOUPI2.js +0 -224
- package/dist/ProxyManager-HEB4TLVX.js +0 -7
- package/dist/SandboxOrchestrator-UIJ5GYBB.js +0 -8
- package/dist/SandboxRuntimeAdapter-FQ56MAB2.js +0 -13
- package/dist/SeatbeltRuntime-EE3TTLEP.js +0 -98
- package/dist/StderrViolationParser-7OYPM2DJ.js +0 -59
- package/dist/ViolationLogStore-RIIUVURH.js +0 -104
- package/dist/artifactExtractor-R7DIP2XO.js +0 -180
- package/dist/bashExecute-GLGLD3JD.js +0 -379
- package/dist/chunk-4BIBE3J7.js +0 -48
- package/dist/chunk-5LZS5CVJ.js +0 -161
- package/dist/chunk-BDQBOLYG.js +0 -120
- package/dist/chunk-BPFEGDC7.js +0 -192
- package/dist/chunk-EPIYC3LA.js +0 -13770
- package/dist/chunk-G4ZGEQFT.js +0 -250
- package/dist/chunk-GQGOWACU.js +0 -770
- package/dist/chunk-J6ZBI6TI.js +0 -1079
- package/dist/chunk-JW3JRHH7.js +0 -12433
- package/dist/chunk-KQAMBXAW.js +0 -163
- package/dist/chunk-KUVV2NAB.js +0 -19125
- package/dist/chunk-LTLJRF6I.js +0 -44
- package/dist/chunk-PFBYGCOW.js +0 -449
- package/dist/chunk-QWB6ZYY4.js +0 -48
- package/dist/chunk-SGPRXN4C.js +0 -245
- package/dist/chunk-UZUHPHZC.js +0 -95
- package/dist/chunk-WBE7SQUB.js +0 -241
- package/dist/chunk-Y4WOJJM3.js +0 -147
- package/dist/commands/doctorCommand.js +0 -87
- package/dist/commands/headlessCommand.js +0 -380
- package/dist/commands/mcpCommand.js +0 -203
- package/dist/commands/updateCommand.js +0 -42
- package/dist/create-C4VEEEYR.js +0 -12
- package/dist/createFile-6PSPLW6R.js +0 -71
- package/dist/deleteFile-AUSRLWIK.js +0 -73
- package/dist/formatConverter-5QEJDW24.js +0 -7
- package/dist/globFiles-TSRN64N2.js +0 -120
- package/dist/grepSearch-634XWZOJ.js +0 -216
- package/dist/index.js +0 -6779
- package/dist/llmMarkdownGenerator-Z6NB26TT.js +0 -371
- package/dist/markdownGenerator-SK2ZQQL4.js +0 -269
- package/dist/mementoService-N4IM6QAC.js +0 -12
- package/dist/notificationDeduplicator-HUC53NEW.js +0 -9
- package/dist/src-F4KZCAA2.js +0 -319
- package/dist/src-ISX322I7.js +0 -1101
- package/dist/store-CAB6BV3P.js +0 -11
- package/dist/subtractCredits-D4KEM6VU.js +0 -12
- package/dist/terminalSetup-C5FHMLC3.js +0 -214
- package/dist/treeSitterEngine-4SGFQDY3.js +0 -330
- package/dist/types-KB5NP6T4.js +0 -7
- package/dist/utils-JCHWDM4Z.js +0 -31
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
ConfigStore
|
|
4
|
-
} from "../chunk-J6ZBI6TI.js";
|
|
5
|
-
import "../chunk-JW3JRHH7.js";
|
|
6
|
-
import "../chunk-4BIBE3J7.js";
|
|
7
|
-
|
|
8
|
-
// src/commands/mcpCommand.ts
|
|
9
|
-
async function handleMcpCommand(subcommand, argv) {
|
|
10
|
-
const configStore = new ConfigStore();
|
|
11
|
-
const config = await configStore.load();
|
|
12
|
-
switch (subcommand) {
|
|
13
|
-
case "list":
|
|
14
|
-
await handleList(config);
|
|
15
|
-
break;
|
|
16
|
-
case "add": {
|
|
17
|
-
if (!argv.name) {
|
|
18
|
-
console.error("\u274C Usage: b4m mcp add <name> -- <command> [args...]");
|
|
19
|
-
console.error("");
|
|
20
|
-
console.error("The -- separator is required to separate the server name from the command.");
|
|
21
|
-
console.error("");
|
|
22
|
-
console.error("Examples:");
|
|
23
|
-
console.error(" b4m mcp add context7 -- npx -y @upstash/context7-mcp");
|
|
24
|
-
console.error(" b4m mcp add github -- docker run -i ghcr.io/modelcontextprotocol/servers/github");
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
const dashDashIndex = process.argv.indexOf("--");
|
|
28
|
-
if (dashDashIndex === -1) {
|
|
29
|
-
console.error("\u274C Missing -- separator");
|
|
30
|
-
console.error("");
|
|
31
|
-
console.error("Usage: b4m mcp add <name> -- <command> [args...]");
|
|
32
|
-
console.error("");
|
|
33
|
-
console.error("The -- separator is required to separate the server name from the command.");
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
const commandParts = process.argv.slice(dashDashIndex + 1);
|
|
37
|
-
if (commandParts.length === 0) {
|
|
38
|
-
console.error("\u274C No command specified after --");
|
|
39
|
-
console.error("");
|
|
40
|
-
console.error("Usage: b4m mcp add <name> -- <command> [args...]");
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
const command = commandParts[0];
|
|
44
|
-
const args = commandParts.slice(1);
|
|
45
|
-
await handleAdd(config, argv.name, command, args, configStore);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
case "remove":
|
|
49
|
-
if (!argv.name) {
|
|
50
|
-
console.error("\u274C Usage: b4m mcp remove <name>");
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
await handleRemove(config, argv.name, configStore);
|
|
54
|
-
break;
|
|
55
|
-
case "enable":
|
|
56
|
-
if (!argv.name) {
|
|
57
|
-
console.error("\u274C Usage: b4m mcp enable <name>");
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
await handleEnable(config, argv.name, configStore);
|
|
61
|
-
break;
|
|
62
|
-
case "disable":
|
|
63
|
-
if (!argv.name) {
|
|
64
|
-
console.error("\u274C Usage: b4m mcp disable <name>");
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
await handleDisable(config, argv.name, configStore);
|
|
68
|
-
break;
|
|
69
|
-
default:
|
|
70
|
-
console.error(`\u274C Unknown MCP subcommand: ${subcommand}`);
|
|
71
|
-
console.error("");
|
|
72
|
-
console.error("Available commands:");
|
|
73
|
-
console.error(" b4m mcp list - List configured MCP servers");
|
|
74
|
-
console.error(" b4m mcp add <name> -- <command> - Add a new MCP server");
|
|
75
|
-
console.error(" b4m mcp remove <name> - Remove an MCP server");
|
|
76
|
-
console.error(" b4m mcp enable <name> - Enable an MCP server");
|
|
77
|
-
console.error(" b4m mcp disable <name> - Disable an MCP server");
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function handleList(config) {
|
|
82
|
-
if (config.mcpServers.length === 0) {
|
|
83
|
-
console.log("\u{1F4E1} No MCP servers configured.");
|
|
84
|
-
console.log("");
|
|
85
|
-
console.log("To add an MCP server:");
|
|
86
|
-
console.log(" b4m mcp add <name> -- <command> [args...]");
|
|
87
|
-
console.log("");
|
|
88
|
-
console.log("Examples:");
|
|
89
|
-
console.log(" b4m mcp add context7 -- npx -y @upstash/context7-mcp");
|
|
90
|
-
console.log(" b4m mcp add github -- docker run -i ghcr.io/modelcontextprotocol/servers/github");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
console.log("\u{1F4E1} Configured MCP Servers:\n");
|
|
94
|
-
for (const server of config.mcpServers) {
|
|
95
|
-
const status = server.enabled ? "\u2705 Enabled" : "\u23F8\uFE0F Disabled";
|
|
96
|
-
const commandInfo = server.command ? `${server.command} ${(server.args || []).join(" ")}` : "(internal)";
|
|
97
|
-
console.log(`\u2022 ${server.name} - ${status}`);
|
|
98
|
-
console.log(` Command: ${commandInfo}`);
|
|
99
|
-
if (Object.keys(server.env).length > 0) {
|
|
100
|
-
const envKeys = Object.keys(server.env).join(", ");
|
|
101
|
-
console.log(` Env vars: ${envKeys}`);
|
|
102
|
-
}
|
|
103
|
-
console.log("");
|
|
104
|
-
}
|
|
105
|
-
console.log("To manage servers:");
|
|
106
|
-
console.log(" b4m mcp add <name> -- <command> [args...] - Add server");
|
|
107
|
-
console.log(" b4m mcp remove <name> - Remove server");
|
|
108
|
-
console.log(" b4m mcp enable <name> - Enable server");
|
|
109
|
-
console.log(" b4m mcp disable <name> - Disable server");
|
|
110
|
-
}
|
|
111
|
-
async function handleAdd(config, name, command, args, configStore) {
|
|
112
|
-
const existing = config.mcpServers.find((s) => s.name === name);
|
|
113
|
-
if (existing) {
|
|
114
|
-
console.error(`\u274C MCP server "${name}" already exists.`);
|
|
115
|
-
console.error(' Use "b4m mcp remove" first to replace it.');
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
|
|
119
|
-
console.error("\u274C Server name must contain only alphanumeric characters, dashes, and underscores.");
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
const newServer = {
|
|
123
|
-
name,
|
|
124
|
-
command,
|
|
125
|
-
args,
|
|
126
|
-
env: {},
|
|
127
|
-
enabled: true
|
|
128
|
-
};
|
|
129
|
-
config.mcpServers.push(newServer);
|
|
130
|
-
try {
|
|
131
|
-
await configStore.save(config);
|
|
132
|
-
console.log(`\u2705 Added MCP server "${name}"`);
|
|
133
|
-
console.log("");
|
|
134
|
-
console.log("Configuration saved to: ~/.bike4mind/config.json");
|
|
135
|
-
console.log("");
|
|
136
|
-
console.log("The server will be available next time you start the CLI.");
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error(`\u274C Failed to save configuration:`, error instanceof Error ? error.message : String(error));
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async function handleRemove(config, name, configStore) {
|
|
143
|
-
const index = config.mcpServers.findIndex((s) => s.name === name);
|
|
144
|
-
if (index === -1) {
|
|
145
|
-
console.error(`\u274C MCP server "${name}" not found.`);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
config.mcpServers.splice(index, 1);
|
|
149
|
-
try {
|
|
150
|
-
await configStore.save(config);
|
|
151
|
-
console.log(`\u2705 Removed MCP server "${name}"`);
|
|
152
|
-
console.log("");
|
|
153
|
-
console.log("Configuration saved to: ~/.bike4mind/config.json");
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(`\u274C Failed to save configuration:`, error instanceof Error ? error.message : String(error));
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async function handleEnable(config, name, configStore) {
|
|
160
|
-
const server = config.mcpServers.find((s) => s.name === name);
|
|
161
|
-
if (!server) {
|
|
162
|
-
console.error(`\u274C MCP server "${name}" not found.`);
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
if (server.enabled) {
|
|
166
|
-
console.log(`\u2139\uFE0F MCP server "${name}" is already enabled.`);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
server.enabled = true;
|
|
170
|
-
try {
|
|
171
|
-
await configStore.save(config);
|
|
172
|
-
console.log(`\u2705 Enabled MCP server "${name}"`);
|
|
173
|
-
console.log("");
|
|
174
|
-
console.log("The server will connect next time you start the CLI.");
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.error(`\u274C Failed to save configuration:`, error instanceof Error ? error.message : String(error));
|
|
177
|
-
process.exit(1);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async function handleDisable(config, name, configStore) {
|
|
181
|
-
const server = config.mcpServers.find((s) => s.name === name);
|
|
182
|
-
if (!server) {
|
|
183
|
-
console.error(`\u274C MCP server "${name}" not found.`);
|
|
184
|
-
process.exit(1);
|
|
185
|
-
}
|
|
186
|
-
if (!server.enabled) {
|
|
187
|
-
console.log(`\u2139\uFE0F MCP server "${name}" is already disabled.`);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
server.enabled = false;
|
|
191
|
-
try {
|
|
192
|
-
await configStore.save(config);
|
|
193
|
-
console.log(`\u2705 Disabled MCP server "${name}"`);
|
|
194
|
-
console.log("");
|
|
195
|
-
console.log("The server will not connect next time you start the CLI.");
|
|
196
|
-
} catch (error) {
|
|
197
|
-
console.error(`\u274C Failed to save configuration:`, error instanceof Error ? error.message : String(error));
|
|
198
|
-
process.exit(1);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
export {
|
|
202
|
-
handleMcpCommand
|
|
203
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
forceCheckForUpdate,
|
|
4
|
-
package_default
|
|
5
|
-
} from "../chunk-SGPRXN4C.js";
|
|
6
|
-
|
|
7
|
-
// src/commands/updateCommand.ts
|
|
8
|
-
import { execSync } from "child_process";
|
|
9
|
-
async function handleUpdateCommand() {
|
|
10
|
-
const currentVersion = package_default.version;
|
|
11
|
-
console.log(`Current version: v${currentVersion}`);
|
|
12
|
-
console.log("Checking for updates...\n");
|
|
13
|
-
const result = await forceCheckForUpdate(currentVersion);
|
|
14
|
-
if (!result) {
|
|
15
|
-
console.error("Failed to check for updates. Check your internet connection.");
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
if (!result.updateAvailable) {
|
|
19
|
-
console.log(`Already on the latest version (v${currentVersion}).`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
console.log(`Update available: v${currentVersion} \u2192 v${result.latestVersion}
|
|
23
|
-
`);
|
|
24
|
-
console.log("Installing update...\n");
|
|
25
|
-
try {
|
|
26
|
-
execSync("npm install -g @bike4mind/cli@latest", {
|
|
27
|
-
stdio: "inherit",
|
|
28
|
-
timeout: 12e4
|
|
29
|
-
});
|
|
30
|
-
console.log(`
|
|
31
|
-
Successfully updated to v${result.latestVersion}.`);
|
|
32
|
-
} catch {
|
|
33
|
-
console.error("\nUpdate failed. Try running manually:");
|
|
34
|
-
console.error(" npm install -g @bike4mind/cli@latest");
|
|
35
|
-
console.error("\nIf you get permission errors, try:");
|
|
36
|
-
console.error(" sudo npm install -g @bike4mind/cli@latest");
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
handleUpdateCommand
|
|
42
|
-
};
|
package/dist/create-C4VEEEYR.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
assertPathAllowed
|
|
4
|
-
} from "./chunk-LTLJRF6I.js";
|
|
5
|
-
|
|
6
|
-
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/createFile/index.js
|
|
7
|
-
import { promises as fs } from "fs";
|
|
8
|
-
import { existsSync } from "fs";
|
|
9
|
-
import path from "path";
|
|
10
|
-
async function createFile(params, allowedDirectories) {
|
|
11
|
-
const { path: filePath, content, createDirectories = true } = params;
|
|
12
|
-
const resolvedPath = assertPathAllowed(filePath, allowedDirectories, "create");
|
|
13
|
-
const fileExists = existsSync(resolvedPath);
|
|
14
|
-
const action = fileExists ? "overwritten" : "created";
|
|
15
|
-
if (createDirectories) {
|
|
16
|
-
const dir = path.dirname(resolvedPath);
|
|
17
|
-
await fs.mkdir(dir, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
await fs.writeFile(resolvedPath, content, "utf-8");
|
|
20
|
-
const stats = await fs.stat(resolvedPath);
|
|
21
|
-
const lines = content.split("\n").length;
|
|
22
|
-
return `File ${action} successfully: ${filePath}
|
|
23
|
-
Size: ${stats.size} bytes
|
|
24
|
-
Lines: ${lines}`;
|
|
25
|
-
}
|
|
26
|
-
var createFileTool = {
|
|
27
|
-
name: "create_file",
|
|
28
|
-
implementation: (context) => ({
|
|
29
|
-
toolFn: async (value) => {
|
|
30
|
-
const params = value;
|
|
31
|
-
const fileExists = existsSync(path.resolve(process.cwd(), path.normalize(params.path)));
|
|
32
|
-
context.logger.info(`\u{1F4DD} CreateFile: ${fileExists ? "Overwriting" : "Creating"} file`, {
|
|
33
|
-
path: params.path,
|
|
34
|
-
size: params.content.length
|
|
35
|
-
});
|
|
36
|
-
try {
|
|
37
|
-
const result = await createFile(params, context.allowedDirectories);
|
|
38
|
-
context.logger.info("\u2705 CreateFile: Success", { path: params.path });
|
|
39
|
-
return result;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
context.logger.error("\u274C CreateFile: Failed", error);
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
toolSchema: {
|
|
46
|
-
name: "create_file",
|
|
47
|
-
description: "Create a new file or overwrite an existing file with the provided content. Will create parent directories if they do not exist. Restricted to current working directory for security. Always prompts user for confirmation before writing.",
|
|
48
|
-
parameters: {
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
path: {
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "Path where the file should be created (relative to current working directory)"
|
|
54
|
-
},
|
|
55
|
-
content: {
|
|
56
|
-
type: "string",
|
|
57
|
-
description: "Content to write to the file"
|
|
58
|
-
},
|
|
59
|
-
createDirectories: {
|
|
60
|
-
type: "boolean",
|
|
61
|
-
description: "Create parent directories if they do not exist (default: true)"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
required: ["path", "content"]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
};
|
|
69
|
-
export {
|
|
70
|
-
createFileTool
|
|
71
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
assertPathAllowed
|
|
4
|
-
} from "./chunk-LTLJRF6I.js";
|
|
5
|
-
|
|
6
|
-
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/deleteFile/index.js
|
|
7
|
-
import { promises as fs } from "fs";
|
|
8
|
-
import { existsSync, statSync } from "fs";
|
|
9
|
-
import path from "path";
|
|
10
|
-
async function deleteFile(params, allowedDirectories) {
|
|
11
|
-
const { path: filePath, recursive = false } = params;
|
|
12
|
-
const resolvedPath = assertPathAllowed(filePath, allowedDirectories, "delete");
|
|
13
|
-
if (!existsSync(resolvedPath)) {
|
|
14
|
-
throw new Error(`File or directory not found: ${filePath}`);
|
|
15
|
-
}
|
|
16
|
-
const stats = statSync(resolvedPath);
|
|
17
|
-
const isDirectory = stats.isDirectory();
|
|
18
|
-
const size = stats.size;
|
|
19
|
-
if (isDirectory && !recursive) {
|
|
20
|
-
throw new Error(`Path is a directory: ${filePath}. Use recursive=true to delete directories and their contents.`);
|
|
21
|
-
}
|
|
22
|
-
if (isDirectory) {
|
|
23
|
-
await fs.rm(resolvedPath, { recursive: true, force: true });
|
|
24
|
-
return `Directory deleted successfully: ${filePath}`;
|
|
25
|
-
} else {
|
|
26
|
-
await fs.unlink(resolvedPath);
|
|
27
|
-
return `File deleted successfully: ${filePath}
|
|
28
|
-
Size: ${size} bytes`;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
var deleteFileTool = {
|
|
32
|
-
name: "delete_file",
|
|
33
|
-
implementation: (context) => ({
|
|
34
|
-
toolFn: async (value) => {
|
|
35
|
-
const params = value;
|
|
36
|
-
const resolvedPath = path.resolve(process.cwd(), path.normalize(params.path));
|
|
37
|
-
const isDirectory = existsSync(resolvedPath) && statSync(resolvedPath).isDirectory();
|
|
38
|
-
context.logger.info(`\u{1F5D1}\uFE0F DeleteFile: Deleting ${isDirectory ? "directory" : "file"}`, {
|
|
39
|
-
path: params.path,
|
|
40
|
-
recursive: params.recursive
|
|
41
|
-
});
|
|
42
|
-
try {
|
|
43
|
-
const result = await deleteFile(params, context.allowedDirectories);
|
|
44
|
-
context.logger.info("\u2705 DeleteFile: Success", { path: params.path });
|
|
45
|
-
return result;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
context.logger.error("\u274C DeleteFile: Failed", error);
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
toolSchema: {
|
|
52
|
-
name: "delete_file",
|
|
53
|
-
description: "Delete a file or directory. For directories, recursive option must be enabled. Restricted to current working directory for security. Always prompts user for confirmation before deletion.",
|
|
54
|
-
parameters: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: {
|
|
57
|
-
path: {
|
|
58
|
-
type: "string",
|
|
59
|
-
description: "Path to the file or directory to delete (relative to current working directory)"
|
|
60
|
-
},
|
|
61
|
-
recursive: {
|
|
62
|
-
type: "boolean",
|
|
63
|
-
description: "Required to delete directories and their contents (default: false). Use with caution as this will delete all files and subdirectories."
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
required: ["path"]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
|
-
export {
|
|
72
|
-
deleteFileTool
|
|
73
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
isPathAllowed
|
|
4
|
-
} from "./chunk-LTLJRF6I.js";
|
|
5
|
-
|
|
6
|
-
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/globFiles/index.js
|
|
7
|
-
import { glob } from "glob";
|
|
8
|
-
import { stat } from "fs/promises";
|
|
9
|
-
import path from "path";
|
|
10
|
-
var DEFAULT_IGNORE_PATTERNS = [
|
|
11
|
-
"**/node_modules/**",
|
|
12
|
-
"**/.git/**",
|
|
13
|
-
"**/dist/**",
|
|
14
|
-
"**/build/**",
|
|
15
|
-
"**/.next/**",
|
|
16
|
-
"**/coverage/**",
|
|
17
|
-
"**/.turbo/**",
|
|
18
|
-
"**/.sst/**",
|
|
19
|
-
"**/*.min.js",
|
|
20
|
-
"**/*.min.css"
|
|
21
|
-
];
|
|
22
|
-
async function findFiles(params, allowedDirectories) {
|
|
23
|
-
const { pattern, dir_path, case_sensitive = true, respect_git_ignore = true } = params;
|
|
24
|
-
const baseCwd = process.cwd();
|
|
25
|
-
const targetDir = dir_path ? path.resolve(baseCwd, path.normalize(dir_path)) : baseCwd;
|
|
26
|
-
const validation = isPathAllowed(targetDir, allowedDirectories);
|
|
27
|
-
if (!validation.allowed) {
|
|
28
|
-
const dirsMsg = allowedDirectories && allowedDirectories.length > 0 ? `Allowed directories: ${[baseCwd, ...allowedDirectories].join(", ")}` : `Working directory: ${baseCwd}`;
|
|
29
|
-
throw new Error(`Access denied: Cannot search outside allowed directories. ${dirsMsg}`);
|
|
30
|
-
}
|
|
31
|
-
const ignorePatterns = respect_git_ignore ? DEFAULT_IGNORE_PATTERNS : [];
|
|
32
|
-
const matches = await glob(pattern, {
|
|
33
|
-
cwd: targetDir,
|
|
34
|
-
dot: false,
|
|
35
|
-
// Don't match hidden files by default
|
|
36
|
-
ignore: ignorePatterns,
|
|
37
|
-
absolute: true,
|
|
38
|
-
nodir: true,
|
|
39
|
-
// Only return files, not directories
|
|
40
|
-
nocase: !case_sensitive,
|
|
41
|
-
// Case-insensitive if requested
|
|
42
|
-
maxDepth: 20
|
|
43
|
-
// Reasonable depth limit
|
|
44
|
-
});
|
|
45
|
-
if (matches.length === 0) {
|
|
46
|
-
return `No files found matching pattern: ${pattern}${dir_path ? ` in ${dir_path}` : ""}`;
|
|
47
|
-
}
|
|
48
|
-
const filesWithStats = [];
|
|
49
|
-
for (const filePath of matches) {
|
|
50
|
-
try {
|
|
51
|
-
const stats = await stat(filePath);
|
|
52
|
-
filesWithStats.push({
|
|
53
|
-
path: filePath,
|
|
54
|
-
mtime: stats.mtimeMs
|
|
55
|
-
});
|
|
56
|
-
} catch {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
filesWithStats.sort((a, b) => b.mtime - a.mtime);
|
|
61
|
-
const MAX_RESULTS = 500;
|
|
62
|
-
const truncated = filesWithStats.length > MAX_RESULTS;
|
|
63
|
-
const results = truncated ? filesWithStats.slice(0, MAX_RESULTS) : filesWithStats;
|
|
64
|
-
const summary = `Found ${filesWithStats.length} file(s)${truncated ? ` (showing first ${MAX_RESULTS})` : ""} matching: ${pattern}`;
|
|
65
|
-
const dirInfo = dir_path ? `
|
|
66
|
-
Directory: ${dir_path}` : "";
|
|
67
|
-
const filesList = results.map((file) => path.relative(baseCwd, file.path)).join("\n");
|
|
68
|
-
return `${summary}${dirInfo}
|
|
69
|
-
|
|
70
|
-
${filesList}`;
|
|
71
|
-
}
|
|
72
|
-
var globFilesTool = {
|
|
73
|
-
name: "glob_files",
|
|
74
|
-
implementation: (context) => ({
|
|
75
|
-
toolFn: async (value) => {
|
|
76
|
-
const params = value;
|
|
77
|
-
context.logger.info("\u{1F50D} GlobFiles: Finding files", {
|
|
78
|
-
pattern: params.pattern,
|
|
79
|
-
dir_path: params.dir_path || "."
|
|
80
|
-
});
|
|
81
|
-
try {
|
|
82
|
-
const result = await findFiles(params, context.allowedDirectories);
|
|
83
|
-
context.logger.info("\u2705 GlobFiles: Success");
|
|
84
|
-
return result;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
context.logger.error("\u274C GlobFiles: Failed", error);
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
toolSchema: {
|
|
91
|
-
name: "glob_files",
|
|
92
|
-
description: "Efficiently finds files matching specific glob patterns (e.g., `src/**/*.ts`, `**/*.md`), returning absolute paths sorted by modification time (newest first). Use this to locate files by name or extension when you need to discover or explore files in a project.",
|
|
93
|
-
parameters: {
|
|
94
|
-
type: "object",
|
|
95
|
-
properties: {
|
|
96
|
-
pattern: {
|
|
97
|
-
type: "string",
|
|
98
|
-
description: 'The glob pattern to match against file paths. Supports wildcards (*, **), character ranges ([abc]), and brace expansion ({ts,tsx}). Examples: "*.ts" for TypeScript files in current dir, "src/**/*.tsx" for all TSX files in src tree, "**/*.{js,ts}" for all JS/TS files.'
|
|
99
|
-
},
|
|
100
|
-
dir_path: {
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "Optional: The absolute path to the directory to search in. If not specified, uses the current working directory. Must be within the current working directory."
|
|
103
|
-
},
|
|
104
|
-
case_sensitive: {
|
|
105
|
-
type: "boolean",
|
|
106
|
-
description: "Optional: Whether the pattern matching should be case-sensitive. Defaults to true. Set to false for case-insensitive matching on case-sensitive file systems."
|
|
107
|
-
},
|
|
108
|
-
respect_git_ignore: {
|
|
109
|
-
type: "boolean",
|
|
110
|
-
description: "Optional: Whether to respect common ignore patterns (node_modules, .git, dist, build, etc.). Defaults to true. Set to false to include all files."
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
required: ["pattern"]
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
};
|
|
118
|
-
export {
|
|
119
|
-
globFilesTool
|
|
120
|
-
};
|