Files
雷电芽衣 a7fc75bf6b chore(go): audit providers claudecode codex cursor gemini
Add managed_runtime.go (paths, config validation, identity, runtime file
changes, status checks) and shell_command.go (quoting, PowerShell
encoding, command parsing) and move the four providers onto them.

Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
2026-09-03 01:42:27 -04:00

71 lines
2.2 KiB
Go

package plugins
import "path/filepath"
func codexHandler(runtimePath, scriptPath, statusMessage string) map[string]any {
return map[string]any{
"type": "command",
"command": posixSource(runtimePath, scriptPath),
"commandWindows": encodedWindowsCommand(runtimePath, scriptPath),
"timeout": codexHookTimeout,
"statusMessage": statusMessage,
}
}
func codexMatcherGroup(handler map[string]any) map[string]any {
return map[string]any{"matcher": "*", "hooks": []any{handler}}
}
func exactCodexHandlerKeys(handler map[string]any) bool {
if len(handler) != 5 {
return false
}
for _, key := range []string{"type", "command", "commandWindows", "timeout", "statusMessage"} {
if _, exists := handler[key]; !exists {
return false
}
}
return true
}
func codexManagedScriptPath(handler map[string]any, status string) (string, bool) {
if !exactCodexHandlerKeys(handler) || handler["type"] != "command" ||
handler["timeout"] != codexHookTimeout || handler["statusMessage"] != status {
return "", false
}
command, _ := handler["command"].(string)
commandWindows, _ := handler["commandWindows"].(string)
posixRuntime, posixScript, posixOK := parsePOSIXCommand(command)
windowsRuntime, windowsScript, windowsOK := parseEncodedWindowsCommand(commandWindows)
if !windowsOK && posixOK {
expected := quoteWindowsArgument(posixRuntime) + " " + quoteWindowsArgument(posixScript)
if commandWindows == expected {
windowsRuntime, windowsScript, windowsOK = posixRuntime, posixScript, true
}
}
if !posixOK || !windowsOK || !filepath.IsAbs(posixRuntime) ||
!filepath.IsAbs(posixScript) || !isNodeExecutable(posixRuntime) ||
!isNodeExecutable(windowsRuntime) ||
!sameManagedPath(posixRuntime, windowsRuntime) ||
!sameManagedPath(posixScript, windowsScript) {
return "", false
}
return posixScript, true
}
func codexManagedAgentID(
handler map[string]any,
scriptName string,
status string,
) (string, bool) {
scriptPath, managed := codexManagedScriptPath(handler, status)
if !managed {
return "", false
}
reference, err := resolveManagedScript(scriptPath, scriptName)
if err != nil || reference == nil {
return "", false
}
return reference.agentID, true
}