Skip to content

Commit bc863b2

Browse files
committed
fix: add AI strategy review workflow
1 parent 37567c1 commit bc863b2

7 files changed

Lines changed: 393 additions & 60 deletions

.github/workflows/ai_review.yml

Lines changed: 121 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,124 @@ name: AI Monthly Review
33
"on":
44
issues:
55
types: [opened]
6+
workflow_dispatch:
7+
inputs:
8+
issue_number:
9+
description: "Issue number to review"
10+
required: true
611

712
jobs:
813
ai-review:
9-
if: contains(github.event.issue.labels.*.name, 'monthly-review')
14+
if: contains(github.event.issue.labels.*.name, 'monthly-review') || inputs.issue_number != ''
1015
runs-on: ubuntu-latest
1116
permissions:
12-
contents: write
17+
contents: read
18+
id-token: write
1319
issues: write
14-
pull-requests: write
1520

1621
steps:
1722
- name: Checkout
1823
uses: actions/checkout@v5
1924

25+
- name: Load review issue context
26+
id: issue_context
27+
run: |
28+
python3 - <<'PY'
29+
import json
30+
import os
31+
import urllib.request
32+
33+
repo = os.environ["GITHUB_REPOSITORY"]
34+
issue_number = os.environ["ISSUE_NUMBER"]
35+
token = os.environ["GITHUB_TOKEN"]
36+
api_url = f"https://api.github.com/repos/{repo}/issues/{issue_number}"
37+
request = urllib.request.Request(
38+
api_url,
39+
headers={
40+
"Accept": "application/vnd.github+json",
41+
"Authorization": f"Bearer {token}",
42+
"X-GitHub-Api-Version": "2022-11-28",
43+
"User-Agent": "crypto-leader-rotation-ai-review",
44+
},
45+
)
46+
with urllib.request.urlopen(request) as response:
47+
issue = json.load(response)
48+
49+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
50+
print("issue_title<<EOF", file=output)
51+
print(issue["title"], file=output)
52+
print("EOF", file=output)
53+
print("issue_body<<EOF", file=output)
54+
print(issue["body"], file=output)
55+
print("EOF", file=output)
56+
PY
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
ISSUE_NUMBER: ${{ inputs.issue_number || github.event.issue.number }}
60+
2061
- name: Run Claude Code Review
62+
id: claude_review
2163
uses: anthropics/claude-code-action@v1
2264
with:
2365
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
24-
model: claude-sonnet-4-6-20250514
66+
github_token: ${{ secrets.GITHUB_TOKEN }}
2567
use_bedrock: false
2668
use_vertex: false
27-
allowed_tools: |
28-
Read
29-
Glob
30-
Grep
31-
Bash(git log:*)
32-
Bash(git diff:*)
33-
Bash(python:*)
34-
custom_instructions: |
35-
You are reviewing the monthly upstream release report for CryptoLeaderRotation,
36-
a research and release system that publishes a monthly 5-symbol Binance Spot
37-
leader universe to its downstream execution engine (BinanceQuant).
38-
39-
The Issue body contains the full monthly report (ai_review_input.md).
40-
Analyze it and provide your review in BOTH English and Chinese.
69+
prompt: |
70+
Do not use Bash or ask for additional approval.
71+
Return only the final bilingual review in markdown.
72+
The workflow will publish your final review as the issue comment.
73+
74+
You are reviewing the monthly upstream selector report for CryptoLeaderRotation.
75+
This repository owns monthly universe selection, ranking, challenger evaluation,
76+
and publication of a 5-symbol Binance Spot leader pool for downstream execution.
77+
78+
This is a strategy-optimization review, not only a release QA check.
79+
Your job is to help the operator judge:
80+
- whether the published official pool looks internally consistent and research-valid,
81+
- whether the current evidence is sufficient to keep or change the selector,
82+
- what the next highest-value shadow/challenger experiments should be.
83+
84+
Important interpretation rules:
85+
- Do not recommend changing production selector logic from one monthly snapshot alone.
86+
- If shadow or challenger tracks are missing, say evidence is incomplete rather than making strong claims.
87+
- Treat release consistency and validation as a prerequisite, but spend most attention on selector quality and research direction.
88+
- BinancePlatform is a downstream execution engine that consumes this 5-symbol pool and then selects its own final live targets from it.
89+
90+
## Issue Title
91+
${{ steps.issue_context.outputs.issue_title }}
92+
93+
## Issue Body
94+
${{ steps.issue_context.outputs.issue_body }}
4195
4296
## Review Scope
4397
44-
1. **Release Consistency Check**
45-
- Do live_pool.json, release_manifest.json, and release_status_summary.json agree
46-
on as_of_date, version, mode, pool_size, and symbols?
47-
- Is the validation status ok with no errors?
48-
- Are there any warnings that need operator attention?
49-
50-
2. **Anomaly Detection**
51-
- Are any artifact ages unexpectedly high (age_days > 7)?
52-
- Is dry_run=True expected or a sign that publish was not actually enabled?
53-
- Are ranking scores reasonable (no extreme values or suspicious clustering)?
54-
- Is pool_size consistent with the expected value (5)?
55-
56-
3. **Downstream Impact (BinanceQuant)**
57-
- BinanceQuant is a downstream execution engine that selects the top 2 symbols
58-
from this pool for trend rotation trading on Binance Spot.
59-
- Note any symbols that are new to the pool vs last month (if determinable from context).
60-
- Flag if any pool symbols might have low liquidity or high volatility concerns
61-
for a real-money execution system.
62-
- Remind the operator that pool changes will affect live positions at the next
63-
BinanceQuant hourly cycle after the Firestore document updates.
64-
65-
4. **Operator Action Items**
66-
- Summarize the operator checklist items from the report.
67-
- Add any additional follow-up items based on your analysis.
68-
- If publish was a dry run, note that the operator should confirm whether
69-
a real publish is intended.
70-
71-
5. **Code Improvements (Optional)**
72-
- If you identify concrete, low-risk improvements to scripts or configuration
73-
in this repository, you may open a Pull Request.
74-
- Do NOT modify strategy logic, ranking parameters, or universe filters.
75-
- Acceptable improvements: documentation, validation checks, error messages,
76-
report formatting, workflow configuration.
77-
- Do NOT auto-merge. The operator will review and decide.
98+
1. **Release Consistency & Contract Health**
99+
- Do release metadata, symbols, pool_size, version, and validation state agree?
100+
- Are there any warnings, stale artifacts, or publish flags that weaken trust in this release?
101+
102+
2. **Selector Quality Review**
103+
- Does the official 5-symbol pool look reasonable for a Binance Spot mainstream leader universe?
104+
- Does the ranking preview show healthy score separation, or suspicious clustering/tie behavior?
105+
- Are any symbols potentially borderline on liquidity, stability, or crowding risk for downstream live use?
106+
107+
3. **Research Coverage & Evidence Gaps**
108+
- Is shadow/challenger coverage present?
109+
- If not present, explicitly say that strategy-optimization evidence is incomplete.
110+
- If present, explain whether official baseline still looks justified versus challengers.
111+
112+
4. **Downstream Impact (BinancePlatform)**
113+
- What are the likely downstream implications for BinancePlatform, which consumes this pool monthly?
114+
- Highlight any pool changes or symbol characteristics that could affect downstream rotation behavior or turnover.
115+
116+
5. **Strategy Optimization Directions**
117+
- Suggest the 1-3 highest-value next research directions in this repository.
118+
- Prefer ideas such as challenger track design, shadow build coverage, ranking weight review, regime-weight review, universe-filter tuning, and validation additions.
119+
- Do not suggest arbitrary complexity; prioritize explainable, low-risk, testable improvements.
120+
121+
6. **Operator Action Items**
122+
- Summarize immediate operator checks for this month.
123+
- Separate "safe to keep production as-is" from "needs more research evidence".
78124
79125
## Output Format
80126
@@ -85,25 +131,40 @@ jobs:
85131
86132
### Release Consistency
87133
...
88-
### Anomalies
134+
### Selector Quality
89135
...
90-
### Downstream Impact (BinanceQuant)
136+
### Research Coverage Gaps
91137
...
92-
### Operator Action Items
138+
### Downstream Impact (BinancePlatform)
93139
...
94-
### Code Improvement Suggestions
140+
### Strategy Optimization Directions
141+
...
142+
### Operator Action Items
95143
...
96144
97145
---
98146
## 中文
99147
100148
### 发布一致性检查
101149
...
102-
### 异常检测
150+
### 选币器质量评估
103151
...
104-
### 下游影响(BinanceQuant)
152+
### 研究覆盖缺口
105153
...
106-
### 操作员待办事项
154+
### 下游影响(BinancePlatform)
155+
...
156+
### 策略优化方向
107157
...
108-
### 代码改进建议
158+
### 操作员待办事项
109159
...
160+
161+
- name: Post AI review issue comment
162+
if: steps.claude_review.outcome == 'success'
163+
run: |
164+
python3 scripts/post_monthly_ai_review_comment.py \
165+
--repo "${GITHUB_REPOSITORY}" \
166+
--issue-number "${{ inputs.issue_number || github.event.issue.number }}" \
167+
--execution-file "${{ steps.claude_review.outputs.execution_file }}" \
168+
--run-url "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
169+
env:
170+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/monthly_publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- Linux
1414
- X64
1515
permissions:
16+
actions: write
1617
contents: write
1718
id-token: write
1819
issues: write
@@ -91,9 +92,11 @@ jobs:
9192

