MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / executeInlineShell

Method executeInlineShell

skills/prompt_processor.go:156–200  ·  view source on GitHub ↗
(content string, skill SkillSpec, approveProjectShell func(SkillShellPermissionRequest) bool)

Source from the content-addressed store, hash-verified

154
155func (p *PromptProcessor) executeInlineShell(content string, skill SkillSpec, approveProjectShell func(SkillShellPermissionRequest) bool) (string, error) {
156 re := regexp.MustCompile("(?s)!`(?P<command>.+?)`")
157 matches := re.FindAllStringSubmatchIndex(content, -1)
158 if len(matches) == 0 {
159 return content, nil
160 }
161 var commands []string
162 for _, match := range matches {
163 command := strings.TrimSpace(content[match[2]:match[3]])
164 decision := DecideInlineShellExecution(skill, command)
165 if !decision.Allowed {
166 return "", fmt.Errorf("%s", decision.Reason)
167 }
168 if decision.RequiresApproval {
169 if approveProjectShell == nil || !approveProjectShell(SkillShellPermissionRequest{SkillName: skill.CanonicalName, Command: command}) {
170 return "", fmt.Errorf("Skill '%s' shell command was denied: %s", skill.CanonicalName, command)
171 }
172 }
173 commands = append(commands, command)
174 }
175 var replacements []string
176 for _, command := range commands {
177 runCWD := skill.Directory
178 if runCWD == "" {
179 runCWD = p.Config.CWD
180 }
181 if err := RunShellSafetyChecks(command, runCWD); err != nil {
182 return "", err
183 }
184 output, err := p.runInlineShell(command, skill.Directory, optionalValue(skill.Frontmatter.Shell))
185 if err != nil {
186 return "", err
187 }
188 replacements = append(replacements, output)
189 }
190 var rendered strings.Builder
191 cursor := 0
192 for i, match := range matches {
193 rendered.WriteString(content[cursor:match[0]])
194 rendered.WriteString(replacements[i])
195 cursor = match[1]
196 }
197 rendered.WriteString(content[cursor:])
198 return rendered.String(), nil
199}
200
201func (p *PromptProcessor) runInlineShell(command, cwd, executable string) (string, error) {
202 runCWD := cwd
203 if runCWD == "" {

Callers 1

ProcessMethod · 0.95

Calls 5

runInlineShellMethod · 0.95
RunShellSafetyChecksFunction · 0.85
optionalValueFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected