@chrono-meta/fh-gate 3.43.0 → 3.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.claude/rules/fh_4axis_gate.md +50 -608
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/AGENTS.md +5 -1
  4. package/CATALOG.md +21 -0
  5. package/CHEATSHEET.md +7 -1
  6. package/docs/USER_GUIDE.md +95 -0
  7. package/docs/codex-compat.md +1 -1
  8. package/knowledge/shared/harness-core/fh_4axis_gate_detail.md +679 -0
  9. package/knowledge/shared/harness-core/fh_integration_contract.md +1 -1
  10. package/knowledge/shared/harness-core/fh_module_contract.md +106 -3
  11. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  12. package/knowledge/shared/harness-core/heavy_skill_to_cartridge.md +185 -0
  13. package/knowledge/shared/learnings/subagent_invocations_log.yaml +221 -0
  14. package/knowledge/shared/plugin-catalog/recommended_plugins.md +53 -9
  15. package/package.json +24 -1
  16. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +50 -14
  18. package/plugins/fh-commons/skills/ko-tech-writer/SKILL_detail.md +80 -0
  19. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_negative.md +30 -0
  20. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_positive.md +56 -0
  21. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  22. package/plugins/fh-meta/CHANGELOG.md +118 -0
  23. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +58 -1
  24. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +4 -0
  25. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  26. package/plugins/fh-meta/skills/steel-quench/SKILL_detail.md +9 -4
  27. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  28. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  29. package/scripts/agy_launch_guard.sh +165 -0
  30. package/scripts/agy_remote_run.sh +187 -0
  31. package/scripts/below_floor_scan.sh +30 -0
  32. package/scripts/codex_launch_guard.sh +123 -0
  33. package/scripts/correction_moments.py +23 -2
  34. package/scripts/fh-gate.sh +612 -14
  35. package/scripts/fh-goal.sh +56 -12
  36. package/scripts/fh-run.sh +1 -1
  37. package/scripts/fh_gate_exec.sh +272 -0
  38. package/scripts/fh_session_load.sh +17 -0
  39. package/scripts/finding_fleet.sh +36 -2
  40. package/scripts/finding_verifier.sh +7 -2
  41. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/README.md +16 -0
  42. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/check_refs.py +12 -0
  43. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/scripts/test_check_refs.py +24 -0
  44. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/SKILL.md +16 -0
  45. package/scripts/fixtures/heavy_skill_smell/clean/tidy-notes/skills/tidy-notes/fh-module.yaml +20 -0
  46. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/SKILL.md +25 -0
  47. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/hooks/hooks.json +7 -0
  48. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/check_links.py +25 -0
  49. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish.sh +9 -0
  50. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/publish_guard.py +6 -0
  51. package/scripts/fixtures/heavy_skill_smell/heavy/docs-publisher-pro/scripts/setup.sh +5 -0
  52. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/SKILL.md +25 -0
  53. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/hooks/hooks.json +10 -0
  54. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/check_refs.py +12 -0
  55. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/guard_push.py +9 -0
  56. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/install.sh +6 -0
  57. package/scripts/fixtures/heavy_skill_smell/heavy/release-notes-pro/scripts/ship.sh +9 -0
  58. package/scripts/heavy_skill_smell.py +311 -0
  59. package/scripts/job_heartbeat.py +186 -0
  60. package/scripts/ko_tech_writer_calibrate.py +88 -1
  61. package/scripts/live_eval_matrix.py +128 -0
  62. package/scripts/live_eval_trace.py +199 -5
  63. package/scripts/package_coverage_check.sh +18 -0
  64. package/scripts/prepush_guard_check.sh +41 -20
  65. package/scripts/probe_live_eval.sh +33 -1
  66. package/scripts/probe_live_eval_lib.py +14 -6
  67. package/scripts/selfcheck.sh +162 -2
  68. package/scripts/selfcheck_shard_weights.txt +2 -0
  69. package/scripts/session_checklist.py +109 -5
  70. package/scripts/sidecar_calibrate.sh +15 -5
  71. package/scripts/sidecar_wait.sh +21 -1
  72. package/scripts/sim_isolated_run.sh +20 -0
  73. package/scripts/test_agy_launch_guard_lanes.sh +347 -0
  74. package/scripts/test_agy_remote_run_lanes.sh +228 -0
  75. package/scripts/test_below_floor_scan_lanes.sh +85 -0
  76. package/scripts/test_codex_launch_guard_lanes.sh +183 -0
  77. package/scripts/test_correction_moments_lanes.sh +37 -0
  78. package/scripts/test_fh_gate_absorb_lanes.sh +255 -0
  79. package/scripts/test_fh_gate_defaults_lanes.sh +169 -0
  80. package/scripts/test_fh_gate_exec_lanes.sh +244 -0
  81. package/scripts/test_fh_gate_fusion_lanes.sh +202 -0
  82. package/scripts/test_fh_gate_regressions.sh +92 -1
  83. package/scripts/test_fh_goal_change_detection_lanes.sh +103 -3
  84. package/scripts/test_finding_pipeline_lanes.sh +41 -3
  85. package/scripts/test_guard_anchor_override_env_lanes.sh +84 -0
  86. package/scripts/test_heavy_skill_smell_lanes.sh +160 -0
  87. package/scripts/test_job_heartbeat_lanes.sh +96 -0
  88. package/scripts/test_live_eval_construct_lanes.sh +29 -6
  89. package/scripts/test_live_eval_matrix_lanes.sh +53 -0
  90. package/scripts/test_live_eval_trace_lanes.sh +165 -12
  91. package/scripts/test_name_boundary_locale_lanes.sh +36 -5
  92. package/scripts/test_preprep_speech_coach_lanes.sh +18 -2
  93. package/scripts/test_prepush_guard_failure_visibility_lanes.sh +152 -0
  94. package/scripts/test_prepush_marker_lookup_lanes.sh +143 -0
  95. package/scripts/test_probe_live_eval_lanes.sh +43 -0
  96. package/scripts/test_regression_guard_sibling_lanes.sh +52 -1
  97. package/scripts/test_session_checklist_lanes.sh +205 -0
  98. package/scripts/test_sidecar_calibrate_lanes.sh +5 -1
  99. package/scripts/test_sidecar_wait_stdin.sh +18 -0
  100. package/scripts/test_sim_isolated_run_lanes.sh +43 -0
  101. package/scripts/universal_guard_check.sh +8 -0
  102. package/templates/.claude/rules/mcp_tool_gating.md +27 -0
  103. package/templates/.git-hooks/pre-push +60 -3
  104. package/templates/regression_guard.sh +8 -4
  105. package/templates/settings.LaneGap.snippet.json +27 -0
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env bash
2
+ # agy_remote_run.sh — an agy stand-in that runs agy ONLY as a separate OS user on another machine.
3
+ #
4
+ # WHY. agy runs its own shell and file tools and sends what they print to the cloud model, so it must
5
+ # not run where company repositories are readable (scripts/agy_launch_guard.sh). This runner never
6
+ # starts agy locally: it copies the prompt and the frozen inputs into a fresh work folder in the remote
7
+ # user's home, runs agy there, streams its output back, copies requested files back, and removes only
8
+ # that work folder. If the route is not available it REFUSES — it never falls back to a local agy.
9
+ #
10
+ # REMOTE. A Windows machine reached by OpenSSH, logged in as a non-admin user whose profile cannot read
11
+ # the other profiles (measure that with --canary; do not assume it). agy installed for that user
12
+ # (default %LOCALAPPDATA%\agy\bin\agy.exe). Configuration comes only from the environment — this public
13
+ # file names no host, account or path:
14
+ # FH_AGY_REMOTE ssh target, e.g. user@host (required)
15
+ # FH_AGY_REMOTE_DENY ;-separated remote paths the user must NOT read (required for --canary); only an
16
+ # access-denied error counts, unless the entry starts with ? (then not-found is accepted too)
17
+ # FH_AGY_REMOTE_AGY remote agy path (default: %LOCALAPPDATA%\agy\bin\agy.exe)
18
+ # FH_AGY_REMOTE_RECEIPT_DIR local receipt folder (default: $HOME/.cache/fh-agy-remote — outside any repo)
19
+ #
20
+ # CANARY. `agy_remote_run.sh --canary` runs NO agy. As the remote user it tries to list or open every
21
+ # FH_AGY_REMOTE_DENY path (each must be refused) and reads a file it writes in a fresh work folder (must
22
+ # succeed), then writes a local receipt: receipt_<first 16 of sha256(target, deny list, agy path)>.txt
23
+ # with key=value lines (verdict, target_sha, epoch, denied=N/N, positive) and one line per path.
24
+ # A run is refused unless that receipt says PASS, is under 7 days old and matches the current settings.
25
+ # 🟥 The receipt records this script's own measurement on the day it ran; it is not proof of isolation.
26
+ # 🟥 A deny on a drive or folder root does NOT override an explicit allow entry on a sub-item: on the
27
+ # operator's machine (2026-11-16) the remote user could still list or open 8 such sub-items (game
28
+ # folders, the recycle bins, an antivirus decoy folder, three device-information files), which the
29
+ # operator accepted. The canary only measures the paths you list — list a sub-item only after you
30
+ # have denied it explicitly, and name the accepted ones where you record the receipt.
31
+ #
32
+ # USAGE (agy-compatible; extra flags are this runner's own and are not passed to agy):
33
+ # agy_remote_run.sh [--input <file>]... [--fetch <name>]... [--fetch-dir <dir>] -p "<prompt>" [agy flags...]
34
+ # agy_remote_run.sh --canary
35
+ # Inputs are copied under their own names ([A-Za-z0-9._-] only, no duplicates). The remote agy gets
36
+ # `--settings` limiting it to its workspace (allowNonWorkspaceAccess=false); the OS user is the barrier.
37
+ # Through FH's scripts: FH_AGY_BIN=<repo>/scripts/agy_remote_run.sh FH_AGY_ISOLATION=remote-os-user.
38
+ #
39
+ # EXIT: 0 ok · 1 remote agy exited non-zero (AGY_RC=<n> on stderr) · 2 usage · 3 refused (no target,
40
+ # no/stale/FAIL/mismatched receipt) · 4 route unavailable (ssh/scp failed) · 5 cleanup not verified
41
+ # --canary: 0 PASS · 1 FAIL · 2 usage · 4 route unavailable
42
+ set -uo pipefail
43
+ SSH=ssh; SCP=scp # by name from PATH; there is no override (the lanes put fakes first on PATH)
44
+ die() { echo "agy_remote_run: $2" >&2; exit "$1"; }
45
+ TARGET="${FH_AGY_REMOTE-}"
46
+ [ -n "$TARGET" ] || die 3 "AGY-REMOTE-REFUSED: FH_AGY_REMOTE is not set — refusing (agy is never started locally)"
47
+ case "$TARGET" in *[!A-Za-z0-9@._-]*) die 2 "FH_AGY_REMOTE must look like user@host" ;; esac
48
+ RAGY="${FH_AGY_REMOTE_AGY:-%LOCALAPPDATA%\\agy\\bin\\agy.exe}"
49
+ case "$RAGY" in *[!A-Za-z0-9%\\:._\ -]*) die 2 "FH_AGY_REMOTE_AGY may contain only letters, digits, % \\ : . _ - and spaces" ;; esac
50
+ DENY="${FH_AGY_REMOTE_DENY-}"
51
+ RDIR="${FH_AGY_REMOTE_RECEIPT_DIR:-$HOME/.cache/fh-agy-remote}"
52
+ case "$DENY$RAGY" in *$'\n'*|*$'\r'*) die 2 "FH_AGY_REMOTE_DENY / FH_AGY_REMOTE_AGY must not contain line breaks" ;; esac
53
+ # length-prefixed fields: no two different settings can produce the same hashed text
54
+ TSHA="$(printf 'v1|%d:%s|%d:%s|%d:%s' "${#TARGET}" "$TARGET" "${#DENY}" "$DENY" "${#RAGY}" "$RAGY" | shasum -a 256 2>/dev/null | cut -c1-64)"
55
+ printf '%s' "$TSHA" | grep -Eq '^[0-9a-f]{64}$' || die 4 "could not compute the settings hash (shasum) — refusing"
56
+ RECEIPT="$RDIR/receipt_${TSHA:0:16}.txt"
57
+ SSHO=(-o BatchMode=yes -o ConnectTimeout=15)
58
+ WD="fh_agy_$(date +%Y%m%d%H%M%S)_$(od -An -N3 -tx1 /dev/urandom | tr -d ' \n')"
59
+ LOCAL="$(mktemp -d "${TMPDIR:-/tmp}/fh_agy_remote.XXXXXX")" || die 4 "cannot create a local temp folder"
60
+ trap 'rm -rf "$LOCAL"' EXIT
61
+
62
+ remote_mkdir() { "$SSH" "${SSHO[@]}" "$TARGET" "mkdir $WD" </dev/null >/dev/null 2>&1; }
63
+ remote_put() { "$SCP" -q "${SSHO[@]}" "$@" "$TARGET:$WD/" </dev/null >/dev/null 2>&1; }
64
+ remote_ps() { "$SSH" "${SSHO[@]}" "$TARGET" "powershell -NoProfile -ExecutionPolicy Bypass -File $WD\\$1" </dev/null; }
65
+ remote_cleanup() { # only the folder this run created; the remote script re-checks the name and parent
66
+ cat > "$LOCAL/cleanup.ps1" <<'PS'
67
+ $n = Split-Path -Leaf $PSScriptRoot
68
+ $parent = Split-Path -Parent $PSScriptRoot
69
+ if ($n -notmatch '^fh_agy_[0-9]{14}_[0-9a-f]{6}$' -or $parent -ne $env:USERPROFILE) { "CLEANUP-REFUSED $n"; exit 3 }
70
+ Set-Location $env:USERPROFILE; Remove-Item -LiteralPath $PSScriptRoot -Recurse -Force
71
+ if (Test-Path -LiteralPath $PSScriptRoot) { "CLEANUP-FAILED"; exit 5 } else { "CLEANUP-OK" }
72
+ PS
73
+ remote_put "$LOCAL/cleanup.ps1" || return 5
74
+ local co; co="$(remote_ps cleanup.ps1 2>/dev/null)" # capture first: no early-exit reader on a pipe
75
+ case "$(printf '%s' "$co" | tr -d '\r')" in CLEANUP-OK|*$'\n'CLEANUP-OK) return 0 ;; *) return 5 ;; esac
76
+ }
77
+ # An interrupt after the remote folder exists still removes it (only this run's folder, re-checked remotely).
78
+ CREATED=0
79
+ on_signal() { trap - INT TERM; [ "$CREATED" = 1 ] && remote_cleanup; echo "agy_remote_run: interrupted" >&2; exit 130; }
80
+ trap on_signal INT TERM
81
+
82
+ if [ "${1-}" = "--canary" ]; then
83
+ [ $# -eq 1 ] || die 2 "--canary takes no other arguments"
84
+ [ -n "$DENY" ] || die 2 "FH_AGY_REMOTE_DENY is empty — a canary with nothing to deny measures nothing"
85
+ printf '%s\n' "$DENY" | tr ';' '\n' | sed '/^$/d' > "$LOCAL/deny.txt"
86
+ cat > "$LOCAL/canary.ps1" <<'PS'
87
+ foreach ($p in Get-Content -LiteralPath (Join-Path $PSScriptRoot 'deny.txt') -Encoding UTF8) {
88
+ $absentOk = $p.StartsWith('?'); if ($absentOk) { $p = $p.Substring(1) }
89
+ try { $i = Get-Item -LiteralPath $p -Force -ErrorAction Stop
90
+ if ($i.PSIsContainer) { [void](Get-ChildItem -LiteralPath $p -Force -ErrorAction Stop) } else { [IO.File]::OpenRead($p).Close() }
91
+ "DENY-FAIL $p (readable)" }
92
+ catch { $x = $_.Exception; $e = $x.GetType().Name # walk wrapped errors (OpenRead wraps its own)
93
+ while ($null -ne $x.InnerException) { $x = $x.InnerException; $e = $e + '/' + $x.GetType().Name }
94
+ if ($e -match 'UnauthorizedAccess' -or ($absentOk -and $e -match 'NotFound')) { "DENY-OK $p ($e)" }
95
+ else { "DENY-FAIL $p (not measured: $e)" } } }
96
+ $f = Join-Path $PSScriptRoot 'positive.txt'; Set-Content -LiteralPath $f -Value 'FH-POSITIVE'
97
+ try { if ((Get-Content -LiteralPath $f -Raw).Trim() -eq 'FH-POSITIVE') { 'POS-OK' } else { 'POS-FAIL' } } catch { 'POS-FAIL' }
98
+ PS
99
+ remote_mkdir || die 4 "AGY-REMOTE-UNAVAILABLE: cannot reach $TARGET (mkdir failed)"
100
+ CREATED=1
101
+ remote_put "$LOCAL/deny.txt" "$LOCAL/canary.ps1" || { remote_cleanup; die 4 "AGY-REMOTE-UNAVAILABLE: copy to $TARGET failed"; }
102
+ out="$(remote_ps canary.ps1 2>&1)"; prc=$?; out="$(printf '%s' "$out" | tr -d '\r')"
103
+ remote_cleanup; crc=$?
104
+ want=$(grep -c '' "$LOCAL/deny.txt")
105
+ ok=$(printf '%s\n' "$out" | grep -c '^DENY-OK ')
106
+ bad=$(printf '%s\n' "$out" | grep -c '^DENY-FAIL ')
107
+ pos=$(printf '%s\n' "$out" | grep -q '^POS-OK$' && echo READ || echo FAIL)
108
+ verdict=FAIL; [ "$ok" -eq "$want" ] && [ "$bad" -eq 0 ] && [ "$pos" = READ ] && [ "$want" -gt 0 ] && [ "$crc" -eq 0 ] && [ "$prc" -eq 0 ] && verdict=PASS
109
+ mkdir -p "$RDIR" || die 4 "cannot create $RDIR"
110
+ { echo "verdict=$verdict"; echo "target_sha=$TSHA"; echo "epoch=$(date +%s)"; echo "denied=$ok/$want"
111
+ echo "positive=$pos"; echo "cleanup=$([ "$crc" -eq 0 ] && echo OK || echo UNVERIFIED)"
112
+ printf '%s\n' "$out" | grep -E '^(DENY-OK|DENY-FAIL|POS-OK|POS-FAIL)'; } > "$RECEIPT.tmp" && mv "$RECEIPT.tmp" "$RECEIPT" \
113
+ || die 4 "could not write the receipt $RECEIPT — the canary result is not recorded"
114
+ echo "AGY-REMOTE-CANARY $verdict denied=$ok/$want positive=$pos receipt=$RECEIPT"
115
+ [ "$verdict" = PASS ] && exit 0 || exit 1
116
+ fi
117
+
118
+ # ── run mode: receipt first, then the route ───────────────────────────────────────────────────────
119
+ [ -f "$RECEIPT" ] || die 3 "AGY-REMOTE-REFUSED: no canary receipt for these settings — run: agy_remote_run.sh --canary"
120
+ r_get() { sed -n "s/^$1=//p" "$RECEIPT" | sed -n 1p; } # first value only; sed reads to the end
121
+ [ "$(r_get verdict)" = PASS ] || die 3 "AGY-REMOTE-REFUSED: the last canary did not pass ($RECEIPT)"
122
+ [ "$(r_get target_sha)" = "$TSHA" ] || die 3 "AGY-REMOTE-REFUSED: receipt is for different settings"
123
+ age=$(( $(date +%s) - $(r_get epoch | grep -E '^[0-9]+$' || echo 0) ))
124
+ [ "$age" -le 604800 ] || die 3 "AGY-REMOTE-REFUSED: canary receipt is older than 7 days — run --canary again"
125
+ [ "$age" -ge 0 ] || die 3 "AGY-REMOTE-REFUSED: canary receipt is dated in the future — run --canary again"
126
+
127
+ PROMPT=""; HAVEP=0; INPUTS=(); FETCH=(); FDIR=""; PASS=()
128
+ while [ $# -gt 0 ]; do
129
+ case "$1" in
130
+ --input) [ $# -ge 2 ] || die 2 "--input needs a file"; INPUTS+=("$2"); shift 2 ;;
131
+ --fetch) [ $# -ge 2 ] || die 2 "--fetch needs a name"
132
+ [ "$2" = "$(basename "$2")" ] || die 2 "--fetch takes a bare file name inside the work folder, not a path: $2"
133
+ FETCH+=("$2"); shift 2 ;;
134
+ --fetch-dir) [ $# -ge 2 ] || die 2 "--fetch-dir needs a folder"; FDIR="$2"; shift 2 ;;
135
+ -p|--print|--prompt) [ $# -ge 2 ] || die 2 "$1 needs a prompt"; PROMPT="$2"; HAVEP=1; shift 2 ;;
136
+ --settings) die 2 "--settings is set by this runner (workspace-only); remove it" ;;
137
+ *) case "$1" in *$'\n'*) die 2 "an agy argument contains a newline" ;; esac; PASS+=("$1"); shift ;;
138
+ esac
139
+ done
140
+ [ "$HAVEP" -eq 1 ] || die 2 "a prompt is required (-p)"
141
+ [ "${#FETCH[@]}" -eq 0 ] || [ -n "$FDIR" ] || die 2 "--fetch needs --fetch-dir"
142
+ seen=" "
143
+ for f in ${INPUTS[@]+"${INPUTS[@]}"} ${FETCH[@]+"${FETCH[@]}"}; do
144
+ b="$(basename "$f")"
145
+ lb="$(printf '%s' "$b" | tr 'A-Z' 'a-z')" # Windows names are case-insensitive
146
+ case "$b" in ''|*[!A-Za-z0-9._-]*) die 2 "file name not allowed: $b" ;; esac
147
+ case "$lb" in prompt.txt|args.txt|settings.json|run.ps1|cleanup.ps1|agy_path.txt|canary.ps1|deny.txt) die 2 "file name reserved by the runner: $b" ;; esac
148
+ done
149
+ for f in ${INPUTS[@]+"${INPUTS[@]}"}; do
150
+ [ -f "$f" ] || die 2 "input not found: $f"
151
+ b="$(basename "$f" | tr 'A-Z' 'a-z')"; case "$seen" in *" $b "*) die 2 "two inputs share the name $b (Windows ignores case)" ;; esac; seen="$seen$b "
152
+ done
153
+ printf '%s' "$PROMPT" > "$LOCAL/prompt.txt"
154
+ : > "$LOCAL/args.txt"; for a in ${PASS[@]+"${PASS[@]}"}; do printf '%s\n' "$a" >> "$LOCAL/args.txt"; done
155
+ printf '{"toolPermission":"always-proceed","allowNonWorkspaceAccess":false}\n' > "$LOCAL/settings.json"
156
+ printf '%s' "$RAGY" > "$LOCAL/agy_path.txt"
157
+ cat > "$LOCAL/run.ps1" <<'PS'
158
+ Set-Location $PSScriptRoot
159
+ $p = Get-Content -LiteralPath 'prompt.txt' -Raw -Encoding UTF8
160
+ $a = @(Get-Content -LiteralPath 'args.txt' -Encoding UTF8 | Where-Object { $_ -ne '' })
161
+ $agy = [Environment]::ExpandEnvironmentVariables((Get-Content -LiteralPath 'agy_path.txt' -Raw -Encoding UTF8).Trim())
162
+ & $agy -p $p @a --settings (Join-Path $PSScriptRoot 'settings.json')
163
+ # printed after agy has exited: the runner trusts only the LAST line, which agy's output cannot follow
164
+ $rc = $LASTEXITCODE
165
+ "FH_AGY_RC=$rc"
166
+ exit $rc # the ssh exit status carries the same code, which nothing agy leaves behind can rewrite
167
+ PS
168
+ remote_mkdir || die 4 "AGY-REMOTE-UNAVAILABLE: cannot reach $TARGET (mkdir failed) — not falling back to a local agy"
169
+ CREATED=1
170
+ remote_put "$LOCAL/prompt.txt" "$LOCAL/args.txt" "$LOCAL/settings.json" "$LOCAL/agy_path.txt" "$LOCAL/run.ps1" ${INPUTS[@]+"${INPUTS[@]}"} \
171
+ || { remote_cleanup; die 4 "AGY-REMOTE-UNAVAILABLE: copy to $TARGET failed"; }
172
+ remote_ps run.ps1 > "$LOCAL/out.txt" 2> "$LOCAL/err.txt"; src=$?
173
+ tr -d '\r' < "$LOCAL/out.txt" | sed '$ { /^FH_AGY_RC=/d; }'; tr -d '\r' < "$LOCAL/err.txt" >&2
174
+ last="$(tr -d '\r' < "$LOCAL/out.txt" | sed '/^$/d' | tail -1)"
175
+ arc="$(printf '%s' "$last" | sed -n 's/^FH_AGY_RC=\(-\{0,1\}[0-9][0-9]*\)$/\1/p')"
176
+ frc=0
177
+ for n in ${FETCH[@]+"${FETCH[@]}"}; do
178
+ mkdir -p "$FDIR" && "$SCP" -q "${SSHO[@]}" "$TARGET:$WD/$n" "$FDIR/" </dev/null >/dev/null 2>&1 || { echo "agy_remote_run: could not fetch $n" >&2; frc=4; }
179
+ done
180
+ remote_cleanup || { echo "agy_remote_run: remote work folder $WD not confirmed removed" >&2; exit 5; }
181
+ [ -n "$arc" ] || { echo "agy_remote_run: no exit code came back from the remote side (ssh exited $src) — route failed" >&2; exit 4; }
182
+ # success needs BOTH: the printed code and the ssh exit status agree (a line printed later by a leftover
183
+ # child cannot change the exit status; an ssh failure cannot print the line)
184
+ [ "$src" = "$(( arc & 255 ))" ] || { echo "agy_remote_run: ssh exited $src but the remote printed FH_AGY_RC=$arc — route or output not trusted" >&2; exit 4; }
185
+ [ "$frc" -eq 0 ] || exit 4
186
+ [ "$arc" = 0 ] && exit 0
187
+ echo "AGY_RC=$arc" >&2; exit 1
@@ -23,7 +23,37 @@ MARKER_DIR="$REPO_ROOT/tracks/_meta"
23
23
  PENDING=0
24
24
  TOTAL=0
25
25
 
26
+ # Worktree redirect (2026-11-20 weekly audit): tracks/ is gitignored, so a git worktree has no
27
+ # markers of its own and the scan printed «0 total, 0 pending» rc 0 while the main checkout held
28
+ # 4 markers — «not read» rendered as «clean». The pre-commit hook WRITES markers to EVIDENCE_ROOT
29
+ # (the main checkout, via --git-common-dir), so with no root argument a worktree reads exactly
30
+ # there — the same rule, so writer and reader agree. If that place has no tracks/_meta, say
31
+ # NOT READ (rc unchanged — a CI worktree must not turn red). An explicit root is never redirected;
32
+ # a main checkout and a fresh clone are unchanged. The common dir is resolved to an absolute path
33
+ # from the cwd (git prints it relative to the cwd, not to the top level) and must be a `.git`
34
+ # directory, so a bare repo, --separate-git-dir or a submodule never names an unrelated parent.
35
+ WT_NOTE=""
36
+ if [ -z "${1:-}" ]; then
37
+ _gcd=$(git rev-parse --git-common-dir 2>/dev/null); _rc=$?
38
+ if [ "$_rc" -eq 0 ] && [ -n "$_gcd" ]; then
39
+ _gcd=$(cd "$_gcd" 2>/dev/null && pwd -P) || _gcd=""
40
+ _here=$(cd "$REPO_ROOT" 2>/dev/null && pwd -P) || _here="$REPO_ROOT"
41
+ if [ -n "$_gcd" ] && [ "$(basename "$_gcd")" = .git ]; then
42
+ _hub=$(dirname "$_gcd")
43
+ if [ "$_hub" != "$_here" ]; then
44
+ if [ -d "$_hub/tracks/_meta" ]; then
45
+ MARKER_DIR="$_hub/tracks/_meta"
46
+ WT_NOTE=" (git worktree — read the main checkout's tracks/_meta, where the pre-commit hook writes markers)"
47
+ else
48
+ WT_NOTE=" (git worktree — the main checkout has no tracks/_meta: markers NOT READ, the counts below are not a clean result)"
49
+ fi
50
+ fi
51
+ fi
52
+ fi
53
+ fi
54
+
26
55
  echo "── below-floor marker scan: $MARKER_DIR ──"
