@soleur/opencode 3.377.0 → 3.378.1

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 (26) hide show
  1. package/package.json +1 -1
  2. package/skills/launch-check/SKILL.md +98 -0
  3. package/skills/launch-check/references/banned-words.txt +6 -0
  4. package/skills/launch-check/references/banner.txt +1 -0
  5. package/skills/launch-check/references/baseline-domains.tsv +6 -0
  6. package/skills/launch-check/references/checks.tsv +25 -0
  7. package/skills/launch-check/references/footer.txt +1 -0
  8. package/skills/launch-check/references/phrases.txt +12 -0
  9. package/skills/launch-check/references/retired-checks.tsv +1 -0
  10. package/skills/launch-check/references/severity-rubric.md +10 -0
  11. package/skills/launch-check/scripts/launch-check.sh +172 -0
  12. package/skills/launch-check/scripts/lib/baseline.sh +54 -0
  13. package/skills/launch-check/scripts/lib/checks.sh +164 -0
  14. package/skills/launch-check/scripts/lib/common.sh +21 -0
  15. package/skills/launch-check/scripts/lib/redact-gate.sh +62 -0
  16. package/skills/launch-check/scripts/lib/render.sh +218 -0
  17. package/skills/launch-check/scripts/lib/safe-walk.sh +74 -0
  18. package/skills/launch-check/test/baseline.test.sh +44 -0
  19. package/skills/launch-check/test/fixtures/report-sample.md +16 -0
  20. package/skills/launch-check/test/identity.test.sh +30 -0
  21. package/skills/launch-check/test/lib.sh +78 -0
  22. package/skills/launch-check/test/redact-gate.test.sh +73 -0
  23. package/skills/launch-check/test/render.test.sh +147 -0
  24. package/skills/launch-check/test/safe-walk-parity.test.sh +51 -0
  25. package/skills/launch-check/test/scan.test.sh +117 -0
  26. package/skills/launch-check/test/wording.test.sh +40 -0
@@ -0,0 +1,62 @@
1
+ # shellcheck shell=bash
2
+ # The write chokepoint. Every byte that reaches the report goes through lc_emit_checked.
3
+ # Requires SKILL_DIR and PLUGIN_DIR. Test seams (honoured only when LAUNCH_CHECK_TEST=1, see lc_seam):
4
+ # LAUNCH_CHECK_REDACT_SENTINEL, LAUNCH_CHECK_GITLEAKS. Optional LC_DEST_ROOT: the write must stay inside it.
5
+ source "$SKILL_DIR/scripts/lib/common.sh"
6
+
7
+ # The version CI pins and code-to-prd documents (parity-tested against code-to-prd.sh, so the two cannot drift apart).
8
+ LC_GITLEAKS_PIN=8.24.2
9
+
10
+ # lc_preflight_scanners: the redaction layers must be runnable before anything is read or written.
11
+ # Resolvable is not runnable: an unpinned version-manager shim satisfies `command -v` and fails on every call, so the
12
+ # binary is probed by running it (bounded when the host has a timeout command; stock macOS has neither).
13
+ lc_preflight_scanners() {
14
+ local gl bound=""
15
+ gl=$(lc_seam LAUNCH_CHECK_GITLEAKS gitleaks)
16
+ command -v "$gl" >/dev/null 2>&1 || lc_abort scanner-missing 2 "install gitleaks $LC_GITLEAKS_PIN (macOS: brew install gitleaks; Linux: your package manager, or mise use gitleaks@$LC_GITLEAKS_PIN)"
17
+ if command -v timeout >/dev/null 2>&1; then bound="timeout 10"; elif command -v gtimeout >/dev/null 2>&1; then bound="gtimeout 10"; fi
18
+ # shellcheck disable=SC2086 # $bound is deliberately split into command and argument
19
+ $bound "$gl" version >/dev/null 2>&1 || lc_abort scanner-failed 2 "gitleaks is on PATH but not runnable; CI pins $LC_GITLEAKS_PIN"
20
+ }
21
+
22
+ # lc_emit_checked <src-file> <dest-path> <dry-run 0|1>: scan the exact bytes, then write them or write nothing.
23
+ # The body runs in a subshell so its EXIT trap owns the scratch directory and the destination temp file on
24
+ # every path (including lc_abort's exit) without replacing the caller's own trap.
25
+ lc_emit_checked() {
26
+ local rc=0
27
+ ( lc__emit_body "$@" ) || rc=$?
28
+ [ "$rc" -eq 0 ] || exit "$rc"
29
+ }
30
+
31
+ # scratch and tmp are deliberately NOT local: the EXIT trap fires after the function has returned, when a local would
32
+ # already be gone (the old form printed "scratch: parameter null or not set" and leaked the scratch directory).
33
+ lc__emit_body() {
34
+ local src=$1 dest=$2 dry=${3:-0} gl s_rc=0 g_rc=0 destdir anc real err
35
+ local REDACT_SENTINEL
36
+ gl=$(lc_seam LAUNCH_CHECK_GITLEAKS gitleaks)
37
+ REDACT_SENTINEL=$(lc_seam LAUNCH_CHECK_REDACT_SENTINEL "$PLUGIN_DIR/skills/incident/scripts/redact-sentinel.sh")
38
+ tmp=""
39
+ command -v "$gl" >/dev/null 2>&1 || lc_abort scanner-missing 2 "gitleaks not found"
40
+ scratch=$(mktemp -d "${TMPDIR:-/tmp}/lc-gate.XXXXXX") || lc_abort scanner-failed 2 "mktemp failed"
41
+ trap 'rm -rf -- "${scratch:?}"; [ -z "$tmp" ] || rm -f -- "$tmp"' EXIT
42
+ bash "$REDACT_SENTINEL" "$src" >/dev/null 2>&1 || s_rc=$?
43
+ [ "$s_rc" -eq 1 ] && lc_abort redaction-hit 1 "layer=sentinel"
44
+ [ "$s_rc" -eq 0 ] || lc_abort scanner-failed 2 "sentinel rc=$s_rc"
45
+ # The repository's own gitleaks configuration must never relax the gate.
46
+ env -u GITLEAKS_CONFIG -u GITLEAKS_CONFIG_TOML "$gl" detect --source "$src" --no-git --report-format json --report-path "$scratch/r.json" --redact --exit-code 1 >/dev/null 2>"$scratch/e" || g_rc=$?
47
+ if [ "$g_rc" -eq 1 ] && grep -q '"RuleID"' "$scratch/r.json" 2>/dev/null; then lc_abort redaction-hit 1 "layer=gitleaks"; fi
48
+ if [ "$g_rc" -ne 0 ]; then err=$(head -c 160 "$scratch/e" | tr '\n\t' ' '); lc_abort scanner-failed 2 "gitleaks rc=$g_rc: $err"; fi
49
+ [ "$dry" = 1 ] && return 0
50
+ destdir=$(dirname "$dest")
51
+ if [ -n "${LC_DEST_ROOT:-}" ]; then
52
+ # Resolve the deepest EXISTING ancestor physically before creating anything: a symlinked knowledge-base/ must not
53
+ # carry the write outside the repository.
54
+ anc=$destdir; while [ ! -d "$anc" ]; do anc=$(dirname "$anc"); done
55
+ real=$(cd "$anc" && pwd -P)
56
+ case "$real/" in "$LC_DEST_ROOT"/*) ;; *) lc_abort write-failed 2 "destination resolves outside the target repository" ;; esac
57
+ fi
58
+ mkdir -p "$destdir" || lc_abort write-failed 2 "mkdir"
59
+ tmp=$(mktemp "$destdir/.launch-check.XXXXXX") || lc_abort write-failed 2 "mktemp"
60
+ if cp "$src" "$tmp" && cmp -s "$src" "$tmp" && chmod 644 "$tmp" && mv -f "$tmp" "$dest"; then tmp=""; return 0; fi
61
+ lc_abort write-failed 2 "copy"
62
+ }
@@ -0,0 +1,218 @@
1
+ # shellcheck shell=bash
2
+ # Report rendering and the living-file diff. Contract: TARGET, WORK, FACTS, JUDGED (may be empty), DRY, CAT
3
+ # (combined catalog), REPORT_REL, STACK are set by the caller. All prose comes from references/ and the catalog;
4
+ # this file only lays out structure. Markdown is built in $WORK/report.md and written ONLY via lc_emit_checked.
5
+ #
6
+ # Trust model: render never takes the facts file, the judged file or the previous report on trust. Facts are
7
+ # validated against the catalog and sanitized (lc_clean_facts), the judged file against a closed schema
8
+ # (lc_validate_judged), the previous report against the state-line grammar (lc_prev_state). A finding is only
9
+ # ever CLOSED on positive evidence that its check ran and came back clean.
10
+
11
+ lc_phrase() { awk -F= -v k="$1" '$1==k {sub(/^[^=]*=/, ""); print; exit}' "$SKILL_DIR/references/phrases.txt"; }
12
+
13
+ # Secret-class findings are counts only: their evidence must match a fixed phrase, never a path.
14
+ LC_COUNT_ONLY_IDS="SEC-01 SEC-02"
15
+
16
+ lc_domain_label() {
17
+ case "$1" in
18
+ security) printf 'Security & secrets' ;;
19
+ tests-ci) printf 'Tests & CI/CD' ;;
20
+ tech-debt) printf 'Tech debt & architecture' ;;
21
+ reliability-ops) printf 'Reliability, performance & ops' ;;
22
+ *) printf '%s' "$1" ;;
23
+ esac
24
+ }
25
+
26
+ # lc_clean_facts: validate $FACTS against the catalog and write a sanitized copy ($WORK/facts.clean), then point FACTS at it.
27
+ # Every non-judged catalog id must have exactly one row with a known status; evidence outside the path/count grammar
28
+ # is withheld (only the fixed phrases the detectors emit, a bare path, or path:line pass), and count-only ids keep only their fixed phrases.
29
+ lc_clean_facts() {
30
+ local out
31
+ out=$(awk -F'\t' -v OFS='\t' -v cat="$CAT" -v facts="$FACTS" -v counted="$LC_COUNT_ONLY_IDS" -v cleaned="$WORK/facts.clean" '
32
+ BEGIN { n = split(counted, c, " "); for (i = 1; i <= n; i++) co[c[i]] = 1 }
33
+ FILENAME == cat { if ($1 != "" && $4 != "judged") need[$1] = 1; next }
34
+ /^#/ || /^$/ { print $0 > cleaned; next }
35
+ { if (NF != 3) { print "line " FNR ": field-count"; bad = 1; exit }
36
+ if (!($1 in need)) { print "line " FNR ": unknown-id " $1; bad = 1; exit }
37
+ if ($1 in seen) { print "line " FNR ": duplicate-id " $1; bad = 1; exit }
38
+ seen[$1] = 1
39
+ if ($2 != "ok" && $2 != "gap" && $2 != "na" && $2 != "unsupported-stack") { print "line " FNR ": status"; bad = 1; exit }
40
+ ev = $3
41
+ if ($1 in co) { if (ev !~ /^(none found|no commits yet|stack is [a-z]+|-|[0-9]+ (finding\(s\)|file\(s\)); (locations|names) withheld, run scan --show-secrets locally to see them)$/) ev = "(evidence withheld)" }
42
+ else if (length(ev) > 200 || ev !~ /^(-|none found|not identified in the files read|no source files recognized|no package\.json|not a Next\.js project|dependency-cruiser configured|no commits yet|stack is [a-z]+|(artifact|original form) present, advisory\/unverified|missing: [A-Za-z0-9._\/@+, -]+|[0-9]+ test files \/ [0-9]+ source files( \(under 5%\))?|[0-9]+ markers|[A-Za-z0-9._\/@+-]+(:[0-9]+)?)$/) ev = "(evidence withheld)"
43
+ print $1, $2, ev > cleaned }
44
+ END { if (bad) exit 1; miss = ""; for (id in need) if (!(id in seen)) miss = miss (miss == "" ? "" : ",") id
45
+ if (miss != "") { print "missing: " miss; exit 2 } }' "$CAT" "$FACTS") || {
46
+ case "$out" in missing:*) lc_abort facts-incomplete 2 "$out (re-run scan)" ;; *) lc_abort facts-invalid 2 "$out" ;; esac
47
+ }
48
+ FACTS="$WORK/facts.clean"
49
+ }
50
+
51
+ # lc_validate_judged <judged-file>: closed schema. id<TAB>status<TAB>severity<TAB>evidence-ids, nothing else.
52
+ lc_validate_judged() {
53
+ local out
54
+ out=$(awk -F'\t' -v cat="$CAT" -v facts="$FACTS" '
55
+ FILENAME == cat { if ($4 == "judged") j[$1] = 1; next }
56
+ FILENAME == facts { f[$1] = 1; next }
57
+ /^#/ || /^$/ { next }
58
+ { bad = ""
59
+ if (NF != 4) bad = "field-count"
60
+ else if (!($1 in j)) bad = "unknown-or-non-judged-id"
61
+ else if ($1 in seen) bad = "duplicate-id"
62
+ else if ($2 != "ok" && $2 != "gap" && $2 != "na") bad = "status"
63
+ else if ($2 == "gap" && $3 != "high" && $3 != "medium" && $3 != "low") bad = "severity"
64
+ else if ($2 != "gap" && $3 != "-") bad = "severity-must-be-dash-unless-gap"
65
+ else if ($2 == "gap" && $4 == "-") bad = "evidence-required"
66
+ else if ($4 != "-") { k = split($4, ev, ","); for (i = 1; i <= k; i++) if (!(ev[i] in f)) bad = "evidence-id" }
67
+ seen[$1] = 1
68
+ if (bad != "") { print "line " FNR ": " bad; exit 1 } }' "$CAT" "$FACTS" "$1") || lc_abort judged-schema 2 "$out"
69
+ }
70
+
71
+ # lc_prev_state <report-file> <outfile>: "id<TAB>status<TAB>rest" lines from the fenced state block. CRLF-tolerant;
72
+ # duplicate ids resolve last-wins; lines outside the grammar are written to <outfile>.bad instead of being guessed at.
73
+ # A report that exists but carries no state block is refused: overwriting it would silently drop every acceptance.
74
+ lc_prev_state() {
75
+ local rc=0
76
+ : > "$2"; : > "$2.bad"
77
+ [ -f "$1" ] || return 0
78
+ tr -d '\r' < "$1" | awk -v bad="$2.bad" '
79
+ /^```launch-check-state$/ { f = 1; seen = 1; next }
80
+ /^```$/ && f { f = 0; next }
81
+ f && /^finding / {
82
+ if ($2 ~ /^[A-Z]+-[A-Za-z0-9-]+$/ && ($3 == "open" || $3 == "accepted")) {
83
+ rest = ""; for (i = 4; i <= NF; i++) rest = rest (i > 4 ? " " : "") $i
84
+ if (!($2 in idx)) { idx[$2] = ++n; order[n] = $2 }
85
+ st[$2] = $3; rs[$2] = rest
86
+ } else print substr($0, 1, 120) > bad
87
+ next }
88
+ f && $0 != "" && $0 !~ /^(schema_version|catalog_hash)=/ { print substr($0, 1, 120) > bad }
89
+ END { if (!seen) exit 3; for (i = 1; i <= n; i++) printf "%s\t%s\t%s\n", order[i], st[order[i]], rs[order[i]] }' > "$2" || rc=$?
90
+ [ "$rc" -eq 0 ] || lc_abort prev-report-invalid 2 "no state block in $REPORT_REL (restore it from git, or delete the file to start fresh)"
91
+ }
92
+
93
+ lc_render() {
94
+ local rep="$WORK/report.md" prev="$WORK/prev.tsv" gaps="$WORK/gaps.tsv" judged_in="$WORK/judged.in"
95
+ local has_prev=0 has_judged=0 prev_hash prev_schema cat_hash today catalog_changed=0
96
+ [ -n "${JUDGED:-}" ] && has_judged=1
97
+ if [ "$has_judged" = 1 ]; then cp "$JUDGED" "$judged_in"; else : > "$judged_in"; fi
98
+ lc_prev_state "$TARGET/$REPORT_REL" "$prev"
99
+ [ -f "$TARGET/$REPORT_REL" ] && has_prev=1
100
+ cat_hash=$(git hash-object --stdin < "$CAT")
101
+ today=$(date -u +%F)
102
+
103
+ # Open gaps (deterministic facts + judged), sorted critical -> low then id.
104
+ awk -F'\t' -v OFS='\t' -v cat="$CAT" -v facts="$FACTS" -v judged="$judged_in" '
105
+ function rank(s) { return s == "critical" ? 1 : s == "high" ? 2 : s == "medium" ? 3 : 4 }
106
+ FILENAME == cat { if ($1 != "") { dom[$1]=$2; cls[$1]=$3; title[$1]=$5; sev[$1]=$6; clos[$1]=$11; rem[$1]=$12; known[$1]=1 } next }
107
+ FILENAME == facts { if ($2 == "gap" && ($1 in known)) print rank(sev[$1]), $1, dom[$1], cls[$1], sev[$1], title[$1], $3, clos[$1], rem[$1]; next }
108
+ FILENAME == judged { if ($0 !~ /^#/ && $2 == "gap" && ($1 in known)) print rank($3), $1, dom[$1], cls[$1], $3, title[$1], "relies on " $4, clos[$1], rem[$1] }
109
+ ' "$CAT" "$FACTS" "$judged_in" | sort -t "$(printf '\t')" -k1,1n -k2,2 > "$gaps"
110
+
111
+ # Partition by the previous state: accepted stays out of the open table.
112
+ awk -F'\t' '$2 == "accepted" {print $1}' "$prev" | sort > "$WORK/prev.accepted.ids"
113
+ cut -f2 "$gaps" | sort > "$WORK/cur.ids"
114
+ comm -23 "$WORK/cur.ids" "$WORK/prev.accepted.ids" > "$WORK/open.ids"
115
+ comm -12 "$WORK/cur.ids" "$WORK/prev.accepted.ids" > "$WORK/accepted.ids"
116
+ cut -f1 "$prev" | sort > "$WORK/prev.ids"
117
+ cut -f1 "$CAT" | sort > "$WORK/cat.ids"
118
+ if [ "$has_prev" = 1 ]; then comm -23 "$WORK/open.ids" "$WORK/prev.ids" > "$WORK/new.ids"; else : > "$WORK/new.ids"; fi
119
+ # Positive evidence that a check ran clean: a deterministic fact with status ok, or a judged line saying ok/na.
120
+ awk -F'\t' '$2 == "ok" {print $1}' "$FACTS" | sort -u > "$WORK/ok.ids"
121
+ awk -F'\t' '!/^#/ && ($2 == "ok" || $2 == "na") {print $1}' "$judged_in" | sort -u > "$WORK/judged.settled.ids"
122
+ # Closed: previously reported, still in the catalog, no longer a gap AND positively settled. Anything else (a check
123
+ # that was not applicable, an unsupported stack, an AI-assisted item not reviewed this run) is carried, not closed.
124
+ : > "$WORK/closed.ids"; : > "$WORK/retired.ids"; : > "$WORK/carry.lines"
125
+ while IFS=$'\t' read -r pid pst prest; do
126
+ [ -n "$pid" ] || continue
127
+ if ! grep -qxF "$pid" "$WORK/cat.ids"; then printf '%s\n' "$pid" >> "$WORK/retired.ids"; continue; fi
128
+ if grep -qxF "$pid" "$WORK/cur.ids"; then continue; fi
129
+ case "$pid" in
130
+ JDG-*) grep -qxF "$pid" "$WORK/judged.settled.ids" && { printf '%s\n' "$pid" >> "$WORK/closed.ids"; continue; } ;;
131
+ *) grep -qxF "$pid" "$WORK/ok.ids" && { printf '%s\n' "$pid" >> "$WORK/closed.ids"; continue; } ;;
132
+ esac
133
+ printf 'finding %s %s%s\n' "$pid" "$pst" "${prest:+ $prest}" >> "$WORK/carry.lines"
134
+ done < "$prev"
135
+
136
+ # Not assessed: checks that did not produce a verdict this run, and AI-assisted items nobody reviewed.
137
+ awk -F'\t' '!/^#/ && ($2 == "na" || $2 == "unsupported-stack") { print $1 "\t" $2 ": " $3 }' "$FACTS" | sort > "$WORK/notassessed.tsv"
138
+ awk -F'\t' '$4 == "judged" {print $1}' "$CAT" | sort > "$WORK/jdg.ids"
139
+ awk -F'\t' '!/^#/ {print $1}' "$judged_in" | sort -u > "$WORK/jdg.seen.ids"
140
+ comm -23 "$WORK/jdg.ids" "$WORK/jdg.seen.ids" | while IFS= read -r id; do printf '%s\t%s\n' "$id" "$(lc_phrase jdg_unreviewed)"; done >> "$WORK/notassessed.tsv"
141
+
142
+ prev_hash=$(awk -F= '/^catalog_hash=/ {print $2; exit}' "$TARGET/$REPORT_REL" 2>/dev/null | tr -d '\r')
143
+ prev_schema=$(awk -F= '/^schema_version=/ {print $2; exit}' "$TARGET/$REPORT_REL" 2>/dev/null | tr -d '\r')
144
+ if [ "$has_prev" = 1 ] && { [ "$prev_hash" != "$cat_hash" ] || [ "${prev_schema:-1}" != 1 ]; }; then
145
+ catalog_changed=1
146
+ printf 'SOLEUR_LAUNCH_CHECK_CATALOG_CHANGED retired=%s\n' "$(grep -c . "$WORK/retired.ids")"
147
+ fi
148
+
149
+ {
150
+ printf -- '---\nlaunch_check_schema: 1\nrun_date: %s\nstack: %s\n---\n\n' "$today" "$STACK"
151
+ printf '# Launch check report\n\n'
152
+ cat "$SKILL_DIR/references/banner.txt"
153
+ printf '\n'
154
+ [ "$STACK" = node ] || printf '%s\n\n' "$(lc_phrase partial_stack)"
155
+ [ "$catalog_changed" = 1 ] && printf '%s\n\n' "$(lc_phrase catalog_changed)"
156
+
157
+ printf '## Summary\n\n| Domain | Critical | High | Medium | Low |\n|---|---|---|---|---|\n'
158
+ local d c
159
+ for d in security tests-ci tech-debt reliability-ops; do
160
+ c=$(awk -F'\t' -v d="$d" -v open="$WORK/open.ids" 'BEGIN { while ((getline l < open) > 0) o[l] = 1 } $3 == d && ($2 in o) { n[$5]++ } END { printf "%d | %d | %d | %d", n["critical"], n["high"], n["medium"], n["low"] }' "$gaps")
161
+ printf '| %s | %s |\n' "$(lc_domain_label "$d")" "$c"
162
+ done
163
+ printf '\n## Findings\n\n'
164
+ if [ -s "$WORK/open.ids" ]; then
165
+ printf '| ID | Severity | Domain | Finding | Evidence | Fix |\n|---|---|---|---|---|---|\n'
166
+ # shellcheck disable=SC2034
167
+ while IFS=$'\t' read -r _ id dom cls sev title ev clos rem; do
168
+ grep -qxF "$id" "$WORK/open.ids" || continue
169
+ ev=${ev//|/\\|}
170
+ fix=$rem; [ "$clos" != "-" ] && fix="$rem Command: \`$clos\`"
171
+ printf '| %s | %s | %s | %s | %s | %s |\n' "$id" "$sev" "$(lc_domain_label "$dom")" "$title" "$ev" "$fix"
172
+ done < "$gaps"
173
+ elif [ -s "$WORK/accepted.ids" ]; then
174
+ printf '%s\n' "$(lc_phrase only_accepted)"
175
+ else
176
+ printf '%s\n' "$(lc_phrase no_open)"
177
+ fi
178
+ [ -s "$WORK/carry.lines" ] && printf '\n%s\n' "$(lc_phrase not_refreshed)"
179
+ printf '\n## Not assessed in this run\n\n'
180
+ if [ -s "$WORK/notassessed.tsv" ]; then
181
+ printf '%s\n\n' "$(lc_phrase not_assessed_intro)"
182
+ while IFS=$'\t' read -r id why; do printf -- '- %s: %s\n' "$id" "$why"; done < "$WORK/notassessed.tsv"
183
+ else printf '%s\n' "$(lc_phrase none)"; fi
184
+ printf '\n## Not installable yet\n\n'
185
+ local v2; v2=$(lc_guard_rows '^v2$' | cut -f1 | tr '\n' ' ')
186
+ if [ -n "${v2// /}" ]; then printf '%s %s\n' "$(lc_phrase v2_intro)" "$v2"; else printf '%s\n' "$(lc_phrase none)"; fi
187
+
188
+ printf '\n## New since last run\n\n'
189
+ if [ "$has_prev" = 0 ]; then printf '%s\n' "$(lc_phrase first_run)"; elif [ -s "$WORK/new.ids" ]; then sed 's/^/- /' "$WORK/new.ids"; else printf '%s\n' "$(lc_phrase none)"; fi
190
+ printf '\n## Closed since last run\n\n'
191
+ if [ "$has_prev" = 0 ]; then printf '%s\n' "$(lc_phrase first_run)"; elif [ -s "$WORK/closed.ids" ]; then sed 's/^/- /' "$WORK/closed.ids"; else printf '%s\n' "$(lc_phrase none)"; fi
192
+ printf '\n## Accepted\n\n'
193
+ if [ -s "$WORK/accepted.ids" ]; then
194
+ while IFS= read -r id; do printf -- '- %s: %s\n' "$id" "$(awk -F'\t' -v id="$id" '$1==id {print $3; exit}' "$prev")"; done < "$WORK/accepted.ids"
195
+ else printf '%s\n' "$(lc_phrase none)"; fi
196
+ printf '\n## Retired checks\n\n'
197
+ if [ -s "$WORK/retired.ids" ]; then
198
+ while IFS= read -r id; do
199
+ printf -- '- %s: %s%s\n' "$id" "$(awk -F'\t' -v id="$id" '$1==id {print $3; exit}' "$SKILL_DIR/references/retired-checks.tsv" 2>/dev/null | grep . || printf '%s' "$(lc_phrase retired_default)")" \
200
+ "$(awk -F'\t' -v id="$id" '$1==id && $2=="accepted" {print " (was accepted: " $3 ")"; exit}' "$prev")"
201
+ done < "$WORK/retired.ids"
202
+ else printf '%s\n' "$(lc_phrase none)"; fi
203
+ if [ -s "$prev.bad" ]; then
204
+ printf '\n## Unrecognised state lines (ignored)\n\n%s\n\n' "$(lc_phrase unrecognised_intro)"
205
+ while IFS= read -r l; do printf -- '- `%s`\n' "$(lc_scrub "${l//\`/}")"; done < "$prev.bad"
206
+ fi
207
+
208
+ printf '\n---\n\n'
209
+ cat "$SKILL_DIR/references/footer.txt"
210
+ printf '\n\n```launch-check-state\nschema_version=1\ncatalog_hash=%s\n' "$cat_hash"
211
+ while IFS= read -r id; do printf 'finding %s open\n' "$id"; done < "$WORK/open.ids"
212
+ while IFS= read -r id; do printf 'finding %s accepted%s\n' "$id" "$(awk -F'\t' -v id="$id" '$1==id && $3!="" {print " " $3; exit}' "$prev")"; done < "$WORK/accepted.ids"
213
+ [ -s "$WORK/carry.lines" ] && cat "$WORK/carry.lines"
214
+ printf '```\n'
215
+ } > "$rep" || lc_abort render-failed 2 "report assembly"
216
+ # shellcheck disable=SC2034 # read by cmd_render
217
+ LC_OPEN_COUNT=$(grep -c . "$WORK/open.ids")
218
+ }
@@ -0,0 +1,74 @@
1
+ # shellcheck shell=bash
2
+ # The never-read list and the walker. Every file the skill reads flows through lc_safe_path.
3
+ # The first six case arms are a superset of code-to-prd's is_excluded() (pinned by safe-walk-parity.test.sh);
4
+ # the rest are launch-check's own classes: state/vars files, SQL and CSV data, sqlite files, fixture data.
5
+
6
+ LC_EXCLUDED_COUNT=0
7
+ LC_SYMLINK_COUNT=0
8
+
9
+ # master.key is listed for parity with code-to-prd's is_excluded(); *.key already covers it.
10
+ #
11
+ # The list is matched case-insensitively (a case-insensitive macOS volume treats `.ENV` and `.env` as one file) and
12
+ # also covers every credential-bearing name SEC-02 reports (lc_credential_paths below), so a file the scan calls a
13
+ # credential is never offered to the AI-assisted review.
14
+ lc_safe_path() {
15
+ local old=0 rc=0
16
+ shopt -q nocasematch && old=1
17
+ shopt -s nocasematch
18
+ lc__safe_path_case "$1" || rc=$?
19
+ [ "$old" = 1 ] || shopt -u nocasematch
20
+ return "$rc"
21
+ }
22
+
23
+ # lc_credential_paths: stdin paths -> those whose NAME marks a credential-bearing file (SEC-02). One definition,
24
+ # shared by the count and by `scan --show-secrets`.
25
+ lc_credential_paths() {
26
+ awk '{ p = tolower($0); b = p; sub(".*/", "", b)
27
+ if (b ~ /\.(example|sample|template|dist|pub)$/) next
28
+ if (b ~ /^\.env($|\.)/ || b ~ /\.env$/ || b == ".envrc" || b ~ /\.(key|p12|pfx|jks|keystore|ppk|tfvars)$/ || b ~ /\.tfstate(\.|$)/ || (b ~ /\.pem$/ && b ~ /(key|priv|secret)/) || b ~ /^(credentials|secrets)(\.|$)/ || b ~ /^id_(rsa|dsa|ecdsa|ed25519)/ || b ~ /^\.(npmrc|netrc|pypirc|htpasswd|git-credentials)$/ || b == ".dev.vars" || b == "kubeconfig" || p ~ /(^|\/)\.(aws|kube)\// || b ~ /service-account.*\.json$/) print $0 }'
29
+ }
30
+
31
+ # shellcheck disable=SC2221,SC2222
32
+ lc__safe_path_case() {
33
+ case "$1" in
34
+ .env|.env.*|*/.env|*/.env.*) return 1 ;;
35
+ secrets.*|*/secrets.*) return 1 ;;
36
+ *.pem|*.key) return 1 ;;
37
+ credentials.*|*/credentials.*) return 1 ;;
38
+ master.key|*/master.key) return 1 ;;
39
+ .git/*|*/.git/*) return 1 ;;
40
+ *.tfstate|*.tfstate.*|*.tfvars|*.tfvars.json) return 1 ;;
41
+ *.sql|*.dump|*.csv|*.sqlite|*.sqlite3|*.db) return 1 ;;
42
+ fixtures/*|*/fixtures/*|__fixtures__/*|*/__fixtures__/*|seeds/*|*/seeds/*) return 1 ;;
43
+ *.env|.envrc|*/.envrc|*.p12|*.pfx|*.jks|*.keystore|*.ppk) return 1 ;;
44
+ credentials|*/credentials|secrets|*/secrets|secrets/*|*/secrets/*) return 1 ;;
45
+ id_rsa*|*/id_rsa*|id_dsa*|*/id_dsa*|id_ecdsa*|*/id_ecdsa*|id_ed25519*|*/id_ed25519*) return 1 ;;
46
+ .npmrc|*/.npmrc|.netrc|*/.netrc|.pypirc|*/.pypirc|.htpasswd|*/.htpasswd|.git-credentials|*/.git-credentials) return 1 ;;
47
+ .dev.vars|*/.dev.vars|kubeconfig|*/kubeconfig|.kube/*|*/.kube/*|.aws/*|*/.aws/*|*service-account*.json) return 1 ;;
48
+ esac
49
+ return 0
50
+ }
51
+
52
+ # lc_walk <target> <outfile>: write the readable, tracked-or-untracked-not-ignored paths, one per line.
53
+ # Counters are set in this shell (call directly, never inside $( )).
54
+ lc_walk() {
55
+ local target=$1 out=$2 p
56
+ : > "$out"
57
+ LC_EXCLUDED_COUNT=0; LC_SYMLINK_COUNT=0
58
+ while IFS= read -r -d '' p; do
59
+ case "$p" in *$'\n'*) LC_EXCLUDED_COUNT=$((LC_EXCLUDED_COUNT + 1)); continue ;; esac
60
+ if ! lc_safe_path "$p"; then LC_EXCLUDED_COUNT=$((LC_EXCLUDED_COUNT + 1)); continue; fi
61
+ if [ -L "$target/$p" ]; then LC_SYMLINK_COUNT=$((LC_SYMLINK_COUNT + 1)); LC_EXCLUDED_COUNT=$((LC_EXCLUDED_COUNT + 1)); continue; fi
62
+ [ -f "$target/$p" ] || continue
63
+ printf '%s\n' "$p" >> "$out"
64
+ done < <(git -C "$target" ls-files -z -c -o --exclude-standard)
65
+ }
66
+
67
+ # lc_stack <filelist>: node | python | ruby | go | other
68
+ lc_stack() {
69
+ if grep -qE '(^|/)package\.json$' "$1"; then echo node
70
+ elif grep -qE '(^|/)(pyproject\.toml|requirements\.txt|setup\.py|Pipfile)$' "$1"; then echo python
71
+ elif grep -qE '(^|/)Gemfile$' "$1"; then echo ruby
72
+ elif grep -qE '(^|/)go\.mod$' "$1"; then echo go
73
+ else echo other; fi
74
+ }
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # The Soleur-baseline checks are derived from guards.tsv at run time, never listed.
3
+ set -uo pipefail
4
+ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
5
+ check "instrument self-test" selftest
6
+ command -v gitleaks >/dev/null 2>&1 || { echo "FAIL - gitleaks is required for this suite"; exit 1; }
7
+ G="$PLUGIN/skills/verification-scaffold/references/guards.tsv"
8
+ want=$(awk -F'\t' '/^#/ {next} !h && $1=="name" {for(i=1;i<=NF;i++) c[$i]=i; h=1; next} h && $c["tier"]=="v1" {print "BASE-" $c["name"]}' "$G" | sort)
9
+ check "guards.tsv has v1 rows (anti-vacuity)" test -n "$want"
10
+ H=$(fx_healthy base); scan_to "$H" "$SCRATCH/h.tsv"
11
+ got=$(awk -F'\t' '$1 ~ /^BASE-/ {print $1}' "$SCRATCH/h.tsv" | sort)
12
+ check "emitted BASE- checks equal the v1 guard names (identity, not count)" test "$got" = "$want"
13
+ check "a v2 guard is not emitted as a gap" bash -c '! grep -q "BASE-block-rm-rf" "$1"' _ "$SCRATCH/h.tsv"
14
+ check "a fixture without scaffold output has baseline gaps" test "$(fact "$SCRATCH/h.tsv" BASE-secret-scan)" = gap
15
+ # Install the guards into a copy, rescan: artifacts present -> ok, never 'satisfied'.
16
+ cp -R "$H" "$SCRATCH/base2"; bash "$PLUGIN/skills/verification-scaffold/scripts/verification-scaffold.sh" --target "$SCRATCH/base2" --headless >/dev/null 2>&1
17
+ gitq "$SCRATCH/base2" add -A; gitq "$SCRATCH/base2" -c commit.gpgsign=false commit -q -m guards 2>/dev/null
18
+ scan_to "$SCRATCH/base2" "$SCRATCH/b2.tsv"
19
+ check "after scaffolding: BASE-secret-scan is ok" test "$(fact "$SCRATCH/b2.tsv" BASE-secret-scan)" = ok
20
+ check "ok evidence says advisory/unverified, not satisfied" grep -qE '^BASE-secret-scan ok .*advisory/unverified' "$SCRATCH/b2.tsv"
21
+ # Mutations via an override manifest.
22
+ printf '# empty\n' > "$SCRATCH/empty.tsv"
23
+ LAUNCH_CHECK_GUARDS_TSV="$SCRATCH/empty.tsv" lc scan --target "$H" --facts "$SCRATCH/e.tsv" > "$SCRATCH/e.out" 2>&1; rc=$?
24
+ check "empty manifest: exit 2 reason=baseline-source-empty (not 0 baseline checks)" bash -c '[ "$1" = 2 ] && grep -q "reason=baseline-source-empty" "$2"' _ "$rc" "$SCRATCH/e.out"
25
+ { cat "$G"; printf 'guard-x\tgeneric-after-extraction\thook\t-\tadvisory\tgit\t-\t.claude/hooks/guard-x.sh\tv1\n'; } > "$SCRATCH/plus.tsv"
26
+ LAUNCH_CHECK_GUARDS_TSV="$SCRATCH/plus.tsv" lc scan --target "$H" --facts "$SCRATCH/p.tsv" >/dev/null 2>&1
27
+ check "a second v1 row appended after a compliant first is emitted too" bash -c 'grep -q "^BASE-guard-x" "$1" && grep -q "^BASE-secret-scan" "$1"' _ "$SCRATCH/p.tsv"
28
+ check "no checks.tsv row duplicates a derived guard (double count)" bash -c '! grep -q "^BASE-" "$1"' _ "$SKILL/references/checks.tsv"
29
+ check "baseline.sh does not hard-code a guard name" bash -c '! grep -nE "secret-scan|commit-on-main|block-stash|orphan-test" "$1" | grep -v "^[0-9]*:[[:space:]]*#"' _ "$SKILL/scripts/lib/baseline.sh"
30
+
31
+ # Label and retirement tables stay inside the vocabulary the renderer counts, and a retired id is never reused.
32
+ check "baseline-domains.tsv uses only known domains and severities" bash -c 'x=$(awk -F"\t" "!/^#/ && \$1 != \"name\" && \$1 != \"\" && (\$2 !~ /^(security|tests-ci|tech-debt|reliability-ops)\$/ || \$3 !~ /^(critical|high|medium|low)\$/)" "$1"); [ -z "$x" ]' _ "$SKILL/references/baseline-domains.tsv"
33
+ check "no catalog id appears in retired-checks.tsv (a retired id cannot come back with a stale acceptance)" bash -c 'ids=$(awk -F"\t" "!/^#/ && \$1 != \"id\" && \$1 != \"\" {print \$1}" "$1"); ret=$(awk -F"\t" "!/^#/ && \$1 != \"id\" && \$1 != \"\" {print \$1}" "$2"); [ -z "$ret" ] || { x=$(printf "%s\n" $ids | grep -xFf <(printf "%s\n" $ret) || true); [ -z "$x" ]; }' _ "$SKILL/references/checks.tsv" "$SKILL/references/retired-checks.tsv"
34
+ G2="$SCRATCH/badlabel"; mkdir -p "$G2"
35
+ printf 'name\ttier\temits\nx-guard\tv1\tfile.txt\n' > "$G2/g.tsv"
36
+ LAUNCH_CHECK_GUARDS_TSV="$G2/g.tsv" lc scan --target "$H" --facts "$SCRATCH/gl.tsv" > "$SCRATCH/gl.out" 2>&1; rc=$?
37
+ check "a one-guard manifest derives exactly one BASE- check" bash -c '[ "$1" = 0 ] && grep -q "^BASE-x-guard" "$2"' _ "$rc" "$SCRATCH/gl.tsv"
38
+ printf 'name\ttier\ntier-less\tv1\n' > "$G2/h.tsv"
39
+ LAUNCH_CHECK_GUARDS_TSV="$G2/h.tsv" lc scan --target "$H" --facts "$SCRATCH/gh.tsv" > "$SCRATCH/gh.out" 2>&1; rc=$?
40
+ check "a manifest header that lost the emits column is malformed (not merely empty)" bash -c '[ "$1" = 2 ] && grep -q "reason=baseline-source-malformed" "$2"' _ "$rc" "$SCRATCH/gh.out"
41
+ printf 'name\ttier\temits\nbad_name\tv1\tfile.txt\n' > "$G2/i.tsv"
42
+ LAUNCH_CHECK_GUARDS_TSV="$G2/i.tsv" lc scan --target "$H" --facts "$SCRATCH/gi.tsv" > "$SCRATCH/gi.out" 2>&1; rc=$?
43
+ check "a guard name outside [A-Za-z0-9-] is refused (its BASE- id would fail verify-report)" bash -c '[ "$1" = 2 ] && grep -q "reason=baseline-source-malformed" "$2"' _ "$rc" "$SCRATCH/gi.out"
44
+ finish 16
@@ -0,0 +1,16 @@
1
+ ---
2
+ launch_check_schema: 1
3
+ run_date: 2026-11-02
4
+ stack: node
5
+ ---
6
+
7
+ # Launch check report
8
+
9
+ Sample fixture for `verify-report`.
10
+
11
+ ```launch-check-state
12
+ schema_version=1
13
+ catalog_hash=sample
14
+ finding CI-01 open
15
+ finding SEC-03 accepted 2026-11-02 prototype only
16
+ ```
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env bash
2
+ # Finding identity is the check id: stable across renames, line shifts and repeated hits.
3
+ set -uo pipefail
4
+ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
5
+ check "instrument self-test" selftest
6
+ K=$(fx_markers ident); scan_to "$K" "$SCRATCH/a.tsv"
7
+ gitq "$K" mv src/debt.js src/renamed.js; { printf '// extra\n'; cat "$K/src/renamed.js"; } > "$K/t" && mv "$K/t" "$K/src/renamed.js"; commit_all "$K"
8
+ scan_to "$K" "$SCRATCH/b.tsv"
9
+ check "rename + line shift: the finding keeps its id and status" test "$(fact "$SCRATCH/a.tsv" DEBT-01)" = "$(fact "$SCRATCH/b.tsv" DEBT-01)"
10
+ check "multiple hits in one file collapse to a single row" test "$(awk -F'\t' '$1=="DEBT-01"' "$SCRATCH/a.tsv" | wc -l | tr -d ' ')" = 1
11
+ M=$(fx_minimal absence); scan_to "$M" "$SCRATCH/c.tsv"
12
+ check "absence check has exactly one row" test "$(awk -F'\t' '$1=="CI-01"' "$SCRATCH/c.tsv" | wc -l | tr -d ' ')" = 1
13
+ CAT="$SKILL/references/checks.tsv"
14
+ check "catalog ids are unique" test -z "$(awk -F'\t' '!/^#/ && $1!="id" {print $1}' "$CAT" | sort | uniq -d)"
15
+ # shellcheck source=/dev/null
16
+ source "$SKILL/scripts/lib/safe-walk.sh"; source "$SKILL/scripts/lib/checks.sh"
17
+ miss=0; while IFS= read -r id; do declare -F "lc_detect_${id//-/_}" >/dev/null || { fail "detector function missing for $id"; miss=1; }; done < <(awk -F'\t' '!/^#/ && $4=="detector" {print $1}' "$CAT")
18
+ [ "$miss" = 0 ] && pass "every detector row has its lc_detect_ function"
19
+ scan_to "$(fx_healthy cov_h)" "$SCRATCH/cov_h.tsv"; scan_to "$(fx_secret cov_s)" "$SCRATCH/cov_s.tsv"; scan_to "$(fx_envfile cov_e)" "$SCRATCH/cov_e.tsv"
20
+ scan_to "$(fx_markers cov_k)" "$SCRATCH/cov_k.tsv"; scan_to "$(fx_next_nogate cov_n)" "$SCRATCH/cov_n.tsv"; scan_to "$(fx_minimal cov_m)" "$SCRATCH/cov_m.tsv"
21
+ cov=0
22
+ while IFS= read -r id; do
23
+ oks=0; gaps=0
24
+ for f in cov_h cov_s cov_e cov_k cov_n cov_m; do
25
+ case "$(fact "$SCRATCH/$f.tsv" "$id")" in ok) oks=1 ;; gap) gaps=1 ;; esac
26
+ done
27
+ { [ "$oks" = 1 ] && [ "$gaps" = 1 ]; } || { fail "check $id lacks a positive or a negative fixture (ok=$oks gap=$gaps)"; cov=1; }
28
+ done < <(awk -F'\t' '!/^#/ && $1!="id" && $4!="judged" {print $1}' "$CAT")
29
+ [ "$cov" = 0 ] && pass "every deterministic check has one positive and one negative fixture"
30
+ finish 7
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bash
2
+ # Shared helpers for the launch-check suites (sourced; not itself a suite).
3
+ # Fixture repos are BUILT AT TEST TIME under a scratch dir: nested .git directories cannot be
4
+ # committed, and a committed secret-shaped string would trip this repository's own gitleaks CI.
5
+ SKILL="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
6
+ LC="$SKILL/scripts/launch-check.sh"
7
+ # shellcheck disable=SC2034
8
+ PLUGIN="$(cd "$SKILL/../.." && pwd -P)"
9
+ # Test seams (scanner, sentinel and manifest overrides) are honoured only under LAUNCH_CHECK_TEST=1; the suites
10
+ # exercise real report writes, so the unattended-run switches are cleared (the headless suite sets them itself).
11
+ export LAUNCH_CHECK_TEST=1
12
+ unset CI LAUNCH_CHECK_HEADLESS
13
+ SCRATCH="$(mktemp -d "${TMPDIR:-/var/tmp}/lc-test.XXXXXX")"
14
+ trap 'rm -rf "${SCRATCH:?}"' EXIT
15
+ passes=0; fails=0
16
+ pass() { printf 'ok - %s\n' "$1"; passes=$((passes + 1)); }
17
+ fail() { printf 'FAIL - %s\n' "$1"; fails=$((fails + 1)); }
18
+ check() { local d=$1; shift; if "$@"; then pass "$d"; else fail "$d"; fi }
19
+
20
+ # git under a constructed environment: no inherited GIT_* location variables, pinned identity.
21
+ gitq() {
22
+ local d=$1; shift
23
+ env -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORY -u GIT_COMMON_DIR -u GIT_NAMESPACE \
24
+ GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
25
+ GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid \
26
+ git -C "$d" "$@"
27
+ }
28
+ # lc: run launch-check with the same cleaned git environment.
29
+ lc() {
30
+ env -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORY -u GIT_COMMON_DIR -u GIT_NAMESPACE \
31
+ GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
32
+ GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid \
33
+ bash "$LC" "$@"
34
+ }
35
+ mkrepo() { local d="$SCRATCH/$1"; mkdir -p "$d"; gitq "$d" init -q -b main; printf '%s' "$d"; }
36
+ commit_all() { gitq "$1" add -A; gitq "$1" -c commit.gpgsign=false commit -q -m fixture; }
37
+ put() { local f=$1; shift; mkdir -p "$(dirname "$f")"; printf '%s\n' "$@" > "$f"; }
38
+ # sub_in_place <file> <sed args...>: edit via a temp file and mv (no removal commands).
39
+ sub_in_place() { local f=$1; shift; sed "$@" "$f" > "$f.new" && mv "$f.new" "$f"; }
40
+
41
+ fx_minimal() { local d; d=$(mkrepo "$1"); put "$d/README.md" '# app'; put "$d/src/index.js" 'console.log(1)'; put "$d/package.json" '{"name":"app"}'; commit_all "$d"; printf '%s' "$d"; }
42
+ fx_healthy() {
43
+ local d; d=$(mkrepo "$1")
44
+ put "$d/package.json" '{"name":"app","dependencies":{"next":"1","@sentry/nextjs":"1"},"devDependencies":{"dependency-cruiser":"1"},"scripts":{"test":"vitest"}}'
45
+ put "$d/package-lock.json" '{}'
46
+ put "$d/.github/workflows/ci.yml" 'name: ci' 'on: [pull_request]' 'jobs:' ' t:' ' runs-on: ubuntu-latest' ' steps:' ' - run: npm test'
47
+ put "$d/.github/dependabot.yml" 'version: 2'
48
+ put "$d/.nvmrc" '22'
49
+ put "$d/docs/adr/0001-record.md" '# ADR 1'
50
+ put "$d/CLAUDE.md" '# conventions'
51
+ put "$d/docs/runbooks/db.md" 'Backup and restore: nightly snapshot.'
52
+ put "$d/src/server.ts" 'app.get("/health", () => "ok")'
53
+ local i; for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21; do put "$d/src/m$i.ts" "export const v$i = $i"; done
54
+ put "$d/src/m1.test.ts" 'test("a", () => {})' ; put "$d/src/m2.test.ts" 'test("b", () => {})'
55
+ commit_all "$d"; printf '%s' "$d"
56
+ }
57
+ fx_python() { local d; d=$(mkrepo "$1"); put "$d/pyproject.toml" '[project]' 'name="app"'; put "$d/app.py" 'print(1)'; commit_all "$d"; printf '%s' "$d"; }
58
+ # The planted secret is assembled from fragments so no contiguous token literal exists in this source.
59
+ planted_secret() { printf '%s%s' 'ghp_' 'R7vK2mQ9xT4bN8cL1wZ5eH3jY6uA0dF2gS9p'; }
60
+ fx_secret() { local d; d=$(fx_healthy "$1"); put "$d/src/config.js" "module.exports = { token: \"$(planted_secret)\" };"; commit_all "$d"; printf '%s' "$d"; }
61
+ fx_envfile() { local d; d=$(fx_minimal "$1"); put "$d/.env" 'DB_URL=postgres://x'; gitq "$d" add -f .env; gitq "$d" -c commit.gpgsign=false commit -q -m env; printf '%s' "$d"; }
62
+ fx_markers() { local d i; d=$(fx_minimal "$1"); : > "$d/src/debt.js"; for i in $(seq 1 60); do printf '// TODO item %s\n' "$i" >> "$d/src/debt.js"; done; commit_all "$d"; printf '%s' "$d"; }
63
+ fx_next_nogate() { local d; d=$(fx_minimal "$1"); put "$d/package.json" '{"name":"app","dependencies":{"next":"1"}}'; put "$d/vercel.json" '{}'; commit_all "$d"; printf '%s' "$d"; }
64
+ fx_symlink() { local d; d=$(fx_minimal "$1"); ln -s /etc/hostname "$d/src/link.js"; put "$d/docs/environment.md" 'doc'; put "$d/key.pem" 'x'; put "$d/data.sql" 'x'; put "$d/terraform.tfstate" '{}'; commit_all "$d"; printf '%s' "$d"; }
65
+
66
+ # fact <facts-file> <id> -> status
67
+ fact() { awk -F'\t' -v id="$2" '$1==id {print $2; exit}' "$1"; }
68
+ scan_to() { # scan_to <repo> <facts-out> [extra args]
69
+ local r=$1 out=$2; shift 2
70
+ lc scan --target "$r" --facts "$out" --files-out "$out.files" "$@" > "$out.stdout" 2> "$out.stderr"
71
+ }
72
+ finish() { # finish <minimum assertion count>
73
+ if [ $((passes + fails)) -lt "$1" ]; then printf 'FAIL - assertion floor: %d ran, %d required\n' $((passes + fails)) "$1"; exit 1; fi
74
+ printf '%d passed, %d failed\n' "$passes" "$fails"
75
+ [ "$fails" -eq 0 ]
76
+ }
77
+ # Instrument self-test: drive pass() and fail() once each in a subshell and require both counters to move.
78
+ selftest() { local p f; p=$(bash -c 'source "$1"; pass x >/dev/null; echo $passes' _ "${BASH_SOURCE[0]}"); f=$(bash -c 'source "$1"; fail x >/dev/null; echo $fails' _ "${BASH_SOURCE[0]}"); [ "$p" = 1 ] && [ "$f" = 1 ]; }
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env bash
2
+ # Guard 1: the single write chokepoint. Controls, bite-proof mutations of a sandbox copy, no leftovers.
3
+ set -uo pipefail
4
+ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
5
+ check "instrument self-test" selftest
6
+ command -v gitleaks >/dev/null 2>&1 || { echo "FAIL - gitleaks is required for this suite"; exit 1; }
7
+ GATE="$SKILL/scripts/lib/redact-gate.sh"
8
+ clean="$SCRATCH/clean.md"; dirty="$SCRATCH/dirty.md"
9
+ printf '# Report\n\nNothing secret here, path docs/secret-handling.md only.\n' > "$clean"
10
+ printf '# Report\n\nContact: %s@%s.invalid\n' 'jane.roe' 'example' > "$dirty"
11
+ run_gate() { # run_gate <gate-lib> <src> <dest> -> rc
12
+ # shellcheck source=/dev/null
13
+ ( set +e; export SKILL_DIR="$SKILL" PLUGIN_DIR="$PLUGIN"; source "$1"; lc_emit_checked "$2" "$3" 0 ) >"$SCRATCH/g.out" 2>&1
14
+ }
15
+ run_gate "$GATE" "$clean" "$SCRATCH/out/clean.md"; rc=$?
16
+ check "control: clean bytes are written" bash -c '[ "$1" = 0 ] && [ -f "$2" ] && cmp -s "$3" "$2"' _ "$rc" "$SCRATCH/out/clean.md" "$clean"
17
+ check "must-PASS: a path containing the word secret but no value is written" test -f "$SCRATCH/out/clean.md"
18
+ run_gate "$GATE" "$dirty" "$SCRATCH/out2/dirty.md"; rc=$?
19
+ check "planted email-shaped value: rc 1, reason=redaction-hit, nothing written" bash -c '[ "$1" = 1 ] && grep -q "reason=redaction-hit" "$2" && [ ! -e "$3" ]' _ "$rc" "$SCRATCH/g.out" "$SCRATCH/out2/dirty.md"
20
+ check "no temp file and no empty directory left behind after an abort" test ! -e "$SCRATCH/out2"
21
+ check "the abort never echoes the matched value" bash -c '! grep -q "jane.roe" "$1"' _ "$SCRATCH/g.out"
22
+
23
+ # Mutation 1: remove the sentinel call from a sandbox copy -> the gate must now let the planted value through.
24
+ mkdir -p "$SCRATCH/mut"
25
+ sed 's/^\(.*REDACT_SENTINEL.*\)$/: # mutated: \1/' "$GATE" > "$SCRATCH/mut/gate.sh"
26
+ check "mutation landed (sandbox copy differs from the pristine gate)" bash -c '! cmp -s "$1" "$2"' _ "$GATE" "$SCRATCH/mut/gate.sh"
27
+ run_gate "$SCRATCH/mut/gate.sh" "$dirty" "$SCRATCH/out3/dirty.md"; rc=$?
28
+ check "mutation 1 (sentinel removed): the planted value now gets through, so the suite is sensitive" test "$rc" = 0 -a -f "$SCRATCH/out3/dirty.md"
29
+ # Scanner that did not run -> rc 2, never 'found secrets' and never a write.
30
+ printf '#!/usr/bin/env bash\nexit 2\n' > "$SCRATCH/s2.sh"; chmod +x "$SCRATCH/s2.sh"
31
+ ( export LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s2.sh"; run_gate "$GATE" "$clean" "$SCRATCH/out4/c.md" ); rc=$?
32
+ check "sentinel exits 2 (did not complete): rc 2 and no file" bash -c '[ "$1" = 2 ] && [ ! -e "$2" ]' _ "$rc" "$SCRATCH/out4/c.md"
33
+ ( export LAUNCH_CHECK_GITLEAKS="$SCRATCH/s2.sh"; run_gate "$GATE" "$clean" "$SCRATCH/out5/c.md" ); rc=$?
34
+ check "gitleaks exits 2 (did not complete): rc 2 and no file" bash -c '[ "$1" = 2 ] && [ ! -e "$2" ]' _ "$rc" "$SCRATCH/out5/c.md"
35
+ ( export LAUNCH_CHECK_GITLEAKS=gitleaks-does-not-exist; run_gate "$GATE" "$clean" "$SCRATCH/out6/c.md" ); rc=$?
36
+ check "gitleaks missing: rc 2 reason=scanner-missing" bash -c '[ "$1" = 2 ] && grep -q "reason=scanner-missing" "$2"' _ "$rc" "$SCRATCH/g.out"
37
+ # Source scan: exactly one write path to the report.
38
+ nw=$(grep -c 'mv -f\|mv "' "$SKILL/scripts/lib/render.sh" "$SKILL/scripts/launch-check.sh" 2>/dev/null | awk -F: '{s+=$2} END{print s+0}')
39
+ check "render.sh and launch-check.sh never move a file onto the report themselves" test "$nw" = 0
40
+ check "no direct redirect to the report path outside the gate" bash -c '! grep -nE ">[> ]*\"?\$\{?(REPORT|DEST)" "$1" "$2" 2>/dev/null' _ "$SKILL/scripts/lib/render.sh" "$SKILL/scripts/launch-check.sh"
41
+ # Harness row: a clean string through the same harness must flip the verdict to written.
42
+ printf '# Report\n\nclean\n' > "$SCRATCH/notplanted.md"
43
+ run_gate "$GATE" "$SCRATCH/notplanted.md" "$SCRATCH/out7/n.md"; rc=$?
44
+ check "harness row: replacing the plant with a clean string flips the verdict (suite can fail)" test "$rc" = 0
45
+
46
+ # --- Review fixes (PR #11867) ---
47
+ # The gitleaks layer alone (the sentinel is stubbed to pass): the redaction gate must catch a token-shaped value there.
48
+ printf '# Report\n\nvalue: %s\n' "$(planted_secret)" > "$SCRATCH/gl.md"
49
+ printf '#!/usr/bin/env bash\nexit 0\n' > "$SCRATCH/s0.sh"; chmod +x "$SCRATCH/s0.sh"
50
+ ( export LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s0.sh"; run_gate "$GATE" "$SCRATCH/gl.md" "$SCRATCH/out8/g.md" ); rc=$?
51
+ check "gitleaks layer alone: rc 1 reason=redaction-hit layer=gitleaks, nothing written" bash -c '[ "$1" = 1 ] && grep -q "layer=gitleaks" "$2" && [ ! -e "$3" ]' _ "$rc" "$SCRATCH/g.out" "$SCRATCH/out8/g.md"
52
+ check "the abort never echoes the token" bash -c '! grep -q "ghp_" "$1"' _ "$SCRATCH/g.out"
53
+ # Seams are test-only: with LAUNCH_CHECK_TEST unset the overrides are ignored and the real layers run.
54
+ ( export LAUNCH_CHECK_TEST=0 LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s0.sh"; run_gate "$GATE" "$dirty" "$SCRATCH/out9/d.md" ); rc=$?
55
+ check "production mode ignores a sentinel override: the planted value is still caught by the real sentinel" bash -c '[ "$1" = 1 ] && grep -q "layer=sentinel" "$2"' _ "$rc" "$SCRATCH/g.out"
56
+ TRUE_BIN=$(command -v true)
57
+ ( export LAUNCH_CHECK_TEST=0 LAUNCH_CHECK_GITLEAKS="$TRUE_BIN"; run_gate "$GATE" "$SCRATCH/gl.md" "$SCRATCH/out10/g.md" ); rc=$?
58
+ check "production mode ignores a scanner override: the token is still caught" test "$rc" = 1
59
+ # No scratch directory or temp file is leaked on success or on abort, and no trap noise reaches stderr.
60
+ mkdir -p "$SCRATCH/tmpd"
61
+ ( export TMPDIR="$SCRATCH/tmpd"; run_gate "$GATE" "$clean" "$SCRATCH/out11/c.md" ); rc=$?
62
+ check "success: no lc-gate scratch directory is left behind and the trap prints nothing" bash -c '[ "$1" = 0 ] && [ -z "$(ls -A "$2")" ] && ! grep -q "parameter null" "$3"' _ "$rc" "$SCRATCH/tmpd" "$SCRATCH/g.out"
63
+ ( export TMPDIR="$SCRATCH/tmpd"; run_gate "$GATE" "$dirty" "$SCRATCH/out12/d.md" )
64
+ check "abort: no scratch directory left behind either" test -z "$(ls -A "$SCRATCH/tmpd")"
65
+ check "the report is written world-readable (644), not as the temp file's 600" bash -c '[ "$(ls -l "$1" | cut -c1-10)" = "-rw-r--r--" ]' _ "$SCRATCH/out/clean.md"
66
+ # The write cannot leave the declared root through a symlinked directory.
67
+ mkdir -p "$SCRATCH/root" "$SCRATCH/away"; ln -s "$SCRATCH/away" "$SCRATCH/root/kb"
68
+ ( export LC_DEST_ROOT="$SCRATCH/root"; run_gate "$GATE" "$clean" "$SCRATCH/root/kb/sub/r.md" ); rc=$?
69
+ check "destination resolving outside LC_DEST_ROOT: rc 2 write-failed, nothing created outside" bash -c '[ "$1" = 2 ] && grep -q "reason=write-failed" "$2" && [ -z "$(ls -A "$3")" ]' _ "$rc" "$SCRATCH/g.out" "$SCRATCH/away"
70
+ # Source scan: every use of the report path is a read or the single chokepoint call.
71
+ stray=$(grep -n 'TARGET/\$REPORT_REL' "$SKILL/scripts/lib/render.sh" "$SKILL/scripts/launch-check.sh" | grep -vE 'lc_emit_checked|lc_prev_state|\[ -f|2>/dev/null' || true)
72
+ check "no use of the report path other than a read or lc_emit_checked" test -z "$stray"
73
+ finish 23