@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
@@ -1,9 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- // mv-absolute-path-block.js — PreToolUse hook (matcher: Bash, if: Bash(mv *))
5
- // Blocks `mv` commands where any argument is an absolute path rooted outside
6
- // the project directory. Directs the user to check the project root.
4
+ /**
5
+ * mv-absolute-path-block.js — PreToolUse / Bash (wiring adds `if: Bash(mv *)`)
6
+ *
7
+ * Blocks: an `mv` with an absolute-path argument rooted outside the hook's idea
8
+ * of the project root (see BUG-0005 below — that idea is not the session's) —
9
+ * the "I thought I was somewhere else" move that lands a file in /etc, /usr,
10
+ * or a neighbouring repo.
11
+ * Why a hook: whether an absolute path is acceptable depends on where the
12
+ * project root is, and a settings.json pattern cannot see the project root.
13
+ * Denying every absolute-path mv would deny the legitimate in-project ones
14
+ * too, and enumerating the roots worth protecting is precisely the unbounded
15
+ * list a hook exists to replace. The verdict also has to arrive as a
16
+ * CORRECTION ("check that you are in the project root") rather than a
17
+ * prohibition, and a deny rule cannot carry a message at all.
18
+ * Fails: open — unparseable stdin exits 0 silently at the JSON.parse catch
19
+ * below. A payload that parses to a non-object (`null`) throws on
20
+ * `data.tool_name` and exits non-zero, which Claude Code reads as a
21
+ * NON-blocking hook error: stderr is surfaced and the tool call proceeds
22
+ * anyway. Both paths allow. This file does not use lib/command-parse.js's
23
+ * readHookInput, so there is no handler-level catch; of the hooks in this
24
+ * directory only interpreter-indirection-guard.js genuinely fails closed.
25
+ * False positives: a pipeline is not a segment boundary here, so a later
26
+ * stage's absolute path is attributed to the `mv` —
27
+ * `mv notes.md archive.md | tee /var/log/mvlog.txt` denies a move that is
28
+ * entirely in-project (BUG-0006, annotated at the segment split below) —
29
+ * escape hatch: join with `&&` instead of `|`, which IS a segment boundary,
30
+ * so the `mv` is then judged on its own two operands.
31
+ * See README.md § Safety / policy hooks for the full rationale.
32
+ */
7
33
 
8
34
  const path = require('path');
9
35
 
