@codewizard-dt/bootstrap 2.15.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/hooks/README.md +192 -184
  2. package/lib/hooks/absolute-path-guard.js +5 -0
  3. package/lib/hooks/claude-settings-guard.js +43 -73
  4. package/lib/hooks/env-content-read-guard.js +13 -3
  5. package/lib/hooks/env-file-guard.js +42 -0
  6. package/lib/hooks/interpreter-indirection-guard.js +7 -0
  7. package/lib/hooks/lib/command-parse.js +8 -0
  8. package/lib/hooks/lib/serena-languages.js +94 -1
  9. package/lib/hooks/lib/serena.js +228 -0
  10. package/lib/hooks/mv-absolute-path-block.js +84 -3
  11. package/lib/hooks/package-install-consent.js +11 -0
  12. package/lib/hooks/protected-write-guard.js +7 -0
  13. package/lib/hooks/serena-bash-grep-block.js +507 -44
  14. package/lib/hooks/serena-first-glob-guard.js +65 -20
  15. package/lib/hooks/serena-first-guard.js +98 -2
  16. package/lib/hooks/serena-first-read-guard.js +92 -2
  17. package/lib/hooks/serena-pre-delegation.js +123 -0
  18. package/lib/hooks/serena-write-guard.js +56 -3
  19. package/lib/scripts/README.md +319 -16
  20. package/lib/scripts/bootstrap-prefs.js +734 -0
  21. package/lib/scripts/install-global.sh +182 -25
  22. package/lib/scripts/install-mcps.sh +102 -14
  23. package/lib/scripts/lib.sh +595 -20
  24. package/lib/scripts/merge-gitignore.sh +254 -16
  25. package/lib/scripts/merge-settings-hooks.js +374 -0
  26. package/lib/scripts/sync-wiki-scaffold.sh +33 -4
  27. package/lib/scripts/templates/CLAUDE-wiki.md +1 -1
  28. package/lib/scripts/templates/bootstrap-prefs-schema.json +175 -0
  29. package/lib/scripts/templates/settings-hooks.json +151 -0
  30. package/lib/scripts/update-project.sh +42 -9
  31. package/lib/skills/README.md +2 -1
  32. package/lib/skills/bootstrap-config/SKILL.md +154 -0
  33. package/lib/skills/git-commit/SKILL.md +54 -1
  34. package/lib/skills/research/SKILL.md +34 -3
  35. package/lib/skills/simplify/SKILL.md +1 -1
  36. package/lib/skills/uat-auto/SKILL.md +9 -4
  37. package/lib/skills/uat-auto-plus/SKILL.md +6 -6
  38. package/lib/skills/uat-generate/SKILL.md +30 -3
  39. package/lib/skills/uat-walk/UAT-CORE.md +41 -6
  40. package/lib/skills/wiki-query/SKILL.md +48 -8
  41. package/package.json +1 -1
@@ -36,8 +36,8 @@ PROJECT_DIR="$(resolve_project_dir "$1")" || exit 1
36
36
  TARGET="$PROJECT_DIR/.gitignore"
37
37
 
38
38
  # Interactive-only: without a tty there is nobody to ask, and we never add
39
- # .gitignore entries without asking.
40
- if [ "$INTERACTIVE" = false ] || [ ! -t 0 ]; then
39
+ # .gitignore entries without asking. has_tty (lib.sh) is the tty seam — it also honours BOOTSTRAP_ASSUME_TTY=1.
40
+ if [ "$INTERACTIVE" = false ] || ! has_tty; then
41
41
  echo ".gitignore: skipped (interactive only — run 'npx @codewizard-dt/bootstrap update' in a terminal to be offered the sections)."
42
42
  exit 0
43
43
  fi
