Skip to content

Commit add1006

Browse files
committed
test message
1 parent 7345e6d commit add1006

7 files changed

Lines changed: 54 additions & 36 deletions

File tree

cmd/iterate/features_tools.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ var themes = map[string]theme{
242242
}
243243

244244
func applyTheme(t theme) {
245+
colorMu.Lock()
246+
defer colorMu.Unlock()
245247
colorLime = t.lime
246248
colorYellow = t.yellow
247249
colorCyan = t.cyan

cmd/iterate/repl.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/signal"
1010
"path/filepath"
1111
"strings"
12+
"sync"
1213
"syscall"
1314
"time"
1415

@@ -17,8 +18,10 @@ import (
1718
"github.com/GrayCodeAI/iterate/internal/ui/selector"
1819
)
1920

20-
// Color variables — reassignable for /theme support
21+
// Color variables — reassignable for /theme support.
22+
// Protected by colorMu: applyTheme writes, signal handler goroutine reads.
2123
var (
24+
colorMu sync.RWMutex
2225
colorReset = "\033[0m"
2326
colorLime = "\033[38;5;154m"
2427
colorYellow = "\033[38;5;220m"
@@ -116,7 +119,11 @@ func setupSigintHandler() {
116119
for range sigCh {
117120
if sess.RequestCancel != nil {
118121
sess.RequestCancel()
119-
fmt.Printf("\r\033[K%s[cancelled]%s\n", colorYellow, colorReset)
122+
// Snapshot colors under read lock — applyTheme writes these from the main goroutine.
123+
colorMu.RLock()
124+
y, r := colorYellow, colorReset
125+
colorMu.RUnlock()
126+
fmt.Printf("\r\033[K%s[cancelled]%s\n", y, r)
120127
}
121128
}
122129
}()

internal/evolution/engine.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ type Engine struct {
7070
prURL string
7171
branchName string
7272
traceID string
73-
toolMap map[string]iteragent.Tool // cached at construction to avoid re-init per call
73+
toolMap map[string]iteragent.Tool // cached at construction — avoids re-init per call
74+
tools []iteragent.Tool // cached tool slice for agent construction
75+
skills *iteragent.SkillSet // cached skills — loaded once per engine
7476
}
7577

7678
// generateTraceID creates a random hex trace ID for request correlation.
@@ -106,12 +108,15 @@ func New(repoPath string, logger *slog.Logger) *Engine {
106108
}
107109
tid := generateTraceID()
108110
tools := iteragent.DefaultTools(repoPath)
111+
skills, _ := iteragent.LoadSkills([]string{filepath.Join(repoPath, "skills")})
109112
e := &Engine{
110113
repoPath: repoPath,
111114
repo: repo,
112115
logger: logger.With("traceID", tid),
113116
traceID: tid,
114117
toolMap: iteragent.ToolMap(tools),
118+
tools: tools,
119+
skills: skills,
115120
}
116121
// Load PR state from previous phase if exists
117122
e.loadPRState()
@@ -206,9 +211,7 @@ func (e *Engine) Run(ctx context.Context, p iteragent.Provider, issues string) (
206211
systemPrompt := buildSystemPrompt(e.repoPath, string(identity))
207212
userMessage := buildUserMessage(e.repoPath, string(journal), issues)
208213

209-
tools := iteragent.DefaultTools(e.repoPath)
210-
skills, _ := iteragent.LoadSkills([]string{filepath.Join(e.repoPath, "skills")})
211-
a := e.newAgent(p, tools, systemPrompt, skills)
214+
a := e.newAgent(p, e.tools, systemPrompt, e.skills)
212215

213216
output, runErr := e.runAgentAndCollectEvents(ctx, a, userMessage)
214217
a.Finish()
@@ -227,7 +230,7 @@ func (e *Engine) Run(ctx context.Context, p iteragent.Provider, issues string) (
227230
return result, nil
228231
}
229232

230-
if err := e.handlePostRunTests(ctx, day, output, p, tools, skills, result); err != nil {
233+
if err := e.handlePostRunTests(ctx, day, output, p, e.tools, e.skills, result); err != nil {
231234
return result, err
232235
}
233236

@@ -392,5 +395,5 @@ func (e *Engine) auditLog(eventType, tool, detail string) {
392395
return
393396
}
394397
defer f.Close()
395-
f.Write(append(data, '\n'))
398+
_, _ = f.Write(append(data, '\n'))
396399
}

internal/evolution/phases.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ func (e *Engine) RunPlanPhase(ctx context.Context, p iteragent.Provider, issues
1919
userMessage := buildPlanPrompt(e.repoPath, string(journal), day, issues)
2020

2121
systemPrompt := buildSystemPrompt(e.repoPath, string(identity))
22-
tools := iteragent.DefaultTools(e.repoPath)
23-
skills, _ := iteragent.LoadSkills([]string{filepath.Join(e.repoPath, "skills")})
24-
a := e.newAgent(p, tools, systemPrompt, skills)
22+
a := e.newAgent(p, e.tools, systemPrompt, e.skills)
2523

2624
var lastContent string
2725
for ev := range a.Prompt(ctx, userMessage) {
@@ -240,11 +238,9 @@ func (e *Engine) runTaskAttempt(ctx context.Context, p iteragent.Provider, task
240238
return true, ""
241239
}
242240

243-
// loadImplementContext prepares system prompt, tools, and skills for implementation.
241+
// loadImplementContext prepares the system prompt for implementation using cached tools and skills.
244242
func (e *Engine) loadImplementContext() (string, []iteragent.Tool, *iteragent.SkillSet) {
245243
identity, _ := os.ReadFile(filepath.Join(e.repoPath, "docs/IDENTITY.md"))
246244
systemPrompt := buildSystemPrompt(e.repoPath, string(identity))
247-
tools := iteragent.DefaultTools(e.repoPath)
248-
skills, _ := iteragent.LoadSkills([]string{filepath.Join(e.repoPath, "skills")})
249-
return systemPrompt, tools, skills
245+
return systemPrompt, e.tools, e.skills
250246
}

internal/ui/selector/selector_history_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestRedactSensitiveInput_RedactsProviderKey(t *testing.T) {
9494

9595
func TestRedactSensitiveInput_PassesThroughSafe(t *testing.T) {
9696
safe := []string{
97-
"/provider anthropic", // no key
97+
"/provider anthropic", // no key
9898
"/help",
9999
"hello world",
100100
"",
@@ -214,25 +214,19 @@ func TestInitHistory_LoadsFromFile(t *testing.T) {
214214
histFile := filepath.Join(dir, "history")
215215
os.WriteFile(histFile, []byte("cmd1\ncmd2\ncmd3\n"), 0o600)
216216

217-
// Temporarily point historyFile to test file and re-load
217+
// Point historyFile at the temp file, then call the real loader.
218218
historyFile = histFile
219-
f, _ := os.Open(histFile)
220-
defer f.Close()
221-
import_scanner := func() {
222-
inputHistoryMu.Lock()
223-
defer inputHistoryMu.Unlock()
224-
import_buf := make([]byte, 4096)
225-
n, _ := f.Read(import_buf)
226-
for _, line := range strings.Split(strings.TrimRight(string(import_buf[:n]), "\n"), "\n") {
227-
if line != "" {
228-
inputHistory = append(inputHistory, line)
229-
}
230-
}
231-
}
232-
import_scanner()
219+
InitHistory()
233220

234221
h := getInputHistory()
235-
if len(h) != 3 || h[0] != "cmd1" {
236-
t.Errorf("unexpected history loaded: %v", h)
222+
// InitHistory appends to existing; we reset first so count is exact.
223+
var found []string
224+
for _, v := range h {
225+
if v == "cmd1" || v == "cmd2" || v == "cmd3" {
226+
found = append(found, v)
227+
}
228+
}
229+
if len(found) != 3 {
230+
t.Errorf("expected cmd1/cmd2/cmd3 in history, got %v", h)
237231
}
238232
}

internal/ui/selector/selector_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ func TestFormatElapsed(t *testing.T) {
145145
input int64 // nanoseconds
146146
contains string
147147
}{
148-
{500_000_000, "ms"}, // 500ms
149-
{5_500_000_000, "s"}, // 5.5s
150-
{65_000_000_000, "m"}, // 1m5s
148+
{500_000_000, "ms"}, // 500ms
149+
{5_500_000_000, "s"}, // 5.5s
150+
{65_000_000_000, "m"}, // 1m5s
151151
}
152152
for _, tt := range tests {
153153
got := formatElapsed(time.Duration(tt.input))

scripts/evolution/evolve.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,39 @@ BRANCH="evolution/day-${DAY}"
184184
=======
185185
# ── Final commit and push ──
186186
log "Pushing changes..."
187+
<<<<<<< Updated upstream
188+
>>>>>>> Stashed changes
189+
=======
187190
>>>>>>> Stashed changes
188191

189192
# Re-calculate day after pull (pull may overwrite DAY_COUNT)
190193
DAY=$(( ($(date -u +%s) - $(date -d "$BIRTH_DATE" +%s 2>/dev/null || date -j -f "%Y-%m-%d" "$BIRTH_DATE" +%s)) / 86400 ))
191194
echo "$DAY" > "${REPOPATH}/DAY_COUNT"
192195

196+
<<<<<<< Updated upstream
193197
<<<<<<< Updated upstream
194198
# Stage and commit all changes
195199
=======
196200
>>>>>>> Stashed changes
201+
=======
202+
>>>>>>> Stashed changes
197203
if [[ -n $(git status -s) ]]; then
198204
git add -A
199205
git commit -m "iterate: Day $DAY evolution session" 2>/dev/null || true
200206
fi
201207
<<<<<<< Updated upstream
202208
=======
203209
git pull --rebase origin main 2>/dev/null || true
210+
<<<<<<< Updated upstream
211+
=======
212+
213+
# Always ensure DAY_COUNT is correct after pull
214+
echo "$DAY" > "${REPOPATH}/DAY_COUNT"
215+
git add DAY_COUNT 2>/dev/null || true
216+
git commit --amend --no-edit 2>/dev/null || git commit -m "iterate: Day $DAY evolution session" 2>/dev/null || true
217+
218+
git push origin main 2>/dev/null || log "Push failed"
219+
>>>>>>> Stashed changes
204220

205221
# Always ensure DAY_COUNT is correct after pull
206222
echo "$DAY" > "${REPOPATH}/DAY_COUNT"

0 commit comments

Comments
 (0)