mss-vdp 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mss_vdp-2.1.0/LICENSE +21 -0
- mss_vdp-2.1.0/PKG-INFO +111 -0
- mss_vdp-2.1.0/README.md +71 -0
- mss_vdp-2.1.0/alert_sender.py +138 -0
- mss_vdp-2.1.0/content_compliance.py +213 -0
- mss_vdp-2.1.0/csharp_scan.py +167 -0
- mss_vdp-2.1.0/go_scan.py +235 -0
- mss_vdp-2.1.0/java_cpp_scan.py +277 -0
- mss_vdp-2.1.0/js_scan.py +453 -0
- mss_vdp-2.1.0/k4_protocols/__init__.py +52 -0
- mss_vdp-2.1.0/k4_protocols/k4_bidirectional_coupler.py +570 -0
- mss_vdp-2.1.0/k4_protocols/k4_guardian_protocol.py +384 -0
- mss_vdp-2.1.0/k4_protocols/k4_logical_work.py +526 -0
- mss_vdp-2.1.0/k4_protocols/k4_pi_adapter.py +747 -0
- mss_vdp-2.1.0/k4_protocols/k4_rsca_genes.py +284 -0
- mss_vdp-2.1.0/k4_protocols/test_k4_protocols.py +485 -0
- mss_vdp-2.1.0/kotlin_scan.py +159 -0
- mss_vdp-2.1.0/llm_bench.py +291 -0
- mss_vdp-2.1.0/lock_profiler.py +326 -0
- mss_vdp-2.1.0/memory_profiler.py +167 -0
- mss_vdp-2.1.0/mss_agent_sdk/__init__.py +29 -0
- mss_vdp-2.1.0/mss_agent_sdk/cli.py +77 -0
- mss_vdp-2.1.0/mss_agent_sdk/client.py +265 -0
- mss_vdp-2.1.0/mss_agent_sdk/config.py +50 -0
- mss_vdp-2.1.0/mss_agent_sdk/decorators.py +165 -0
- mss_vdp-2.1.0/mss_agent_sdk/demo.py +156 -0
- mss_vdp-2.1.0/mss_agent_sdk/mss_types.py +80 -0
- mss_vdp-2.1.0/mss_agent_sdk/setup.py +47 -0
- mss_vdp-2.1.0/mss_agent_sdk/test_sdk.py +127 -0
- mss_vdp-2.1.0/mss_agent_sdk/test_sdk_standalone.py +195 -0
- mss_vdp-2.1.0/mss_proof/__init__.py +54 -0
- mss_vdp-2.1.0/mss_proof/axiom_kb.py +304 -0
- mss_vdp-2.1.0/mss_proof/benchmark.py +370 -0
- mss_vdp-2.1.0/mss_proof/collatz_cycle_verifier.py +96 -0
- mss_vdp-2.1.0/mss_proof/proof_explain.py +292 -0
- mss_vdp-2.1.0/mss_proof/proof_search.py +787 -0
- mss_vdp-2.1.0/mss_proof/tptp_parser.py +309 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/PKG-INFO +111 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/SOURCES.txt +113 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/dependency_links.txt +1 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/entry_points.txt +27 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/requires.txt +13 -0
- mss_vdp-2.1.0/mss_vdp.egg-info/top_level.txt +30 -0
- mss_vdp-2.1.0/org_resilience.py +474 -0
- mss_vdp-2.1.0/php_scan.py +149 -0
- mss_vdp-2.1.0/ps_judge.py +253 -0
- mss_vdp-2.1.0/py_clean.py +260 -0
- mss_vdp-2.1.0/rate_limiter.py +114 -0
- mss_vdp-2.1.0/ruby_scan.py +142 -0
- mss_vdp-2.1.0/rust_scan.py +240 -0
- mss_vdp-2.1.0/service_monitor.py +233 -0
- mss_vdp-2.1.0/setup.cfg +4 -0
- mss_vdp-2.1.0/setup.py +78 -0
- mss_vdp-2.1.0/symbolic_engine_v4/__init__.py +23 -0
- mss_vdp-2.1.0/symbolic_engine_v4/api/__init__.py +7 -0
- mss_vdp-2.1.0/symbolic_engine_v4/api/enhanced.py +304 -0
- mss_vdp-2.1.0/symbolic_engine_v4/api/rest.py +266 -0
- mss_vdp-2.1.0/symbolic_engine_v4/axiom_integration.py +181 -0
- mss_vdp-2.1.0/symbolic_engine_v4/core/__init__.py +14 -0
- mss_vdp-2.1.0/symbolic_engine_v4/core/graph.py +203 -0
- mss_vdp-2.1.0/symbolic_engine_v4/core/types.py +91 -0
- mss_vdp-2.1.0/symbolic_engine_v4/monitor/__init__.py +7 -0
- mss_vdp-2.1.0/symbolic_engine_v4/monitor/dashboard.py +94 -0
- mss_vdp-2.1.0/symbolic_engine_v4/monitor/health_monitor.py +218 -0
- mss_vdp-2.1.0/symbolic_engine_v4/parser/__init__.py +7 -0
- mss_vdp-2.1.0/symbolic_engine_v4/parser/jsonl_parser.py +200 -0
- mss_vdp-2.1.0/symbolic_engine_v4/plugins/__init__.py +7 -0
- mss_vdp-2.1.0/symbolic_engine_v4/plugins/base.py +148 -0
- mss_vdp-2.1.0/symbolic_engine_v4/reasoner/__init__.py +7 -0
- mss_vdp-2.1.0/symbolic_engine_v4/reasoner/path_finder.py +213 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_api.py +75 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_core.py +74 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_integration.py +143 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_pathfinder.py +68 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_quick.py +34 -0
- mss_vdp-2.1.0/symbolic_engine_v4/test_v4_core.py +101 -0
- mss_vdp-2.1.0/tests/test_forbidden_v3_5.py +42 -0
- mss_vdp-2.1.0/tests/test_suite_v3_7.py +188 -0
- mss_vdp-2.1.0/tools/__init__.py +3 -0
- mss_vdp-2.1.0/tools/archive_h147.py +29 -0
- mss_vdp-2.1.0/tools/archive_manager.py +266 -0
- mss_vdp-2.1.0/tools/auto_archive.py +107 -0
- mss_vdp-2.1.0/tools/calibrate_taskbar.py +127 -0
- mss_vdp-2.1.0/tools/comprehensive_audit.py +168 -0
- mss_vdp-2.1.0/tools/cross_paradigm_bridge.py +158 -0
- mss_vdp-2.1.0/tools/dangerous_operation_policy.py +103 -0
- mss_vdp-2.1.0/tools/death_filter.py +218 -0
- mss_vdp-2.1.0/tools/dual_audit.py +139 -0
- mss_vdp-2.1.0/tools/heat_tax_profiler.py +161 -0
- mss_vdp-2.1.0/tools/kb_integrity_check.py +146 -0
- mss_vdp-2.1.0/tools/logic_virus_scanner.py +304 -0
- mss_vdp-2.1.0/tools/logical_rigidity_verifier.py +301 -0
- mss_vdp-2.1.0/tools/meaning_blackhole_agent.py +246 -0
- mss_vdp-2.1.0/tools/mss_audit_runner.py +76 -0
- mss_vdp-2.1.0/tools/mss_meaning_audit_v02.py +706 -0
- mss_vdp-2.1.0/tools/mss_review_runner.py +332 -0
- mss_vdp-2.1.0/tools/paradigm_audit.py +80 -0
- mss_vdp-2.1.0/tools/paradigm_purge.py +152 -0
- mss_vdp-2.1.0/tools/paradigm_purge_extra.py +36 -0
- mss_vdp-2.1.0/tools/paradigm_purge_final.py +33 -0
- mss_vdp-2.1.0/tools/paradigm_purge_residual.py +48 -0
- mss_vdp-2.1.0/tools/paradigm_purge_v2.py +85 -0
- mss_vdp-2.1.0/tools/paradigm_purge_v3.py +27 -0
- mss_vdp-2.1.0/tools/paradigm_purge_v4.py +10 -0
- mss_vdp-2.1.0/tools/perception_shell_adapter.py +136 -0
- mss_vdp-2.1.0/tools/session_recall_summarizer.py +64 -0
- mss_vdp-2.1.0/tools/sync_taskbar.py +39 -0
- mss_vdp-2.1.0/tools/t_value_filter.py +96 -0
- mss_vdp-2.1.0/tools/task_manager.py +254 -0
- mss_vdp-2.1.0/tools/test_tools.py +59 -0
- mss_vdp-2.1.0/tools/thinking_fold.py +90 -0
- mss_vdp-2.1.0/vdp_dsl.py +204 -0
- mss_vdp-2.1.0/vdp_fuzzer.py +275 -0
- mss_vdp-2.1.0/vdp_pipeline.py +308 -0
- mss_vdp-2.1.0/vdp_scan.py +426 -0
mss_vdp-2.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MSS-AI Project Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mss_vdp-2.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mss-vdp
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: MSS Verification Discipline Protocol — Multi-language code quality & compliance scanner
|
|
5
|
+
Home-page: https://github.com/mss-ai/vdp
|
|
6
|
+
Author: MSS-AI
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: tree-sitter>=0.20
|
|
19
|
+
Requires-Dist: tree-sitter-python
|
|
20
|
+
Requires-Dist: tree-sitter-javascript
|
|
21
|
+
Requires-Dist: tree-sitter-rust
|
|
22
|
+
Requires-Dist: tree-sitter-java
|
|
23
|
+
Requires-Dist: tree-sitter-cpp
|
|
24
|
+
Requires-Dist: tree-sitter-c
|
|
25
|
+
Requires-Dist: tree-sitter-go
|
|
26
|
+
Requires-Dist: tree-sitter-ruby
|
|
27
|
+
Requires-Dist: tree-sitter-php
|
|
28
|
+
Requires-Dist: uvicorn
|
|
29
|
+
Requires-Dist: fastapi
|
|
30
|
+
Requires-Dist: pydantic
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: description-content-type
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: requires-dist
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
# MSS-VDP v2.0
|
|
42
|
+
|
|
43
|
+
**Verification Discipline Protocol** — Multi-language code quality, security, and compliance scanner.
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install mss-vdp
|
|
49
|
+
|
|
50
|
+
# Scan Python
|
|
51
|
+
vdp-scan src/ --json
|
|
52
|
+
|
|
53
|
+
# Scan JavaScript
|
|
54
|
+
vdp-js src/ --json
|
|
55
|
+
|
|
56
|
+
# Full pipeline (all languages)
|
|
57
|
+
vdp-pipeline . --json
|
|
58
|
+
|
|
59
|
+
# Smoke test (19 checks)
|
|
60
|
+
vdp-smoke
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Supported Languages (10)
|
|
64
|
+
|
|
65
|
+
| Language | Command | Engine | Rules |
|
|
66
|
+
|----------|---------|--------|-------|
|
|
67
|
+
| Python | `vdp-scan` | tree-sitter | V1-V6 |
|
|
68
|
+
| JavaScript/TS | `vdp-js` | tree-sitter | V1-V9 |
|
|
69
|
+
| Rust | `vdp-rust` | tree-sitter | R1-R5 |
|
|
70
|
+
| Java | `vdp-scan --java` | tree-sitter | J1-J5 |
|
|
71
|
+
| C/C++ | `vdp-scan --cpp` | tree-sitter | C1-C4 |
|
|
72
|
+
| Go | `vdp-go` | tree-sitter | G1-G5 |
|
|
73
|
+
| Ruby | `vdp-ruby` | tree-sitter | R1-R5 |
|
|
74
|
+
| PHP | `vdp-php` | tree-sitter | P1-P5 |
|
|
75
|
+
| Kotlin | `vdp-kotlin` | regex | K1-K5 |
|
|
76
|
+
| C# | `vdp-csharp` | regex | C1-C5 |
|
|
77
|
+
|
|
78
|
+
## Tools
|
|
79
|
+
|
|
80
|
+
### Runtimes
|
|
81
|
+
- **Rate Limiter** — Token bucket for API protection
|
|
82
|
+
- **Service Monitor** — Health check + Lark/Slack alerts
|
|
83
|
+
- **Lock Profiler** — Thread contention detection
|
|
84
|
+
- **Memory Profiler** — tracemalloc leak detection
|
|
85
|
+
- **Fuzzer** — Random mutation testing
|
|
86
|
+
|
|
87
|
+
### Domain Tools
|
|
88
|
+
- **PowerShell Verify** — 11-command PS safety checker
|
|
89
|
+
- **PowerShell Judge** — Golden answer benchmark
|
|
90
|
+
- **Python Clean** — venv/pyc/pip diagnostics
|
|
91
|
+
- **Android/iOS Verify** — Mobile dev diagnostics
|
|
92
|
+
|
|
93
|
+
### Analysis
|
|
94
|
+
- **Org Resilience** — Organizational health + 3-layer Tuning Degree
|
|
95
|
+
- **Content Compliance** — Document quality scanner
|
|
96
|
+
- **LLM Benchmark** — Offline/live/regression LLM evaluation
|
|
97
|
+
- **VDP DSL** — Custom rule engine (YAML-based)
|
|
98
|
+
|
|
99
|
+
## CI/CD
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
# GitHub Actions
|
|
103
|
+
.github/workflows/vdp-pipeline.yml
|
|
104
|
+
|
|
105
|
+
# GitLab CI
|
|
106
|
+
.gitlab-ci.yml
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
mss_vdp-2.1.0/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# MSS-VDP v2.0
|
|
2
|
+
|
|
3
|
+
**Verification Discipline Protocol** — Multi-language code quality, security, and compliance scanner.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install mss-vdp
|
|
9
|
+
|
|
10
|
+
# Scan Python
|
|
11
|
+
vdp-scan src/ --json
|
|
12
|
+
|
|
13
|
+
# Scan JavaScript
|
|
14
|
+
vdp-js src/ --json
|
|
15
|
+
|
|
16
|
+
# Full pipeline (all languages)
|
|
17
|
+
vdp-pipeline . --json
|
|
18
|
+
|
|
19
|
+
# Smoke test (19 checks)
|
|
20
|
+
vdp-smoke
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Supported Languages (10)
|
|
24
|
+
|
|
25
|
+
| Language | Command | Engine | Rules |
|
|
26
|
+
|----------|---------|--------|-------|
|
|
27
|
+
| Python | `vdp-scan` | tree-sitter | V1-V6 |
|
|
28
|
+
| JavaScript/TS | `vdp-js` | tree-sitter | V1-V9 |
|
|
29
|
+
| Rust | `vdp-rust` | tree-sitter | R1-R5 |
|
|
30
|
+
| Java | `vdp-scan --java` | tree-sitter | J1-J5 |
|
|
31
|
+
| C/C++ | `vdp-scan --cpp` | tree-sitter | C1-C4 |
|
|
32
|
+
| Go | `vdp-go` | tree-sitter | G1-G5 |
|
|
33
|
+
| Ruby | `vdp-ruby` | tree-sitter | R1-R5 |
|
|
34
|
+
| PHP | `vdp-php` | tree-sitter | P1-P5 |
|
|
35
|
+
| Kotlin | `vdp-kotlin` | regex | K1-K5 |
|
|
36
|
+
| C# | `vdp-csharp` | regex | C1-C5 |
|
|
37
|
+
|
|
38
|
+
## Tools
|
|
39
|
+
|
|
40
|
+
### Runtimes
|
|
41
|
+
- **Rate Limiter** — Token bucket for API protection
|
|
42
|
+
- **Service Monitor** — Health check + Lark/Slack alerts
|
|
43
|
+
- **Lock Profiler** — Thread contention detection
|
|
44
|
+
- **Memory Profiler** — tracemalloc leak detection
|
|
45
|
+
- **Fuzzer** — Random mutation testing
|
|
46
|
+
|
|
47
|
+
### Domain Tools
|
|
48
|
+
- **PowerShell Verify** — 11-command PS safety checker
|
|
49
|
+
- **PowerShell Judge** — Golden answer benchmark
|
|
50
|
+
- **Python Clean** — venv/pyc/pip diagnostics
|
|
51
|
+
- **Android/iOS Verify** — Mobile dev diagnostics
|
|
52
|
+
|
|
53
|
+
### Analysis
|
|
54
|
+
- **Org Resilience** — Organizational health + 3-layer Tuning Degree
|
|
55
|
+
- **Content Compliance** — Document quality scanner
|
|
56
|
+
- **LLM Benchmark** — Offline/live/regression LLM evaluation
|
|
57
|
+
- **VDP DSL** — Custom rule engine (YAML-based)
|
|
58
|
+
|
|
59
|
+
## CI/CD
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
# GitHub Actions
|
|
63
|
+
.github/workflows/vdp-pipeline.yml
|
|
64
|
+
|
|
65
|
+
# GitLab CI
|
|
66
|
+
.gitlab-ci.yml
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
MSS 告警发送器 — Lark/Slack Webhook 通知
|
|
4
|
+
集成 rate_limiter TokenBucket 防止平台限流
|
|
5
|
+
"""
|
|
6
|
+
import os, json, urllib.request, time
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from rate_limiter import TokenBucket
|
|
9
|
+
|
|
10
|
+
# ── Webhook 地址 (环境变量) ──
|
|
11
|
+
LARK_WEBHOOK = os.getenv("LARK_WEBHOOK_URL", "")
|
|
12
|
+
SLACK_WEBHOOK = os.getenv("SLACK_WEBHOOK_URL", "")
|
|
13
|
+
|
|
14
|
+
# ── 告警限速器: 1条/分钟, burst 2 (防同一事件多次触发) ──
|
|
15
|
+
_alert_limiter = TokenBucket(rate=1/60, burst=2)
|
|
16
|
+
|
|
17
|
+
# ── 颜色映射 ──
|
|
18
|
+
COLORS = {"ERROR": "red", "WARN": "orange", "INFO": "green"}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def send_alert(platform: str, title: str, content: str, level: str = "ERROR") -> bool:
|
|
22
|
+
"""发送告警到 Lark 或 Slack (自动限速)"""
|
|
23
|
+
if not _alert_limiter.consume(1):
|
|
24
|
+
print(f"[ALERT] Rate limited: {title[:60]}")
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
28
|
+
|
|
29
|
+
if platform == "lark":
|
|
30
|
+
if not LARK_WEBHOOK:
|
|
31
|
+
print("[ALERT] LARK_WEBHOOK_URL not configured")
|
|
32
|
+
return False
|
|
33
|
+
payload = {
|
|
34
|
+
"msg_type": "interactive",
|
|
35
|
+
"card": {
|
|
36
|
+
"header": {
|
|
37
|
+
"title": {"tag": "plain_text", "content": title},
|
|
38
|
+
"template": COLORS.get(level, "blue"),
|
|
39
|
+
},
|
|
40
|
+
"elements": [{
|
|
41
|
+
"tag": "div",
|
|
42
|
+
"text": {"tag": "lark_md", "content": f"**时间**: {ts}\n{content}"}
|
|
43
|
+
}]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
url = LARK_WEBHOOK
|
|
47
|
+
|
|
48
|
+
elif platform == "slack":
|
|
49
|
+
if not SLACK_WEBHOOK:
|
|
50
|
+
print("[ALERT] SLACK_WEBHOOK_URL not configured")
|
|
51
|
+
return False
|
|
52
|
+
payload = {
|
|
53
|
+
"attachments": [{
|
|
54
|
+
"color": COLORS.get(level, "#36a64f"),
|
|
55
|
+
"title": title,
|
|
56
|
+
"text": f"*{ts}*\n{content}",
|
|
57
|
+
"footer": "MSS VDP Monitor",
|
|
58
|
+
}]
|
|
59
|
+
}
|
|
60
|
+
url = SLACK_WEBHOOK
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
|
66
|
+
try:
|
|
67
|
+
req = urllib.request.Request(url, data=body, headers={"Content-Type": "application/json"})
|
|
68
|
+
with urllib.request.urlopen(req, timeout=5) as resp:
|
|
69
|
+
return resp.status == 200
|
|
70
|
+
except Exception as e:
|
|
71
|
+
print(f"[ALERT] Send failed: {e}")
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def send_both(title: str, content: str, level: str = "ERROR"):
|
|
76
|
+
"""同时发送到 Lark 和 Slack"""
|
|
77
|
+
ok_l = send_alert("lark", title, content, level) if LARK_WEBHOOK else None
|
|
78
|
+
ok_s = send_alert("slack", title, content, level) if SLACK_WEBHOOK else None
|
|
79
|
+
return ok_l, ok_s
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# ── 预定义告警模板 ──
|
|
83
|
+
|
|
84
|
+
def alert_service_down(service_name: str, port: int, detail: str = "") -> bool:
|
|
85
|
+
return send_both(
|
|
86
|
+
f"🚨 服务 {service_name} 下线",
|
|
87
|
+
f"端口 `{port}` 无响应\n{detail}",
|
|
88
|
+
"ERROR"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def alert_service_up(service_name: str, port: int) -> bool:
|
|
92
|
+
return send_both(
|
|
93
|
+
f"✅ 服务 {service_name} 恢复",
|
|
94
|
+
f"端口 `{port}` 已恢复正常",
|
|
95
|
+
"INFO"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def alert_rate_limit(ip: str, endpoint: str, count: int) -> bool:
|
|
99
|
+
return send_both(
|
|
100
|
+
f"🛡️ 速率限制触发",
|
|
101
|
+
f"IP `{ip}` 在 `{endpoint}` 被拦截 {count} 次",
|
|
102
|
+
"WARN"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def alert_vdp_scan_complete(files: int, violations: int, rejects: int, duration_ms: float) -> bool:
|
|
106
|
+
level = "ERROR" if rejects > 0 else "INFO"
|
|
107
|
+
return send_both(
|
|
108
|
+
f"{'❌' if rejects else '✅'} VDP 扫描完成",
|
|
109
|
+
f"文件: {files} | 违规: {violations} | 拒绝: {rejects} | 耗时: {duration_ms:.0f}ms",
|
|
110
|
+
level
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def alert_memory_warning(process: str, current_mb: float, limit_mb: float) -> bool:
|
|
114
|
+
return send_both(
|
|
115
|
+
f"⚠️ 内存使用告警",
|
|
116
|
+
f"进程 `{process}` 使用 {current_mb:.1f}MB / 限制 {limit_mb:.1f}MB",
|
|
117
|
+
"WARN"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# ── CLI ──
|
|
122
|
+
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
import argparse
|
|
125
|
+
ap = argparse.ArgumentParser(description='MSS 告警发送器')
|
|
126
|
+
ap.add_argument('--test', action='store_true', help='发送测试告警')
|
|
127
|
+
ap.add_argument('--platform', choices=['lark','slack','both'], default='both')
|
|
128
|
+
args = ap.parse_args()
|
|
129
|
+
|
|
130
|
+
if args.test:
|
|
131
|
+
print(f"Testing alert...")
|
|
132
|
+
print(f" Lark webhook: {'configured' if LARK_WEBHOOK else 'NOT SET'}")
|
|
133
|
+
print(f" Slack webhook: {'configured' if SLACK_WEBHOOK else 'NOT SET'}")
|
|
134
|
+
|
|
135
|
+
ok = alert_service_down("test-service", 9999, "这是一个测试告警")
|
|
136
|
+
print(f" Sent: {ok}")
|
|
137
|
+
else:
|
|
138
|
+
ap.print_help()
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
MSS 内容合规扫描器 v15.1
|
|
4
|
+
针对文档/报告/知识库条目的文本质量审计。
|
|
5
|
+
规则: C1_CLAIM (无锚断言), C2_VAGUE (模糊语言), C3_MEME (模因污染),
|
|
6
|
+
C4_PSEUDO (伪科学性), C5_THERMAL (热税短视)
|
|
7
|
+
100% 自包含, 无外部依赖。
|
|
8
|
+
"""
|
|
9
|
+
import json, re, argparse, os, sys
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
# ── 规则定义 ──
|
|
14
|
+
|
|
15
|
+
RULES = {
|
|
16
|
+
'C1_CLAIM': {
|
|
17
|
+
'name': '无锚断言检测',
|
|
18
|
+
'severity': 'reject',
|
|
19
|
+
'patterns': [
|
|
20
|
+
r'必然|绝对|毫无疑问|100%|永远|绝不会|显然',
|
|
21
|
+
r'所有.*都|没有人|从未|始终|完全',
|
|
22
|
+
r'科学证明|研究表明|数据表明|事实是',
|
|
23
|
+
],
|
|
24
|
+
'detail': '绝对化/无证据断言 — 违反 A7 诚实边界公理',
|
|
25
|
+
'layer': 'L2',
|
|
26
|
+
},
|
|
27
|
+
'C2_VAGUE': {
|
|
28
|
+
'name': '模糊语言检测',
|
|
29
|
+
'severity': 'warn',
|
|
30
|
+
'patterns': [
|
|
31
|
+
r'某种程度|或多或少|某种意义上|似乎|可能.*也可能',
|
|
32
|
+
r'一言难尽|说不清|难以描述',
|
|
33
|
+
r'各方面|全方位|多层次|多维度',
|
|
34
|
+
],
|
|
35
|
+
'detail': '模糊化表达 — 降低信息密度, 增加意义热税 (A3)',
|
|
36
|
+
'layer': 'L2',
|
|
37
|
+
},
|
|
38
|
+
'C3_MEME': {
|
|
39
|
+
'name': '模因污染检测',
|
|
40
|
+
'severity': 'warn',
|
|
41
|
+
'patterns': [
|
|
42
|
+
r'降维打击|底层逻辑|顶层设计|闭环|赋能',
|
|
43
|
+
r'抓手|对齐|颗粒度|引爆点|护城河',
|
|
44
|
+
r'范式|生态|入口|中台|私域',
|
|
45
|
+
r'all in|内卷|躺平|PUA|画饼',
|
|
46
|
+
],
|
|
47
|
+
'detail': '商业化模因/流行语 — 模因污染降低意义保真度',
|
|
48
|
+
'layer': 'L3',
|
|
49
|
+
},
|
|
50
|
+
'C4_PSEUDO': {
|
|
51
|
+
'name': '伪科学性检测',
|
|
52
|
+
'severity': 'reject',
|
|
53
|
+
'patterns': [
|
|
54
|
+
r'量子.*能|量子.*疗|量子.*灵',
|
|
55
|
+
r'能量场|频率共振|宇宙法则|吸引力法则',
|
|
56
|
+
r'负离子|远红外|纳米.*量子|石墨烯.*量子',
|
|
57
|
+
r'熵增.*逆|意识.*量子|灵魂.*量子',
|
|
58
|
+
],
|
|
59
|
+
'detail': '伪科学用语 — 将科学术语用作魔法咒语 (A5 物理投影断裂)',
|
|
60
|
+
'layer': 'L1',
|
|
61
|
+
},
|
|
62
|
+
'C5_THERMAL': {
|
|
63
|
+
'name': '热税短视检测',
|
|
64
|
+
'severity': 'warn',
|
|
65
|
+
'patterns': [
|
|
66
|
+
r'快速.*搞定|一键.*解决|秒变|立马',
|
|
67
|
+
r'不花.*时间|零成本|无脑|躺赚',
|
|
68
|
+
r'短期.*见效|快速.*变现|立刻.*提升',
|
|
69
|
+
],
|
|
70
|
+
'detail': '热税短视症 — 承诺零热税操作, 忽略长期代价 (A3)',
|
|
71
|
+
'layer': 'L1',
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ContentComplianceScanner:
|
|
77
|
+
"""v15.1 内容合规扫描器"""
|
|
78
|
+
|
|
79
|
+
def scan_text(self, text: str, target: str = '<inline>') -> dict:
|
|
80
|
+
violations = []
|
|
81
|
+
for rule_id, rule in RULES.items():
|
|
82
|
+
for pat in rule['patterns']:
|
|
83
|
+
for m in re.finditer(pat, text):
|
|
84
|
+
# Extract surrounding context
|
|
85
|
+
start = max(0, m.start() - 20)
|
|
86
|
+
end = min(len(text), m.end() + 40)
|
|
87
|
+
snippet = text[start:end].replace('\n', ' ')
|
|
88
|
+
violations.append({
|
|
89
|
+
'rule_id': rule_id,
|
|
90
|
+
'severity': rule['severity'],
|
|
91
|
+
'layer': rule['layer'],
|
|
92
|
+
'category': rule['name'],
|
|
93
|
+
'detail': rule['detail'],
|
|
94
|
+
'loc': f'pos {m.start()}',
|
|
95
|
+
'match': m.group(),
|
|
96
|
+
'context': snippet.strip(),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
violations.sort(key=lambda v: (v['severity'] == 'reject', v['loc']))
|
|
100
|
+
|
|
101
|
+
lines = len(text.split('\n')) if text else 0
|
|
102
|
+
score = max(0, 100 - len(violations) * 5)
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
'target': target, 'target_type': 'text',
|
|
106
|
+
'total_lines': lines,
|
|
107
|
+
'violations': violations,
|
|
108
|
+
'verdict': 'reject' if any(v['severity']=='reject' for v in violations)
|
|
109
|
+
else 'warn' if violations else 'pass',
|
|
110
|
+
'compliance_score': score,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
def scan_file(self, filepath: str) -> dict:
|
|
114
|
+
try:
|
|
115
|
+
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
|
|
116
|
+
content = f.read()
|
|
117
|
+
except Exception as e:
|
|
118
|
+
return {'target': filepath, 'error': str(e), 'violations': []}
|
|
119
|
+
return self.scan_text(content, filepath)
|
|
120
|
+
|
|
121
|
+
def scan_directory(self, directory: str, patterns: list = None) -> list:
|
|
122
|
+
if patterns is None:
|
|
123
|
+
patterns = ['*.md', '*.txt', '*.json', '*.py', '*.yaml', '*.yml']
|
|
124
|
+
|
|
125
|
+
results = []
|
|
126
|
+
for root, dirs, files in os.walk(directory):
|
|
127
|
+
dirs[:] = [d for d in dirs if not d.startswith('.') and d not in ('node_modules', '.git', '__pycache__')]
|
|
128
|
+
for f in files:
|
|
129
|
+
fp = os.path.join(root, f)
|
|
130
|
+
if any(Path(f).match(p) for p in patterns):
|
|
131
|
+
r = self.scan_file(fp)
|
|
132
|
+
if r.get('violations'):
|
|
133
|
+
results.append(r)
|
|
134
|
+
|
|
135
|
+
return results
|
|
136
|
+
|
|
137
|
+
def batch_report(self, results: list) -> dict:
|
|
138
|
+
total_v = sum(len(r.get('violations', [])) for r in results)
|
|
139
|
+
rejects = sum(1 for r in results if r.get('verdict') == 'reject')
|
|
140
|
+
by_rule = {}
|
|
141
|
+
for r in results:
|
|
142
|
+
for v in r.get('violations', []):
|
|
143
|
+
rid = v['rule_id']
|
|
144
|
+
by_rule[rid] = by_rule.get(rid, 0) + 1
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
'timestamp': datetime.now().isoformat(),
|
|
148
|
+
'files_scanned': len(results),
|
|
149
|
+
'total_violations': total_v,
|
|
150
|
+
'rejects': rejects,
|
|
151
|
+
'by_rule': by_rule,
|
|
152
|
+
'verdict': 'reject' if rejects > 0 else 'warn' if total_v > 0 else 'pass',
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def main():
|
|
157
|
+
ap = argparse.ArgumentParser(description='MSS 内容合规扫描器 v15.1')
|
|
158
|
+
ap.add_argument('target', nargs='?', help='文件或目录')
|
|
159
|
+
ap.add_argument('--json', action='store_true', help='JSON 输出')
|
|
160
|
+
ap.add_argument('--recursive', action='store_true', help='递归扫描目录')
|
|
161
|
+
ap.add_argument('--demo', action='store_true', help='自助扫描 (扫描自身)')
|
|
162
|
+
ap.add_argument('--rules', action='store_true', help='输出规则列表')
|
|
163
|
+
args = ap.parse_args()
|
|
164
|
+
|
|
165
|
+
if args.rules:
|
|
166
|
+
for rid, rule in RULES.items():
|
|
167
|
+
print(f"[{rule['severity']:6s}] {rid} [{rule['layer']}] {rule['name']}")
|
|
168
|
+
print(f" {rule['detail']}")
|
|
169
|
+
print(f" 示例: {rule['patterns'][0][:60]}")
|
|
170
|
+
print()
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
scanner = ContentComplianceScanner()
|
|
174
|
+
|
|
175
|
+
if args.demo:
|
|
176
|
+
target = os.path.dirname(__file__) or '.'
|
|
177
|
+
args.recursive = True
|
|
178
|
+
elif not args.target:
|
|
179
|
+
ap.print_help()
|
|
180
|
+
return
|
|
181
|
+
else:
|
|
182
|
+
target = args.target
|
|
183
|
+
|
|
184
|
+
if os.path.isfile(target):
|
|
185
|
+
result = scanner.scan_file(target)
|
|
186
|
+
results = [result]
|
|
187
|
+
elif args.recursive:
|
|
188
|
+
results = scanner.scan_directory(target)
|
|
189
|
+
else:
|
|
190
|
+
results = [scanner.scan_file(f) for f in Path(target).glob('*') if f.is_file()]
|
|
191
|
+
|
|
192
|
+
report = scanner.batch_report(results)
|
|
193
|
+
|
|
194
|
+
if args.json:
|
|
195
|
+
print(json.dumps({'report': report, 'results': results}, indent=2, ensure_ascii=False))
|
|
196
|
+
else:
|
|
197
|
+
print(f"扫描 {report['files_scanned']} 文件: {report['total_violations']} violations ({report['verdict']})")
|
|
198
|
+
if report['by_rule']:
|
|
199
|
+
for rid, count in sorted(report['by_rule'].items()):
|
|
200
|
+
print(f" {rid}: {count}")
|
|
201
|
+
|
|
202
|
+
for r in results[:10]:
|
|
203
|
+
vs = r.get('violations', [])
|
|
204
|
+
if vs:
|
|
205
|
+
print(f"\n {r['target']}:")
|
|
206
|
+
for v in vs[:5]:
|
|
207
|
+
print(f" [{v['severity']:6s}] {v['rule_id']} | {v['match']:12s} | {v['detail'][:60]}")
|
|
208
|
+
|
|
209
|
+
sys.exit(1 if report['verdict'] == 'reject' else 0)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if __name__ == '__main__':
|
|
213
|
+
main()
|