|
| 1 | +name: Long Horizon Shadow Signal |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + provider: |
| 7 | + description: "Bridge provider" |
| 8 | + required: false |
| 9 | + type: choice |
| 10 | + default: "auto" |
| 11 | + options: |
| 12 | + - auto |
| 13 | + - api |
| 14 | + - anthropic |
| 15 | + - codex |
| 16 | + - openai |
| 17 | + source_ref: |
| 18 | + description: "Ref to pass to CodexAuditBridge" |
| 19 | + required: false |
| 20 | + default: "main" |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + issues: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + dispatch-shadow-signal: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + env: |
| 30 | + BRIDGE_REPOSITORY: ${{ vars.SELFHOSTED_CODEX_REVIEW_REPOSITORY || 'QuantStrategyLab/CodexAuditBridge' }} |
| 31 | + BRIDGE_TASK: long_horizon_signal_shadow |
| 32 | + BRIDGE_PROVIDER: ${{ inputs.provider || 'auto' }} |
| 33 | + SOURCE_REF: ${{ inputs.source_ref || 'main' }} |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v6 |
| 36 | + |
| 37 | + - uses: actions/setup-python@v6 |
| 38 | + with: |
| 39 | + python-version: "3.11" |
| 40 | + |
| 41 | + - name: Validate existing latest signal if present |
| 42 | + run: python scripts/validate_latest_signal.py --allow-missing |
| 43 | + |
| 44 | + - name: Detect GitHub App Credentials |
| 45 | + id: app_credentials |
| 46 | + env: |
| 47 | + APP_ID: ${{ vars.CROSS_REPO_GITHUB_APP_ID }} |
| 48 | + APP_PRIVATE_KEY: ${{ secrets.CROSS_REPO_GITHUB_APP_PRIVATE_KEY }} |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | + if [ -n "${APP_ID:-}" ] && [ -n "${APP_PRIVATE_KEY:-}" ]; then |
| 52 | + echo "available=true" >> "$GITHUB_OUTPUT" |
| 53 | + else |
| 54 | + echo "available=false" >> "$GITHUB_OUTPUT" |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Create GitHub App Token For Bridge Repository |
| 58 | + id: bridge_app_token |
| 59 | + if: steps.app_credentials.outputs.available == 'true' |
| 60 | + continue-on-error: true |
| 61 | + uses: actions/create-github-app-token@v3 |
| 62 | + with: |
| 63 | + app-id: ${{ vars.CROSS_REPO_GITHUB_APP_ID }} |
| 64 | + private-key: ${{ secrets.CROSS_REPO_GITHUB_APP_PRIVATE_KEY }} |
| 65 | + owner: ${{ github.repository_owner }} |
| 66 | + repositories: | |
| 67 | + CodexAuditBridge |
| 68 | + permission-actions: write |
| 69 | + |
| 70 | + - name: Create shadow signal issue and dispatch bridge |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ github.token }} |
| 73 | + APP_TOKEN: ${{ steps.bridge_app_token.outputs.token }} |
| 74 | + CODEX_AUDIT_DISPATCH_TOKEN: ${{ secrets.CODEX_AUDIT_DISPATCH_TOKEN }} |
| 75 | + run: | |
| 76 | + python - <<'PY' |
| 77 | + import json |
| 78 | + import os |
| 79 | + import urllib.request |
| 80 | + import urllib.error |
| 81 | +
|
| 82 | + repo = os.environ["GITHUB_REPOSITORY"] |
| 83 | + bridge_repo = os.environ["BRIDGE_REPOSITORY"] |
| 84 | + token = os.environ["GH_TOKEN"] |
| 85 | + dispatch_token = os.environ.get("APP_TOKEN") or os.environ.get("CODEX_AUDIT_DISPATCH_TOKEN") |
| 86 | + if not dispatch_token: |
| 87 | + raise SystemExit("Bridge dispatch requires a GitHub App token or CODEX_AUDIT_DISPATCH_TOKEN") |
| 88 | +
|
| 89 | + def request(method, url, payload=None, auth_token=token): |
| 90 | + data = json.dumps(payload).encode("utf-8") if payload is not None else None |
| 91 | + req = urllib.request.Request( |
| 92 | + url, |
| 93 | + data=data, |
| 94 | + method=method, |
| 95 | + headers={ |
| 96 | + "Authorization": f"Bearer {auth_token}", |
| 97 | + "Accept": "application/vnd.github+json", |
| 98 | + "Content-Type": "application/json", |
| 99 | + }, |
| 100 | + ) |
| 101 | + with urllib.request.urlopen(req, timeout=60) as response: |
| 102 | + body = response.read().decode("utf-8") |
| 103 | + return response.status, json.loads(body) if body else None |
| 104 | +
|
| 105 | + issue_body = "\n".join([ |
| 106 | + "## Long-Horizon Shadow Signal Request", |
| 107 | + "", |
| 108 | + f"- Source ref: `{os.environ['SOURCE_REF']}`", |
| 109 | + "- Mode: `shadow`", |
| 110 | + "- Required output: `data/output/latest_signal.json`", |
| 111 | + "- AI output must not place orders or change live strategy rules.", |
| 112 | + "", |
| 113 | + "## Context", |
| 114 | + "", |
| 115 | + "Use repository examples and any committed context bundles as evidence.", |
| 116 | + "If evidence is insufficient, report findings and do not edit artifacts.", |
| 117 | + ]) |
| 118 | + _, issue = request( |
| 119 | + "POST", |
| 120 | + f"https://api.github.com/repos/{repo}/issues", |
| 121 | + {"title": "Long-horizon AI shadow signal review", "body": issue_body}, |
| 122 | + ) |
| 123 | +
|
| 124 | + dispatch_payload = { |
| 125 | + "ref": "main", |
| 126 | + "inputs": { |
| 127 | + "source_repo": repo, |
| 128 | + "issue_number": str(issue["number"]), |
| 129 | + "source_ref": os.environ["SOURCE_REF"], |
| 130 | + "mode": "review_and_fix", |
| 131 | + "provider": os.environ["BRIDGE_PROVIDER"], |
| 132 | + "task": os.environ["BRIDGE_TASK"], |
| 133 | + "auto_merge": "false", |
| 134 | + }, |
| 135 | + } |
| 136 | + status, _ = request( |
| 137 | + "POST", |
| 138 | + f"https://api.github.com/repos/{bridge_repo}/actions/workflows/selfhosted_monthly_review.yml/dispatches", |
| 139 | + dispatch_payload, |
| 140 | + auth_token=dispatch_token, |
| 141 | + ) |
| 142 | + if status not in (201, 204): |
| 143 | + raise RuntimeError(f"unexpected dispatch status: {status}") |
| 144 | + print(f"Created issue #{issue['number']} and dispatched {bridge_repo}") |
| 145 | + PY |
0 commit comments