UNPKG

@plastichub/osr-ai-tools

Version:

CLI and library for LLM tools

429 lines 1.01 MB
[ { "model": "anthropic/claude-3.5-sonnet", "messages": [ { "role": "system", "content": "You are a helpful assistant that modifies existing project files based on user requirements." }, { "role": "system", "content": "for Typescript boilerplates, use this layout for CLI projects: \nsrc/index.ts (create ts logger)\nsrc/main.ts (yargs main entry)\nsrc/constants.ts (tslog logger name)\nsrc/zod_schemas.ts (all zod schemas go here)\nsrc/commands/index.ts (register all commands from src/commands/** here, commands always import functions from src/lib/category )\nsrc/commands/types.ts (command to write zod schemas to Typescript interfaces)\npackage.json (leave dependencies empty, add common scripts)" }, { "role": "system", "content": "when using yargs, all commands are async" }, { "role": "user", "content": "for Typescript, dont use chalk, commander, ora, or any other fancy library, just use the basics, always use imports, never require. use tslog, yargs, axios and Zod whenevern possible" }, { "role": "user", "content": "## Filesystem \r\n\r\nFor filesystem operations, use\r\n\r\nimport { sync as rm } from '@plastichub/fs/remove' (path)\r\nimport { sync as dir } from '@plastichub/fs/dir' (path)\r\nimport { sync as write } from '@plastichub/fs/write' (path, content)\r\nimport { sync as read } from '@plastichub/fs/read' (path)\r\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob' (directory,glob | glob[])\r\n\r\n## Configuration\r\n\r\nAPI keys and other settings:\r\n\r\n```ts\r\nimport { CONFIG_DEFAULT } from '@plastichub/osr-commons'\r\nexport const foo = (yarg) => {\r\n const config = CONFIG_DEFAULT(args.env_key) as any\r\n if (!config) {\r\n logger.warn('No config found!')\r\n return\r\n }\r\n if (config && !config.openai.key) {\r\n logger.warn('No OpenAI key found in config!')\r\n return\r\n }\r\n const api_key = argv.openai_key || process.env.OPENAI_API_KEY || config.openai.key\r\n}\r\n```\r\n\r\n## Zod Schemas\r\n\r\nThe framework provides tools to convert from a Zod schema to Yargs as follows\r\n\r\n```ts\r\n\r\nimport { toYargs } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas.ts'\r\n// example : const options = (yargs: CLI.Argv) => toYargs(yargs, MySchema())\r\n```\r\n\r\nAdditionally, all Zod schemas will be exported on demand, via Yargs command \"types\"\r\n\r\n```ts\r\nimport { generate_interfaces } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas'\r\n\r\nexport const types = () => generate_interfaces(\r\n [\r\n MySchema()\r\n ], 'src/zod_types.ts')\r\n```\r\n\r\n### Logging\r\n\r\nEach package has a tslog factory at src/index.ts. Use it for all commands and library functions\r\n\r\n```ts\r\nexport { Logger } from 'tslog'\r\nimport { createLogger } from '@plastichub/osr-log'\r\nimport { Logger } from 'tslog'\r\nexport const logger:Logger<unknown> = createLogger('Package Name')\r\n```\r\n\r\n\r\nLLM Tools are specified as follows\r\n\r\n- always export \"tools\" as the main function\r\n- dont register LLM tools as yarg commands\r\n- seperate the tool's implementation in src/lib/tools\r\n- LLM tools require 'openai' as dependency\r\n\r\neg: src/tools/fs:\r\n\r\n```ts\r\nimport { join } from 'path'\r\nimport * as path from 'path'\r\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction'\r\nimport { isString } from '@plastichub/core/primitives'\r\nimport { sync as dir } from '@plastichub/fs/dir'\r\nimport { sync as write } from '@plastichub/fs/write'\r\nimport { logger } from '../'\r\n\r\nexport const tools = (target:any): Array<any> => {\r\n return [\r\n {\r\n type: 'function',\r\n function: {\r\n name: \"read_file\",\r\n description: \"read a file, at given a path\",\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n file: {\r\n type: \"object\",\r\n properties: {\r\n path: { type: \"string\" }\r\n }\r\n }\r\n },\r\n required: [\"file\"],\r\n },\r\n function: async (ret) => {\r\n try {\r\n const { file } = ret as any\r\n const filePath = join(target, file.path)\r\n logger.debug(`Tool::ReadFile Reading file ${filePath}`)\r\n } catch (error) {\r\n logger.error(`Error reading file`, error)\r\n } \r\n },\r\n parse: JSON.parse\r\n }\r\n } as RunnableToolFunction<{ id: string }>\r\n ]\r\n}\r\n```\r\n### Typescript tsconfig\r\n\r\nUse this defaults\r\n\r\n```json\r\n\"compilerOptions\": {\r\n \"target\": \"ES2020\",\r\n \"module\": \"commonjs\",\r\n \"outDir\": \"./dist\",\r\n \"rootDir\": \"./src\",\r\n \"strict\": true,\r\n \"esModuleInterop\": true,\r\n \"skipLibCheck\": true,\r\n \"allowJs\": true,\r\n \"noImplicitAny\": false,\r\n \"strictNullChecks\": false,\r\n \"forceConsistentCasingInFileNames\": true\r\n },\r\n```\r\n\r\n### Yargs\r\n\r\nCommands are registered as follows (src/command/index.ts) :\r\n\r\n```ts\r\nimport type { Argv } from 'yargs'\r\nimport { types } from './types'\r\nexport const commands = (yargs: Argv) => \r\n{\r\n return yargs\r\n .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)\r\n .strict()\r\n .help()\r\n}\r\n```\r\n\r\n### Nodejs\r\n\r\n- import built-ins always as import * as 'path'\r\n" }, { "role": "user", "content": "Modify the following project files : Adjust all yargs code as instructed\n\nCurrent files:\n[\n {\n \"path\": \"package.json\",\n \"content\": \"{\\n \\\"name\\\": \\\"llm-tools-cli\\\",\\n \\\"version\\\": \\\"1.0.0\\\",\\n \\\"description\\\": \\\"CLI and library for LLM tools\\\",\\n \\\"main\\\": \\\"dist/index.js\\\",\\n \\\"bin\\\": {\\n \\\"llm-tools\\\": \\\"./dist/main.js\\\"\\n },\\n \\\"scripts\\\": {\\n \\\"build\\\": \\\"tsc\\\",\\n \\\"start\\\": \\\"node dist/main.js\\\",\\n \\\"dev\\\": \\\"ts-node src/main.ts\\\",\\n \\\"types\\\": \\\"ts-node src/main.ts types\\\"\\n },\\n \\\"dependencies\\\": {\\n \\\"@plastichub/core\\\": \\\"^0.2.6\\\",\\n \\\"@plastichub/fs\\\": \\\"^0.13.39\\\",\\n \\\"@plastichub/osr-commons\\\": \\\"^0.3.7\\\",\\n \\\"@plastichub/osr-log\\\": \\\"^0.1.1\\\",\\n \\\"axios\\\": \\\"^1.7.9\\\",\\n \\\"openai\\\": \\\"^4.76.3\\\",\\n \\\"tslog\\\": \\\"^4.9.3\\\",\\n \\\"yargs\\\": \\\"^17.7.2\\\",\\n \\\"zod\\\": \\\"^3.24.1\\\"\\n },\\n \\\"devDependencies\\\": {\\n \\\"@types/node\\\": \\\"^18.0.0\\\",\\n \\\"@types/yargs\\\": \\\"^17.0.0\\\",\\n \\\"ts-node\\\": \\\"^10.9.0\\\",\\n \\\"typescript\\\": \\\"^4.9.0\\\"\\n }\\n}\"\n },\n {\n \"path\": \"src\\\\zod_schemas.ts\",\n \"content\": \"import { z } from 'zod';\\n\\nexport const ListFilesSchema = z.object({\\n directory: z.string().describe('Directory path to list files from'),\\n pattern: z.string().optional().describe('Glob pattern for filtering files')\\n});\\n\\nexport const RemoveFileSchema = z.object({\\n path: z.string().describe('Path of the file to remove')\\n});\\n\"\n },\n {\n \"path\": \"src\\\\main.ts\",\n \"content\": \"#!/usr/bin/env node\\nimport * as yargs from 'yargs';\\nimport { commands } from './commands';\\n\\nasync function main() {\\n const argv = await commands(yargs).argv;\\n}\\n\\nmain().catch(console.error);\\n\"\n },\n {\n \"path\": \"src\\\\index.ts\",\n \"content\": \"import { Logger } from 'tslog';\\nimport { createLogger } from '@plastichub/osr-log';\\n\\nexport const logger: Logger<unknown> = createLogger('llm-tools-cli');\\n\"\n },\n {\n \"path\": \"src\\\\constants.ts\",\n \"content\": \"export const LOGGER_NAME = 'llm-tools-cli';\\n\"\n },\n {\n \"path\": \"src\\\\lib\\\\tools\\\\fs.ts\",\n \"content\": \"import * as path from 'path';\\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction';\\nimport { sync as dir } from '@plastichub/fs/dir';\\nimport { sync as rm } from '@plastichub/fs/remove';\\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob';\\nimport { logger } from '../../index';\\n\\nexport const tools = (target: string): Array<any> => {\\n return [\\n {\\n type: 'function',\\n function: {\\n name: 'list_files',\\n description: 'List all files in a directory',\\n parameters: {\\n type: 'object',\\n properties: {\\n directory: { type: 'string' },\\n pattern: { type: 'string', optional: true }\\n },\\n required: ['directory']\\n },\\n function: async (params: any) => {\\n try {\\n const directory = path.join(target, params.directory);\\n const pattern = params.pattern || '**/*';\\n logger.debug(`Tool::ListFiles Listing files in ${directory} with pattern ${pattern}`);\\n return glob(directory, [pattern]);\\n } catch (error) {\\n logger.error('Error listing files', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>,\\n {\\n type: 'function',\\n function: {\\n name: 'remove_file',\\n description: 'Remove a file at given path',\\n parameters: {\\n type: 'object',\\n properties: {\\n path: { type: 'string' }\\n },\\n required: ['path']\\n },\\n function: async (params: any) => {\\n try {\\n const filePath = path.join(target, params.path);\\n logger.debug(`Tool::RemoveFile Removing file ${filePath}`);\\n rm(filePath);\\n return true;\\n } catch (error) {\\n logger.error('Error removing file', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>\\n ];\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\types.ts\",\n \"content\": \"import { generate_interfaces } from '@plastichub/osr-commons';\\nimport { ListFilesSchema, RemoveFileSchema } from '../zod_schemas';\\n\\nexport const types = async () => {\\n return generate_interfaces([\\n ListFilesSchema,\\n RemoveFileSchema\\n ], 'src/zod_types.ts');\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\index.ts\",\n \"content\": \"import type { Argv } from 'yargs';\\nimport { types } from './types';\\n\\nexport const commands = (yargs: Argv) => {\\n return yargs\\n .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)\\n .strict()\\n .help();\\n};\\n\"\n }\n]" }, { "role": "user", "content": "Commit all files via git (tool)" }, { "role": "user", "content": "Update readme.md file, with setup instructions and usage (all commands and library functions)" } ], "tools": [ { "type": "function", "function": { "name": "modify_project_files", "description": "Modify existing project files", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "path", "content" ] } } }, "required": [ "files" ] } } }, { "type": "function", "function": { "name": "create_project_structure", "description": "Create project structure with files and folders", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "path", "content" ] } } }, "required": [ "files" ] } } }, { "type": "function", "function": { "name": "create_file", "description": "Creates a file, given a path and content", "parameters": { "type": "object", "properties": { "file": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } } } }, "required": [ "file" ] } } }, { "type": "function", "function": { "name": "read_file", "description": "read a file, at given a path", "parameters": { "type": "object", "properties": { "file": { "type": "object", "properties": { "path": { "type": "string" } } } }, "required": [ "file" ] } } }, { "type": "function", "function": { "name": "install_dependency", "description": "Install a dependency using npm", "parameters": { "type": "object", "properties": { "dependencies": { "type": "array", "items": { "type": "string" } } }, "required": [ "dependencies" ] } } }, { "type": "function", "function": { "name": "commit_files_git", "description": "Commit files using git", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "string" } }, "message": { "type": "string" } }, "required": [ "files" ] } } } ], "tool_choice": "auto", "ts": "2024-12-15T12:17:26.611Z" }, { "model": "anthropic/claude-3.5-sonnet", "messages": [ { "role": "system", "content": "You are a helpful assistant that modifies existing project files based on user requirements." }, { "role": "system", "content": "for Typescript boilerplates, use this layout for CLI projects: \nsrc/index.ts (create ts logger)\nsrc/main.ts (yargs main entry)\nsrc/constants.ts (tslog logger name)\nsrc/zod_schemas.ts (all zod schemas go here)\nsrc/commands/index.ts (register all commands from src/commands/** here, commands always import functions from src/lib/category )\nsrc/commands/types.ts (command to write zod schemas to Typescript interfaces)\npackage.json (leave dependencies empty, add common scripts)" }, { "role": "system", "content": "when using yargs, all commands are async" }, { "role": "user", "content": "for Typescript, dont use chalk, commander, ora, or any other fancy library, just use the basics, always use imports, never require. use tslog, yargs, axios and Zod whenevern possible" }, { "role": "user", "content": "## Filesystem \r\n\r\nFor filesystem operations, use\r\n\r\nimport { sync as rm } from '@plastichub/fs/remove' (path)\r\nimport { sync as dir } from '@plastichub/fs/dir' (path)\r\nimport { sync as write } from '@plastichub/fs/write' (path, content)\r\nimport { sync as read } from '@plastichub/fs/read' (path)\r\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob' (directory,glob | glob[])\r\n\r\n## Configuration\r\n\r\nAPI keys and other settings:\r\n\r\n```ts\r\nimport { CONFIG_DEFAULT } from '@plastichub/osr-commons'\r\nexport const foo = (yarg) => {\r\n const config = CONFIG_DEFAULT(args.env_key) as any\r\n if (!config) {\r\n logger.warn('No config found!')\r\n return\r\n }\r\n if (config && !config.openai.key) {\r\n logger.warn('No OpenAI key found in config!')\r\n return\r\n }\r\n const api_key = argv.openai_key || process.env.OPENAI_API_KEY || config.openai.key\r\n}\r\n```\r\n\r\n## Zod Schemas\r\n\r\nThe framework provides tools to convert from a Zod schema to Yargs as follows\r\n\r\n```ts\r\n\r\nimport { toYargs } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas.ts'\r\n// example : const options = (yargs: CLI.Argv) => toYargs(yargs, MySchema())\r\n```\r\n\r\nAdditionally, all Zod schemas will be exported on demand, via Yargs command \"types\"\r\n\r\n```ts\r\nimport { generate_interfaces } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas'\r\n\r\nexport const types = () => generate_interfaces(\r\n [\r\n MySchema()\r\n ], 'src/zod_types.ts')\r\n```\r\n\r\n### Logging\r\n\r\nEach package has a tslog factory at src/index.ts. Use it for all commands and library functions\r\n\r\n```ts\r\nexport { Logger } from 'tslog'\r\nimport { createLogger } from '@plastichub/osr-log'\r\nimport { Logger } from 'tslog'\r\nexport const logger:Logger<unknown> = createLogger('Package Name')\r\n```\r\n\r\n\r\nLLM Tools are specified as follows\r\n\r\n- always export \"tools\" as the main function\r\n- dont register LLM tools as yarg commands\r\n- seperate the tool's implementation in src/lib/tools\r\n- LLM tools require 'openai' as dependency\r\n\r\neg: src/tools/fs:\r\n\r\n```ts\r\nimport { join } from 'path'\r\nimport * as path from 'path'\r\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction'\r\nimport { isString } from '@plastichub/core/primitives'\r\nimport { sync as dir } from '@plastichub/fs/dir'\r\nimport { sync as write } from '@plastichub/fs/write'\r\nimport { logger } from '../'\r\n\r\nexport const tools = (target:any): Array<any> => {\r\n return [\r\n {\r\n type: 'function',\r\n function: {\r\n name: \"read_file\",\r\n description: \"read a file, at given a path\",\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n file: {\r\n type: \"object\",\r\n properties: {\r\n path: { type: \"string\" }\r\n }\r\n }\r\n },\r\n required: [\"file\"],\r\n },\r\n function: async (ret) => {\r\n try {\r\n const { file } = ret as any\r\n const filePath = join(target, file.path)\r\n logger.debug(`Tool::ReadFile Reading file ${filePath}`)\r\n } catch (error) {\r\n logger.error(`Error reading file`, error)\r\n } \r\n },\r\n parse: JSON.parse\r\n }\r\n } as RunnableToolFunction<{ id: string }>\r\n ]\r\n}\r\n```\r\n### Typescript tsconfig\r\n\r\nUse this defaults\r\n\r\n```json\r\n\"compilerOptions\": {\r\n \"target\": \"ES2020\",\r\n \"module\": \"commonjs\",\r\n \"outDir\": \"./dist\",\r\n \"rootDir\": \"./src\",\r\n \"strict\": true,\r\n \"esModuleInterop\": true,\r\n \"skipLibCheck\": true,\r\n \"allowJs\": true,\r\n \"noImplicitAny\": false,\r\n \"strictNullChecks\": false,\r\n \"forceConsistentCasingInFileNames\": true\r\n },\r\n```\r\n\r\n### Yargs\r\n\r\nCommands are registered as follows (src/command/index.ts) :\r\n\r\n```ts\r\nimport type { Argv } from 'yargs'\r\nimport { types } from './types'\r\nexport const commands = (yargs: Argv) => \r\n{\r\n return yargs\r\n .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)\r\n .strict()\r\n .help()\r\n}\r\n```\r\n\r\n### Nodejs\r\n\r\n- import built-ins always as import * as 'path'\r\n" }, { "role": "user", "content": "Modify the following project files : Adjust all yargs code as instructed\n\nCurrent files:\n[\n {\n \"path\": \"package.json\",\n \"content\": \"{\\n \\\"name\\\": \\\"llm-tools-cli\\\",\\n \\\"version\\\": \\\"1.0.0\\\",\\n \\\"description\\\": \\\"CLI and library for LLM tools\\\",\\n \\\"main\\\": \\\"dist/index.js\\\",\\n \\\"bin\\\": {\\n \\\"llm-tools\\\": \\\"./dist/main.js\\\"\\n },\\n \\\"scripts\\\": {\\n \\\"build\\\": \\\"tsc\\\",\\n \\\"start\\\": \\\"node dist/main.js\\\",\\n \\\"dev\\\": \\\"ts-node src/main.ts\\\",\\n \\\"types\\\": \\\"ts-node src/main.ts types\\\"\\n },\\n \\\"dependencies\\\": {\\n \\\"@plastichub/core\\\": \\\"^0.2.6\\\",\\n \\\"@plastichub/fs\\\": \\\"^0.13.39\\\",\\n \\\"@plastichub/osr-commons\\\": \\\"^0.3.7\\\",\\n \\\"@plastichub/osr-log\\\": \\\"^0.1.1\\\",\\n \\\"axios\\\": \\\"^1.7.9\\\",\\n \\\"openai\\\": \\\"^4.76.3\\\",\\n \\\"tslog\\\": \\\"^4.9.3\\\",\\n \\\"yargs\\\": \\\"^17.7.2\\\",\\n \\\"zod\\\": \\\"^3.24.1\\\"\\n },\\n \\\"devDependencies\\\": {\\n \\\"@types/node\\\": \\\"^18.0.0\\\",\\n \\\"@types/yargs\\\": \\\"^17.0.0\\\",\\n \\\"ts-node\\\": \\\"^10.9.0\\\",\\n \\\"typescript\\\": \\\"^4.9.0\\\"\\n }\\n}\"\n },\n {\n \"path\": \"Readme.md\",\n \"content\": \"# LLM Tools CLI\\n\\nA command-line interface and library for LLM (Language Model) tools with filesystem operations support.\\n\\n## Setup\\n\\n```bash\\n# Install dependencies\\nnpm install\\n\\n# Build the project\\nnpm run build\\n\\n# Create symlink for global usage\\nnpm link\\n```\\n\\n## Configuration\\n\\nThe application uses configuration files for API keys and settings. Create a configuration file with the following structure:\\n\\n```json\\n{\\n \\\"openai\\\": {\\n \\\"key\\\": \\\"your-openai-key\\\"\\n }\\n}\\n```\\n\\nThe configuration can be loaded using the `env_key` parameter or environment variables.\\n\\n## Commands\\n\\n### Generate TypeScript Types\\n\\nGenerate TypeScript interfaces from Zod schemas:\\n\\n```bash\\nllm-tools types\\n```\\n\\n## Library Functions\\n\\n### Filesystem Tools\\n\\nThe package provides LLM tools for filesystem operations:\\n\\n#### List Files\\n```typescript\\ninterface ListFilesParams {\\n directory: string; // Directory path to list files from\\n pattern?: string; // Optional glob pattern for filtering files\\n}\\n```\\n\\n#### Remove File\\n```typescript\\ninterface RemoveFileParams {\\n path: string; // Path of the file to remove\\n}\\n```\\n\\n### Development\\n\\n```bash\\n# Run in development mode\\nnpm run dev\\n\\n# Generate TypeScript interfaces\\nnpm run types\\n```\\n\\n## Project Structure\\n\\n```\\nsrc/\\n├── index.ts # Logger setup\\n├── main.ts # CLI entry point\\n├── constants.ts # Constants definition\\n├── zod_schemas.ts # Zod schema definitions\\n├── commands/\\n│ ├── index.ts # Command registration\\n│ └── types.ts # Types generation command\\n└── lib/\\n └── tools/\\n └── fs.ts # Filesystem tools implementation\\n```\\n\\n## Dependencies\\n\\n- tslog: Logging functionality\\n- yargs: CLI argument parsing\\n- zod: Schema validation\\n- axios: HTTP client\\n- openai: OpenAI API integration\\n- @plastichub packages: Filesystem and utility functions\\n\\n## License\\n\\nMIT\"\n },\n {\n \"path\": \"src\\\\zod_schemas.ts\",\n \"content\": \"import { z } from 'zod';\\n\\nexport const ListFilesSchema = z.object({\\n directory: z.string().describe('Directory path to list files from'),\\n pattern: z.string().optional().describe('Glob pattern for filtering files')\\n});\\n\\nexport const RemoveFileSchema = z.object({\\n path: z.string().describe('Path of the file to remove')\\n});\\n\"\n },\n {\n \"path\": \"src\\\\main.ts\",\n \"content\": \"#!/usr/bin/env node\\nimport * as yargs from 'yargs';\\nimport { commands } from './commands';\\nimport { logger } from './';\\n\\nasync function main() {\\n try {\\n const argv = await commands(yargs).argv;\\n } catch (error) {\\n logger.error('Error executing command:', error);\\n process.exit(1);\\n }\\n}\\n\\nmain();\"\n },\n {\n \"path\": \"src\\\\index.ts\",\n \"content\": \"import { Logger } from 'tslog';\\nimport { createLogger } from '@plastichub/osr-log';\\n\\nexport const logger: Logger<unknown> = createLogger('llm-tools-cli');\\n\"\n },\n {\n \"path\": \"src\\\\constants.ts\",\n \"content\": \"export const LOGGER_NAME = 'llm-tools-cli';\\n\"\n },\n {\n \"path\": \"src\\\\lib\\\\tools\\\\fs.ts\",\n \"content\": \"import * as path from 'path';\\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction';\\nimport { sync as dir } from '@plastichub/fs/dir';\\nimport { sync as rm } from '@plastichub/fs/remove';\\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob';\\nimport { logger } from '../../index';\\n\\nexport const tools = (target: string): Array<any> => {\\n return [\\n {\\n type: 'function',\\n function: {\\n name: 'list_files',\\n description: 'List all files in a directory',\\n parameters: {\\n type: 'object',\\n properties: {\\n directory: { type: 'string' },\\n pattern: { type: 'string', optional: true }\\n },\\n required: ['directory']\\n },\\n function: async (params: any) => {\\n try {\\n const directory = path.join(target, params.directory);\\n const pattern = params.pattern || '**/*';\\n logger.debug(`Tool::ListFiles Listing files in ${directory} with pattern ${pattern}`);\\n return glob(directory, [pattern]);\\n } catch (error) {\\n logger.error('Error listing files', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>,\\n {\\n type: 'function',\\n function: {\\n name: 'remove_file',\\n description: 'Remove a file at given path',\\n parameters: {\\n type: 'object',\\n properties: {\\n path: { type: 'string' }\\n },\\n required: ['path']\\n },\\n function: async (params: any) => {\\n try {\\n const filePath = path.join(target, params.path);\\n logger.debug(`Tool::RemoveFile Removing file ${filePath}`);\\n rm(filePath);\\n return true;\\n } catch (error) {\\n logger.error('Error removing file', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>\\n ];\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\types.ts\",\n \"content\": \"import { generate_interfaces } from '@plastichub/osr-commons';\\nimport { ListFilesSchema, RemoveFileSchema } from '../zod_schemas';\\n\\nexport const types = async () => {\\n return generate_interfaces([\\n ListFilesSchema,\\n RemoveFileSchema\\n ], 'src/zod_types.ts');\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\index.ts\",\n \"content\": \"import type { Argv } from 'yargs';\\nimport { types } from './types';\\nimport { CONFIG_DEFAULT } from '@plastichub/osr-commons';\\nimport { logger } from '../';\\n\\nexport const commands = (yargs: Argv) => {\\n return yargs\\n .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)\\n .option('env_key', {\\n type: 'string',\\n description: 'Environment configuration key'\\n })\\n .middleware([(argv) => {\\n const config = CONFIG_DEFAULT(argv.env_key) as any;\\n if (!config) {\\n logger.warn('No config found!');\\n return;\\n }\\n return config;\\n }])\\n .strict()\\n .help();\\n};\"\n }\n]" }, { "role": "user", "content": "Commit all files via git (tool)" }, { "role": "user", "content": "Update readme.md file, with setup instructions and usage (all commands and library functions)" } ], "tools": [ { "type": "function", "function": { "name": "modify_project_files", "description": "Modify existing project files", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "path", "content" ] } } }, "required": [ "files" ] } } }, { "type": "function", "function": { "name": "create_project_structure", "description": "Create project structure with files and folders", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } }, "required": [ "path", "content" ] } } }, "required": [ "files" ] } } }, { "type": "function", "function": { "name": "create_file", "description": "Creates a file, given a path and content", "parameters": { "type": "object", "properties": { "file": { "type": "object", "properties": { "path": { "type": "string" }, "content": { "type": "string" } } } }, "required": [ "file" ] } } }, { "type": "function", "function": { "name": "read_file", "description": "read a file, at given a path", "parameters": { "type": "object", "properties": { "file": { "type": "object", "properties": { "path": { "type": "string" } } } }, "required": [ "file" ] } } }, { "type": "function", "function": { "name": "install_dependency", "description": "Install a dependency using npm", "parameters": { "type": "object", "properties": { "dependencies": { "type": "array", "items": { "type": "string" } } }, "required": [ "dependencies" ] } } }, { "type": "function", "function": { "name": "commit_files_git", "description": "Commit files using git", "parameters": { "type": "object", "properties": { "files": { "type": "array", "items": { "type": "string" } }, "message": { "type": "string" } }, "required": [ "files" ] } } } ], "tool_choice": "auto", "ts": "2024-12-15T12:17:59.604Z" }, { "model": "anthropic/claude-3.5-sonnet", "messages": [ { "role": "system", "content": "You are a helpful assistant that modifies existing project files based on user requirements." }, { "role": "system", "content": "for Typescript boilerplates, use this layout for CLI projects: \nsrc/index.ts (create ts logger)\nsrc/main.ts (yargs main entry)\nsrc/constants.ts (tslog logger name)\nsrc/zod_schemas.ts (all zod schemas go here)\nsrc/commands/index.ts (register all commands from src/commands/** here, commands always import functions from src/lib/category )\nsrc/commands/types.ts (command to write zod schemas to Typescript interfaces)\npackage.json (leave dependencies empty, add common scripts)" }, { "role": "system", "content": "when using yargs, all commands are async" }, { "role": "user", "content": "for Typescript, dont use chalk, commander, ora, or any other fancy library, just use the basics, always use imports, never require. use tslog, yargs, axios and Zod whenevern possible" }, { "role": "user", "content": "## Filesystem \r\n\r\nFor filesystem operations, use\r\n\r\nimport { sync as rm } from '@plastichub/fs/remove' (path)\r\nimport { sync as dir } from '@plastichub/fs/dir' (path)\r\nimport { sync as write } from '@plastichub/fs/write' (path, content)\r\nimport { sync as read } from '@plastichub/fs/read' (path)\r\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob' (directory,glob | glob[])\r\n\r\n## Configuration\r\n\r\nAPI keys and other settings:\r\n\r\n```ts\r\nimport { CONFIG_DEFAULT } from '@plastichub/osr-commons'\r\nexport const foo = (yarg) => {\r\n const config = CONFIG_DEFAULT(args.env_key) as any\r\n if (!config) {\r\n logger.warn('No config found!')\r\n return\r\n }\r\n if (config && !config.openai.key) {\r\n logger.warn('No OpenAI key found in config!')\r\n return\r\n }\r\n const api_key = argv.openai_key || process.env.OPENAI_API_KEY || config.openai.key\r\n}\r\n```\r\n\r\n## Zod Schemas\r\n\r\nThe framework provides tools to convert from a Zod schema to Yargs as follows\r\n\r\n```ts\r\n\r\nimport { toYargs } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas.ts'\r\n// example : const options = (yargs: CLI.Argv) => toYargs(yargs, MySchema())\r\n```\r\n\r\nAdditionally, all Zod schemas will be exported on demand, via Yargs command \"types\"\r\n\r\n```ts\r\nimport { generate_interfaces } from '@plastichub/osr-commons'\r\nimport { MySchema } from 'src/schemas'\r\n\r\nexport const types = () => generate_interfaces(\r\n [\r\n MySchema()\r\n ], 'src/zod_types.ts')\r\n```\r\n\r\n### Logging\r\n\r\nEach package has a tslog factory at src/index.ts. Use it for all commands and library functions\r\n\r\n```ts\r\nexport { Logger } from 'tslog'\r\nimport { createLogger } from '@plastichub/osr-log'\r\nimport { Logger } from 'tslog'\r\nexport const logger:Logger<unknown> = createLogger('Package Name')\r\n```\r\n\r\n\r\nLLM Tools are specified as follows\r\n\r\n- always export \"tools\" as the main function\r\n- dont register LLM tools as yarg commands\r\n- seperate the tool's implementation in src/lib/tools\r\n- LLM tools require 'openai' as dependency\r\n\r\neg: src/tools/fs:\r\n\r\n```ts\r\nimport { join } from 'path'\r\nimport * as path from 'path'\r\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction'\r\nimport { isString } from '@plastichub/core/primitives'\r\nimport { sync as dir } from '@plastichub/fs/dir'\r\nimport { sync as write } from '@plastichub/fs/write'\r\nimport { logger } from '../'\r\n\r\nexport const tools = (target:any): Array<any> => {\r\n return [\r\n {\r\n type: 'function',\r\n function: {\r\n name: \"read_file\",\r\n description: \"read a file, at given a path\",\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n file: {\r\n type: \"object\",\r\n properties: {\r\n path: { type: \"string\" }\r\n }\r\n }\r\n },\r\n required: [\"file\"],\r\n },\r\n function: async (ret) => {\r\n try {\r\n const { file } = ret as any\r\n const filePath = join(target, file.path)\r\n logger.debug(`Tool::ReadFile Reading file ${filePath}`)\r\n } catch (error) {\r\n logger.error(`Error reading file`, error)\r\n } \r\n },\r\n parse: JSON.parse\r\n }\r\n } as RunnableToolFunction<{ id: string }>\r\n ]\r\n}\r\n```\r\n### Typescript tsconfig\r\n\r\nUse this defaults\r\n\r\n```json\r\n\"compilerOptions\": {\r\n \"target\": \"ES2020\",\r\n \"module\": \"commonjs\",\r\n \"outDir\": \"./dist\",\r\n \"rootDir\": \"./src\",\r\n \"strict\": true,\r\n \"esModuleInterop\": true,\r\n \"skipLibCheck\": true,\r\n \"allowJs\": true,\r\n \"noImplicitAny\": false,\r\n \"strictNullChecks\": false,\r\n \"forceConsistentCasingInFileNames\": true\r\n },\r\n```\r\n\r\n### Yargs\r\n\r\nCommands are registered as follows (src/command/index.ts) :\r\n\r\n```ts\r\nimport type { Argv } from 'yargs'\r\nimport { types } from './types'\r\nexport const commands = (yargs: Argv) => \r\n{\r\n return yargs\r\n .command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)\r\n .strict()\r\n .help()\r\n}\r\n```\r\n\r\n### Nodejs\r\n\r\n- import built-ins always as import * as 'path'\r\n" }, { "role": "user", "content": "Modify the following project files : fix src/main.ts : import * as yargs from 'yargs'; : Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.\n\nCurrent files:\n[\n {\n \"path\": \"package.json\",\n \"content\": \"{\\n \\\"name\\\": \\\"llm-tools-cli\\\",\\n \\\"version\\\": \\\"1.0.0\\\",\\n \\\"description\\\": \\\"CLI and library for LLM tools\\\",\\n \\\"main\\\": \\\"dist/index.js\\\",\\n \\\"bin\\\": {\\n \\\"llm-tools\\\": \\\"./dist/main.js\\\"\\n },\\n \\\"scripts\\\": {\\n \\\"build\\\": \\\"tsc\\\",\\n \\\"start\\\": \\\"node dist/main.js\\\",\\n \\\"dev\\\": \\\"ts-node src/main.ts\\\",\\n \\\"types\\\": \\\"ts-node src/main.ts types\\\"\\n },\\n \\\"dependencies\\\": {\\n \\\"@plastichub/core\\\": \\\"^0.2.6\\\",\\n \\\"@plastichub/fs\\\": \\\"^0.13.39\\\",\\n \\\"@plastichub/osr-commons\\\": \\\"^0.3.7\\\",\\n \\\"@plastichub/osr-log\\\": \\\"^0.1.1\\\",\\n \\\"axios\\\": \\\"^1.7.9\\\",\\n \\\"openai\\\": \\\"^4.76.3\\\",\\n \\\"tslog\\\": \\\"^4.9.3\\\",\\n \\\"yargs\\\": \\\"^17.7.2\\\",\\n \\\"zod\\\": \\\"^3.24.1\\\"\\n },\\n \\\"devDependencies\\\": {\\n \\\"@types/node\\\": \\\"^18.0.0\\\",\\n \\\"@types/yargs\\\": \\\"^17.0.0\\\",\\n \\\"ts-node\\\": \\\"^10.9.0\\\",\\n \\\"typescript\\\": \\\"^4.9.0\\\"\\n }\\n}\"\n },\n {\n \"path\": \"Readme.md\",\n \"content\": \"# LLM Tools CLI\\n\\nA command-line interface and library for LLM (Language Model) tools with filesystem operations support.\\n\\n## Setup\\n\\n```bash\\n# Install dependencies\\nnpm install\\n\\n# Build the project\\nnpm run build\\n\\n# Create symlink for global usage\\nnpm link\\n```\\n\\n## Configuration\\n\\nThe application uses configuration files for API keys and settings. Configuration can be loaded in multiple ways:\\n\\n1. Using `--env_key` parameter\\n2. Environment variables (e.g., OPENAI_API_KEY)\\n3. Configuration file\\n\\nExample configuration file:\\n\\n```json\\n{\\n \\\"openai\\\": {\\n \\\"key\\\": \\\"your-openai-key\\\"\\n }\\n}\\n```\\n\\n## Commands\\n\\n### Generate TypeScript Types\\n\\nGenerate TypeScript interfaces from Zod schemas:\\n\\n```bash\\nllm-tools types\\n```\\n\\n## Library Functions\\n\\n### Filesystem Tools\\n\\nThe package provides two main LLM tools for filesystem operations:\\n\\n#### List Files\\n```typescript\\ninterface ListFilesParams {\\n directory: string; // Directory path to list files from\\n pattern?: string; // Optional glob pattern for filtering files\\n}\\n```\\n\\nExample usage in LLM tools:\\n```typescript\\nawait list_files({\\n directory: './src',\\n pattern: '**/*.ts'\\n});\\n```\\n\\n#### Remove File\\n```typescript\\ninterface RemoveFileParams {\\n path: string; // Path of the file to remove\\n}\\n```\\n\\nExample usage in LLM tools:\\n```typescript\\nawait remove_file({\\n path: './temp/file.txt'\\n});\\n```\\n\\n## Development\\n\\n```bash\\n# Run in development mode\\nnpm run dev\\n\\n# Generate TypeScript interfaces\\nnpm run types\\n```\\n\\n## Project Structure\\n\\n```\\nsrc/\\n├── index.ts # Logger setup using tslog\\n├── main.ts # CLI entry point with yargs\\n├── constants.ts # Constants and logger name\\n├── zod_schemas.ts # Zod schema definitions\\n├── commands/\\n│ ├── index.ts # Command registration\\n│ └── types.ts # Types generation command\\n└── lib/\\n └── tools/\\n └── fs.ts # Filesystem tools implementation\\n```\\n\\n## Key Features\\n\\n- **Type Safety**: Uses Zod for schema validation and TypeScript interface generation\\n- **Filesystem Operations**: Built-in tools for file listing and removal\\n- **Logging**: Structured logging with tslog\\n- **Configuration Management**: Flexible configuration loading\\n- **OpenAI Integration**: Built-in support for OpenAI API\\n\\n## Dependencies\\n\\n### Core Dependencies\\n- tslog: Type-safe logging\\n- yargs: Command-line argument parsing\\n- zod: Schema validation and type generation\\n- axios: HTTP client\\n- openai: OpenAI API integration\\n\\n### Plastichub Dependencies\\n- @plastichub/core: Core utilities\\n- @plastichub/fs: Filesystem operations\\n- @plastichub/osr-commons: Common utilities\\n- @plastichub/osr-log: Logging utilities\\n\\n## Development Dependencies\\n- TypeScript and related type definitions\\n- ts-node for development execution\\n\\n## License\\n\\nMIT\\n\"\n },\n {\n \"path\": \"src\\\\zod_schemas.ts\",\n \"content\": \"import { z } from 'zod';\\n\\nexport const ListFilesSchema = z.object({\\n directory: z.string().describe('Directory path to list files from'),\\n pattern: z.string().optional().describe('Glob pattern for filtering files')\\n});\\n\\nexport const RemoveFileSchema = z.object({\\n path: z.string().describe('Path of the file to remove')\\n});\\n\"\n },\n {\n \"path\": \"src\\\\main.ts\",\n \"content\": \"#!/usr/bin/env node\\nimport * as yargs from 'yargs';\\nimport { commands } from './commands';\\nimport { logger } from './';\\n\\nasync function main() {\\n try {\\n const argv = await commands(yargs).argv;\\n } catch (error) {\\n logger.error('Error executing command:', error);\\n process.exit(1);\\n }\\n}\\n\\nmain();\"\n },\n {\n \"path\": \"src\\\\index.ts\",\n \"content\": \"import { Logger } from 'tslog';\\nimport { createLogger } from '@plastichub/osr-log';\\n\\nexport const logger: Logger<unknown> = createLogger('llm-tools-cli');\\n\"\n },\n {\n \"path\": \"src\\\\constants.ts\",\n \"content\": \"export const LOGGER_NAME = 'llm-tools-cli';\\n\"\n },\n {\n \"path\": \"src\\\\lib\\\\tools\\\\fs.ts\",\n \"content\": \"import * as path from 'path';\\nimport { RunnableToolFunction } from 'openai/lib/RunnableFunction';\\nimport { sync as dir } from '@plastichub/fs/dir';\\nimport { sync as rm } from '@plastichub/fs/remove';\\nimport { filesEx as glob } from '@plastichub/osr-commons/_glob';\\nimport { logger } from '../../index';\\n\\nexport const tools = (target: string): Array<any> => {\\n return [\\n {\\n type: 'function',\\n function: {\\n name: 'list_files',\\n description: 'List all files in a directory',\\n parameters: {\\n type: 'object',\\n properties: {\\n directory: { type: 'string' },\\n pattern: { type: 'string', optional: true }\\n },\\n required: ['directory']\\n },\\n function: async (params: any) => {\\n try {\\n const directory = path.join(target, params.directory);\\n const pattern = params.pattern || '**/*';\\n logger.debug(`Tool::ListFiles Listing files in ${directory} with pattern ${pattern}`);\\n return glob(directory, [pattern]);\\n } catch (error) {\\n logger.error('Error listing files', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>,\\n {\\n type: 'function',\\n function: {\\n name: 'remove_file',\\n description: 'Remove a file at given path',\\n parameters: {\\n type: 'object',\\n properties: {\\n path: { type: 'string' }\\n },\\n required: ['path']\\n },\\n function: async (params: any) => {\\n try {\\n const filePath = path.join(target, params.path);\\n logger.debug(`Tool::RemoveFile Removing file ${filePath}`);\\n rm(filePath);\\n return true;\\n } catch (error) {\\n logger.error('Error removing file', error);\\n throw error;\\n }\\n },\\n parse: JSON.parse\\n }\\n } as RunnableToolFunction<any>\\n ];\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\types.ts\",\n \"content\": \"import { generate_interfaces } from '@plastichub/osr-commons';\\nimport { ListFilesSchema, RemoveFileSchema } from '../zod_schemas';\\n\\nexport const types = async () => {\\n return generate_interfaces([\\n ListFilesSchema,\\n RemoveFileSchema\\n ], 'src/zod_types.ts');\\n};\\n\"\n },\n {\n \"path\": \"src\\\\commands\\\\index.ts\",\n \"content\": \"import type { Argv } from 'yargs';\\nimpor