@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.
@@ -28,7 +28,7 @@
28
28
 
29
29
  set -uo pipefail
30
30
 
31
- GOBLIN_INSTALL_VERSION="0.6.0"
31
+ GOBLIN_INSTALL_VERSION="0.7.3"
32
32
  SELF_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
33
33
  SRC=$(cd "$SELF_DIR/.." && pwd)
34
34
  # shellcheck source=goblin-lib.sh
@@ -447,7 +447,7 @@ ADV_CEILING=$(default_ advisory_ceiling); [ -n "$ADV_CEILING" ] || ADV_CEILING=1
447
447
  # The optional second gate (the TODO ceiling); blank it to render one gate only.
448
448
  GATE2_NAME=$(default_ gate2_name)
449
449
  GATE2_CMD=$(default_ gate2_cmd)
450
- # The security surface (SC-01..SC-09) and the perf baseline (PF-01).
450
+ # The security surface (SC-01..SC-08 enforcement; SC-09 is a library advisory) and the perf baseline (PF-01).
451
451
  SEC_GITIGNORE_FAMILY=$(default_ sec_gitignore_family); [ -n "$SEC_GITIGNORE_FAMILY" ] || SEC_GITIGNORE_FAMILY=no
452
452
  SEC_BUILD_OUTPUT=$(default_ sec_build_output)
453
453
  SEC_WRITE_ROUTES=$(default_ sec_write_routes)
@@ -470,7 +470,14 @@ LAYERS_BLOCK=""
470
470
  # skill rows (SK-01/02/04) — a fresh repo's harness runs them instead of skipping. An
471
471
  # explicit --opt-out is the only thing that records a part in disabled:.
472
472
  DISABLED=""
473
- if [ -n "$OPT_OUT" ]; then DISABLED="$DISABLED$OPT_OUT,"; fi
473
+ if [ -n "$OPT_OUT" ]; then
474
+ # An opt-out ADDS to the parts already recorded: seed from the PREVIOUS value — brackets
475
+ # stripped — or the flag merge lets this run's render ([skills]) replace the carried
476
+ # [mcp] and the older opt-outs are lost (measured on this tree). A fresh install has no
477
+ # previous value, so the list is exactly this run's part.
478
+ PREV_DISABLED=$(g_agents_read "$CONFIG" disabled 2>/dev/null || true)
479
+ DISABLED="${PREV_DISABLED//[][]/},$OPT_OUT,"
480
+ fi
474
481
  DISABLED=$(printf '%s' "$DISABLED" | tr ',' '\n' | grep -v '^$' | sort -u | paste -sd, -)
475
482
 
476
483
  # FIX 3: a *-SPEC.md and reviews/ are policed by LIBRARY rows (SP-01..03, PG-01..03, off by
@@ -678,6 +685,97 @@ render_config() {
678
685
  grep -v '^gate__cmd: $' "$TMP/agents-block.raw" > "$TMP/agents-block"
679
686
  }
680
687
 