56
+ [ -n "$WT_NOTE" ] && echo "$WT_NOTE"
27
57
 
28
58
  if [ ! -d "$MARKER_DIR" ]; then
29
59
  echo " (no tracks/_meta directory — nothing to scan)"
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env bash
2
+ # codex_launch_guard.sh — FH starts codex through here. Lighter than agy_launch_guard.sh: codex is allowed
3
+ # on this machine, but never on company-repo material.
4
+ #
5
+ # WHY. codex `--sandbox read-only` limits writes, not reads: measured 2026-11-16 with canary files, it read
6
+ # paths in its cwd, in another temp folder and in the home directory. Whatever it reads goes to the cloud
7
+ # model. So a codex arm may only be handed public material, and this guard refuses the obvious leak: a
8
+ # prompt, an argument or a working folder that names a configured company-repo root.
9
+ #
10
+ # LIST. Company-repo roots, one absolute path per line, from FH_COMPANY_ROOTS (newline- or ':'-separated)
11
+ # or else the file FH_COMPANY_ROOTS_FILE (default: <repo>/.claude/rules/.company-roots, gitignored; '#'
12
+ # comments and blank lines ignored). No root path appears in any public file.
13
+ #
14
+ # MATCH. A root matches when it appears as a path in the prompt (stdin) or an argument — the root string
15
+ # followed by '/', end of text, or a character that cannot continue a path name — in any of three spellings:
16
+ # as given, its real path, with a leading /private removed (macOS /tmp = /private/tmp), and with $HOME
17
+ # written as '~'. Case-sensitive. The working folder matches when its real path is the root or below it.
18
+ # NOT matched: a relative path, file content pasted without its path, or an encoded path — the guard is a
19
+ # string check, not isolation. Not reached: a caller that starts codex by absolute path around this guard
20
+ # (finding_fleet routes CODEX_BIN and bare `codex` through a PATH shim; an absolute path skips it).
21
+ #
22
+ # UNCONFIGURED. No list, or an empty one: codex runs and the guard prints «CODEX-GUARD: no company roots
23
+ # configured — not checked» on stderr. That is said out loud, never shown as clean.
24
+ #
25
+ # Usage: bash scripts/codex_launch_guard.sh <codex-binary> [codex arguments...] (prompt on stdin; see STDIN below)
26
+ # Exit: 3 = refused (codex not started; stderr starts «HARNESS-ERROR: CODEX-REFUSED») · 2 = usage
27
+ # · otherwise codex's own exit code (a codex exit of 3 is told apart by the missing CODEX-REFUSED line)
28
+ set -uo pipefail
29
+ [ $# -ge 1 ] || { echo "usage: codex_launch_guard.sh <codex-binary> [codex arguments...]" >&2; exit 2; }
30
+ _here="$(cd "$(dirname "$0")" && pwd -P)"
31
+ _rootsfile="${FH_COMPANY_ROOTS_FILE:-$_here/../.claude/rules/.company-roots}"
32
+ _tmp="$(mktemp "${TMPDIR:-/tmp}/fh_codex_prompt.XXXXXX")" || { echo "HARNESS-ERROR: codex_launch_guard cannot create a temp file — codex not started" >&2; exit 3; }
33
+ trap 'rm -f "$_tmp"' EXIT
34
+ # STDIN. A terminal means no prompt (nothing is read). Anything else is read until it ends — but not forever:
35
+ # a stdin that sends nothing new for FH_GUARD_STDIN_IDLE_S seconds (default 60), or has not ended after
36
+ # FH_GUARD_STDIN_MAX_S seconds in all (default 600), is a refusal — never a partial or empty prompt passed on,
37
+ # never a hang. An agent's background shell hands its children a stdin that stays open and never ends;
38
+ # measured 2026-11-20, a plain `cat` here waited 2 h 30 min and, after the guard was killed, still held the
39
+ # caller's output pipe open. Each limit is a whole number of seconds from 1 to 86400 (unset or empty = the
40
+ # default); anything else is refused.
41
+ if [ -t 0 ]; then : > "$_tmp"
42
+ else
43
+ _idle="${FH_GUARD_STDIN_IDLE_S:-60}"; _max="${FH_GUARD_STDIN_MAX_S:-600}"
44
+ for _lim in "FH_GUARD_STDIN_IDLE_S=$_idle" "FH_GUARD_STDIN_MAX_S=$_max"; do
45
+ _v="${_lim#*=}"
46
+ case "$_v" in ''|*[!0-9]*) _v=x ;; *) [ "${#_v}" -le 5 ] && [ "$((10#$_v))" -ge 1 ] && [ "$((10#$_v))" -le 86400 ] || _v=x ;; esac
47
+ [ "$_v" = x ] && { echo "HARNESS-ERROR: CODEX-REFUSED — ${_lim%%=*}='${_lim#*=}' is not a whole number of seconds from 1 to 86400; codex was not started." >&2; exit 3; }
48
+ done
49
+ python3 -c '
50
+ import os, select, sys, time
51
+ idle, total = int(sys.argv[1], 10), int(sys.argv[2], 10); out = sys.stdout.buffer
52
+ end = time.monotonic() + total
53
+ try:
54
+ while True:
55
+ left = end - time.monotonic()
56
+ if left <= 0: sys.exit(125)
57
+ if not select.select([0], [], [], min(idle, left))[0]:
58
+ sys.exit(125 if time.monotonic() >= end else 124)
59
+ b = os.read(0, 65536)
60
+ if not b: break
61
+ out.write(b)
62
+ except OSError: sys.exit(5)
63
+ ' "$_idle" "$_max" > "$_tmp"
64
+ case $? in
65
+ 0) ;;
66
+ 124) echo "HARNESS-ERROR: CODEX-REFUSED — stdin is open but sent nothing for ${_idle} s and never ended (an agent background shell does this); codex was not started. Pipe the prompt in, or run with < /dev/null." >&2; exit 3 ;;
67
+ 125) echo "HARNESS-ERROR: CODEX-REFUSED — stdin had not ended after ${_max} s in all; codex was not started. Pipe in a prompt that ends, or run with < /dev/null." >&2; exit 3 ;;
68
+ *) echo "HARNESS-ERROR: CODEX-REFUSED — codex_launch_guard could not read the prompt from stdin; codex was not started." >&2; exit 3 ;;
69
+ esac
70
+ fi
71
+ _verdict="$(FH_GUARD_PROMPT="$_tmp" FH_GUARD_ROOTS_FILE="$_rootsfile" python3 - "${@:2}" <<'PY'
72
+ import os, re, sys
73
+ def roots():
74
+ env = os.environ.get("FH_COMPANY_ROOTS")
75
+ if env is not None and env.strip():
76
+ raw = re.split(r"[\n:]", env)
77
+ else:
78
+ try: raw = open(os.environ["FH_GUARD_ROOTS_FILE"], encoding="utf-8").read().splitlines()
79
+ except FileNotFoundError: raw = [] # no list at all: unconfigured, said out loud
80
+ except OSError as e: # a list that exists but cannot be read: refuse
81
+ print("ERROR the company-roots file exists but cannot be read (%s)" % type(e).__name__); sys.exit(0)
82
+ out = []
83
+ for r in raw:
84
+ r = r.strip()
85
+ if r and not r.startswith("#"): out.append(r.rstrip("/"))
86
+ return out
87
+ R = roots()
88
+ if not R:
89
+ print("UNCONFIGURED"); sys.exit(0)
90
+ home = os.path.expanduser("~").rstrip("/")
91
+ def spellings(r):
92
+ s = {r}
93
+ try: s.add(os.path.realpath(r).rstrip("/"))
94
+ except OSError: pass
95
+ for x in list(s):
96
+ if x.startswith("/private/"): s.add(x[len("/private"):])
97
+ if home and (x == home or x.startswith(home + "/")): s.add("~" + x[len(home):])
98
+ return [x for x in s if x]
99
+ pats = []
100
+ for r in R:
101
+ for sp in spellings(r):
102
+ pats.append(re.compile(re.escape(sp) + r"(?=/|$|[^A-Za-z0-9._\-~])"))
103
+ def hit(text): return any(p.search(text) for p in pats)
104
+ where = []
105
+ try: prompt = open(os.environ["FH_GUARD_PROMPT"], encoding="utf-8", errors="replace").read()
106
+ except OSError: print("ERROR cannot read the prompt"); sys.exit(0)
107
+ if hit(prompt): where.append("prompt")
108
+ if any(hit(a) for a in sys.argv[1:]): where.append("argument")
109
+ cwd = os.path.realpath(os.getcwd())
110
+ for r in R:
111
+ rr = os.path.realpath(r)
112
+ if cwd == rr or cwd.startswith(rr.rstrip("/") + "/"): where.append("working folder"); break
113
+ print("REFUSE " + ",".join(where) if where else "OK")
114
+ PY
115
+ )" || _verdict="ERROR the matcher failed"
116
+ case "$_verdict" in
117
+ OK) ;;
118
+ UNCONFIGURED) echo "CODEX-GUARD: no company roots configured — not checked (set FH_COMPANY_ROOTS or $_rootsfile)" >&2 ;;
119
+ REFUSE*) echo "HARNESS-ERROR: CODEX-REFUSED — a company-repo root appears in the ${_verdict#REFUSE }; codex was not started. Send codex public material only." >&2; exit 3 ;;
120
+ *) echo "HARNESS-ERROR: CODEX-REFUSED — codex_launch_guard could not check (${_verdict}); codex was not started." >&2; exit 3 ;;
121
+ esac
122
+ exec 3<"$_tmp"; rm -f "$_tmp"; trap - EXIT
123
+ exec "$@" <&3 3<&-
@@ -14,6 +14,15 @@ What it claims and what it does not:
14
14
  · "recurring" = two cue hits on different days that share >= --min-shared content words. Word