@@ -18,10 +44,56 @@ process.stdin.on('end', () => {
18
44
  const fullCmd = String(data.tool_input?.command ?? '').trim();
19
45
  if (!fullCmd) process.exit(0);
20
46
 
47
+ // BUG-0005 — UNEXPLAINED DIVERGENCE, annotated here and deliberately not fixed.
48
+ // Every sibling guard that needs a project root reads `data.cwd` off the hook
49
+ // payload and falls back to `process.cwd()` only if it is missing
50
+ // (protected-write-guard.js:189, claude-settings-guard.js:192,
51
+ // interpreter-indirection-guard.js:579, serena-pre-delegation.js:95). This one
52
+ // alone asks node and never looks at the payload. `data.cwd` is the
53
+ // authoritative session cwd Claude Code reports for the tool call;
54
+ // `process.cwd()` is merely wherever the node process running this hook was
55
+ // started. When the two differ the check inverts in BOTH directions: absolute
56
+ // paths that really are in-project stop matching `cwdWithSep` and get denied,
57
+ // while paths under node's cwd but outside the session's project get allowed.
58
+ // No comment, commit message, or test explains the choice, which is why it is
59
+ // filed rather than assumed intentional. Do not swap it in passing — it is a
60
+ // behaviour change to a live shipped control and belongs to BUG-0005.
21
61
  const cwd = process.cwd();
22
62
  const cwdWithSep = cwd + path.sep;
23
63
 
24
64
  // Split on command separators and inspect each segment independently.
65
+ //
66
+ // BUG-0006 — DIVERGENCE, annotated and deliberately not fixed: this list is
67
+ // `;`, `&&`, `||` but NOT `|`, whereas lib/command-parse.js's splitSegments
68
+ // (:48) includes the pipe. Read the next three paragraphs before touching it,
69
+ // because the obvious reading of this gap is wrong.
70
+ //
71
+ // It is NOT a bypass. `args` is `tokens.slice(mvIdx + 1)` and runs to the end
72
+ // of the segment, straight through any `|`, so an absolute path still lands in
73
+ // `args` regardless of which pipeline stage wrote it:
74
+ // echo x | mv /etc/foo /tmp/bar still denies
75
+ // cat mv | mv /etc/x /tmp/y still denies
76
+ //
77
+ // The actual defect is the inverse — FALSE denials. Operands belonging to a
78
+ // later stage are attributed to the `mv`, so a wholly in-project move that
79
+ // merely logs somewhere absolute is refused:
80
+ // mv notes.md archive.md | tee /var/log/mvlog.txt denies, wrongly
81
+ //
82
+ // WARNING TO THE NEXT READER: the tempting fix — anchor the verb at the head
83
+ // of each segment, the way absolute-path-guard.js does — would OPEN the bypass
84
+ // this only looks like it has. With `|` still absent from the split,
85
+ // `echo x | mv /etc/foo /tmp/bar` is one segment headed by `echo`, and an
86
+ // anchored check would stop seeing the `mv` entirely. Adding `|` to the split
87
+ // and anchoring the verb are a single change, not two; either one alone makes
88
+ // this hook strictly worse. That coupling is why it is filed as BUG-0006
89
+ // instead of patched in place.
90
+ //
91
+ // One nuance if you go to reproduce any of the above: the shipped wiring gates
92
+ // this hook behind `if: Bash(mv *)` (settings-hooks.json:104), so only commands
93
+ // whose first token is `mv` reach the file at all. `echo x | mv /etc/foo …` is
94
+ // filtered out upstream and never arrives, while the false-denial case does,
95
+ // because it starts with `mv`. The gate lives in settings-hooks.json, not
96
+ // here, so the logic above still has to stand on its own if it is relaxed.
25
97
  const segments = fullCmd.split(/;|&&|\|\|/).map(s => s.trim()).filter(Boolean);
26
98
 
27
99
  for (const segment of segments) {
@@ -30,6 +102,15 @@ process.stdin.on('end', () => {
30
102
  if (mvIdx === -1) continue;
31
103
 
32
104
  // Arguments after 'mv', skipping flags (-n, -f, -v, etc.)
105
+ //
106
+ // `!t.startsWith('-')` is a heuristic, not getopt, and it is safe in this
107
+ // one direction: every mv flag that takes a value takes a PATH as that value
108
+ // (`-t /etc/cron.d`, `--target-directory=/etc/cron.d`). Dropping the flag
109
+ // therefore leaves its value behind in `args`, still inspected — the naive
110
+ // failure mode where a flag swallows the very path you wanted to check
111
+ // cannot occur here. The cost is the mirror case: a file whose name starts
112
+ // with `-` is skipped. That is free, because such a name cannot also start
113
+ // with `/`, and an absolute path is the only thing this hook blocks.
33
114
  const args = tokens.slice(mvIdx + 1).filter(t => !t.startsWith('-'));
34
115
 
35
116
  const offendingArg = args.find(arg => {
@@ -36,6 +36,11 @@
36
36
  // `npm install -g @playwright/mcp@latest` at the prompt IS gated. Both are
37
37
  // correct: consent was given once for the setup script as a whole; an ad-hoc
38
38
  // install carries no such consent.
39
+ //
40
+ // Fails: open — matching is pure token inspection with no external input, and a
41
+ // throw exits 0 via lib/command-parse.js. The asymmetry that matters here is
42
+ // coverage rather than failure: a manager or invocation form absent from the
43
+ // tables below is allowed, which is also why the scope note above holds.
39
44
 
40
45
  const { readHookInput, splitSegments, tokenize, deny } = require('./lib/command-parse');
41
46
 
@@ -92,6 +97,12 @@ function stripInvocationPrefix(tokens) {
92
97
  // `uvx --from X` fetches and runs X, so it is an install in everything but
93
98
  // name. The flag is located anywhere in the segment rather than at a fixed
94
99
  // position, because `uvx --python 3.12 --from X` is equally valid.
100
+ //
101
+ // NOTE: bare `uvx <pkg>` (no `--from`) returns null here and is therefore
102
+ // ALLOWED, even though it fetches and runs a package by the same reasoning
103
+ // above. Whether that is a deliberate scope choice or an oversight is not
104
+ // recoverable from this file or from lib/hooks/README.md — verify before
105
+ // changing, and do not treat the current behaviour as intentional coverage.
95
106
  function uvxSource(tokens) {
96
107
  for (let i = 1; i < tokens.length; i++) {
97
108
  if (tokens[i] === '--from') return tokens[i + 1] ?? '';
@@ -64,6 +64,13 @@
64
64
  // unremarkable but which points into ~/.claude/ is not caught.
65
65
  // - `git --config-env=alias.x=VAR` reads the value from an environment
66
66
  // variable, so the dangerous string never appears in the command. Not covered.
67
+ //
68
+ // Fails: open — all three rules are pure string/path matching over the command
69
+ // itself, with no file read, no subprocess, and no external list, so there is no
70
+ // "could not check" state to fail into. If this hook throws anyway,
71
+ // lib/command-parse.js catches it and exits 0 and the command is allowed.
72
+ // Ambiguous MATCHES go the other way and block — see the inherited false
73
+ // positive above.
67
74
 
68
75
  const path = require('path');
69
76
  const os = require('os');