diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..92be7d5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,19 @@ +## AI assistance + +Which AI tool and model were used? Write `None` if no AI was used. + +## What changed + +Describe the change and its purpose. + +## How verified + +List the checks run and their results. Explain any checks that could not run. + +## Why + + + +## Risk + + diff --git a/.github/governance/policy.json b/.github/governance/policy.json new file mode 100644 index 0000000..5b548f7 --- /dev/null +++ b/.github/governance/policy.json @@ -0,0 +1,23 @@ +{ + "version": "pr-governance/v3", + "mode": "enforce", + "review_routing": { + "dispatch_mentions": [ + "@codex review", + "@claude review" + ] + }, + "r0_paths": [ + "README.md", + "CHANGELOG.md", + "docs/prose/" + ], + "r2_paths": [ + "scripts/", + ".github/governance/", + ".github/scripts/", + "src/" + ], + "dependabot_template_exemption": true, + "max_evidence_age_hours": 168 +} diff --git a/.github/workflows/codex-nudge.yml b/.github/workflows/codex-nudge.yml new file mode 100644 index 0000000..602c8b2 --- /dev/null +++ b/.github/workflows/codex-nudge.yml @@ -0,0 +1,36 @@ +name: Review request + +# Copy to .github/workflows/codex-nudge.yml and replace Pigbibi/PrGovernance. +# Nudges Codex then Claude (see policy.review_routing). Cursor Bugbot must be +# triggered by a human (`cursor review` / `bugbot run`); bot-posted triggers are ignored. +# Optional org var GOVERNANCE_REVIEWERS_JSON overrides reviewer identities. + +on: + schedule: + - cron: '15 2,14 * * *' + workflow_dispatch: + +permissions: + contents: read + # createComment on a pull request needs pull-requests:write; issues:write + # alone returns 403 Resource not accessible by integration. + pull-requests: write + issues: write + +concurrency: + group: review-request + cancel-in-progress: false + +jobs: + nudge: + name: Request a review + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Request + uses: Pigbibi/PrGovernance/pr-governance@7fe2ee20a3ee144ea944619e1c56f7ed5edc9152 + env: + GOVERNANCE_REVIEWERS_JSON: ${{ vars.GOVERNANCE_REVIEWERS_JSON }} + GOVERNANCE_DISPATCH_MENTIONS_JSON: ${{ vars.GOVERNANCE_DISPATCH_MENTIONS_JSON }} + with: + mode: nudge diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml new file mode 100644 index 0000000..3e263cd --- /dev/null +++ b/.github/workflows/docs-check.yml @@ -0,0 +1,30 @@ +name: Documentation check + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: docs-check-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + policy: + uses: QuantStrategyLab/.github/.github/workflows/docs-acceptance.yml@b4966bdd8780cad3ae5154ae50d8b98259a16dc6 + with: + policy-revision: b4966bdd8780cad3ae5154ae50d8b98259a16dc6 + mode: advisory + + docs: + name: Documentation check + needs: policy + if: always() + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Require documentation policy acceptance + run: test "${{ needs.policy.result }}" = "success" diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..b9c6cb1 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,73 @@ +name: Shared Gitleaks scan + +on: + workflow_call: + inputs: + full-history: + description: Scan all fetched branches and their complete history + type: boolean + required: false + default: false + +permissions: + contents: read + +jobs: + scan: + name: Gitleaks + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Check out the caller with full history + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + fetch-depth: 0 + persist-credentials: false + path: source + - name: Check out trusted scanner and shared configuration + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + repository: QuantStrategyLab/.github + # Pin the helper commit; changes to helpers require an explicit pin update. + ref: 0da4da68433b803cda17d3f84e29875a94a32273 + persist-credentials: false + path: secret-scan-tools + - name: Install checksum-verified Gitleaks + run: bash secret-scan-tools/scripts/install-gitleaks.sh "$RUNNER_TEMP/shared-gitleaks" + - name: Fetch every branch, including logs and state + if: inputs.full-history + working-directory: source + run: git fetch origin '+refs/heads/*:refs/remotes/origin/*' + - name: Scan with shared rules and redacted output + id: scan + shell: bash + env: + FULL_HISTORY: ${{ inputs.full-history }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + PR_HEAD: ${{ github.event.pull_request.head.sha }} + PUSH_BASE: ${{ github.event.before }} + PUSH_HEAD: ${{ github.sha }} + run: | + set -euo pipefail + log_opts=--all + if [[ "$FULL_HISTORY" != true ]]; then + base="${PR_BASE:-$PUSH_BASE}" + head="${PR_HEAD:-$PUSH_HEAD}" + if [[ -z "$base" || "$base" =~ ^0+$ || -z "$head" ]]; then + echo 'Missing comparison commits; refusing an incomplete scan' >&2 + exit 2 + fi + log_opts="$base..$head" + fi + python3 secret-scan-tools/scripts/scan-secrets.py git source \ + --gitleaks "$RUNNER_TEMP/shared-gitleaks/gitleaks" \ + --log-opts="$log_opts" \ + --summary "$RUNNER_TEMP/gitleaks-summary/summary.json" + - name: Upload only the path and rule summary + if: ${{ !cancelled() && inputs.full-history && steps.scan.outcome != 'skipped' }} + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: gitleaks-history-summary-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ runner.temp }}/gitleaks-summary/summary.json + if-no-files-found: error + retention-days: 3 diff --git a/.github/workflows/pr-review-signal.yml b/.github/workflows/pr-review-signal.yml new file mode 100644 index 0000000..0d9fc3b --- /dev/null +++ b/.github/workflows/pr-review-signal.yml @@ -0,0 +1,25 @@ +name: PR review signal + +# Copy to .github/workflows/pr-review-signal.yml and replace nothing: this +# workflow holds no permissions and runs no repository code. It exists because a +# review event on a fork or Dependabot pull request gets a read-only token, so +# the gate that publishes statuses has to be started by `workflow_run` instead. +# Keep the workflow name; risk-gate.yml refers to it. + +on: + pull_request_review: + types: [submitted, edited, dismissed] + pull_request_review_comment: + types: [created, edited, deleted] + +permissions: + contents: read + +jobs: + signal: + name: Signal review change + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Signal + run: echo "review event recorded" diff --git a/.github/workflows/risk-gate.yml b/.github/workflows/risk-gate.yml new file mode 100644 index 0000000..7f4c1e8 --- /dev/null +++ b/.github/workflows/risk-gate.yml @@ -0,0 +1,100 @@ +name: PR risk gate + +# Copy to .github/workflows/risk-gate.yml and replace Pigbibi/PrGovernance with +# the owner's governance repository (for example Pigbibi/PrGovernance). +# The job names in this file are the required status check contexts; keep them. + +on: + pull_request_target: + types: [opened, reopened, synchronize, edited, labeled, unlabeled, ready_for_review, closed] + issue_comment: + types: [created, edited, deleted] + # A review or inline comment on a fork or Dependabot pull request gets a + # read-only token, so those events are relayed through the permissionless + # `PR review signal` workflow and evaluated by this trusted run. + workflow_run: + workflows: ["PR review signal"] + types: [completed] + push: + branches: [main, master] + # A merge made with GITHUB_TOKEN raises no push, and nothing raises an event + # for a resolved review thread, so a sweep closes both gaps. + schedule: + - cron: '17 3 * * *' + workflow_dispatch: + inputs: + pr_number: + description: Existing pull request number to evaluate + required: true + type: string + +# The gate reads metadata only. It never checks out or runs pull request code. +permissions: + contents: read + pull-requests: read + issues: read + statuses: write + actions: write + +jobs: + # The labeled payload is the only authenticated record of which head a + # clearing label was added to. Recording it in its own job keeps the evidence + # independent of an evaluation that a later event may supersede. + record_label: + name: Record the head a clearing label was added to + if: github.event_name == 'pull_request_target' && github.event.action == 'labeled' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + issues: read + pull-requests: read + statuses: write + steps: + - name: Record label head + uses: Pigbibi/PrGovernance/pr-governance@7fe2ee20a3ee144ea944619e1c56f7ed5edc9152 + env: + GOVERNANCE_OWNER_ID: ${{ vars.RISK_GATE_OWNER_ID }} + GOVERNANCE_OWNER_LOGIN: ${{ vars.RISK_GATE_OWNER }} + with: + mode: gate + record-label: 'true' + + evaluate: + name: Evaluate PR governance + needs: record_label + # A skipped recorder is the normal case for every other event. + if: >- + always() && needs.record_label.result != 'cancelled' && + (github.event_name != 'issue_comment' || + (github.event.issue.pull_request && + (github.event.comment.user.type == 'Bot' || + contains(github.event.comment.body || '', 'codex-review') || + contains(github.event.comment.body || '', 'ai-review-receipt')))) + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + pull-requests: read + issues: read + statuses: write + actions: write + # Job-level, so an irrelevant comment skips the job without cancelling an + # evaluation already running. Label evidence no longer rides on this run. + concurrency: + group: pr-governance-${{ github.event.pull_request.number || github.event.issue.number || github.event.workflow_run.pull_requests[0].number || inputs.pr_number || github.run_id }} + cancel-in-progress: true + steps: + - name: Evaluate + uses: Pigbibi/PrGovernance/pr-governance@7fe2ee20a3ee144ea944619e1c56f7ed5edc9152 + env: + GOVERNANCE_OWNER_ID: ${{ vars.RISK_GATE_OWNER_ID }} + GOVERNANCE_OWNER_LOGIN: ${{ vars.RISK_GATE_OWNER }} + # Optional: a repository that keeps account identifiers out of public + # source configures the reviewer here instead of in policy.json. + GOVERNANCE_REVIEWER_APP_ID: ${{ vars.RISK_GATE_REVIEWER_APP_ID }} + GOVERNANCE_REVIEWER_USER_ID: ${{ vars.RISK_GATE_REVIEWER_USER_ID }} + GOVERNANCE_REVIEWER_LOGIN: ${{ vars.RISK_GATE_REVIEWER_LOGIN }} + GOVERNANCE_REVIEWERS_JSON: ${{ vars.GOVERNANCE_REVIEWERS_JSON }} + with: + mode: gate + record-label: 'false' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41e3b76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +__pycache__/ +*.pyc +.pytest_cache/ +.ruff_cache/ +.DS_Store + +# AI assistant / agent local state +.claude/ +.codex/ +.cursor/ +.cursorrules +.worktrees/ +worktrees/ + +# Keep AI rule entrypoints tracked even when global gitignore excludes Markdown +!AGENTS.md +!CLAUDE.md + +# Local working notes & internal process records (never commit) +.local/ +ops-notes/ +*.local.md +*.internal.md +*[Aa][Uu][Dd][Ii][Tt]*.md +*[Hh][Aa][Nn][Dd][Oo][Ff][Ff]*.md +*-[Rr][Ee][Vv][Ii][Ee][Ww]-*.md +*_[Rr][Ee][Vv][Ii][Ee][Ww]_*.md +docs/audits/ +docs/plans/ +docs/handoffs/ +docs/superpowers/ +docs/changes/ +docs/acceptance-policy.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d2272c4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/gitleaks/gitleaks + rev: 83d9cd684c87d95d656c1458ef04895a7f1cbd8e # v8.30.1 + hooks: + - id: gitleaks + args: [--redact] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.0 + hooks: + - id: ruff + args: [--fix] diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e9584be --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,44 @@ +# AGENTS.md + +Rules for AI assistants and maintainers in `QuantStrategyLab/FuseControl`. Reusable PR governance actions live in `Pigbibi/PrGovernance`. + +## What this repository is + +FUSE breaker specification and reference engine for QuantStrategyLab (`FUSE-1`). + +## Layout + +- `README.md` — FUSE-1 scope, coordination status, and safety posture. +- `.github/governance/policy.json` — PR governance policy (`pr-governance/v3`). + +## Local checks + +```sh +python3 -m unittest discover -s tests -p "test_*.py" +``` + +## Naming and documentation + +- English is default; document filenames use lowercase kebab-case (`README.md`, `AGENTS.md`, `CLAUDE.md` keep standard casing). +- Update `README.md` only when user-visible behavior, CLI, or configuration changes; never append PR narration or sections after `## License`. + + +- Public repositories (with `LICENSE`) include `CONTRIBUTING.md`, `SECURITY.md`, `CODE_OF_CONDUCT.md`, and issue/PR templates (`pull_request_template.md`). +- Public `SECURITY.md` covers disclosure only; never mix private rotation procedures into public files. + + +## Do not + +- Do not enable live trading, Kelly sizing, or stop-loss arming (`loss_breakers_armed: false`). +- Do not delete or archive active coordination branches or status notes. +- Do not commit `docs/plans/`, `docs/audits/`, `docs/changes/`, or `docs/acceptance-policy.md`. + + +- Public material carries no real resource names or accounts: use synthetic placeholders (``, ``). +- Judge whether a change is clean by `git diff` and `git ls-files`; `.gitignore` affects untracked files only. + + +## Commits and pull requests + +- Use English Conventional Commits (`feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`) with headers ≤ 72 characters. +- Fill in PR template sections (`AI assistance`, `What changed`, `How verified`, `Risk`). R2 paths require green CI, `ai-review` on the exact head SHA, and one clearing label (`agent-approved` or `owner-approved`). Never push to `main` or use `--admin`. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..43c994c --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..93b61c7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,39 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We pledge to make participation in our project a harassment-free experience for +everyone, regardless of age, body size, visible or invisible disability, +ethnicity, sex characteristics, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, caste, color, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to a positive environment: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community + +Examples of unacceptable behavior: + +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement + +Maintainers are responsible for clarifying and enforcing acceptable behavior and +will take fair corrective action in response to any behavior they deem +inappropriate, threatening, offensive, or harmful. Instances of unacceptable +behavior may be reported by contacting the repository maintainers through +GitHub Private Vulnerability Reporting or repository advisories. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 2.1, +available at . diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..66f73c1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +# Contributing + +Thanks for contributing to QuantStrategyLab repositories. + +Documentation follows the [QuantStrategyLab documentation style guide](https://github.com/QuantStrategyLab/.github/blob/main/docs/STYLE_GUIDE.md). + +## Workflow + +1. Branch from `origin/main` using a short prefix such as `feat/`, `fix/`, `docs/`, `refactor/`, `test/`, or `chore/`. +2. Keep pull requests focused and run the local style and script checks before pushing: + +```sh +python3 scripts/test_style.py +python3 scripts/check_style.py --phase 2 +``` + +3. Use English Conventional Commits (`feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`) with commit headers at most 72 characters. +4. Fill in every section of `.github/PULL_REQUEST_TEMPLATE.md`. + +## Security and Content Hygiene + +- Never commit `.local/`, `ops-notes/`, `docs/plans/`, `docs/audits/`, `docs/handoffs/`, `docs/changes/`, `docs/acceptance-policy.md`, or real credentials, account IDs, and infrastructure identifiers. +- See [SECURITY.md](SECURITY.md) for private vulnerability reporting. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b116a36 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 QuantStrategyLab + +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. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..0a781fb --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,29 @@ +# Security policy + +This repository holds the organisation's shared GitHub configuration. The policy +below covers every repository under the organisation, not only this one. + +## Reporting a vulnerability + +Report through GitHub private vulnerability reporting on the repository +concerned, or through the owner's published GitHub profile contact method. Do not +open a public issue for a vulnerability, and do not include credentials, account +identifiers, private session data or customer records in a report. + +Include the repository, the affected version or commit, the impact you observed, +and the smallest reproduction that still shows it. Redact anything that is not +needed to reproduce. + +## Scope + +A report about a documentation repository or a shared workflow is in scope when +it would let someone change what a build or a published document says. A report +about a live deployment belongs with the repository that owns the deployment; +credential storage and rotation procedures live in the private operations +repository, not in public security policies. + +## What happens next + +The maintainer acknowledges a report on a best-effort basis and coordinates the +fix and the disclosure timing with you. There is no bounty and no guaranteed +response time.