欢迎为 Kernelsoul 项目做出贡献!以下指南帮助你快速上手。
Welcome to Kernelsoul! We appreciate your interest in contributing.
- 行为准则 / Code of Conduct
- 如何贡献 / How to Contribute
- 开发环境 / Development Setup
- 代码风格 / Code Style
- 测试 / Testing
- 提交 PR / Submitting a PR
- 命名规范 / Naming Conventions
- 项目架构 / Architecture Overview
中文: 本项目遵循开放、包容的原则。我们不允许任何形式的骚扰、歧视或不尊重行为。请保持建设性和友善。
English: This project is open and inclusive. Harassment, discrimination, or disrespectful behavior of any kind will not be tolerated. Be constructive and be kind.
- 报告 Bug — 在 GitHub Issues 提交,包含:
- Python 版本、操作系统
- 复现步骤
- 期望行为 vs 实际行为
- 相关日志或错误输出
- 提出功能请求 — 先搜索现有 Issue 避免重复,清晰描述使用场景和期望
- 提交代码 — Fork 仓库 → 创建分支 → 提交修改 → 发起 Pull Request
- 改进文档 — 修复错别字、补充遗漏、翻译不准确、增加示例
- Report Bugs — Open a GitHub Issue with:
- Python version, OS
- Reproduction steps
- Expected vs actual behavior
- Relevant logs or error output
- Feature Requests — Search existing issues first. Clearly describe the use case and expected outcome.
- Submit Code — Fork → Branch → Commit → Pull Request
- Improve Docs — Fix typos, fill gaps, correct translations, add examples.
# 克隆仓库
git clone https://github.com/1960125129h-ctrl/Kernelsoul.git
cd Kernelsoul
# 安装依赖
pip install -r requirements.txt
# 或: pip install openai httpx fastapi uvicorn numpy
# 配置 API Key
cp configs/system.json.example configs/system.json
# 编辑 system.json 填入你的 API Key
# 运行测试(确保修改不破坏已有功能)
python -m pytest tests/ -v# Clone the repo
git clone https://github.com/1960125129h-ctrl/Kernelsoul.git
cd Kernelsoul
# Install dependencies
pip install -r requirements.txt
# Or: pip install openai httpx fastapi uvicorn numpy
# Configure API key
cp configs/system.json.example configs/system.json
# Edit system.json with your API key
# Run tests to verify nothing is broken
python -m pytest tests/ -v- Python: 遵循 PEP 8,行宽 100 字符
- f-string: 外双引号、内单引号(如
f"Value: {item['name']}") - 编码: 所有
.py文件使用 UTF-8 without BOM - 类型提示: 关键函数请加类型注解
- 导入顺序: 标准库 → 第三方库 → 本地模块,分组用空行隔开
- 注释: 公共 API 和核心逻辑用英文写 docstring;中文注释用于复杂逻辑补充说明
- 命名: 类用
PascalCase,函数/变量用snake_case,常量用UPPER_SNAKE_CASE
- Python: PEP 8 compliant, 100-char line width
- f-strings: Outer double quotes, inner single quotes (e.g.,
f"Value: {item['name']}") - Encoding: All
.pyfiles use UTF-8 without BOM - Type hints: Add type annotations to critical functions
- Import order: Standard library → Third-party → Local modules, grouped with blank lines
- Comments: Public APIs and core logic use English docstrings; Chinese comments for complex logic clarifications
- Naming:
PascalCasefor classes,snake_casefor functions/variables,UPPER_SNAKE_CASEfor constants
所有新功能或 Bug 修复必须包含测试。测试使用 pytest 框架。
# 运行全部测试
python -m pytest tests/ -v
# 运行特定测试文件
python -m pytest tests/test_memory.py -v
# 运行特定测试用例
python -m pytest tests/test_memory.py::TestMemoryManager::test_light_compress_trigger_at_10 -v测试原则:
- 单模块测试放在
tests/目录,以test_开头 - 同层测试不需要 mock 真实 API 调用
- 测试数据文件放在
test_data/目录 - 端到端测试放在
tests/e2e/目录
All new features or bug fixes must include tests. We use pytest.
# Run all tests
python -m pytest tests/ -v
# Run a specific test file
python -m pytest tests/test_memory.py -v
# Run a specific test case
python -m pytest tests/test_memory.py::TestMemoryManager::test_light_compress_trigger_at_10 -vTesting principles:
- Unit tests go in
tests/, prefixed withtest_ - Unit tests should not mock real API calls
- Test data goes in
test_data/ - End-to-end tests go in
tests/e2e/
- Fork 本仓库,在 fork 中创建功能分支:
feature/my-feature或fix/issue-123 - 保持小提交,每次提交只做一个逻辑变更
- 写清晰的 commit message,参考以下格式:
feat: add semantic rendering hybrid mode fix: correct memory compression threshold docs: update API endpoint documentation refactor: simplify DSL compiler parse loop test: add evolution trigger edge cases - 发起 PR 前:
- 运行全部测试,确保通过
- 确保你的分支基于最新的
main
- PR 描述包含:
- 变更摘要
- 关联 Issue 编号(如
Closes #123) - 测试步骤(如果适用)
- Fork the repo, create a feature branch in your fork:
feature/my-featureorfix/issue-123 - Keep commits small — one logical change per commit
- Write clear commit messages following this convention:
feat: add semantic rendering hybrid mode fix: correct memory compression threshold docs: update API endpoint documentation refactor: simplify DSL compiler parse loop test: add evolution trigger edge cases - Before opening a PR:
- Run all tests — they must pass
- Rebase your branch onto latest
main
- PR description should include:
- Summary of changes
- Related issue number (e.g.,
Closes #123) - Test steps (if applicable)
Kernelsoul 项目经历过改名,请理解以下命名规则:
| 应使用 | 不应使用 |
|---|---|
Kernelsoul(项目名) |
Soulscript, V4 Character OS |
v4(版本标识,小写) |
V4(大写作为项目名) |
chara_card_v4 |
chara_card_soulscript |
meta_cognition_v4 |
meta_cognition_kernelsoul |
规则: 大写 V4 作为项目名已不再使用;小写 v4 版本标识保留不变。
Kernelsoul was renamed from its previous names. Please follow these conventions:
| Use | Don't Use |
|---|---|
Kernelsoul (project name) |
Soulscript, V4 Character OS |
v4 (version identifier, lowercase) |
V4 (uppercase as project name) |
chara_card_v4 |
chara_card_soulscript |
meta_cognition_v4 |
meta_cognition_kernelsoul |
Rule: Uppercase V4 as a project name is deprecated. Lowercase v4 version identifiers are preserved.
src/kernelsoul/
├── core_engine.py # 引擎主循环,总装所有模块
├── api_server.py # FastAPI REST 服务 + SSE 流式对话
├── game_state.py # 强类型 GameState
├── state_manager.py # 状态持久化
├── memory_manager.py # 三层记忆压缩(轻/深/史诗)
├── parser_engine.py # AI 响应解析(JSON 块 → 裸 JSON → 自然语言)
├── dsl_compiler.py # SLL 递归下降解析器
├── rule_compiler.py # AI 协作规则编译器
├── evolution_trigger.py # 规则进化触发器
├── worldbook_retriever.py # 世界书关键词检索
├── character_card_loader.py# V1-V4 角色卡加载
├── plugin_manager.py # 沙箱插件系统
├── ai_bridge.py # LLM API 桥接
├── context.py # 上下文组装
├── session_meta.py # 会话元数据
├── path_resolver.py # 路径解析
├── draft_manager.py # 草稿管理
├── semantic_engine.py # 语义引擎(v2.4)
├── semantic_renderer.py # 语义渲染器(v2.4)
└── phrase_library.py # KNN 短语库(v2.4)
src/kernelsoul/
├── core_engine.py # Engine main loop, orchestration
├── api_server.py # FastAPI REST server + SSE streaming
├── game_state.py # Strongly-typed GameState
├── state_manager.py # State persistence
├── memory_manager.py # 3-tier memory compression (light/deep/epic)
├── parser_engine.py # AI response parser (JSON block → bare JSON → NL)
├── dsl_compiler.py # SLL recursive descent parser
├── rule_compiler.py # AI-assisted rule compiler
├── evolution_trigger.py # Rule evolution trigger
├── worldbook_retriever.py # Worldbook keyword retrieval
├── character_card_loader.py# V1-V4 character card loader
├── plugin_manager.py # Sandbox plugin system
├── ai_bridge.py # LLM API bridge
├── context.py # Context assembly
├── session_meta.py # Session metadata
├── path_resolver.py # Path resolution
├── draft_manager.py # Draft management
├── semantic_engine.py # Semantic engine (v2.4)
├── semantic_renderer.py # Semantic renderer (v2.4)
└── phrase_library.py # KNN phrase library (v2.4)
Thank you for contributing to Kernelsoul! / 感谢你对 Kernelsoul 的贡献!