688
+ # The carry is NOT a list of names. It used to be: CARRY_KEYS enumerated seven keys the
689
+ # render-call drew from hardcoded literals, and everything else in the previous block was
690
+ # overwritten with the render's literal — or, for keys the render does not emit at all
691
+ # (a gate_<name>_cmd a newer template never draws, or a hand-added key), silently DELETED,
692
+ # comment lines included. That manufactured absence is this card's bug: a re-install raised
693
+ # a ratchet ceiling back to the template's measured number, deleted the gate that enforced
694
+ # it, and deleted the comment block that recorded why the ceiling is what it is — in
695
+ # silence, on every upgrade. The kit's own doctrine — a declared key that is absent is a
696
+ # skip with a reason, never a silent pass — makes the installer the one writer that must
697
+ # not manufacture it. So carry_forward now reads the previous block as LINES (g_agents_pairs
698
+ # loses comments) and keeps every line the new render did not reproduce under the same key:
699
+ # - a pair whose key the render emitted -> the previous value replaces the rendered one;
700
+ # - a pair whose key the render did NOT emit -> re-inserted, so a declared gate or any
701
+ # key a newer template stopped drawing cannot vanish;
702
+ # - a `#` comment line or any other non-pair line -> preserved verbatim, in its old
703
+ # relative position.
704
+ # Two rules sit above the merge:
705
+ # - A flag is a decision; the absence of a flag is not. A key this run was TOLD a value
706
+ # for (MERGE_FLAG_KEYS below: --gate, --archive, --opt-out) keeps the rendered value —
707
+ # the flag's — not the carried one. MERGE_FLAG_KEYS is rebuilt on every run from the
708
+ # parsed options; it is never read from a record. The practice pin is the DELIBERATE
709
+ # exception to this rule: IN-02's own contract — an --upgrade must never re-pin the
710
+ # standard by itself, even when --practice names a file; --re-pin is the decision — is
711
+ # stronger and sits above the merge (the keep-old-practice sed and the carry agree on
712
+ # the same answer: the previous pin, until --re-pin).
713
+ # - A value the project deliberately blanked stays blank (an empty previous value
714
+ # carries nothing), and a fresh install has no previous block and is untouched: the
715
+ # render is the answer on day one.
716
+ # The practice pin keeps its own contract above this mechanism: an OMITTED --practice never
717
+ # re-pins the standard (IN-02 — the block below and the sed over the rendered lines), and
718
+ # --re-pin remains the deliberate path for an edited standard.
719
+ MERGE_FLAG_KEYS=""
720
+ [ -n "${GOB_GATE:-}" ] && MERGE_FLAG_KEYS="$MERGE_FLAG_KEYS gate_${GATE_NAME}_cmd"
721
+ [ "$ARCHIVE" = "true" ] && MERGE_FLAG_KEYS="$MERGE_FLAG_KEYS archive"
722
+ [ -n "$OPT_OUT" ] && MERGE_FLAG_KEYS="$MERGE_FLAG_KEYS disabled"
723
+
724
+ # carry_forward — merge the PREVIOUS block into the rendered one, line by line. The rendered
725
+ # file is read first (its key -> line map drives the merge), then the previous block's lines
726
+ # are walked in order: a pair whose key the render emitted prints the rendered line (with the
727
+ # previous value spliced in, unless the key is in MERGE_FLAG_KEYS — the flag wins), a pair
728
+ # the render does not emit prints verbatim, and every other line (comments) prints verbatim.
729
+ # Rendered lines no previous key consumed (the markers, and keys newer than the previous
730
+ # block) are appended in render order afterwards. The value is cut at the FIRST ": " and
731
+ # rebuilt as `key: value`, so a value carrying ": " or a raw tab round-trips byte for byte
732
+ # (the same contract g_agents_pairs gives the write). A duplicated previous key: the first
733
+ # occurrence wins and the rest are dropped — g_agents_read stops at the first match, so a
734
+ # kept duplicate would shadow the carried value. An EMPTY previous value carries nothing —
735
+ # a value the project blanked stays blank. A failure here EXITS: a re-install that cannot
736
+ # read the previous block must not go on and write the render over it.
737
+ carry_forward() {
738
+ [ -f "$CONFIG" ] || return 0
739
+ g_agents_block "$CONFIG" > "$TMP/prev-block" 2>/dev/null \
740
+ || { g_err "could not read the previous gob block in $CONFIG"; exit 1; }
741
+ [ -s "$TMP/prev-block" ] || return 0
742
+ MERGE_FLAG_KEYS="$MERGE_FLAG_KEYS" awk '
743
+ FNR == NR { # pass 1: the rendered block — key -> line index
744
+ rn++; rline[rn] = $0
745
+ if (match($0, /^[A-Za-z_][A-Za-z0-9_.-]*:/)) {
746
+ k = substr($0, 1, RLENGTH - 1)
747
+ if (!(k in remit)) remit[k] = rn
748
+ }
749
+ next
750
+ }
751
+ { # pass 2: the previous block, in file order
752
+ if (match($0, /^[A-Za-z_][A-Za-z0-9_.-]*:/)) {
753
+ k = substr($0, 1, RLENGTH - 1)
754
+ if (k in remit) {
755
+ if (k in pdone) next # a duplicated previous key: first wins, rest dropped
756
+ pdone[k] = 1
757
+ v = ""
758
+ if (index($0, ": ") > 0) v = substr($0, index($0, ": ") + 2)
759
+ if (v != "" && index(" " ENVIRON["MERGE_FLAG_KEYS"] " ", " " k " ") == 0) {
760
+ rline[remit[k]] = k ": " v
761
+ }
762
+ print rline[remit[k]]
763
+ used[remit[k]] = 1
764
+ } else {
765
+ print $0 # the render has no line for this key: re-inserted
766
+ }
767
+ next
768
+ }
769
+ print $0 # a comment (or any non-pair line): kept verbatim
770
+ }
771
+ END {
772
+ for (i = 1; i <= rn; i++) if (!(i in used)) print rline[i]
773
+ }
774
+ ' "$TMP/agents-block" "$TMP/prev-block" > "$TMP/agents-block.merged" \
775
+ && mv "$TMP/agents-block.merged" "$TMP/agents-block" \
776
+ || { g_err "could not carry the previous block forward into $CONFIG"; exit 1; }
777
+ }
778
+
681
779
  render_config