15
15
  overlap is a candidate filter, not a topic judgment — the reader decides whether a group is one rule.
16
16
  · every exclusion is counted and printed (malformed rows, short rows), never dropped silently.
17
+ · scheduled-trigger prompts (cron / self-scheduled check-ins) land in the ledger as if the operator
18
+ typed them. A row is a `repeated-prompt` (excluded, counted) when its whole text — whitespace
19
+ collapsed, digits removed so a time or counter inside it does not hide the repeat — is at least
20
+ REPEAT_MIN_CHARS long and occurs >= REPEAT_MIN times across ALL parseable ledger rows (counted
21
+ before --since, so the verdict does not depend on the window). Short texts are never excluded:
22
+ a short correction said three times is the signal this tool exists for. 2026-11-20 weekly audit:
23
+ 24 of 24 «recurring pairs» were two cron prompts pairing on «linked list_sessions».
24
+ Residual: a long correction pasted verbatim three times is excluded (counted, so it is visible);
25
+ a cron prompt over MAX_CHARS is counted under `long`, not here.
17
26
 
18
27
  usage: python3 scripts/correction_moments.py [ledger_dir] [--since YYYY-MM-DD] [--min-shared N] [--all]
19
28
  exit: 0 = ran · 2 = ledger dir missing or holds no rows (NOT a "no corrections" result)
