码巢引擎2026年开发文档
00-开发规范
后端规范
README
后端开发手册
前端规范
README
TypeScript最佳实践
前端布局规范
前端页面模板
前端颜色与组件规范
核心规范
组件配置手册
问题排查指南
页面模板
最佳实践
README
bp-20260223-m7ps
图片上传优化总结
BUG自动记录系统使用指南
README
TYPE_SAFETY_GUIDE
常见BUG知识库
常见BUG知识库
开发前检查清单
开发安全规范
开发规范-完整版-含FutureBirdAadminAi部署
数据模型字典
文档分类规范
文档标准化规范
文档模板-基础版
文档模板-技术版
类型安全快速参考卡
类型安全规范体系
规范更新指南
过期文档清理机制
错误处理规范
错误预防指南
常见BUG知识库
常见BUG知识库
01-快速开始
Gitee快速开始
README
协作快速开始
快速开始
质量保证快速开始
02-部署指南
Docker更新指南
Docker部署
FutureBirdAadminAi部署指南
FutureBirdAadminAi部署问题分析
README
发布指南
宝塔Docker部署教程
宝塔PM2部署教程
宝塔图形化部署教程
快速发布指南
数据库和依赖变更处理指南
构建和发布
构建标准
构建检查清单
生产部署快速开始
生产部署方案
生产部署标准
生产部署检查清单
程序备份性能
自动修复和发布指南
自动化发布命令使用指南
部署快速开始
部署指南
项目更新部署指南
03-开发指南
Git凭据配置
Git推送规则
Git自动配置
README
全局样式
协作设置
定时任务
开发指南
开发流程
开发环境标准
技术改进
贡献指南
项目目录树
项目目录结构
04-API文档
API接口文档
README
hr-api
企业API
05-数据库
DATABASE_SCHEMA
README
分区指南
数据库字典
数据持久化
数据模型统一
数据迁移
06-架构设计
RBAC-PERMISSIONS
README
SaaS客户引导流程设计
companyId统一规范
employee-permission-system-design
enterprise-data-linkage
仓库实现总结
仓库模式
企业管理端员工权限系统分析
前端架构
前端重构总结
员工权限系统评估报告
员工管理菜单重构方案
权限系统混乱问题分析
架构优化计划
架构使用指南
架构结构
架构结构
状态管理
用户身份管理体系
系统架构
面试管理模块重构规划
项目技术栈
07-测试质量
README
测试修复标准
测试报告
质量保证系统
08-版本管理
CHANGELOG
README
VERSION_RULES
09-配置指南
README
SMTP配置指南
主题切换指南
渠道配置指南
环境变量指南
环境隔离
12-项目记忆
README
知识库导入指南
记忆系统指南
13-迁移指南
README
备份迁移指南
管理员迁移指南
迁移快速开始
17-其他
README
压缩摘要
18-开放平台
01-架构设计
02-API接口设计
03-安全机制
04-前端设计
05-数据库设计
开放平台API指南
开放平台API说明
19-智能进化
AI执行规则
AI进化机制
README
自动化实现总览
黄金规则
40-操作教程
README
微信公众号域名配置指南
微信本地开发调试指南
44-技能文件
alipay-payment-integration
references
checklist
SKILL
audio
python
README
typescript
README
SKILL
database
python
README
typescript
README
SKILL
design-style-thinking
SKILL
doctor
references
sql-patterns
SKILL
document-generation
python
README
SKILL
email
SKILL
embedding
python
README
typescript
README
SKILL
expo-advanced
references
audio-record-play
file-upload
masonry-layout
save-to-gallery
top-tab-navigation
SKILL
feishu-base
SKILL
feishu-message
SKILL
fetch-url
python
README
typescript
README
SKILL
frontend-design
LICENSE
SKILL
FutureBird-coding-web-performance-best-practice
SKILL
general-dev-preview
references
web-preview
SKILL
image-generation
python
README
typescript
README
SKILL
knowledge
references
python
README
typescript
README
cli
SKILL
llm
python
README
typescript
README
SKILL
miniapp-upload-asr
SKILL
pptx-generation
python
README
SKILL
project-memory-loader
scripts
project_memory_loader
SKILL
repair
scripts
merge-commit-map
SKILL
shadcn-web-base-theme
assets
colors
amber
artistic-green
bento-blue
blue
cyan
emerald
fuchsia
gray
green
indigo
lime
low-pink
neutral
orange
purple
red
retro-brown
rose
sky
supbase-green
teal
tech-purple
vintage-grey
violet
yellow
fonts
business
classic
playful
radius
2xl
2xs
lg
md
none
sm
xl
xs
shadow
artistic
bento
cool
retro
superbase
tech
tool
vintage
default
references
colors
fonts
quick
radius
shadows
scripts
theme
SKILL
package
skill-creator-coze
scripts
init_skill
quick_validate
SKILL
storage
python
README
typescript
README
SKILL
supabase
assets
supabase-client
supabase-client
references
_future
asset-supabase-browser
asset-supabase-config-inject
asset-supabase-config-route
python-auth
python-realtime
python-storage
typescript-auth
typescript-realtime
typescript-storage
typescript-supabase-browser
typescript-supabase-config-inject
typescript-supabase-config-route
python
README
database
edge-functions
orm-model-guide
supabase_client
typescript
README
database
drizzle-schema-guide
edge-functions
supabase-client
cli
rls
SKILL
supabase-auth
references
typescript
supabase-browser
supabase-config-inject
supabase-config-route
auth-config
verify-session
SKILL
ui-design-ref
reference
3D黏土风
克莱因蓝高定风
暗黑科技风
杂志风
极光柔和
柔和卡片
玻璃拟态
纯白极简风
自然有机
SKILL
ui-ux-pro-max
scripts
core
design_system
search
SKILL
vercel-composition-patterns
rules
architecture-avoid-boolean-props
architecture-compound-components
patterns-children-over-render-props
patterns-explicit-variants
react19-no-forwardref
state-context-interface
state-decouple-implementation
state-lift-state
AGENTS
SKILL
vercel-react-best-practices
rules
advanced-event-handler-refs
advanced-init-once
advanced-use-latest
async-api-routes
async-defer-await
async-dependencies
async-parallel
async-suspense-boundaries
bundle-barrel-imports
bundle-conditional
bundle-defer-third-party
bundle-dynamic-imports
bundle-preload
client-event-listeners
client-localstorage-schema
client-passive-event-listeners
client-swr-dedup
js-batch-dom-css
js-cache-function-results
js-cache-property-access
js-cache-storage
js-combine-iterations
js-early-exit
js-hoist-regexp
js-index-maps
js-length-check-first
js-min-max-loop
js-set-map-lookups
js-tosorted-immutable
rendering-activity
rendering-animate-svg-wrapper
rendering-conditional-render
rendering-content-visibility
rendering-hoist-jsx
rendering-hydration-no-flicker
rendering-hydration-suppress-warning
rendering-svg-precision
rendering-usetransition-loading
rerender-defer-reads
rerender-dependencies
rerender-derived-state-no-effect
rerender-derived-state
rerender-functional-setstate
rerender-lazy-state-init
rerender-memo-with-default-value
rerender-memo
rerender-move-effect-to-event
rerender-simple-expression-in-memo
rerender-transitions
rerender-use-ref-transient-values
server-auth-actions
server-cache-lru
server-cache-react
server-dedup-props
server-parallel-fetching
server-serialization
AGENTS
SKILL
video-edit
python
README
typescript
README
SKILL
video-generation
python
README
typescript
README
SKILL
volcano-ark
SKILL
web-design-guidelines
SKILL
web-search
python
README
typescript
README
SKILL
webrtc-best-practice
SKILL
websocket-guide
references
nextjs
nodejs
SKILL
wechat-bot
SKILL
wechat-official-account
SKILL
README
README
未来鸟:企业数字化转型奔腾的力量!
-
+
首页
project_memory_loader
#!/usr/bin/env python3 """ 项目记忆加载器 v2.0 用于调用项目记忆 API 获取项目上下文信息 功能: - 加载项目上下文(PROJECT.md + TODO + 记忆数据) - 离线模式支持 - 记忆质量评分 - 重复记忆合并 - 过期记忆清理 - 自动维护 API 端点:http://localhost:5000/api/project-memory/context """ import argparse import json import os import re import sys from datetime import datetime from pathlib import Path from typing import Any, Dict, List, Optional try: import requests except ImportError: requests = None print("Warning: requests module not installed. Offline mode will be used.", file=sys.stderr) # 配置 DEFAULT_API_URL = "http://localhost:5000/api/project-memory/context" PROJECT_ROOT = os.environ.get("COZE_WORKSPACE_PATH", "/workspace/projects") OFFLINE_MODE = os.environ.get("OFFLINE_MODE", "").lower() in ("true", "1", "yes") class ProjectContextLoader: """项目上下文加载器""" def __init__( self, api_url: str = DEFAULT_API_URL, offline: bool = False, timeout: int = 10 ): self.api_url = api_url self.offline = offline or OFFLINE_MODE or requests is None self.timeout = timeout self.project_root = Path(PROJECT_ROOT) def load_context( self, format: str = "json", refresh: bool = False, compact: bool = False ) -> Dict[str, Any]: """ 加载项目上下文 Args: format: 返回格式 (json/markdown) refresh: 是否强制刷新缓存 compact: 是否使用精简模式 Returns: 项目上下文数据 """ if self.offline: return self._load_offline() return self._load_from_api(format, refresh, compact) def _load_from_api( self, format: str, refresh: bool, compact: bool ) -> Dict[str, Any]: """从 API 加载上下文""" params = {} if format == "markdown": params["format"] = "markdown" if refresh: params["refresh"] = "true" if compact: params["compact"] = "true" try: response = requests.get( self.api_url, params=params, headers={"Accept": "application/json"}, timeout=self.timeout ) if response.status_code == 200: if format == "markdown": return { "success": True, "format": "markdown", "content": response.text } return response.json() elif response.status_code == 404: return { "success": False, "error": "API 端点不存在,请确认 API 服务已正确配置", "fallback": self._load_offline() } else: return { "success": False, "error": f"API 请求失败,状态码: {response.status_code}", "fallback": self._load_offline() } except requests.exceptions.ConnectionError: return { "success": False, "error": "无法连接到 API 服务,使用离线模式", "offline": True, "fallback": self._load_offline() } except requests.exceptions.Timeout: return { "success": False, "error": "API 请求超时", "fallback": self._load_offline() } except Exception as e: return { "success": False, "error": f"API 请求异常: {str(e)}", "fallback": self._load_offline() } def _load_offline(self) -> Dict[str, Any]: """离线模式:直接读取本地文件""" result = { "success": True, "offline": True, "loadedAt": datetime.now().isoformat(), "project": {}, "todos": {"pending": [], "inProgress": [], "completed": []}, "memories": {"recent": [], "highPriority": []}, "redLines": [], "commonErrors": [], "devGuide": {"quickCommands": [], "coreFiles": []} } # 读取 PROJECT.md project_md = self._read_project_md() if project_md: result["project"] = project_md["project"] result["todos"] = project_md["todos"] # 读取压缩摘要 summary = self._read_summary_md() if summary: result["todos"].update(summary.get("todos", {})) result["redLines"] = summary.get("redLines", []) result["commonErrors"] = summary.get("commonErrors", []) result["devGuide"] = summary.get("devGuide", {}) return result def _read_project_md(self) -> Optional[Dict[str, Any]]: """读取 PROJECT.md""" project_path = self.project_root / "PROJECT.md" if not project_path.exists(): return None try: content = project_path.read_text(encoding="utf-8") return self._parse_project_md(content) except Exception as e: return {"error": str(e)} def _parse_project_md(self, content: str) -> Dict[str, Any]: """解析 PROJECT.md 内容""" result = { "project": {}, "todos": {"pending": [], "inProgress": [], "completed": []} } # 解析基本信息 name_match = re.search(r"\*\*名称\*\*\s*\|\s*(.+)", content) version_match = re.search(r"\*\*版本\*\*\s*\|\s*(.+)", content) tech_match = re.search(r"\*\*技术栈\*\*\s*\|\s*(.+)", content) result["project"] = { "name": name_match.group(1).strip() if name_match else "工资表SaaS系统", "version": version_match.group(1).strip() if version_match else "0.5.0", "techStack": [t.strip() for t in tech_match.group(1).split(",")] if tech_match else [], "port": 5000 } # 解析待开发功能 pending_section = re.search(r"## 🚧 待开发功能[\s\S]*?(?=##|$)", content) if pending_section: lines = pending_section.group(0).split("\n") current_priority = "normal" for line in lines: priority_match = re.match(r"### (P\d+):", line) if priority_match: p_num = int(priority_match.group(1)[1:]) current_priority = "critical" if p_num <= 1 else ("high" if p_num == 2 else "normal") item_match = re.match(r"- \[ \] (.+)", line) if item_match: result["todos"]["pending"].append({ "content": item_match.group(1).strip(), "priority": current_priority, "status": "pending" }) # 解析已完成功能 completed_section = re.search(r"## ✅ 已完成功能[\s\S]*?(?=##|$)", content) if completed_section: lines = completed_section.group(0).split("\n") for line in lines: item_match = re.match(r"### (P\d+): (.+)", line) if item_match: result["todos"]["completed"].append({ "content": item_match.group(2).strip(), "priority": "normal", "status": "completed" }) return result def _read_summary_md(self) -> Optional[Dict[str, Any]]: """读取压缩摘要""" summary_path = self.project_root / "docs/17-其他/压缩摘要.md" if not summary_path.exists(): return None try: content = summary_path.read_text(encoding="utf-8") return self._parse_summary_md(content) except Exception as e: return {"error": str(e)} def _parse_summary_md(self, content: str) -> Dict[str, Any]: """解析压缩摘要内容""" result = { "todos": {"pending": [], "inProgress": [], "completed": []}, "redLines": [], "commonErrors": [], "devGuide": {"quickCommands": [], "coreFiles": []} } # 解析 TODO todo_section = re.search(r"## TODO[\s\S]*?(?=##|$)", content) if todo_section: lines = todo_section.group(0).split("\n") for line in lines: item_match = re.match(r"- (.+)", line) if item_match and "TODO" not in item_match.group(1): result["todos"]["pending"].append({ "content": item_match.group(1).strip(), "priority": "normal", "status": "pending" }) # 解析常见错误 error_section = re.search(r"## 🐛 常见错误速查[\s\S]*?(?=##|$)", content) if error_section: lines = error_section.group(0).split("\n") for line in lines: match = re.match(r"\|\s*(.+?)\s*\|\s*(.+?)\s*\|\s*(.+?)\s*\|", line) if match and match.group(1) != "错误": result["commonErrors"].append({ "error": match.group(1).strip(), "cause": match.group(2).strip(), "solution": match.group(3).strip() }) # 解析快速命令 cmd_section = re.search(r"## ⚡ 快速命令[\s\S]*?(?=##|$)", content) if cmd_section: lines = cmd_section.group(0).split("\n") for line in lines: match = re.match(r"\|\s*`?([^`|\n]+)`?\s*\|\s*(.+?)\s*\|\s*(.+?)\s*\|", line) if match and match.group(1) != "命令": result["devGuide"]["quickCommands"].append({ "command": match.group(1).strip(), "purpose": match.group(2).strip(), "when": match.group(3).strip() }) return result def generate_markdown_summary(self, context: Dict[str, Any]) -> str: """生成 Markdown 格式的摘要""" md = "# 📋 项目状态概览\n\n" md += f"> 加载时间: {datetime.now().strftime('%Y/%m/%d %H:%M:%S')}\n" md += f"> API 状态: {'❌ 离线模式' if context.get('offline') else '✅ 在线'}\n\n" # 项目信息 project = context.get("project", {}) if project: md += "## 📦 项目信息\n" md += "| 项目 | 内容 |\n" md += "|------|------|\n" md += f"| **名称** | {project.get('name', 'N/A')} |\n" md += f"| **版本** | {project.get('version', 'N/A')} |\n" md += f"| **技术栈** | {', '.join(project.get('techStack', []))} |\n" md += f"| **端口** | {project.get('port', 5000)} |\n\n" # TODO 列表 todos = context.get("todos", {}) pending = todos.get("pending", []) if pending: md += "## 📝 待办事项\n" for todo in pending[:10]: priority = todo.get("priority", "normal") icon = "🔴" if priority == "critical" else ("🟡" if priority == "high" else "⚪") md += f"- {icon} {todo.get('content', '')}\n" md += "\n" # 最近记忆 memories = context.get("memories", {}) recent = memories.get("recent", []) if recent: md += "## 🧠 最近记忆\n" for m in recent[:5]: md += f"- **[{m.get('type', 'unknown')}]** {m.get('title', '')}\n" md += "\n" # 高优先级记忆 high_priority = memories.get("highPriority", []) if high_priority: md += "## ⭐ 重要事项\n" for m in high_priority[:5]: importance = m.get("importance", "normal").upper() md += f"- **[{importance}]** {m.get('title', '')}\n" md += "\n" # 红线规则 red_lines = context.get("redLines", []) if red_lines: md += "## 🚨 关键红线\n" for i, rule in enumerate(red_lines[:5], 1): md += f"{i}. {rule.get('title', rule.get('category', ''))}: {rule.get('description', '')[:50]}...\n" md += "\n" # 快速命令 dev_guide = context.get("devGuide", {}) commands = dev_guide.get("quickCommands", []) if commands: md += "## ⚡ 快速命令\n" md += "| 命令 | 用途 |\n" md += "|------|------|\n" for cmd in commands[:5]: md += f"| `{cmd.get('command', '')}` | {cmd.get('purpose', '')} |\n" md += "\n" return md def call_maintenance_action( self, action: str, dry_run: bool = False, **kwargs ) -> Dict[str, Any]: """ 调用维护动作 Args: action: 动作类型 (quality/merge/cleanup/maintenance/report) dry_run: 是否试运行 Returns: 动作结果 """ if self.offline: return { "success": False, "error": "离线模式不支持维护操作" } api_url = self.api_url.replace("/context", "/maintenance") try: response = requests.post( api_url, json={ "action": action, "dryRun": dry_run, **kwargs }, headers={"Content-Type": "application/json"}, timeout=self.timeout * 2 ) if response.status_code == 200: return response.json() else: return { "success": False, "error": f"API 请求失败,状态码: {response.status_code}" } except Exception as e: return { "success": False, "error": str(e) } def main(): """主函数""" parser = argparse.ArgumentParser( description="项目记忆加载器 v2.0 - 加载项目上下文信息", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=""" 示例: # 加载项目上下文(JSON 格式) python project_memory_loader.py # 加载项目上下文(Markdown 格式) python project_memory_loader.py --format markdown # 精简模式 python project_memory_loader.py --compact # 离线模式 python project_memory_loader.py --offline # 获取记忆质量报告 python project_memory_loader.py --action quality # 预览重复记忆合并建议 python project_memory_loader.py --action merge --dry-run # 执行重复记忆合并 python project_memory_loader.py --action merge # 清理过期记忆 python project_memory_loader.py --action cleanup # 运行完整维护 python project_memory_loader.py --action maintenance """ ) parser.add_argument( "--format", "-f", choices=["json", "markdown"], default="json", help="输出格式 (默认: json)" ) parser.add_argument( "--refresh", "-r", action="store_true", help="强制刷新缓存" ) parser.add_argument( "--compact", "-c", action="store_true", help="精简模式,只返回核心信息" ) parser.add_argument( "--offline", "-o", action="store_true", help="离线模式,直接读取本地文件" ) parser.add_argument( "--action", "-a", choices=["quality", "merge", "cleanup", "maintenance", "report"], help="执行维护动作" ) parser.add_argument( "--dry-run", action="store_true", help="试运行,只返回结果不执行" ) parser.add_argument( "--api-url", default=DEFAULT_API_URL, help=f"API 端点 URL (默认: {DEFAULT_API_URL})" ) parser.add_argument( "--timeout", type=int, default=10, help="API 请求超时时间(秒)(默认: 10)" ) args = parser.parse_args() loader = ProjectContextLoader( api_url=args.api_url, offline=args.offline, timeout=args.timeout ) # 执行维护动作 if args.action: result = loader.call_maintenance_action( args.action, dry_run=args.dry_run ) print(json.dumps(result, ensure_ascii=False, indent=2)) sys.exit(0 if result.get("success") else 1) # 加载上下文 result = loader.load_context( format=args.format, refresh=args.refresh, compact=args.compact ) # 输出结果 if args.format == "markdown" and "content" in result: print(result["content"]) elif "fallback" in result and result.get("offline"): # 使用降级数据生成 markdown md = loader.generate_markdown_summary(result["fallback"]) print(md) else: print(json.dumps(result, ensure_ascii=False, indent=2)) # 设置退出码 if not result.get("success", True): sys.exit(1) if __name__ == "__main__": main()
未来鸟
2026年7月27日 11:03
转发
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
分享
链接
类型
密码
更新密码
有效期
Markdown文件
Word文件
PDF文档(打印)
AI