682
780
  # The re-shadow refusal (W3 §5.3): a record with engine.mode=global is a MIGRATED repo.
683
781
  # Re-installing would recreate the 18-file payload (the vendored step of the resolution
@@ -729,6 +827,11 @@ put ".gob/engine/categories.tsv" "$SRC/manifest/categories.tsv"
729
827
  # wish, so the table and the engine install together or not at all.
730
828
  put ".gob/manifest/bans.tsv" "$SRC/manifest/bans.tsv"
731
829
  put ".gob/bin/goblin-bans" "$SRC/bin/goblin-bans"
830
+ # AG-01's approve command: shipped like the bans engine, hash-pinned by installed.json. The
831
+ # record it appends to (.gob/agents.approved) is deliberately NOT in this list — it is the
832
+ # project's own history, rewritten by every approval, so pinning it would turn IN-02 red on
833
+ # every legitimate approve.
834
+ put ".gob/bin/goblin-approve" "$SRC/bin/goblin-approve"
732
835
  put ".gob/bans/README.md" "$SRC/bans/README.md"
733
836
  put ".gob/bans/grep-ban.sh" "$SRC/bans/grep-ban.sh"
734
837
  put ".gob/bans/layer-check.sh" "$SRC/bans/layer-check.sh"
@@ -746,7 +849,9 @@ if [ "$DRY_RUN" -eq 0 ] && [ -f "$CONFIG" ]; then
746
849
  # The block file here is the RENDERED template ("key: value" lines, no tabs), so the match
747
850
  # anchors on the key prefix, not on a tab field ($1 == "practice" never fired under the
748
851
  # rendered shape and the freshly rendered NEW hash flowed straight through — an --upgrade
749
- # re-pinned the standard silently, exactly what IN-02 exists to catch).
852
+ # re-pinned the standard silently, exactly what IN-02 exists to catch). This sits ABOVE the
853
+ # line merge: even an explicit --practice does not re-pin on a re-install (the merge would
854
+ # otherwise keep the freshly hashed pin); --re-pin is the decision path for a new pin.
750
855
  if [ -n "$PREV_FILES" ]; then
751
856
  KEEP_PRACTICE=$(g_agents_read "$CONFIG" practice)
752
857
  KEEP_PRACTICE_SHA=$(g_agents_read "$CONFIG" practice_sha256)
@@ -754,6 +859,14 @@ if [ "$DRY_RUN" -eq 0 ] && [ -f "$CONFIG" ]; then
754
859
  sed -i "s#^practice: .*\$#practice: $KEEP_PRACTICE#; s#^practice_sha256: .*\$#practice_sha256: $KEEP_PRACTICE_SHA#" "$TMP/agents-block"
755
860
  fi
756
861
  fi
