src / index.ts
import { type PluginContext } from "@lmstudio/sdk";
import { z } from 'zod'
import { tool } from '@lmstudio/sdk'
import { run, isCdCommand } from '@/utils'
const Bash = tool({
name: 'Bash',
description: 'run a shell command',
parameters: {
command: z.string(),
cwd: z.string().optional().describe('Working directory to run the command in')
},
implementation: async ({ command, cwd }) => {
if (isCdCommand(command)) {
return 'Do not use "cd" in commands. Instead, use the "cwd" parameter to specify the working directory for this command.'
}
return await run(command, cwd)
}
})
const CD = tool({
name: 'CD',
description: 'change the current working directory',
parameters: { path: z.string().default('.') },
implementation: ({ path }) => process.chdir(path) ?? `current working directory set to \`${process.cwd()}\``
})
const Tree = tool({
name: 'Tree',
description: 'view directory tree (ignores build/dependency artifacts)',
parameters: { path: z.string() },
implementation: async ({ path }) => await run(`tree -I "node_modules|dist|build" ${path}`)
})
const Now = tool({
name: 'Now',
description: 'get the current date & time',
parameters: {},
implementation: () => new Date().toLocaleString()
})
const CWD = tool({
name: 'CWD',
description: 'list the current working directory',
parameters: {},
implementation: () => process.cwd()
})
const LS = tool({
name: 'LS',
description: 'list the contents of a directory',
parameters: { path: z.string() },
implementation: async ({ path }) => await run(`ls -la ${path}`)
})
export async function main(context: PluginContext) {
context.withToolsProvider(() => Promise.resolve([Bash, CD, Now, Tree, CWD, LS]));
}