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
This commit is contained in:
1 parent
1ede03d989
commit
34ff4c1ea8
34 files changed
+421
-1876
No files matched your search
@@ -6,9 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,12 +46,6 @@ type grokRenderedDocument struct {
|
||||
remove bool
|
||||
}
|
||||
|
||||
type grokRuntimeContract struct {
|
||||
agentID string
|
||||
guardPath string
|
||||
auditPath string
|
||||
}
|
||||
|
||||
func cloneGrokObject(value map[string]any) map[string]any {
|
||||
clone := make(map[string]any, len(value))
|
||||
for key, item := range value {
|
||||
@@ -262,7 +254,7 @@ func exactManagedGrokGroup(group grokGroup) bool {
|
||||
func managedGrokReference(
|
||||
handler map[string]any,
|
||||
scriptName string,
|
||||
) (*grokRuntimeReference, error) {
|
||||
) (*managedScriptReference, error) {
|
||||
if len(handler) != 3 || handler["type"] != "command" ||
|
||||
handler["timeout"] != grokHookTimeout {
|
||||
return nil, nil
|
||||
@@ -303,7 +295,7 @@ func removeManagedGrokGroups(
|
||||
return nil, err
|
||||
}
|
||||
remove := reference != nil &&
|
||||
(agentID == "" || sameGrokAgentID(reference.agentID, agentID))
|
||||
(agentID == "" || sameManagedAgentID(reference.agentID, agentID))
|
||||
if !remove {
|
||||
kept = append(kept, handler)
|
||||
}
|
||||
@@ -407,18 +399,11 @@ func renderGrokDocument(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func grokReferenceKey(agentID string) string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return strings.ToLower(agentID)
|
||||
}
|
||||
return agentID
|
||||
}
|
||||
|
||||
func grokReferencesForEvent(
|
||||
groups []grokGroup,
|
||||
scriptName string,
|
||||
) (map[string][]grokRuntimeReference, error) {
|
||||
result := map[string][]grokRuntimeReference{}
|
||||
) (map[string][]managedScriptReference, error) {
|
||||
result := map[string][]managedScriptReference{}
|
||||
for _, group := range groups {
|
||||
if !exactManagedGrokGroup(group) {
|
||||
continue
|
||||
@@ -431,14 +416,14 @@ func grokReferencesForEvent(
|
||||
if reference == nil {
|
||||
continue
|
||||
}
|
||||
key := grokReferenceKey(reference.agentID)
|
||||
key := managedReferenceKey(reference.agentID)
|
||||
result[key] = append(result[key], *reference)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func grokRuntimeContracts(hooks grokHooks) ([]grokRuntimeContract, error) {
|
||||
func grokRuntimeContracts(hooks grokHooks) ([]managedRuntimeContract, error) {
|
||||
guards, err := grokReferencesForEvent(hooks["PreToolUse"], grokGuardScript)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -459,16 +444,16 @@ func grokRuntimeContracts(hooks grokHooks) ([]grokRuntimeContract, error) {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
contracts := make([]grokRuntimeContract, 0, len(keys))
|
||||
contracts := make([]managedRuntimeContract, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
guard := guards[key]
|
||||
success := successes[key]
|
||||
failure := failures[key]
|
||||
if len(guard) != 1 || len(success) != 1 || len(failure) != 1 ||
|
||||
!sameGrokPath(success[0].scriptPath, failure[0].scriptPath) {
|
||||
!sameManagedPath(success[0].scriptPath, failure[0].scriptPath) {
|
||||
continue
|
||||
}
|
||||
contracts = append(contracts, grokRuntimeContract{
|
||||
contracts = append(contracts, managedRuntimeContract{
|
||||
agentID: guard[0].agentID, guardPath: guard[0].scriptPath,
|
||||
auditPath: success[0].scriptPath,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user