862
+ # The install-once contract for the block itself: a re-install must not ERASE a project's
863
+ # declaration and turn the gate that reads it into a SKIP. The merge above keeps every line
864
+ # the render did not reproduce under the same key — values, keys the render no longer emits,
865
+ # and comments. Gated on the BLOCK's presence, not
866
+ # on the previous install record: an AGENTS.md that carries a gob block is the project's
867
+ # answers whether or not installed.json survived, and the carry is a no-op when no block
868
+ # exists (so a fresh install still renders today's defaults).
869
+ carry_forward
757
870
  g_agents_write "$CONFIG" < "$TMP/agents-block" >/dev/null \
758
871
  || { g_err "could not write the gob block into $CONFIG"; exit 1; }
759
872
  fi
@@ -920,7 +1033,12 @@ if [ "$DRY_RUN" -eq 0 ]; then
920
1033
  fi
921
1034
  if [ -n "$OPT_OUT" ] && grep -q "^$GOB_AGENTS_BEGIN" "$CONFIG" 2>/dev/null; then
922
1035
  cur=$(g_agents_read "$CONFIG" disabled)
923
- new=$(printf '%s,%s' "${cur#[]}" "${OPT_OUT}" | tr ',' '\n' | grep -v '^$' | sort -u | paste -sd, -)
1036
+ # The strip must remove BOTH brackets: ${cur#[]} is an empty glob class and matches
1037
+ # nothing, so the previous value's own brackets flowed into the re-wrap — a fresh
1038
+ # --opt-out mcp measured `disabled: [[mcp],mcp]` (nested, part twice) on 0.7.1. Strip,
1039
+ # append this run's part, dedupe, sort, wrap once.
1040
+ cur=${cur//[][]/}
1041
+ new=$(printf '%s,%s' "$cur" "${OPT_OUT}" | tr ',' '\n' | grep -v '^$' | sort -u | paste -sd, -)
924
1042
  {
925
1043
  while IFS=$'\t' read -r k v; do
926
1044
  [ "$k" = "disabled" ] && continue
package/bin/goblin-lib.sh CHANGED
@@ -16,7 +16,7 @@
16
16
  # - name: typecheck four-space-indented second member of a list entry
17
17
  # cmd: npx tsc --noEmit
18
18
 
19
- GOBLIN_LIB_VERSION="0.6.0"
19
+ GOBLIN_LIB_VERSION="0.7.3"
20
20
 
21
21
  # ---------------------------------------------------------------- output -----
22
22
  # g_trunc <width> <text> — fold a long detail to one line at <width> columns, keeping the
@@ -50,12 +50,15 @@ g_fold() {
50
50
  }'
51
51
  }
52
52
  g_pass() {
53
- if [ "${GOB_VERIFY_VERBOSE:-0}" -eq 1 ]; then
54
- printf 'PASS %-6s %s\n' "$1" "$(g_trunc "${GOB_REPORT_COLS:-100}" "$2")"
55
- elif printf '%s' "$2" | grep -q "$(printf '\n')"; then
56
- # Multi-line PASS payloads print whole: the payload often IS the pin a test reads
57
- # (SK-03's advisory-ceiling line), and the collapse must not swallow it.
53
+ if printf '%s' "$2" | grep -q "$(printf '\n')"; then
54
+ # Multi-line PASS payloads print whole in every mode: the payload often IS the pin a
55
+ # test reads (SK-03's advisory-ceiling line), and under --only this used to run the
56
+ # whole payload through g_trunc below — whose length counts the newlines too, so the
57
+ # second line was cut mid-token (the ~100-col fold is for single-line payloads,
58
+ # exactly as g_adv has always done it).
58
59
  printf 'PASS %-6s %s\n' "$1" "$2"
60
+ elif [ "${GOB_VERIFY_VERBOSE:-0}" -eq 1 ]; then
61
+ printf 'PASS %-6s %s\n' "$1" "$(g_trunc "${GOB_REPORT_COLS:-100}" "$2")"
59
62
  else
60
63
  printf 'PASS %-6s (ok)\n' "$1"
61
64
  fi