From 39692ba99fb55c7d621fd2153fc490204d7df5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sun, 31 May 2026 15:07:15 +0000 Subject: [PATCH] dev: start-* launchers always start from a clean setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The launchers reused whatever was left under $XDG_CACHE_HOME/nuwiki-dev between runs — seed_wiki() skipped reseeding when index.wiki already existed, so stale edits from a previous session leaked into the next, and old swap/viminfo/coc state carried over. Each launch now starts clean: - seed_wiki() reseeds the managed scratch wiki from a pristine copy every run (rm -rf + write_sample_wiki). A user-pointed NUWIKI_DEV_WIKI is never wiped — it's seeded only when empty, so a real wiki is never clobbered. NUWIKI_DEV_NO_SEED still bypasses seeding entirely. - new reset_dirs() helper wipes + recreates each launcher's owned state dirs (vim viminfo/swap/undo, coc data, nvim XDG state/data/config) before launch. Cached plugin clones (vim-lsp, async.vim, coc.nvim) are kept — only the wiki and editor state are reset. Header docs updated to describe the fresh-each-launch behavior. Co-Authored-By: Claude Opus 4.8 (1M context) --- development/_common.sh | 34 +++++++++++++++++++++++++++++----- development/start-nvim.sh | 7 ++++++- development/start-vim-coc.sh | 6 ++++++ development/start-vim.sh | 6 ++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/development/_common.sh b/development/_common.sh index 800e053..d48fe30 100644 --- a/development/_common.sh +++ b/development/_common.sh @@ -12,7 +12,10 @@ # log — prefixed status line # ensure_binary — build + symlink nuwiki-ls # write_sample_wiki DIR — lay down the feature-showcase wiki -# seed_wiki — seed WIKI_DIR (respects NUWIKI_DEV_NO_SEED) +# reset_dirs DIR... — wipe + recreate owned state dirs +# seed_wiki — (re)seed WIKI_DIR fresh each run; never +# touches a user-supplied NUWIKI_DEV_WIKI; +# respects NUWIKI_DEV_NO_SEED # Resolve paths relative to this file so it works regardless of which # launcher sources it. @@ -261,16 +264,37 @@ A diary entry. Back to [[diary]]. EOF } +# reset_dirs DIR... — wipe and recreate each dir so a launch always starts +# from clean editor state (swap/undo/viminfo, coc data, nvim XDG dirs). Only +# ever called on dirs the launchers own under $DEV_DIR. +reset_dirs() { + local d + for d in "$@"; do + rm -rf "$d" + mkdir -p "$d" + done +} + seed_wiki() { if [[ "${NUWIKI_DEV_NO_SEED:-0}" == "1" ]]; then log "NUWIKI_DEV_NO_SEED=1 — skipping wiki seed (using $WIKI_DIR as-is)" return fi - mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary" - # Seed the whole showcase as a unit; skip when an index already exists - # so a re-run never clobbers edits made while testing. - if [[ -f "$WIKI_DIR/index.wiki" ]]; then + # A user-pointed wiki (NUWIKI_DEV_WIKI) is never wiped — it might be a real + # wiki. Seed the sample only when it has no index yet, so we don't clobber it. + if [[ -n "${NUWIKI_DEV_WIKI:-}" ]]; then + mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary" + if [[ -f "$WIKI_DIR/index.wiki" ]]; then + log "using existing wiki at $WIKI_DIR (left untouched)" + return + fi + write_sample_wiki "$WIKI_DIR" return fi + # Managed scratch wiki under the dev cache: always start from a pristine + # copy so stale edits from a previous run never leak into the next. + log "reseeding scratch wiki (fresh copy): $WIKI_DIR" + rm -rf "$WIKI_DIR" + mkdir -p "$WIKI_DIR" "$WIKI_DIR/diary" write_sample_wiki "$WIKI_DIR" } diff --git a/development/start-nvim.sh b/development/start-nvim.sh index 88e3e7c..6963e04 100755 --- a/development/start-nvim.sh +++ b/development/start-nvim.sh @@ -22,6 +22,11 @@ # so this is a fast no-op when nothing changed. Set # NUWIKI_DEV_SKIP_BUILD=1 to skip the build step entirely. # +# Each launch starts clean: the scratch wiki is reseeded from a pristine +# copy and the editor state (cache/data/config) is wiped, so stale edits +# never carry over. A wiki you point at with NUWIKI_DEV_WIKI is never wiped +# (seeded only if empty). +# # Tested with Neovim 0.10+. State (cache/data/config) lives under # $XDG_CACHE_HOME/nuwiki-dev/ so your real Neovim install stays # untouched. @@ -78,7 +83,7 @@ main() { ensure_binary seed_wiki write_init - mkdir -p "$STATE_DIR" "$DATA_DIR" "$CONFIG_DIR" + reset_dirs "$STATE_DIR" "$DATA_DIR" "$CONFIG_DIR" log "launching: nvim --clean -u $INIT_FILE" if [[ $# -gt 0 ]]; then diff --git a/development/start-vim-coc.sh b/development/start-vim-coc.sh index 5ee04bc..a6dd59c 100755 --- a/development/start-vim-coc.sh +++ b/development/start-vim-coc.sh @@ -29,6 +29,11 @@ # the running LSP. `cargo build --release` is incremental, so this is a fast # no-op when nothing changed. Set NUWIKI_DEV_SKIP_BUILD=1 to skip the build. # +# Each launch starts clean: the scratch wiki is reseeded from a pristine +# copy and the editor state (viminfo/swap/undo, coc data) is wiped, so stale +# edits never carry over. The cached coc.nvim clone is kept. A wiki you point +# at with NUWIKI_DEV_WIKI is never wiped (seeded only if empty). +# # Tested with Vim 9.1+ and Node 18+. State (viminfo/sessions, coc data) lives # under $XDG_CACHE_HOME/nuwiki-dev/ so your real Vim install stays untouched. @@ -165,6 +170,7 @@ main() { write_coc_settings seed_wiki write_vimrc + reset_dirs "$VIM_STATE" "$COC_DATA" mkdir -p "$VIM_STATE/swap" "$VIM_STATE/backup" "$VIM_STATE/undo" "$COC_DATA" log "launching: vim --clean -u $VIMRC" diff --git a/development/start-vim.sh b/development/start-vim.sh index 939ee1d..cc32d28 100755 --- a/development/start-vim.sh +++ b/development/start-vim.sh @@ -20,6 +20,11 @@ # so this is a fast no-op when nothing changed. Set # NUWIKI_DEV_SKIP_BUILD=1 to skip the build step entirely. # +# Each launch starts clean: the scratch wiki is reseeded from a pristine +# copy and the editor state (viminfo/swap/undo) is wiped, so stale edits +# never carry over. The cached vim-lsp/async.vim clones are kept. A wiki you +# point at with NUWIKI_DEV_WIKI is never wiped (seeded only if empty). +# # Tested with Vim 9.1+. State (viminfo/sessions) lives under # $XDG_CACHE_HOME/nuwiki-dev/ so your real Vim install stays untouched. @@ -119,6 +124,7 @@ main() { ensure_vim_lsp seed_wiki write_vimrc + reset_dirs "$VIM_STATE" mkdir -p "$VIM_STATE/swap" "$VIM_STATE/backup" "$VIM_STATE/undo" log "launching: vim --clean -u $VIMRC"