MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createSkillCommand

Function createSkillCommand

cli/src/commands/command-registry.ts:648–700  ·  view source on GitHub ↗

* Creates a dynamic command definition for a skill. * When invoked, the skill's content is sent to the agent.

(skillName: string)

Source from the content-addressed store, hash-verified

646 * When invoked, the skill's content is sent to the agent.
647 */
648function createSkillCommand(skillName: string): CommandDefinition {
649 return defineCommandWithArgs({
650 name: skillName,
651 handler: (params, args) => {
652 const skill = getSkillByName(skillName)
653 if (!skill) {
654 params.setMessages((prev) => [
655 ...prev,
656 getUserMessage(params.inputValue.trim()),
657 getSystemMessage(`Skill not found: ${skillName}`),
658 ])
659 params.saveToHistory(params.inputValue.trim())
660 params.setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
661 return
662 }
663
664 const trimmed = params.inputValue.trim()
665 params.saveToHistory(trimmed)
666 params.setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
667
668 // Build the message content with skill context and optional user args
669 const skillContext = `<skill name="${skill.name}">
670${skill.content}
671</skill>`
672
673 const userPrompt = `I invoke the following skill:\n\n${skillContext}\n\n`
674 + (args.trim()
675 ? `User request: ${args.trim()}`
676 : '')
677
678 // Check streaming/queue state
679 if (
680 params.isStreaming ||
681 params.streamMessageIdRef.current ||
682 params.isChainInProgressRef.current
683 ) {
684 const pendingAttachments = capturePendingAttachments()
685 params.addToQueue(userPrompt, pendingAttachments)
686 params.setInputFocused(true)
687 params.inputRef.current?.focus()
688 return
689 }
690
691 params.sendMessage({
692 content: userPrompt,
693 agentMode: params.agentMode,
694 })
695 setTimeout(() => {
696 params.scrollToLatest()
697 }, 0)
698 },
699 })
700}

Callers 1

findCommandFunction · 0.85

Calls 6

getSkillByNameFunction · 0.90
getUserMessageFunction · 0.90
getSystemMessageFunction · 0.90
defineCommandWithArgsFunction · 0.85
setTimeoutFunction · 0.85

Tested by

no test coverage detected