You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: refactor waza new to use shared FileWriter #58 (#66)
* feat: refactor waza new to use shared FileWriter #58
Replace the inline write loop in cmd_new.go with the shared FileWriter
from internal/scaffold/writer.go. Malformed SKILL.md detection still runs
before FileWriter — the file is removed so FileWriter creates it fresh.
Inventory now uses consistent ➕/✅ emoji indicators (always visible,
not gated behind --verbose), matching the waza init behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* chore: update squad state for #58
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
-**What:** Created `FileWriter` service in `internal/scaffold/` that encapsulates the create-if-missing + skip-if-exists pattern used by `waza init`. Returns structured `Inventory` with per-entry outcomes. Refactored `cmd_init.go` Phase 5 to use `FileWriter` instead of its inline write loop. Inventory is always visible with ➕/✅ indicators. 8 unit tests covering all paths.
101
101
-**Key learning:** The `internal/scaffold/` package already existed with template functions for eval/skill generation — `FileWriter` fits naturally alongside those. The `FileEntry` type mirrors the old `initItem` struct but is exported for reuse by `cmd_new.go` in a future PR. Empty-content file entries (e.g., when `needConfigPrompt` is false) are treated as skipped — the writer doesn't create zero-byte files.
102
+
103
+
### #58 — Refactor waza new to use shared FileWriter (PR pending)
-**What:** Replaced the inline `writeFiles()` loop and `fileEntry` type in `cmd_new.go` with the shared `FileWriter` from `internal/scaffold/writer.go`. The malformed SKILL.md detection (`detectExistingSkillMD`) still runs before FileWriter — when overwrite is needed, the malformed file is deleted so FileWriter creates it fresh with ➕. Removed `lipgloss` dependency from the file. Updated 5 test assertions to match ➕/✅ emoji indicators instead of lipgloss-styled ✓/+.
108
+
-**Key learning:** The `overwrite` flag pattern from the old `fileEntry` struct doesn't map directly to FileWriter's create-if-missing model. The clean solution is to `os.Remove` the malformed file before passing it to FileWriter, so the writer sees it as absent and creates it normally. This avoids adding overwrite complexity to the shared FileWriter API while keeping the malformed-detection logic intact.
When a file needs to be overwritten (e.g., malformed SKILL.md repair), the caller should `os.Remove` the file before passing it to `FileWriter`. The FileWriter then sees it as absent and creates it normally with ➕ indicator. This avoids adding overwrite/force-write complexity to the shared `FileWriter` API.
10
+
11
+
## Why
12
+
13
+
The FileWriter's single responsibility is create-if-missing + skip-if-exists. Adding an overwrite flag would complicate the API and make it harder to reason about. The delete-then-create pattern keeps the FileWriter simple while letting callers handle their own pre-write logic.
14
+
15
+
## Impact
16
+
17
+
Any future command that needs to overwrite an existing file via FileWriter should follow this pattern: detect the condition, remove the stale file, then call `fw.Write()`.
0 commit comments