Files
雷电芽衣 34ff4c1ea8 chore(go): audit providers kimi grok qwen letta
Move Kimi, Grok, and Qwen onto managed_runtime.go and shell_command.go;
share the encoded and shell command builders and the quoted Windows
legacy parser with Droid; split managed_changes.go; dedupe Letta's hook
entry filtering and stop swallowing settings read errors.

Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
2026-09-03 02:16:58 -04:00

61 lines
1.7 KiB
Go

package plugins
import (
"path/filepath"
"strings"
)
func readKimiLegacyWindowsArgument(command string, start int) (string, int, bool) {
if start >= len(command) {
return "", start, false
}
if command[start] == '"' {
closing := strings.IndexByte(command[start+1:], '"')
if closing < 0 {
return "", start, false
}
closing += start + 1
return command[start+1 : closing], closing + 1, true
}
end := start
for end < len(command) && command[end] != ' ' {
if command[end] == '"' || command[end] == '\t' || command[end] == '\r' || command[end] == '\n' {
return "", start, false
}
end++
}
return command[start:end], end, end > start
}
// parseKimiLegacyWindowsCommand reads the pre-2.1 quoteWindowsArgument form.
func parseKimiLegacyWindowsCommand(command string) (string, string, bool) {
runtimePath, next, ok := readKimiLegacyWindowsArgument(command, 0)
if !ok || next >= len(command) || command[next] != ' ' {
return "", "", false
}
scriptPath, end, ok := readKimiLegacyWindowsArgument(command, next+1)
if !ok || end != len(command) {
return "", "", false
}
expected := quoteWindowsArgument(runtimePath) + " " + quoteWindowsArgument(scriptPath)
return runtimePath, scriptPath, command == expected
}
func parseKimiCommand(command string) (string, string, bool) {
if runtimePath, scriptPath, ok := parseEncodedCommand(command); ok {
return runtimePath, scriptPath, true
}
return parseKimiLegacyWindowsCommand(command)
}
func kimiRuntimeReferenceForCommand(
command string,
scriptName string,
) (*managedScriptReference, error) {
runtimePath, scriptPath, ok := parseKimiCommand(command)
if !ok || !filepath.IsAbs(runtimePath) || !isNodeExecutable(runtimePath) {
return nil, nil
}
return resolveManagedScript(scriptPath, scriptName)
}