Code quality fixes from review
toolsrv: - Remove dead 'var _ = os.Args' in sandbox/native_linux.go - Fix stale comment in server.go (said 'spec.go') - Fix misleading test comment in proc_test.go - Add outputLimit constant in exec.go (was magic number) - Handle error from registry.New() in main.go - Change startup log from Warn to Info olliesrv: - Remove duplicate normalizeWorkflow() call in tool_match.go - Consolidate duplicate nil checks in runtime.go - Remove reimplemented stdlib functions in toolclient/toolsrv.go - Simplify cacheSummary() - remove unused variable capture -27 lines
This commit is contained in:
parent
9b9c1a9539
commit
67edfdf58b
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// spec.go - virtfs-based namespace specification for toolsrvclient.
|
||||
// server.go - virtfs-based namespace specification for toolsrv.
|
||||
package server
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue