@techgoblin/gobstack 0.6.0 → 0.7.3

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/bin/goblin-verify CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  set -uo pipefail
21
21
 
22
- GOBLIN_VERIFY_VERSION="0.6.0"
22
+ GOBLIN_VERIFY_VERSION="0.7.3"
23
23
  SELF_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
24
24
  # shellcheck source=goblin-lib.sh
25
25
  . "$SELF_DIR/goblin-lib.sh"
@@ -47,7 +47,8 @@ goblin-verify — prove a goblin-stack install is still what it says it is.
47
47
  --json machine-readable output
48
48
  --source <path> read the manifest from a goblin-stack checkout instead of .gob/
49
49
 
50
- Exit codes: 0 pass | 1 a check failed | 2 could not run | 3 the manifest is broken.
50
+ Exit codes: 0 pass | 1 a check failed | 2 could not run | 3 the manifest is broken
51
+ (also 3 for --only AG-01 with no approval record: not policed yet, not red).
51
52
  USAGE
52
53
  }
53
54
 
@@ -301,9 +302,12 @@ if [ -n "$ONLY" ]; then
301
302
  if [ "$_hit" -eq 0 ] && [ -n "$LOCAL_FILE" ]; then
302
303
  awk -F'\t' -v x="$want" '$1==x {f=1} END{exit !f}' "$LOCAL_FILE" && _hit=1
303
304
  fi
305
+ if [ "$_hit" -eq 0 ] && [ -n "$LIBRARY_FILE" ]; then
306
+ awk -F'\t' -v x="$want" 'NR>1 && $1==x {f=1} END{exit !f}' "$LIBRARY_FILE" && _hit=1
307
+ fi
304
308
  [ "$_hit" -eq 1 ] || UNKNOWN="$UNKNOWN $want"
305
309
  done
306
- [ -z "$UNKNOWN" ] || { g_err "--only names id(s) in neither the manifest nor the local override:$UNKNOWN"; exit 2; }
310
+ [ -z "$UNKNOWN" ] || { g_err "--only names id(s) in neither the manifest, the library nor the local override:$UNKNOWN"; exit 2; }
307
311
  # A valid id that is SOURCE-scope (PR-01..PR-04) selects no target row: the run emits
308
312
  # nothing and exits 0, which is the same no-op gate D15 closed for a typo (F2-6).
309
313
  TARGET_ROWS=0
@@ -315,6 +319,10 @@ if [ -n "$ONLY" ]; then
315
319
  awk -F'\t' -v x="$want" '$1==x && $2=="target" {f=1} END{exit !f}' "$LOCAL_FILE" \
316
320
  && TARGET_ROWS=1
317
321
  fi
322
+ if [ "$TARGET_ROWS" -eq 0 ] && [ -n "$LIBRARY_FILE" ]; then
323
+ awk -F'\t' -v x="$want" 'NR>1 && $1==x && $2=="target" {f=1} END{exit !f}' "$LIBRARY_FILE" \
324
+ && TARGET_ROWS=1
325
+ fi
318
326
  done
319
327
  if [ "$TARGET_ROWS" -eq 0 ]; then
320
328
  g_err "--only $ONLY selects no target-scope row, so this run would execute nothing and"
@@ -421,7 +429,7 @@ export _GOB_MANIFEST="$MANIFEST"
421
429
  export GOBLIN_ROOT="$ROOT"
422
430
  export GOBLIN_CONFIG="$CONFIG"
423
431
 
424
- # ---- the security surface (SC-01..SC-09) and the perf baseline (PF-01) -----------------------
432
+ # ---- the security surface (SC-01..SC-08; SC-09 lives in the library manifest) and the perf baseline (PF-01) ----
425
433
  # Every one of these is DECLARED in .gob/goblin.yaml. A stack-specific rule guessed from the
426
434
  # files on disk is how a matrix starts lying; a declared key that is absent is a skip with a
427
435
  # reason, never a silent pass.
@@ -741,56 +749,635 @@ check_hp_05() {
741
749
  [ "$found" -eq 1 ]
742
750
  }
743
751
 
744
- # ---- the curation wave (CURATION-2026-11-07 §2/§6 phase 1): HV-02, HP-06, HV-01 ----------
745
- # Three text probes adopted from one project's measured failures, cheapest-and-most-
746
- # preventative first (§6): an instrument that convicts the product (C2 -> HV-02), a queue
747
- # that lies (C3 -> HP-06), and a check whose input is not the input the user gets (C1 ->
748
- # HV-01). All three are the BN-01 class - grep over text, no AST - and each carries its
749
- # honest limit in its why cell and in docs/LIMITS.md.
752
+ # ---- the curation wave (CURATION-2026-11-07 §2/§6 phase 1): HP-06, HV-01 -------------------
753
+ # Text probes adopted from one project's measured failures, cheapest-and-most-
754
+ # preventative first (§6): a queue that lies (C3 -> HP-06), and a check whose input is
755
+ # not the input the user gets (C1 -> HV-01). Both are the BN-01 class - grep over text,
756
+ # no AST - and each carries its honest limit in its why cell and in docs/LIMITS.md.
757
+ # (The third probe of the wave, HV-02, was withdrawn on 2026-11-25 - its statement bound
758
+ # it to a browser-plus-Node surface only one project has; it lives in
759
+ # docs/AUDIT-2026-11-25-framework-agnostic.md under "withdrawn - where it went".)
760
+
761
+ # ---- PV-01 (CURATION-2026-11-25, opt-in library row) ---------------------------
762
+ # A plain text probe over a route tree, the same class as check_hv_01: no AST, no
763
+ # runtime, no config key — the framework's own directory conventions are read as
764
+ # HEURISTICS, so a repo without them gets SKIP-with-a-reason, never a RED. PV-02 was
765
+ # withdrawn as framework-specific (see LIMITS #62). Return 0 pass / 1 red / 3 skip, and
766
+ # a skip PRINTS its reason: an opt-in row whose lane is absent says so out loud, it
767
+ # never vanishes into a bare green.
768
+
769
+ _pv_route_trees() {
770
+ # the route-tree roots the framework conventions name; any one of them counts
771
+ local t
772
+ for t in "$ROOT/app" "$ROOT/src/app" "$ROOT/pages" "$ROOT/routes"; do
773
+ [ -d "$t" ] && printf '%s\n' "$t"
774
+ done
775
+ }
750
776
 
751
- check_hv_02() {
752
- # C2: a number taken from a live surface carries its guard. Text probe over the harness dir:
753
- # PRESENCE of a guard is provable, EFFECTIVENESS is not (a decorative guard passes - the
754
- # limit is stated, not hidden). A `guarded: <reason>` marker comment is the escape hatch for
755
- # a harness whose guard is not nameable in these tokens.
756
- local d="$GOBLIN_HARNESS_DIR" f rel bad=0 n=0 nb=0 np=0
757
- if [ -z "$d" ]; then
758
- if [ "$GOBLIN_HARNESS_STATE" = "absent" ]; then
759
- printf 'harness_dir %s is declared and scaffold_checks is yes, but the directory is absent\n' \
760
- "$GOBLIN_HARNESS_REL"
761
- return 1
777
+ _pv_find() {
778
+ # find under one route-tree root, pruned of vendored and generated trees
779
+ local root="$1"
780
+ shift
781
+ find "$root" \( -name node_modules -o -name .next -o -name dist -o -name .git \) -prune -o "$@" -print
782
+ }
783
+
784
+ _pv01_imports_of() {
785
+ # the module specifiers of one file's import / export-from / require / dynamic import()
786
+ # calls, read over the WHOLE file text, not line by line: prettier wraps a brace list
787
+ # across lines, so the line-anchored grep this replaces never saw a `} from './x'` line
788
+ # and a compliant surface was falsely RED (PR #2 review). awk is already a checked
789
+ # and RS="\001" makes the file one record portably). Text
790
+ # only: comments are stripped first. The from-clause keyword scan masks quoted runs in the
791
+ # segment it inspects, so a specifier-shaped string literal no longer vouches for an
792
+ # in-string ` from '<spec>'` even when the string mentions `import`; the mask itself is
793
+ # text, not a lexer — an escaped quote or a JSX apostrophe can break it, and the resulting
794
+ # error is a false RED (docs/LIMITS.md #61).
795
+ awk -v Q1="'" -v Q2='"' '
796
+ function seg_has_static_kw(seg, i, k, p, we, nxt, out, q, j, done) {
797
+ # the segment between the last consumed specifier and a `from` may only own that
798
+ # from-clause if a STATIC import/export keyword stands in the SAME statement. Take the
799
+ # slice after the last statement boundary (`;`) so a bare `import './x'` earlier in the
800
+ # segment cannot vouch for a stray ` from "` — but MASK QUOTED RUNS FIRST, because a
801
+ # string literal that merely mentions `import` must not vouch for the in-string
802
+ # ` from "` either (`const s = "import x from '../shared-a'"` was exactly such a false
803
+ # GREEN): every quoted run becomes an empty pair, and an UNTERMINATED
804
+ # quote drops the rest of the segment (an unbalanced quote means the keyword, if any,
805
+ # sits inside that string). The mask is a text rule, not a lexer: a JSX-text apostrophe
806
+ # (the possessive kind) or an escaped quote makes it resynchronise at the wrong quote,
807
+ # and the truncated segment loses keywords — fewer specifiers vouched, a false RED,
808
+ # never a false GREEN (LIMITS #61). Inside the masked slice the LAST keyword may not
809
+ # be a dynamic import( call, which owns no from-clause.
810
+ # Off-by-one, fixed (PR #2 review round 3): the old `we = p + RSTART + RLENGTH - 1`
811
+ # landed on the last character OF the keyword, so `nxt` was `t(`/`t ` and the `!= "("` test
812
+ # fired on every segment containing import/export — the loop never continued and the
813
+ # dynamic exclusion never ran. Now `we = p + RSTART + RLENGTH` is one past the keyword:
814
+ # for seg = "import x" the match is "^import" (RSTART=1, RLENGTH=7), so we = 8 and
815
+ # substr(seg, we, 1) is "x", the character after the keyword.
816
+ out = ""; p = 1; done = 0
817
+ qqre = "[" Q1 Q2 "]"
818
+ while (match(substr(seg, p), qqre)) {
819
+ out = out substr(seg, p, RSTART - 1) Q1 Q1
820
+ q = substr(seg, p + RSTART - 1, 1)
821
+ j = index(substr(seg, p + RSTART), q)
822
+ if (j == 0) { seg = out; done = 1; break } # unterminated: the rest is string content
823
+ p = p + RSTART + j # one past the closing quote
824
+ }
825
+ if (!done) seg = out substr(seg, p) # after the break seg IS out; appending a slice of it duplicated the masked text (fixed)
826
+ k = 0; p = 1
827
+ while ((i = index(substr(seg, p), ";")) > 0) { k = p + i - 1; p = k + 1 }
828
+ if (k > 0) seg = substr(seg, k + 1)
829
+ p = 0
830
+ while (match(substr(seg, p + 1), /(^|[^A-Za-z0-9_$])(import|export)/)) {
831
+ we = p + RSTART + RLENGTH # one past the keyword, absolute in seg
832
+ nxt = substr(seg, we, 1) # the character after the keyword
833
+ if (nxt != "(") return 1 # a static import/export owns the from-clause
834
+ p = we # a dynamic import(: keep scanning
835
+ }
836
+ return 0
837
+ }
838
+ BEGIN { RS = "\001" } # the whole file is one record; no source text carries \001
839
+ {
840
+ s = $0
841
+ # strip block comments (they span lines)
842
+ out = ""
843
+ while ((i = index(s, "/*")) > 0) {
844
+ out = out substr(s, 1, i - 1)
845
+ s = substr(s, i + 2)
846
+ j = index(s, "*/")
847
+ if (j == 0) { s = ""; break }
848
+ s = substr(s, j + 2)
849
+ }
850
+ s = out s
851
+ # strip line comments: a // not preceded by : (a URL scheme) ends at its line end
852
+ out = ""
853
+ while ((i = index(s, "//")) > 0) {
854
+ if (i > 1 && substr(s, i - 1, 1) == ":") {
855
+ out = out substr(s, 1, i + 1)
856
+ s = substr(s, i + 2)
857
+ continue
858
+ }
859
+ out = out substr(s, 1, i - 1) "\n"
860
+ s = substr(s, i)
861
+ j = index(s, "\n")
862
+ if (j == 0) { s = ""; break }
863
+ s = substr(s, j)
864
+ }
865
+ s = out s
866
+ gsub(/[ \t\r\n]+/, " ", s)
867
+ qq = "[" Q1 Q2 "][^" Q1 Q2 "]*[" Q1 Q2 "]" # a quoted string
868
+ fromre = " from [" Q1 Q2 "]" # ... from "<spec>"
869
+ # static import ... from / export ... from. RSTART is relative to the
870
+ # substr(s, prev) window, so absolute positions add prev - 1.
871
+ prev = 1
872
+ while (match(substr(s, prev), fromre)) {
873
+ seg = substr(s, prev, RSTART - 1)
874
+ qpos = prev - 1 + RSTART + RLENGTH - 1 # the opening quote, in s
875
+ if (seg_has_static_kw(seg)) {
876
+ rest = substr(s, qpos) # starts AT the quote
877
+ if (match(rest, qq)) {
878
+ sp = substr(rest, RSTART + 1, RLENGTH - 2)
879
+ if (sp != "") print sp
880
+ prev = qpos + RSTART + RLENGTH # one past the closing quote
881
+ continue
882
+ }
883
+ }
884
+ prev = qpos + 1
885
+ }
886
+ # side-effect import "<spec>" - printed with a SE: prefix so the resolver can EXCLUDE
887
+ # it from the shared-evidence intersection: an import with no from clause loads a
888
+ # module without naming what renders, so two layouts wiring the same module by side
889
+ # effect prove nothing about the shell (PR #2 review round 2, theme-is-not-the-shell)
890
+ imp = "(^|[^A-Za-z0-9_$])import [" Q1 Q2 "]"
891
+ t = s
892
+ while (match(t, imp)) {
893
+ qpos = RSTART + RLENGTH - 1 # the opening quote, in t
894
+ rest = substr(t, qpos)
895
+ if (match(rest, qq)) {
896
+ sp = substr(rest, RSTART + 1, RLENGTH - 2)
897
+ if (sp != "") print "SE:" sp
898
+ t = substr(t, qpos + RSTART + RLENGTH)
899
+ } else {
900
+ t = substr(t, qpos + 1)
901
+ }
902
+ }
903
+ # dynamic import("<spec>") and require("<spec>") in any position
904
+ dyn = "(^|[^A-Za-z0-9_$])import ?\\( ?[" Q1 Q2 "]"
905
+ req = "(^|[^A-Za-z0-9_$])require ?\\( ?[" Q1 Q2 "]"
906
+ for (di = 1; di <= 2; di++) {
907
+ t = s
908
+ pat = (di == 1 ? dyn : req)
909
+ while (match(t, pat)) {
910
+ qpos = RSTART + RLENGTH - 1 # the opening quote, in t
911
+ rest = substr(t, qpos)
912
+ if (match(rest, qq)) {
913
+ sp = substr(rest, RSTART + 1, RLENGTH - 2)
914
+ if (sp != "") print sp
915
+ t = substr(t, qpos + RSTART + RLENGTH)
916
+ } else {
917
+ t = substr(t, qpos + 1)
918
+ }
919
+ }
920
+ }
921
+ }
922
+ ' "$1" 2>/dev/null
923
+ }
924
+
925
+ _pv_norm_spec() {
926
+ # resolve a relative specifier against the importing file's directory so `../layout` from
927
+ # a preview dir and `./layout` from the root name the same module; only relative
928
+ # specifiers reach this function (a bare specifier is resolved or dropped by
929
+ # _pv01_resolve_spec first)
930
+ local cur="$1" rest="$2" seg
931
+ case "$rest" in ./*|../*) ;; *) printf '%s' "$rest"; return ;; esac
932
+ rest=${rest#./}
933
+ while [ -n "$rest" ]; do
934
+ seg="${rest%%/*}"
935
+ if [ "$rest" = "${rest#*/}" ]; then rest=""; else rest="${rest#*/}"; fi
936
+ case "$seg" in
937
+ ""|".") : ;;
938
+ "..") cur="${cur%/*}" ;;
939
+ *) cur="$cur/$seg" ;;
940
+ esac
941
+ done
942
+ printf '%s' "$cur"
943
+ }
944
+
945
+ # ---- PV-01 module resolution: the intersection counts project-resolvable modules only ----
946
+ # A bare specifier (an installed package, a builtin, an alias) used to pass through unchanged
947
+ # and was counted as shared evidence — `react` in both layouts cleared the surface (false
948
+ # GREEN, the worse direction). The rule now: relative specifiers normalise and count as
949
+ # before; a bare specifier counts only when it resolves to a file that exists inside $ROOT
950
+ # (tsconfig.json/jsconfig.json baseUrl+paths first, then <ROOT>/<spec> with extension and
951
+ # index probing); everything else is dropped from the intersection and named in the RED
952
+ # message (LIMITS #61, PR #2 review round 2).
953
+
954
+ _pv01_tsconfig_load() {
955
+ # read compilerOptions.baseUrl + paths once per run, best effort and STRICT JSON only: a
956
+ # commented JSONC file fails the parse and the aliases it declares stay unresolvable (the
957
+ # documented false-RED direction). Sets _PV01_BASEURL and _PV01_PATHS (pattern<TAB>target
958
+ # lines, longest pattern first).
959
+ _PV01_BASEURL=""
960
+ _PV01_PATHS=""
961
+ local f parsed
962
+ for f in "$ROOT/tsconfig.json" "$ROOT/jsconfig.json"; do
963
+ [ -f "$f" ] || continue
964
+ parsed=$(python3 - "$f" <<'PYEOF' 2>/dev/null
965
+ import json, sys
966
+ try:
967
+ with open(sys.argv[1]) as fh:
968
+ cfg = json.load(fh)
969
+ except Exception:
970
+ sys.exit(0)
971
+ co = cfg.get("compilerOptions") or {}
972
+ bu = co.get("baseUrl")
973
+ if isinstance(bu, str):
974
+ print("BASE\t" + bu)
975
+ paths = co.get("paths")
976
+ if isinstance(paths, dict):
977
+ for pat, targets in paths.items():
978
+ if not isinstance(targets, list):
979
+ continue
980
+ for tgt in targets:
981
+ if isinstance(tgt, str):
982
+ print("PATH\t" + pat + "\t" + tgt)
983
+ PYEOF
984
+ ) || parsed=""
985
+ [ -n "$parsed" ] || continue
986
+ _PV01_BASEURL=$(printf '%s\n' "$parsed" | awk -F'\t' '$1=="BASE"{print $2; exit}')
987
+ _PV01_PATHS=$(printf '%s\n' "$parsed" \
988
+ | awk -F'\t' '$1=="PATH"{print length($2)"\t"$2"\t"$3}' | sort -nr | cut -f2-)
989
+ return 0
990
+ done
991
+ }
992
+
993
+ _pv01_probe() {
994
+ # does a ROOT-relative candidate exist as a file inside the project? print the found path
995
+ # (relative to ROOT, with the probed extension) or nothing. Extension probing follows the
996
+ # bundler's usual order; index probing maps a directory onto its entry file.
997
+ local p="$1" ext
998
+ case "$p" in ""|.|/*|./*|../*) return 1 ;; esac
999
+ [ -f "$ROOT/$p" ] && { printf '%s' "$p"; return 0; }
1000
+ for ext in ts tsx js jsx mjs cjs mts cts json; do
1001
+ [ -f "$ROOT/$p.$ext" ] && { printf '%s' "$p.$ext"; return 0; }
1002
+ done
1003
+ for ext in ts tsx js jsx mjs cjs mts cts; do
1004
+ [ -f "$ROOT/$p/index.$ext" ] && { printf '%s' "$p/index.$ext"; return 0; }
1005
+ done
1006
+ return 1
1007
+ }
1008
+
1009
+ _pv01_key_of_found() {
1010
+ # canonical comparison key of a resolved file: the ROOT-relative path without its probed
1011
+ # extension and without a trailing /index, so `@/layout`, `./layout.tsx` and an index entry
1012
+ # name the same module as the relative normalisation does
1013
+ local k="$1"
1014
+ case "$k" in *.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.mts|*.cts|*.json) k="${k%.*}" ;; esac
1015
+ case "$k" in */index) k="${k%/index}" ;; esac
1016
+ printf '%s' "$k"
1017
+ }
1018
+
1019
+ _pv01_norm_base() {
1020
+ # a baseUrl of "." or "./" means the tsconfig's own directory (= ROOT): normalise to empty
1021
+ local b="${1#./}"; b="${b#/}"; b="${b%/}"
1022
+ [ "$b" = "." ] && b=""
1023
+ printf '%s' "$b"
1024
+ }
1025
+
1026
+ _pv01_probe_target() {
1027
+ # substitute the star of a paths target, join the baseUrl (or the tsconfig dir = ROOT when
1028
+ # there is none), and probe. $1 = target (may carry exactly one *), $2 = substituted text
1029
+ local tgt="$1" sub="$2" p b
1030
+ case "$tgt" in
1031
+ *\**) p="${tgt/\*/$sub}" ;;
1032
+ *) [ -z "$sub" ] || return 1; p="$tgt" ;;
1033
+ esac
1034
+ p="${p#./}"
1035
+ case "$p" in
1036
+ ""|.) return 1 ;;
1037
+ /*) p="${p#/}" ;;
1038
+ *)
1039
+ if [ -n "$_PV01_BASEURL" ]; then
1040
+ b=$(_pv01_norm_base "$_PV01_BASEURL")
1041
+ [ -n "$b" ] && p="$b/$p"
1042
+ fi
1043
+ ;;
1044
+ esac
1045
+ _pv01_probe "$p"
1046
+ }
1047
+
1048
+ _pv01_is_asset_spec() {
1049
+ # is this specifier a style/asset import? A shared stylesheet (or image, or font) proves
1050
+ # the same THEME, never the same SHELL: a reported tenant's preview layout and its public
1051
+ # layout both imported the same globals.css and the pre-fix row PASSED on the exact file
1052
+ # that shipped the bug (PR #2 review round 2, measured pre-fix). These extensions are
1053
+ # never evidence.
1054
+ case "$1" in
1055
+ *.css|*.scss|*.sass|*.less|*.styl|*.svg|*.png|*.jpg|*.jpeg|*.webp|*.gif|*.ico|*.woff|*.woff2|*.ttf) return 0 ;;
1056
+ *) return 1 ;;
1057
+ esac
1058
+ }
1059
+
1060
+ _pv01_emit_key() {
1061
+ # print the classification line of one resolved module:
1062
+ # A<TAB><key> an asset/side-effect import - NEVER shared-shell evidence
1063
+ # K<TAB><key> project CODE the layout really pulls in
1064
+ # $1 = canonical key, $2 = the specifier as written, $3 = the resolved ROOT-relative
1065
+ # path, $4 = 1 when the specifier came from a side-effect import
1066
+ local key="$1" spec="$2" found="$3" se="$4" k="K"
1067
+ if [ "$se" -eq 1 ] || _pv01_is_asset_spec "$spec" || _pv01_is_asset_spec "$found"; then k="A"; fi
1068
+ printf '%s\t%s\n' "$k" "$key"
1069
+ }
1070
+
1071
+ _pv01_resolve_spec() {
1072
+ # classify one import specifier of the layout living in dir $1:
1073
+ # K<TAB><key> counts as shared evidence: project CODE (relative specifiers always do,
1074
+ # normalised; bare specifiers when they resolve inside the project)
1075
+ # A<TAB><key> a style/asset import, or any side-effect import (no from clause) - the
1076
+ # theme and the wiring, never evidence of a shared shell; still tracked so
1077
+ # the RED message can say when a surface shares ONLY those
1078
+ # D<TAB><spec> dropped: a specifier that resolves to nothing inside the project
1079
+ # (an installed package, a builtin, an unresolvable alias) or names
1080
+ # a module outside the project root (a relative that climbs out)
1081
+ local cur="$1" spec="$2" pat tgt sub prefix suffix found norm se=0
1082
+ case "$spec" in
1083
+ "SE:"*) se=1; spec="${spec#SE:}" ;;
1084
+ esac
1085
+ case "$spec" in
1086
+ ./*|../*)
1087
+ # one canonical key space for every branch: _pv_norm_spec yields an ABSOLUTE path, the
1088
+ # alias/baseUrl branches yield ROOT-relative ones — keys from two different spaces never
1089
+ # intersect, so a surface naming the same module relative while the public layout names it
1090
+ # through a resolvable alias was a guaranteed false RED. Strip $ROOT/ and canonicalise
1091
+ # (extension off, trailing /index off) exactly as _pv01_key_of_found does. A relative
1092
+ # specifier that climbs out of ROOT names a module outside the project: dropped and named
1093
+ # in the RED message like any other unresolvable specifier, never a silent empty key.
1094
+ norm=$(_pv_norm_spec "$cur" "$spec")
1095
+ case "$norm" in
1096
+ "$ROOT"/*) _pv01_emit_key "$(_pv01_key_of_found "${norm#"$ROOT"/}")" "$spec" "${norm#"$ROOT"/}" "$se"; return 0 ;;
1097
+ esac
1098
+ printf 'D\t%s\n' "$spec"; return 0 ;;
1099
+ esac
1100
+ if [ -n "$_PV01_PATHS" ]; then
1101
+ while IFS=$'\t' read -r pat tgt; do
1102
+ [ -n "$pat" ] || continue
1103
+ case "$pat" in
1104
+ *\*)
1105
+ prefix="${pat%\**}"; suffix="${pat#*\*}"
1106
+ case "$spec" in "$prefix"*) ;; *) continue ;; esac
1107
+ sub="${spec#"$prefix"}"
1108
+ case "$sub" in
1109
+ *"$suffix") sub="${sub%"$suffix"}" ;;
1110
+ *) continue ;;
1111
+ esac
1112
+ if found=$(_pv01_probe_target "$tgt" "$sub"); then
1113
+ _pv01_emit_key "$(_pv01_key_of_found "$found")" "$spec" "$found" "$se"; return 0
1114
+ fi
1115
+ ;;
1116
+ *)
1117
+ [ "$spec" = "$pat" ] || continue
1118
+ if found=$(_pv01_probe_target "$tgt" ""); then
1119
+ _pv01_emit_key "$(_pv01_key_of_found "$found")" "$spec" "$found" "$se"; return 0
1120
+ fi
1121
+ ;;
1122
+ esac
1123
+ done <<< "$_PV01_PATHS"
1124
+ fi
1125
+ if [ -n "$_PV01_BASEURL" ]; then
1126
+ sub="$(_pv01_norm_base "$_PV01_BASEURL")"
1127
+ [ -n "$sub" ] && sub="$sub/" || sub=""
1128
+ if found=$(_pv01_probe "$sub${spec#./}"); then
1129
+ _pv01_emit_key "$(_pv01_key_of_found "$found")" "$spec" "$found" "$se"; return 0
762
1130
  fi
763
- printf 'no harness dir (%s absent, scaffold_checks is no) - nothing to guard\n' \
764
- "$GOBLIN_HARNESS_REL"
1131
+ fi
1132
+ if found=$(_pv01_probe "${spec#./}"); then
1133
+ _pv01_emit_key "$(_pv01_key_of_found "$found")" "$spec" "$found" "$se"; return 0
1134
+ fi
1135
+ printf 'D\t%s\n' "$spec"
1136
+ }
1137
+
1138
+ _pv01_asset_note() {
1139
+ # called when the code-module intersection is empty: if what the layouts DO share is
1140
+ # only stylesheet/asset (or side-effect) imports, say so in the FAIL message - the theme
1141
+ # is not the shell (PR #2 review round 2). $1 surface path, $2/$3 sorted shared-evidence
1142
+ # A-key lists (one key per line) of the two layouts.
1143
+ local surf="$1" aov
1144
+ aov=$(comm -12 <(printf '%s\n' "$2") <(printf '%s\n' "$3"))
1145
+ [ -n "$aov" ] || return 0
1146
+ if printf '%s\n' "$aov" | grep -Eq '\.(css|scss|sass|less|styl|svg|png|jpe?g|webp|gif|ico|woff2?|ttf)$'; then
1147
+ printf 'note: %s shares only stylesheet/asset imports, which are the theme and not the shell\n' "$surf"
1148
+ else
1149
+ printf 'note: %s shares only side-effect imports, which load modules without naming what renders\n' "$surf"
1150
+ fi
1151
+ }
1152
+
1153
+ # PV-01 route-layout selection: the first EXISTING exact code basename in this
1154
+ # precedence order. The exclusion of layout.test.tsx, layout.spec.tsx, layout.d.ts,
1155
+ # layout.css and layout.module.css is structural - they are different basenames, the
1156
+ # candidate list simply does not contain them, no suffix blacklist is involved - so a
1157
+ # stylesheet or a test sitting beside a layout is never compared and a directory whose
1158
+ # only layout.* files are such siblings is reported as NO LAYOUT, not as an import
1159
+ # mismatch. Deterministic when two code layouts sit side by side (tsx wins over js).
1160
+ _pv01_layout_in() {
1161
+ local f
1162
+ for f in layout.tsx layout.ts layout.jsx layout.js layout.mts layout.mjs layout.cts layout.cjs; do
1163
+ if [ -f "$1/$f" ]; then
1164
+ printf '%s\n' "$1/$f"
1165
+ return 0
1166
+ fi
1167
+ done
1168
+ return 1
1169
+ }
1170
+
1171
+ check_pv_01() {
1172
+ # P1 (CURATION-2026-11-25): a surface that exists to be reviewed renders the same shell
1173
+ # the published route renders. A candidate review surface is a directory in a route tree
1174
+ # whose name matches preview|previewed|draft|staging; its layout must import at least one
1175
+ # PROJECT-RESOLVABLE module the public layout at the equivalent position (the same route
1176
+ # tree without that segment, or the nearest code layout above it — chosen by exact
1177
+ # basename, see _pv01_layout_in) also imports — unless the
1178
+ # file carries `preview_differs: <list>` declaring the difference. The intersection is
1179
+ # over CANONICAL KEYS — ROOT-relative module paths, extension and trailing /index
1180
+ # stripped — so both layouts may name the same module relative or through a resolvable
1181
+ # alias (tsconfig.json/jsconfig.json baseUrl+paths first, then <ROOT>/<spec> with
1182
+ # extension and index probing) and still intersect; a relative specifier that climbs
1183
+ # out of the project root names a module outside the repo and is dropped like any
1184
+ # unresolvable specifier — an installed package or a builtin is
1185
+ # never evidence of a shared shell, and a specifier that resolves nowhere is dropped and
1186
+ # named in the RED message. Neither is a style/asset import or a side-effect import: the
1187
+ # shared stylesheet is the THEME the two surfaces agree on, not the SHELL one renders
1188
+ # (the bug that motivated this paragraph passed PV-01 on a preview layout whose only
1189
+ # project imports were globals.css and a banner), and `import '<x>'` wires a module
1190
+ # without naming what renders — the intersection counts project CODE modules only
1191
+ # (_pv01_resolve_spec classes them A and they never count; when a surface shares ONLY
1192
+ # those, the RED message says exactly that). When NO ancestor layout exists inside the route tree, the
1193
+ # public layout is searched among SIBLING route groups of the same tree: every depth-1
1194
+ # entry under the tree that is not on the surface's own path and does not itself look
1195
+ # like a review surface — a grouped sibling contributes EVERY code layout under it, a plain
1196
+ # sibling its depth-1 layout only. This is the shape that produced the rule (the public
1197
+ # shell in `app/(frontend)/[locale]/layout.tsx`, the review surface in
1198
+ # `app/(preview)/preview/layout.tsx`, nothing above it): the ancestor-only walk found no
1199
+ # public layout, printed `not judged` and still returned PASS — a green that judged
1200
+ # nothing. The fallback compares the surface against EACH candidate and passes if ANY
1201
+ # candidate shares at least one project-resolvable module, naming the group and the
1202
+ # shared modules (max 3, then +N more); when candidates exist but none shares a module
1203
+ # the row is RED, naming the candidates tried and the specifiers dropped as
1204
+ # unresolvable. Honest limit (LIMITS #61): an import proves reachability,
1205
+ # never an identical render — a shell imported and then overridden by a local wrapper
1206
+ # passes; the sibling fallback passes if ANY sibling group matches, so a group that
1207
+ # shares only a trivial util clears the surface too; and an unresolvable alias or a
1208
+ # runtime-built specifier is a false RED the
1209
+ # preview_differs: hatch exists to clear. The from-clause keyword scan masks quoted runs
1210
+ # in the segment it inspects, so a specifier-shaped string literal no longer vouches for
1211
+ # an in-string ` from '<spec>'`; the mask is text, not a lexer — an escaped quote or a JSX
1212
+ # apostrophe breaks it toward a false RED, never a false GREEN.
1213
+ local tree d b surf up pub sameshell=0 bad=0 n=0 declared=0 inherited=0 unjudged=0 shared
1214
+ local s_out p_out surf_dropped pub_dropped
1215
+ local trees sibshell=0 cands ent name rel first_seg label cand
1216
+ local sib_ok cand_names cand_dropped sn sdisp sd all_dropped s_a cand_a
1217
+ _pv01_tsconfig_load
1218
+ trees=$(_pv_route_trees)
1219
+ if [ -z "$trees" ]; then
1220
+ printf 'no route tree (no app/, src/app/, pages/ or routes/)\n'
765
1221
  return 3
766
1222
  fi
767
- for f in "$d"/*; do
768
- [ -f "$f" ] || continue
769
- n=$((n + 1))
770
- rel="${f#"$ROOT"/}"
771
- # the marker clears every clause in the file: it names the reason the guard lives elsewhere
772
- grep -Eq 'guarded:[[:space:]]*[^[:space:]]' "$f" && continue
773
- if grep -q 'getBoundingClientRect(' "$f"; then
774
- if grep -Eq 'innerWidth|innerHeight|visualViewport' "$f"; then
775
- nb=$((nb + 1))
776
- else
777
- printf '%s measures a bounding box (getBoundingClientRect) with no viewport guard (innerWidth/innerHeight/visualViewport) and no guarded: marker\n' "$rel"
778
- bad=1
1223
+ while IFS= read -r tree; do
1224
+ [ -n "$tree" ] || continue
1225
+ while IFS= read -r d; do
1226
+ [ -n "$d" ] || continue
1227
+ b="${d##*/}"
1228
+ printf '%s\n' "$b" | grep -Eqi 'preview|previewed|draft|staging' || continue
1229
+ surf=$(_pv01_layout_in "$d")
1230
+ if [ -z "$surf" ]; then
1231
+ if [ -n "$(ls "$d"/layout.* 2>/dev/null)" ]; then
1232
+ # layout-shaped files exist but none is an exact code basename: report the
1233
+ # truth - there is no route layout here - instead of comparing a stylesheet
1234
+ bad=1; n=$((n + 1))
1235
+ printf 'no layout file was found in %s - the layout.* files there are not route layouts, nothing to compare against the published shell\n' "${d#"$ROOT"/}"
1236
+ continue
1237
+ fi
1238
+ # no layout of its own: it inherits the public layout, nothing to compare
1239
+ inherited=$((inherited + 1)); n=$((n + 1)); continue
779
1240
  fi
780
- fi
781
- if grep -Eq 'execSync|execFileSync|spawnSync|child_process' "$f" \
782
- && grep -Eq 'parseFloat|parseInt|Number[[:space:]]*\(' "$f"; then
783
- if grep -Eq 'Number[.]isFinite|isNaN|isFinite' "$f"; then
784
- np=$((np + 1))
785
- else
786
- printf '%s parses a number out of another process stdout with no finite guard (Number.isFinite/isNaN) and no guarded: marker\n' "$rel"
1241
+ n=$((n + 1))
1242
+ if grep -Eq 'preview_differs:[[:space:]]*[^[:space:]]' "$surf"; then
1243
+ declared=$((declared + 1)); continue
1244
+ fi
1245
+ # the public layout at the equivalent position, then the nearest layout.* above
1246
+ up="${d%/*}"
1247
+ pub=""
1248
+ while :; do
1249
+ pub=$(_pv01_layout_in "$up")
1250
+ [ -n "$pub" ] && break
1251
+ case "$up" in
1252
+ "$tree") break ;;
1253
+ "$tree"/*) up="${up%/*}" ;;
1254
+ *) break ;;
1255
+ esac
1256
+ done
1257
+ if [ -z "$pub" ]; then
1258
+ # No ancestor layout inside the route tree: fall back to the layouts of SIBLING
1259
+ # route groups of the same tree (see the header comment). Candidates are the
1260
+ # depth-1 entries under the tree except the surface's own depth-1 ancestor and
1261
+ # any entry that itself looks like a review surface — a sibling review surface is
1262
+ # not published furniture, and comparing two surfaces proves nothing.
1263
+ s_out=$(_pv01_imports_of "$surf" | while IFS= read -r s; do _pv01_resolve_spec "${surf%/*}" "$s"; done)
1264
+ rel="${d#"$tree"/}"
1265
+ first_seg="${rel%%/*}"
1266
+ cands=""
1267
+ for ent in "$tree"/*; do
1268
+ [ -d "$ent" ] || continue
1269
+ name="${ent##*/}"
1270
+ case "$name" in
1271
+ .*|node_modules|.next|dist) continue ;;
1272
+ esac
1273
+ [ "$name" = "$first_seg" ] && continue
1274
+ printf '%s' "$name" | grep -Eqi 'preview|previewed|draft|staging' && continue
1275
+ case "$name" in
1276
+ \(*)
1277
+ # a grouped sibling: every code layout in its subtree is a candidate,
1278
+ # chosen by exact basename (_pv01_layout_in) so stylesheets and tests
1279
+ # under the group are never candidates
1280
+ while IFS= read -r sdir; do
1281
+ cand=$(_pv01_layout_in "$sdir")
1282
+ [ -n "$cand" ] || continue
1283
+ cands="$cands$name"$'\t'"$cand"$'\n'
1284
+ done < <(_pv_find "$ent" -type d)
1285
+ ;;
1286
+ *)
1287
+ # a plain sibling: its depth-1 code layout only
1288
+ cand=$(_pv01_layout_in "$ent")
1289
+ [ -n "$cand" ] && cands="$cands$name"$'\t'"$cand"$'\n'
1290
+ ;;
1291
+ esac
1292
+ done
1293
+ if [ -z "$cands" ]; then
1294
+ unjudged=$((unjudged + 1))
1295
+ printf 'note: %s has no public layout above it and no sibling route group layout to fall back to - not judged\n' "${surf#"$ROOT"/}"
1296
+ continue
1297
+ fi
1298
+ sib_ok=0
1299
+ cand_names=""
1300
+ cand_dropped=""
1301
+ s_a=$(printf '%s\n' "$s_out" | awk -F'\t' '$1=="A"{print $2}' | sort -u)
1302
+ cand_a=""
1303
+ while IFS=$'\t' read -r label cand; do
1304
+ [ -n "$cand" ] || continue
1305
+ cand_names="$cand_names ${cand#"$ROOT"/}"
1306
+ p_out=$(_pv01_imports_of "$cand" | while IFS= read -r s; do _pv01_resolve_spec "${cand%/*}" "$s"; done)
1307
+ cand_dropped="$cand_dropped$(printf '%s\n' "$p_out" | awk -F'\t' '$1=="D"{printf "%s ", $2}')"
1308
+ cand_a="$cand_a$(printf '%s\n' "$p_out" | awk -F'\t' '$1=="A"{print $2}' | sort -u)"
1309
+ shared=$(comm -12 \
1310
+ <(printf '%s\n' "$s_out" | awk -F'\t' '$1=="K"{print $2}' | sort -u) \
1311
+ <(printf '%s\n' "$p_out" | awk -F'\t' '$1=="K"{print $2}' | sort -u))
1312
+ if [ -n "$shared" ]; then
1313
+ sib_ok=1
1314
+ sn=$(printf '%s\n' "$shared" | grep -c .)
1315
+ sdisp=$(printf '%s\n' "$shared" | head -3 | paste -sd ',' - | sed 's/,/, /g')
1316
+ [ "$sn" -gt 3 ] && sdisp="$sdisp (+$((sn - 3)) more)"
1317
+ sibshell=$((sibshell + 1))
1318
+ # two lines: a single-line PASS payload truncates at the report width under
1319
+ # --only (GOB_VERIFY_VERBOSE=1), which would cut the shared-module list off;
1320
+ # a multi-line PASS payload prints whole (g_pass)
1321
+ printf 'note: %s renders the published shell of group %s\n' \
1322
+ "${surf#"$ROOT"/}" "$label"
1323
+ printf ' shares %s\n' "$sdisp"
1324
+ break
1325
+ fi
1326
+ done <<< "$cands"
1327
+ if [ "$sib_ok" -eq 0 ]; then
1328
+ bad=1
1329
+ printf "%s imports no module any sibling route group's public layout imports and carries no preview_differs: marker - it does not render any published shell (tried:%s)\n" \
1330
+ "${surf#"$ROOT"/}" "$cand_names"
1331
+ _pv01_asset_note "${surf#"$ROOT"/}" "$s_a" "$cand_a"
1332
+ sd=$(printf '%s\n' "$s_out" | awk -F'\t' '$1=="D"{printf "%s ", $2}')
1333
+ all_dropped=$(printf '%s%s' "$sd" "$cand_dropped" | tr ' ' '\n' | awk '!seen[$0]++ && $0 != "" {printf "%s ", $0}')
1334
+ if [ -n "$all_dropped" ]; then
1335
+ printf 'note: specifier(s) dropped as unresolvable (not counted as shared evidence): %s\n' "$all_dropped"
1336
+ fi
1337
+ fi
1338
+ continue
1339
+ fi
1340
+ s_out=$(_pv01_imports_of "$surf" | while IFS= read -r s; do _pv01_resolve_spec "${surf%/*}" "$s"; done)
1341
+ p_out=$(_pv01_imports_of "$pub" | while IFS= read -r s; do _pv01_resolve_spec "${pub%/*}" "$s"; done)
1342
+ surf_dropped=$(printf '%s\n' "$s_out" | awk -F'\t' '$1=="D"{printf "%s ", $2}')
1343
+ pub_dropped=$(printf '%s\n' "$p_out" | awk -F'\t' '$1=="D"{printf "%s ", $2}')
1344
+ shared=$(comm -12 \
1345
+ <(printf '%s\n' "$s_out" | awk -F'\t' '$1=="K"{print $2}' | sort -u) \
1346
+ <(printf '%s\n' "$p_out" | awk -F'\t' '$1=="K"{print $2}' | sort -u))
1347
+ if [ -z "$shared" ]; then
1348
+ printf '%s imports no module the public layout %s imports and carries no preview_differs: marker - it does not render the published shell\n' \
1349
+ "${surf#"$ROOT"/}" "${pub#"$ROOT"/}"
1350
+ _pv01_asset_note "${surf#"$ROOT"/}" \
1351
+ "$(printf '%s\n' "$s_out" | awk -F'\t' '$1=="A"{print $2}' | sort -u)" \
1352
+ "$(printf '%s\n' "$p_out" | awk -F'\t' '$1=="A"{print $2}' | sort -u)"
1353
+ if [ -n "$surf_dropped" ] || [ -n "$pub_dropped" ]; then
1354
+ printf 'note: %s specifier(s) of those layouts did not resolve inside the project (an installed package, a builtin or an unresolvable alias) and were NOT counted as shared evidence - an alias the bundler resolves but this text probe cannot is a known false RED here; declare the surface with preview_differs: <list> to clear it\n' \
1355
+ "$(printf '%s %s' "$surf_dropped" "$pub_dropped" | wc -w | tr -d ' ')"
1356
+ fi
787
1357
  bad=1
1358
+ else
1359
+ sameshell=$((sameshell + 1))
1360
+ sn=$(printf '%s\n' "$shared" | grep -c .)
1361
+ sdisp=$(printf '%s\n' "$shared" | head -3 | paste -sd ',' - | sed 's/,/, /g')
1362
+ [ "$((sn - 3))" -gt 0 ] && sdisp="$sdisp (+$((sn - 3)) more)"
1363
+ # two lines: a single-line PASS payload folds at the report width and would cut
1364
+ # the module list off; each line prints whole - the sibling branch has written its
1365
+ # note as its own line since PV-01 landed
1366
+ printf 'note: %s renders the published shell of %s\n' \
1367
+ "${surf#"$ROOT"/}" "${pub#"$ROOT"/}"
1368
+ printf ' shares %s\n' "$sdisp"
788
1369
  fi
789
- fi
790
- done
1370
+ done < <(_pv_find "$tree" -type d)
1371
+ done <<PV
1372
+ $trees
1373
+ PV
1374
+ if [ "$n" -eq 0 ]; then
1375
+ printf 'no candidate review surface directory (no dir named *preview*/draft*/staging* under the route tree)\n'
1376
+ return 3
1377
+ fi
791
1378
  [ "$bad" -eq 0 ] || return 1
792
- printf '%d harness file(s); %d guarded bounding-box measurement(s), %d guarded parsed-number measurement(s)\n' \
793
- "$n" "$nb" "$np"
1379
+ printf "%d review surface(s): %d share the published shell, %d via a sibling group's shell, %d declared via preview_differs:, %d inherit the public layout, %d not judged (no public layout above and no sibling layout)\n" \
1380
+ "$n" "$sameshell" "$sibshell" "$declared" "$inherited" "$unjudged"
794
1381
  return 0
795
1382
  }
796
1383
 
@@ -866,7 +1453,7 @@ check_hv_01() {
866
1453
  # beside a hand-written doc/board/payload/fixture literal - never that the call path matches
867
1454
  # the product wiring. The stronger form needs the product to export a single factory, which is
868
1455
  # a design change, not a probe (the why cell and docs/LIMITS.md say so).
869
- local d="$GOBLIN_HARNESS_DIR" f rel bad=0 n=0 nk=0
1456
+ local d="$GOBLIN_HARNESS_DIR" f rel bad=0 n=0 nk=0 js=0
870
1457
  if [ -z "$d" ]; then
871
1458
  if [ "$GOBLIN_HARNESS_STATE" = "absent" ]; then
872
1459
  printf 'harness_dir %s is declared and scaffold_checks is yes, but the directory is absent\n' \
@@ -879,6 +1466,14 @@ check_hv_01() {
879
1466
  fi
880
1467
  for f in "$d"/*; do
881
1468
  [ -f "$f" ] || continue
1469
+ # OCA: the probe reads import/require syntax it cannot see in other languages. A non-JS
1470
+ # harness file is not examined (it used to be false-REDed on a doc literal alone); a dir
1471
+ # with no JS-family harness at all is a zero-inspection SKIP, not a vacuous PASS.
1472
+ case "$f" in
1473
+ *.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.vue|*.svelte) ;;
1474
+ *) continue ;;
1475
+ esac
1476
+ js=$((js + 1))
882
1477
  n=$((n + 1))
883
1478
  rel="${f#"$ROOT"/}"
884
1479
  # a document/board/payload/fixture literal: an object, array or JSON string assigned to a
@@ -897,12 +1492,55 @@ check_hv_01() {
897
1492
  printf '%s constructs a doc/board/payload/fixture literal with no package import and no produced_by: marker - the input the check asserts is not the input the user gets\n' "$rel"
898
1493
  bad=1
899
1494
  done
1495
+ if [ "$js" -eq 0 ]; then
1496
+ printf 'no JS-family harness file in %s - the text probe reads import/require syntax it cannot see in other languages\n' "$GOBLIN_HARNESS_REL"
1497
+ return 3
1498
+ fi
900
1499
  [ "$bad" -eq 0 ] || return 1
901
1500
  printf '%d harness file(s); %d constructed input(s), each through a package import or a produced_by marker\n' \
902
1501
  "$n" "$nk"
903
1502
  return 0
904
1503
  }
905
1504
 
1505
+ check_ag_01() {
1506
+ # C6 / AG-01: the gate file itself changes only with a recorded approval. GT-01/GT-02 read
1507
+ # the gates out of AGENTS.md, so the file that decides what "green" means must not be
1508
+ # silently editable by the worker the gate polices. The record is .gob/agents.approved,
1509
+ # append-only, one row per approval: date <TAB> sha256 <TAB> approver <TAB> reason — the
1510
+ # LAST row wins, and only the HASH is coverage: a row carries no file name, so a reason
1511
+ # mentioning some other file clears nothing (the control in tests/t-verify-red.sh pins
1512
+ # that). No record at all is a SKIP, never a red: an existing install must not turn red
1513
+ # just by upgrading to an engine that ships this row. What this cannot see (the hash is a
1514
+ # witness, not a signature — a worker able to write both files forges a record) is
1515
+ # docs/LIMITS.md #60.
1516
+ local rec="$ROOT/.gob/agents.approved" agents="$ROOT/AGENTS.md"
1517
+ if [ ! -s "$rec" ] || ! grep -q . "$rec" 2>/dev/null; then
1518
+ printf 'no approval record; run gob approve-agents "<reason>"\n'
1519
+ return 3
1520
+ fi
1521
+ local row rdate rsha rapp
1522
+ row=$(grep . "$rec" | tail -n 1)
1523
+ rdate=$(printf '%s' "$row" | awk -F'\t' '{print $1}')
1524
+ rsha=$(printf '%s' "$row" | awk -F'\t' '{print $2}')
1525
+ rapp=$(printf '%s' "$row" | awk -F'\t' '{print $3}')
1526
+ if [ -z "$rsha" ]; then
1527
+ printf 'no approval record; run gob approve-agents "<reason>"\n'
1528
+ return 3
1529
+ fi
1530
+ local actual
1531
+ actual=$(g_sha256_file "$agents")
1532
+ if [ "$actual" = "$rsha" ]; then
1533
+ printf 'AGENTS.md matches the approval recorded %s by %s\n' "$rdate" "$rapp"
1534
+ return 0
1535
+ fi
1536
+ printf 'AGENTS.md changed with no recorded approval\n'
1537
+ printf ' file AGENTS.md\n'
1538
+ printf ' recorded %s (approved %s by %s)\n' "$rsha" "$rdate" "$rapp"
1539
+ printf ' actual %s\n' "$actual"
1540
+ printf ' fix: after a human reads the diff — gob approve-agents "<one-line reason>"\n'
1541
+ return 1
1542
+ }
1543
+
906
1544
  check_gt_01() {
907
1545
  # Every `- name:` under `gates:` is a DECLARED gate, and every declared gate must carry a
908
1546
  # `cmd:`. Counting only the name+cmd PAIRS (what this row did) let a gate lose its `cmd:` -
@@ -1046,6 +1684,7 @@ check_hs_01() {
1046
1684
 
1047
1685
  check_hs_02() {
1048
1686
  local env cmd commit d tmp bad=0 f rc base name qname pat
1687
+ local replayed=0 excluded=0 excluded_exts="" tail_note=""
1049
1688
  env=$(g_agents_read "$CONFIG" replay.env)
1050
1689
  cmd=$(g_agents_read "$CONFIG" replay.cmd)
1051
1690
  commit=$(g_unquote "$(g_agents_read "$CONFIG" replay.commit)")
@@ -1087,10 +1726,22 @@ check_hs_02() {
1087
1726
  fi
1088
1727
  mkdir -p "$tmp/wt/$GOBLIN_HARNESS_REL"
1089
1728
  cp -a "$d/." "$tmp/wt/$GOBLIN_HARNESS_REL/"
1090
- for f in "$tmp/wt/$GOBLIN_HARNESS_REL"/*.mjs; do
1091
- [ -e "$f" ] || continue
1729
+ replayed=0 excluded=0 excluded_exts=""
1730
+ for f in "$tmp/wt/$GOBLIN_HARNESS_REL"/*; do
1731
+ [ -f "$f" ] || continue
1092
1732
  base=$(basename "$f")
1093
- name=${base%.mjs}
1733
+ case "$base" in
1734
+ *.mjs) name=${base%.mjs} ;;
1735
+ *)
1736
+ # OCA: a harness the replay set does not run is NAMED, never silently outside it.
1737
+ excluded=$((excluded + 1))
1738
+ case " $excluded_exts " in
1739
+ *" .${base##*.} "*) ;;
1740
+ *) excluded_exts="$excluded_exts .${base##*.}" ;;
1741
+ esac
1742
+ continue ;;
1743
+ esac
1744
+ replayed=$((replayed + 1))
1094
1745
  # Z2-3: the name is SHELL-QUOTED before it is substituted, because it now reaches a shell.
1095
1746
  # This row runs the DECLARED command rather than `node "$f"` (Z1-4), so a file in the harness
1096
1747
  # dir - a name the row does not control - is part of the command text `bash -c` parses.
@@ -1114,7 +1765,24 @@ check_hs_02() {
1114
1765
  done
1115
1766
  git -C "$ROOT" worktree remove --force "$tmp/wt" >/dev/null 2>&1
1116
1767
  rm -rf "$tmp"
1117
- [ "$bad" -eq 0 ] && printf 'every harness was RED at %s (run as: %s)\n' "${commit:0:7}" "$cmd"
1768
+ # OCA: zero harnesses replayed proves nothing about the pre-change tree - SKIP naming the
1769
+ # dir, and (when the dir held files the replay set does not run) the excluded extensions.
1770
+ if [ "$replayed" -eq 0 ]; then
1771
+ if [ "$excluded" -gt 0 ]; then
1772
+ printf 'no harness in %s matched the replay set - %d file(s) present with extension(s)%s, which the replay set (*.mjs) does not run\n' \
1773
+ "$GOBLIN_HARNESS_REL" "$excluded" "${excluded_exts# }"
1774
+ else
1775
+ printf 'no harness in %s matched the replay set\n' "$GOBLIN_HARNESS_REL"
1776
+ fi
1777
+ return 3
1778
+ fi
1779
+ # OCA: the RED-proof line says how many harnesses carried it, and what the replay set did
1780
+ # and did not run - so a PASS can never silently shrink its own coverage.
1781
+ tail_note=""
1782
+ [ "$excluded" -gt 0 ] \
1783
+ && tail_note=$(printf '; not replayed:%s (%d file(s), the replay set runs *.mjs)' "${excluded_exts# }" "$excluded")
1784
+ [ "$bad" -eq 0 ] && printf 'every harness was RED at %s (replayed %d: .mjs; run as: %s)%s\n' \
1785
+ "${commit:0:7}" "$replayed" "$cmd" "$tail_note"
1118
1786
  return $bad
1119
1787
  }
1120
1788
 
@@ -1240,6 +1908,26 @@ check_ds_02() {
1240
1908
  return 0
1241
1909
  }
1242
1910
 
1911
+ # The JS-family source set sc_sources greps, as a FILE count. The include/exclude list is
1912
+ # duplicated on purpose: find counts the files the grep would read, which is the "examined"
1913
+ # denominator the zero-inspection gates (SC-03, SC-04) skip on — a repo where this is 0 is a
1914
+ # repo the row saw nothing of. The declared harness directory (AGENTS.md harness_dir:, the
1915
+ # installer's default checks/) is excluded: a harness file is scaffold the kit itself wrote,
1916
+ # not application source, and counting it let a repo whose ONLY JS-family file was the kit's
1917
+ # own checks/assert.mjs answer SC-03 with a green "0 ... name(s)" over zero application
1918
+ # source — the same grade-the-scaffold pathology the audit accused HV-02 of.
1919
+ js_source_count() {
1920
+ local hd="${GOBLIN_HARNESS_REL#./}"
1921
+ hd="${hd%/}"
1922
+ ( cd "$ROOT" && find . -type f \
1923
+ \( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \
1924
+ -o -name '*.mjs' -o -name '*.cjs' -o -name '*.vue' -o -name '*.svelte' \) \
1925
+ -not -path './.next/*' -not -path './node_modules/*' -not -path './.gob/*' \
1926
+ -not -path './.hermes/*' -not -path './dist/*' -not -path './build/*' \
1927
+ -not -path './out/*' -not -path './coverage/*' \
1928
+ ${hd:+-not -path "./$hd/*"} 2>/dev/null | grep -c . )
1929
+ }
1930
+
1243
1931
  check_sc_02() {
1244
1932
  # Clause 1 is a file rule; clause 2 is BEHAVIOURAL - it asks git's own matcher, so an ignore
1245
1933
  # rule that looks right but does not match still fails. `git check-ignore -q` accepts exactly
@@ -1270,7 +1958,7 @@ check_sc_03() {
1270
1958
  # Clause 1: a client-visible NAME that is secret-shaped. Clause 2: a known secret PREFIX in
1271
1959
  # real build output. The second clause is reported, never silently skipped: a repo with no
1272
1960
  # build output is told so on the line.
1273
- local hits hits_all hits_n vs_keys vs_files out n=0 bad=0
1961
+ local hits hits_all hits_n vs_keys vs_files out n=0 bad=0 src_n=0
1274
1962
  hits_all=$(sc_sources 'NEXT_PUBLIC_[A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|PASSWD|PRIVATE)')
1275
1963
  # W5-11: this line printed a CHARACTER count as a hit count - `${#hits}` on a multiline
1276
1964
  # string - so ONE matching line of 70 characters was reported as "70 client-visible
@@ -1292,6 +1980,14 @@ check_sc_03() {
1292
1980
  grep -qE '(sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|AKIA[A-Z0-9]{16}|eyJ[A-Za-z0-9_-]{20,}\.)' "$f" 2>/dev/null \
1293
1981
  && { printf 'a secret-shaped literal is in build output: %s\n' "${f#"$ROOT"/}"; bad=1; }
1294
1982
  done
1983
+ # OCA: the files this row examined are the JS-family source set (js_source_count) plus
1984
+ # whatever clause 2 found. Zero of both means the row inspected nothing - SKIP with the
1985
+ # reason naming what it could not see, never a vacuous green "0 ... name(s)".
1986
+ src_n=$(js_source_count)
1987
+ if [ "$src_n" -eq 0 ] && [ "$n" -eq 0 ]; then
1988
+ printf 'no file in the JS-family set and no declared build output to scan\n'
1989
+ return 3
1990
+ fi
1295
1991
  if [ "$n" -eq 0 ]; then
1296
1992
  printf '%d client-visible secret-shaped name(s); no build output to scan for clause 2\n' "$hits_n"
1297
1993
  else
@@ -1304,7 +2000,8 @@ check_sc_04() {
1304
2000
  # A JS-written cookie needs `secure` + `samesite` in the SAME statement; a server-side set
1305
2001
  # needs `httpOnly` + `sameSite`. Same-statement only: a write spread over three lines is not
1306
2002
  # seen, and the row says so rather than implying it read the statement.
1307
- local js srv bad=0 n=0 line
2003
+ local js srv bad=0 n=0 line files=0
2004
+ files=$(js_source_count)
1308
2005
  js=$(sc_sources 'document\.cookie[[:space:]]*=')
1309
2006
  srv=$(sc_sources '(cookies\(\)\.set\(|res\.cookie\(|NextResponse\.cookie\()')
1310
2007
  if [ -n "$js" ]; then
@@ -1325,6 +2022,13 @@ EOF
1325
2022
  $srv
1326
2023
  EOF
1327
2024
  fi
2025
+ # OCA: zero cookie writes examined proves nothing about cookies. SKIP with the examined
2026
+ # count - a Python web repo (`response.set_cookie`) is not in the JS-family set, so 0 is
2027
+ # exactly what it gets, instead of the old vacuous PASS.
2028
+ if [ "$n" -eq 0 ]; then
2029
+ printf 'no cookie write found in %d examined file(s)\n' "$files"
2030
+ return 3
2031
+ fi
1328
2032
  printf '%d cookie write(s) checked; a JS-written cookie is readable by any script - reported, not failed\n' "$n"
1329
2033
  [ "$bad" -eq 0 ]
1330
2034
  }
@@ -1334,6 +2038,14 @@ check_sc_05() {
1334
2038
  # or be named in .gob/boundary-waivers. Partial by design: it proves a validator is called,
1335
2039
  # not that the schema is right.
1336
2040
  local d f rel n=0 bad=0 w=0
2041
+ # OCA: an undeclared security.write_routes is a route surface the row cannot see - SKIP
2042
+ # with that reason, per the contract "a declared key that is absent is a skip with a
2043
+ # reason, never a silent pass" (the engine's own contract note). Declared but unmatched
2044
+ # gets the same treatment below: a handler count of 0 examined nothing.
2045
+ if [ -z "$SEC_WRITE_ROUTES" ]; then
2046
+ printf 'security.write_routes is not declared - there is no route surface to check\n'
2047
+ return 3
2048
+ fi
1337
2049
  for d in $SEC_WRITE_ROUTES; do
1338
2050
  [ -d "$ROOT/$d" ] || continue
1339
2051
  while IFS= read -r f; do
@@ -1350,6 +2062,12 @@ check_sc_05() {
1350
2062
  $(find "$ROOT/$d" -type f \( -name 'route.ts' -o -name 'route.js' -o -name 'route.tsx' \) 2>/dev/null)
1351
2063
  EOF
1352
2064
  done
2065
+ # OCA: declared but zero handlers matched is still zero inspection - SKIP naming the
2066
+ # declaration and the 0 matches, never "0 write handler(s)" green.
2067
+ if [ "$n" -eq 0 ]; then
2068
+ printf 'security.write_routes is declared (%s) and no write handler matched it\n' "$SEC_WRITE_ROUTES"
2069
+ return 3
2070
+ fi
1353
2071
  printf '%d write handler(s), %d waived; %d dir(s) declared\n' "$n" "$w" "${#SEC_WRITE_ROUTES}"
1354
2072
  [ "$bad" -eq 0 ]
1355
2073
  }
@@ -1454,13 +2172,6 @@ check_bn_01() { check_bn_run BN-01; }
1454
2172
  check_bn_02() { check_bn_run BN-02; }
1455
2173
  check_bn_03() { check_bn_run BN-03; }
1456
2174
  check_bn_05() { check_bn_run BN-05; }
1457
- # G6 section B.2: the Electron failure surface, as bans. Same engine, same exit contract, same
1458
- # SKIP-when-unlisted behaviour - the mechanism is G5's, only the patterns are new.
1459
- check_bn_06() { check_bn_run BN-06; }
1460
- check_bn_07() { check_bn_run BN-07; }
1461
- check_bn_08() { check_bn_run BN-08; }
1462
- check_bn_09() { check_bn_run BN-09; }
1463
-
1464
2175
  check_pf_01() {
1465
2176
  # The perf NUMBER lives in `ratchet:` (GT-04/GT-05 unchanged). This row is the other half: the
1466
2177
  # baseline must name the commit it was measured on, so raising the ceiling cannot silently
@@ -2174,7 +2885,22 @@ setup_local_override() {
2174
2885
  }
2175
2886
  setup_local_override
2176
2887
 
2177
- PASS=0; FAIL=0; ADV=0; SKIP=0; BAD=0
2888
+ # --only may drive a LIBRARY row directly: probe one shipped row without turning it on
2889
+ # repo-wide. Append the row's matrix line to the run set for this run only; an id the run
2890
+ # set already carries (the matrix or the local override) is left alone, never duplicated.
2891
+ if [ -n "$ONLY" ] && [ -n "$LIBRARY_FILE" ]; then
2892
+ _only_tmp=$(mktemp "${TMPDIR:-/tmp}/gob-only.XXXXXX")
2893
+ cp "$RUN_MANIFEST" "$_only_tmp"
2894
+ for _want in $(printf '%s' "$ONLY" | tr ',' ' '); do
2895
+ [ -n "$_want" ] || continue
2896
+ awk -F'\t' -v x="$_want" '$1==x {f=1} END{exit !f}' "$RUN_MANIFEST" && continue
2897
+ awk -F'\t' -v x="$_want" 'NR>1 && $1==x {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7}' \
2898
+ "$LIBRARY_FILE" >> "$_only_tmp"
2899
+ done
2900
+ RUN_MANIFEST="$_only_tmp"
2901
+ fi
2902
+
2903
+ PASS=0; FAIL=0; ADV=0; SKIP=0; BAD=0; AG01_SKIP=0
2178
2904
  JSON_ROWS=""
2179
2905
 
2180
2906
  # json_escape <text> — a JSON string body. The detail of a check is arbitrary shell output
@@ -2224,6 +2950,16 @@ while IFS=$'\t' read -r id scope rule enforced_by artifact check why; do
2224
2950
  emit "$id" ADV "$rule (advisory)"
2225
2951
  continue
2226
2952
  ;;
2953
+ *" read by a human")
2954
+ # GT-06/EX-01 (the 2026-11-27 lessons): an advisory row may name its reader in the
2955
+ # check column instead of a command. Executing that prose as a shell command exits
2956
+ # 127 - a false RED on a row whose enforced_by is advisory - so it carries the same
2957
+ # verdict as the literal advisory above. A wire control still reaches it: the wire
2958
+ # replaces the WHOLE check with a failing command, which matches neither branch.
2959
+ ADV=$((ADV + 1))
2960
+ emit "$id" ADV "$rule (advisory)"
2961
+ continue
2962
+ ;;
2227
2963
  goblin-verify\ --only\ *)
2228
2964
  fn="check_$(printf '%s' "$id" | tr 'A-Z' 'a-z' | tr '-' '_')"
2229
2965
  if ! command -v "$fn" >/dev/null 2>&1 && ! declare -F "$fn" >/dev/null 2>&1; then
@@ -2267,6 +3003,11 @@ while IFS=$'\t' read -r id scope rule enforced_by artifact check why; do
2267
3003
  3) SKIP=$((SKIP + 1)); emit "$id" SKIP "$detail" ;;
2268
3004
  *) FAIL=$((FAIL + 1)); emit "$id" FAIL "$detail (exit $rc)" ;;
2269
3005
  esac
3006
+ # AG-01's no-record skip is the one skip a CALLER must tell apart from green: `--only AG-01`
3007
+ # on a repo with no approval record exits 3 (the card's contract; goblin-bans has the same
3008
+ # single-selection rule). Scoped to AG-01 deliberately: every other row's skip stays exit 0,
3009
+ # a shape the existing controls pin (HP-06's "no HANDOFF.md is a SKIP, never red").
3010
+ if [ "$id" = "AG-01" ] && [ "$rc" -eq 3 ]; then AG01_SKIP=1; fi
2270
3011
  done < "$RUN_MANIFEST"
2271
3012
 
2272
3013
  # ---- the honesty gate, run-time half: a local check that produced no verdict ----------------
@@ -2404,4 +3145,8 @@ SEE
2404
3145
  fi
2405
3146
 
2406
3147
  if [ "$FAIL" -gt 0 ] || [ "$BAD" -eq 1 ]; then exit 1; fi
3148
+ # The adoption skip, surfaced: AG-01 skipped and nothing else ran (the `--only AG-01` shape)
3149
+ # is exit 3 — "not policed yet", distinguishable from a green 0 by a script running the gate.
3150
+ # A full run that skips AG-01 still exits 0 (a default install verifies green).
3151
+ if [ "$AG01_SKIP" -eq 1 ] && [ "$PASS" -eq 0 ] && [ "$FAIL" -eq 0 ]; then exit 3; fi
2407
3152
  exit 0