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

Function analyzeSingleCommand

tools/bash/permissions.go:139–187  ·  view source on GitHub ↗
(command string)

Source from the content-addressed store, hash-verified

137}
138
139func analyzeSingleCommand(command string) PermissionResult {
140 cleaned := strings.TrimSpace(command)
141 if cleaned == "" {
142 return PermissionResult{
143 Allowed: true, Risk: RiskSafe, Reason: "Empty command",
144 NeedsUserDecision: false, ParseResult: ParseSimple,
145 }
146 }
147 if appsecurity.IsDangerous(cleaned) {
148 return PermissionResult{
149 Allowed: false, Risk: RiskHigh, Reason: "Command matches dangerous pattern",
150 NeedsUserDecision: true, ParseResult: ParseSimple,
151 }
152 }
153 semantic := CheckSemantics(cleaned)
154 if semantic == "dangerous" {
155 return PermissionResult{
156 Allowed: false, Risk: RiskHigh,
157 Reason: "Command contains dangerous patterns (AST)",
158 NeedsUserDecision: true, ParseResult: ParseSimple,
159 }
160 }
161 if semantic == "too-complex" {
162 return PermissionResult{
163 Allowed: false, Risk: RiskHigh,
164 Reason: "Command is too complex for automated analysis",
165 NeedsUserDecision: true, ParseResult: ParseTooComplex,
166 }
167 }
168 secResult := RunAllSecurityChecks(cleaned)
169 if IsBlocking(secResult) {
170 return PermissionResult{
171 Allowed: false, Risk: RiskCritical,
172 Reason: "Security check failed: " + joinFindingDescriptions(secResult.Findings, 3),
173 NeedsUserDecision: true, ParseResult: ParseSimple,
174 }
175 }
176 if len(secResult.Findings) > 0 {
177 return PermissionResult{
178 Allowed: false, Risk: RiskNormal,
179 Reason: "Security warnings: " + joinFindingDescriptions(secResult.Findings, 3),
180 NeedsUserDecision: true, ParseResult: ParseSimple,
181 }
182 }
183 return PermissionResult{
184 Allowed: true, Risk: RiskSafe, Reason: "All checks passed",
185 NeedsUserDecision: false, ParseResult: ParseSimple,
186 }
187}
188
189func generateRuleSuggestions(subcommands []string) []string {
190 var suggestions []string

Callers 1

Calls 4

CheckSemanticsFunction · 0.85
RunAllSecurityChecksFunction · 0.85
IsBlockingFunction · 0.85
joinFindingDescriptionsFunction · 0.85

Tested by

no test coverage detected