Skip to content

Commit 0768bd4

Browse files
committed
chore: resolve merge conflicts and update @openai/agents peer dependencies
2 parents d6d1923 + 3b3c561 commit 0768bd4

37 files changed

Lines changed: 4377 additions & 23 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import sys
5+
import argparse
6+
from collections import defaultdict
7+
from datetime import datetime
8+
9+
def get_ts_files(root_dir):
10+
"""Recursively find all TypeScript files, ignoring build/module directories."""
11+
ignore_dirs = {'node_modules', 'dist', '.git', '.wrangler', '.vscode', 'drizzle', '.github'}
12+
ts_files = []
13+
14+
for dirpath, dirnames, filenames in os.walk(root_dir):
15+
# Modify dirnames in-place to skip ignored directories
16+
dirnames[:] = [d for d in dirnames if d not in ignore_dirs]
17+
for filename in filenames:
18+
if filename.endswith('.ts') or filename.endswith('.tsx'):
19+
ts_files.append(os.path.join(dirpath, filename))
20+
21+
return ts_files
22+
23+
def main():
24+
# Generate timestamp in yyyy-mm-dd 12h time format (e.g., 2026-03-13-06-44pm)
25+
now_str = datetime.now().strftime("%Y-%m-%d-%I-%M%p").lower()
26+
filename = f"drizzle-schema-report-{now_str}.md"
27+
28+
# User's custom report location (preserving original spelling of 'hygeine')
29+
default_report_path = os.path.join(os.getcwd(), "scripts", "reports", "hygeine", filename)
30+
31+
parser = argparse.ArgumentParser(description="Analyze Drizzle ORM schema and D1 usage.")
32+
parser.add_argument("--output", default=default_report_path, help="Output Markdown file path")
33+
args = parser.parse_args()
34+
35+
# Ensure the target directory exists before executing the file scan
36+
os.makedirs(os.path.dirname(args.output), exist_ok=True)
37+
38+
root_dir = os.getcwd()
39+
files = get_ts_files(root_dir)
40+
41+
tables = []
42+
43+
# 1. Extract all Drizzle Table definitions
44+
# Matches: export const varName = sqliteTable('tableName', ...)
45+
table_regex = re.compile(r"export\s+const\s+([a-zA-Z0-9_]+)\s*=\s*(?:sqliteTable|pgTable|mysqlTable)\(\s*['\"]([^'\"]+)['\"]")
46+
47+
for file_path in files:
48+
try:
49+
with open(file_path, 'r', encoding='utf-8') as f:
50+
content = f.read()
51+
matches = table_regex.findall(content)
52+
for var_name, table_name in matches:
53+
rel_path = os.path.relpath(file_path, root_dir)
54+
tables.append({
55+
"var_name": var_name,
56+
"table_name": table_name,
57+
"file": rel_path
58+
})
59+
except Exception as e:
60+
print(f"Warning: Could not read {file_path}: {e}")
61+
62+
file_interactions = defaultdict(set)
63+
db1_map = defaultdict(set) # For env.DB
64+
db2_map = defaultdict(set) # For env.DB_WEBHOOKS
65+
66+
# 2. Scan files for table imports and D1 database interactions
67+
for file_path in files:
68+
try:
69+
with open(file_path, 'r', encoding='utf-8') as f:
70+
content = f.read()
71+
72+
rel_path = os.path.relpath(file_path, root_dir)
73+
74+
# Look for standard Cloudflare Worker / Hono context bindings
75+
uses_db1 = 'env.DB' in content or 'c.env.DB' in content
76+
uses_db2 = 'env.DB_WEBHOOKS' in content or 'c.env.DB_WEBHOOKS' in content
77+
78+
imported_tables = set()
79+
80+
for t in tables:
81+
# Regex boundary check for the specific Drizzle table variable
82+
var_regex = re.compile(r"\b" + re.escape(t['var_name']) + r"\b")
83+
84+
if var_regex.search(content):
85+
imported_tables.add(t['table_name'])
86+
87+
if uses_db1:
88+
db1_map[t['table_name']].add(rel_path)
89+
if uses_db2:
90+
db2_map[t['table_name']].add(rel_path)
91+
92+
if imported_tables:
93+
file_interactions[rel_path] = imported_tables
94+
95+
except Exception as e:
96+
print(f"Warning: Could not read {file_path}: {e}")
97+
98+
# 3. Generate the Markdown Report
99+
md = ["# Drizzle ORM Schema & D1 Analysis Report\n"]
100+
md.append("## Table Names by Database\n")
101+
102+
md.append("### env.DB")
103+
db1_sorted = sorted(db1_map.keys())
104+
if db1_sorted:
105+
for t in db1_sorted:
106+
md.append(f"- {t}")
107+
else:
108+
md.append("- *No tables definitively mapped to env.DB yet*")
109+
110+
md.append("\n### env.DB_WEBHOOKS")
111+
db2_sorted = sorted(db2_map.keys())
112+
if db2_sorted:
113+
for t in db2_sorted:
114+
md.append(f"- {t}")
115+
else:
116+
md.append("- *No tables definitively mapped to env.DB_WEBHOOKS yet*")
117+
118+
# Catch AI Slop (Orphaned Tables)
119+
all_discovered = sorted(list(set(t['table_name'] for t in tables)))
120+
mapped_tables = set(db1_sorted + db2_sorted)
121+
unmapped = [t for t in all_discovered if t not in mapped_tables]
122+
123+
if unmapped:
124+
md.append("\n### Unmapped / Orphaned Schema Tables")
125+
md.append("*(Suspicious AI Slop: Defined in code but no CRUD operations with a known D1 env var detected)*")
126+
for t in unmapped:
127+
md.append(f"- {t}")
128+
129+
md.append("\n---\n\n## Code Files Interacting with D1 Tables\n")
130+
for file_path in sorted(file_interactions.keys()):
131+
tables_used = ", ".join(sorted(file_interactions[file_path]))
132+
md.append(f"### `{file_path}`")
133+
md.append(f"- **Tables Imported:** {tables_used}\n")
134+
135+
md.append("---\n\n## env.DB d1 db")
136+
md.append("| Table Name | Short File Paths |")
137+
md.append("|---|---|")
138+
if db1_sorted:
139+
for t in db1_sorted:
140+
paths = ", ".join([f"`{p}`" for p in sorted(db1_map[t])])
141+
md.append(f"| **{t}** | {paths} |")
142+
else:
143+
md.append("| *None Detected* | *N/A* |")
144+
145+
md.append("\n## env.DB_WEBHOOKS d1 db")
146+
md.append("| Table Name | Short File Paths |")
147+
md.append("|---|---|")
148+
if db2_sorted:
149+
for t in db2_sorted:
150+
paths = ", ".join([f"`{p}`" for p in sorted(db2_map[t])])
151+
md.append(f"| **{t}** | {paths} |")
152+
else:
153+
md.append("| *None Detected* | *N/A* |")
154+
155+
# 4. Write to disk
156+
try:
157+
with open(args.output, 'w', encoding='utf-8') as f:
158+
f.write("\n".join(md) + "\n")
159+
print(f"✅ Schema analysis complete! Report generated at: {args.output}")
160+
except Exception as e:
161+
print(f"❌ Failed to write report: {e}")
162+
sys.exit(1)
163+
164+
if __name__ == "__main__":
165+
main()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Drizzle Schema Analysis Report
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.ts'
7+
- '**/*.tsx'
8+
workflow_dispatch: # Allows manual triggering from the Actions tab
9+
10+
jobs:
11+
analyze-schema:
12+
runs-on: ubuntu-latest
13+
name: Generate Schema Report
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Ensure Script is Executable
25+
run: chmod +x scripts/analyze_drizzle_schema.py
26+
27+
- name: Run Schema Analysis
28+
run: python scripts/analyze_drizzle_schema.py --output drizzle-schema-report.md
29+
30+
- name: Upload Report Artifact
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: drizzle-schema-report
34+
path: drizzle-schema-report.md
35+
retention-days: 14
36+
37+
# Optional: Fail the PR if unmapped/orphaned tables (AI slop) are detected.
38+
# Remove or comment out if you just want the report without blocking the PR.
39+
- name: Check for AI Slop
40+
run: |
41+
if grep -q "### Unmapped / Orphaned Schema Tables" drizzle-schema-report.md; then
42+
echo "::error::Orphaned Drizzle tables detected! Please review the schema for AI slop."
43+
exit 1
44+
fi
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: PR Code Block Merger
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
workflow_dispatch: # Allow manual triggers
7+
8+
jobs:
9+
merge-code-blocks:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 30
20+
21+
- name: Create initial prompt
22+
env:
23+
USER_PROMPT: |
24+
Please analyze the code changes in this Pull Request and merge duplicate or adjacent code blocks where appropriate:
25+
26+
## Focus Areas
27+
28+
1. **Code Duplication & Merging**
29+
- Identify duplicated code blocks introduced or existing in the modified files.
30+
- Consolidate redundant logic into reusable functions or shared blocks.
31+
- Merge adjacent or consecutive blocks that perform similar operations.
32+
- Apply DRY principles strictly across the current PR scope.
33+
34+
2. **Complexity Reduction**
35+
- Simplify overly complex functions resulting from merged blocks.
36+
- Combine conditionals and reduce nesting where logic overlaps.
37+
38+
3. **Formatting & Cleanup**
39+
- Ensure the newly merged code blocks maintain consistent indentation.
40+
- Clean up any orphaned variables or dead code left behind after the merge.
41+
- Organize imports if the merged blocks change dependencies.
42+
43+
Guidelines:
44+
- Make incremental, safe refactorings targeted at the PR diff.
45+
- Strictly preserve existing functionality and operational behavior.
46+
- Group related changes logically and format them cleanly.
47+
- Push the refactored, merged code blocks directly to this PR branch.
48+
49+
Do not make changes if the code blocks cannot be safely merged without altering intended behavior.
50+
shell: bash
51+
run: |
52+
echo "$USER_PROMPT" > prompt.txt
53+
54+
- name: Save git log
55+
shell: bash
56+
run: |
57+
echo -e '\n\nLog of the last 20 commits (in the format of `git log --stat`):' >> prompt.txt
58+
echo '```' >> prompt.txt
59+
git log -20 --stat >> prompt.txt
60+
echo '```' >> prompt.txt
61+
62+
- name: Assemble Jules payload
63+
shell: bash
64+
env:
65+
STARTING_BRANCH: ${{ github.head_ref || github.ref_name }}
66+
run: |
67+
jq -n --arg jules_prompt "$(cat prompt.txt)" --arg starting_branch "$STARTING_BRANCH" --arg repo_full_name "${{ github.repository }}" '{
68+
"prompt": $jules_prompt,
69+
"sourceContext": {
70+
"source": "sources/github/\($repo_full_name)",
71+
"githubRepoContext": {
72+
"startingBranch": $starting_branch
73+
}
74+
},
75+
"requirePlanApproval": false,
76+
"automationMode": "AUTO_CREATE_PR"
77+
}' > jules_payload.json
78+
79+
- name: Invoke Jules API
80+
shell: bash
81+
run: |
82+
curl 'https://jules.googleapis.com/v1alpha/sessions' \
83+
-X POST \
84+
-H "Content-Type: application/json" \
85+
-H "X-Goog-Api-Key: ${{ secrets.JULES_API_KEY }}" \
86+
-d @jules_payload.json

0 commit comments

Comments
 (0)