@@ -27,6 +36,8 @@ STOP = set("그리고 그런데 그러면 이거 이건 그거 그건 저거 지
27
36
  "있어 있는 없어 없는 아니 아냐 아니야 아니라 말고 다시 정정 해줘 해봐 한번 모두 전부 같은 같아 "
28
37
  "this that with from have what when which there would could about into than then also only does your will".split())
29
38
  MIN_CHARS = 6
39
+ REPEAT_MIN_CHARS = 40 # shorter texts are never treated as scheduled prompts
40
+ REPEAT_MIN = 3 # occurrences across all ledger rows that make a text a scheduled prompt
30
41
  MAX_CHARS = 600 # longer rows are almost always pasted reports or documents, not a correction in the operator's words
31
42
 
32
43
 
@@ -54,6 +65,8 @@ def main(argv):
54
65
  min_shared = int(opt.get("--min-shared", "2"))
55
66
  files = sorted(glob.glob(os.path.join(d, "*.jsonl")))
56
67
  rows, bad, short, envelope, long_ = [], 0, 0, 0, 0
68
+ norm = lambda t: re.sub(r"\d+", "", " ".join(t.split()))
69
+ seen = {}
57
70
  for f in files:
58
71
  sess = os.path.basename(f)[:8]
59
72
  for line in open(f, encoding="utf-8", errors="replace"):
