diff --git a/.agents/skills/adversarial-claim-check/SKILL.md b/.agents/skills/adversarial-claim-check/SKILL.md index 8fbf776..f6f191a 100644 --- a/.agents/skills/adversarial-claim-check/SKILL.md +++ b/.agents/skills/adversarial-claim-check/SKILL.md @@ -24,24 +24,45 @@ Proves that a repository's claims, dependency pins, and security invariants hold 1. **Create an isolated disposable worktree.** Never mutate the primary checkout for destructive or sabotage experiments: ```bash + REPO="$(git rev-parse --show-toplevel)" AUDIT_TMP="$(mktemp -d -t heretek-check-XXXXXX)" - trap 'git worktree remove --force "$AUDIT_TMP/wt" || :; rm -rf "$AUDIT_TMP"' EXIT - git worktree add --detach "$AUDIT_TMP/wt" HEAD + WT_CREATED=0 + + cleanup() { + # Never `rm -rf` the worktree: Git keeps .git/worktrees/ metadata and the + # path stays registered as a broken worktree until `git worktree prune` runs. + if [ "$WT_CREATED" -eq 1 ] && ! git -C "$REPO" worktree remove --force "$AUDIT_TMP/wt"; then + echo "ERROR: worktree cleanup failed; Git still tracks $AUDIT_TMP/wt." >&2 + echo "Recover manually: git -C '$REPO' worktree remove --force '$AUDIT_TMP/wt' && rm -rf '$AUDIT_TMP'" >&2 + echo "Then confirm with: git -C '$REPO' worktree list" >&2 + exit 1 + fi + rm -rf "$AUDIT_TMP" + } + trap cleanup EXIT + + git -C "$REPO" worktree add --detach "$AUDIT_TMP/wt" HEAD && WT_CREATED=1 ``` + The worktree is created with `-C "$REPO"` so the script works from any subdirectory. `WT_CREATED` is only set when `worktree add` succeeds, so a failed add cannot report a phantom cleanup failure. Remove the temp directory only after `git worktree remove` succeeds; a failed removal is reported with the exact recovery command instead of being suppressed with `|| :`. + 2. **Verify package & lockfile truth.** - **Bun / Node**: Run `npm pack --dry-run` (or `bun pm pack --dry-run`) inside `"$AUDIT_TMP/wt"` and confirm every entry point (`main`, `exports`, `bin`, `files`) resolves to a built file that exists. - **Python (`uv`)**: Run `uv lock --check` and confirm `[tool.uv] exclude-newer = "7 days"` is respected. - **GitHub Actions (remote actions)**: Confirm each remote action `uses: owner/repo[/path]@ref` is pinned to a full 40-character commit SHA. Exclude local action paths (`./.github/actions/...`) and Docker references (`docker://...`) from this SHA check. - **GitHub Actions (reusable workflows)**: Separately confirm each remote workflow `uses: owner/repo/.github/workflows/file.yml@ref` is pinned to a full 40-character commit SHA. Exclude local workflow paths (`./.github/workflows/...`). -3. **Sabotage critical invariants.** For each security or correctness invariant changed in the PR: - - Introduce a 1-line break in `"$AUDIT_TMP/wt"`. - - Run the test suite in `"$AUDIT_TMP/wt"` and confirm it exits non-zero. - - Restore the file with `git -C "$AUDIT_TMP/wt" checkout -- .`. +3. **Sabotage critical invariants (green -> red -> green).** For each security or correctness invariant changed in the PR: + - **Baseline first.** Run the relevant test suite in the pristine worktree and require exit `0`: `git -C "$AUDIT_TMP/wt" status --porcelain` must be empty before this run. If the suite is already red, stop and fix the environment — a pre-existing or unrelated failure would otherwise satisfy the "fails after sabotage" step without proving anything. + - Introduce a 1-line break in `"$AUDIT_TMP/wt"` (comment out the guard, invert the condition, or drop the validation check). + - Re-run the same suite and require a non-zero exit. Confirm the failing test is the one that guards the sabotaged invariant, not an unrelated pre-existing failure. + - Restore with `git -C "$AUDIT_TMP/wt" checkout -- .`. + - Re-run the suite and require exit `0` again: this proves the guard is what the test observes and that the restore actually took effect. 4. **Confirm clean working tree.** Verify `git status --porcelain` on the main checkout is empty after cleanup. ## Gotchas - A test that passes when the production guard is commented out is a lie; fix the test before merging. +- A red suite after sabotage proves nothing unless the same suite was green on the pristine worktree first; always record both runs. +- Deleting a worktree directory with `rm -rf` leaves stale metadata in `.git/worktrees/`; always go through `git worktree remove`, and surface a failed removal instead of swallowing it with `|| :`. diff --git a/.agents/skills/evidence-pr/SKILL.md b/.agents/skills/evidence-pr/SKILL.md index 38b1d4a..daf8f94 100644 --- a/.agents/skills/evidence-pr/SKILL.md +++ b/.agents/skills/evidence-pr/SKILL.md @@ -34,19 +34,38 @@ Every pull request in a `Heretek-AI` repository must prove its claims with execu git diff --cached --stat ``` - Scan the staged blobs using the repository's no-local-paths pattern (not just the working files): + Scan the staged blobs using the repository's no-local-paths patterns (not just the working files). Run from the repository root so staged files outside the current subdirectory are included: ```bash - PATTERN='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' - if git grep --cached -nIE "$PATTERN" -- .; then - echo "ERROR: Machine-local paths found in staged content." >&2 - exit 1 - else - scan_status=$? - [ "$scan_status" -eq 1 ] || exit "$scan_status" - fi + cd "$(git rev-parse --show-toplevel)" # or prefix each call with: git -C "$(git rev-parse --show-toplevel)" + + scan_staged_paths() { + local pattern="$1" label="$2" scan_status + if git grep --cached -nIE "$pattern" -- .; then + echo "ERROR: $label found in staged content." >&2 + return 1 + else + scan_status=$? + # git grep: 0 = matches (fail), 1 = no matches (clean), >1 = scan error (bad regex, unreadable index). + [ "$scan_status" -eq 1 ] || return "$scan_status" + fi + } + + # Pattern 1 (canonical, identical to .github/workflows/hygiene.yml): high-signal + # directories only, so CI catches these. + PATTERN_CANONICAL='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' + + # Pattern 2 (stricter, local-only): ANY absolute home-directory reference, so a + # path into another checkout such as /Users//src/other-repo is caught even + # though "src" is not one of pattern 1's high-signal directories. + PATTERN_HOME_DIR='file:///(home|Users|root)/|(^|[^A-Za-z0-9_.-])/(home|Users)/[^/[:space:]"'"'"'`<>]+/' + + scan_staged_paths "$PATTERN_CANONICAL" "Machine-local high-signal path" || exit $? + scan_staged_paths "$PATTERN_HOME_DIR" "Absolute home-directory path" || exit $? ``` + Intent: pattern 1 mirrors the CI gate exactly — a match there means the `hygiene / No machine-local paths` check will fail, so it is the blocking signal. Pattern 2 is deliberately stricter than CI and is not enforced by any workflow; clear it locally so cross-checkout references (`/Users//src/other-repo`, `file:////notes.md`) never enter review, even though CI would pass them. Non-zero statuses are propagated on purpose: `git grep` returns 1 for "no match" (clean) and a larger code for a genuine scan error, so an error fails the check instead of being read as clean. + Resolve any matches or scan errors before claiming the no-local-paths invariant is verified. 3. **Run local pre-commit and test gates.** Execute Lefthook and the repository's canonical test command, capturing the exact output: @@ -66,6 +85,10 @@ Every pull request in a `Heretek-AI` repository must prove its claims with execu gh pr checks --watch ``` + Before merge, run the `ocr-thread-resolution` skill: Tier 1 rulesets set + `required_review_thread_resolution: true`, so any unresolved review thread + (including OCR inline threads) blocks merge. + ## Gotchas - Never claim a test passed without executing it in the current working tree. diff --git a/.agents/skills/hygiene-and-workflow-audit/SKILL.md b/.agents/skills/hygiene-and-workflow-audit/SKILL.md index 8b6cf9a..7fc9170 100644 --- a/.agents/skills/hygiene-and-workflow-audit/SKILL.md +++ b/.agents/skills/hygiene-and-workflow-audit/SKILL.md @@ -26,7 +26,15 @@ Enforces `Heretek-AI` repository hygiene and GitHub Actions supply-chain hardeni ```bash PATTERN='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' - ! git grep -nIE "$PATTERN" -- . + if git grep -nIE "$PATTERN" -- .; then + echo "ERROR: Machine-local paths found in tracked files." >&2 + exit 1 + else + grep_status=$? + # 0 = matches (fail), 1 = no matches (clean), >1 = scan error (bad regex, unreadable index). + # Never collapse this into a bare status check: an invalid regex must fail loudly, not pass. + [ "$grep_status" -eq 1 ] || exit "$grep_status" + fi ``` 2. **Enforce GitHub Actions security invariants.** Every workflow under `.github/workflows/` must satisfy: @@ -39,7 +47,7 @@ Enforces `Heretek-AI` repository hygiene and GitHub Actions supply-chain hardeni ```bash actionlint - uvx zizmor@1.30.1 --format=plain . + uvx zizmor@1.33.1 --format=plain . ``` 4. **Validate Agent Skills (`SKILL.md`).** In `Heretek-AI/.github` only, validate the canonical `skills/` directory: @@ -52,5 +60,6 @@ Enforces `Heretek-AI` repository hygiene and GitHub Actions supply-chain hardeni ## Gotchas +- `! git grep ...` is not a valid "must be absent" assertion: `!` maps both "no match" (1) and any scan error to success, so a broken pattern silently passes the audit. Always branch on the status and accept only 1 as clean. - `actionlint` skips input validation on SHA-pinned actions; verify action input names against upstream `action.yml` when pinning. - Never add `pull_request_target` workflows that check out or execute untrusted PR head code. diff --git a/.agents/skills/ocr-thread-resolution/SKILL.md b/.agents/skills/ocr-thread-resolution/SKILL.md new file mode 100644 index 0000000..0d9918f --- /dev/null +++ b/.agents/skills/ocr-thread-resolution/SKILL.md @@ -0,0 +1,66 @@ +--- +name: ocr-thread-resolution +description: Clear unresolved PR review threads (including OCR inline threads) so Tier 1 branch protection lets the PR merge. Use when a PR is blocked on review threads, after pushing fixes to an OCR-reviewed PR, or before merging any PR in a Heretek-AI repository. +license: MIT +compatibility: opencode claude codex copilot +metadata: + audience: maintainers-and-agents + workflow: github-pr + opencode/slash: "true" +--- + +# OCR Thread Resolution + +Tier 1 rulesets set `required_review_thread_resolution: true` +(`templates/rulesets/tier1-main.json`). GitHub blocks merge while **any** +review thread is unresolved — including OCR's inline threads. OCR runs with +`resolve_outdated: 'true'`, so it auto-resolves its own outdated threads, but +live findings still need a human or agent to fix the code or reply with a +reason. + +## Steps + +1. **List unresolved threads.** From the repository root: + + ```bash + bash scripts/ocr/list-unresolved-threads.sh + ``` + + When working in a fleet clone the script lives in the `.github` checkout; + use its path there (e.g. `bash /path/to/.github/scripts/ocr/list-unresolved-threads.sh`). + Stdout is one JSON object per unresolved thread (`id`, `path`, `line`, + `isOutdated`, `author`, `body` truncated to 500 chars, `url`); the count + goes to stderr. Exit status is always 0 in list mode, so piping to `jq` + is safe. + +2. **Fix or reply, per thread.** For each thread, do exactly one of: + - Fix the code, commit, and push; or + - Reply on the thread with a written justification (why the finding does + not apply), then resolve. + +3. **Resolve deliberately.** Resolve one thread at a time after its fix or + reply is in place: + + ```bash + bash scripts/ocr/list-unresolved-threads.sh --resolve --confirm + ``` + + The `--confirm` flag is mandatory; the script refuses without it. + +4. **Re-run to zero.** Repeat step 1 until the stderr count reads + `unresolved_threads=0`. + +5. **Wait for the incremental OCR re-run and re-check.** Pushing fixes + triggers OCR again in incremental mode, which may post new threads. Run + step 1 once more after the re-run finishes. + +## Gotchas + +- Never resolve a thread without a code fix or a written reason on the thread. +- Never bulk-resolve: resolve one thread at a time so each fix-or-reason is + auditable. +- Outdated OCR threads are auto-resolved by OCR in `resolve_outdated: 'true'` + mode; do not hand-resolve a thread OCR is about to clear — re-run the + list script after the OCR run instead. +- `required_review_thread_resolution` counts threads from every reviewer, + not just OCR. Human threads need the same fix-or-reply treatment. diff --git a/.agents/skills/security-review/SKILL.md b/.agents/skills/security-review/SKILL.md index 52cd64b..0805f2c 100644 --- a/.agents/skills/security-review/SKILL.md +++ b/.agents/skills/security-review/SKILL.md @@ -26,9 +26,12 @@ Conducts a disciplined, evidence-backed security review modeled on a threat-mode - Identify high-value assets (credentials, tokens, filesystem writes, subprocess execution, database queries, CI runner privileges). 2. **Run fast deterministic checks first (if available locally).** - - Secrets & hygiene: `gitleaks protect --staged --redact --no-banner` (or `gitleaks detect --no-git`). + - Secrets & hygiene — pick the scanner mode that matches what you are reviewing: + - Pre-commit or staged-change check: `gitleaks protect --staged --redact --no-banner` + - PR branch or repository review (scans commits in range, not just the index): `gitleaks detect --source . --log-opts="--diff-merges=separate $(git merge-base origin/main HEAD)..HEAD" --redact --no-banner`. Substitute the real upstream base ref (for example `origin/trunk`) and omit `--log-opts` only when you intend to scan the entire history. `--no-git` (directory mode) remains available for non-git artifacts such as release tarballs. + - Both `protect --staged` and `detect --log-opts` are current `gitleaks` v8 flags (verified against 8.30.1). `--redact` already defaults to 100% but pass it explicitly so a future default change cannot leak secret material into the review log. - Dependencies & IaC: `trivy fs --scanners vuln,misconfig,secret --severity HIGH,CRITICAL .` - - GitHub Actions: `actionlint` and `uvx zizmor@1.30.1 --format=plain .` + - GitHub Actions: `actionlint` and `uvx zizmor@1.33.1 --format=plain .` 3. **Trace untrusted sources to dangerous sinks.** Check each changed or targeted component for: @@ -37,8 +40,9 @@ Conducts a disciplined, evidence-backed security review modeled on a threat-mode - **Secrets & data exposure:** hardcoded keys, secrets logged to stdout/stderr, unredacted error traces, `persist-credentials: true` on untrusted checkouts. - **Supply chain & deserialization:** unpinned third-party actions or downloads, unsafe YAML/pickle/JSON deserialization, prototype pollution. -4. **Verify before reporting.** - - Confirm the code path is actually reachable from an untrusted source (no dead code or test-only fixtures). +4. **Verify before reporting.** The evidence bar differs by finding class: + - **Code-execution, injection, and authentication/authorization findings** must have a reachable path from an untrusted source to the dangerous sink. No dead code, unreachable branches, or test-only fixtures; if you cannot show the path, downgrade it to an unverified observation rather than a finding. + - **Exposed credentials and high-value secrets** are reported on exposure alone. A live credential in a readable file — tracked source, workflow `env:`, committed config, log or build artifact, PR comment — is a finding even if no application code path consumes it, because read access to the repository or artifact is enough to use it. Do not demand a source-to-sink trace here; instead prove the value is real (valid format, not an obvious placeholder or documented dummy, and not already public by design) and state the exposure surface and who can read it. - Document the exact file, symbol, line range, precondition, impact, and severity (`CRITICAL`, `HIGH`, `MEDIUM`, `LOW`). - Never run destructive exploits or execute untrusted payloads outside an isolated sandbox. @@ -51,6 +55,8 @@ Conducts a disciplined, evidence-backed security review modeled on a threat-mode For each verified finding, report: - **Severity & Title:** `[HIGH] Command injection in :` -- **Evidence:** Exact file path, line range, and source-to-sink trace -- **Impact & Precondition:** Who can trigger it and what they gain -- **Fix:** Concrete patch or remediation step + verification test +- **Evidence:** Exact file path and line range, plus the evidence required for the finding class — a source-to-sink trace for code-execution/injection/auth, or the exposure surface plus proof the value is live for credentials/secrets +- **Impact & Precondition:** Who can trigger it and what they gain; for an exposed secret, who can read it and what the credential grants +- **Fix:** Concrete patch or remediation step + verification test; for a secret, rotate first, then remove it from the tree and history + +A live credential that grants production, CI, registry, or cloud access is at least `HIGH` even with no reachable code path; reserve `MEDIUM` for values whose exposure requires an already-privileged reader or grants no capability. diff --git a/.claude/hooks/post-edit-format.sh b/.claude/hooks/post-edit-format.sh new file mode 100755 index 0000000..fd4e35a --- /dev/null +++ b/.claude/hooks/post-edit-format.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Managed by Heretek-AI/.github fleet-sync — Claude Code PostToolUse (Edit|Write) hook +# Runs fast, single-file auto-formatting/linting and checks for machine-local paths. +# Gracefully degrades (exit 0) when optional stack tools are not installed locally. +set -euo pipefail + +payload="$(cat)" + +extract_path() { + if command -v jq >/dev/null 2>&1; then + printf '%s' "$payload" | jq -r '.tool_input.file_path // .tool_input.path // empty' + elif command -v python3 >/dev/null 2>&1; then + printf '%s' "$payload" | python3 -c 'import json,sys +try: + d = json.load(sys.stdin) + ti = d.get("tool_input") or {} + print(ti.get("file_path") or ti.get("path") or "") +except Exception: + pass' + fi +} + +target="$(extract_path)" +[ -z "$target" ] && exit 0 +[ -f "$target" ] || exit 0 + +case "$target" in + *.py | *.pyi) + if command -v ruff >/dev/null 2>&1; then + ruff check --fix --quiet "$target" 2>/dev/null || true + ruff format --quiet "$target" 2>/dev/null || true + elif command -v uv >/dev/null 2>&1; then + uv run --quiet ruff check --fix --quiet "$target" 2>/dev/null || true + uv run --quiet ruff format --quiet "$target" 2>/dev/null || true + fi + ;; + *.js | *.jsx | *.ts | *.tsx | *.mjs | *.cjs | *.json | *.jsonc | *.css) + if command -v biome >/dev/null 2>&1; then + biome check --write --no-errors-on-unmatched "$target" >/dev/null 2>&1 || true + elif command -v bunx >/dev/null 2>&1 && { [ -f "${CLAUDE_PROJECT_DIR:-.}/biome.jsonc" ] || [ -f "${CLAUDE_PROJECT_DIR:-.}/biome.json" ]; }; then + bunx --bun @biomejs/biome check --write --no-errors-on-unmatched "$target" >/dev/null 2>&1 || true + elif command -v node >/dev/null 2>&1; then + if [[ "$target" == *.json || "$target" == *.jsonc ]]; then + node -e "JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))" "$target" >/dev/null 2>&1 || true + elif [[ "$target" == *.js || "$target" == *.mjs || "$target" == *.cjs ]]; then + node --check "$target" >&2 || true + fi + fi + ;; + *.rs) + if command -v rustfmt >/dev/null 2>&1; then + rustfmt --quiet "$target" 2>/dev/null || true + fi + ;; + *.c | *.cc | *.cpp | *.cxx | *.h | *.hh | *.hpp | *.hxx) + if command -v clang-format >/dev/null 2>&1; then + clang-format -i "$target" 2>/dev/null || true + fi + ;; + *.gd) + if command -v gdstyle >/dev/null 2>&1; then + gdstyle fmt "$target" >/dev/null 2>&1 || true + elif command -v gdformat >/dev/null 2>&1; then + gdformat "$target" >/dev/null 2>&1 || true + elif command -v gdscript-formatter >/dev/null 2>&1; then + gdscript-formatter "$target" >/dev/null 2>&1 || true + fi + ;; + *.sh) + if command -v shfmt >/dev/null 2>&1; then + shfmt -i 2 -ci -w "$target" 2>/dev/null || true + fi + if command -v shellcheck >/dev/null 2>&1; then + shellcheck "$target" >&2 || true + fi + ;; + *.toml) + if command -v tombi >/dev/null 2>&1; then + tombi format "$target" >/dev/null 2>&1 || true + elif command -v taplo >/dev/null 2>&1; then + taplo fmt "$target" >/dev/null 2>&1 || true + fi + ;; + *.md) + if command -v rumdl >/dev/null 2>&1; then + rumdl check --fix "$target" >/dev/null 2>&1 || true + fi + ;; +esac + +# Advisory machine-local path warning on the edited file +LOCAL_PATH_RE='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' +if grep -nIE "$LOCAL_PATH_RE" "$target" >/dev/null 2>&1; then + echo "WARN (Heretek-AI post-edit-format): Machine-local path detected in '$target'. Replace with a repo-relative path or owner/name." >&2 +fi + +exit 0 diff --git a/.claude/hooks/pre-bash-guard.sh b/.claude/hooks/pre-bash-guard.sh new file mode 100755 index 0000000..03fdfaa --- /dev/null +++ b/.claude/hooks/pre-bash-guard.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# Managed by Heretek-AI/.github fleet-sync — Claude Code PreToolUse (Bash) guard +# Blocks destructive shell/git commands and hook-bypass flags (exit 2 + stderr). +set -euo pipefail + +payload="$(cat)" + +extract_command() { + if command -v jq >/dev/null 2>&1; then + printf '%s' "$payload" | jq -r '.tool_input.command // empty' + elif command -v python3 >/dev/null 2>&1; then + printf '%s' "$payload" | python3 -c 'import json,sys +try: + d = json.load(sys.stdin) + print((d.get("tool_input") or {}).get("command") or "") +except Exception: + sys.exit(1)' + else + echo "BLOCKED: Neither jq nor python3 is available to inspect Bash tool input (fail-closed)." >&2 + exit 2 + fi +} + +cmd="$(extract_command)" || { + echo "BLOCKED: Failed to parse PreToolUse JSON payload (fail-closed)." >&2 + exit 2 +} + +[ -z "$cmd" ] && exit 0 + +block() { + echo "BLOCKED by Heretek-AI pre-bash-guard: $1" >&2 + exit 2 +} + +# 1. Destructive recursive deletions targeting root, home, cwd, parent, or wildcard +# shellcheck disable=SC2016 +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])rm[[:space:]]+-[A-Za-z]*([rR][A-Za-z]*f|f[A-Za-z]*[rR])[A-Za-z]*[[:space:]]+(/([[:space:]]|$)|~|\.\.?([[:space:]/]|$)|\*|\$HOME)'; then + block "Destructive 'rm -rf' targeting root, home, current/parent directory, or wildcard is prohibited." +fi + +# 2. Force-pushing to git (allow --force-with-lease on non-default branches only) +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])git[[:space:]]+push([[:space:]]|$)'; then + if printf '%s' "$cmd" | grep -Eq '([[:space:]]|^)(--force|-f)([[:space:]]|$)'; then + block "Force-pushing with 'git push --force' / '-f' is prohibited. Use '--force-with-lease' on a feature branch." + fi + if printf '%s' "$cmd" | grep -Eq -- '--force-with-lease' && + printf '%s' "$cmd" | grep -Eq '([[:space:]])(main|master)([[:space:]]|$)'; then + block "Force-pushing to 'main' or 'master' is prohibited." + fi +fi + +# 3. Destructive git history/worktree resets and clean +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])git[[:space:]]+reset[[:space:]]+--hard([[:space:]]|$)'; then + block "'git reset --hard' can destroy uncommitted work. Confirm manually or stash changes first." +fi +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])git[[:space:]]+clean[[:space:]]+-[A-Za-z]*f[A-Za-z]*d|git[[:space:]]+clean[[:space:]]+-[A-Za-z]*d[A-Za-z]*f'; then + block "'git clean -fd' permanently deletes untracked files and directories." +fi + +# 4. Bypassing git/lefthook quality gates +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])git[[:space:]]+(commit|push|merge)([[:space:]].*)?[[:space:]]--no-verify([[:space:]]|$)'; then + block "Bypassing git/Lefthook checks with '--no-verify' is prohibited." +fi + +# 5. Unsafe permissions or remote-pipe shell execution +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])chmod[[:space:]]+(-R[[:space:]]+)?0?777([[:space:]]|$)'; then + block "'chmod 777' creates world-writable files and is prohibited." +fi +if printf '%s' "$cmd" | grep -Eq '(curl|wget)[[:space:]].*\|[[:space:]]*(ba|z|da)?sh([[:space:]]|$)'; then + block "Piping remote downloads directly to a shell ('curl|sh') is prohibited." +fi + +# 6. Privileged PR merges bypassing branch protection and required reviews. +# (Deliberately no resolveReviewThread justification detection: too fragile.) +if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])gh[[:space:]]+pr[[:space:]]+merge([[:space:]]|$)' && + printf '%s' "$cmd" | grep -Eq '(^|[[:space:]])--admin([[:space:]=]|$)'; then + block "'gh pr merge --admin' bypasses required reviews and branch protection and is prohibited." +fi + +exit 0 diff --git a/.claude/hooks/pre-edit-guard.sh b/.claude/hooks/pre-edit-guard.sh new file mode 100755 index 0000000..13a57ea --- /dev/null +++ b/.claude/hooks/pre-edit-guard.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# Managed by Heretek-AI/.github fleet-sync — Claude Code PreToolUse (Edit|Write) guard +# Protects secrets, .env files, private keys, .git internals, and fleet-managed files (exit 2). +set -euo pipefail + +payload="$(cat)" + +extract_path() { + if command -v jq >/dev/null 2>&1; then + printf '%s' "$payload" | jq -r '.tool_input.file_path // .tool_input.path // empty' + elif command -v python3 >/dev/null 2>&1; then + printf '%s' "$payload" | python3 -c 'import json,sys +try: + d = json.load(sys.stdin) + ti = d.get("tool_input") or {} + print(ti.get("file_path") or ti.get("path") or "") +except Exception: + sys.exit(1)' + else + echo "BLOCKED: Neither jq nor python3 is available to inspect Edit/Write tool input (fail-closed)." >&2 + exit 2 + fi +} + +target="$(extract_path)" || { + echo "BLOCKED: Failed to parse PreToolUse JSON payload (fail-closed)." >&2 + exit 2 +} + +[ -z "$target" ] && exit 0 + +block() { + echo "BLOCKED by Heretek-AI pre-edit-guard: $1" >&2 + exit 2 +} + +base="$(basename "$target")" + +# 1. Protect .env files (allow example/sample/template files) +if [[ "$base" == ".env" || "$base" == .env.* ]]; then + case "$base" in + .env.example | .env.sample | .env.template | .env.dist) ;; + *) block "Direct edits to environment secret file '$target' are prohibited. Edit '.env.example' instead." ;; + esac +fi + +# 2. Protect private keys and credential files +case "$base" in + *.pem | *.key | *.p12 | *.pfx | id_rsa | id_ed25519 | id_ecdsa | *credentials*.json | *secrets*.yaml | *secrets*.yml) + block "Direct edits to key/credential file '$target' are prohibited." + ;; +esac + +# 3. Protect .git internals +if [[ "$target" == *"/.git/"* || "$target" == ".git/"* || "$base" == ".git" ]]; then + block "Direct edits inside '.git/' are prohibited." +fi + +# 4. Protect fleet-managed read-only configs in downstream repos (allowed in Heretek-AI/.github itself) +project_dir="${CLAUDE_PROJECT_DIR:-.}" +if [ ! -f "$project_dir/fleet-manifest.json" ]; then + if [[ "$base" == "lefthook.yml" || "$base" == ".editorconfig" || "$base" == ".gitattributes" || "$target" == *".claude/settings.json" || "$target" == *".claude/hooks/"* ]]; then + if [ -f "$target" ] && grep -qF "Managed by Heretek-AI/.github fleet-sync" "$target" 2>/dev/null; then + block "'$target' is managed by Heretek-AI/.github fleet-sync. Put local overrides in 'lefthook-local.yml' or '.claude/settings.local.json'." + fi + fi +fi + +exit 0 diff --git a/.claude/hooks/stop-verify-gate.sh b/.claude/hooks/stop-verify-gate.sh new file mode 100755 index 0000000..ecbf94c --- /dev/null +++ b/.claude/hooks/stop-verify-gate.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash +# Managed by Heretek-AI/.github fleet-sync — Claude Code Stop verification gate +# Performs a fast diff-only hygiene check before Claude finishes responding. +# Respects stop_hook_active to prevent infinite Stop hook loops. +set -euo pipefail + +payload="$(cat)" + +# Prevent infinite Stop hook loops per Claude Code specification +stop_active="false" +if [ -n "$payload" ]; then + if command -v jq >/dev/null 2>&1; then + stop_active="$(printf '%s' "$payload" | jq -r '.stop_hook_active // false' 2>/dev/null || echo "false")" + elif command -v python3 >/dev/null 2>&1; then + stop_active="$(printf '%s' "$payload" | python3 -c 'import json,sys +try: + print("true" if json.load(sys.stdin).get("stop_hook_active") else "false") +except Exception: + print("false")')" + fi +fi +[ "$stop_active" = "true" ] && exit 0 + +project_dir="${CLAUDE_PROJECT_DIR:-.}" +if ! git -C "$project_dir" rev-parse --is-inside-work-tree >/dev/null 2>&1; then + exit 0 +fi + +# Collect modified/staged files (fast, no untracked scan) +mapfile -t changed_files < <( + { + git -C "$project_dir" diff --name-only --diff-filter=ACMR 2>/dev/null || true + git -C "$project_dir" diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true + } | sort -u +) + +# --- Advisory thread reminder (never blocks) ------------------------------- +# 1. Unresolved review-thread reminder. Runs even when no files changed, +# but only when `gh` and `timeout` are present and the branch has an open +# PR. Uses an inline GraphQL call mirroring +# scripts/ocr/list-unresolved-threads.sh (the fleet does not sync scripts/, +# so synced hooks cannot call that script). Capped with `timeout 5`; any +# failure skips silently. +if command -v gh >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1; then + ( + pr_number="$(timeout 5 gh pr view --json number --jq '.number' 2>/dev/null)" || exit 0 + case "$pr_number" in + '' | null | *[!0-9]*) exit 0 ;; + *) : ;; + esac + repo_full="$(timeout 5 gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null)" || exit 0 + case "$repo_full" in + */*) : ;; + *) exit 0 ;; + esac + owner="${repo_full%%/*}" + name="${repo_full#*/}" + # shellcheck disable=SC2016 # GraphQL $variables are expanded by gh, not the shell. + threads_query='query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){reviewThreads(first:100){nodes{id isResolved isOutdated path line comments(first:1){nodes{author{login} body url}}}}}}}' + threads_json="$(timeout 5 gh api graphql -F owner="$owner" -F name="$name" -F number="$pr_number" -f query="$threads_query" 2>/dev/null)" || exit 0 + [[ -n "$threads_json" ]] || exit 0 + if command -v jq >/dev/null 2>&1; then + unresolved="$(printf '%s' "$threads_json" | jq '[.data.repository.pullRequest.reviewThreads.nodes[]? | select(.isResolved == false)] | length' 2>/dev/null)" || exit 0 + elif command -v python3 >/dev/null 2>&1; then + unresolved="$(printf '%s' "$threads_json" | python3 -c 'import json,sys +try: + nodes = json.load(sys.stdin)["data"]["repository"]["pullRequest"]["reviewThreads"]["nodes"] + print(sum(1 for t in nodes if not t.get("isResolved"))) +except Exception: + print(0)')" || exit 0 + else + exit 0 + fi + case "$unresolved" in + '' | *[!0-9]* | 0) exit 0 ;; + *) : ;; + esac + echo "REMINDER (advisory, non-blocking) from Heretek-AI stop-verify-gate: PR #${pr_number} has ${unresolved} unresolved review thread(s); Tier 1 requires review-thread resolution before merge." >&2 + ) || true +fi + +[ "${#changed_files[@]}" -eq 0 ] && exit 0 + +LOCAL_PATH_RE='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' +DEBUG_RE='(^|[[:space:];])(breakpoint\(\)|pdb\.set_trace\(\)|debugger;)([[:space:];]|$)' + +issues=() +for rel in "${changed_files[@]}"; do + [ -f "$project_dir/$rel" ] || continue + # Skip evidence/report directories and hook scripts themselves + case "$rel" in + docs/evidence/* | docs/reports/* | .omo/* | .claude/hooks/* | templates/claude/hooks/*) + continue + ;; + esac + if grep -nIE "$LOCAL_PATH_RE" "$project_dir/$rel" >/dev/null 2>&1; then + issues+=("machine-local path in $rel") + fi + case "$rel" in + *.py | *.js | *.ts | *.jsx | *.tsx | *.mjs | *.cjs) + if grep -nE "$DEBUG_RE" "$project_dir/$rel" >/dev/null 2>&1; then + issues+=("leftover debug breakpoint in $rel") + fi + ;; + esac +done + +if [ "${#issues[@]}" -gt 0 ]; then + echo "BLOCKED by Heretek-AI stop-verify-gate: Clean up these hygiene issues before finishing:" >&2 + for item in "${issues[@]}"; do + echo " - $item" >&2 + done + exit 2 +fi + +# --- Advisory changed-file checks (never block) ---------------------------- +# 2. Advisory changed-file checks: `gdstyle check` for changed *.gd files +# and `fallow dead-code --changed-since HEAD` for changed JS/TS files. +# Each capped with `timeout 8`, output trimmed to 20 lines to keep agent +# context small. Findings print a reminder; never block. +if command -v timeout >/dev/null 2>&1; then + gd_files=() + js_files=() + for rel in "${changed_files[@]}"; do + case "$rel" in + *.gd) gd_files+=("$rel") ;; + *.js | *.ts | *.jsx | *.tsx | *.mjs | *.cjs) js_files+=("$rel") ;; + *) : ;; + esac + done + if [[ "${#gd_files[@]}" -gt 0 ]] && command -v gdstyle >/dev/null 2>&1; then + gd_out="$(cd "$project_dir" && timeout 8 gdstyle check -- "${gd_files[@]}" 2>&1 | head -20)" || true + if printf '%s' "$gd_out" | grep -Eq '[0-9]+:[0-9]+ (warning|error)'; then + echo "REMINDER (advisory, non-blocking) from Heretek-AI stop-verify-gate: gdstyle reported findings in changed GDScript files (first 20 lines):" >&2 || true + printf '%s\n' "$gd_out" >&2 || true + fi + fi + if [[ "${#js_files[@]}" -gt 0 ]] && command -v fallow >/dev/null 2>&1; then + fallow_tmp="$(mktemp 2>/dev/null)" || fallow_tmp="" + if [[ -n "$fallow_tmp" ]]; then + if (cd "$project_dir" && timeout 8 fallow dead-code --no-cache --changed-since HEAD >"$fallow_tmp" 2>&1); then + : # clean: stay silent + else + echo "REMINDER (advisory, non-blocking) from Heretek-AI stop-verify-gate: fallow dead-code exited non-zero for changes since HEAD — findings or tool error (first 20 lines):" >&2 || true + head -20 "$fallow_tmp" >&2 || true + fi + rm -f "$fallow_tmp" + fi + fi +fi + +exit 0 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..be24c33 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,50 @@ +{ + "_managed_by": "Managed by Heretek-AI/.github fleet-sync \u2014 Profile: node-zerodep (Zero-dependency Node.js). Put local overrides in .claude/settings.local.json.", + "hooks": { + "PreToolUse": [ + { + "matcher": "Bash", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pre-bash-guard.sh", + "timeout": 10 + } + ] + }, + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pre-edit-guard.sh", + "timeout": 10 + } + ] + } + ], + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/post-edit-format.sh", + "timeout": 15 + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/stop-verify-gate.sh", + "timeout": 10 + } + ] + } + ] + } +} diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..eb62231 --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,6 @@ +# Managed by Heretek-AI/.github fleet-sync. Local overrides belong in the CodeRabbit UI. +inheritance: true +reviews: + auto_review: + ignore_title_keywords: + - "chore(org-sync)" diff --git a/.editorconfig b/.editorconfig index 895f31d..5c7eb8f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# Standardized EditorConfig — Managed by Heretek-AI/.github +# Managed by Heretek-AI/.github fleet-sync — Standardized EditorConfig root = true [*] diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 8f9f8cd..909a64f 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -18,3 +18,4 @@ config-variables: - APP_ID - APP_CLIENT_ID - STX_HALO_ENABLED + - DEAD_CODE_BLOCKING diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..0978b64 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,25 @@ +# Caller template -- fleet-managed (scripts/sync-fleet.sh bootstraps and +# refreshes it in every workflow-enabled repo except `sync_workflows: false` +# mirrors; manual install only needed elsewhere). +# To install manually: copy to .github/workflows/code-quality.yml, pin `uses: +# Heretek-AI/.github/...` to the current Heretek-AI/.github main SHA +# (full 40-hex, never a tag), and follow docs/opt-in-workflows.md. + +name: Code Quality + +concurrency: + group: code-quality-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +on: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + code-quality: + uses: Heretek-AI/.github/.github/workflows/code-quality.yml@607db4d7eefb2b328c92f4a1b99121be848bc81c # main + with: + blocking: false diff --git a/.github/workflows/dead-code-and-deps.yml b/.github/workflows/dead-code-and-deps.yml new file mode 100644 index 0000000..66fbc4d --- /dev/null +++ b/.github/workflows/dead-code-and-deps.yml @@ -0,0 +1,34 @@ +# Caller template -- fleet-managed (scripts/sync-fleet.sh bootstraps and +# refreshes it in every workflow-enabled repo except `sync_workflows: false` +# mirrors; manual install only needed elsewhere). +# To install manually: copy to .github/workflows/dead-code-and-deps.yml, pin +# `uses: Heretek-AI/.github/...` to the current Heretek-AI/.github main SHA +# (full 40-hex, never a tag), and follow docs/opt-in-workflows.md. +# +# Blocking ratchet: this caller stays advisory (`blocking: false`). Once the +# repo baseline is clean, set the `DEAD_CODE_BLOCKING` repository variable to +# 'true' to fail on findings with no workflow edit. + +name: Dead Code & Dependency Hygiene + +concurrency: + group: dead-code-and-deps-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +on: + pull_request: + schedule: + - cron: "0 7 * * 1" + workflow_dispatch: + +permissions: + contents: read + security-events: write + +jobs: + dead-code-and-deps: + uses: Heretek-AI/.github/.github/workflows/dead-code-and-deps.yml@607db4d7eefb2b328c92f4a1b99121be848bc81c # main + with: + stack: auto + upload_sarif: true + blocking: false diff --git a/.github/workflows/hygiene.yml b/.github/workflows/hygiene.yml index 765795b..9b89aa5 100644 --- a/.github/workflows/hygiene.yml +++ b/.github/workflows/hygiene.yml @@ -10,6 +10,6 @@ permissions: jobs: hygiene: - uses: Heretek-AI/.github/.github/workflows/hygiene.yml@a7d24561f53c55b2b10dc377af69638bd4d05244 # main + uses: Heretek-AI/.github/.github/workflows/hygiene.yml@607db4d7eefb2b328c92f4a1b99121be848bc81c # main with: audit_workflows: true diff --git a/.github/workflows/ocr.yml b/.github/workflows/ocr.yml index cd1973d..dfac193 100644 --- a/.github/workflows/ocr.yml +++ b/.github/workflows/ocr.yml @@ -28,7 +28,7 @@ concurrency: on: pull_request: types: [opened, synchronize, reopened] - issue_comment: + issue_comment: # zizmor: ignore[dangerous-triggers] manual opt-in trigger; execution gated on MEMBER/OWNER/COLLABORATOR association plus an explicit /open-code-review command prefix (job `if` below, re-checked in ocr-review.yml), least-privilege permissions, no PR-code execution. types: [created] permissions: @@ -37,6 +37,6 @@ permissions: jobs: review: - uses: Heretek-AI/.github/.github/workflows/ocr-review.yml@a7d24561f53c55b2b10dc377af69638bd4d05244 # main + uses: Heretek-AI/.github/.github/workflows/ocr-review.yml@607db4d7eefb2b328c92f4a1b99121be848bc81c # main secrets: OCR_LLM_TOKEN: ${{ secrets.OCR_LLM_TOKEN }} diff --git a/.gitignore b/.gitignore index 699d0bb..d6972d9 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ docs/re/_scratch/ docs/re/tools/pclntab/pclntab docs/re/tools/strhdr/strhdr signer/target/ + +# Local Claude Code overrides (never synced by fleet-sync) +.claude/settings.local.json diff --git a/.rumdl.toml b/.rumdl.toml new file mode 100644 index 0000000..22eebc8 --- /dev/null +++ b/.rumdl.toml @@ -0,0 +1,15 @@ +# Managed by Heretek-AI/.github fleet-sync — Standardized rumdl Markdown linter config +# Spec: https://github.com/rvben/rumdl + +[global] +disable = [ + "MD013", # Line length (prose tables and long URLs) + "MD033", # Inline HTML (used in README badges and collapsible details) + "MD041", # First-line H1 (frontmatter or HTML headers may precede H1) +] +exclude = [ + "docs/evidence/**", + "node_modules/**", + ".venv/**", + "target/**", +] diff --git a/lefthook.yml b/lefthook.yml index 830f691..b6af9ae 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,6 +1,16 @@ -# Standardized Lefthook v2 configuration — Profile: node-zerodep (Node.js zero-dependency + node:test) +# Standardized Lefthook v2 configuration — Profile: node-zerodep (Node.js zero-dependency + node:test + Fallow) # Managed by Heretek-AI/.github fleet-sync. Local overrides belong in lefthook-local.yml. -min_version: 1.10.0 +# +# Missing-tool policy (applies to every job in this profile): +# * When a tool is not installed, the job prints +# `WARN: not installed; skipping ` and that check is skipped, so a +# workstation without the full toolchain can still commit. +# * Export LEFTHOOK_STRICT=1 to turn every missing required tool into a hard failure. +# CI must set it, so a missing tool can never silently disable a gate. +# * An installed tool that fails always fails the job, except the checks explicitly +# documented below as advisory (fallow/tach/skylos/cargo-machete/cargo-deny/cppcheck/qlty on pre-push). +# fallow-dead-code stays advisory unless FALLOW_BLOCKING=1 ratchets it to a hard gate. +min_version: 2.2.4 pre-commit: parallel: true @@ -8,27 +18,84 @@ pre-commit: - name: no-local-paths run: | PATTERN='file:///(home|Users|root)/|/(home|Users)/[^/[:space:]"'"'"'`<>]+/(Projects|Documents|Desktop|Downloads|\.gemini|\.claude|\.codex|\.cursor)(/|[^A-Za-z0-9_-]|$)' - if git grep -nIE "$PATTERN" -- {staged_files}; then + # Scan the git index (--cached), not the working tree, so the staged bytes are what + # gets checked even when the file on disk has been edited again since staging. + if git grep --cached -nIE "$PATTERN" -- {staged_files}; then echo "ERROR: Machine-local paths found in staged files. Use repo-relative paths or owner/name." exit 1 + else + status=$? + fi + # grep exit 1 means "no match" (clean); anything above 1 is a real git grep failure. + if [ "$status" -gt 1 ]; then + echo "ERROR: git grep failed with exit code $status while scanning staged files." + exit 1 fi - name: gitleaks run: | - if command -v gitleaks >/dev/null 2>&1; then - gitleaks protect --staged --redact --no-banner + if ! command -v gitleaks >/dev/null 2>&1; then + echo "WARN: gitleaks not installed; skipping secret scan." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 fi + gitleaks protect --staged --redact --no-banner - name: node-syntax-check glob: "*.{js,mjs,cjs}" run: | + if ! command -v node >/dev/null 2>&1; then + echo "WARN: node not installed; skipping Node syntax check." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi for f in {staged_files}; do - node --check "$f" + node --check "$f" || exit 1 done - name: json-validate glob: "*.json" - run: jq empty {staged_files} + run: | + # Validate every staged file; prefer jq, fall back to the python3 standard library. + if command -v jq >/dev/null 2>&1; then + validator=jq + elif command -v python3 >/dev/null 2>&1; then + validator=python3 + else + validator= + fi + if [ -z "$validator" ]; then + echo "WARN: neither jq nor python3 is installed; skipping JSON validation." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + for f in {staged_files}; do + if [ "$validator" = "jq" ]; then + jq empty "$f" || exit 1 + else + python3 -m json.tool -- "$f" >/dev/null || exit 1 + fi + done + + - name: typos + run: | + if ! command -v typos >/dev/null 2>&1; then + echo "WARN: typos not installed; skipping source spell check." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + typos {staged_files} + + - name: markdown-rumdl + glob: "*.md" + stage_fixed: true + run: | + if ! command -v rumdl >/dev/null 2>&1; then + echo "WARN: rumdl not installed; skipping Markdown lint." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + rumdl check --fix {staged_files} - name: shellcheck glob: "*.sh" @@ -36,23 +103,88 @@ pre-commit: if command -v shellcheck >/dev/null 2>&1; then shellcheck {staged_files} else - bash -n {staged_files} + # `bash -n file1 file2` only parses the first file, so loop over all staged files. + echo "WARN: shellcheck not installed; falling back to bash -n (syntax only)." + for f in {staged_files}; do + bash -n "$f" || exit 1 + done fi - name: workflow-audit glob: ".github/workflows/*.{yml,yaml}" run: | - if command -v actionlint >/dev/null 2>&1; then actionlint {staged_files}; fi - if command -v zizmor >/dev/null 2>&1; then zizmor --format=plain {staged_files}; fi + # Accumulate status: a passing zizmor must never mask a failing actionlint (or vice versa). + status=0 + if command -v actionlint >/dev/null 2>&1; then + actionlint -ignore 'reusable workflow call.*not following the format' {staged_files} || status=1 + else + echo "WARN: actionlint not installed; skipping workflow syntax validation." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then status=1; fi + fi + if command -v zizmor >/dev/null 2>&1; then + zizmor --format=plain {staged_files} || status=1 + else + echo "WARN: zizmor not installed; skipping workflow security audit." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then status=1; fi + fi + if [ "$status" -ne 0 ]; then exit 1; fi pre-push: parallel: true jobs: - name: node-test - run: node --test + run: | + if ! command -v node >/dev/null 2>&1; then + echo "WARN: node not installed; skipping node --test." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + node --test - name: fallow-health run: | - if command -v fallow >/dev/null 2>&1; then - fallow health --score || echo "WARN: fallow reported JS/TS health or dead-code findings (advisory)." + if ! command -v fallow >/dev/null 2>&1; then + echo "WARN: fallow not installed; skipping JS/TS health check." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + fallow health --score || echo "WARN: fallow reported JS/TS health or dead-code findings (advisory)." + + - name: fallow-dead-code + run: | + if ! command -v fallow >/dev/null 2>&1; then + echo "WARN: fallow not installed; skipping JS/TS dead-code check." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + # Advisory by default. Set FALLOW_BLOCKING=1 (per-repo lefthook-local.yml or CI env) + # to ratchet this to a hard gate once the repo baseline is clean. + # When origin/main is absent (shallow clone), fall back to a full scan — + # fallow itself also degrades to a full scan with a warning in that case. + if git rev-parse --verify --quiet origin/main >/dev/null 2>&1; then + if [ "${FALLOW_BLOCKING:-0}" = "1" ]; then + fallow dead-code --no-cache --changed-since origin/main + else + fallow dead-code --no-cache --changed-since origin/main || echo "WARN: fallow reported dead-code findings (advisory)." + fi + else + echo "WARN: origin/main not found (shallow clone?); running full dead-code scan." + if [ "${FALLOW_BLOCKING:-0}" = "1" ]; then + fallow dead-code --no-cache + else + fallow dead-code --no-cache || echo "WARN: fallow reported dead-code findings (advisory)." + fi + fi + + - name: qlty-check + run: | + if ! command -v qlty >/dev/null 2>&1; then + echo "WARN: qlty not installed; skipping Qlty lint." + if [ "${LEFTHOOK_STRICT:-0}" = "1" ]; then exit 1; fi + exit 0 + fi + if [ ! -f .qlty/qlty.toml ]; then + echo "WARN: .qlty/qlty.toml not found; skipping Qlty check (run qlty init)." + exit 0 fi + qlty check --no-progress || echo "WARN: qlty reported lint findings (advisory)." diff --git a/typos.toml b/typos.toml new file mode 100644 index 0000000..2a19587 --- /dev/null +++ b/typos.toml @@ -0,0 +1,28 @@ +# Managed by Heretek-AI/.github fleet-sync — Standardized typos configuration +# Spec: https://github.com/crate-ci/typos/blob/master/docs/reference.md + +[files] +extend-exclude = [ + "*.lock", + "*.min.js", + "*.min.css", + "*.sarif", + "docs/evidence/**", + "docs/reports/**", + "CHANGELOG.md", +] + +[default.extend-words] +heretek = "heretek" +Heretek = "Heretek" +zizmor = "zizmor" +aislop = "aislop" +secfoo = "secfoo" +rumdl = "rumdl" +tombi = "tombi" +skylos = "skylos" +deptry = "deptry" +lefthook = "lefthook" +opencode = "opencode" +sarif = "sarif" +SARIF = "SARIF"