{"_id":"@affectively/slash-commands","_rev":"3-40c9bf68b87d8eb1dce9e965440be114","name":"@affectively/slash-commands","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@affectively/slash-commands","version":"1.0.0","keywords":["slash-commands","command-parser","zod","cli","chat","discord","slack","autocomplete","validation","schema"],"author":{"name":"AFFECTIVELY","email":"opensource@affectively.ai"},"license":"MIT","_id":"@affectively/slash-commands@1.0.0","maintainers":[{"name":"buley","email":"buley@outlook.com"}],"homepage":"https://github.com/affectively-ai/slash-commands#readme","bugs":{"url":"https://github.com/affectively-ai/slash-commands/issues"},"dist":{"shasum":"eef7461ab91a348c9242f2a517823b3031bdae27","tarball":"https://registry.npmjs.org/@affectively/slash-commands/-/slash-commands-1.0.0.tgz","fileCount":8,"integrity":"sha512-E/RVmcbdSD4eB13Y6IyMWjVR85JLImi0Fa3aO9KtamaetJ4zdOZ2BpdarCLr6rlUhGbgmhQ/xHrjXkYHOpjwWQ==","signatures":[{"sig":"MEUCIQCJwqtCx27rN9Cn8CGJDsU7jdzHbzDPPRCq5kXC7zG4zwIgRUP4EIiPo6PQQRsWBoEV//UqmZDfGmh30Dvl0wjQ1Hk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":93456},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"8b710f9bbcd1d7c4fdcfe21647c64c2317f6d0b5","scripts":{"test":"bun test","build":"tsup src/index.ts --format cjs,esm --dts --external zod","prepublishOnly":"npm run build"},"_npmUser":{"name":"buley","email":"buley@outlook.com"},"repository":{"url":"git+https://github.com/affectively-ai/slash-commands.git","type":"git"},"_npmVersion":"11.7.0","description":"Slash command parser with Zod schema integration. Auto-generates commands from Zod schemas with autocomplete, validation, and type coercion for CLI and chat interfaces.","directories":{},"_nodeVersion":"25.4.0","dependencies":{"zod":"^3.23.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.9.0","@types/node":"^22.0.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/slash-commands_1.0.0_1769380348194_0.148033159345911","host":"s3://npm-registry-packages-npm-production"},"deprecated":"This package is deprecated and no longer supported. Do not use."},"1.1.0":{"name":"@affectively/slash-commands","version":"1.1.0","keywords":["slash-commands","command-parser","zod","cli","chat","discord","slack","autocomplete","validation","schema"],"author":{"name":"AFFECTIVELY","email":"opensource@affectively.ai"},"license":"MIT","_id":"@affectively/slash-commands@1.1.0","maintainers":[{"name":"buley","email":"buley@outlook.com"}],"homepage":"https://github.com/affectively-ai/slash-commands#readme","bugs":{"url":"https://github.com/affectively-ai/slash-commands/issues"},"dist":{"shasum":"39ca2490f0954f5b5a4c391e7a3966bcba81718b","tarball":"https://registry.npmjs.org/@affectively/slash-commands/-/slash-commands-1.1.0.tgz","fileCount":8,"integrity":"sha512-E7LsG+tsYN4sS8Y/2xEHdhTYpPCSZkeOuslL8V0R+q9au6Rc5NVnllTN9gM+e0kZ6BBJKKnPQRu2YMezr5F6BQ==","signatures":[{"sig":"MEQCIGKdSLOz/QKsXdnOPPX0EPAibyleNwMM1VdgRmsNuLGHAiB/loD5I/jbP8MbBTv9ekYk3wTNnQ/3W/uqw9jsGFBpIQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":96039},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"bf8cff31bc0fafe52b51472ade81f79f4f6efd3c","scripts":{"test":"bun test","build":"tsup src/index.ts --format cjs,esm --dts --external zod","prepublishOnly":"npm run build"},"_npmUser":{"name":"buley","email":"buley@outlook.com"},"repository":{"url":"git+https://github.com/affectively-ai/slash-commands.git","type":"git"},"_npmVersion":"11.8.0","description":"Slash command parser with Zod schema integration. Auto-generates commands from Zod schemas with autocomplete, validation, and type coercion for CLI and chat interfaces.","directories":{},"_nodeVersion":"25.5.0","dependencies":{"zod":"^3.23.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.9.0","@types/node":"^22.0.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/slash-commands_1.1.0_1771376665618_0.4475339628763606","host":"s3://npm-registry-packages-npm-production"},"deprecated":"This package is deprecated and no longer supported. Do not use."}},"time":{"created":"2026-01-25T22:32:28.088Z","modified":"2026-03-27T20:03:45.399Z","1.0.0":"2026-01-25T22:32:28.341Z","1.1.0":"2026-02-18T01:04:25.776Z"},"bugs":{"url":"https://github.com/affectively-ai/slash-commands/issues"},"author":{"name":"AFFECTIVELY","email":"opensource@affectively.ai"},"license":"MIT","homepage":"https://github.com/affectively-ai/slash-commands#readme","keywords":["slash-commands","command-parser","zod","cli","chat","discord","slack","autocomplete","validation","schema"],"repository":{"url":"git+https://github.com/affectively-ai/slash-commands.git","type":"git"},"description":"Slash command parser with Zod schema integration. Auto-generates commands from Zod schemas with autocomplete, validation, and type coercion for CLI and chat interfaces.","maintainers":[{"name":"buley","email":"buley@outlook.com"}],"readme":"# @affectively/slash-commands\n\nSlash command parser with Zod schema integration. Auto-generates commands from Zod schemas with autocomplete, validation, and type coercion for CLI and chat interfaces.\n\n## Features\n\n- **Zod Integration** - Generate commands directly from Zod schemas\n- **Type Coercion** - Automatically convert strings to numbers, booleans, arrays\n- **Autocomplete** - Fuzzy matching suggestions for commands and arguments\n- **Validation** - Validate arguments against schema with detailed errors\n- **Subscription Tiers** - Built-in support for tiered command access\n- **Aliases** - Auto-generated aliases (kebab-case, acronyms)\n- **Flexible Syntax** - Supports `key=value`, `--key=value`, `--key value`, `-k`\n\n## Installation\n\n```bash\nnpm install @affectively/slash-commands zod\n# or\nbun add @affectively/slash-commands zod\n# or\nyarn add @affectively/slash-commands zod\n```\n\n## Quick Start\n\n```typescript\nimport {\n  slashCommandRegistry,\n  parseSlashCommand,\n  getAutocompleteSuggestions,\n} from '@affectively/slash-commands';\nimport { z } from 'zod';\n\n// Register commands from tool definitions\nslashCommandRegistry.registerFromTools([\n  {\n    name: 'users_list',\n    description: 'List users with optional filtering',\n    inputSchema: z.object({\n      role: z.enum(['admin', 'user', 'guest']).optional().describe('Filter by role'),\n      limit: z.number().default(10).describe('Maximum results'),\n      active: z.boolean().optional().describe('Only active users'),\n    }),\n    requiredTier: 'free',\n  },\n  {\n    name: 'users_create',\n    description: 'Create a new user',\n    inputSchema: z.object({\n      email: z.string().describe('User email address'),\n      name: z.string().describe('Display name'),\n      role: z.enum(['admin', 'user', 'guest']).default('user'),\n    }),\n    requiredTier: 'premium',\n  },\n]);\n\n// Parse user input\nconst parsed = parseSlashCommand('/users_list limit=20 role=admin');\nconsole.log(parsed);\n// {\n//   command: 'users_list',\n//   args: { limit: 20, role: 'admin' },\n//   found: true,\n//   errors: undefined\n// }\n\n// Get autocomplete suggestions\nconst suggestions = getAutocompleteSuggestions('/us', { userTier: 'premium' });\nconsole.log(suggestions);\n// [\n//   { command: 'users_list', displayText: '/users_list', ... },\n//   { command: 'users_create', displayText: '/users_create', ... }\n// ]\n```\n\n## Supported Syntax\n\n```bash\n# Basic command\n/command\n\n# Named arguments\n/command arg1=value1 arg2=value2\n\n# Quoted values (for spaces)\n/command name=\"John Doe\"\n\n# CLI-style flags\n/command --limit=10 --active\n\n# Short flags\n/command -l 10 -a\n\n# Boolean flags\n/command --active\n\n# Hierarchical commands (auto-converted)\n/users list  →  users_list\n```\n\n## Type Coercion\n\nArguments are automatically coerced to appropriate types:\n\n```typescript\nparseSlashCommand('/cmd num=42');        // { num: 42 } (number)\nparseSlashCommand('/cmd flag=true');     // { flag: true } (boolean)\nparseSlashCommand('/cmd arr=[1,2,3]');   // { arr: [1,2,3] } (array)\nparseSlashCommand('/cmd obj={\"a\":1}');   // { obj: { a: 1 } } (object)\n```\n\n## Registry API\n\n```typescript\nimport { slashCommandRegistry } from '@affectively/slash-commands';\n\n// Register a single command\nslashCommandRegistry.register(commandDefinition);\n\n// Register multiple commands\nslashCommandRegistry.registerAll([cmd1, cmd2]);\n\n// Register from tool definitions (with Zod schemas)\nslashCommandRegistry.registerFromTools(tools);\n\n// Get command by name or alias\nconst cmd = slashCommandRegistry.get('users_list');\nconst cmd = slashCommandRegistry.get('ul'); // Auto-generated alias\n\n// Filter by category\nconst userCommands = slashCommandRegistry.getByCategory('users');\n\n// Filter by subscription tier\nconst freeCommands = slashCommandRegistry.getForTier('free');\n\n// Get all categories\nconst categories = slashCommandRegistry.getCategories();\n```\n\n## Autocomplete\n\n```typescript\nimport {\n  getAutocompleteSuggestions,\n  getSuggestionsGroupedByCategory,\n  shouldShowAutocomplete,\n  fuzzyMatch,\n} from '@affectively/slash-commands';\n\n// Get suggestions for partial input\nconst suggestions = getAutocompleteSuggestions('/us', {\n  userTier: 'premium',\n  maxSuggestions: 10,\n  includeHidden: false,\n  minScore: 30,\n});\n\n// Group by category for UI\nconst grouped = getSuggestionsGroupedByCategory('/us', { userTier: 'premium' });\n// { users: [...], utilities: [...] }\n\n// Check if autocomplete should show\nif (shouldShowAutocomplete(input)) {\n  // Show autocomplete UI\n}\n\n// Test fuzzy match score\nconst score = fuzzyMatch('ul', 'users_list'); // 80+ (initials match)\n```\n\n## Command Execution\n\n```typescript\nimport { executeSlashCommand, createAPIExecutor } from '@affectively/slash-commands';\n\n// Execute with custom executor\nconst result = await executeSlashCommand(\n  '/users_list limit=10',\n  {\n    userTier: 'premium',\n    apiBaseUrl: 'https://api.example.com',\n    authToken: 'bearer-token',\n  },\n  async (command, args, context) => {\n    // Your execution logic here\n    return await fetch(`/api/${command}`, {\n      method: 'POST',\n      body: JSON.stringify(args),\n    });\n  }\n);\n\n// Or use the built-in API executor\nconst apiExecutor = createAPIExecutor('https://api.example.com', 'auth-token');\nconst result = await executeSlashCommand('/users_list', context, apiExecutor);\n```\n\n## Generating Commands\n\n```typescript\nimport { generateSlashCommand, generateSlashCommands } from '@affectively/slash-commands';\nimport { z } from 'zod';\n\nconst command = generateSlashCommand({\n  name: 'search',\n  description: 'Search for items',\n  inputSchema: z.object({\n    query: z.string().describe('Search query'),\n    page: z.number().default(1),\n  }),\n});\n\nconsole.log(command.helpText);\n// /search\n//\n// Search for items\n//\n// Parameters:\n//   query <string> (required)\n//     Search query\n//   page <number> (optional) (default: 1)\n\nconsole.log(command.examples);\n// ['/search', '/search query=\"example\"']\n```\n\n## Subscription Tiers\n\n```typescript\n// Commands can require specific subscription tiers\nconst command = generateSlashCommand({\n  name: 'premium_feature',\n  description: 'A premium feature',\n  inputSchema: z.object({}),\n  requiredTier: 'premium',\n});\n\n// Filter available commands by tier\nconst available = slashCommandRegistry.getForTier('free');\n\n// Autocomplete respects tiers (shows but marks inaccessible)\nconst suggestions = getAutocompleteSuggestions('/pre', { userTier: 'free' });\n// Returns suggestion with hasAccess: false\n```\n\n## API Reference\n\n### Parser\n\n- `parseSlashCommand(input, registry?, options?)` - Parse input into command and args\n- `isSlashCommand(input)` - Check if input starts with /\n- `extractCommandName(input)` - Get command name from input\n- `formatCommand(command, args)` - Format command for display\n- `getPartialCommand(input)` - Get partial command info for autocomplete\n\n### Registry\n\n- `SlashCommandRegistry` - Main registry class\n- `slashCommandRegistry` - Global singleton instance\n- `executeSlashCommand(input, context, executor)` - Execute a command\n- `createAPIExecutor(baseUrl, token?)` - Create API-based executor\n\n### Generator\n\n- `generateSlashCommand(tool)` - Generate command from tool definition\n- `generateSlashCommands(tools)` - Generate multiple commands\n- `extractParametersFromZod(schema)` - Extract params from Zod schema\n- `extractParametersFromJsonSchema(schema)` - Extract params from JSON schema\n\n### Autocomplete\n\n- `getAutocompleteSuggestions(input, options?, registry?)` - Get suggestions\n- `getSuggestionsGroupedByCategory(input, options?, registry?)` - Grouped suggestions\n- `shouldShowAutocomplete(input)` - Check if autocomplete should show\n- `fuzzyMatch(query, target)` - Calculate match score (0-100)\n\n## License\n\nMIT © AFFECTIVELY\n","readmeFilename":"README.md"}