@@ -64,6 +77,7 @@ def main(argv):
64
77
  t, ts = x.get("text"), x.get("ts")
65
78
  if not isinstance(t, str) or not isinstance(ts, str):
66
79
  bad += 1; continue
80
+ seen[norm(t)] = seen.get(norm(t), 0) + 1
67
81
  if ts[:10] < since:
68
82
  continue
69
83
  if t.lstrip().startswith("<"):
@@ -74,6 +88,13 @@ def main(argv):
74
88
  if len(t) > MAX_CHARS:
75
89
  long_ += 1; continue
76
90
  rows.append((ts, sess, t))
91
+ is_rep = lambda t: len(norm(t)) >= REPEAT_MIN_CHARS and seen[norm(t)] >= REPEAT_MIN
92
+ repeated = sum(1 for _, _, t in rows if is_rep(t))
93
+ rows = [r for r in rows if not is_rep(r[2])]
94
+ if not rows and repeated:
95
+ print("⬜ every row is a repeated scheduled prompt (repeated-prompt=%d, envelope=%d short=%d long=%d malformed=%d)"
96
+ " — NOT MEASURED, not «no corrections»" % (repeated, envelope, short, long_, bad))
97
+ return 2
77
98
  if not rows:
78
99
  print("⬜ no ledger rows under %s (files=%d) — NOT MEASURED, not «no corrections»" % (d, len(files)))