9293
- name: Create Monthly Review Issue
9394
if: success() && env.PUBLISH_ENABLED != 'false'
95+
id: review_issue
9496
env:
9597
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9698
GITHUB_REPOSITORY: ${{ github.repository }}
99+
GITHUB_OUTPUT: ${{ github.output }}
97100
run: |
98101
set -euo pipefail
99102
python - <<'PY'
@@ -154,6 +157,46 @@ jobs:
154157
},
155158
)
156159
print(f"Created issue #{issue['number']}: {issue['html_url']}")
160+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
161+
print(f"issue_number={issue['number']}", file=output)
162+
print(f"issue_url={issue['html_url']}", file=output)
163+
PY
164+
165+
- name: Trigger AI Monthly Review
166+
if: success() && env.PUBLISH_ENABLED != 'false'
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
GITHUB_REPOSITORY: ${{ github.repository }}
170+
GITHUB_REF_NAME: ${{ github.ref_name }}
171+
ISSUE_NUMBER: ${{ steps.review_issue.outputs.issue_number }}
172+
run: |
173+
set -euo pipefail
174+
python - <<'PY'
175+
import json
176+
import os
177+
import urllib.request
178+
179+
token = os.environ["GITHUB_TOKEN"]
180+
repository = os.environ["GITHUB_REPOSITORY"]
181+
ref_name = os.environ["GITHUB_REF_NAME"]
182+
issue_number = os.environ["ISSUE_NUMBER"]
183+
payload = {"ref": ref_name, "inputs": {"issue_number": issue_number}}
184+
request = urllib.request.Request(
185+
f"https://api.github.com/repos/{repository}/actions/workflows/ai_review.yml/dispatches",
186+
data=json.dumps(payload).encode("utf-8"),
187+
method="POST",
188+
headers={
189+
"Authorization": f"Bearer {token}",
190+
"Accept": "application/vnd.github+json",
191+
"Content-Type": "application/json",
192+
"X-GitHub-Api-Version": "2022-11-28",
193+
"User-Agent": "crypto-leader-rotation-monthly-publish",
194+
},
195+
)
196+
with urllib.request.urlopen(request) as response:
197+
if response.status not in (201, 204):
198+
raise RuntimeError(f"Unexpected dispatch status: {response.status}")
199+
print(f"Triggered ai_review.yml for issue #{issue_number} on ref {ref_name}")
157200
PY
158201
159202
- name: Write Release Heartbeat

0 commit comments

Comments
 (0)