From ad82c09720c7fd25be7ecd0deabc896fc8b95df6 Mon Sep 17 00:00:00 2001 From: therichardngai-code Date: Sun, 1 Mar 2026 21:23:38 +0700 Subject: [PATCH] fix(bootstrap): SeedUserFiles should use agent-level USER.md as seed for predefined agents (#30) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: SeedUserFiles uses agent-level USER.md as seed for predefined agents For predefined agents, the wizard writes a populated USER.md (owner name, language, notes) via agents.files.set into agent_context_files (agent-level). On the first chat message, SeedUserFiles was seeding a blank embedded template into user_context_files (per-user level). LoadContextFiles for predefined agents lets per-user content override agent-level content, so the blank per-user USER.md shadowed the wizard-written content. The owner profile was stored in the DB but never served to the agent, triggering unnecessary onboarding. Fix: before falling back to the embedded template, check whether agent_context_files already has a non-empty USER.md for the agent. If it does, use that content as the per-user seed. The check is conditional (predefined agent + USER.md not yet seeded per-user) so it adds at most one extra DB read per new user. The existing "don't overwrite" guard (hasFile check) is unchanged — personalized per-user content written through conversation is still never overwritten. * test: add unit tests for SeedUserFiles agent-level USER.md seeding Covers: - Predefined agent: wizard-written USER.md at agent level is used as per-user seed (primary regression test for the bug fix) - Predefined agent: falls back to blank embedded template when no agent-level USER.md exists - Predefined agent: existing per-user content is never overwritten - Open agent: embedded template path is unaffected - Predefined agent: BOOTSTRAP.md uses BOOTSTRAP_PREDEFINED.md template - Idempotency: second SeedUserFiles call seeds nothing * fix(bootstrap): SeedUserFiles uses agent-level USER.md as seed for predefined agents Use map[string]string for agent-level files (more general, extensible) and clean continue-based loop flow, matching the investigation spec in plans/goclaw-pr/goclaw-pr-seed-user-files.md exactly. Previous implementation used a single string and if/else structure — functionally correct but diverged from the spec in variable type, load condition, and loop exit pattern.