fix: make mosaic init idempotent — detect existing config files #355

Merged
jason.woltje merged 2 commits from fix/idempotent-init into main 2026-04-03 01:30:02 +00:00
Owner

Problem

mosaic init blindly overwrites existing SOUL.md, USER.md, and TOOLS.md with no detection, causing users to lose their customized agent identity on reinstall/upgrade.

Changes

packages/mosaic/framework/tools/_scripts/mosaic-init (bash script)

  • Added detect_existing_config() — checks for existing config files before proceeding
  • Interactive mode shows 3 options: keep (update runtime adapters only), import (re-use existing values as defaults, then re-run prompts), overwrite (timestamped backup + fresh)
  • Non-interactive mode exits cleanly if files exist (unless --force is passed)
  • Added import_existing_values() — parses agent name, role, style, user name, pronouns, timezone from existing markdown
  • Added --force flag to skip detection in scripts/CI

packages/cli/src/commands/launch.ts

  • checkSoul() now prefers mosaic wizard (TypeScript, already idempotent) over the legacy bash mosaic-init when SOUL.md is missing
  • Falls back to bash script if wizard isn't available

packages/mosaic/src/stages/detect-install.ts

  • reconfigure action now pre-loads existing config values (previously only keep did this)
  • Users see their current settings as defaults when reconfiguring

packages/mosaic/src/stages/soul-setup.ts

  • During reconfigure, shows existing agent name and communication style as pre-filled defaults

Tests

  • Added: reconfigure pre-populates state from existing files
  • Added: reset does NOT pre-populate (clean slate)
  • All 37 tests pass

Testing

pnpm --filter @mosaic/mosaic test   # 37 passed
pnpm typecheck                      # 36/36 tasks passed
pnpm lint                           # 20/20 tasks passed
pnpm format:check                   # All matched files use Prettier code style
## Problem `mosaic init` blindly overwrites existing `SOUL.md`, `USER.md`, and `TOOLS.md` with no detection, causing users to lose their customized agent identity on reinstall/upgrade. ## Changes ### `packages/mosaic/framework/tools/_scripts/mosaic-init` (bash script) - Added `detect_existing_config()` — checks for existing config files before proceeding - Interactive mode shows 3 options: **keep** (update runtime adapters only), **import** (re-use existing values as defaults, then re-run prompts), **overwrite** (timestamped backup + fresh) - Non-interactive mode exits cleanly if files exist (unless `--force` is passed) - Added `import_existing_values()` — parses agent name, role, style, user name, pronouns, timezone from existing markdown - Added `--force` flag to skip detection in scripts/CI ### `packages/cli/src/commands/launch.ts` - `checkSoul()` now prefers `mosaic wizard` (TypeScript, already idempotent) over the legacy bash `mosaic-init` when SOUL.md is missing - Falls back to bash script if wizard isn't available ### `packages/mosaic/src/stages/detect-install.ts` - `reconfigure` action now pre-loads existing config values (previously only `keep` did this) - Users see their current settings as defaults when reconfiguring ### `packages/mosaic/src/stages/soul-setup.ts` - During `reconfigure`, shows existing agent name and communication style as pre-filled defaults ### Tests - Added: reconfigure pre-populates state from existing files - Added: reset does NOT pre-populate (clean slate) - All 37 tests pass ## Testing ``` pnpm --filter @mosaic/mosaic test # 37 passed pnpm typecheck # 36/36 tasks passed pnpm lint # 20/20 tasks passed pnpm format:check # All matched files use Prettier code style ```
jason.woltje added 1 commit 2026-04-03 01:25:17 +00:00
fix: make mosaic init idempotent — detect existing config files
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
ci/woodpecker/push/ci Pipeline failed
361fece023
- mosaic-init bash script: detect existing SOUL.md/USER.md/TOOLS.md and
  prompt user to keep, import (re-use values as defaults), or overwrite.
  Non-interactive mode exits cleanly unless --force is passed.
  Overwrite creates timestamped backups before replacing files.

- launch.ts checkSoul(): prefer 'mosaic wizard' over legacy bash script
  when SOUL.md is missing, with fallback to mosaic-init.

- detect-install.ts: pre-populate wizard state with existing values when
  user chooses 'reconfigure', so they see current settings as defaults.

- soul-setup.ts: show existing agent name and communication style as
  defaults during reconfiguration.

- Added tests for reconfigure pre-population and reset non-population.
jason.woltje added 1 commit 2026-04-03 01:26:34 +00:00
chore: bump @mosaic/mosaic and @mosaic/cli to 0.0.3
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
07efaa9580
jason.woltje merged commit e46f0641f6 into main 2026-04-03 01:30:02 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#355