longhun 1.0.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.
- longhun-1.0.0/PKG-INFO +77 -0
- longhun-1.0.0/README.md +60 -0
- longhun-1.0.0/longhun/__init__.py +27 -0
- longhun-1.0.0/longhun/cli.py +128 -0
- longhun-1.0.0/longhun/cnsh.py +62 -0
- longhun-1.0.0/longhun/dna.py +35 -0
- longhun-1.0.0/longhun/evaluator.py +98 -0
- longhun-1.0.0/longhun/tricolor.py +84 -0
- longhun-1.0.0/longhun.egg-info/PKG-INFO +77 -0
- longhun-1.0.0/longhun.egg-info/SOURCES.txt +14 -0
- longhun-1.0.0/longhun.egg-info/dependency_links.txt +1 -0
- longhun-1.0.0/longhun.egg-info/entry_points.txt +2 -0
- longhun-1.0.0/longhun.egg-info/requires.txt +3 -0
- longhun-1.0.0/longhun.egg-info/top_level.txt +1 -0
- longhun-1.0.0/pyproject.toml +37 -0
- longhun-1.0.0/setup.cfg +4 -0
longhun-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: longhun
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 🐉 龍魂主权技术栈统一 SDK · DNA追溯 + 三色审计 + 15条国产替代规则 + CNSH桥 · 一个账号走全部服务
|
|
5
|
+
Author-email: 诸葛鑫(UID9622)· 龍芯北辰 <346045695@qq.com>
|
|
6
|
+
License: MulanPSL-2.0
|
|
7
|
+
Keywords: longhun,dna,tricolor,audit,cnsh,sovereign,国产替代
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Provides-Extra: cnsh
|
|
16
|
+
Requires-Dist: cnsh-suite>=1.0; extra == "cnsh"
|
|
17
|
+
|
|
18
|
+
# 🐉 longhun · 龍魂统一 SDK
|
|
19
|
+
|
|
20
|
+
**一个账号 = 龍魂生态全部服务。** 人格工具 + 知识库 + 搜索 + API,统一调用、统一 DNA 追溯、统一三色审计、统一按量计费(CNY·个人每月 1 万次免费)。
|
|
21
|
+
|
|
22
|
+
- DNA: `#龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622`
|
|
23
|
+
- 创建者: 诸葛鑫(UID9622)· 归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
24
|
+
- License: MulanPSL v2(可商业使用·需署名·勿删 DNA 追溯码)
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install longhun
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
零三方依赖 · Python ≥3.8 · 即装即用。
|
|
33
|
+
|
|
34
|
+
## 3 行代码快速开始
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import longhun
|
|
38
|
+
from longhun import generate_dna, audit, scan_text
|
|
39
|
+
|
|
40
|
+
dna = generate_dna("MY-APP") # 🧬 打 DNA 追溯码
|
|
41
|
+
audit("my-app", "started", "🟢") # 📝 记三色审计日志
|
|
42
|
+
print(scan_text("openai.com")) # ⚖️ 15条国产替代扫描 → R01 🔴
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 统一 CLI
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
longhun version
|
|
49
|
+
longhun dna stamp --module MY-APP
|
|
50
|
+
longhun audit requirements.txt # 15条国产替代规则扫描
|
|
51
|
+
longhun audit summary # 三色审计汇总
|
|
52
|
+
longhun tricolor audit pay order_001 🟢
|
|
53
|
+
longhun cnsh run hello.cnsh # CNSH 运行桥
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 能力清单
|
|
57
|
+
|
|
58
|
+
| 模块 | 能力 | 对应 sovereign-stack |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `longhun.dna` | DNA 追溯码生成 | `dna/dna_middleware.py` |
|
|
61
|
+
| `longhun.tricolor` | 三色审计(sqlite·append-only) | `dna/tricolor_audit.py` |
|
|
62
|
+
| `longhun.evaluator` | 15条国产替代规则(人民币主权) | `evaluator/evaluator.py` |
|
|
63
|
+
| `longhun.cnsh` | CNSH 运行桥(本机解释器) | `08_BIN/cnsh/` |
|
|
64
|
+
|
|
65
|
+
## 发布(维护者用)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install build
|
|
69
|
+
python -m build
|
|
70
|
+
twine upload dist/*
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 关联
|
|
74
|
+
|
|
75
|
+
- 统一入口: https://github.com/UID9622/sovereign-stack
|
|
76
|
+
- 主权技术栈全模块: api-gateway / pricing / search-engine / dna / sbom / dependency-isolation / terraform-huawei
|
|
77
|
+
- 定价: 个人 1 万次免费/月 · 超出 ¥0.0001/次 · 开源项目免费
|
longhun-1.0.0/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# 🐉 longhun · 龍魂统一 SDK
|
|
2
|
+
|
|
3
|
+
**一个账号 = 龍魂生态全部服务。** 人格工具 + 知识库 + 搜索 + API,统一调用、统一 DNA 追溯、统一三色审计、统一按量计费(CNY·个人每月 1 万次免费)。
|
|
4
|
+
|
|
5
|
+
- DNA: `#龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622`
|
|
6
|
+
- 创建者: 诸葛鑫(UID9622)· 归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
7
|
+
- License: MulanPSL v2(可商业使用·需署名·勿删 DNA 追溯码)
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install longhun
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
零三方依赖 · Python ≥3.8 · 即装即用。
|
|
16
|
+
|
|
17
|
+
## 3 行代码快速开始
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import longhun
|
|
21
|
+
from longhun import generate_dna, audit, scan_text
|
|
22
|
+
|
|
23
|
+
dna = generate_dna("MY-APP") # 🧬 打 DNA 追溯码
|
|
24
|
+
audit("my-app", "started", "🟢") # 📝 记三色审计日志
|
|
25
|
+
print(scan_text("openai.com")) # ⚖️ 15条国产替代扫描 → R01 🔴
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 统一 CLI
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
longhun version
|
|
32
|
+
longhun dna stamp --module MY-APP
|
|
33
|
+
longhun audit requirements.txt # 15条国产替代规则扫描
|
|
34
|
+
longhun audit summary # 三色审计汇总
|
|
35
|
+
longhun tricolor audit pay order_001 🟢
|
|
36
|
+
longhun cnsh run hello.cnsh # CNSH 运行桥
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 能力清单
|
|
40
|
+
|
|
41
|
+
| 模块 | 能力 | 对应 sovereign-stack |
|
|
42
|
+
| --- | --- | --- |
|
|
43
|
+
| `longhun.dna` | DNA 追溯码生成 | `dna/dna_middleware.py` |
|
|
44
|
+
| `longhun.tricolor` | 三色审计(sqlite·append-only) | `dna/tricolor_audit.py` |
|
|
45
|
+
| `longhun.evaluator` | 15条国产替代规则(人民币主权) | `evaluator/evaluator.py` |
|
|
46
|
+
| `longhun.cnsh` | CNSH 运行桥(本机解释器) | `08_BIN/cnsh/` |
|
|
47
|
+
|
|
48
|
+
## 发布(维护者用)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install build
|
|
52
|
+
python -m build
|
|
53
|
+
twine upload dist/*
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 关联
|
|
57
|
+
|
|
58
|
+
- 统一入口: https://github.com/UID9622/sovereign-stack
|
|
59
|
+
- 主权技术栈全模块: api-gateway / pricing / search-engine / dna / sbom / dependency-isolation / terraform-huawei
|
|
60
|
+
- 定价: 个人 1 万次免费/月 · 超出 ¥0.0001/次 · 开源项目免费
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🐉 龍魂主权技术栈 · 统一 SDK v1.0
|
|
3
|
+
一个包装齐:DNA追溯 + 三色审计 + 15条国产替代规则 + CNSH桥
|
|
4
|
+
一个账号 = 龍魂生态全部服务(人格工具 + 知识库 + 搜索 + API)
|
|
5
|
+
零三方依赖 · 即装即用
|
|
6
|
+
|
|
7
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622
|
|
8
|
+
创建者: 诸葛鑫(UID9622)
|
|
9
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
10
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "1.0.0"
|
|
14
|
+
__dna__ = "#龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622"
|
|
15
|
+
__author__ = "诸葛鑫 | UID9622 · 龍芯北辰"
|
|
16
|
+
__license__ = "MulanPSL v2"
|
|
17
|
+
|
|
18
|
+
from .dna import generate_dna, dna_stamp
|
|
19
|
+
from .tricolor import audit, tricolor_status
|
|
20
|
+
from .evaluator import scan_text, RULES
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"__version__", "__dna__", "__author__", "__license__",
|
|
24
|
+
"generate_dna", "dna_stamp",
|
|
25
|
+
"audit", "tricolor_status",
|
|
26
|
+
"scan_text", "RULES",
|
|
27
|
+
]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
🐉 longhun 统一 CLI v1.0
|
|
4
|
+
一个命令入口走全部能力:
|
|
5
|
+
longhun version
|
|
6
|
+
longhun dna stamp --module xxx
|
|
7
|
+
longhun audit file.py # 15条国产替代扫描
|
|
8
|
+
longhun audit summary # 三色审计汇总
|
|
9
|
+
longhun tricolor audit <module> <event> <color>
|
|
10
|
+
longhun cnsh run <file.cnsh>
|
|
11
|
+
|
|
12
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-CLI-V1.0-UID9622
|
|
13
|
+
创建者: 诸葛鑫(UID9622)
|
|
14
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
15
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import json
|
|
20
|
+
import sys
|
|
21
|
+
from . import __version__, __dna__
|
|
22
|
+
from . import dna as dna_mod
|
|
23
|
+
from . import tricolor as tricolor_mod
|
|
24
|
+
from . import evaluator as evaluator_mod
|
|
25
|
+
from . import cnsh as cnsh_mod
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def cmd_version(args):
|
|
29
|
+
print(json.dumps({
|
|
30
|
+
"name": "longhun",
|
|
31
|
+
"version": __version__,
|
|
32
|
+
"dna": __dna__,
|
|
33
|
+
"author": "诸葛鑫 | UID9622 · 龍芯北辰",
|
|
34
|
+
"license": "MulanPSL v2",
|
|
35
|
+
}, indent=2, ensure_ascii=False))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def cmd_dna(args):
|
|
39
|
+
stamp = dna_mod.dna_stamp(args.module, args.version)
|
|
40
|
+
if args.json:
|
|
41
|
+
print(json.dumps(stamp, indent=2, ensure_ascii=False))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def cmd_audit(args):
|
|
45
|
+
if args.target == "summary":
|
|
46
|
+
counts = tricolor_mod.summary()
|
|
47
|
+
print(json.dumps({"summary": counts,
|
|
48
|
+
"tricolor": "🔴" if counts["🔴"] else
|
|
49
|
+
("🟡" if counts["🟡"] else "🟢")},
|
|
50
|
+
indent=2, ensure_ascii=False))
|
|
51
|
+
return
|
|
52
|
+
result = evaluator_mod.scan_file(args.target)
|
|
53
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def cmd_tricolor(args):
|
|
57
|
+
if args.action == "audit":
|
|
58
|
+
dna = tricolor_mod.audit(args.module, args.event, args.color,
|
|
59
|
+
json.loads(args.detail or "{}"))
|
|
60
|
+
print(f"✅ 已记录审计日志 · DNA: {dna}")
|
|
61
|
+
elif args.action == "summary":
|
|
62
|
+
counts = tricolor_mod.summary(args.module)
|
|
63
|
+
print(json.dumps(counts, indent=2, ensure_ascii=False))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def cmd_cnsh(args):
|
|
67
|
+
result = cnsh_mod.run_cnsh(args.file, use_code=args.code)
|
|
68
|
+
if not result.get("ok"):
|
|
69
|
+
print(f"❌ {result.get('error', '运行失败')}", file=sys.stderr)
|
|
70
|
+
sys.exit(1)
|
|
71
|
+
if result.get("stdout"):
|
|
72
|
+
print(result["stdout"])
|
|
73
|
+
if result.get("stderr"):
|
|
74
|
+
print(result["stderr"], file=sys.stderr)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def build_parser():
|
|
78
|
+
p = argparse.ArgumentParser(
|
|
79
|
+
prog="longhun",
|
|
80
|
+
description="🐉 龍魂主权技术栈统一 SDK · DNA追溯 + 三色审计 + 15条国产替代规则 + CNSH桥")
|
|
81
|
+
sub = p.add_subparsers(dest="command")
|
|
82
|
+
|
|
83
|
+
sub.add_parser("version", help="版本信息")
|
|
84
|
+
|
|
85
|
+
dna_p = sub.add_parser("dna", help="DNA 追溯码")
|
|
86
|
+
dna_s = dna_p.add_subparsers(dest="dna_cmd", required=True)
|
|
87
|
+
stamp_p = dna_s.add_parser("stamp", help="生成 DNA 戳")
|
|
88
|
+
stamp_p.add_argument("--module", default="SDK")
|
|
89
|
+
stamp_p.add_argument("--version", default="1.0")
|
|
90
|
+
stamp_p.add_argument("--json", action="store_true")
|
|
91
|
+
|
|
92
|
+
audit_p = sub.add_parser("audit", help="15条国产替代规则评估")
|
|
93
|
+
audit_p.add_argument("target", help="文件路径 或 summary")
|
|
94
|
+
|
|
95
|
+
tricolor_p = sub.add_parser("tricolor", help="三色审计")
|
|
96
|
+
tri_s = tricolor_p.add_subparsers(dest="tri_cmd", required=True)
|
|
97
|
+
aud_p = tri_s.add_parser("audit", help="记录审计日志")
|
|
98
|
+
aud_p.add_argument("module"); aud_p.add_argument("event")
|
|
99
|
+
aud_p.add_argument("color", choices=["🟢", "🟡", "🔴"])
|
|
100
|
+
aud_p.add_argument("--detail", default="{}")
|
|
101
|
+
tri_s.add_parser("summary", help="审计汇总").add_argument("--module")
|
|
102
|
+
|
|
103
|
+
cnsh_p = sub.add_parser("cnsh", help="CNSH 运行桥")
|
|
104
|
+
cnsh_s = cnsh_p.add_subparsers(dest="cnsh_cmd", required=True)
|
|
105
|
+
run_p = cnsh_s.add_parser("run", help="运行 CNSH")
|
|
106
|
+
run_p.add_argument("file", help=".cnsh 文件路径")
|
|
107
|
+
run_p.add_argument("--code", action="store_true", help="按内联代码处理")
|
|
108
|
+
|
|
109
|
+
return p
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main():
|
|
113
|
+
parser = build_parser()
|
|
114
|
+
args = parser.parse_args()
|
|
115
|
+
if not args.command:
|
|
116
|
+
parser.print_help()
|
|
117
|
+
return
|
|
118
|
+
{
|
|
119
|
+
"version": cmd_version,
|
|
120
|
+
"dna": cmd_dna,
|
|
121
|
+
"audit": cmd_audit,
|
|
122
|
+
"tricolor": cmd_tricolor,
|
|
123
|
+
"cnsh": cmd_cnsh,
|
|
124
|
+
}[args.command](args)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if __name__ == "__main__":
|
|
128
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🐉 CNSH 运行桥 v1.0
|
|
3
|
+
统一入口:longhun cnsh run <file.cnsh>
|
|
4
|
+
本机有 CNSH 运行时 → 直接调用(08_BIN/cnsh/interpreter.py 或 cnsh 命令)
|
|
5
|
+
没有 → 清晰提示安装路径(零黑箱)
|
|
6
|
+
|
|
7
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-CNSH-V1.0-UID9622
|
|
8
|
+
创建者: 诸葛鑫(UID9622)
|
|
9
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
10
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
# 已知的 CNSH 解释器路径(按优先级)
|
|
20
|
+
CANDIDATES = [
|
|
21
|
+
os.environ.get("LONGHUN_CNSH_PATH", ""),
|
|
22
|
+
str(Path.home() / "longhun-system/08_BIN/cnsh/interpreter.py"),
|
|
23
|
+
str(Path.home() / "longhun-system/bin/lh.py"),
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _find_interpreter():
|
|
28
|
+
for cand in CANDIDATES:
|
|
29
|
+
if cand and Path(cand).exists():
|
|
30
|
+
return cand
|
|
31
|
+
if shutil.which("cnsh"):
|
|
32
|
+
return "cnsh"
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run_cnsh(file_or_code, use_code: bool = False) -> dict:
|
|
37
|
+
"""运行 CNSH 文件或内联代码"""
|
|
38
|
+
interpreter = _find_interpreter()
|
|
39
|
+
if not interpreter:
|
|
40
|
+
return {
|
|
41
|
+
"ok": False,
|
|
42
|
+
"error": (
|
|
43
|
+
"未找到 CNSH 运行时。请任选其一:\n"
|
|
44
|
+
" 1) 安装: pip install cnsh-suite\n"
|
|
45
|
+
" 2) 设置: export LONGHUN_CNSH_PATH=/path/to/cnsh/interpreter.py\n"
|
|
46
|
+
" 3) 克隆: https://github.com/UID9622/CNSH"
|
|
47
|
+
),
|
|
48
|
+
}
|
|
49
|
+
cmd = [sys.executable, interpreter, "--code", file_or_code] if use_code \
|
|
50
|
+
else [sys.executable, interpreter, file_or_code]
|
|
51
|
+
try:
|
|
52
|
+
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
|
53
|
+
return {
|
|
54
|
+
"ok": proc.returncode == 0,
|
|
55
|
+
"stdout": proc.stdout,
|
|
56
|
+
"stderr": proc.stderr,
|
|
57
|
+
"exit_code": proc.returncode,
|
|
58
|
+
}
|
|
59
|
+
except subprocess.TimeoutExpired:
|
|
60
|
+
return {"ok": False, "error": "CNSH 运行超时(30s)"}
|
|
61
|
+
except Exception as e:
|
|
62
|
+
return {"ok": False, "error": str(e)}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🐉 DNA 追溯码生成 v1.0
|
|
3
|
+
格式: #龍芯⚡️YYYY-MM-DD-模块-V版本-UID9622
|
|
4
|
+
溯源: 每个调用/文件/请求都有身份 · 零黑箱可复核
|
|
5
|
+
|
|
6
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-DNA-V1.0-UID9622
|
|
7
|
+
创建者: 诸葛鑫(UID9622)
|
|
8
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
9
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
|
|
14
|
+
UID = "UID9622"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def generate_dna(module: str, version: str = "1.0") -> str:
|
|
18
|
+
"""生成 DNA 追溯码:模块 + 版本 + 日期 + 归属"""
|
|
19
|
+
date_str = datetime.now().strftime("%Y-%m-%d")
|
|
20
|
+
return f"#龍芯⚡️{date_str}-{module.upper()}-V{version}-{UID}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def dna_stamp(module: str = "SDK", version: str = "1.0") -> dict:
|
|
24
|
+
"""打印并返回 DNA 戳(含时间)"""
|
|
25
|
+
stamp = {
|
|
26
|
+
"dna": generate_dna(module, version),
|
|
27
|
+
"uid": UID,
|
|
28
|
+
"timestamp": datetime.now().isoformat(),
|
|
29
|
+
}
|
|
30
|
+
print(f"🧬 {stamp['dna']}")
|
|
31
|
+
return stamp
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
dna_stamp()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🐉 15条国产替代规则评估器 v1.0
|
|
3
|
+
人民币主权 · 自主可控 · 能自建不申请 · 确需外部先国产
|
|
4
|
+
逐条三色判定:🟢国产合规 / 🟡可替代待改进 / 🔴强制国产
|
|
5
|
+
|
|
6
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-EVALUATOR-V1.0-UID9622
|
|
7
|
+
创建者: 诸葛鑫(UID9622)
|
|
8
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
9
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# ──────────────────────────────────────────
|
|
13
|
+
# 15条国产替代规则(人民币主权焊点 #IRON-YUAN-SOVEREIGNTY)
|
|
14
|
+
# ──────────────────────────────────────────
|
|
15
|
+
RULES = [
|
|
16
|
+
{"id": "R01", "category": "大模型/API", "domestic": ["hunyuan", "dashscope", "qianfan", "wenxin", "doubao", "volcengine", "zhipu", "bigmodel", "spark"],
|
|
17
|
+
"foreign": ["openai.com", "anthropic", "claude.ai", "api.gemini", "googleapis"],
|
|
18
|
+
"note": "混元/通义/文心/豆包/智谱优先,OpenAI/Claude 强制国产"},
|
|
19
|
+
{"id": "R02", "category": "云服务", "domestic": ["huaweicloud", "myhuaweicloud", "aliyuncs", "qcloud", "tencentcloud"],
|
|
20
|
+
"foreign": ["amazonaws", "azure", "cloud.google", "vercel", "netlify"],
|
|
21
|
+
"note": "华为云/阿里云/腾讯云优先,AWS/Azure 强制国产"},
|
|
22
|
+
{"id": "R03", "category": "数据库", "domestic": ["opengauss", "tidb", "oceanbase", "gaussdb", "dmdbms", "polardb", "doris"],
|
|
23
|
+
"foreign": ["oracle", "sqlserver", "mongodb.com", "neon.tech"],
|
|
24
|
+
"note": "openGauss/TiDB/OceanBase/GaussDB 优先"},
|
|
25
|
+
{"id": "R04", "category": "对象存储", "domestic": ["obs", "cos.", "oss-", "myhuaweicloud"],
|
|
26
|
+
"foreign": ["s3.amazonaws", "storage.googleapis", "cloudflare-r2"],
|
|
27
|
+
"note": "OBS/COS/OSS 优先,S3 可替代"},
|
|
28
|
+
{"id": "R05", "category": "搜索", "domestic": ["searxng", "baidu.com/s", "cn.bing", "bing.com"],
|
|
29
|
+
"foreign": ["google.com/search", "api.duckduckgo", "serpapi", "brave.com/search"],
|
|
30
|
+
"note": "自建 SearXNG/百度/Bing 优先,禁付费外部搜索 API"},
|
|
31
|
+
{"id": "R06", "category": "地图", "domestic": ["amap.com", "lbs.amap", "api.map.baidu", "map.qq"],
|
|
32
|
+
"foreign": ["maps.google", "mapbox"],
|
|
33
|
+
"note": "高德/百度/腾讯地图优先,Google Maps 强制国产"},
|
|
34
|
+
{"id": "R07", "category": "支付", "domestic": ["alipay", "wechatpay", "wxpay", "tenpay"],
|
|
35
|
+
"foreign": ["stripe", "paypal", "adyen"],
|
|
36
|
+
"note": "支付宝/微信支付/数字人民币优先"},
|
|
37
|
+
{"id": "R08", "category": "推送", "domestic": ["jpush", "getui", "umeng"],
|
|
38
|
+
"foreign": ["fcm.googleapis", "apns", "onesignal"],
|
|
39
|
+
"note": "极光/个推/友盟优先(境内业务强制)"},
|
|
40
|
+
{"id": "R09", "category": "语音/OCR", "domestic": ["iflytek", "xfyun", "aip.baidubce"],
|
|
41
|
+
"foreign": ["speech.googleapis", "aws.transcribe", "ocr.space"],
|
|
42
|
+
"note": "讯飞/百度优先"},
|
|
43
|
+
{"id": "R10", "category": "代码托管", "domestic": ["gitee.com"],
|
|
44
|
+
"foreign": ["gitlab.com", "bitbucket.org"],
|
|
45
|
+
"note": "GitHub(主)/Gitee(镜像) 优先,境外 GitLab 可替代"},
|
|
46
|
+
{"id": "R11", "category": "字体/前端资源", "domestic": ["fonts.loli.net", "cdn.bootcss", "lib.baomitu"],
|
|
47
|
+
"foreign": ["fonts.googleapis", "fonts.gstatic", "cdnjs.cloudflare", "unpkg.com"],
|
|
48
|
+
"note": "思源/自托管/国内镜像优先,Google Fonts 强制国产"},
|
|
49
|
+
{"id": "R12", "category": "数据分析", "domestic": ["aliyun", "umeng"],
|
|
50
|
+
"foreign": ["google-analytics", "googletagmanager", "segment.com", "amplitude", "mixpanel"],
|
|
51
|
+
"note": "自建统计优先,GA 强制国产"},
|
|
52
|
+
{"id": "R13", "category": "邮件", "domestic": ["exmail.qq", "qiye.aliyun"],
|
|
53
|
+
"foreign": ["gmail.com", "sendgrid", "mailgun"],
|
|
54
|
+
"note": "自建/腾讯企业邮/阿里企业邮优先"},
|
|
55
|
+
{"id": "R14", "category": "CI/CD", "domestic": ["coding.net"],
|
|
56
|
+
"foreign": ["github-actions", "circleci", "travis-ci", "gitlab-ci"],
|
|
57
|
+
"note": "腾讯 Coding 优先;GitHub Actions 可接受(主仓托管在 GitHub)"},
|
|
58
|
+
{"id": "R15", "category": "CDN/域名", "domestic": ["dnspod", "qcloud", "aliyun.com"],
|
|
59
|
+
"foreign": ["cloudflare", "akamai", "fastly", "route53"],
|
|
60
|
+
"note": "DNSPod/国内节点优先;Cloudflare 仅作境外降级"},
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def scan_text(text: str) -> dict:
|
|
65
|
+
"""对配置/代码/文档文本跑 15 条规则"""
|
|
66
|
+
low = (text or "").lower()
|
|
67
|
+
results = []
|
|
68
|
+
for rule in RULES:
|
|
69
|
+
hit_domestic = [kw for kw in rule["domestic"] if kw in low]
|
|
70
|
+
hit_foreign = [kw for kw in rule["foreign"] if kw in low]
|
|
71
|
+
if hit_foreign and not hit_domestic:
|
|
72
|
+
level = "🔴"
|
|
73
|
+
elif hit_foreign and hit_domestic:
|
|
74
|
+
level = "🟡"
|
|
75
|
+
elif hit_domestic:
|
|
76
|
+
level = "🟢"
|
|
77
|
+
else:
|
|
78
|
+
continue
|
|
79
|
+
results.append({
|
|
80
|
+
"id": rule["id"], "category": rule["category"], "level": level,
|
|
81
|
+
"hit_domestic": hit_domestic, "hit_foreign": hit_foreign,
|
|
82
|
+
"note": rule["note"],
|
|
83
|
+
})
|
|
84
|
+
red = sum(1 for r in results if r["level"] == "🔴")
|
|
85
|
+
yello = sum(1 for r in results if r["level"] == "🟡")
|
|
86
|
+
green = sum(1 for r in results if r["level"] == "🟢")
|
|
87
|
+
return {
|
|
88
|
+
"rules_checked": len(results),
|
|
89
|
+
"results": results,
|
|
90
|
+
"summary": {"🔴": red, "🟡": yello, "🟢": green},
|
|
91
|
+
"tricolor": "🔴" if red else ("🟡" if yello else "🟢"),
|
|
92
|
+
"principle": "人民币主权·自主可控·能自建不申请·确需外部先国产",
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def scan_file(path: str) -> dict:
|
|
97
|
+
with open(path, encoding="utf-8", errors="ignore") as f:
|
|
98
|
+
return scan_text(f.read())
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🐉 三色审计 v1.0
|
|
3
|
+
🟢 绿色:通过·可用·正常
|
|
4
|
+
🟡 黄色:待审·降级·需人工确认
|
|
5
|
+
🔴 红色:拒绝·熔断·触发告警
|
|
6
|
+
审计日志落 sqlite(~/.longhun/audit.db)· append-only
|
|
7
|
+
|
|
8
|
+
DNA: #龍芯⚡️2026-08-31-LONGHUN-TRICOLOR-V1.0-UID9622
|
|
9
|
+
创建者: 诸葛鑫(UID9622)
|
|
10
|
+
归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
11
|
+
License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import sqlite3
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from .dna import generate_dna
|
|
20
|
+
|
|
21
|
+
DB_PATH = Path.home() / ".longhun" / "audit.db"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _init_db():
|
|
25
|
+
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
conn = sqlite3.connect(str(DB_PATH))
|
|
27
|
+
conn.executescript("""
|
|
28
|
+
CREATE TABLE IF NOT EXISTS audit_log (
|
|
29
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
+
timestamp TEXT,
|
|
31
|
+
module TEXT,
|
|
32
|
+
event TEXT,
|
|
33
|
+
color TEXT CHECK(color IN ('🟢','🟡','🔴')),
|
|
34
|
+
detail TEXT,
|
|
35
|
+
dna TEXT
|
|
36
|
+
);
|
|
37
|
+
""")
|
|
38
|
+
conn.commit()
|
|
39
|
+
conn.close()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def tricolor_status(status_code: int, has_data: bool = True) -> str:
|
|
43
|
+
"""三色判定:2xx且有数据=🟢 / 4xx=🟡 / 5xx=🔴"""
|
|
44
|
+
if status_code < 300 and has_data:
|
|
45
|
+
return "🟢"
|
|
46
|
+
if status_code < 500:
|
|
47
|
+
return "🟡"
|
|
48
|
+
return "🔴"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def audit(module: str, event: str, color: str, detail: dict = None) -> str:
|
|
52
|
+
"""记录一条审计日志 · 返回该条 DNA"""
|
|
53
|
+
_init_db()
|
|
54
|
+
dna = generate_dna(f"AUDIT-{module}")
|
|
55
|
+
conn = sqlite3.connect(str(DB_PATH))
|
|
56
|
+
conn.execute(
|
|
57
|
+
"INSERT INTO audit_log (timestamp, module, event, color, detail, dna) "
|
|
58
|
+
"VALUES (?,?,?,?,?,?)",
|
|
59
|
+
(datetime.now().isoformat(), module, event, color,
|
|
60
|
+
json.dumps(detail or {}, ensure_ascii=False), dna),
|
|
61
|
+
)
|
|
62
|
+
conn.commit()
|
|
63
|
+
conn.close()
|
|
64
|
+
if color == "🔴":
|
|
65
|
+
print(f"🔴 [AUDIT-ALERT] {module} | {event} | {detail}")
|
|
66
|
+
return dna
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def summary(module: str = None) -> dict:
|
|
70
|
+
"""审计汇总(按颜色计数)"""
|
|
71
|
+
_init_db()
|
|
72
|
+
conn = sqlite3.connect(str(DB_PATH))
|
|
73
|
+
where, params = ("WHERE module=?", (module,)) if module else ("", ())
|
|
74
|
+
rows = conn.execute(
|
|
75
|
+
f"SELECT color, COUNT(*) FROM audit_log {where} GROUP BY color", params
|
|
76
|
+
).fetchall()
|
|
77
|
+
conn.close()
|
|
78
|
+
counts = {"🟢": 0, "🟡": 0, "🔴": 0}
|
|
79
|
+
for color, cnt in rows:
|
|
80
|
+
counts[color] = cnt
|
|
81
|
+
return counts
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
_init_db()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: longhun
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 🐉 龍魂主权技术栈统一 SDK · DNA追溯 + 三色审计 + 15条国产替代规则 + CNSH桥 · 一个账号走全部服务
|
|
5
|
+
Author-email: 诸葛鑫(UID9622)· 龍芯北辰 <346045695@qq.com>
|
|
6
|
+
License: MulanPSL-2.0
|
|
7
|
+
Keywords: longhun,dna,tricolor,audit,cnsh,sovereign,国产替代
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Provides-Extra: cnsh
|
|
16
|
+
Requires-Dist: cnsh-suite>=1.0; extra == "cnsh"
|
|
17
|
+
|
|
18
|
+
# 🐉 longhun · 龍魂统一 SDK
|
|
19
|
+
|
|
20
|
+
**一个账号 = 龍魂生态全部服务。** 人格工具 + 知识库 + 搜索 + API,统一调用、统一 DNA 追溯、统一三色审计、统一按量计费(CNY·个人每月 1 万次免费)。
|
|
21
|
+
|
|
22
|
+
- DNA: `#龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622`
|
|
23
|
+
- 创建者: 诸葛鑫(UID9622)· 归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
24
|
+
- License: MulanPSL v2(可商业使用·需署名·勿删 DNA 追溯码)
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install longhun
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
零三方依赖 · Python ≥3.8 · 即装即用。
|
|
33
|
+
|
|
34
|
+
## 3 行代码快速开始
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import longhun
|
|
38
|
+
from longhun import generate_dna, audit, scan_text
|
|
39
|
+
|
|
40
|
+
dna = generate_dna("MY-APP") # 🧬 打 DNA 追溯码
|
|
41
|
+
audit("my-app", "started", "🟢") # 📝 记三色审计日志
|
|
42
|
+
print(scan_text("openai.com")) # ⚖️ 15条国产替代扫描 → R01 🔴
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 统一 CLI
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
longhun version
|
|
49
|
+
longhun dna stamp --module MY-APP
|
|
50
|
+
longhun audit requirements.txt # 15条国产替代规则扫描
|
|
51
|
+
longhun audit summary # 三色审计汇总
|
|
52
|
+
longhun tricolor audit pay order_001 🟢
|
|
53
|
+
longhun cnsh run hello.cnsh # CNSH 运行桥
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 能力清单
|
|
57
|
+
|
|
58
|
+
| 模块 | 能力 | 对应 sovereign-stack |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `longhun.dna` | DNA 追溯码生成 | `dna/dna_middleware.py` |
|
|
61
|
+
| `longhun.tricolor` | 三色审计(sqlite·append-only) | `dna/tricolor_audit.py` |
|
|
62
|
+
| `longhun.evaluator` | 15条国产替代规则(人民币主权) | `evaluator/evaluator.py` |
|
|
63
|
+
| `longhun.cnsh` | CNSH 运行桥(本机解释器) | `08_BIN/cnsh/` |
|
|
64
|
+
|
|
65
|
+
## 发布(维护者用)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install build
|
|
69
|
+
python -m build
|
|
70
|
+
twine upload dist/*
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 关联
|
|
74
|
+
|
|
75
|
+
- 统一入口: https://github.com/UID9622/sovereign-stack
|
|
76
|
+
- 主权技术栈全模块: api-gateway / pricing / search-engine / dna / sbom / dependency-isolation / terraform-huawei
|
|
77
|
+
- 定价: 个人 1 万次免费/月 · 超出 ¥0.0001/次 · 开源项目免费
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
longhun/__init__.py
|
|
4
|
+
longhun/cli.py
|
|
5
|
+
longhun/cnsh.py
|
|
6
|
+
longhun/dna.py
|
|
7
|
+
longhun/evaluator.py
|
|
8
|
+
longhun/tricolor.py
|
|
9
|
+
longhun.egg-info/PKG-INFO
|
|
10
|
+
longhun.egg-info/SOURCES.txt
|
|
11
|
+
longhun.egg-info/dependency_links.txt
|
|
12
|
+
longhun.egg-info/entry_points.txt
|
|
13
|
+
longhun.egg-info/requires.txt
|
|
14
|
+
longhun.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
longhun
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "longhun"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "🐉 龍魂主权技术栈统一 SDK · DNA追溯 + 三色审计 + 15条国产替代规则 + CNSH桥 · 一个账号走全部服务"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MulanPSL-2.0" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "诸葛鑫(UID9622)· 龍芯北辰", email = "346045695@qq.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["longhun", "dna", "tricolor", "audit", "cnsh", "sovereign", "国产替代"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
]
|
|
23
|
+
dependencies = []
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
cnsh = ["cnsh-suite>=1.0"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
longhun = "longhun.cli:main"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
packages = ["longhun"]
|
|
33
|
+
|
|
34
|
+
# DNA: #龍芯⚡️2026-08-31-LONGHUN-SDK-V1.0-UID9622
|
|
35
|
+
# 创建者: 诸葛鑫(UID9622)
|
|
36
|
+
# 归属名: 诸葛鑫 | UID9622 · 龍芯北辰
|
|
37
|
+
# License: MulanPSL v2 (https://license.coscl.org.cn/MulanPSL2)
|
longhun-1.0.0/setup.cfg
ADDED