-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (157 loc) · 7.23 KB
/
Copy pathmistcoder-scan.yml
File metadata and controls
188 lines (157 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# .github/workflows/mistcoder-scan.yml
# MISTCODER Threat-Native Blockchain
# Layer 8 — Constitutional CI/CD Guard
#
# Runs on every pull request.
# Scans changed Python files through the Trinity.
# Blocks merge if a CRITICAL certified kill chain is found.
# Posts a full threat report as a PR comment.
#
# This is the moment MISTCODER becomes a platform.
name: MISTCODER Constitutional Scan
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
pull-requests: write
issues: write
contents: read
jobs:
mistcoder-scan:
name: Trinity Threat Certification
runs-on: ubuntu-latest
steps:
# ── Checkout ────────────────────────────────────────────────────────
- name: Checkout repository
uses: actions/checkout@v4
# ── Python setup ────────────────────────────────────────────────────
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
# ── Install deps ────────────────────────────────────────────────────
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# ── Run MISTCODER scan ───────────────────────────────────────────────
- name: Run MISTCODER Trinity scan
id: scan
run: |
echo "Running MISTCODER constitutional scan..."
python -m blockchain.mistcoder_chain_runner 2>&1 | tee scan_output.txt
echo "scan_complete=true" >> $GITHUB_OUTPUT
# ── Run chain exporter ───────────────────────────────────────────────
- name: Export certified chain data
run: |
python -m blockchain.chain_exporter 2>&1 | tee export_output.txt
# ── Check for CRITICAL findings ──────────────────────────────────────
- name: Constitutional gate — check for CRITICAL kill chains
id: gate
run: |
python - <<'EOF'
import json
import sys
from pathlib import Path
# Read the chain export
export_path = Path("sandbox/chain_export.js")
if not export_path.exists():
print("No chain export found — scan may have failed.")
sys.exit(1)
# Parse the DATA object from the JS file
content = export_path.read_text(encoding="utf-8")
# Strip JS wrapper to get pure JSON
json_start = content.find("const DATA = ") + len("const DATA = ")
json_end = content.rfind(";")
data = json.loads(content[json_start:json_end])
findings = data.get("findings", {})
chains = data.get("chains", [])
blockchain = data.get("blockchain", {})
critical_count = findings.get("critical", 0)
certified = blockchain.get("certified", 0)
blocks = blockchain.get("blocks", 0)
# Find highest scoring certified chain
critical_chains = [
c for c in chains
if c.get("score", 0) >= 8.0 and c.get("certified", False)
]
print(f"MISTCODER Constitutional Gate")
print(f" Certified blocks : {blocks}")
print(f" Certified chains : {certified}")
print(f" Critical findings: {critical_count}")
print(f" Critical chains : {len(critical_chains)}")
if critical_chains:
print()
print("CRITICAL kill chains found:")
for c in critical_chains[:3]:
print(f" {c['id']} score={c['score']} "
f"hash={c.get('block_hash','?')[:16]}...")
print()
print("COVENANT VERDICT: HALT DEPLOYMENTS")
print("Constitutional threshold exceeded.")
print("Merge blocked by MISTCODER Trinity.")
# Write status for PR comment
with open("gate_result.txt", "w") as f:
f.write("BLOCKED")
sys.exit(1)
else:
print()
print("COVENANT VERDICT: CERTIFIED CLEAR")
print("No critical kill chains. Merge permitted.")
with open("gate_result.txt", "w") as f:
f.write("CLEAR")
sys.exit(0)
EOF
# ── Post PR comment ──────────────────────────────────────────────────
- name: Post threat report to PR
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
// Read scan output
let scanOut = '';
let gateOut = '';
let gateFile = '';
try { scanOut = fs.readFileSync('scan_output.txt', 'utf8'); } catch(e) {}
try { gateOut = fs.readFileSync('export_output.txt','utf8'); } catch(e) {}
try { gateFile = fs.readFileSync('gate_result.txt', 'utf8').trim(); } catch(e) {}
const blocked = gateFile === 'BLOCKED';
const verdict = blocked
? '🔴 **COVENANT VERDICT: HALT DEPLOYMENTS**'
: '🟢 **COVENANT VERDICT: CERTIFIED CLEAR**';
const badge = blocked
? ''
: '';
const body = `## ${badge}
### MISTCODER Constitutional Scan — Trinity Report
${verdict}
---
**Scan details:**
\`\`\`
${scanOut.slice(-2000)}
\`\`\`
---
> *MISTCODER — Know your attack surface before the adversary does.*
> *PHANTOM simulates · ORACLE challenges · COVENANT certifies*
`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
# ── Upload chain export as artifact ─────────────────────────────────
- name: Upload certified chain as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: mistcoder-chain-${{ github.sha }}
path: |
sandbox/chain_export.js
sandbox/oracle_knowledge.json
sandbox/oracle_signatures.json
retention-days: 90