@@ -86,6 +86,20 @@ section_missing_count() {
86
86
 
87
87
  added=0
88
88
 
89
+ # section_missing_lines <section-file>: print the entries that would be added,
90
+ # one per line, indented. Same selection logic as section_missing_count — a
91
+ # count alone ("3 new line(s)?") asks the user to consent to something they
92
+ # cannot see, so the prompt shows exactly what it will write.
93
+ section_missing_lines() {
94
+ local line trimmed
95
+ while IFS= read -r line || [ -n "$line" ]; do
96
+ trimmed="${line#"${line%%[![:space:]]*}"}"
97
+ [ -z "$trimmed" ] && continue
98
+ case "$trimmed" in \#*) continue ;; esac
99
+ grep -qFx -- "$line" "$EXISTING" || printf ' %s\n' "$line"
100
+ done < "$1"
101
+ }
102
+
89
103
  # merge_section <section-file>: append the section's missing lines, keeping
90
104
  # comment/blank lines buffered so headers only land when new entries follow.
91
105
  merge_section() {
@@ -114,26 +128,118 @@ merge_section() {
114
128
  done < "$1"
115
129
  }
116
130
 
131
+ # Tally before asking anything: the opening question should state the real
132
+ # scope, and a project with nothing to offer must not be asked at all.
133
+ total_missing=0
134
+ sections_offered=0
117
135
  i=1
118
136
  while [ "$i" -le "$SECTION_COUNT" ]; do
119
- SEC="$WORK_DIR/sec.$i"
120
- TITLE="section $i"
121
- [ -f "$WORK_DIR/title.$i" ] && TITLE="$(cat "$WORK_DIR/title.$i")"
122
- missing="$(section_missing_count "$SEC")"
123
- if [ "$missing" -eq 0 ]; then
124
- : # nothing new to offer for this section
125
- elif prompt_yn " Add/update .gitignore section '$TITLE' ($missing new line(s))? [y/N]: "; then
126
- merge_section "$SEC"
127
- else
128
- echo " .gitignore section '$TITLE': skipped."
137
+ n="$(section_missing_count "$WORK_DIR/sec.$i")"
138
+ if [ "$n" -gt 0 ]; then
139
+ total_missing=$((total_missing + n))
140
+ sections_offered=$((sections_offered + 1))
129
141
  fi
130
142
  i=$((i + 1))
131
143
  done
132
144
 
133
- if [ "$added" -eq 0 ]; then
134
- echo ".gitignore: no changes made in $PROJECT_DIR"
145
+ # One gate for the whole .gitignore pass, so a user who does not want their
146
+ # .gitignore touched answers once instead of once per section. This covers the
147
+ # section loop ONLY — the .git/info/exclude block below is a different mechanism
148
+ # (machine-local, never committed) and keeps its own prompt, so declining here
149
+ # still lets the sentinel repair run.
150
+ #
151
+ # The remembered answer is read with `prefs_get` rather than `prompt_yn_sticky`
152
+ # because this key is `scope: either`: it must resolve project → global →
153
+ # default. `prompt_yn_sticky` is single-selector by design (see the banner at
154
+ # lib.sh:226-232), which is correct only for `global`/`project` keys.
155
+ review_sections=0
156
+ if [ "$total_missing" -eq 0 ]; then
157
+ echo ".gitignore: already has everything the template offers in $PROJECT_DIR"
135
158
  else
159
+ case "$(prefs_get gitignore.offerSectionUpdates "$PROJECT_DIR")" in
160
+ false)
161
+ echo ".gitignore: skipped entirely — no sections offered. (remembered answer gitignore.offerSectionUpdates=false — change with /bootstrap-config)"
162
+ ;;
163
+ true)
164
+ # Schema default. The opening gate is dropped, but every section is still
165
+ # offered by title below, so nothing is ever appended silently.
166
+ review_sections=1
167
+ echo ".gitignore: opening gate off (remembered answer gitignore.offerSectionUpdates=true — change with /bootstrap-config); each section is still offered by title."
168
+ ;;
169
+ *)
170
+ # `ask`, `unset`, or an unrecognized value — today's behavior.
171
+ if prompt_yn " Review .gitignore updates? ($total_missing line(s) across $sections_offered section(s)) [y/N]: "; then
172
+ review_sections=1
173
+ else
174
+ prefs_set gitignore.offerSectionUpdates "$PROJECT_DIR" false
175
+ echo ".gitignore: skipped entirely — no sections offered."
176
+ fi
177
+ ;;
178
+ esac
179
+ fi
180
+
181
+ if [ "$review_sections" -eq 1 ]; then
182
+ i=1
183
+ while [ "$i" -le "$SECTION_COUNT" ]; do
184
+ SEC="$WORK_DIR/sec.$i"
185
+ TITLE="section $i"
186
+ [ -f "$WORK_DIR/title.$i" ] && TITLE="$(cat "$WORK_DIR/title.$i")"
187
+ missing="$(section_missing_count "$SEC")"
188
+ if [ "$missing" -gt 0 ]; then
189
+ # The title -> key slug is computed by bootstrap-prefs.js, NOT here. One
190
+ # banner title contains an em dash (U+2014): "Claude Code — machine-local
191
+ # MCP registration (...)". A byte-wise awk/sed `[^a-z0-9]` slugifier sees
192
+ # that character as three UTF-8 bytes and emits three dashes; the helper's
193
+ # JS regex carries the `u` flag and emits one. Keeping a single Unicode-
194
+ # aware implementation of the rule is the whole reason for the subshell.
195
+ #
196
+ # Guarded so a key we cannot compute never silently suppresses a section:
197
+ # --section-key exits 1 when a title slugifies to empty, node may be absent
198
+ # entirely, and this script runs under `set -euo pipefail`. On any failure
199
+ # SECTION_KEY stays empty and we fall back to the unconditional prompt.
200
+ SECTION_KEY=""
201
+ if [ -f "$BOOTSTRAP_PREFS_JS" ] && command -v node >/dev/null 2>&1; then
202
+ SECTION_KEY="$(node "$BOOTSTRAP_PREFS_JS" --section-key "$TITLE" 2>/dev/null)" || SECTION_KEY=""
203
+ fi
204
+ if [ -z "$SECTION_KEY" ]; then
205
+ echo " Warning: could not compute a preference key for .gitignore section '$TITLE' — asking every time." >&2
206
+ fi
207
+
208
+ if [ -n "$SECTION_KEY" ] && [ "$(prefs_get "$SECTION_KEY" "$PROJECT_DIR")" = "false" ]; then
209
+ # Remembered decline: skip BEFORE the preview. Re-listing lines the user
210
+ # already refused is the noise the remembered answer exists to remove.
211
+ echo " .gitignore section '$TITLE': skipped (remembered answer $SECTION_KEY=false — change with /bootstrap-config)."
212
+ else
213
+ # Show the actual lines before asking. Comment/blank lines are omitted:
214
+ # they are only written as headers when a real entry follows, so listing
215
+ # them would misrepresent what the "y" adds.
216
+ echo " .gitignore section '$TITLE' would add $missing line(s):"
217
+ section_missing_lines "$SEC"
218
+ if prompt_yn " Add these to .gitignore? [y/N]: "; then
219
+ # Deliberately records NOTHING on accept. A remembered `true` would
220
+ # append on the next run without asking and break the promise at the
221
+ # top of this file; the schema's one-value grammar (values: "false")
222
+ # already rejects it, so there is no second copy of the rule here.
223
+ merge_section "$SEC"
224
+ else
225
+ if [ -n "$SECTION_KEY" ]; then
226
+ prefs_set "$SECTION_KEY" "$PROJECT_DIR" false
227
+ fi
228
+ echo " .gitignore section '$TITLE': skipped."
229
+ fi
230
+ fi
231
+ fi
232
+ i=$((i + 1))
233
+ done
234
+ fi
235
+
236
+ # Only summarise when the section pass actually ran; the gate's own message
237
+ # already said what happened otherwise, and a second "no changes made" line
238
+ # reads as if something was attempted.
239
+ if [ "$added" -gt 0 ]; then
136
240
  echo ".gitignore: $added line(s) merged into $PROJECT_DIR"
