@windyroad/risk-scorer 0.12.5 → 0.12.6-preview.578
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.
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/lib/gate-helpers.sh +105 -0
- package/package.json +1 -1
|
@@ -13,6 +13,111 @@ _mtime() { stat -c%Y "$1" 2>/dev/null || /usr/bin/stat -f%m "$1" 2>/dev/null ||
|
|
|
13
13
|
# Portable hash: tries md5sum, falls back to md5 -r, then shasum
|
|
14
14
|
_hashcmd() { md5sum 2>/dev/null || md5 -r 2>/dev/null || shasum 2>/dev/null; }
|
|
15
15
|
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# Substance-aware drift hash + atomic verdict-write (ADR-009 amendment
|
|
18
|
+
# 2026-06-06, P353 + P303 close).
|
|
19
|
+
#
|
|
20
|
+
# `_substance_hash_path` normalises trivial/no-op edits BEFORE hashing so a
|
|
21
|
+
# PASS marker survives whitespace / CRLF / trailing-newline edits while still
|
|
22
|
+
# detecting substantive policy changes. Conservative boundary: when in doubt
|
|
23
|
+
# whether an edit is trivial vs substantive, this helper treats it as
|
|
24
|
+
# substantive (re-review fires). Only whitespace + line-ending + trailing-
|
|
25
|
+
# newline are normalised in this iteration — single-numeral edits and
|
|
26
|
+
# frontmatter-key changes are intentionally NOT normalised. See ADR-009
|
|
27
|
+
# 2026-06-06 amendment for the ratified contract.
|
|
28
|
+
#
|
|
29
|
+
# `_atomic_mark_with_hash` writes the marker + hash file as an atomic pair
|
|
30
|
+
# (mktemp + mv) so a PASS NEVER silently fails to persist (the empirically-
|
|
31
|
+
# measured P353 failure mode that forced BYPASS_RISK_GATE=1 on every
|
|
32
|
+
# external-comms gate clearance). Either both files land, or neither does.
|
|
33
|
+
# Non-zero exit on failure so callers can emit a diagnostic.
|
|
34
|
+
# ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
# Substance-aware hash of a file or directory path.
|
|
37
|
+
# For directories: hashes the concatenated content of all *.md files
|
|
38
|
+
# (excluding README.md) in sorted order.
|
|
39
|
+
# For files: hashes the file content.
|
|
40
|
+
# Normalisation BEFORE hashing: CRLF → LF, strip trailing whitespace per
|
|
41
|
+
# line, normalise trailing whitespace to a single \n.
|
|
42
|
+
# Echoes "missing" for paths that do not exist (drop-in equivalence with the
|
|
43
|
+
# pre-amendment `cat | _hashcmd | cut -d' ' -f1` site behaviour).
|
|
44
|
+
# Echoes a hex sha256 of the normalised content on success.
|
|
45
|
+
_substance_hash_path() {
|
|
46
|
+
local path="$1"
|
|
47
|
+
if [ -z "$path" ]; then
|
|
48
|
+
echo "missing"
|
|
49
|
+
return 0
|
|
50
|
+
fi
|
|
51
|
+
if [ -f "$path" ]; then
|
|
52
|
+
cat "$path" 2>/dev/null | _substance_normalize_then_hash
|
|
53
|
+
elif [ -d "$path" ]; then
|
|
54
|
+
find "$path" -name '*.md' -not -name 'README.md' -print0 \
|
|
55
|
+
| sort -z \
|
|
56
|
+
| xargs -0 cat 2>/dev/null \
|
|
57
|
+
| _substance_normalize_then_hash
|
|
58
|
+
else
|
|
59
|
+
echo "missing"
|
|
60
|
+
fi
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Internal: reads from stdin, normalises whitespace + line endings, emits a
|
|
64
|
+
# hex sha256 of the normalised content. Conservative boundary documented in
|
|
65
|
+
# ADR-009 2026-06-06 amendment: ambiguous edits stay substantive.
|
|
66
|
+
_substance_normalize_then_hash() {
|
|
67
|
+
python3 -c "
|
|
68
|
+
import sys, hashlib
|
|
69
|
+
data = sys.stdin.buffer.read().decode('utf-8', errors='replace')
|
|
70
|
+
# CRLF / CR -> LF
|
|
71
|
+
data = data.replace('\r\n', '\n').replace('\r', '\n')
|
|
72
|
+
# Strip trailing whitespace per line.
|
|
73
|
+
lines = [line.rstrip() for line in data.split('\n')]
|
|
74
|
+
# Re-join and normalise trailing whitespace to a single \n.
|
|
75
|
+
normalised = '\n'.join(lines).rstrip() + '\n'
|
|
76
|
+
print(hashlib.sha256(normalised.encode('utf-8')).hexdigest())
|
|
77
|
+
" 2>/dev/null || echo "missing"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Atomically write a presence marker + its paired hash file. Either both
|
|
81
|
+
# files land or neither does. Returns 0 on success, 1 on failure. On failure
|
|
82
|
+
# any partial state is rolled back.
|
|
83
|
+
# Usage: _atomic_mark_with_hash "/tmp/architect-reviewed-${SID}" "$HASH"
|
|
84
|
+
_atomic_mark_with_hash() {
|
|
85
|
+
local marker="$1"
|
|
86
|
+
local hash="$2"
|
|
87
|
+
local hash_file="${marker}.hash"
|
|
88
|
+
|
|
89
|
+
if [ -z "$marker" ]; then
|
|
90
|
+
return 1
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
local htmp="${hash_file}.tmp.$$.${RANDOM:-0}"
|
|
94
|
+
local mtmp="${marker}.tmp.$$.${RANDOM:-0}"
|
|
95
|
+
|
|
96
|
+
# Write hash to tempfile.
|
|
97
|
+
if ! printf '%s\n' "$hash" > "$htmp" 2>/dev/null; then
|
|
98
|
+
rm -f "$htmp"
|
|
99
|
+
return 1
|
|
100
|
+
fi
|
|
101
|
+
# Write empty marker to tempfile.
|
|
102
|
+
if ! : > "$mtmp" 2>/dev/null; then
|
|
103
|
+
rm -f "$htmp" "$mtmp"
|
|
104
|
+
return 1
|
|
105
|
+
fi
|
|
106
|
+
# Atomic rename: hash file first.
|
|
107
|
+
if ! mv -f "$htmp" "$hash_file" 2>/dev/null; then
|
|
108
|
+
rm -f "$htmp" "$mtmp"
|
|
109
|
+
return 1
|
|
110
|
+
fi
|
|
111
|
+
# Atomic rename: marker second. If this fails, roll back the hash file
|
|
112
|
+
# so we never observe a hash-without-marker half-state.
|
|
113
|
+
if ! mv -f "$mtmp" "$marker" 2>/dev/null; then
|
|
114
|
+
rm -f "$mtmp"
|
|
115
|
+
rm -f "$hash_file"
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
118
|
+
return 0
|
|
119
|
+
}
|
|
120
|
+
|
|
16
121
|
# Paths excluded from pipeline state hashing and docs-only detection.
|
|
17
122
|
_doc_exclusions() {
|
|
18
123
|
echo ':!docs/' ':!.risk-reports/' ':!.changeset/' ':!governance/' ':!.claude/plans/' ':!CLAUDE.md' ':!AGENTS.md' ':!PRINCIPLES.md' ':!DECISION-MANAGEMENT.md' ':!AGENTIC_RISK_REGISTER.md' ':!PROBLEM-MANAGEMENT.md'
|
package/package.json
CHANGED