diff --git a/cmd/olliesrv/internal/agent/history.go b/cmd/olliesrv/internal/agent/history.go index e655a57..765f022 100644 --- a/cmd/olliesrv/internal/agent/history.go +++ b/cmd/olliesrv/internal/agent/history.go @@ -469,10 +469,7 @@ func (s *History) cacheSummary(key, summary string) { if len(summary) > maxSummaryCacheBytes { return } - if old, ok := s.summaryCache[key]; ok { - delete(s.summaryCache, key) - _ = old - } + delete(s.summaryCache, key) // Remove old entry if exists s.summaryCache[key] = summary bytes := 0 for k, value := range s.summaryCache { diff --git a/cmd/olliesrv/internal/agent/runtime.go b/cmd/olliesrv/internal/agent/runtime.go index b2701dc..7180a5e 100644 --- a/cmd/olliesrv/internal/agent/runtime.go +++ b/cmd/olliesrv/internal/agent/runtime.go @@ -163,13 +163,11 @@ func (rt *Runtime) PreambleString() string { func BuildRuntime(cfg *AgentConfig, srv *toolclient.ToolsrvConn, cwd string, env []string, systemPrompt, envBlock string) *Runtime { var allToolInfos []protocol.ToolInfo var allTools []backend.Tool + var toolRevision uint64 if srv != nil { allToolInfos, _ = srv.ListTools() allTools = toolInfosToBackend(allToolInfos) - } - var toolRevision uint64 - if srv != nil { toolRevision = srv.ToolRegistryRevision() } diff --git a/cmd/olliesrv/internal/agent/tool_match.go b/cmd/olliesrv/internal/agent/tool_match.go index 63ecb90..ab4c697 100644 --- a/cmd/olliesrv/internal/agent/tool_match.go +++ b/cmd/olliesrv/internal/agent/tool_match.go @@ -68,8 +68,8 @@ func matchTools(input string, tools []protocol.ToolInfo) string { return "" } - workflowText := normalizeWorkflow(input).SearchText() workflow := normalizeWorkflow(input) + workflowText := workflow.SearchText() searchInput := input if workflowText != "" { searchInput += " Workflow: " + workflowText diff --git a/cmd/olliesrv/internal/toolclient/toolsrv.go b/cmd/olliesrv/internal/toolclient/toolsrv.go index 0742034..143e21e 100644 --- a/cmd/olliesrv/internal/toolclient/toolsrv.go +++ b/cmd/olliesrv/internal/toolclient/toolsrv.go @@ -313,8 +313,8 @@ func (c *ToolsrvConn) HostInfo() (HostInfo, error) { } info := HostInfo{} - for _, line := range splitLines(string(data)) { - if idx := indexOf(line, '='); idx >= 0 { + for _, line := range strings.Split(string(data), "\n") { + if idx := strings.IndexByte(line, '='); idx >= 0 { key := line[:idx] val := line[idx+1:] switch key { @@ -423,8 +423,8 @@ func (c *ToolsrvConn) readProcInfo(name string) map[string]any { } info := make(map[string]any) - for _, line := range splitLines(string(data)) { - if idx := indexOf(line, '='); idx >= 0 { + for _, line := range strings.Split(string(data), "\n") { + if idx := strings.IndexByte(line, '='); idx >= 0 { key := line[:idx] val := line[idx+1:] switch key { @@ -514,30 +514,6 @@ func randomSecret() (string, error) { return hex.EncodeToString(b), nil } -func splitLines(s string) []string { - var lines []string - start := 0 - for i := 0; i < len(s); i++ { - if s[i] == '\n' { - lines = append(lines, s[start:i]) - start = i + 1 - } - } - if start < len(s) { - lines = append(lines, s[start:]) - } - return lines -} - -func indexOf(s string, c byte) int { - for i := 0; i < len(s); i++ { - if s[i] == c { - return i - } - } - return -1 -} - func escapeValue(s string) string { // Escape newlines and backslashes result := make([]byte, 0, len(s)) diff --git a/cmd/toolsrv/internal/exec/exec.go b/cmd/toolsrv/internal/exec/exec.go index 3c38ab6..4502801 100644 --- a/cmd/toolsrv/internal/exec/exec.go +++ b/cmd/toolsrv/internal/exec/exec.go @@ -21,6 +21,8 @@ import ( "ollie/util" ) +const outputLimit = 10 * 1024 * 1024 // 10 MiB + // StartResult reports whether an external command started. type StartResult struct { Process *os.Process @@ -194,7 +196,7 @@ func executeSandboxed(ctx context.Context, toolPath, stdinData, cwd string, envE } lw := &limitedWriter{ w: w, - limit: 10 * 1024 * 1024, + limit: outputLimit, } cmd.Stdout = lw cmd.Stderr = lw diff --git a/cmd/toolsrv/internal/sandbox/native_linux.go b/cmd/toolsrv/internal/sandbox/native_linux.go index d9bcd3c..82721ab 100644 --- a/cmd/toolsrv/internal/sandbox/native_linux.go +++ b/cmd/toolsrv/internal/sandbox/native_linux.go @@ -6,7 +6,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "os" "os/exec" "strings" "syscall" @@ -129,5 +128,3 @@ func restrict(cfg *Config, cwd string, env map[string]string) error { } return nil } - -var _ = os.Args diff --git a/cmd/toolsrv/internal/server/proc_test.go b/cmd/toolsrv/internal/server/proc_test.go index 5f2f5ff..015e1b5 100644 --- a/cmd/toolsrv/internal/server/proc_test.go +++ b/cmd/toolsrv/internal/server/proc_test.go @@ -273,7 +273,7 @@ func TestGcProcs(t *testing.T) { t.Error("proc 1 should have been GC'd (exited, read >10min ago)") } if _, ok := st.procs[2]; ok { - t.Error("proc 2 should NOT be GC'd (never read)") + t.Error("proc 2 should be GC'd (exited, never read, timed out)") } if _, ok := st.procs[3]; !ok { t.Error("proc 3 should NOT be GC'd (recently read)") diff --git a/cmd/toolsrv/internal/server/server.go b/cmd/toolsrv/internal/server/server.go index 477fa93..404cb4f 100644 --- a/cmd/toolsrv/internal/server/server.go +++ b/cmd/toolsrv/internal/server/server.go @@ -1,4 +1,4 @@ -// spec.go - virtfs-based namespace specification for toolsrvclient. +// server.go - virtfs-based namespace specification for toolsrv. package server import ( diff --git a/cmd/toolsrv/main.go b/cmd/toolsrv/main.go index c9b84e0..db972d7 100644 --- a/cmd/toolsrv/main.go +++ b/cmd/toolsrv/main.go @@ -90,7 +90,10 @@ func main() { // Native Landlock is applied by the sandbox-exec child; no external wrapper is required. // Create tool registry - toolReg, _ := registry.New() + toolReg, err := registry.New() + if err != nil { + logger.Warn("tool registry: %v", err) + } // Create server state srv := server.NewServer() @@ -153,7 +156,7 @@ func main() { defer ln.Close() defer os.Remove(*listenPath) - logger.Warn("listening on %s", *listenPath) + logger.Info("listening on %s", *listenPath) // Accept connections go func() {