241
+ elif [ "$review_sections" -eq 1 ]; then
242
+ echo ".gitignore: no changes made in $PROJECT_DIR"
137
243
  fi
138
244
 
139
245
  # Machine-local git exclusion for bootstrap agent state. These dirs must NEVER
@@ -258,17 +364,149 @@ if [ -d "$PROJECT_DIR/.git" ]; then
258
364
  : # already canonical — leave the file byte-identical
259
365
  elif [ "$exclude_missing" -gt 0 ]; then
260
366
  # Accepting newly hides paths from git, so this stays a consent prompt.
261
- if prompt_yn " Keep .serena/, raw/, wiki/ out of git on THIS machine (.git/info/exclude — not shared with the team; visible to Serena; @-autocomplete restored via the installed fileSuggestion script)? [y/N]: "; then
367
+ #
368
+ # `gitignore.infoExclude` is declines-only: a decline records `false` and
369
+ # suppresses the re-offer, an accept records NOTHING, because accepting
370
+ # changes the world and `exclude_is_canonical` above already makes it
371
+ # sticky. Keep this key distinct from `gitignore.offerSectionUpdates` (the
372
+ # .gitignore section pass) and `prefs.gitTracking` (the preference files
373
+ # themselves) — declining one must never disable another.
374
+ if [ "$(prefs_get gitignore.infoExclude "$PROJECT_DIR")" = "false" ]; then
375
+ echo " .git/info/exclude: skipped (remembered answer gitignore.infoExclude=false — change with /bootstrap-config)."
376
+ elif prompt_yn " Keep .serena/, raw/, wiki/ out of git on THIS machine (.git/info/exclude — not shared with the team; visible to Serena; @-autocomplete restored via the installed fileSuggestion script)? [y/N]: "; then
262
377
  if exclude_apply; then
