Drop unused expandHome and standardizeJSONC, share the runtime base URL validator between the guard and audit templates, and trim comments. Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package plugins
|
|
|
|
import "strings"
|
|
|
|
// extractElydoraScriptPath reads the legacy shared command-hook shape.
|
|
func extractElydoraScriptPath(hookArray any) string {
|
|
entries, _ := hookArray.([]any)
|
|
for _, entry := range entries {
|
|
object, ok := entry.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if hooks, ok := object["hooks"].([]any); ok {
|
|
for _, hook := range hooks {
|
|
handler, ok := hook.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if command, _ := handler["command"].(string); strings.Contains(
|
|
command,
|
|
"elydora",
|
|
) {
|
|
return extractPathFromNodeCommand(command)
|
|
}
|
|
}
|
|
}
|
|
if command, _ := object["command"].(string); strings.Contains(
|
|
command,
|
|
"elydora",
|
|
) {
|
|
return extractPathFromNodeCommand(command)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func extractPathFromNodeCommand(command string) string {
|
|
command = strings.TrimSpace(command)
|
|
if strings.HasPrefix(command, "node ") {
|
|
return strings.TrimSpace(command[5:])
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func hasElydoraEntry(hookArray any) bool {
|
|
entries, _ := hookArray.([]any)
|
|
for _, entry := range entries {
|
|
if object, ok := entry.(map[string]any); ok && isElydoraHookEntry(object) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isElydoraHookEntry(object map[string]any) bool {
|
|
if hooks, ok := object["hooks"].([]any); ok {
|
|
for _, hook := range hooks {
|
|
handler, ok := hook.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if command, _ := handler["command"].(string); strings.Contains(
|
|
command,
|
|
"elydora",
|
|
) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
command, _ := object["command"].(string)
|
|
return strings.Contains(command, "elydora")
|
|
}
|