Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3b61c46
refactor(acp,bg,agenteval,config): use slices.Contains, for range N, …
N1xev Jul 5, 2026
7a9fb24
refactor(agent): use maps.Copy and slices.Contains in loop.go
N1xev Jul 5, 2026
f7b349e
refactor(agent): use strings.Cut/CutPrefix/CutSuffix instead of Index…
N1xev Jul 5, 2026
7bbfd43
refactor(agent): use max/min builtins for clamp patterns
N1xev Jul 5, 2026
144b9ef
refactor(agent): use for range N in tests
N1xev Jul 5, 2026
7c6f3ca
refactor(cli): use slices.Contains, for range N, SplitSeq, Cut, wg.Go
N1xev Jul 5, 2026
7464f25
refactor(cron,daemon,hooks,imageinput,lsp,etc): use slices.Contains, …
N1xev Jul 5, 2026
f4ef5f0
refactor(mcp,oauth): use slices.Contains, for range N, Cut
N1xev Jul 5, 2026
36ba9ee
refactor(modelregistry): use slices.Contains, for range N, strings.Cu…
N1xev Jul 5, 2026
dbd95d7
refactor(providers): use slices.Contains, SplitSeq, for range N, max …
N1xev Jul 5, 2026
24f516b
refactor(sessions,notify,perfbench,plugins,redaction,release): use fo…
N1xev Jul 5, 2026
24bb819
refactor(repoinfo,review,securefile,selfverify): use slices.Contains,…
N1xev Jul 5, 2026
0ebb69f
refactor(skills,specialist,specmode,swarm): use slices.Contains, for …
N1xev Jul 5, 2026
18ae94a
refactor(tools): use slices.Contains, strings.Cut, for range N, wg.Go…
N1xev Jul 5, 2026
f2eaf59
refactor(tui): use max/min builtins, slices.Contains, strings.Cut/Spl…
N1xev Jul 5, 2026
701f74c
refactor(tui): use for range N, strings.Cut/SplitSeq/CutPrefix in tes…
N1xev Jul 5, 2026
4a8a2fc
refactor(update,usercommands,verify,workspaceseed): use strings.Cut, …
N1xev Jul 5, 2026
dd22ec6
refactor(zerogit,zeroruntime): use SplitSeq, strings.Cut, min builtin
N1xev Jul 5, 2026
3a2eda2
formatting
N1xev Jul 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/acp/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestConnSurvivesMalformedLine(t *testing.T) {

dec := json.NewDecoder(clientR)
var sawParseError, sawPong bool
for i := 0; i < 2; i++ {
for i := range 2 {
var msg struct {
Result any `json:"result"`
Error *struct {
Expand Down
8 changes: 2 additions & 6 deletions internal/acp/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acp

import (
"encoding/json"
"slices"

"github.com/Gitlawb/zero/internal/agent"
)
Expand Down Expand Up @@ -85,12 +86,7 @@ func decisionFromOutcome(outcome RequestPermissionOutcome, offered []agent.Permi
}

func actionOffered(action agent.PermissionDecisionAction, offered []agent.PermissionDecisionAction) bool {
for _, a := range offered {
if a == action {
return true
}
}
return false
return slices.Contains(offered, action)
}

// permissionToolCall builds the ToolCall descriptor embedded in a
Expand Down
6 changes: 3 additions & 3 deletions internal/agent/command_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
return cleaned
}

func safeRequestedPrefix(prefix []string, command []string) bool {

Check failure on line 171 in internal/agent/command_prefix.go

View workflow job for this annotation

GitHub Actions / Security & code health

unreachable func: safeRequestedPrefix
return safeRequestedPrefixForSegments(prefix, [][]string{command})
}

Expand Down Expand Up @@ -196,7 +196,7 @@
return matched
}

func safeShellCommandTokens(command string) ([]string, bool) {

Check failure on line 199 in internal/agent/command_prefix.go

View workflow job for this annotation

GitHub Actions / Security & code health

unreachable func: safeShellCommandTokens
segments, ok := safeShellCommandSegments(command)
if !ok || len(segments) != 1 {
return nil, false
Expand Down Expand Up @@ -343,7 +343,7 @@
if body == "" {
return false
}
for _, part := range strings.Split(body, ",") {
for part := range strings.SplitSeq(body, ",") {
if part == "" {
return false
}
Expand Down Expand Up @@ -466,8 +466,8 @@
}
name = strings.ToLower(name)
for _, suffix := range []string{".exe", ".cmd", ".bat", ".com"} {
if strings.HasSuffix(name, suffix) {
return strings.TrimSuffix(name, suffix)
if before, ok := strings.CutSuffix(name, suffix); ok {
return before
}
}
return name
Expand All @@ -485,7 +485,7 @@
return true
}

func equalStringSlices(left []string, right []string) bool {

Check failure on line 488 in internal/agent/command_prefix.go

View workflow job for this annotation

GitHub Actions / Security & code health

unreachable func: equalStringSlices
if len(left) != len(right) {
return false
}
Expand Down
5 changes: 1 addition & 4 deletions internal/agent/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ func CompactMessages(messages []zeroruntime.Message, opts CompactionOptions) (Co

// Naive boundary: keep the last preserveLast messages. Then widen the suffix
// backward to a safe boundary so it never starts on a tool result.
boundary := len(messages) - preserveLast
if boundary < systemEnd {
boundary = systemEnd
}
boundary := max(len(messages)-preserveLast, systemEnd)
boundary = safeSuffixBoundary(messages, systemEnd, boundary)

middle := messages[systemEnd:boundary]
Expand Down
13 changes: 5 additions & 8 deletions internal/agent/compaction_preserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
// editNote reduces an edit tool's result to a single short line (its first
// non-empty line, byte-capped on a rune boundary) for the preserved summary.
func editNote(content string) string {
for _, line := range strings.Split(content, "\n") {
for line := range strings.SplitSeq(content, "\n") {
s := strings.TrimSpace(line)
if s == "" {
continue
Expand Down Expand Up @@ -369,11 +369,11 @@
if !strings.HasPrefix(content, projectInstructionsHeadingPrefix) {
return "", ""
}
firstLineEnd := strings.IndexByte(content, '\n')
if firstLineEnd < 0 {
before, _, ok := strings.Cut(content, "\n")
if !ok {
return "", ""
}
heading := strings.TrimSpace(content[:firstLineEnd])
heading := strings.TrimSpace(before)
if !strings.Contains(heading, projectInstructionsHeadingMarker) {
return "", ""
}
Expand Down Expand Up @@ -417,10 +417,7 @@
if len(body) <= maxPreservedSkillBytes {
return body
}
limit := maxPreservedSkillBytes - len(truncationNote)
if limit < 0 {
limit = 0
}
limit := max(maxPreservedSkillBytes-len(truncationNote), 0)
// Walk back to the start of a rune so a multibyte sequence is never split.
for limit > 0 && !utf8.RuneStart(body[limit]) {
limit--
Expand Down Expand Up @@ -583,7 +580,7 @@
// block. JSON escaping makes this lossless even when a skill body contains
// markdown headings, code fences, or quotes. Returns ("", nil) when absent or
// malformed.
func parsePreservedState(summaryContent string) (string, []skillEntry) {

Check failure on line 583 in internal/agent/compaction_preserve.go

View workflow job for this annotation

GitHub Actions / Security & code health

unreachable func: parsePreservedState
state := parsePreservedStateBlock(summaryContent)
return state.Plan, preservedSkillsToEntries(state.Skills)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/compaction_recent_edits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestRecentEditsMergeNewerWins(t *testing.T) {
func TestRecentEditsCapKeepsReeditedFile(t *testing.T) {
// Earlier compaction preserved exactly maxRecentEdits files, f0 the oldest.
older := make([]skillEntry, 0, maxRecentEdits)
for i := 0; i < maxRecentEdits; i++ {
for i := range maxRecentEdits {
older = append(older, skillEntry{name: fmt.Sprintf("f%d.go", i), body: "old"})
}
// Fresh window re-edits the OLDEST file (f0) and adds a brand-new file, so the
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/compaction_summarizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestSummarizeWithFallbackChunksOnContextLimit(t *testing.T) {
if err != nil {
t.Fatalf("summarizeWithFallback failed: %v", err)
}
for i := 0; i < n; i++ {
for i := range n {
if !strings.Contains(summary, fmt.Sprintf("msg-%d", i)) {
t.Fatalf("combined summary missing msg-%d: %q", i, summary)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/defer_savings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (t richMCPTool) Deferred() bool { return true }
func TestDeferralTokenSavingsMeasurement(t *testing.T) {
const mcpToolCount = 6
registry := tools.NewRegistry()
for i := 0; i < mcpToolCount; i++ {
for i := range mcpToolCount {
registry.Register(richMCPTool{name: fmt.Sprintf("mcp__websearch__search_v%d", i)})
}
registry.Register(fakeToolSearchTool{})
Expand Down
8 changes: 4 additions & 4 deletions internal/agent/guardrails.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,18 @@ func IsNoProgressStop(content string) bool {
}
rest := trimmed[len(noOutputStopPrefix):]
const turnsSep = " turns "
sep := strings.Index(rest, turnsSep)
if sep < 0 {
before, after, ok := strings.Cut(rest, turnsSep)
if !ok {
return false
}
// The text between the prefix and " turns " must be exactly the bare integer
// count; anything else means this isn't the guard's own answer.
if _, err := strconv.Atoi(rest[:sep]); err != nil {
if _, err := strconv.Atoi(before); err != nil {
return false
}
// The marker must be immediately followed (one space) by the suffix and then
// end — no arbitrary text wedged in between.
return rest[sep+len(turnsSep):] == noOutputStopMarker+" "+noOutputStopSuffix
return after == noOutputStopMarker+" "+noOutputStopSuffix
}

// Reminder markers are stable substrings used both to build the reminder text
Expand Down
8 changes: 4 additions & 4 deletions internal/agent/guardrails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestRunInjectsStalePlanReminderAfterManyToolCalls(t *testing.T) {
turns := [][]zeroruntime.StreamEvent{
toolTurn("plan-1", "update_plan", `{"plan":[{"content":"step one"}]}`),
}
for i := 0; i < staleToolCallThreshold+2; i++ {
for range staleToolCallThreshold + 2 {
turns = append(turns, toolTurn("call", "read_file", `{"path":"notes.txt"}`))
}
turns = append(turns, textTurn("done"))
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestRunStalePlanReminderIsOneShotPerInterval(t *testing.T) {
}
// Enough tool calls to exceed the threshold by a wide margin; the reminder
// must fire once for the interval, not on every subsequent turn.
for i := 0; i < staleToolCallThreshold*2; i++ {
for range staleToolCallThreshold * 2 {
turns = append(turns, toolTurn("call", "read_file", `{"path":"notes.txt"}`))
}
turns = append(turns, textTurn("done"))
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestRunInjectsToolOnlyProgressReminder(t *testing.T) {
registry.Register(tools.NewReadFileTool(root))

turns := make([][]zeroruntime.StreamEvent, 0, toolOnlyProgressReminderAt+1)
for i := 0; i < toolOnlyProgressReminderAt; i++ {
for range toolOnlyProgressReminderAt {
turns = append(turns, toolTurn("call", "read_file", `{"path":"notes.txt"}`))
}
turns = append(turns, textTurn("done"))
Expand Down Expand Up @@ -441,7 +441,7 @@ func repeatedFlakyTurns(n int) [][]zeroruntime.StreamEvent {
{Type: zeroruntime.StreamEventDone},
}
turns := make([][]zeroruntime.StreamEvent, 0, n)
for i := 0; i < n; i++ {
for range n {
turns = append(turns, turn)
}
return turns
Expand Down
15 changes: 5 additions & 10 deletions internal/agent/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"errors"
"fmt"
"io"
"maps"
"slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -2481,9 +2483,7 @@
return nil
}
copied := make(map[string]any, len(args))
for key, value := range args {
copied[key] = value
}
maps.Copy(copied, args)
return copied
}

Expand Down Expand Up @@ -2512,7 +2512,7 @@
}

// partitionToolsCached is partitionTools with an optional per-tool definition
// cache. The partitioning itself (visibility, deferral, ordering) is recomputed

Check failure on line 2515 in internal/agent/loop.go

View workflow job for this annotation

GitHub Actions / Security & code health

unreachable func: partitionTools
// every call — it must be, because a tool's deferred state can flip mid-run (e.g.
// swarm tools un-defer once a swarm is active). Only the expensive part —
// rendering each tool's JSON-schema parameters — is memoized by tool name, since a
Expand Down Expand Up @@ -2679,12 +2679,7 @@
}

func containsToolName(names []string, name string) bool {
for _, candidate := range names {
if candidate == name {
return true
}
}
return false
return slices.Contains(names, name)
}

func schemaToRuntimeMap(schema tools.Schema) map[string]any {
Expand Down Expand Up @@ -2803,7 +2798,7 @@
return nil
}
var names []string
for _, part := range strings.Split(raw, ",") {
for part := range strings.SplitSeq(raw, ",") {
if trimmed := strings.TrimSpace(part); trimmed != "" {
names = append(names, trimmed)
}
Expand Down
8 changes: 2 additions & 6 deletions internal/agent/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -2393,12 +2394,7 @@ func TestRunAlwaysAllowWithoutSandboxStillAllowsCall(t *testing.T) {
}

func containsPermissionDecision(decisions []PermissionDecisionAction, want PermissionDecisionAction) bool {
for _, decision := range decisions {
if decision == want {
return true
}
}
return false
return slices.Contains(decisions, want)
}

// cancelMidStreamProvider cancels the run while the provider stream is open and
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/reconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestJitteredBackoffStaysInBounds(t *testing.T) {
// so backoff still grows attempt over attempt while decorrelating retries.
for attempt := 1; attempt <= 5; attempt++ {
base := backoffFor(attempt)
for i := 0; i < 200; i++ {
for range 200 {
got := jitteredBackoff(attempt)
if got < base || got > base+base/2 {
t.Fatalf("attempt %d jittered backoff %v out of [%v, %v]", attempt, got, base, base+base/2)
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/skills_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestSkillsContextCapsLongList(t *testing.T) {
skills := make([]SkillInfo, 0, 40)
for i := 0; i < 40; i++ {
for i := range 40 {
n := strconv.Itoa(i)
skills = append(skills, SkillInfo{Name: "skill-" + n, Description: "does something useful, number " + n})
}
Expand Down
11 changes: 4 additions & 7 deletions internal/agent/system_prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,7 @@ func truncateGuidelineContent(content string, limit int) string {
if limit <= 0 {
return ""
}
cut := limit - len(truncationMarker)
if cut < 0 {
cut = 0
}
cut := max(limit-len(truncationMarker), 0)
for cut > 0 && !utf8.RuneStart(content[cut]) {
cut--
}
Expand Down Expand Up @@ -443,7 +440,7 @@ func projectGuidelineDirs(cwd, gitRoot string) []string {
}
dirs := []string{gitRoot}
cur := gitRoot
for _, seg := range strings.Split(rel, string(filepath.Separator)) {
for seg := range strings.SplitSeq(rel, string(filepath.Separator)) {
if seg == "" || seg == "." {
continue
}
Expand Down Expand Up @@ -636,8 +633,8 @@ func gitBranchForPrompt(cwd string) string {
return ""
}
ref := strings.TrimSpace(string(data))
if strings.HasPrefix(ref, "ref: ") {
return strings.TrimPrefix(strings.TrimPrefix(ref, "ref: "), "refs/heads/")
if after, ok := strings.CutPrefix(ref, "ref: "); ok {
return strings.TrimPrefix(after, "refs/heads/")
}
if len(ref) >= 7 {
return ref[:7]
Expand Down
2 changes: 1 addition & 1 deletion internal/agenteval/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Task struct {
ExpectedChangedFiles []string `json:"expectedChangedFiles"`
ForbiddenChangedFiles []string `json:"forbiddenChangedFiles,omitempty"`
RequiredTraceEvents []string `json:"requiredTraceEvents,omitempty"`
ContextChecks ContextChecks `json:"contextChecks,omitempty"`
ContextChecks ContextChecks `json:"contextChecks"`
}

type Command struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/agenteval/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func ParseTraceEventKeys(stdout string) []string {
seen := map[string]bool{}
for _, line := range strings.Split(stdout, "\n") {
for line := range strings.SplitSeq(stdout, "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/background/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Task struct {
Status Status `json:"status"`
OutputFile string `json:"outputFile"`
StartedAt time.Time `json:"startedAt"`
CompletedAt time.Time `json:"completedAt,omitempty"`
CompletedAt time.Time `json:"completedAt"`
ExitCode int `json:"exitCode,omitempty"`
}

Expand Down
9 changes: 4 additions & 5 deletions internal/cli/agent_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -316,16 +317,14 @@ func appendAgentEvalModel(models []string, value string) []string {
if value == "" {
return models
}
for _, model := range models {
if model == value {
return models
}
if slices.Contains(models, value) {
return models
}
return append(models, value)
}

func appendAgentEvalModels(models []string, value string) []string {
for _, model := range strings.Split(value, ",") {
for model := range strings.SplitSeq(value, ",") {
models = appendAgentEvalModel(models, model)
}
return models
Expand Down
9 changes: 2 additions & 7 deletions internal/cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -812,13 +813,7 @@ func TestRunSkipPermissionsUnsafeMergesAddDirGrants(t *testing.T) {
t.Fatal("AgentOptions.Sandbox = nil, want sandbox engine")
}
roots := launchedOptions.AgentOptions.Sandbox.Scope().Roots()
found := false
for _, root := range roots {
if root == resolvedExtra {
found = true
break
}
}
found := slices.Contains(roots, resolvedExtra)
if !found {
t.Fatalf("scope roots = %v, want extra root %q", roots, resolvedExtra)
}
Expand Down
8 changes: 3 additions & 5 deletions internal/cli/cron_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ func TestFireJobClaimPreventsDoubleFire(t *testing.T) {
// Two schedulers fire the same due job concurrently; the atomic claim must let
// exactly one through, so the job never double-fires (M9).
var wg sync.WaitGroup
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range 2 {
wg.Go(func() {
job, _ := store.Get(due.ID)
var out, errb bytes.Buffer
fireJob(store, nowFn, job, &out, &errb, fx.run)
}()
})
}
wg.Wait()

Expand Down
Loading
Loading