263
378
  printf '%s' "$exclude_added"
264
379
  echo " Note: this protects only this clone — teammates opt in by running 'npx @codewizard-dt/bootstrap update' themselves."
265
380
  fi
381
+ else
382
+ prefs_set gitignore.infoExclude "$PROJECT_DIR" false
266
383
  fi
267
384
  else
268
385
  # All three are already excluded somewhere in the file: git's behaviour does
269
- # not change, only the picker's view of it. A pure repair, so no prompt.
386
+ # not change, only the picker's view of it. A pure repair, so no prompt —
387
+ # deliberately regardless of the stored `gitignore.infoExclude` value, since
388
+ # a decline refuses newly hiding paths, not repairing a sentinel.
270
389
  if exclude_apply; then
271
390
  echo " .git/info/exclude: reordered .serena/, raw/, wiki/ under the bootstrap sentinel (git unchanged; restores @-autocomplete)"
272
391
  fi
273
392
  fi
274
393
  fi
394
+
395
+ # ---------------------------------------------------------------------------
396
+ # How should git treat the preference files themselves?
397
+ #
398
+ # Asked LAST, after both passes above, so that any answer recorded earlier in
399
+ # this run has already created <project>/.claude/bootstrap-prefs.json and its
400
+ # generated companion .claude/bootstrap-prefs.README.md. The paths being offered
401
+ # therefore actually exist, and the user can open them before deciding.
402
+ #
403
+ # Chicken-and-egg, and it needs no special handling: the answer to this question
404
+ # lives in the very file the question governs. The values file is created by the
405
+ # first recorded answer and the question is asked afterwards, so the file is
406
+ # always there by the time we get here. `[3] neither` is a pure no-op that
407
+ # leaves prior state untouched, and `[1]` writes to .gitignore while the user is
408
+ # being asked, explicitly, right then — so the promise in this file's header
409
+ # comment (nothing reaches a project's .gitignore unasked) holds for that
410
+ # branch too.
411
+ #
412
+ # `prefs.gitTracking` is the ONE key in this script recorded in ALL THREE
413
+ # directions. The declines-only rule that governs gitignore.offerSectionUpdates
414
+ # and gitignore.infoExclude deliberately does NOT apply: this is a choice among
415
+ # three outcomes, not a yes/no on adding lines, so every answer is a real
416
+ # decision worth remembering. prompt_choice_sticky does that recording itself —
417
+ # do NOT also call prefs_set. One answer governs BOTH files; they live in the
418
+ # same directory precisely so a single question can cover them.
419
+ #
420
+ # The `has_tty` guard is belt-and-braces — the tty check at :40 already exits
421
+ # before this point on a non-interactive run. It stays because it is the seam a
422
+ # rework of that guard hangs off, and because reaching prompt_choice_sticky
423
+ # without a tty would resolve to the default without anyone being asked.
424
+ # ---------------------------------------------------------------------------
425
+ if has_tty; then
426
+ # The two governed paths, defined once.
427
+ PREFS_VALUES_PATH=".claude/bootstrap-prefs.json"
428
+ PREFS_README_PATH=".claude/bootstrap-prefs.README.md"
429
+
430
+ echo " How should .claude/bootstrap-prefs.json be treated by git?"
431
+ echo " [1] .gitignore — ignored for everyone who clones this repo (shared decision)"
432
+ echo " [2] .git/info/exclude — ignored on this machine only, teammates unaffected (default)"
433
+ echo " [3] neither — commit it, so the whole team shares these answers"
434
+ # Resolution is POSITIONAL: the trailing name list must stay in the printed
435
+ # menu order above, or a typed digit silently resolves to the wrong outcome.
436
+ answer="$(prompt_choice_sticky prefs.gitTracking "$PROJECT_DIR" exclude " How should we proceed? [1/2/3]: " gitignore exclude neither)"
437
+
438
+ case "$answer" in
439
+ gitignore)
440
+ prefs_written=0
441
+ for p in "$PREFS_VALUES_PATH" "$PREFS_README_PATH"; do
442
+ if [ -f "$TARGET" ] && grep -qFx -- "$p" "$TARGET"; then
443
+ continue
444
+ fi
445
+ if [ "$prefs_written" -eq 0 ]; then
446
+ if [ -s "$TARGET" ]; then
447
+ # Same idiom as merge_section: $() strips a trailing newline, so a
448
+ # non-empty result means the file does not end in one.
449
+ if [ -n "$(tail -c1 "$TARGET")" ]; then printf '\n' >> "$TARGET"; fi
450
+ printf '\n' >> "$TARGET"
451
+ fi
452
+ printf '# bootstrap preferences (remembered installer answers)\n' >> "$TARGET"
453
+ fi
454
+ printf '%s\n' "$p" >> "$TARGET"
455
+ echo " + $p"
456
+ prefs_written=$((prefs_written + 1))
457
+ done
458
+ if [ "$prefs_written" -eq 0 ]; then
459
+ echo " .gitignore: already ignores the bootstrap preference files."
460
+ else
461
+ echo " .gitignore: bootstrap preference files ignored for everyone who clones this repo."
462
+ fi
463
+ ;;
464
+ exclude)
465
+ if [ ! -d "$PROJECT_DIR/.git" ]; then
466
+ echo " .git/info/exclude: $PROJECT_DIR is not a git repository — nothing to exclude; the preference files stay visible to git."
467
+ else
468
+ prefs_written=0
469
+ for p in "$PREFS_VALUES_PATH" "$PREFS_README_PATH"; do
470
+ if [ -f "$GIT_EXCLUDE" ] && grep -qFx -- "$p" "$GIT_EXCLUDE"; then
471
+ continue
472
+ fi
473
+ if [ "$prefs_written" -eq 0 ]; then
474
+ mkdir -p "$(dirname "$GIT_EXCLUDE")"
475
+ if [ -s "$GIT_EXCLUDE" ] && [ -n "$(tail -c1 "$GIT_EXCLUDE")" ]; then
476
+ printf '\n' >> "$GIT_EXCLUDE"
477
+ fi
478
+ # Their OWN "#" header, never bare. Two things depend on it: the
479
+ # block above may already have normalized the sentinel block to the
480
+ # bottom of this file, and a "#" line directly after wiki/ is exactly
481
+ # what exclude_is_canonical accepts as the block terminator; and
482
+ # exclude_stranded stops scanning at the first "#", so our entries
483
+ # are never reported as stranded inside the bootstrap block.
484
+ printf '# bootstrap preferences (machine-local)\n' >> "$GIT_EXCLUDE"
485
+ fi
486
+ printf '%s\n' "$p" >> "$GIT_EXCLUDE"
487
+ echo " + $p (.git/info/exclude)"
488
+ prefs_written=$((prefs_written + 1))
489
+ done
490
+ if [ "$prefs_written" -eq 0 ]; then
491
+ echo " .git/info/exclude: already excludes the bootstrap preference files."
492
+ else
493
+ echo " Note: this hides them on THIS machine only — teammates are unaffected."
494
+ fi
495
+ # Verify rather than trust: a file left non-canonical is silently
496
+ # rewritten by exclude_normalize on every future run. Repair ONLY when
497
+ # the sentinel is already present — exclude_apply would otherwise create
498
+ # the block and hide .serena/, raw/, wiki/ from a user who just declined
499
+ # exactly that above. A later normalize pass leaves our lines intact,
500
+ # because its scrub only removes the sentinel and those three paths.
501
+ if [ -f "$GIT_EXCLUDE" ] \
502
+ && grep -qFx -- "$EXCLUDE_SENTINEL" "$GIT_EXCLUDE" \
503
+ && ! exclude_is_canonical "$GIT_EXCLUDE"; then
504
+ exclude_apply || true
505
+ fi
506
+ fi
507
+ ;;
508
+ neither|*)
509
+ echo " .claude/bootstrap-prefs.json and .claude/bootstrap-prefs.README.md stay visible to git — commit them so the whole team shares these answers."
510
+ ;;
511
+ esac
512
+ fi