79
100
  return 2
@@ -94,9 +115,9 @@ def main(argv):
94
115
  recurring.sort(key=lambda p: -len(p[2]))
95
116
  days = sorted({r[0][:10] for r in rows})
96
117
  print("# correction moments — %s .. %s (%d days)" % (days[0], days[-1], len(days)))
97
- print("ledgers=%d · utterances=%d · excluded: envelope=%d short(<%d chars)=%d long(>%d chars)=%d malformed=%d · cue hits=%d · "
118
+ print("ledgers=%d · utterances=%d · excluded: envelope=%d short(<%d chars)=%d long(>%d chars)=%d malformed=%d repeated-prompt=%d · cue hits=%d · "
98
119
  "recurring pairs (different days, >=%d shared words)=%d · re-pasted pairs dropped=%d" % (len(files), len(rows), envelope, MIN_CHARS, short, MAX_CHARS, long_, bad,
99
- len(hits), min_shared, len(recurring), repaste))
120
+ repeated, len(hits), min_shared, len(recurring), repaste))
100
121
  print("limits: cue-word recall only (a correction with no cue word is invisible — e.g. «영어로 써졌네», 2026-10-18) · word overlap is a candidate filter\n")
101
122
  for k, (i, j, sh) in enumerate(recurring, 1):
102
123
  print("## R%d — shared: %s" % (k, " ".join(sorted(sh)[:8])))