Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions .agents/skills/adversarial-claim-check/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name> 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
Comment thread
BillyOutlast marked this conversation as resolved.
Resolved
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 `|| :`.
41 changes: 32 additions & 9 deletions .agents/skills/evidence-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<user>/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:]"'"'"'`<>]+/'
Comment thread
BillyOutlast marked this conversation as resolved.
Resolved

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/<user>/src/other-repo`, `file:///<home>/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.
Comment thread
BillyOutlast marked this conversation as resolved.
Resolved

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:
Expand All @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions .agents/skills/hygiene-and-workflow-audit/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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.
66 changes: 66 additions & 0 deletions .agents/skills/ocr-thread-resolution/SKILL.md
Original file line number Diff line number Diff line change
@@ -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 <owner/repo> <pr-number>
```

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 <thread-id> --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.
20 changes: 13 additions & 7 deletions .agents/skills/security-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Comment thread
BillyOutlast marked this conversation as resolved.
Resolved
- 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.

Expand All @@ -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 <file>:<line>`
- **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.
Loading
Loading