```yaml
version: 1
meta:
  name: security-scan
  description: >
    Scan a repository for leaked secrets, personal information, and exploitable
    vulnerabilities, and produce a triaged findings report. Read-only: the loop
    never modifies the target repository.
  author: looper-pattern-library
  created: 2026-07-05

goal:
  statement: >
    Review the source of {{TARGET_REPO}} (working tree AND full git history)
    for security exposures - hardcoded API keys / tokens / credentials,
    personal information (PII), and exploitable code vulnerabilities - and
    produce SECURITY-FINDINGS.md where every finding is typed, severity-rated,
    located at file:line (and commit for history hits), and given a
    remediation note.
  context_sources:
    # The repo is not on disk yet. This clone (not shallow, so history is
    # available) lands in the throwaway workspace dir before the plan draft.
    - cmd: "git clone {{TARGET_REPO}} loop-workspace/repo"
      timeout_sec: 300
  definition_of_done: >
    SECURITY-FINDINGS.md exists and (1) covers secrets, PII, and
    vulnerabilities, (2) has zero unresolved candidates - each is either
    confirmed with severity + location + remediation, or dismissed with a
    stated reason, (3) contains no TBD or placeholder text, and (4) every
    confirmed vulnerability is exploitable as described, not speculative.
  verification:
    - id: prog-scan-ran
      type: programmatic
      # Deterministic secret/PII candidate sweep over working tree + history.
      check: ["python", "scripts/scan-secrets.py", "loop-workspace/repo", "--out", "loop-workspace/candidates.json"]
      expect: exit_zero
    - id: findings-schema
      type: programmatic
      # Structural check: every finding has type, severity, location, remediation; no TBDs.
      check: ["python", "scripts/check-findings.py", "loop-workspace/SECURITY-FINDINGS.md"]
      expect: exit_zero
    - id: plan-sound
      type: judge
      rubric: >
        The scan-plan.md names every area to inspect (secrets, PII,
        vulnerabilities), states how git history will be covered, lists the
        file groups / languages present in loop-workspace/repo, and depends
        only on context the loop actually gathers. Verdict revise if any of
        the three security areas is unaddressed or history coverage is
        undefined.
    - id: triage-complete
      type: judge
      rubric: >
        Judge SECURITY-FINDINGS.md against loop-workspace/candidates.json.
        Every candidate from the programmatic sweep appears in the report as
        either CONFIRMED (with severity, file:line/commit, and remediation)
        or DISMISSED (with a concrete reason such as "example value in
        README" or "test fixture"). No candidate is left untriaged and no
        entry contains TBD. Return verdict pass only when zero candidates
        are unresolved.
    - id: vuln-soundness
      type: judge
      rubric: >
        For each vulnerability in SECURITY-FINDINGS.md, confirm it is
        exploitable as described given the surrounding code (e.g. unsanitized
        input reaching a sink, missing authz check on a real route). Mark
        verdict revise for any finding that is speculative, mislocated, or
        already mitigated by nearby code.

host:
  cli: claude
  model: default
  invoke: ["claude", "-p"]
  timeout_sec: 600

council:
  # Local-family judge - gates the plan and final report. Same host family is
  # acceptable here because the judge task (real secret vs placeholder,
  # exploitable vs speculative) is near-objective and keeps content on-machine.
  - id: judge-1
    role: judge
    cli: claude
    model: default
    invoke: ["claude", "-p"]
    timeout_sec: 600
    scope: [plan, delivery]
    local: false
  # Cross-vendor adversarial reviewer - NOTES ONLY, scoped to vulnerability
  # snippets. Cannot clean a gate. First send is consent-gated at runtime;
  # secret/PII values and redaction-glob files never reach it.
  - id: vuln-reviewer
    role: reviewer
    cli: codex
    model: default
    invoke: ["codex", "exec"]
    timeout_sec: 600
    scope: [delivery]
    local: false

gates:
  plan_gate:
    when: after_plan
    members: [judge-1]
    verdict_policy: revise_until_clean
    verdict_source: judge-1
    criteria: [plan-sound]
    max_revisions: 2
  delivery_gate:
    when: after_each_delivery
    members: [judge-1, vuln-reviewer]
    verdict_policy: revise_until_clean
    verdict_source: judge-1
    criteria: [prog-scan-ran, findings-schema, triage-complete, vuln-soundness]
    max_revisions: 2

loop_control:
  max_iterations: 10
  budget:
    usd: 5.0
    tokens: 2000000
    wall_clock_min: 30
  no_progress:
    max_stalled_iterations: 2
    signals:
      - same blocking issue repeats across iterations
      - SECURITY-FINDINGS.md has no material change after a revise verdict
      - the same candidate stays untriaged
    action: stop
  human_checkpoints:
    - before first cross-vendor send to vuln-reviewer
  stop_conditions:
    - delivery_gate passes clean (all four criteria) on SECURITY-FINDINGS.md
    - max_iterations reached
    - same blocker repeats for 2 iterations
    - any budget cap exceeded

execution:
  mode: in_session
  # The loop writes only inside ./loop-workspace. The target repo is cloned
  # into the gitignored throwaway loop-workspace/repo and is never modified.
  isolation: current_workspace
  side_effects:
    requires_approval: true
    duplicate_action_check: true
    notes: >
      Only side effects are (1) git clone of the target repo into the
      throwaway dir and (2) the consent-gated cross-vendor send. No pushes,
      no writes to the target repo.

observability:
  state_file: state.json
  run_log: run-log.md
  checkpoint_granularity: gate

privacy:
  egress:
    - to: judge-1
      sends: [plan, findings-report]
      redact: [".env", ".env.*", "secrets/**", "**/*.key"]
      consent: required
    - to: vuln-reviewer
      # Only vulnerability code snippets - never raw secret/PII values.
      sends: [vulnerability-snippets]
      redact: [".env", ".env.*", "secrets/**", "**/*.key"]
      consent: required

workspace:
  dir: ./loop-workspace
  layout:
    - repo/                 # throwaway clone of the target (gitignored, read-only)
    - scan-plan.md          # host plan, gated by plan_gate
    - candidates.json       # programmatic secret/PII sweep output
    - "findings-draft-{n}.md"
    - "review-{n}.md"       # judge + reviewer notes per iteration
    - SECURITY-FINDINGS.md  # final deliverable
    - state.json
    - run-log.md
```

---

Copyright (c) 2026 Kevin Simback License files are attached. [MIT](https://knowen.md/f/0cf2b407-a5a2-4840-bbfc-2450c7693b96)

### MIT notice

````text
MIT License

Copyright (c) 2026 Kevin Simback

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
````