Project Files
dist / toolsProvider.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolsProvider = toolsProvider;
const sdk_1 = require("@lmstudio/sdk");
const fs_1 = require("fs");
const zod_1 = require("zod");
const orchestrator_1 = require("./orchestrator");
const store_1 = require("./memory/store");
const workspace_1 = require("./workspace");
async function toolsProvider(ctl) {
const tools = [];
function getWorkspaceRoot() {
return ctl.getWorkingDirectory();
}
tools.push((0, sdk_1.tool)({
name: "forge_list_files",
description: "List files in the current workspace or a subdirectory.",
parameters: {
dir: zod_1.z.string().default("."),
max_depth: zod_1.z.number().int().min(1).max(12).default(8),
},
implementation: async ({ dir, max_depth }) => {
const workspaceRoot = getWorkspaceRoot();
const files = await (0, workspace_1.listWorkspaceFiles)(workspaceRoot, dir, max_depth);
return JSON.stringify(files, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_read_file",
description: "Read a text file in the current workspace.",
parameters: {
file_path: zod_1.z.string(),
},
implementation: async ({ file_path }) => {
const workspaceRoot = getWorkspaceRoot();
return await (0, workspace_1.readWorkspaceFile)(workspaceRoot, file_path);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_write_file",
description: "Write a text file in the current workspace.",
parameters: {
file_path: zod_1.z.string(),
content: zod_1.z.string(),
overwrite: zod_1.z.boolean().default(true),
},
implementation: async ({ file_path, content, overwrite }) => {
const workspaceRoot = getWorkspaceRoot();
if (!overwrite && (0, fs_1.existsSync)((0, workspace_1.resolveWithin)(workspaceRoot, file_path))) {
return "Error: File already exists.";
}
await (0, workspace_1.writeWorkspaceFile)(workspaceRoot, file_path, content);
return JSON.stringify({ ok: true, file_path, bytes: content.length }, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_apply_patch",
description: "Apply a diff-style patch to a workspace file.",
parameters: {
file_path: zod_1.z.string(),
operation: zod_1.z.enum([
"overwrite",
"replace",
"insert_before",
"insert_after",
"delete",
]),
target: zod_1.z.string().optional(),
content: zod_1.z.string().optional(),
},
implementation: async ({ file_path, operation, target, content }) => {
const workspaceRoot = getWorkspaceRoot();
const result = await (0, workspace_1.applyPatchToFile)(workspaceRoot, {
file: file_path,
operation,
target,
content,
});
return JSON.stringify(result, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_add_memory",
description: "Store a long-term memory entry for future plugin builds.",
parameters: {
kind: zod_1.z.string(),
content: zod_1.z.string(),
meta: zod_1.z.any().optional(),
},
implementation: async ({ kind, content, meta }) => {
const workspaceRoot = getWorkspaceRoot();
const memory = new store_1.MemoryStore(workspaceRoot);
const record = await memory.add(kind, content, meta ?? {});
return JSON.stringify(record, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_search_memory",
description: "Search the long-term memory store.",
parameters: {
query: zod_1.z.string(),
limit: zod_1.z.number().int().min(1).max(20).default(8),
},
implementation: async ({ query, limit }) => {
const workspaceRoot = getWorkspaceRoot();
const memory = new store_1.MemoryStore(workspaceRoot);
const items = await memory.search(query, limit);
return JSON.stringify(items, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_autobuild",
description: "Build or repair an LM Studio plugin. target_dir may be a relative workspace label or a full Windows/absolute path.",
parameters: {
spec: zod_1.z.string(),
target_dir: zod_1.z.string().optional(),
max_rounds: zod_1.z.number().int().min(1).max(8).default(4),
},
implementation: async ({ spec, target_dir, max_rounds }) => {
const workspaceRoot = getWorkspaceRoot();
const memory = new store_1.MemoryStore(workspaceRoot);
const builder = new orchestrator_1.AutoBuilder(ctl.client, workspaceRoot, memory);
const result = await builder.build(spec, {
targetDir: target_dir,
maxRounds: max_rounds,
});
return JSON.stringify(result, null, 2);
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_delete_file",
description: "Delete a file in the current workspace.",
parameters: {
file_path: zod_1.z.string(),
},
implementation: async ({ file_path }) => {
const workspaceRoot = getWorkspaceRoot();
try {
await (0, workspace_1.deleteWorkspaceFile)(workspaceRoot, file_path);
return JSON.stringify({ ok: true, path: file_path }, null, 2);
}
catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : "Unknown error" }, null, 2);
}
},
}));
tools.push((0, sdk_1.tool)({
name: "forge_move_file",
description: "Move or rename a file in the current workspace.",
parameters: {
old_path: zod_1.z.string(),
new_path: zod_1.z.string(),
},
implementation: async ({ old_path, new_path }) => {
const workspaceRoot = getWorkspaceRoot();
try {
await (0, workspace_1.moveWorkspaceFile)(workspaceRoot, old_path, new_path);
return JSON.stringify({ ok: true, from: old_path, to: new_path }, null, 2);
}
catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : "Unknown error" }, null, 2);
}
},
}));
return tools;
}